@neovici/cosmoz-utils 6.19.0 → 6.20.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.
@@ -36,10 +36,12 @@ export const hauntedPolymer = (outputPath, hook) => (base) => {
36
36
  }
37
37
  connectedCallback() {
38
38
  super.connectedCallback();
39
+ this._scheduler.resume();
39
40
  this._scheduler.update();
40
41
  }
41
42
  disconnectedCallback() {
42
43
  super.disconnectedCallback();
44
+ this._scheduler.pause();
43
45
  this._scheduler.teardown();
44
46
  }
45
47
  _propertiesChanged(currentProps, changedProps, oldProps) {
@@ -1,9 +1,6 @@
1
1
  import { Rec } from '../object';
2
2
  /**
3
- * Copies properties of an Object into a memoized object.
4
- * Useful to create an object that does not change.
5
- *
6
- * @param {Object} meta - The source object
7
- * @returns {Object} The memoized object.
3
+ * Returns a stable object reference, mutated in-place with the
4
+ * latest properties of `meta`. The identity never changes (`===`).
8
5
  */
9
6
  export declare const useMeta: <T extends Rec>(meta: T) => T;
@@ -1,10 +1,7 @@
1
1
  import { useMemo } from '@pionjs/pion';
2
2
  /**
3
- * Copies properties of an Object into a memoized object.
4
- * Useful to create an object that does not change.
5
- *
6
- * @param {Object} meta - The source object
7
- * @returns {Object} The memoized object.
3
+ * Returns a stable object reference, mutated in-place with the
4
+ * latest properties of `meta`. The identity never changes (`===`).
8
5
  */
9
6
  export const useMeta = (meta) => {
10
7
  const ref = useMemo(() => ({}), []);
@@ -0,0 +1 @@
1
+ export declare const ANY_KEY: unique symbol;
@@ -0,0 +1 @@
1
+ export const ANY_KEY = Symbol('any key');
@@ -1,4 +1,5 @@
1
1
  export type * from './types';
2
+ export * from './consts';
2
3
  export * from './context';
3
4
  export * from './use-activity';
4
5
  export * from './use-keybindings';
@@ -1,3 +1,4 @@
1
+ export * from './consts';
1
2
  export * from './context';
2
3
  export * from './use-activity';
3
4
  export * from './use-keybindings';
@@ -1,5 +1,8 @@
1
+ import { ANY_KEY } from './consts';
1
2
  export type Activity = symbol;
2
- export type Matcher = Pick<KeyboardEvent, 'key'> & Partial<Pick<KeyboardEvent, 'ctrlKey' | 'metaKey' | 'altKey' | 'shiftKey'>>;
3
+ export type Matcher = Partial<Pick<KeyboardEvent, 'ctrlKey' | 'metaKey' | 'altKey' | 'shiftKey'>> & {
4
+ key: KeyboardEvent['key'] | typeof ANY_KEY;
5
+ };
3
6
  export type Info = {
4
7
  title: string;
5
8
  description: string;
@@ -10,8 +13,9 @@ export type BindingOptions = {
10
13
  export type KeyBinding = readonly [Matcher, Activity[], Info, BindingOptions?];
11
14
  export type ActivityHandler = {
12
15
  activity: Activity;
13
- callback: () => void;
16
+ callback: (e: KeyboardEvent) => void;
14
17
  check?: () => boolean;
15
18
  element?: () => Element | null | undefined;
19
+ allowDefault?: boolean;
16
20
  };
17
21
  export type RegisterFn = (handler: ActivityHandler) => () => void;
@@ -27,8 +27,9 @@ export const useKeybindings = (bindings) => {
27
27
  });
28
28
  if (!handler)
29
29
  return;
30
- e.preventDefault();
31
- handler.callback();
30
+ if (!handler.allowDefault)
31
+ e.preventDefault();
32
+ handler.callback(e);
32
33
  };
33
34
  document.addEventListener('keydown', keyboardEventHandler, true);
34
35
  return () => document.removeEventListener('keydown', keyboardEventHandler, true);
@@ -1,4 +1,5 @@
1
- export const matches = (e) => ([matcher]) => Object.entries(matcher).every(([key, value]) => e[key] === value);
1
+ import { ANY_KEY } from './consts';
2
+ export const matches = (e) => ([matcher]) => Object.entries(matcher).every(([key, value]) => e[key] === value || value === ANY_KEY);
2
3
  export const isInteractive = (el) => {
3
4
  if (el == null)
4
5
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-utils",
3
- "version": "6.19.0",
3
+ "version": "6.20.1",
4
4
  "description": "Date, money and template management functions commonly needed in Cosmoz views.",
5
5
  "keywords": [
6
6
  "polymer",