@wordpress/keyboard-shortcuts 4.19.2 → 4.20.0

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 CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.20.0 (2023-10-05)
6
+
5
7
  ## 4.19.0 (2023-09-20)
6
8
 
7
9
  ## 4.18.0 (2023-08-31)
package/README.md CHANGED
@@ -26,7 +26,7 @@ _Parameters_
26
26
 
27
27
  _Returns_
28
28
 
29
- - `import('@wordpress/element').WPElement`: Component.
29
+ - `Element`: Component.
30
30
 
31
31
  ### store
32
32
 
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ShortcutProvider = ShortcutProvider;
7
+ var _react = require("react");
7
8
  var _element = require("@wordpress/element");
8
9
  var _context = require("../context");
9
10
  /**
@@ -25,21 +26,21 @@ const {
25
26
  *
26
27
  * @param {Object} props Props to pass to `div`.
27
28
  *
28
- * @return {import('@wordpress/element').WPElement} Component.
29
+ * @return {Element} Component.
29
30
  */
30
31
  function ShortcutProvider(props) {
31
- const keyboardShortcuts = (0, _element.useRef)(new Set());
32
+ const [keyboardShortcuts] = (0, _element.useState)(() => new Set());
32
33
  function onKeyDown(event) {
33
34
  if (props.onKeyDown) props.onKeyDown(event);
34
- for (const keyboardShortcut of keyboardShortcuts.current) {
35
+ for (const keyboardShortcut of keyboardShortcuts) {
35
36
  keyboardShortcut(event);
36
37
  }
37
38
  }
38
39
 
39
40
  /* eslint-disable jsx-a11y/no-static-element-interactions */
40
- return (0, _element.createElement)(Provider, {
41
+ return (0, _react.createElement)(Provider, {
41
42
  value: keyboardShortcuts
42
- }, (0, _element.createElement)("div", {
43
+ }, (0, _react.createElement)("div", {
43
44
  ...props,
44
45
  onKeyDown: onKeyDown
45
46
  }));
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_context","Provider","context","ShortcutProvider","props","keyboardShortcuts","useRef","Set","onKeyDown","event","keyboardShortcut","current","createElement","value"],"sources":["@wordpress/keyboard-shortcuts/src/components/shortcut-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { context } from '../context';\n\nconst { Provider } = context;\n\n/**\n * Handles callbacks added to context by `useShortcut`.\n * Adding a provider allows to register contextual shortcuts\n * that are only active when a certain part of the UI is focused.\n *\n * @param {Object} props Props to pass to `div`.\n *\n * @return {import('@wordpress/element').WPElement} Component.\n */\nexport function ShortcutProvider( props ) {\n\tconst keyboardShortcuts = useRef( new Set() );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( props.onKeyDown ) props.onKeyDown( event );\n\n\t\tfor ( const keyboardShortcut of keyboardShortcuts.current ) {\n\t\t\tkeyboardShortcut( event );\n\t\t}\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\treturn (\n\t\t<Provider value={ keyboardShortcuts }>\n\t\t\t<div { ...props } onKeyDown={ onKeyDown } />\n\t\t</Provider>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAM;EAAEE;AAAS,CAAC,GAAGC,gBAAO;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAAEC,KAAK,EAAG;EACzC,MAAMC,iBAAiB,GAAG,IAAAC,eAAM,EAAE,IAAIC,GAAG,CAAC,CAAE,CAAC;EAE7C,SAASC,SAASA,CAAEC,KAAK,EAAG;IAC3B,IAAKL,KAAK,CAACI,SAAS,EAAGJ,KAAK,CAACI,SAAS,CAAEC,KAAM,CAAC;IAE/C,KAAM,MAAMC,gBAAgB,IAAIL,iBAAiB,CAACM,OAAO,EAAG;MAC3DD,gBAAgB,CAAED,KAAM,CAAC;IAC1B;EACD;;EAEA;EACA,OACC,IAAAX,QAAA,CAAAc,aAAA,EAACX,QAAQ;IAACY,KAAK,EAAGR;EAAmB,GACpC,IAAAP,QAAA,CAAAc,aAAA;IAAA,GAAUR,KAAK;IAAGI,SAAS,EAAGA;EAAW,CAAE,CAClC,CAAC;EAEZ;AACD"}
1
+ {"version":3,"names":["_element","require","_context","Provider","context","ShortcutProvider","props","keyboardShortcuts","useState","Set","onKeyDown","event","keyboardShortcut","_react","createElement","value"],"sources":["@wordpress/keyboard-shortcuts/src/components/shortcut-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { context } from '../context';\n\nconst { Provider } = context;\n\n/**\n * Handles callbacks added to context by `useShortcut`.\n * Adding a provider allows to register contextual shortcuts\n * that are only active when a certain part of the UI is focused.\n *\n * @param {Object} props Props to pass to `div`.\n *\n * @return {Element} Component.\n */\nexport function ShortcutProvider( props ) {\n\tconst [ keyboardShortcuts ] = useState( () => new Set() );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( props.onKeyDown ) props.onKeyDown( event );\n\n\t\tfor ( const keyboardShortcut of keyboardShortcuts ) {\n\t\t\tkeyboardShortcut( event );\n\t\t}\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\treturn (\n\t\t<Provider value={ keyboardShortcuts }>\n\t\t\t<div { ...props } onKeyDown={ onKeyDown } />\n\t\t</Provider>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA,MAAM;EAAEE;AAAS,CAAC,GAAGC,gBAAO;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,gBAAgBA,CAAEC,KAAK,EAAG;EACzC,MAAM,CAAEC,iBAAiB,CAAE,GAAG,IAAAC,iBAAQ,EAAE,MAAM,IAAIC,GAAG,CAAC,CAAE,CAAC;EAEzD,SAASC,SAASA,CAAEC,KAAK,EAAG;IAC3B,IAAKL,KAAK,CAACI,SAAS,EAAGJ,KAAK,CAACI,SAAS,CAAEC,KAAM,CAAC;IAE/C,KAAM,MAAMC,gBAAgB,IAAIL,iBAAiB,EAAG;MACnDK,gBAAgB,CAAED,KAAM,CAAC;IAC1B;EACD;;EAEA;EACA,OACC,IAAAE,MAAA,CAAAC,aAAA,EAACX,QAAQ;IAACY,KAAK,EAAGR;EAAmB,GACpC,IAAAM,MAAA,CAAAC,aAAA;IAAA,GAAUR,KAAK;IAAGI,SAAS,EAAGA;EAAW,CAAE,CAClC,CAAC;EAEZ;AACD"}
@@ -36,9 +36,9 @@ exports.unregisterShortcut = unregisterShortcut;
36
36
  * @example
37
37
  *
38
38
  *```js
39
+ * import { useEffect } from 'react';
39
40
  * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
40
41
  * import { useSelect, useDispatch } from '@wordpress/data';
41
- * import { useEffect } from '@wordpress/element';
42
42
  * import { __ } from '@wordpress/i18n';
43
43
  *
44
44
  * const ExampleComponent = () => {
@@ -98,9 +98,9 @@ function registerShortcut({
98
98
  * @example
99
99
  *
100
100
  *```js
101
+ * import { useEffect } from 'react';
101
102
  * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
102
103
  * import { useSelect, useDispatch } from '@wordpress/data';
103
- * import { useEffect } from '@wordpress/element';
104
104
  * import { __ } from '@wordpress/i18n';
105
105
  *
106
106
  * const ExampleComponent = () => {
@@ -1 +1 @@
1
- {"version":3,"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/edit-post/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/edit-post/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAgBA,CAAE;EACjCC,IAAI;EACJC,QAAQ;EACRC,WAAW;EACXC,cAAc;EACdC;AACD,CAAC,EAAG;EACH,OAAO;IACNC,IAAI,EAAE,mBAAmB;IACzBL,IAAI;IACJC,QAAQ;IACRE,cAAc;IACdC,OAAO;IACPF;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,kBAAkBA,CAAEN,IAAI,EAAG;EAC1C,OAAO;IACNK,IAAI,EAAE,qBAAqB;IAC3BL;EACD,CAAC;AACF"}
1
+ {"version":3,"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { useEffect } from 'react';\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { useEffect } from 'react';\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/edit-post/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/edit-post/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"],"mappings":";;;;;;;AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,gBAAgBA,CAAE;EACjCC,IAAI;EACJC,QAAQ;EACRC,WAAW;EACXC,cAAc;EACdC;AACD,CAAC,EAAG;EACH,OAAO;IACNC,IAAI,EAAE,mBAAmB;IACzBL,IAAI;IACJC,QAAQ;IACRE,cAAc;IACdC,OAAO;IACPF;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASI,kBAAkBA,CAAEN,IAAI,EAAG;EAC1C,OAAO;IACNK,IAAI,EAAE,qBAAqB;IAC3BL;EACD,CAAC;AACF"}
@@ -1,8 +1,8 @@
1
- import { createElement } from "@wordpress/element";
1
+ import { createElement } from "react";
2
2
  /**
3
3
  * WordPress dependencies
4
4
  */
5
- import { useRef } from '@wordpress/element';
5
+ import { useState } from '@wordpress/element';
6
6
 
7
7
  /**
8
8
  * Internal dependencies
@@ -19,13 +19,13 @@ const {
19
19
  *
20
20
  * @param {Object} props Props to pass to `div`.
21
21
  *
22
- * @return {import('@wordpress/element').WPElement} Component.
22
+ * @return {Element} Component.
23
23
  */
24
24
  export function ShortcutProvider(props) {
25
- const keyboardShortcuts = useRef(new Set());
25
+ const [keyboardShortcuts] = useState(() => new Set());
26
26
  function onKeyDown(event) {
27
27
  if (props.onKeyDown) props.onKeyDown(event);
28
- for (const keyboardShortcut of keyboardShortcuts.current) {
28
+ for (const keyboardShortcut of keyboardShortcuts) {
29
29
  keyboardShortcut(event);
30
30
  }
31
31
  }
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","context","Provider","ShortcutProvider","props","keyboardShortcuts","Set","onKeyDown","event","keyboardShortcut","current","createElement","value"],"sources":["@wordpress/keyboard-shortcuts/src/components/shortcut-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { context } from '../context';\n\nconst { Provider } = context;\n\n/**\n * Handles callbacks added to context by `useShortcut`.\n * Adding a provider allows to register contextual shortcuts\n * that are only active when a certain part of the UI is focused.\n *\n * @param {Object} props Props to pass to `div`.\n *\n * @return {import('@wordpress/element').WPElement} Component.\n */\nexport function ShortcutProvider( props ) {\n\tconst keyboardShortcuts = useRef( new Set() );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( props.onKeyDown ) props.onKeyDown( event );\n\n\t\tfor ( const keyboardShortcut of keyboardShortcuts.current ) {\n\t\t\tkeyboardShortcut( event );\n\t\t}\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\treturn (\n\t\t<Provider value={ keyboardShortcuts }>\n\t\t\t<div { ...props } onKeyDown={ onKeyDown } />\n\t\t</Provider>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,oBAAoB;;AAE3C;AACA;AACA;AACA,SAASC,OAAO,QAAQ,YAAY;AAEpC,MAAM;EAAEC;AAAS,CAAC,GAAGD,OAAO;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,gBAAgBA,CAAEC,KAAK,EAAG;EACzC,MAAMC,iBAAiB,GAAGL,MAAM,CAAE,IAAIM,GAAG,CAAC,CAAE,CAAC;EAE7C,SAASC,SAASA,CAAEC,KAAK,EAAG;IAC3B,IAAKJ,KAAK,CAACG,SAAS,EAAGH,KAAK,CAACG,SAAS,CAAEC,KAAM,CAAC;IAE/C,KAAM,MAAMC,gBAAgB,IAAIJ,iBAAiB,CAACK,OAAO,EAAG;MAC3DD,gBAAgB,CAAED,KAAM,CAAC;IAC1B;EACD;;EAEA;EACA,OACCG,aAAA,CAACT,QAAQ;IAACU,KAAK,EAAGP;EAAmB,GACpCM,aAAA;IAAA,GAAUP,KAAK;IAAGG,SAAS,EAAGA;EAAW,CAAE,CAClC,CAAC;EAEZ;AACD"}
1
+ {"version":3,"names":["useState","context","Provider","ShortcutProvider","props","keyboardShortcuts","Set","onKeyDown","event","keyboardShortcut","createElement","value"],"sources":["@wordpress/keyboard-shortcuts/src/components/shortcut-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { context } from '../context';\n\nconst { Provider } = context;\n\n/**\n * Handles callbacks added to context by `useShortcut`.\n * Adding a provider allows to register contextual shortcuts\n * that are only active when a certain part of the UI is focused.\n *\n * @param {Object} props Props to pass to `div`.\n *\n * @return {Element} Component.\n */\nexport function ShortcutProvider( props ) {\n\tconst [ keyboardShortcuts ] = useState( () => new Set() );\n\n\tfunction onKeyDown( event ) {\n\t\tif ( props.onKeyDown ) props.onKeyDown( event );\n\n\t\tfor ( const keyboardShortcut of keyboardShortcuts ) {\n\t\t\tkeyboardShortcut( event );\n\t\t}\n\t}\n\n\t/* eslint-disable jsx-a11y/no-static-element-interactions */\n\treturn (\n\t\t<Provider value={ keyboardShortcuts }>\n\t\t\t<div { ...props } onKeyDown={ onKeyDown } />\n\t\t</Provider>\n\t);\n\t/* eslint-enable jsx-a11y/no-static-element-interactions */\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,oBAAoB;;AAE7C;AACA;AACA;AACA,SAASC,OAAO,QAAQ,YAAY;AAEpC,MAAM;EAAEC;AAAS,CAAC,GAAGD,OAAO;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,gBAAgBA,CAAEC,KAAK,EAAG;EACzC,MAAM,CAAEC,iBAAiB,CAAE,GAAGL,QAAQ,CAAE,MAAM,IAAIM,GAAG,CAAC,CAAE,CAAC;EAEzD,SAASC,SAASA,CAAEC,KAAK,EAAG;IAC3B,IAAKJ,KAAK,CAACG,SAAS,EAAGH,KAAK,CAACG,SAAS,CAAEC,KAAM,CAAC;IAE/C,KAAM,MAAMC,gBAAgB,IAAIJ,iBAAiB,EAAG;MACnDI,gBAAgB,CAAED,KAAM,CAAC;IAC1B;EACD;;EAEA;EACA,OACCE,aAAA,CAACR,QAAQ;IAACS,KAAK,EAAGN;EAAmB,GACpCK,aAAA;IAAA,GAAUN,KAAK;IAAGG,SAAS,EAAGA;EAAW,CAAE,CAClC,CAAC;EAEZ;AACD"}
@@ -29,9 +29,9 @@
29
29
  * @example
30
30
  *
31
31
  *```js
32
+ * import { useEffect } from 'react';
32
33
  * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
33
34
  * import { useSelect, useDispatch } from '@wordpress/data';
34
- * import { useEffect } from '@wordpress/element';
35
35
  * import { __ } from '@wordpress/i18n';
36
36
  *
37
37
  * const ExampleComponent = () => {
@@ -91,9 +91,9 @@ export function registerShortcut({
91
91
  * @example
92
92
  *
93
93
  *```js
94
+ * import { useEffect } from 'react';
94
95
  * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
95
96
  * import { useSelect, useDispatch } from '@wordpress/data';
96
- * import { useEffect } from '@wordpress/element';
97
97
  * import { __ } from '@wordpress/i18n';
98
98
  *
99
99
  * const ExampleComponent = () => {
@@ -1 +1 @@
1
- {"version":3,"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { useEffect } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/edit-post/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/edit-post/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,gBAAgBA,CAAE;EACjCC,IAAI;EACJC,QAAQ;EACRC,WAAW;EACXC,cAAc;EACdC;AACD,CAAC,EAAG;EACH,OAAO;IACNC,IAAI,EAAE,mBAAmB;IACzBL,IAAI;IACJC,QAAQ;IACRE,cAAc;IACdC,OAAO;IACPF;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,kBAAkBA,CAAEN,IAAI,EAAG;EAC1C,OAAO;IACNK,IAAI,EAAE,qBAAqB;IAC3BL;EACD,CAAC;AACF"}
1
+ {"version":3,"names":["registerShortcut","name","category","description","keyCombination","aliases","type","unregisterShortcut"],"sources":["@wordpress/keyboard-shortcuts/src/store/actions.js"],"sourcesContent":["/** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */\n\n/**\n * Keyboard key combination.\n *\n * @typedef {Object} WPShortcutKeyCombination\n *\n * @property {string} character Character.\n * @property {WPKeycodeModifier|undefined} modifier Modifier.\n */\n\n/**\n * Configuration of a registered keyboard shortcut.\n *\n * @typedef {Object} WPShortcutConfig\n *\n * @property {string} name Shortcut name.\n * @property {string} category Shortcut category.\n * @property {string} description Shortcut description.\n * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.\n * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.\n */\n\n/**\n * Returns an action object used to register a new keyboard shortcut.\n *\n * @param {WPShortcutConfig} config Shortcut config.\n *\n * @example\n *\n *```js\n * import { useEffect } from 'react';\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { registerShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * registerShortcut( {\n * name: 'custom/my-custom-shortcut',\n * category: 'my-category',\n * description: __( 'My custom shortcut' ),\n * keyCombination: {\n * modifier: 'primary',\n * character: 'j',\n * },\n * } );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'custom/my-custom-shortcut'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is registered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is not registered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function registerShortcut( {\n\tname,\n\tcategory,\n\tdescription,\n\tkeyCombination,\n\taliases,\n} ) {\n\treturn {\n\t\ttype: 'REGISTER_SHORTCUT',\n\t\tname,\n\t\tcategory,\n\t\tkeyCombination,\n\t\taliases,\n\t\tdescription,\n\t};\n}\n\n/**\n * Returns an action object used to unregister a keyboard shortcut.\n *\n * @param {string} name Shortcut name.\n *\n * @example\n *\n *```js\n * import { useEffect } from 'react';\n * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';\n * import { useSelect, useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n *\n * const ExampleComponent = () => {\n * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );\n *\n * useEffect( () => {\n * unregisterShortcut( 'core/edit-post/next-region' );\n * }, [] );\n *\n * const shortcut = useSelect(\n * ( select ) =>\n * select( keyboardShortcutsStore ).getShortcutKeyCombination(\n * 'core/edit-post/next-region'\n * ),\n * []\n * );\n *\n * return shortcut ? (\n * <p>{ __( 'Shortcut is not unregistered.' ) }</p>\n * ) : (\n * <p>{ __( 'Shortcut is unregistered.' ) }</p>\n * );\n * };\n *```\n * @return {Object} action.\n */\nexport function unregisterShortcut( name ) {\n\treturn {\n\t\ttype: 'UNREGISTER_SHORTCUT',\n\t\tname,\n\t};\n}\n"],"mappings":"AAAA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,gBAAgBA,CAAE;EACjCC,IAAI;EACJC,QAAQ;EACRC,WAAW;EACXC,cAAc;EACdC;AACD,CAAC,EAAG;EACH,OAAO;IACNC,IAAI,EAAE,mBAAmB;IACzBL,IAAI;IACJC,QAAQ;IACRE,cAAc;IACdC,OAAO;IACPF;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,kBAAkBA,CAAEN,IAAI,EAAG;EAC1C,OAAO;IACNK,IAAI,EAAE,qBAAqB;IAC3BL;EACD,CAAC;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/keyboard-shortcuts",
3
- "version": "4.19.2",
3
+ "version": "4.20.0",
4
4
  "description": "Handling keyboard shortcuts.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -26,9 +26,9 @@
26
26
  "react-native": "src/index",
27
27
  "dependencies": {
28
28
  "@babel/runtime": "^7.16.0",
29
- "@wordpress/data": "^9.12.2",
30
- "@wordpress/element": "^5.19.2",
31
- "@wordpress/keycodes": "^3.42.2",
29
+ "@wordpress/data": "^9.13.0",
30
+ "@wordpress/element": "^5.20.0",
31
+ "@wordpress/keycodes": "^3.43.0",
32
32
  "rememo": "^4.0.2"
33
33
  },
34
34
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "5d2e3d07cc97af8090fc32c1e5d5013a2967e752"
40
+ "gitHead": "9b8e598c5418d38fe72197c24ef1d3dd6c712151"
41
41
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useRef } from '@wordpress/element';
4
+ import { useState } from '@wordpress/element';
5
5
 
6
6
  /**
7
7
  * Internal dependencies
@@ -17,15 +17,15 @@ const { Provider } = context;
17
17
  *
18
18
  * @param {Object} props Props to pass to `div`.
19
19
  *
20
- * @return {import('@wordpress/element').WPElement} Component.
20
+ * @return {Element} Component.
21
21
  */
22
22
  export function ShortcutProvider( props ) {
23
- const keyboardShortcuts = useRef( new Set() );
23
+ const [ keyboardShortcuts ] = useState( () => new Set() );
24
24
 
25
25
  function onKeyDown( event ) {
26
26
  if ( props.onKeyDown ) props.onKeyDown( event );
27
27
 
28
- for ( const keyboardShortcut of keyboardShortcuts.current ) {
28
+ for ( const keyboardShortcut of keyboardShortcuts ) {
29
29
  keyboardShortcut( event );
30
30
  }
31
31
  }
@@ -29,9 +29,9 @@
29
29
  * @example
30
30
  *
31
31
  *```js
32
+ * import { useEffect } from 'react';
32
33
  * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
33
34
  * import { useSelect, useDispatch } from '@wordpress/data';
34
- * import { useEffect } from '@wordpress/element';
35
35
  * import { __ } from '@wordpress/i18n';
36
36
  *
37
37
  * const ExampleComponent = () => {
@@ -91,9 +91,9 @@ export function registerShortcut( {
91
91
  * @example
92
92
  *
93
93
  *```js
94
+ * import { useEffect } from 'react';
94
95
  * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
95
96
  * import { useSelect, useDispatch } from '@wordpress/data';
96
- * import { useEffect } from '@wordpress/element';
97
97
  * import { __ } from '@wordpress/i18n';
98
98
  *
99
99
  * const ExampleComponent = () => {