@eclipse-glsp/protocol 2.7.0-next.19 → 2.7.0-next.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/array-util.d.ts +1 -0
- package/lib/utils/array-util.d.ts.map +1 -1
- package/lib/utils/array-util.js +18 -0
- package/lib/utils/array-util.js.map +1 -1
- package/lib/utils/function-util.d.ts +34 -0
- package/lib/utils/function-util.d.ts.map +1 -0
- package/lib/utils/function-util.js +61 -0
- package/lib/utils/function-util.js.map +1 -0
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/utils/array-util.spec.ts +205 -0
- package/src/utils/array-util.ts +17 -0
- package/src/utils/function-util.spec.ts +109 -0
- package/src/utils/function-util.ts +81 -0
package/lib/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export * from './sprotty-geometry-point';
|
|
|
54
54
|
export * from './utils/array-util';
|
|
55
55
|
export * from './utils/disposable';
|
|
56
56
|
export * from './utils/event';
|
|
57
|
+
export * from './utils/function-util';
|
|
57
58
|
export * from './utils/geometry-movement';
|
|
58
59
|
export * from './utils/geometry-util';
|
|
59
60
|
export * from './utils/geometry-vector';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC;AACtD,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAA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;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,qCAAqC,CAAC;AACpD,cAAc,wCAAwC,CAAC;AACvD,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC;AACrD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yBAAyB,CAAC;AACxC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC;AACrD,cAAc,2DAA2D,CAAC;AAC1E,cAAc,sDAAsD,CAAC;AACrE,cAAc,sDAAsD,CAAC;AACrE,cAAc,uDAAuD,CAAC;AACtE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,yDAAyD,CAAC;AACxE,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -70,6 +70,7 @@ __exportStar(require("./sprotty-geometry-point"), exports);
|
|
|
70
70
|
__exportStar(require("./utils/array-util"), exports);
|
|
71
71
|
__exportStar(require("./utils/disposable"), exports);
|
|
72
72
|
__exportStar(require("./utils/event"), exports);
|
|
73
|
+
__exportStar(require("./utils/function-util"), exports);
|
|
73
74
|
__exportStar(require("./utils/geometry-movement"), exports);
|
|
74
75
|
__exportStar(require("./utils/geometry-util"), exports);
|
|
75
76
|
__exportStar(require("./utils/geometry-vector"), exports);
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,kEAAgD;AAChD,wEAAsD;AACtD,8DAA4C;AAC5C,6DAA2C;AAC3C,sEAAoD;AACpD,qEAAmD;AACnD,kEAAgD;AAChD,uEAAqD;AACrD,sEAAoD;AACpD,yEAAuD;AACvD,uEAAqD;AACrD,uEAAqD;AACrD,+DAA6C;AAC7C,oEAAkD;AAClD,iEAA+C;AAC/C,iEAA+C;AAC/C,sEAAoD;AACpD,iEAA+C;AAC/C,0DAAwC;AACxC,8DAA4C;AAC5C,6DAA2C;AAC3C,4EAA0D;AAC1D,uEAAqD;AACrD,uEAAqD;AACrD,4FAA0E;AAC1E,uFAAqE;AACrE,uFAAqE;AACrE,wFAAsE;AACtE,8FAA4E;AAC5E,0FAAwE;AACxE,iEAA+C;AAC/C,wDAAsC;AACtC,uDAAqC;AACrC,+CAA6B;AAC7B,oDAAkC;AAClC,4DAA0C;AAC1C,+DAA6C;AAC7C,2DAAyC;AACzC,qDAAmC;AACnC,qDAAmC;AACnC,gDAA8B;AAC9B,4DAA0C;AAC1C,wDAAsC;AACtC,0DAAwC;AACxC,oDAAkC;AAClC,oDAAkC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,kEAAgD;AAChD,wEAAsD;AACtD,8DAA4C;AAC5C,6DAA2C;AAC3C,sEAAoD;AACpD,qEAAmD;AACnD,kEAAgD;AAChD,uEAAqD;AACrD,sEAAoD;AACpD,yEAAuD;AACvD,uEAAqD;AACrD,uEAAqD;AACrD,+DAA6C;AAC7C,oEAAkD;AAClD,iEAA+C;AAC/C,iEAA+C;AAC/C,sEAAoD;AACpD,iEAA+C;AAC/C,0DAAwC;AACxC,8DAA4C;AAC5C,6DAA2C;AAC3C,4EAA0D;AAC1D,uEAAqD;AACrD,uEAAqD;AACrD,4FAA0E;AAC1E,uFAAqE;AACrE,uFAAqE;AACrE,wFAAsE;AACtE,8FAA4E;AAC5E,0FAAwE;AACxE,iEAA+C;AAC/C,wDAAsC;AACtC,uDAAqC;AACrC,+CAA6B;AAC7B,oDAAkC;AAClC,4DAA0C;AAC1C,+DAA6C;AAC7C,2DAAyC;AACzC,qDAAmC;AACnC,qDAAmC;AACnC,gDAA8B;AAC9B,wDAAsC;AACtC,4DAA0C;AAC1C,wDAAsC;AACtC,0DAAwC;AACxC,oDAAkC;AAClC,oDAAkC"}
|
|
@@ -131,4 +131,5 @@ export declare function partition<T>(source: T[], matchGuard: TypeGuard<T>): {
|
|
|
131
131
|
* @returns The array of values without any undefined values.
|
|
132
132
|
*/
|
|
133
133
|
export declare function arrayOf<T>(...values: (T | undefined)[]): T[];
|
|
134
|
+
export declare function groupBy<T, K>(array: T[], keyFn: (item: T) => K, sorted?: boolean): Map<K, T[]>;
|
|
134
135
|
//# sourceMappingURL=array-util.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-util.d.ts","sourceRoot":"","sources":["../../src/utils/array-util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEhE;;GAEG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AAEpC;;;;GAIG;AACH,wBA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AE,MAAM,CAAC,EAAE,OAAO,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAe9F"}
|
package/lib/utils/array-util.js
CHANGED
|
@@ -29,6 +29,7 @@ exports.isStringArray = isStringArray;
|
|
|
29
29
|
exports.isArrayMatching = isArrayMatching;
|
|
30
30
|
exports.partition = partition;
|
|
31
31
|
exports.arrayOf = arrayOf;
|
|
32
|
+
exports.groupBy = groupBy;
|
|
32
33
|
function first(array, n) {
|
|
33
34
|
if (n) {
|
|
34
35
|
return array.filter((_, index) => index < n);
|
|
@@ -171,4 +172,21 @@ function partition(source, matchGuard) {
|
|
|
171
172
|
function arrayOf(...values) {
|
|
172
173
|
return values.filter(element => element !== undefined);
|
|
173
174
|
}
|
|
175
|
+
function groupBy(array, keyFn, sorted) {
|
|
176
|
+
const grouped = new Map();
|
|
177
|
+
for (const item of array) {
|
|
178
|
+
const key = keyFn(item);
|
|
179
|
+
const values = grouped.get(key);
|
|
180
|
+
if (values) {
|
|
181
|
+
values.push(item);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
grouped.set(key, [item]);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (sorted) {
|
|
188
|
+
return new Map([...grouped.entries()].sort());
|
|
189
|
+
}
|
|
190
|
+
return grouped;
|
|
191
|
+
}
|
|
174
192
|
//# sourceMappingURL=array-util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array-util.js","sourceRoot":"","sources":["../../src/utils/array-util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAuBlF,sBAKC;AAgBD,oBAKC;AAQD,sBAEC;AAOD,wBAOC;AASD,4BAEC;AAOD,0BAKC;AAOD,kCAMC;AAUD,sCAEC;AAUD,wCAEC;AAUD,gDAEC;AASD,sCAEC;AASD,0CAEC;AAED,8BAWC;AAOD,0BAEC;
|
|
1
|
+
{"version":3,"file":"array-util.js","sourceRoot":"","sources":["../../src/utils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AU,EAAE,KAAqB,EAAE,MAAgB;IAC7E,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAChC,IAAI,MAAM,EAAE,CAAC;YACT,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;QAC7B,CAAC;IACL,CAAC;IACD,IAAI,MAAM,EAAE,CAAC;QACT,OAAO,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
/**
|
|
17
|
+
* Minimal lodash-compatible debounce subset.
|
|
18
|
+
* Compared to `lodash.DebouncedFunc<T>`:
|
|
19
|
+
* - The debounced call returns `void` instead of `ReturnType<T> | undefined`.
|
|
20
|
+
* - `flush()`, `pending()`, and `maxWait` are not supported.
|
|
21
|
+
*/
|
|
22
|
+
export interface DebouncedFunc<T extends (...args: any[]) => any> {
|
|
23
|
+
(...args: Parameters<T>): void;
|
|
24
|
+
cancel(): void;
|
|
25
|
+
}
|
|
26
|
+
export interface DebounceSettings {
|
|
27
|
+
leading?: boolean;
|
|
28
|
+
trailing?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Minimal lodash-compatible debounce. See {@link DebouncedFunc} for intentional differences from `lodash.debounce`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options?: DebounceSettings): DebouncedFunc<T>;
|
|
34
|
+
//# sourceMappingURL=function-util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-util.d.ts","sourceRoot":"","sources":["../../src/utils/function-util.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF;;;;;GAKG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG;IAC5D,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAC/B,MAAM,IAAI,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,gBAAqB,GAAG,aAAa,CAAC,CAAC,CAAC,CA6CnI"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/********************************************************************************
|
|
3
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
4
|
+
*
|
|
5
|
+
* This program and the accompanying materials are made available under the
|
|
6
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
*
|
|
9
|
+
* This Source Code may also be made available under the following Secondary
|
|
10
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
* with the GNU Classpath Exception which is available at
|
|
13
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
*
|
|
15
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.debounce = debounce;
|
|
19
|
+
/**
|
|
20
|
+
* Minimal lodash-compatible debounce. See {@link DebouncedFunc} for intentional differences from `lodash.debounce`.
|
|
21
|
+
*/
|
|
22
|
+
function debounce(func, wait, options = {}) {
|
|
23
|
+
var _a, _b;
|
|
24
|
+
let timeout;
|
|
25
|
+
let lastArgs;
|
|
26
|
+
let lastThis;
|
|
27
|
+
let hasPendingCall = false;
|
|
28
|
+
const leading = (_a = options.leading) !== null && _a !== void 0 ? _a : false;
|
|
29
|
+
const trailing = (_b = options.trailing) !== null && _b !== void 0 ? _b : true;
|
|
30
|
+
const debounced = function (...args) {
|
|
31
|
+
const shouldCallLeading = leading && timeout === undefined;
|
|
32
|
+
lastArgs = args;
|
|
33
|
+
lastThis = this;
|
|
34
|
+
hasPendingCall = true;
|
|
35
|
+
if (shouldCallLeading) {
|
|
36
|
+
func.apply(lastThis, lastArgs);
|
|
37
|
+
hasPendingCall = false;
|
|
38
|
+
}
|
|
39
|
+
if (timeout !== undefined) {
|
|
40
|
+
clearTimeout(timeout);
|
|
41
|
+
}
|
|
42
|
+
timeout = setTimeout(() => {
|
|
43
|
+
timeout = undefined;
|
|
44
|
+
if (trailing && hasPendingCall && lastArgs !== undefined) {
|
|
45
|
+
func.apply(lastThis, lastArgs);
|
|
46
|
+
hasPendingCall = false;
|
|
47
|
+
}
|
|
48
|
+
}, wait);
|
|
49
|
+
};
|
|
50
|
+
debounced.cancel = () => {
|
|
51
|
+
if (timeout !== undefined) {
|
|
52
|
+
clearTimeout(timeout);
|
|
53
|
+
timeout = undefined;
|
|
54
|
+
}
|
|
55
|
+
lastArgs = undefined;
|
|
56
|
+
lastThis = undefined;
|
|
57
|
+
hasPendingCall = false;
|
|
58
|
+
};
|
|
59
|
+
return debounced;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=function-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"function-util.js","sourceRoot":"","sources":["../../src/utils/function-util.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;AAqBlF,4BA6CC;AAhDD;;GAEG;AACH,SAAgB,QAAQ,CAAoC,IAAO,EAAE,IAAY,EAAE,UAA4B,EAAE;;IAC7G,IAAI,OAAkD,CAAC;IACvD,IAAI,QAAmC,CAAC;IACxC,IAAI,QAA0C,CAAC;IAC/C,IAAI,cAAc,GAAG,KAAK,CAAC;IAE3B,MAAM,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,KAAK,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAA,OAAO,CAAC,QAAQ,mCAAI,IAAI,CAAC;IAE1C,MAAM,SAAS,GAAG,UAAsC,GAAG,IAAmB;QAC1E,MAAM,iBAAiB,GAAG,OAAO,IAAI,OAAO,KAAK,SAAS,CAAC;QAE3D,QAAQ,GAAG,IAAI,CAAC;QAChB,QAAQ,GAAG,IAAI,CAAC;QAChB,cAAc,GAAG,IAAI,CAAC;QAEtB,IAAI,iBAAiB,EAAE,CAAC;YACpB,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YAC/B,cAAc,GAAG,KAAK,CAAC;QAC3B,CAAC;QAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1B,CAAC;QAED,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACtB,OAAO,GAAG,SAAS,CAAC;YACpB,IAAI,QAAQ,IAAI,cAAc,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;gBACvD,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;gBAC/B,cAAc,GAAG,KAAK,CAAC;YAC3B,CAAC;QACL,CAAC,EAAE,IAAI,CAAC,CAAC;IACb,CAAqB,CAAC;IAEtB,SAAS,CAAC,MAAM,GAAG,GAAG,EAAE;QACpB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YACxB,YAAY,CAAC,OAAO,CAAC,CAAC;YACtB,OAAO,GAAG,SAAS,CAAC;QACxB,CAAC;QACD,QAAQ,GAAG,SAAS,CAAC;QACrB,QAAQ,GAAG,SAAS,CAAC;QACrB,cAAc,GAAG,KAAK,CAAC;IAC3B,CAAC,CAAC;IAEF,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eclipse-glsp/protocol",
|
|
3
|
-
"version": "2.7.0-next.
|
|
3
|
+
"version": "2.7.0-next.20+cb1a787",
|
|
4
4
|
"description": "The protocol definition for client-server communication in GLSP",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eclipse",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "cb1a787ae45d16094f0655021f3b8882531e0c8e"
|
|
62
62
|
}
|
package/src/index.ts
CHANGED
|
@@ -54,6 +54,7 @@ export * from './sprotty-geometry-point';
|
|
|
54
54
|
export * from './utils/array-util';
|
|
55
55
|
export * from './utils/disposable';
|
|
56
56
|
export * from './utils/event';
|
|
57
|
+
export * from './utils/function-util';
|
|
57
58
|
export * from './utils/geometry-movement';
|
|
58
59
|
export * from './utils/geometry-util';
|
|
59
60
|
export * from './utils/geometry-vector';
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { TypeGuard } from './type-util';
|
|
19
|
+
import {
|
|
20
|
+
arrayOf,
|
|
21
|
+
asArray,
|
|
22
|
+
distinctAdd,
|
|
23
|
+
first,
|
|
24
|
+
flatPush,
|
|
25
|
+
groupBy,
|
|
26
|
+
isArrayOfClass,
|
|
27
|
+
isArrayOfType,
|
|
28
|
+
isStringArray,
|
|
29
|
+
last,
|
|
30
|
+
partition,
|
|
31
|
+
pluck,
|
|
32
|
+
remove
|
|
33
|
+
} from './array-util';
|
|
34
|
+
|
|
35
|
+
describe('ArrayUtil', () => {
|
|
36
|
+
describe('remove', () => {
|
|
37
|
+
it('should remove a present value and leave others intact', () => {
|
|
38
|
+
const arr = [1, 2, 3, 4];
|
|
39
|
+
remove(arr, 2, 4);
|
|
40
|
+
expect(arr).to.deep.equal([1, 3]);
|
|
41
|
+
});
|
|
42
|
+
it('should only remove the first occurrence', () => {
|
|
43
|
+
const arr = [1, 2, 2, 3];
|
|
44
|
+
remove(arr, 2);
|
|
45
|
+
expect(arr).to.deep.equal([1, 2, 3]);
|
|
46
|
+
});
|
|
47
|
+
it('should do nothing for absent values', () => {
|
|
48
|
+
const arr = [1, 2];
|
|
49
|
+
remove(arr, 99);
|
|
50
|
+
expect(arr).to.deep.equal([1, 2]);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('flatPush', () => {
|
|
55
|
+
it('should push single values and nested arrays', () => {
|
|
56
|
+
const arr: number[] = [1];
|
|
57
|
+
flatPush(arr, [2, [3, 4], 5]);
|
|
58
|
+
expect(arr).to.deep.equal([1, 2, 3, 4, 5]);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('distinctAdd', () => {
|
|
63
|
+
it('should add only values not already present', () => {
|
|
64
|
+
const arr = [1, 2];
|
|
65
|
+
distinctAdd(arr, 2, 3, 4, 1);
|
|
66
|
+
expect(arr).to.deep.equal([1, 2, 3, 4]);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe('first', () => {
|
|
71
|
+
it('should return the first element without n', () => {
|
|
72
|
+
expect(first([10, 20, 30])).to.equal(10);
|
|
73
|
+
});
|
|
74
|
+
it('should return first n elements', () => {
|
|
75
|
+
expect(first([10, 20, 30], 2)).to.deep.equal([10, 20]);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('last', () => {
|
|
80
|
+
it('should return the last element without n', () => {
|
|
81
|
+
expect(last([10, 20, 30])).to.equal(30);
|
|
82
|
+
});
|
|
83
|
+
it('should return last n elements', () => {
|
|
84
|
+
expect(last([10, 20, 30], 2)).to.deep.equal([20, 30]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('pluck', () => {
|
|
89
|
+
it('should extract the given property from each element', () => {
|
|
90
|
+
const items = [
|
|
91
|
+
{ id: 1, name: 'a' },
|
|
92
|
+
{ id: 2, name: 'b' }
|
|
93
|
+
];
|
|
94
|
+
expect(pluck(items, 'name')).to.deep.equal(['a', 'b']);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('asArray', () => {
|
|
99
|
+
it('should wrap a single value in an array', () => {
|
|
100
|
+
expect(asArray(5)).to.deep.equal([5]);
|
|
101
|
+
});
|
|
102
|
+
it('should return the array as-is', () => {
|
|
103
|
+
const arr = [1, 2];
|
|
104
|
+
expect(asArray(arr)).to.equal(arr);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('isArrayOfType', () => {
|
|
109
|
+
const isNumber: TypeGuard<number> = (v: unknown): v is number => typeof v === 'number';
|
|
110
|
+
|
|
111
|
+
it('should return true for a matching array', () => {
|
|
112
|
+
expect(isArrayOfType([1, 2, 3], isNumber)).to.be.true;
|
|
113
|
+
});
|
|
114
|
+
it('should return false for an empty array by default', () => {
|
|
115
|
+
expect(isArrayOfType([], isNumber)).to.be.false;
|
|
116
|
+
});
|
|
117
|
+
it('should return true for an empty array with supportEmpty', () => {
|
|
118
|
+
expect(isArrayOfType([], isNumber, true)).to.be.true;
|
|
119
|
+
});
|
|
120
|
+
it('should return false for a mixed array', () => {
|
|
121
|
+
expect(isArrayOfType([1, 'two'], isNumber)).to.be.false;
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('isArrayOfClass', () => {
|
|
126
|
+
it('should return true when all elements are instances of the class', () => {
|
|
127
|
+
expect(isArrayOfClass([new Date(), new Date()], Date)).to.be.true;
|
|
128
|
+
});
|
|
129
|
+
it('should return false for non-instances', () => {
|
|
130
|
+
expect(isArrayOfClass([{}, new Date()], Date)).to.be.false;
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('isStringArray', () => {
|
|
135
|
+
it('should return true for a string array', () => {
|
|
136
|
+
expect(isStringArray(['a', 'b'])).to.be.true;
|
|
137
|
+
});
|
|
138
|
+
it('should return false for a mixed array', () => {
|
|
139
|
+
expect(isStringArray(['a', 1])).to.be.false;
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe('partition', () => {
|
|
144
|
+
const isString = (v: unknown): v is string => typeof v === 'string';
|
|
145
|
+
|
|
146
|
+
it('should split elements by predicate', () => {
|
|
147
|
+
const result = partition(['a', 1, 'b', 2] as (string | number)[], isString as TypeGuard<string | number>);
|
|
148
|
+
expect(result.match).to.deep.equal(['a', 'b']);
|
|
149
|
+
expect(result.rest).to.deep.equal([1, 2]);
|
|
150
|
+
});
|
|
151
|
+
it('should handle all-match case', () => {
|
|
152
|
+
const result = partition(['a', 'b'], isString as TypeGuard<string>);
|
|
153
|
+
expect(result.match).to.deep.equal(['a', 'b']);
|
|
154
|
+
expect(result.rest).to.deep.equal([]);
|
|
155
|
+
});
|
|
156
|
+
it('should handle empty array', () => {
|
|
157
|
+
const result = partition([], isString as TypeGuard<string>);
|
|
158
|
+
expect(result.match).to.deep.equal([]);
|
|
159
|
+
expect(result.rest).to.deep.equal([]);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('arrayOf', () => {
|
|
164
|
+
it('should filter out undefined values', () => {
|
|
165
|
+
expect(arrayOf(1, undefined, 2, undefined, 3)).to.deep.equal([1, 2, 3]);
|
|
166
|
+
});
|
|
167
|
+
it('should return empty array when all undefined', () => {
|
|
168
|
+
expect(arrayOf(undefined, undefined)).to.deep.equal([]);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe('groupBy', () => {
|
|
173
|
+
it('should group elements by the key function', () => {
|
|
174
|
+
const items = [
|
|
175
|
+
{ type: 'fruit', name: 'apple' },
|
|
176
|
+
{ type: 'veggie', name: 'carrot' },
|
|
177
|
+
{ type: 'fruit', name: 'banana' }
|
|
178
|
+
];
|
|
179
|
+
const result = groupBy(items, i => i.type);
|
|
180
|
+
expect(result.size).to.equal(2);
|
|
181
|
+
expect(result.get('fruit')!.map(i => i.name)).to.deep.equal(['apple', 'banana']);
|
|
182
|
+
expect(result.get('veggie')!.map(i => i.name)).to.deep.equal(['carrot']);
|
|
183
|
+
});
|
|
184
|
+
it('should return an empty map for an empty array', () => {
|
|
185
|
+
expect(groupBy([], () => 'k').size).to.equal(0);
|
|
186
|
+
});
|
|
187
|
+
it('should support numeric keys', () => {
|
|
188
|
+
const result = groupBy([1, 2, 3, 4, 5], n => n % 2);
|
|
189
|
+
expect(result.get(0)).to.deep.equal([2, 4]);
|
|
190
|
+
expect(result.get(1)).to.deep.equal([1, 3, 5]);
|
|
191
|
+
});
|
|
192
|
+
it('should sort groups by key when sorted is true', () => {
|
|
193
|
+
const items = [
|
|
194
|
+
{ rank: 3, name: 'c' },
|
|
195
|
+
{ rank: 1, name: 'a' },
|
|
196
|
+
{ rank: 2, name: 'b' },
|
|
197
|
+
{ rank: 1, name: 'a2' }
|
|
198
|
+
];
|
|
199
|
+
const result = groupBy(items, i => i.rank, true);
|
|
200
|
+
const keys = [...result.keys()];
|
|
201
|
+
expect(keys).to.deep.equal([1, 2, 3]);
|
|
202
|
+
expect(result.get(1)!.map(i => i.name)).to.deep.equal(['a', 'a2']);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
package/src/utils/array-util.ts
CHANGED
|
@@ -202,3 +202,20 @@ export function partition<T>(source: T[], matchGuard: TypeGuard<T>): { match: T[
|
|
|
202
202
|
export function arrayOf<T>(...values: (T | undefined)[]): T[] {
|
|
203
203
|
return values.filter(element => element !== undefined) as T[];
|
|
204
204
|
}
|
|
205
|
+
|
|
206
|
+
export function groupBy<T, K>(array: T[], keyFn: (item: T) => K, sorted?: boolean): Map<K, T[]> {
|
|
207
|
+
const grouped = new Map<K, T[]>();
|
|
208
|
+
for (const item of array) {
|
|
209
|
+
const key = keyFn(item);
|
|
210
|
+
const values = grouped.get(key);
|
|
211
|
+
if (values) {
|
|
212
|
+
values.push(item);
|
|
213
|
+
} else {
|
|
214
|
+
grouped.set(key, [item]);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (sorted) {
|
|
218
|
+
return new Map([...grouped.entries()].sort());
|
|
219
|
+
}
|
|
220
|
+
return grouped;
|
|
221
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import * as sinon from 'sinon';
|
|
19
|
+
import { debounce } from './function-util';
|
|
20
|
+
|
|
21
|
+
describe('FunctionUtil', () => {
|
|
22
|
+
let clock: sinon.SinonFakeTimers;
|
|
23
|
+
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
clock = sinon.useFakeTimers();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
clock.restore();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('debounce', () => {
|
|
33
|
+
it('should invoke the function after the wait period (trailing by default)', () => {
|
|
34
|
+
const spy = sinon.spy();
|
|
35
|
+
const debounced = debounce(spy, 100);
|
|
36
|
+
debounced();
|
|
37
|
+
expect(spy.called).to.be.false;
|
|
38
|
+
clock.tick(100);
|
|
39
|
+
expect(spy.calledOnce).to.be.true;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should reset the timer on rapid calls and only invoke once', () => {
|
|
43
|
+
const spy = sinon.spy();
|
|
44
|
+
const debounced = debounce(spy, 100);
|
|
45
|
+
debounced();
|
|
46
|
+
clock.tick(50);
|
|
47
|
+
debounced();
|
|
48
|
+
clock.tick(50);
|
|
49
|
+
expect(spy.called).to.be.false;
|
|
50
|
+
clock.tick(50);
|
|
51
|
+
expect(spy.calledOnce).to.be.true;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('should pass the latest arguments', () => {
|
|
55
|
+
const spy = sinon.spy();
|
|
56
|
+
const debounced = debounce(spy, 100);
|
|
57
|
+
debounced('a');
|
|
58
|
+
debounced('b');
|
|
59
|
+
clock.tick(100);
|
|
60
|
+
expect(spy.calledOnce).to.be.true;
|
|
61
|
+
expect(spy.firstCall.args).to.deep.equal(['b']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should invoke immediately with leading: true', () => {
|
|
65
|
+
const spy = sinon.spy();
|
|
66
|
+
const debounced = debounce(spy, 100, { leading: true });
|
|
67
|
+
debounced();
|
|
68
|
+
expect(spy.calledOnce).to.be.true;
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should not invoke trailing call when leading: true, trailing: false', () => {
|
|
72
|
+
const spy = sinon.spy();
|
|
73
|
+
const debounced = debounce(spy, 100, { leading: true, trailing: false });
|
|
74
|
+
debounced();
|
|
75
|
+
debounced();
|
|
76
|
+
expect(spy.calledOnce).to.be.true;
|
|
77
|
+
clock.tick(100);
|
|
78
|
+
expect(spy.calledOnce).to.be.true;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should invoke both leading and trailing when both are true', () => {
|
|
82
|
+
const spy = sinon.spy();
|
|
83
|
+
const debounced = debounce(spy, 100, { leading: true, trailing: true });
|
|
84
|
+
debounced('first');
|
|
85
|
+
expect(spy.calledOnce).to.be.true;
|
|
86
|
+
debounced('second');
|
|
87
|
+
clock.tick(100);
|
|
88
|
+
expect(spy.calledTwice).to.be.true;
|
|
89
|
+
expect(spy.secondCall.args).to.deep.equal(['second']);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('cancel', () => {
|
|
93
|
+
it('should prevent a pending trailing invocation', () => {
|
|
94
|
+
const spy = sinon.spy();
|
|
95
|
+
const debounced = debounce(spy, 100);
|
|
96
|
+
debounced();
|
|
97
|
+
debounced.cancel();
|
|
98
|
+
clock.tick(100);
|
|
99
|
+
expect(spy.called).to.be.false;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('should be safe to call when nothing is pending', () => {
|
|
103
|
+
const spy = sinon.spy();
|
|
104
|
+
const debounced = debounce(spy, 100);
|
|
105
|
+
expect(() => debounced.cancel()).to.not.throw();
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code may also be made available under the following Secondary
|
|
9
|
+
* Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
* with the GNU Classpath Exception which is available at
|
|
12
|
+
* https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
*
|
|
14
|
+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
|
|
15
|
+
********************************************************************************/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Minimal lodash-compatible debounce subset.
|
|
19
|
+
* Compared to `lodash.DebouncedFunc<T>`:
|
|
20
|
+
* - The debounced call returns `void` instead of `ReturnType<T> | undefined`.
|
|
21
|
+
* - `flush()`, `pending()`, and `maxWait` are not supported.
|
|
22
|
+
*/
|
|
23
|
+
export interface DebouncedFunc<T extends (...args: any[]) => any> {
|
|
24
|
+
(...args: Parameters<T>): void;
|
|
25
|
+
cancel(): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DebounceSettings {
|
|
29
|
+
leading?: boolean;
|
|
30
|
+
trailing?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Minimal lodash-compatible debounce. See {@link DebouncedFunc} for intentional differences from `lodash.debounce`.
|
|
35
|
+
*/
|
|
36
|
+
export function debounce<T extends (...args: any[]) => any>(func: T, wait: number, options: DebounceSettings = {}): DebouncedFunc<T> {
|
|
37
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
38
|
+
let lastArgs: Parameters<T> | undefined;
|
|
39
|
+
let lastThis: ThisParameterType<T> | undefined;
|
|
40
|
+
let hasPendingCall = false;
|
|
41
|
+
|
|
42
|
+
const leading = options.leading ?? false;
|
|
43
|
+
const trailing = options.trailing ?? true;
|
|
44
|
+
|
|
45
|
+
const debounced = function (this: ThisParameterType<T>, ...args: Parameters<T>): void {
|
|
46
|
+
const shouldCallLeading = leading && timeout === undefined;
|
|
47
|
+
|
|
48
|
+
lastArgs = args;
|
|
49
|
+
lastThis = this;
|
|
50
|
+
hasPendingCall = true;
|
|
51
|
+
|
|
52
|
+
if (shouldCallLeading) {
|
|
53
|
+
func.apply(lastThis, lastArgs);
|
|
54
|
+
hasPendingCall = false;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (timeout !== undefined) {
|
|
58
|
+
clearTimeout(timeout);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
timeout = setTimeout(() => {
|
|
62
|
+
timeout = undefined;
|
|
63
|
+
if (trailing && hasPendingCall && lastArgs !== undefined) {
|
|
64
|
+
func.apply(lastThis, lastArgs);
|
|
65
|
+
hasPendingCall = false;
|
|
66
|
+
}
|
|
67
|
+
}, wait);
|
|
68
|
+
} as DebouncedFunc<T>;
|
|
69
|
+
|
|
70
|
+
debounced.cancel = () => {
|
|
71
|
+
if (timeout !== undefined) {
|
|
72
|
+
clearTimeout(timeout);
|
|
73
|
+
timeout = undefined;
|
|
74
|
+
}
|
|
75
|
+
lastArgs = undefined;
|
|
76
|
+
lastThis = undefined;
|
|
77
|
+
hasPendingCall = false;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return debounced;
|
|
81
|
+
}
|