@neovici/cosmoz-utils 6.13.0 → 6.13.2

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.
@@ -8,6 +8,7 @@ export type KeyBinding = readonly [Matcher, Activity[], Info];
8
8
  export type ActivityHandler = {
9
9
  activity: Activity;
10
10
  callback: () => void;
11
+ check?: () => boolean;
11
12
  element?: () => Element | null | undefined;
12
13
  };
13
14
  export type RegisterFn = (handler: ActivityHandler) => () => void;
@@ -4,7 +4,7 @@ import { focusIsInEditableArea, isInteractive, matches } from './utils';
4
4
  export const useKeybindings = (bindings) => {
5
5
  const meta = useMeta({ bindings });
6
6
  useEffect(() => {
7
- const handler = (e) => {
7
+ const keyboardEventHandler = (e) => {
8
8
  if (e.defaultPrevented) {
9
9
  return;
10
10
  }
@@ -18,14 +18,20 @@ export const useKeybindings = (bindings) => {
18
18
  if (handlers.length === 0)
19
19
  return;
20
20
  // find first actionable handler
21
- const handler = handlers.find((handler) => !handler.element || isInteractive(handler.element()));
21
+ const handler = handlers.find((handler) => {
22
+ if ((handler.check && !handler.check()) ||
23
+ (handler.element && !isInteractive(handler.element()))) {
24
+ return false;
25
+ }
26
+ return handler;
27
+ });
22
28
  if (!handler)
23
29
  return;
24
30
  e.preventDefault();
25
31
  handler.callback();
26
32
  };
27
- document.addEventListener('keydown', handler, true);
28
- return () => document.removeEventListener('keydown', handler, true);
33
+ document.addEventListener('keydown', keyboardEventHandler, true);
34
+ return () => document.removeEventListener('keydown', keyboardEventHandler, true);
29
35
  }, []);
30
36
  const register = useCallback((handler) => {
31
37
  meta[handler.activity] = [handler, ...(meta[handler.activity] ?? [])];
@@ -19,7 +19,7 @@ export const focusIsInEditableArea = () => {
19
19
  const active = getActiveElement(document);
20
20
  if (!active)
21
21
  return false;
22
- if (active.matches('input, textarea'))
22
+ if (active.matches('input:not([type="checkbox"]), textarea'))
23
23
  return true;
24
24
  if ('isContentEditable' in active && active.isContentEditable) {
25
25
  return true;
package/dist/memoize.js CHANGED
@@ -1,3 +1,4 @@
1
+ const sym = Symbol('memo');
1
2
  export const memize = (fn) => {
2
3
  let called = false, lastResult;
3
4
  return function () {
@@ -10,7 +11,7 @@ export const memize = (fn) => {
10
11
  return result;
11
12
  };
12
13
  }, memoize = (fn) => {
13
- let lastArg, lastResult;
14
+ let lastArg = sym, lastResult;
14
15
  return function (arg) {
15
16
  if (lastArg === arg) {
16
17
  return lastResult;
@@ -21,7 +22,7 @@ export const memize = (fn) => {
21
22
  return result;
22
23
  };
23
24
  }, memooize = (fn) => {
24
- let lastArg1, lastArg2, lastResult;
25
+ let lastArg1 = sym, lastArg2 = sym, lastResult;
25
26
  return function (arg1, arg2) {
26
27
  if (lastArg1 === arg1 && lastArg2 === arg2) {
27
28
  return lastResult;
@@ -33,7 +34,7 @@ export const memize = (fn) => {
33
34
  return result;
34
35
  };
35
36
  }, memoooize = (fn) => {
36
- let lastArg1, lastArg2, lastArg3, lastResult;
37
+ let lastArg1 = sym, lastArg2 = sym, lastArg3 = sym, lastResult;
37
38
  return function (arg1, arg2, arg3) {
38
39
  if (lastArg1 === arg1 && lastArg2 === arg2 && lastArg3 === arg3) {
39
40
  return lastResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "6.13.0",
3
+ "version": "6.13.2",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",
@@ -76,8 +76,8 @@
76
76
  "@pionjs/pion": "^2.7.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@commitlint/cli": "^18.0.0",
80
- "@commitlint/config-conventional": "^18.0.0",
79
+ "@commitlint/cli": "^19.0.0",
80
+ "@commitlint/config-conventional": "^19.0.0",
81
81
  "@neovici/cfg": "^1.15.1",
82
82
  "@open-wc/testing": "^4.0.0",
83
83
  "@polymer/polymer": "^3.3.1",
@@ -86,7 +86,7 @@
86
86
  "@types/mocha": "^10.0.3",
87
87
  "husky": "^8.0.0",
88
88
  "lit-html": "^2.0.0 || ^3.0.0",
89
- "semantic-release": "^22.0.0",
90
- "sinon": "^17.0.0"
89
+ "semantic-release": "^24.0.0",
90
+ "sinon": "^19.0.0"
91
91
  }
92
92
  }