@fluentui/priority-overflow 0.0.0-nightly-20230223-0420.1 → 0.0.0-nightly-20230223-2115.1

Sign up to get free protection for your applications and to get access to all the features.
package/.swcrc ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://json.schemastore.org/swcrc",
3
+ "env": {
4
+ "targets": {
5
+ "chrome": "84",
6
+ "edge": "84",
7
+ "firefox": "75",
8
+ "opera": "73",
9
+ "safari": "14.1"
10
+ }
11
+ },
12
+ "exclude": [
13
+ "/testing",
14
+ "/**/*.cy.ts",
15
+ "/**/*.cy.tsx",
16
+ "/**/*.spec.ts",
17
+ "/**/*.spec.tsx",
18
+ "/**/*.test.ts",
19
+ "/**/*.test.tsx"
20
+ ],
21
+ "jsc": {
22
+ "parser": {
23
+ "syntax": "typescript",
24
+ "tsx": true,
25
+ "decorators": false,
26
+ "dynamicImport": false
27
+ },
28
+ "target": "es2019",
29
+ "externalHelpers": true
30
+ },
31
+ "minify": false,
32
+ "sourceMaps": true
33
+ }
package/CHANGELOG.json CHANGED
@@ -2,9 +2,9 @@
2
2
  "name": "@fluentui/priority-overflow",
3
3
  "entries": [
4
4
  {
5
- "date": "Thu, 23 Feb 2023 04:27:20 GMT",
6
- "tag": "@fluentui/priority-overflow_v0.0.0-nightly-20230223-0420.1",
7
- "version": "0.0.0-nightly-20230223-0420.1",
5
+ "date": "Thu, 23 Feb 2023 21:23:04 GMT",
6
+ "tag": "@fluentui/priority-overflow_v0.0.0-nightly-20230223-2115.1",
7
+ "version": "0.0.0-nightly-20230223-2115.1",
8
8
  "comments": {
9
9
  "prerelease": [
10
10
  {
package/CHANGELOG.md CHANGED
@@ -1,13 +1,13 @@
1
1
  # Change Log - @fluentui/priority-overflow
2
2
 
3
- This log was last generated on Thu, 23 Feb 2023 04:27:20 GMT and should not be manually modified.
3
+ This log was last generated on Thu, 23 Feb 2023 21:23:04 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## [0.0.0-nightly-20230223-0420.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v0.0.0-nightly-20230223-0420.1)
7
+ ## [0.0.0-nightly-20230223-2115.1](https://github.com/microsoft/fluentui/tree/@fluentui/priority-overflow_v0.0.0-nightly-20230223-2115.1)
8
8
 
9
- Thu, 23 Feb 2023 04:27:20 GMT
10
- [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.1..@fluentui/priority-overflow_v0.0.0-nightly-20230223-0420.1)
9
+ Thu, 23 Feb 2023 21:23:04 GMT
10
+ [Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/priority-overflow_v9.0.1..@fluentui/priority-overflow_v0.0.0-nightly-20230223-2115.1)
11
11
 
12
12
  ### Changes
13
13
 
package/lib/debounce.js CHANGED
@@ -3,8 +3,7 @@
3
3
  * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide
4
4
  * @param fn - Function to debounce
5
5
  * @returns debounced function
6
- */
7
- export function debounce(fn) {
6
+ */export function debounce(fn) {
8
7
  let pending;
9
8
  return () => {
10
9
  if (!pending) {
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAAA;;;;;;AAMA,OAAM,SAAUA,QAAQ,CAACC,EAAY;EACnC,IAAIC,OAAgB;EACpB,OAAO,MAAK;IACV,IAAI,CAACA,OAAO,EAAE;MACZA,OAAO,GAAG,IAAI;MACdC,cAAc,CAAC,MAAK;QAClB;QACA;QACAD,OAAO,GAAG,KAAK;QACfD,EAAE,EAAE;MACN,CAAC,CAAC;;EAEN,CAAC;AACH","names":["debounce","fn","pending","queueMicrotask"],"sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/debounce.ts"],"sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"]}
1
+ {"version":3,"mappings":"AAAA;;;;;GAMA,OAAO,SAASA,SAASC,EAAY,EAAE;EACrC,IAAIC;EACJ,OAAO,MAAM;IACX,IAAI,CAACA,SAAS;MACZA,UAAU,IAAI;MACdC,eAAe,MAAM;QACnB;QACA;QACAD,UAAU,KAAK;QACfD;MACF;IACF;EACF;AACF","names":["debounce","fn","pending","queueMicrotask"],"sources":["../src/debounce.ts"],"sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"]}
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC","sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"]}
1
+ {"version":3,"mappings":"AAAA,SAASA,qBAAqB,QAAQ","names":["createOverflowManager"],"sources":["../src/index.ts"],"sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"]}
@@ -91,7 +91,8 @@ export function createOverflowManager() {
91
91
  const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);
92
92
  const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);
93
93
  const groupVisibility = {};
94
- Object.entries(overflowGroups).forEach(([groupId, groupState]) => {
94
+ Object.entries(overflowGroups).forEach(param => {
95
+ let [groupId, groupState] = param;
95
96
  if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {
96
97
  groupVisibility[groupId] = 'overflow';
97
98
  } else if (groupState.visibleItemIds.size === 0) {
@@ -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;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,GAAGpB,mBAAmB,CAAS,CAACqB,CAAC,EAAEC,CAAC,KAAI;IAC9D,MAAMC,KAAK,GAAGT,aAAa,CAACO,CAAC,CAAC;IAC9B,MAAMG,KAAK,GAAGV,aAAa,CAACQ,CAAC,CAAC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C;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":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/overflowManager.ts"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (): boolean => {\n if (!container) {\n return false;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n return true;\n }\n\n return false;\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}
1
+ {"version":3,"mappings":"AAAA,SAASA,QAAQ,QAAQ;AACzB,SAASC,mBAAmB,QAAQ;AAGpC;;;;AAIA,OAAO,SAASC,wBAAyC;EACvD,IAAIC;EACJ,IAAIC;EACJ;EACA,IAAIC,YAAY,KAAK;EACrB;EACA,IAAIC,gBAAgB,KAAK;EACzB,MAAMC,UAAoC;IACxCC,SAAS;IACTC,cAAc;IACdC,mBAAmB;IACnBC,gBAAgB;IAChBC,wBAAwB,MAAMC;IAC9BC,kBAAkB,MAAMD;EAC1B;EAEA,MAAME,gBAAmD,CAAC;EAC1D,MAAMC,iBAAiG,CAAC;EACxG,MAAMC,iBAAiB,IAAIC,eAAeC,WAAW;IACnD,IAAI,CAACA,OAAO,CAAC,EAAE,IAAI,CAAChB,WAAW;MAC7B;IACF;IAEAiB;EACF;EAEA,MAAMC,qBAAqBpB,oBAA4B,CAACqB,GAAGC,MAAM;IAC/D,MAAMC,Q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AKE,OAAO,CAAC,CAACI,cAAc,CAACF,MAAM,CAACJ,KAAKK,EAAE;MAC1D/B,cAAc,CAAC0B,KAAKE,OAAO,CAAC,CAACC,gBAAgB,CAACC,MAAM,CAACJ,KAAKK,EAAE;IAC9D;IAEA,OAAOhC,aAAa,CAAC0C,OAAO;IAC5BrC;EACF;EAEA,OAAO;IACL+D;IACAD;IACAN;IACAC;IACAU;IACAnE;IACAiE;IACAC;EACF;AACF","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","param","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"],"sources":["../src/overflowManager.ts"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (): boolean => {\n if (!container) {\n return false;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n return true;\n }\n\n return false;\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}
@@ -1,8 +1,7 @@
1
1
  /**
2
2
  * @param compare - comparison function for items
3
3
  * @returns Priority queue implemented with a min heap
4
- */
5
- export function createPriorityQueue(compare) {
4
+ */export function createPriorityQueue(compare) {
6
5
  const arr = [];
7
6
  let size = 0;
8
7
  const left = i => {
@@ -1 +1 @@
1
- {"version":3,"mappings":"AAaA;;;;AAIA,OAAM,SAAUA,mBAAmB,CAAIC,OAAkC;EACvE,MAAMC,GAAG,GAAQ,EAAE;EACnB,IAAIC,IAAI,GAAG,CAAC;EAEZ,MAAMC,IAAI,GAAIC,CAAS,IAAI;IACzB,OAAO,CAAC,GAAGA,CAAC,GAAG,CAAC;EAClB,CAAC;EAED,MAAMC,KAAK,GAAID,CAAS,IAAI;IAC1B,OAAO,CAAC,GAAGA,CAAC,GAAG,CAAC;EAClB,CAAC;EAED,MAAME,MAAM,GAAIF,CAAS,IAAI;IAC3B,OAAOG,IAAI,CAACC,KAAK,CAAC,CAACJ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;EAChC,CAAC;EAED,MAAMK,IAAI,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,GAAGC,GAAG;EACd,CAAC;EAED,MAAMC,OAAO,GAAIT,CAAS,IAAI;IAC5B,IAAIU,QAAQ,GAAGV,CAAC;IAChB,MAAMW,CAAC,GAAGZ,IAAI,CAACC,CAAC,CAAC;IACjB,MAAMY,CAAC,GAAGX,KAAK,CAACD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K,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","names":["createPriorityQueue","compare","arr","size","left","i","right","parent","Math","floor","swap","a","b","tmp","heapify","smallest","l","r","dequeue","Error","res","peek","enqueue","item","p","contains","index","indexOf","remove","clear","all","slice"],"sourceRoot":"","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
+ {"version":3,"mappings":"AAaA;;;GAIA,OAAO,SAASA,oBAAuBC,OAAkC,EAAoB;EAC3F,MAAMC,MAAW,EAAE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AI,KAAKJ,QAAQC,GAAG,CAACsB,EAAE,EAAEtB,GAAG,CAACG,EAAE,IAAI,GAAG;MAC3CK,KAAKc,GAAGnB;MACRA,IAAImB;MACJA,IAAIjB,OAAOF;IACb;EACF;EAEA,MAAMoB,WAAYF,QAAY;IAC5B,MAAMG,QAAQxB,IAAIyB,OAAO,CAACJ;IAC1B,OAAOG,SAAS,KAAKA,QAAQvB;EAC/B;EAEA,MAAMyB,SAAUL,QAAY;IAC1B,MAAMlB,IAAIH,IAAIyB,OAAO,CAACJ;IAEtB,IAAIlB,MAAM,CAAC,KAAKA,KAAKF,MAAM;MACzB;IACF;IAEAD,GAAG,CAACG,EAAE,GAAGH,GAAG,CAAC,EAAEC,KAAK;IACpBW,QAAQT;EACV;EAEA,MAAMwB,QAAQ,MAAM;IAClB1B,OAAO;EACT;EAEA,MAAM2B,MAAM,MAAM;IAChB,OAAO5B,IAAI6B,KAAK,CAAC,GAAG5B;EACtB;EAEA,OAAO;IACL2B;IACAD;IACAJ;IACAP;IACAI;IACAD;IACAO;IACAzB,MAAM,MAAMA;EACd;AACF","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"],"sources":["../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"]}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type OverflowDirection = 'start' | 'end';\nexport type OverflowAxis = 'horizontal' | 'vertical';\nexport type OverflowGroupState = 'visible' | 'hidden' | 'overflow';\nexport interface OverflowItemEntry {\n /**\n * HTML element that will be disappear when overflowed\n */\n element: HTMLElement;\n /**\n * Lower priority items are invisible first when the container is overflowed\n * @default 0\n */\n priority: number;\n /**\n * Specific id, used to track visibility and provide updates to consumers\n */\n id: string;\n\n groupId?: string;\n}\n\n/**\n * signature similar to standard event listeners, but typed to handle the custom event\n */\nexport type OnUpdateOverflow = (data: OverflowEventPayload) => void;\n\nexport type OnUpdateItemVisibility = (data: OnUpdateItemVisibilityPayload) => void;\n\n/**\n * Payload of the custom DOM event for overflow updates\n */\nexport interface OverflowEventPayload {\n visibleItems: OverflowItemEntry[];\n invisibleItems: OverflowItemEntry[];\n groupVisibility: Record<string, OverflowGroupState>;\n}\n\nexport interface OnUpdateItemVisibilityPayload {\n item: OverflowItemEntry;\n visible: boolean;\n}\n\nexport interface ObserveOptions {\n /**\n * Padding (in px) at the end of the container before overflow occurs\n * Useful to account for extra elements (i.e. dropdown menu)\n * or to account for any kinds of margins between items which are hard to measure with JS\n * @default 10\n */\n padding?: number;\n /**\n * Direction where items are removed when overflow occurs\n * @default end\n */\n overflowDirection?: OverflowDirection;\n\n /**\n * Horizontal or vertical overflow\n * @default horizontal\n */\n overflowAxis?: OverflowAxis;\n\n /**\n * The minimum number of visible items\n */\n minimumVisible?: number;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateItemVisibility: OnUpdateItemVisibility;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateOverflow: OnUpdateOverflow;\n}\n\n/**\n * @internal\n */\nexport interface OverflowManager {\n /**\n * Starts observing the container and managing the overflow state\n */\n observe: (container: HTMLElement, options: ObserveOptions) => void;\n /**\n * Stops observing the container\n */\n disconnect: () => void;\n /**\n * Add overflow items\n */\n addItem: (items: OverflowItemEntry) => void;\n /**\n * Remove overflow item\n */\n removeItem: (itemId: string) => void;\n /**\n * Manually update the overflow, updates are batched and async\n */\n update: () => void;\n /**\n * Manually update the overflow sync\n */\n forceUpdate: () => void;\n\n /**\n * Adds an element that opens an overflow menu. This is used to calculate\n * available space and check if additional items need to overflow\n */\n addOverflowMenu: (element: HTMLElement) => void;\n\n /**\n * Unsets the overflow menu element\n */\n removeOverflowMenu: () => void;\n}\n"]}
1
+ {"version":3,"mappings":"AAAA","names":[],"sources":["../src/types.ts"],"sourcesContent":["export type OverflowDirection = 'start' | 'end';\nexport type OverflowAxis = 'horizontal' | 'vertical';\nexport type OverflowGroupState = 'visible' | 'hidden' | 'overflow';\nexport interface OverflowItemEntry {\n /**\n * HTML element that will be disappear when overflowed\n */\n element: HTMLElement;\n /**\n * Lower priority items are invisible first when the container is overflowed\n * @default 0\n */\n priority: number;\n /**\n * Specific id, used to track visibility and provide updates to consumers\n */\n id: string;\n\n groupId?: string;\n}\n\n/**\n * signature similar to standard event listeners, but typed to handle the custom event\n */\nexport type OnUpdateOverflow = (data: OverflowEventPayload) => void;\n\nexport type OnUpdateItemVisibility = (data: OnUpdateItemVisibilityPayload) => void;\n\n/**\n * Payload of the custom DOM event for overflow updates\n */\nexport interface OverflowEventPayload {\n visibleItems: OverflowItemEntry[];\n invisibleItems: OverflowItemEntry[];\n groupVisibility: Record<string, OverflowGroupState>;\n}\n\nexport interface OnUpdateItemVisibilityPayload {\n item: OverflowItemEntry;\n visible: boolean;\n}\n\nexport interface ObserveOptions {\n /**\n * Padding (in px) at the end of the container before overflow occurs\n * Useful to account for extra elements (i.e. dropdown menu)\n * or to account for any kinds of margins between items which are hard to measure with JS\n * @default 10\n */\n padding?: number;\n /**\n * Direction where items are removed when overflow occurs\n * @default end\n */\n overflowDirection?: OverflowDirection;\n\n /**\n * Horizontal or vertical overflow\n * @default horizontal\n */\n overflowAxis?: OverflowAxis;\n\n /**\n * The minimum number of visible items\n */\n minimumVisible?: number;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateItemVisibility: OnUpdateItemVisibility;\n\n /**\n * Callback when item visibility is updated\n */\n onUpdateOverflow: OnUpdateOverflow;\n}\n\n/**\n * @internal\n */\nexport interface OverflowManager {\n /**\n * Starts observing the container and managing the overflow state\n */\n observe: (container: HTMLElement, options: ObserveOptions) => void;\n /**\n * Stops observing the container\n */\n disconnect: () => void;\n /**\n * Add overflow items\n */\n addItem: (items: OverflowItemEntry) => void;\n /**\n * Remove overflow item\n */\n removeItem: (itemId: string) => void;\n /**\n * Manually update the overflow, updates are batched and async\n */\n update: () => void;\n /**\n * Manually update the overflow sync\n */\n forceUpdate: () => void;\n\n /**\n * Adds an element that opens an overflow menu. This is used to calculate\n * available space and check if additional items need to overflow\n */\n addOverflowMenu: (element: HTMLElement) => void;\n\n /**\n * Unsets the overflow menu element\n */\n removeOverflowMenu: () => void;\n}\n"]}
@@ -1,28 +1,29 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.debounce = void 0;
7
1
  /**
8
2
  * Microtask debouncer
9
3
  * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide
10
4
  * @param fn - Function to debounce
11
5
  * @returns debounced function
12
- */
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "debounce", {
11
+ enumerable: true,
12
+ get: ()=>debounce
13
+ });
13
14
  function debounce(fn) {
14
- let pending;
15
- return () => {
16
- if (!pending) {
17
- pending = true;
18
- queueMicrotask(() => {
19
- // Need to set pending to `false` before the debounced function is run.
20
- // React can actually interrupt the function while it's running!
21
- pending = false;
22
- fn();
23
- });
24
- }
25
- };
26
- }
27
- exports.debounce = debounce;
15
+ let pending;
16
+ return ()=>{
17
+ if (!pending) {
18
+ pending = true;
19
+ queueMicrotask(()=>{
20
+ // Need to set pending to `false` before the debounced function is run.
21
+ // React can actually interrupt the function while it's running!
22
+ pending = false;
23
+ fn();
24
+ });
25
+ }
26
+ };
27
+ } //# sourceMappingURL=debounce.js.map
28
+
28
29
  //# sourceMappingURL=debounce.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;AAAA;;;;;;AAMA,SAAgBA,QAAQ,CAACC,EAAY;EACnC,IAAIC,OAAgB;EACpB,OAAO,MAAK;IACV,IAAI,CAACA,OAAO,EAAE;MACZA,OAAO,GAAG,IAAI;MACdC,cAAc,CAAC,MAAK;QAClB;QACA;QACAD,OAAO,GAAG,KAAK;QACfD,EAAE,EAAE;MACN,CAAC,CAAC;;EAEN,CAAC;AACH;AAbAG","names":["debounce","fn","pending","queueMicrotask","exports"],"sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/debounce.ts"],"sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"]}
1
+ {"version":3,"sources":["../lib/debounce.js"],"sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */export function debounce(fn) {\n let pending;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n//# sourceMappingURL=debounce.js.map"],"names":["debounce","fn","pending","queueMicrotask"],"mappings":"AAAA;;;;;CAKC;;;;+BAAkBA;;aAAAA;;AAAT,SAASA,SAASC,EAAE,EAAE;IAC9B,IAAIC;IACJ,OAAO,IAAM;QACX,IAAI,CAACA,SAAS;YACZA,UAAU,IAAI;YACdC,eAAe,IAAM;gBACnB,uEAAuE;gBACvE,gEAAgE;gBAChED,UAAU,KAAK;gBACfD;YACF;QACF,CAAC;IACH;AACF,EACA,oCAAoC"}
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
6
- exports.createOverflowManager = void 0;
7
- var overflowManager_1 = /*#__PURE__*/require("./overflowManager");
8
5
  Object.defineProperty(exports, "createOverflowManager", {
9
- enumerable: true,
10
- get: function () {
11
- return overflowManager_1.createOverflowManager;
12
- }
6
+ enumerable: true,
7
+ get: ()=>_overflowManager.createOverflowManager
13
8
  });
9
+ const _overflowManager = require("./overflowManager");
10
+ //# sourceMappingURL=index.js.map
11
+
14
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;AAAA;AAASA;EAAAC;EAAAC;IAAA,8CAAqB;EAAA;AAAA","names":["Object","enumerable","get"],"sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/index.ts"],"sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"]}
1
+ {"version":3,"sources":["../lib/index.js"],"sourcesContent":["export { createOverflowManager } from './overflowManager';\n//# sourceMappingURL=index.js.map"],"names":["createOverflowManager"],"mappings":";;;;+BAASA;;aAAAA,sCAAqB;;iCAAQ;CACtC,iCAAiC"}
@@ -1,224 +1,223 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "createOverflowManager", {
6
+ enumerable: true,
7
+ get: ()=>createOverflowManager
5
8
  });
6
- exports.createOverflowManager = void 0;
7
- const debounce_1 = /*#__PURE__*/require("./debounce");
8
- const priorityQueue_1 = /*#__PURE__*/require("./priorityQueue");
9
- /**
10
- * @internal
11
- * @returns overflow manager instance
12
- */
9
+ const _debounce = require("./debounce");
10
+ const _priorityQueue = require("./priorityQueue");
13
11
  function createOverflowManager() {
14
- let container;
15
- let overflowMenu;
16
- // Set as true when resize observer is observing
17
- let observing = false;
18
- // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
19
- let forceDispatch = false;
20
- const options = {
21
- padding: 10,
22
- overflowAxis: 'horizontal',
23
- overflowDirection: 'end',
24
- minimumVisible: 0,
25
- onUpdateItemVisibility: () => undefined,
26
- onUpdateOverflow: () => undefined
27
- };
28
- const overflowItems = {};
29
- const overflowGroups = {};
30
- const resizeObserver = new ResizeObserver(entries => {
31
- if (!entries[0] || !container) {
32
- return;
33
- }
34
- update();
35
- });
36
- const invisibleItemQueue = priorityQueue_1.createPriorityQueue((a, b) => {
37
- const itemA = overflowItems[a];
38
- const itemB = overflowItems[b];
39
- // Higher priority at the top of the queue
40
- const priority = itemB.priority - itemA.priority;
41
- if (priority !== 0) {
42
- return priority;
43
- }
44
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
45
- // equal priority, use DOM order
46
- // eslint-disable-next-line no-bitwise
47
- return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
48
- });
49
- const visibleItemQueue = priorityQueue_1.createPriorityQueue((a, b) => {
50
- const itemA = overflowItems[a];
51
- const itemB = overflowItems[b];
52
- // Lower priority at the top of the queue
53
- const priority = itemA.priority - itemB.priority;
54
- if (priority !== 0) {
55
- return priority;
56
- }
57
- const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
58
- // equal priority, use DOM order
59
- // eslint-disable-next-line no-bitwise
60
- return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
61
- });
62
- const getOffsetSize = el => {
63
- return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
64
- };
65
- const makeItemVisible = () => {
66
- const nextVisible = invisibleItemQueue.dequeue();
67
- visibleItemQueue.enqueue(nextVisible);
68
- const item = overflowItems[nextVisible];
69
- options.onUpdateItemVisibility({
70
- item,
71
- visible: true
12
+ let container;
13
+ let overflowMenu;
14
+ // Set as true when resize observer is observing
15
+ let observing = false;
16
+ // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
17
+ let forceDispatch = false;
18
+ const options = {
19
+ padding: 10,
20
+ overflowAxis: 'horizontal',
21
+ overflowDirection: 'end',
22
+ minimumVisible: 0,
23
+ onUpdateItemVisibility: ()=>undefined,
24
+ onUpdateOverflow: ()=>undefined
25
+ };
26
+ const overflowItems = {};
27
+ const overflowGroups = {};
28
+ const resizeObserver = new ResizeObserver((entries)=>{
29
+ if (!entries[0] || !container) {
30
+ return;
31
+ }
32
+ update();
72
33
  });
73
- if (item.groupId) {
74
- overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
75
- overflowGroups[item.groupId].visibleItemIds.add(item.id);
76
- }
77
- return getOffsetSize(item.element);
78
- };
79
- const makeItemInvisible = () => {
80
- const nextInvisible = visibleItemQueue.dequeue();
81
- invisibleItemQueue.enqueue(nextInvisible);
82
- const item = overflowItems[nextInvisible];
83
- const width = getOffsetSize(item.element);
84
- options.onUpdateItemVisibility({
85
- item,
86
- visible: false
34
+ const invisibleItemQueue = (0, _priorityQueue.createPriorityQueue)((a, b)=>{
35
+ const itemA = overflowItems[a];
36
+ const itemB = overflowItems[b];
37
+ // Higher priority at the top of the queue
38
+ const priority = itemB.priority - itemA.priority;
39
+ if (priority !== 0) {
40
+ return priority;
41
+ }
42
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
43
+ // equal priority, use DOM order
44
+ // eslint-disable-next-line no-bitwise
45
+ return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
87
46
  });
88
- if (item.groupId) {
89
- overflowGroups[item.groupId].visibleItemIds.delete(item.id);
90
- overflowGroups[item.groupId].invisibleItemIds.add(item.id);
91
- }
92
- return width;
93
- };
94
- const dispatchOverflowUpdate = () => {
95
- const visibleItemIds = visibleItemQueue.all();
96
- const invisibleItemIds = invisibleItemQueue.all();
97
- const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);
98
- const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);
99
- const groupVisibility = {};
100
- Object.entries(overflowGroups).forEach(([groupId, groupState]) => {
101
- if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {
102
- groupVisibility[groupId] = 'overflow';
103
- } else if (groupState.visibleItemIds.size === 0) {
104
- groupVisibility[groupId] = 'hidden';
105
- } else {
106
- groupVisibility[groupId] = 'visible';
107
- }
47
+ const visibleItemQueue = (0, _priorityQueue.createPriorityQueue)((a, b)=>{
48
+ const itemA = overflowItems[a];
49
+ const itemB = overflowItems[b];
50
+ // Lower priority at the top of the queue
51
+ const priority = itemA.priority - itemB.priority;
52
+ if (priority !== 0) {
53
+ return priority;
54
+ }
55
+ const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
56
+ // equal priority, use DOM order
57
+ // eslint-disable-next-line no-bitwise
58
+ return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
108
59
  });
109
- options.onUpdateOverflow({
110
- visibleItems,
111
- invisibleItems,
112
- groupVisibility
113
- });
114
- };
115
- const processOverflowItems = () => {
116
- if (!container) {
117
- return false;
118
- }
119
- const availableSize = getOffsetSize(container) - options.padding;
120
- const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
121
- // Snapshot of the visible/invisible state to compare for updates
122
- const visibleTop = visibleItemQueue.peek();
123
- const invisibleTop = invisibleItemQueue.peek();
124
- const visibleItemIds = visibleItemQueue.all();
125
- let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {
126
- const child = overflowItems[visibleItemId].element;
127
- return sum + getOffsetSize(child);
128
- }, 0);
129
- // Add items until available width is filled - can result in overflow
130
- while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {
131
- currentWidth += makeItemVisible();
132
- }
133
- // Remove items until there's no more overflow
134
- while (currentWidth > availableSize && visibleItemQueue.size() > 0) {
135
- if (visibleItemQueue.size() <= options.minimumVisible) {
136
- break;
137
- }
138
- currentWidth -= makeItemInvisible();
139
- }
140
- // make sure the overflow menu can fit
141
- if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
142
- makeItemInvisible();
143
- }
144
- // only update when the state of visible/invisible items has changed
145
- if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
146
- return true;
147
- }
148
- return false;
149
- };
150
- const forceUpdate = () => {
151
- if (processOverflowItems() || forceDispatch) {
152
- forceDispatch = false;
153
- dispatchOverflowUpdate();
154
- }
155
- };
156
- const update = debounce_1.debounce(forceUpdate);
157
- const observe = (observedContainer, userOptions) => {
158
- Object.assign(options, userOptions);
159
- observing = true;
160
- Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));
161
- container = observedContainer;
162
- resizeObserver.observe(container);
163
- };
164
- const disconnect = () => {
165
- observing = false;
166
- resizeObserver.disconnect();
167
- };
168
- const addItem = item => {
169
- if (overflowItems[item.id]) {
170
- return;
171
- }
172
- overflowItems[item.id] = item;
173
- // some options can affect priority which are only set on `observe`
174
- if (observing) {
175
- // Updates to elements might not change the queue tops
176
- // i.e. new element is enqueued but the top of the queue stays the same
177
- // force a dispatch on the next batched update
178
- forceDispatch = true;
179
- visibleItemQueue.enqueue(item.id);
180
- }
181
- if (item.groupId) {
182
- if (!overflowGroups[item.groupId]) {
183
- overflowGroups[item.groupId] = {
184
- visibleItemIds: new Set(),
185
- invisibleItemIds: new Set()
186
- };
187
- }
188
- overflowGroups[item.groupId].visibleItemIds.add(item.id);
189
- }
190
- update();
191
- };
192
- const addOverflowMenu = el => {
193
- overflowMenu = el;
194
- };
195
- const removeOverflowMenu = () => {
196
- overflowMenu = undefined;
197
- };
198
- const removeItem = itemId => {
199
- if (!overflowItems[itemId]) {
200
- return;
201
- }
202
- const item = overflowItems[itemId];
203
- visibleItemQueue.remove(itemId);
204
- invisibleItemQueue.remove(itemId);
205
- if (item.groupId) {
206
- overflowGroups[item.groupId].visibleItemIds.delete(item.id);
207
- overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
208
- }
209
- delete overflowItems[itemId];
210
- update();
211
- };
212
- return {
213
- addItem,
214
- disconnect,
215
- forceUpdate,
216
- observe,
217
- removeItem,
218
- update,
219
- addOverflowMenu,
220
- removeOverflowMenu
221
- };
222
- }
223
- exports.createOverflowManager = createOverflowManager;
60
+ const getOffsetSize = (el)=>{
61
+ return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
62
+ };
63
+ const makeItemVisible = ()=>{
64
+ const nextVisible = invisibleItemQueue.dequeue();
65
+ visibleItemQueue.enqueue(nextVisible);
66
+ const item = overflowItems[nextVisible];
67
+ options.onUpdateItemVisibility({
68
+ item,
69
+ visible: true
70
+ });
71
+ if (item.groupId) {
72
+ overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
73
+ overflowGroups[item.groupId].visibleItemIds.add(item.id);
74
+ }
75
+ return getOffsetSize(item.element);
76
+ };
77
+ const makeItemInvisible = ()=>{
78
+ const nextInvisible = visibleItemQueue.dequeue();
79
+ invisibleItemQueue.enqueue(nextInvisible);
80
+ const item = overflowItems[nextInvisible];
81
+ const width = getOffsetSize(item.element);
82
+ options.onUpdateItemVisibility({
83
+ item,
84
+ visible: false
85
+ });
86
+ if (item.groupId) {
87
+ overflowGroups[item.groupId].visibleItemIds.delete(item.id);
88
+ overflowGroups[item.groupId].invisibleItemIds.add(item.id);
89
+ }
90
+ return width;
91
+ };
92
+ const dispatchOverflowUpdate = ()=>{
93
+ const visibleItemIds = visibleItemQueue.all();
94
+ const invisibleItemIds = invisibleItemQueue.all();
95
+ const visibleItems = visibleItemIds.map((itemId)=>overflowItems[itemId]);
96
+ const invisibleItems = invisibleItemIds.map((itemId)=>overflowItems[itemId]);
97
+ const groupVisibility = {};
98
+ Object.entries(overflowGroups).forEach((param)=>{
99
+ let [groupId, groupState] = param;
100
+ if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {
101
+ groupVisibility[groupId] = 'overflow';
102
+ } else if (groupState.visibleItemIds.size === 0) {
103
+ groupVisibility[groupId] = 'hidden';
104
+ } else {
105
+ groupVisibility[groupId] = 'visible';
106
+ }
107
+ });
108
+ options.onUpdateOverflow({
109
+ visibleItems,
110
+ invisibleItems,
111
+ groupVisibility
112
+ });
113
+ };
114
+ const processOverflowItems = ()=>{
115
+ if (!container) {
116
+ return false;
117
+ }
118
+ const availableSize = getOffsetSize(container) - options.padding;
119
+ const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
120
+ // Snapshot of the visible/invisible state to compare for updates
121
+ const visibleTop = visibleItemQueue.peek();
122
+ const invisibleTop = invisibleItemQueue.peek();
123
+ const visibleItemIds = visibleItemQueue.all();
124
+ let currentWidth = visibleItemIds.reduce((sum, visibleItemId)=>{
125
+ const child = overflowItems[visibleItemId].element;
126
+ return sum + getOffsetSize(child);
127
+ }, 0);
128
+ // Add items until available width is filled - can result in overflow
129
+ while(currentWidth < availableSize && invisibleItemQueue.size() > 0){
130
+ currentWidth += makeItemVisible();
131
+ }
132
+ // Remove items until there's no more overflow
133
+ while(currentWidth > availableSize && visibleItemQueue.size() > 0){
134
+ if (visibleItemQueue.size() <= options.minimumVisible) {
135
+ break;
136
+ }
137
+ currentWidth -= makeItemInvisible();
138
+ }
139
+ // make sure the overflow menu can fit
140
+ if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {
141
+ makeItemInvisible();
142
+ }
143
+ // only update when the state of visible/invisible items has changed
144
+ if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
145
+ return true;
146
+ }
147
+ return false;
148
+ };
149
+ const forceUpdate = ()=>{
150
+ if (processOverflowItems() || forceDispatch) {
151
+ forceDispatch = false;
152
+ dispatchOverflowUpdate();
153
+ }
154
+ };
155
+ const update = (0, _debounce.debounce)(forceUpdate);
156
+ const observe = (observedContainer, userOptions)=>{
157
+ Object.assign(options, userOptions);
158
+ observing = true;
159
+ Object.values(overflowItems).forEach((item)=>visibleItemQueue.enqueue(item.id));
160
+ container = observedContainer;
161
+ resizeObserver.observe(container);
162
+ };
163
+ const disconnect = ()=>{
164
+ observing = false;
165
+ resizeObserver.disconnect();
166
+ };
167
+ const addItem = (item)=>{
168
+ if (overflowItems[item.id]) {
169
+ return;
170
+ }
171
+ overflowItems[item.id] = item;
172
+ // some options can affect priority which are only set on `observe`
173
+ if (observing) {
174
+ // Updates to elements might not change the queue tops
175
+ // i.e. new element is enqueued but the top of the queue stays the same
176
+ // force a dispatch on the next batched update
177
+ forceDispatch = true;
178
+ visibleItemQueue.enqueue(item.id);
179
+ }
180
+ if (item.groupId) {
181
+ if (!overflowGroups[item.groupId]) {
182
+ overflowGroups[item.groupId] = {
183
+ visibleItemIds: new Set(),
184
+ invisibleItemIds: new Set()
185
+ };
186
+ }
187
+ overflowGroups[item.groupId].visibleItemIds.add(item.id);
188
+ }
189
+ update();
190
+ };
191
+ const addOverflowMenu = (el)=>{
192
+ overflowMenu = el;
193
+ };
194
+ const removeOverflowMenu = ()=>{
195
+ overflowMenu = undefined;
196
+ };
197
+ const removeItem = (itemId)=>{
198
+ if (!overflowItems[itemId]) {
199
+ return;
200
+ }
201
+ const item = overflowItems[itemId];
202
+ visibleItemQueue.remove(itemId);
203
+ invisibleItemQueue.remove(itemId);
204
+ if (item.groupId) {
205
+ overflowGroups[item.groupId].visibleItemIds.delete(item.id);
206
+ overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
207
+ }
208
+ delete overflowItems[itemId];
209
+ update();
210
+ };
211
+ return {
212
+ addItem,
213
+ disconnect,
214
+ forceUpdate,
215
+ observe,
216
+ removeItem,
217
+ update,
218
+ addOverflowMenu,
219
+ removeOverflowMenu
220
+ };
221
+ } //# sourceMappingURL=overflowManager.js.map
222
+
224
223
  //# sourceMappingURL=overflowManager.js.map
@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,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":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/overflowManager.ts"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (): boolean => {\n if (!container) {\n return false;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n return true;\n }\n\n return false;\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}
1
+ {"version":3,"sources":["../lib/overflowManager.js"],"sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager() {\n let container;\n let overflowMenu;\n // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = false;\n const options = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined\n };\n const overflowItems = {};\n const overflowGroups = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n update();\n });\n const invisibleItemQueue = createPriorityQueue((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n const visibleItemQueue = createPriorityQueue((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n if (priority !== 0) {\n return priority;\n }\n const positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n const getOffsetSize = el => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({\n item,\n visible: true\n });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n return getOffsetSize(item.element);\n };\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({\n item,\n visible: false\n });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n return width;\n };\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n const groupVisibility = {};\n Object.entries(overflowGroups).forEach(param => {\n let [groupId, groupState] = param;\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n options.onUpdateOverflow({\n visibleItems,\n invisibleItems,\n groupVisibility\n });\n };\n const processOverflowItems = () => {\n if (!container) {\n return false;\n }\n const availableSize = getOffsetSize(container) - options.padding;\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n // make sure the overflow menu can fit\n if (visibleItemQueue.size() > options.minimumVisible && invisibleItemQueue.size() > 0 && currentWidth + overflowMenuOffset > availableSize) {\n makeItemInvisible();\n }\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n return true;\n }\n return false;\n };\n const forceUpdate = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\n };\n const update = debounce(forceUpdate);\n const observe = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n container = observedContainer;\n resizeObserver.observe(container);\n };\n const disconnect = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n const addItem = item => {\n if (overflowItems[item.id]) {\n return;\n }\n overflowItems[item.id] = item;\n // some options can affect priority which are only set on `observe`\n if (observing) {\n // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\n visibleItemQueue.enqueue(item.id);\n }\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set(),\n invisibleItemIds: new Set()\n };\n }\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n update();\n };\n const addOverflowMenu = el => {\n overflowMenu = el;\n };\n const removeOverflowMenu = () => {\n overflowMenu = undefined;\n };\n const removeItem = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n delete overflowItems[itemId];\n update();\n };\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu\n };\n}\n//# sourceMappingURL=overflowManager.js.map"],"names":["createOverflowManager","container","overflowMenu","observing","forceDispatch","options","padding","overflowAxis","overflowDirection","minimumVisible","onUpdateItemVisibility","undefined","onUpdateOverflow","overflowItems","overflowGroups","resizeObserver","ResizeObserver","entries","update","invisibleItemQueue","createPriorityQueue","a","b","itemA","itemB","priority","positionStatusBit","Node","DOCUMENT_POSITION_FOLLOWING","DOCUMENT_POSITION_PRECEDING","element","compareDocumentPosition","visibleItemQueue","getOffsetSize","el","offsetWidth","offsetHeight","makeItemVisible","nextVisible","dequeue","enqueue","item","visible","groupId","invisibleItemIds","delete","id","visibleItemIds","add","makeItemInvisible","nextInvisible","width","dispatchOverflowUpdate","all","visibleItems","map","itemId","invisibleItems","groupVisibility","Object","forEach","param","groupState","size","processOverflowItems","availableSize","overflowMenuOffset","visibleTop","peek","invisibleTop","currentWidth","reduce","sum","visibleItemId","child","forceUpdate","debounce","observe","observedContainer","userOptions","assign","values","disconnect","addItem","Set","addOverflowMenu","removeOverflowMenu","removeItem","remove"],"mappings":";;;;+BAMgBA;;aAAAA;;0BANS;+BACW;AAK7B,SAASA,wBAAwB;IACtC,IAAIC;IACJ,IAAIC;IACJ,gDAAgD;IAChD,IAAIC,YAAY,KAAK;IACrB,+FAA+F;IAC/F,IAAIC,gBAAgB,KAAK;IACzB,MAAMC,UAAU;QACdC,SAAS;QACTC,cAAc;QACdC,mBAAmB;QACnBC,gBAAgB;QAChBC,wBAAwB,IA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jC7B,cAAc,CAAC2B,KAAKE,OAAO,CAAC,GAAG;oBAC7BI,gBAAgB,IAAIqC;oBACpBxC,kBAAkB,IAAIwC;gBACxB;YACF,CAAC;YACDtE,cAAc,CAAC2B,KAAKE,OAAO,CAAC,CAACI,cAAc,CAACC,GAAG,CAACP,KAAKK,EAAE;QACzD,CAAC;QACD5B;IACF;IACA,MAAMmE,kBAAkBnD,CAAAA,KAAM;QAC5BhC,eAAegC;IACjB;IACA,MAAMoD,qBAAqB,IAAM;QAC/BpF,eAAeS;IACjB;IACA,MAAM4E,aAAa/B,CAAAA,SAAU;QAC3B,IAAI,CAAC3C,aAAa,CAAC2C,OAAO,EAAE;YAC1B;QACF,CAAC;QACD,MAAMf,OAAO5B,aAAa,CAAC2C,OAAO;QAClCxB,iBAAiBwD,MAAM,CAAChC;QACxBrC,mBAAmBqE,MAAM,CAAChC;QAC1B,IAAIf,KAAKE,OAAO,EAAE;YAChB7B,cAAc,CAAC2B,KAAKE,OAAO,CAAC,CAACI,cAAc,CAACF,MAAM,CAACJ,KAAKK,EAAE;YAC1DhC,cAAc,CAAC2B,KAAKE,OAAO,CAAC,CAACC,gBAAgB,CAACC,MAAM,CAACJ,KAAKK,EAAE;QAC9D,CAAC;QACD,OAAOjC,aAAa,CAAC2C,OAAO;QAC5BtC;IACF;IACA,OAAO;QACLiE;QACAD;QACAP;QACAE;QACAU;QACArE;QACAmE;QACAC;IACF;AACF,EACA,2CAA2C"}
@@ -1,98 +1,99 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createPriorityQueue = void 0;
7
1
  /**
8
2
  * @param compare - comparison function for items
9
3
  * @returns Priority queue implemented with a min heap
10
- */
4
+ */ "use strict";
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ Object.defineProperty(exports, "createPriorityQueue", {
9
+ enumerable: true,
10
+ get: ()=>createPriorityQueue
11
+ });
11
12
  function createPriorityQueue(compare) {
12
- const arr = [];
13
- let size = 0;
14
- const left = i => {
15
- return 2 * i + 1;
16
- };
17
- const right = i => {
18
- return 2 * i + 2;
19
- };
20
- const parent = i => {
21
- return Math.floor((i - 1) / 2);
22
- };
23
- const swap = (a, b) => {
24
- const tmp = arr[a];
25
- arr[a] = arr[b];
26
- arr[b] = tmp;
27
- };
28
- const heapify = i => {
29
- let smallest = i;
30
- const l = left(i);
31
- const r = right(i);
32
- if (l < size && compare(arr[l], arr[smallest]) < 0) {
33
- smallest = l;
34
- }
35
- if (r < size && compare(arr[r], arr[smallest]) < 0) {
36
- smallest = r;
37
- }
38
- if (smallest !== i) {
39
- swap(smallest, i);
40
- heapify(smallest);
41
- }
42
- };
43
- const dequeue = () => {
44
- if (size === 0) {
45
- throw new Error('Priority queue empty');
46
- }
47
- const res = arr[0];
48
- arr[0] = arr[--size];
49
- heapify(0);
50
- return res;
51
- };
52
- const peek = () => {
53
- if (size === 0) {
54
- return null;
55
- }
56
- return arr[0];
57
- };
58
- const enqueue = item => {
59
- arr[size++] = item;
60
- let i = size - 1;
61
- let p = parent(i);
62
- while (i > 0 && compare(arr[p], arr[i]) > 0) {
63
- swap(p, i);
64
- i = p;
65
- p = parent(i);
66
- }
67
- };
68
- const contains = item => {
69
- const index = arr.indexOf(item);
70
- return index >= 0 && index < size;
71
- };
72
- const remove = item => {
73
- const i = arr.indexOf(item);
74
- if (i === -1 || i >= size) {
75
- return;
76
- }
77
- arr[i] = arr[--size];
78
- heapify(i);
79
- };
80
- const clear = () => {
81
- size = 0;
82
- };
83
- const all = () => {
84
- return arr.slice(0, size);
85
- };
86
- return {
87
- all,
88
- clear,
89
- contains,
90
- dequeue,
91
- enqueue,
92
- peek,
93
- remove,
94
- size: () => size
95
- };
96
- }
97
- exports.createPriorityQueue = createPriorityQueue;
13
+ const arr = [];
14
+ let size = 0;
15
+ const left = (i)=>{
16
+ return 2 * i + 1;
17
+ };
18
+ const right = (i)=>{
19
+ return 2 * i + 2;
20
+ };
21
+ const parent = (i)=>{
22
+ return Math.floor((i - 1) / 2);
23
+ };
24
+ const swap = (a, b)=>{
25
+ const tmp = arr[a];
26
+ arr[a] = arr[b];
27
+ arr[b] = tmp;
28
+ };
29
+ const heapify = (i)=>{
30
+ let smallest = i;
31
+ const l = left(i);
32
+ const r = right(i);
33
+ if (l < size && compare(arr[l], arr[smallest]) < 0) {
34
+ smallest = l;
35
+ }
36
+ if (r < size && compare(arr[r], arr[smallest]) < 0) {
37
+ smallest = r;
38
+ }
39
+ if (smallest !== i) {
40
+ swap(smallest, i);
41
+ heapify(smallest);
42
+ }
43
+ };
44
+ const dequeue = ()=>{
45
+ if (size === 0) {
46
+ throw new Error('Priority queue empty');
47
+ }
48
+ const res = arr[0];
49
+ arr[0] = arr[--size];
50
+ heapify(0);
51
+ return res;
52
+ };
53
+ const peek = ()=>{
54
+ if (size === 0) {
55
+ return null;
56
+ }
57
+ return arr[0];
58
+ };
59
+ const enqueue = (item)=>{
60
+ arr[size++] = item;
61
+ let i = size - 1;
62
+ let p = parent(i);
63
+ while(i > 0 && compare(arr[p], arr[i]) > 0){
64
+ swap(p, i);
65
+ i = p;
66
+ p = parent(i);
67
+ }
68
+ };
69
+ const contains = (item)=>{
70
+ const index = arr.indexOf(item);
71
+ return index >= 0 && index < size;
72
+ };
73
+ const remove = (item)=>{
74
+ const i = arr.indexOf(item);
75
+ if (i === -1 || i >= size) {
76
+ return;
77
+ }
78
+ arr[i] = arr[--size];
79
+ heapify(i);
80
+ };
81
+ const clear = ()=>{
82
+ size = 0;
83
+ };
84
+ const all = ()=>{
85
+ return arr.slice(0, size);
86
+ };
87
+ return {
88
+ all,
89
+ clear,
90
+ contains,
91
+ dequeue,
92
+ enqueue,
93
+ peek,
94
+ remove,
95
+ size: ()=>size
96
+ };
97
+ } //# sourceMappingURL=priorityQueue.js.map
98
+
98
99
  //# sourceMappingURL=priorityQueue.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":";;;;;;AAaA;;;;AAIA,SAAgBA,mBA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C,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":"","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
+ {"version":3,"sources":["../lib/priorityQueue.js"],"sourcesContent":["/**\n * @param compare - comparison function for items\n * @returns Priority queue implemented with a min heap\n */export function createPriorityQueue(compare) {\n const arr = [];\n let size = 0;\n const left = i => {\n return 2 * i + 1;\n };\n const right = i => {\n return 2 * i + 2;\n };\n const parent = i => {\n return Math.floor((i - 1) / 2);\n };\n const swap = (a, b) => {\n const tmp = arr[a];\n arr[a] = arr[b];\n arr[b] = tmp;\n };\n const heapify = i => {\n let smallest = i;\n const l = left(i);\n const r = right(i);\n if (l < size && compare(arr[l], arr[smallest]) < 0) {\n smallest = l;\n }\n if (r < size && compare(arr[r], arr[smallest]) < 0) {\n smallest = r;\n }\n if (smallest !== i) {\n swap(smallest, i);\n heapify(smallest);\n }\n };\n const dequeue = () => {\n if (size === 0) {\n throw new Error('Priority queue empty');\n }\n const res = arr[0];\n arr[0] = arr[--size];\n heapify(0);\n return res;\n };\n const peek = () => {\n if (size === 0) {\n return null;\n }\n return arr[0];\n };\n const enqueue = item => {\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 const contains = item => {\n const index = arr.indexOf(item);\n return index >= 0 && index < size;\n };\n const remove = item => {\n const i = arr.indexOf(item);\n if (i === -1 || i >= size) {\n return;\n }\n arr[i] = arr[--size];\n heapify(i);\n };\n const clear = () => {\n size = 0;\n };\n const all = () => {\n return arr.slice(0, size);\n };\n return {\n all,\n clear,\n contains,\n dequeue,\n enqueue,\n peek,\n remove,\n size: () => size\n };\n}\n//# sourceMappingURL=priorityQueue.js.map"],"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"],"mappings":"AAAA;;;CAGC;;;;+BAAkBA;;aAAAA;;AAAT,SAASA,oBAAoBC,OAAO,EAAE;IAC9C,MAAMC,MAAM,EAAE;IACd,IAAIC,OAAO;IACX,MAAMC,OAAOC,CAAAA,IAAK;QAChB,OAAO,IAAIA,IAAI;IACjB;IACA,MAAMC,QAAQD,CAAAA,IAAK;QACjB,OAAO,IAAIA,IAAI;IACjB;IACA,MAAME,SAASF,CAAAA,IAAK;QAClB,OAAOG,KAAKC,KAAK,CAAC,AAACJ,CAAAA,IAAI,CAAA,IAAK;IAC9B;IACA,MAAMK,OAAO,CAACC,GAAGC,IAAM;QACrB,MAAMC,MAAMX,GAAG,CAACS,EAAE;QAClBT,GAAG,CAACS,EAAE,GAAGT,GAAG,CAACU,EAAE;QACfV,GAAG,CAACU,EAAE,GAAGC;IACX;IACA,MAAMC,UAAUT,CAAAA,IAAK;QACnB,IAAIU,WAAWV;QACf,MAAMW,IAAIZ,KAAKC;QACf,MAAMY,IAAIX,MAA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AC,EAAEC,KAAK;QACpBW,QAAQT;IACV;IACA,MAAMwB,QAAQ,IAAM;QAClB1B,OAAO;IACT;IACA,MAAM2B,MAAM,IAAM;QAChB,OAAO5B,IAAI6B,KAAK,CAAC,GAAG5B;IACtB;IACA,OAAO;QACL2B;QACAD;QACAJ;QACAP;QACAI;QACAD;QACAO;QACAzB,MAAM,IAAMA;IACd;AACF,EACA,yCAAyC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
-
3
2
  Object.defineProperty(exports, "__esModule", {
4
- value: true
3
+ value: true
5
4
  });
5
+ //# sourceMappingURL=types.js.map
6
+
6
7
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"mappings":"","names":[],"sourceRoot":"","sources":[],"sourcesContent":[]}
1
+ {"version":3,"sources":["../lib/types.js"],"sourcesContent":["export {};\n//# sourceMappingURL=types.js.map"],"names":[],"mappings":";;;;CACA,iCAAiC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluentui/priority-overflow",
3
- "version": "0.0.0-nightly-20230223-0420.1",
3
+ "version": "0.0.0-nightly-20230223-2115.1",
4
4
  "description": "Vanilla JS utilities to implement overflow menus",
5
5
  "main": "lib-commonjs/index.js",
6
6
  "module": "lib/index.js",
@@ -20,7 +20,7 @@
20
20
  "lint": "just-scripts lint",
21
21
  "test": "jest --passWithNoTests",
22
22
  "type-check": "tsc -b tsconfig.json",
23
- "generate-api": "tsc -p ./tsconfig.lib.json --emitDeclarationOnly && just-scripts api-extractor"
23
+ "generate-api": "just-scripts generate-api"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@fluentui/eslint-plugin": "*",
@@ -28,7 +28,7 @@
28
28
  "@fluentui/scripts-tasks": "*"
29
29
  },
30
30
  "dependencies": {
31
- "tslib": "^2.1.0"
31
+ "@swc/helpers": "^0.4.14"
32
32
  },
33
33
  "beachball": {},
34
34
  "exports": {