@knime/utils 1.2.7 → 1.3.1
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/CHANGELOG.md +12 -0
- package/package.json +9 -6
- package/src/hotkeys.ts +32 -0
- package/src/index.ts +1 -0
- package/src/intervalUtils.ts +0 -3
- package/src/navigator.ts +12 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @knime/utils
|
|
2
2
|
|
|
3
|
+
## 1.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a674c18: Allow zero duration but disallow empty duration in IntervalInput
|
|
8
|
+
|
|
9
|
+
## 1.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 59af778: Added a utility file for `hotkeys`. This utility can be used to detect if a modifier key is pressed or if the hotkey is pressed without any modifier keys. Additionally the `getMetaOrCtrlKey()` util was moved from `navigator` to the new `hotkeys` util.
|
|
14
|
+
|
|
3
15
|
## 1.2.7
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knime/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Internal utility functions and constants shared across @knime packages.",
|
|
5
5
|
"homepage": "https://knime.github.io/webapps-common/",
|
|
6
6
|
"license": "GPL 3 and Additional Permissions according to Sec. 7 (SEE the file LICENSE)",
|
|
7
7
|
"author": "KNIME AG, Zurich, Switzerland",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"consola": "3.2.3",
|
|
11
10
|
"date-fns": "2.30.0",
|
|
12
11
|
"date-fns-tz": "2.0.0",
|
|
13
12
|
"@knime/styles": "1.3.1"
|
|
14
13
|
},
|
|
14
|
+
"peerDependencies": {
|
|
15
|
+
"consola": "3.x"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"consola": "3.2.3",
|
|
19
|
+
"flush-promises": "^1.0.2",
|
|
20
|
+
"mock-xmlhttprequest": "^8.3.0"
|
|
21
|
+
},
|
|
15
22
|
"main": "src/index.ts",
|
|
16
23
|
"module": "src/index.ts",
|
|
17
24
|
"files": [
|
|
@@ -32,10 +39,6 @@
|
|
|
32
39
|
"import": "./test-utils/index.ts"
|
|
33
40
|
}
|
|
34
41
|
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"flush-promises": "^1.0.2",
|
|
37
|
-
"mock-xmlhttprequest": "^8.3.0"
|
|
38
|
-
},
|
|
39
42
|
"scripts": {
|
|
40
43
|
"test:unit": "TZ='Europe/Berlin' vitest"
|
|
41
44
|
}
|
package/src/hotkeys.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { navigatorUtils } from "@knime/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Checks if any modifier key (Ctrl, Meta, Alt, or Shift) is pressed.
|
|
5
|
+
* @param {KeyboardEvent} event - The keyboard event to check.
|
|
6
|
+
* @returns {boolean} True if a modifier key is pressed, otherwise false.
|
|
7
|
+
*/
|
|
8
|
+
export const isModifierKeyPressed = (event: KeyboardEvent): boolean => {
|
|
9
|
+
return event.ctrlKey || event.metaKey || event.altKey || event.shiftKey;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a specific key (or keys) were pressed without any modifier keys.
|
|
14
|
+
* @param {KeyboardEvent} event - The keyboard event to check.
|
|
15
|
+
* @param {string | string[]} keys - The key or keys to check for.
|
|
16
|
+
* @returns {boolean} True if the specified key(s) were pressed without modifiers, otherwise false.
|
|
17
|
+
*/
|
|
18
|
+
export const isKeyWithoutModifiers = (
|
|
19
|
+
event: KeyboardEvent,
|
|
20
|
+
keys: string | string[],
|
|
21
|
+
): boolean => {
|
|
22
|
+
const keyList = Array.isArray(keys) ? keys : [keys];
|
|
23
|
+
return keyList.includes(event.key) && !isModifierKeyPressed(event);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @returns name of the primary modifier key for the current platform
|
|
29
|
+
*/
|
|
30
|
+
export const getMetaOrCtrlKey = (): string => {
|
|
31
|
+
return navigatorUtils.getMetaOrCtrlKey();
|
|
32
|
+
};
|
package/src/index.ts
CHANGED
package/src/intervalUtils.ts
CHANGED
|
@@ -22,7 +22,6 @@ type IntervalStringValidationResult =
|
|
|
22
22
|
valid: true;
|
|
23
23
|
type: AllowedIntervalTypes;
|
|
24
24
|
negative: boolean;
|
|
25
|
-
zero: boolean;
|
|
26
25
|
}
|
|
27
26
|
| { valid: false };
|
|
28
27
|
|
|
@@ -305,7 +304,6 @@ export const isValidHumanReadableIntervalString = (
|
|
|
305
304
|
valid: true,
|
|
306
305
|
type: actualType,
|
|
307
306
|
negative,
|
|
308
|
-
zero: isZero(validationResult),
|
|
309
307
|
};
|
|
310
308
|
} else {
|
|
311
309
|
return { valid: false };
|
|
@@ -382,7 +380,6 @@ export const isValidISOIntervalString = (
|
|
|
382
380
|
valid: true,
|
|
383
381
|
type: actualType,
|
|
384
382
|
negative,
|
|
385
|
-
zero: isZero(validationResult),
|
|
386
383
|
};
|
|
387
384
|
} else {
|
|
388
385
|
return { valid: false };
|
package/src/navigator.ts
CHANGED
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
*
|
|
3
3
|
* @returns true when the platform of the user is Mac
|
|
4
4
|
*/
|
|
5
|
-
export const isMac = () =>
|
|
5
|
+
export const isMac = (): boolean =>
|
|
6
|
+
navigator?.userAgent?.toLowerCase()?.includes("mac");
|
|
6
7
|
|
|
7
8
|
/**
|
|
9
|
+
* @deprecated Since version 1.3.6. Use `hotkeys.ts` instead.
|
|
8
10
|
*
|
|
9
|
-
* @returns name of the primary modifier key for the current platform
|
|
11
|
+
* @returns name of the primary modifier key for the current platform.
|
|
10
12
|
*/
|
|
11
|
-
export const getMetaOrCtrlKey = () =>
|
|
13
|
+
export const getMetaOrCtrlKey = () => {
|
|
14
|
+
if (import.meta.env.DEV) {
|
|
15
|
+
consola.warn(
|
|
16
|
+
"getMetaOrCtrlKey is deprecated on navigatorUtils. Please use hotkeys.ts instead.",
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return isMac() ? "metaKey" : "ctrlKey";
|
|
20
|
+
};
|