@fluentui/priority-overflow 9.0.1 → 9.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,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,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,CAAC,CAAC;IAElB,IAAIW,CAAC,GAAGb,IAAI,IAAIF,OAA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GmB,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
+ {"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,I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AE,IAAI,EAAG;YAC3CK,KAAKc,GAAGnB;YACRA,IAAImB;YACJA,IAAIjB,OAAOF;QACb;IACF;IACA,MAAMoB,WAAWF,CAAAA,OAAQ;QACvB,MAAMG,QAAQxB,IAAIyB,OAAO,CAACJ;QAC1B,OAAOG,SAAS,KAAKA,QAAQvB;IAC/B;IACA,MAAMyB,SAASL,CAAAA,OAAQ;QACrB,MAAMlB,IAAIH,IAAIyB,OAAO,CAACJ;QACtB,IAAIlB,MAAM,CAAC,KAAKA,KAAKF,MAAM;YACzB;QACF,CAAC;QACDD,GAAG,CAACG,EAAE,GAAGH,GAAG,CAAC,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":"../src/","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": "9.0.1",
3
+ "version": "9.0.2",
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
  "disallowedChangeTypes": [
@@ -39,6 +39,7 @@
39
39
  "exports": {
40
40
  ".": {
41
41
  "types": "./dist/index.d.ts",
42
+ "node": "./lib-commonjs/index.js",
42
43
  "import": "./lib/index.js",
43
44
  "require": "./lib-commonjs/index.js"
44
45
  },
@@ -1,27 +0,0 @@
1
- define(["require", "exports"], function (require, exports) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.debounce = void 0;
5
- /**
6
- * Microtask debouncer
7
- * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide
8
- * @param fn - Function to debounce
9
- * @returns debounced function
10
- */
11
- function debounce(fn) {
12
- var pending;
13
- return function () {
14
- if (!pending) {
15
- pending = true;
16
- queueMicrotask(function () {
17
- // Need to set pending to `false` before the debounced function is run.
18
- // React can actually interrupt the function while it's running!
19
- pending = false;
20
- fn();
21
- });
22
- }
23
- };
24
- }
25
- exports.debounce = debounce;
26
- });
27
- //# sourceMappingURL=debounce.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debounce.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/debounce.ts"],"names":[],"mappings":";;;;IAAA;;;;;OAKG;IACH,SAAgB,QAAQ,CAAC,EAAY;QACnC,IAAI,OAAgB,CAAC;QACrB,OAAO;YACL,IAAI,CAAC,OAAO,EAAE;gBACZ,OAAO,GAAG,IAAI,CAAC;gBACf,cAAc,CAAC;oBACb,uEAAuE;oBACvE,gEAAgE;oBAChE,OAAO,GAAG,KAAK,CAAC;oBAChB,EAAE,EAAE,CAAC;gBACP,CAAC,CAAC,CAAC;aACJ;QACH,CAAC,CAAC;IACJ,CAAC;IAbD,4BAaC","sourcesContent":["/**\n * Microtask debouncer\n * https://developer.mozilla.org/en-US/docs/Web/API/HTML_DOM_API/Microtask_guide\n * @param fn - Function to debounce\n * @returns debounced function\n */\nexport function debounce(fn: Function) {\n let pending: boolean;\n return () => {\n if (!pending) {\n pending = true;\n queueMicrotask(() => {\n // Need to set pending to `false` before the debounced function is run.\n // React can actually interrupt the function while it's running!\n pending = false;\n fn();\n });\n }\n };\n}\n"]}
package/lib-amd/index.js DELETED
@@ -1,7 +0,0 @@
1
- define(["require", "exports", "./overflowManager"], function (require, exports, overflowManager_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createOverflowManager = void 0;
5
- Object.defineProperty(exports, "createOverflowManager", { enumerable: true, get: function () { return overflowManager_1.createOverflowManager; } });
6
- });
7
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/index.ts"],"names":[],"mappings":";;;;IAAS,wHAAA,qBAAqB,OAAA","sourcesContent":["export { createOverflowManager } from './overflowManager';\nexport type {\n ObserveOptions,\n OnUpdateItemVisibility,\n OnUpdateItemVisibilityPayload,\n OnUpdateOverflow,\n OverflowAxis,\n OverflowDirection,\n OverflowEventPayload,\n OverflowGroupState,\n OverflowItemEntry,\n OverflowManager,\n} from './types';\n"]}
@@ -1,216 +0,0 @@
1
- define(["require", "exports", "./debounce", "./priorityQueue"], function (require, exports, debounce_1, priorityQueue_1) {
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.createOverflowManager = void 0;
5
- /**
6
- * @internal
7
- * @returns overflow manager instance
8
- */
9
- function createOverflowManager() {
10
- var container;
11
- var overflowMenu;
12
- // Set as true when resize observer is observing
13
- var observing = false;
14
- // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change
15
- var forceDispatch = false;
16
- var options = {
17
- padding: 10,
18
- overflowAxis: 'horizontal',
19
- overflowDirection: 'end',
20
- minimumVisible: 0,
21
- onUpdateItemVisibility: function () { return undefined; },
22
- onUpdateOverflow: function () { return undefined; },
23
- };
24
- var overflowItems = {};
25
- var overflowGroups = {};
26
- var resizeObserver = new ResizeObserver(function (entries) {
27
- if (!entries[0] || !container) {
28
- return;
29
- }
30
- update();
31
- });
32
- var invisibleItemQueue = priorityQueue_1.createPriorityQueue(function (a, b) {
33
- var itemA = overflowItems[a];
34
- var itemB = overflowItems[b];
35
- // Higher priority at the top of the queue
36
- var priority = itemB.priority - itemA.priority;
37
- if (priority !== 0) {
38
- return priority;
39
- }
40
- var positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;
41
- // equal priority, use DOM order
42
- // eslint-disable-next-line no-bitwise
43
- return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
44
- });
45
- var visibleItemQueue = priorityQueue_1.createPriorityQueue(function (a, b) {
46
- var itemA = overflowItems[a];
47
- var itemB = overflowItems[b];
48
- // Lower priority at the top of the queue
49
- var priority = itemA.priority - itemB.priority;
50
- if (priority !== 0) {
51
- return priority;
52
- }
53
- var positionStatusBit = options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
54
- // equal priority, use DOM order
55
- // eslint-disable-next-line no-bitwise
56
- return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;
57
- });
58
- var getOffsetSize = function (el) {
59
- return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;
60
- };
61
- var makeItemVisible = function () {
62
- var nextVisible = invisibleItemQueue.dequeue();
63
- visibleItemQueue.enqueue(nextVisible);
64
- var item = overflowItems[nextVisible];
65
- options.onUpdateItemVisibility({ item: item, visible: true });
66
- if (item.groupId) {
67
- overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
68
- overflowGroups[item.groupId].visibleItemIds.add(item.id);
69
- }
70
- return getOffsetSize(item.element);
71
- };
72
- var makeItemInvisible = function () {
73
- var nextInvisible = visibleItemQueue.dequeue();
74
- invisibleItemQueue.enqueue(nextInvisible);
75
- var item = overflowItems[nextInvisible];
76
- var width = getOffsetSize(item.element);
77
- options.onUpdateItemVisibility({ item: item, visible: false });
78
- if (item.groupId) {
79
- overflowGroups[item.groupId].visibleItemIds.delete(item.id);
80
- overflowGroups[item.groupId].invisibleItemIds.add(item.id);
81
- }
82
- return width;
83
- };
84
- var dispatchOverflowUpdate = function () {
85
- var visibleItemIds = visibleItemQueue.all();
86
- var invisibleItemIds = invisibleItemQueue.all();
87
- var visibleItems = visibleItemIds.map(function (itemId) { return overflowItems[itemId]; });
88
- var invisibleItems = invisibleItemIds.map(function (itemId) { return overflowItems[itemId]; });
89
- var groupVisibility = {};
90
- Object.entries(overflowGroups).forEach(function (_a) {
91
- var groupId = _a[0], groupState = _a[1];
92
- if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {
93
- groupVisibility[groupId] = 'overflow';
94
- }
95
- else if (groupState.visibleItemIds.size === 0) {
96
- groupVisibility[groupId] = 'hidden';
97
- }
98
- else {
99
- groupVisibility[groupId] = 'visible';
100
- }
101
- });
102
- options.onUpdateOverflow({ visibleItems: visibleItems, invisibleItems: invisibleItems, groupVisibility: groupVisibility });
103
- };
104
- var processOverflowItems = function () {
105
- if (!container) {
106
- return false;
107
- }
108
- var availableSize = getOffsetSize(container) - options.padding;
109
- var overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;
110
- // Snapshot of the visible/invisible state to compare for updates
111
- var visibleTop = visibleItemQueue.peek();
112
- var invisibleTop = invisibleItemQueue.peek();
113
- var visibleItemIds = visibleItemQueue.all();
114
- var currentWidth = visibleItemIds.reduce(function (sum, visibleItemId) {
115
- var child = overflowItems[visibleItemId].element;
116
- return sum + getOffsetSize(child);
117
- }, 0);
118
- // Add items until available width is filled - can result in overflow
119
- while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {
120
- currentWidth += makeItemVisible();
121
- }
122
- // Remove items until there's no more overflow
123
- while (currentWidth > availableSize && visibleItemQueue.size() > 0) {
124
- if (visibleItemQueue.size() <= options.minimumVisible) {
125
- break;
126
- }
127
- currentWidth -= makeItemInvisible();
128
- }
129
- // make sure the overflow menu can fit
130
- if (visibleItemQueue.size() > options.minimumVisible &&
131
- invisibleItemQueue.size() > 0 &&
132
- currentWidth + overflowMenuOffset > availableSize) {
133
- makeItemInvisible();
134
- }
135
- // only update when the state of visible/invisible items has changed
136
- if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {
137
- return true;
138
- }
139
- return false;
140
- };
141
- var forceUpdate = function () {
142
- if (processOverflowItems() || forceDispatch) {
143
- forceDispatch = false;
144
- dispatchOverflowUpdate();
145
- }
146
- };
147
- var update = debounce_1.debounce(forceUpdate);
148
- var observe = function (observedContainer, userOptions) {
149
- Object.assign(options, userOptions);
150
- observing = true;
151
- Object.values(overflowItems).forEach(function (item) { return visibleItemQueue.enqueue(item.id); });
152
- container = observedContainer;
153
- resizeObserver.observe(container);
154
- };
155
- var disconnect = function () {
156
- observing = false;
157
- resizeObserver.disconnect();
158
- };
159
- var addItem = function (item) {
160
- if (overflowItems[item.id]) {
161
- return;
162
- }
163
- overflowItems[item.id] = item;
164
- // some options can affect priority which are only set on `observe`
165
- if (observing) {
166
- // Updates to elements might not change the queue tops
167
- // i.e. new element is enqueued but the top of the queue stays the same
168
- // force a dispatch on the next batched update
169
- forceDispatch = true;
170
- visibleItemQueue.enqueue(item.id);
171
- }
172
- if (item.groupId) {
173
- if (!overflowGroups[item.groupId]) {
174
- overflowGroups[item.groupId] = {
175
- visibleItemIds: new Set(),
176
- invisibleItemIds: new Set(),
177
- };
178
- }
179
- overflowGroups[item.groupId].visibleItemIds.add(item.id);
180
- }
181
- update();
182
- };
183
- var addOverflowMenu = function (el) {
184
- overflowMenu = el;
185
- };
186
- var removeOverflowMenu = function () {
187
- overflowMenu = undefined;
188
- };
189
- var removeItem = function (itemId) {
190
- if (!overflowItems[itemId]) {
191
- return;
192
- }
193
- var item = overflowItems[itemId];
194
- visibleItemQueue.remove(itemId);
195
- invisibleItemQueue.remove(itemId);
196
- if (item.groupId) {
197
- overflowGroups[item.groupId].visibleItemIds.delete(item.id);
198
- overflowGroups[item.groupId].invisibleItemIds.delete(item.id);
199
- }
200
- delete overflowItems[itemId];
201
- update();
202
- };
203
- return {
204
- addItem: addItem,
205
- disconnect: disconnect,
206
- forceUpdate: forceUpdate,
207
- observe: observe,
208
- removeItem: removeItem,
209
- update: update,
210
- addOverflowMenu: addOverflowMenu,
211
- removeOverflowMenu: removeOverflowMenu,
212
- };
213
- }
214
- exports.createOverflowManager = createOverflowManager;
215
- });
216
- //# sourceMappingURL=overflowManager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"overflowManager.js","sourceRoot":"","sources":["../../../../../../../packages/react-components/priority-overflow/src/overflowManager.ts"],"names":[],"mappings":";;;;IAIA;;;OAGG;IACH,SAAgB,qBAAqB;QACnC,IAAI,SAAkC,CAAC;QACvC,IAAI,YAAqC,CAAC;QAC1C,gDAAgD;QAChD,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,+FAA+F;QAC/F,IAAI,aAAa,GAAG,KAAK,CAAC;QAC1B,IAAM,OAAO,GAA6B;YACxC,OAAO,EAAE,EAAE;YACX,YAAY,EAAE,YAAY;YAC1B,iBAAiB,EAAE,KAAK;YACxB,cAAc,EAAE,CAAC;YACjB,sBAAsB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;YACvC,gBAAgB,EAAE,cAAM,OAAA,SAAS,EAAT,CAAS;SAClC,CAAC;QAEF,IAAM,aAAa,GAAsC,EAAE,CAAC;QAC5D,IAAM,cAAc,GAAmF,EAAE,CAAC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AAI,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAC5D,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAC/D;YAED,OAAO,aAAa,CAAC,MAAM,CAAC,CAAC;YAC7B,MAAM,EAAE,CAAC;QACX,CAAC,CAAC;QAEF,OAAO;YACL,OAAO,SAAA;YACP,UAAU,YAAA;YACV,WAAW,aAAA;YACX,OAAO,SAAA;YACP,UAAU,YAAA;YACV,MAAM,QAAA;YACN,eAAe,iBAAA;YACf,kBAAkB,oBAAA;SACnB,CAAC;IACJ,CAAC;IA5PD,sDA4PC","sourcesContent":["import { debounce } from './debounce';\nimport { createPriorityQueue } from './priorityQueue';\nimport type { OverflowGroupState, OverflowItemEntry, OverflowManager, ObserveOptions } from './types';\n\n/**\n * @internal\n * @returns overflow manager instance\n */\nexport function createOverflowManager(): OverflowManager {\n let container: HTMLElement | undefined;\n let overflowMenu: HTMLElement | undefined;\n // Set as true when resize observer is observing\n let observing = false;\n // If true, next update will dispatch to onUpdateOverflow even if queue top states don't change\n let forceDispatch = false;\n const options: Required<ObserveOptions> = {\n padding: 10,\n overflowAxis: 'horizontal',\n overflowDirection: 'end',\n minimumVisible: 0,\n onUpdateItemVisibility: () => undefined,\n onUpdateOverflow: () => undefined,\n };\n\n const overflowItems: Record<string, OverflowItemEntry> = {};\n const overflowGroups: Record<string, { visibleItemIds: Set<string>; invisibleItemIds: Set<string> }> = {};\n const resizeObserver = new ResizeObserver(entries => {\n if (!entries[0] || !container) {\n return;\n }\n\n update();\n });\n\n const invisibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Higher priority at the top of the queue\n const priority = itemB.priority - itemA.priority;\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_FOLLOWING : Node.DOCUMENT_POSITION_PRECEDING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const visibleItemQueue = createPriorityQueue<string>((a, b) => {\n const itemA = overflowItems[a];\n const itemB = overflowItems[b];\n // Lower priority at the top of the queue\n const priority = itemA.priority - itemB.priority;\n\n if (priority !== 0) {\n return priority;\n }\n\n const positionStatusBit =\n options.overflowDirection === 'end' ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;\n\n // equal priority, use DOM order\n // eslint-disable-next-line no-bitwise\n return itemA.element.compareDocumentPosition(itemB.element) & positionStatusBit ? -1 : 1;\n });\n\n const getOffsetSize = (el: HTMLElement) => {\n return options.overflowAxis === 'horizontal' ? el.offsetWidth : el.offsetHeight;\n };\n\n const makeItemVisible = () => {\n const nextVisible = invisibleItemQueue.dequeue();\n visibleItemQueue.enqueue(nextVisible);\n\n const item = overflowItems[nextVisible];\n options.onUpdateItemVisibility({ item, visible: true });\n if (item.groupId) {\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n return getOffsetSize(item.element);\n };\n\n const makeItemInvisible = () => {\n const nextInvisible = visibleItemQueue.dequeue();\n invisibleItemQueue.enqueue(nextInvisible);\n\n const item = overflowItems[nextInvisible];\n const width = getOffsetSize(item.element);\n options.onUpdateItemVisibility({ item, visible: false });\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.add(item.id);\n }\n\n return width;\n };\n\n const dispatchOverflowUpdate = () => {\n const visibleItemIds = visibleItemQueue.all();\n const invisibleItemIds = invisibleItemQueue.all();\n\n const visibleItems = visibleItemIds.map(itemId => overflowItems[itemId]);\n const invisibleItems = invisibleItemIds.map(itemId => overflowItems[itemId]);\n\n const groupVisibility: Record<string, OverflowGroupState> = {};\n Object.entries(overflowGroups).forEach(([groupId, groupState]) => {\n if (groupState.invisibleItemIds.size && groupState.visibleItemIds.size) {\n groupVisibility[groupId] = 'overflow';\n } else if (groupState.visibleItemIds.size === 0) {\n groupVisibility[groupId] = 'hidden';\n } else {\n groupVisibility[groupId] = 'visible';\n }\n });\n\n options.onUpdateOverflow({ visibleItems, invisibleItems, groupVisibility });\n };\n\n const processOverflowItems = (): boolean => {\n if (!container) {\n return false;\n }\n\n const availableSize = getOffsetSize(container) - options.padding;\n const overflowMenuOffset = overflowMenu ? getOffsetSize(overflowMenu) : 0;\n\n // Snapshot of the visible/invisible state to compare for updates\n const visibleTop = visibleItemQueue.peek();\n const invisibleTop = invisibleItemQueue.peek();\n\n const visibleItemIds = visibleItemQueue.all();\n let currentWidth = visibleItemIds.reduce((sum, visibleItemId) => {\n const child = overflowItems[visibleItemId].element;\n return sum + getOffsetSize(child);\n }, 0);\n\n // Add items until available width is filled - can result in overflow\n while (currentWidth < availableSize && invisibleItemQueue.size() > 0) {\n currentWidth += makeItemVisible();\n }\n\n // Remove items until there's no more overflow\n while (currentWidth > availableSize && visibleItemQueue.size() > 0) {\n if (visibleItemQueue.size() <= options.minimumVisible) {\n break;\n }\n currentWidth -= makeItemInvisible();\n }\n\n // make sure the overflow menu can fit\n if (\n visibleItemQueue.size() > options.minimumVisible &&\n invisibleItemQueue.size() > 0 &&\n currentWidth + overflowMenuOffset > availableSize\n ) {\n makeItemInvisible();\n }\n\n // only update when the state of visible/invisible items has changed\n if (visibleItemQueue.peek() !== visibleTop || invisibleItemQueue.peek() !== invisibleTop) {\n return true;\n }\n\n return false;\n };\n\n const forceUpdate: OverflowManager['forceUpdate'] = () => {\n if (processOverflowItems() || forceDispatch) {\n forceDispatch = false;\n dispatchOverflowUpdate();\n }\n };\n\n const update: OverflowManager['update'] = debounce(forceUpdate);\n\n const observe: OverflowManager['observe'] = (observedContainer, userOptions) => {\n Object.assign(options, userOptions);\n observing = true;\n Object.values(overflowItems).forEach(item => visibleItemQueue.enqueue(item.id));\n\n container = observedContainer;\n resizeObserver.observe(container);\n };\n\n const disconnect: OverflowManager['disconnect'] = () => {\n observing = false;\n resizeObserver.disconnect();\n };\n\n const addItem: OverflowManager['addItem'] = item => {\n if (overflowItems[item.id]) {\n return;\n }\n\n overflowItems[item.id] = item;\n\n // some options can affect priority which are only set on `observe`\n if (observing) {\n // Updates to elements might not change the queue tops\n // i.e. new element is enqueued but the top of the queue stays the same\n // force a dispatch on the next batched update\n forceDispatch = true;\n visibleItemQueue.enqueue(item.id);\n }\n\n if (item.groupId) {\n if (!overflowGroups[item.groupId]) {\n overflowGroups[item.groupId] = {\n visibleItemIds: new Set<string>(),\n invisibleItemIds: new Set<string>(),\n };\n }\n\n overflowGroups[item.groupId].visibleItemIds.add(item.id);\n }\n\n update();\n };\n\n const addOverflowMenu: OverflowManager['addOverflowMenu'] = el => {\n overflowMenu = el;\n };\n\n const removeOverflowMenu: OverflowManager['removeOverflowMenu'] = () => {\n overflowMenu = undefined;\n };\n\n const removeItem: OverflowManager['removeItem'] = itemId => {\n if (!overflowItems[itemId]) {\n return;\n }\n\n const item = overflowItems[itemId];\n visibleItemQueue.remove(itemId);\n invisibleItemQueue.remove(itemId);\n\n if (item.groupId) {\n overflowGroups[item.groupId].visibleItemIds.delete(item.id);\n overflowGroups[item.groupId].invisibleItemIds.delete(item.id);\n }\n\n delete overflowItems[itemId];\n update();\n };\n\n return {\n addItem,\n disconnect,\n forceUpdate,\n observe,\n removeItem,\n update,\n addOverflowMenu,\n removeOverflowMenu,\n };\n}\n"]}