PluginProbe
Gutenberg / 18.9.0
Gutenberg v18.9.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / keyboard-shortcuts / index.js

index.js in Gutenberg 18.9.0, at build/keyboard-shortcuts/index.js

796 lines 24.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /******/ (() => { // webpackBootstrap
2 /******/ "use strict";
3 /******/ // The require scope
4 /******/ var __webpack_require__ = {};
5 /******/
6 /************************************************************************/
7 /******/ /* webpack/runtime/define property getters */
8 /******/ (() => {
9 /******/ // define getter functions for harmony exports
10 /******/ __webpack_require__.d = (exports, definition) => {
11 /******/ for(var key in definition) {
12 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
13 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
14 /******/ }
15 /******/ }
16 /******/ };
17 /******/ })();
18 /******/
19 /******/ /* webpack/runtime/hasOwnProperty shorthand */
20 /******/ (() => {
21 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
22 /******/ })();
23 /******/
24 /******/ /* webpack/runtime/make namespace object */
25 /******/ (() => {
26 /******/ // define __esModule on exports
27 /******/ __webpack_require__.r = (exports) => {
28 /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
29 /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
30 /******/ }
31 /******/ Object.defineProperty(exports, '__esModule', { value: true });
32 /******/ };
33 /******/ })();
34 /******/
35 /************************************************************************/
36 var __webpack_exports__ = {};
37 // ESM COMPAT FLAG
38 __webpack_require__.r(__webpack_exports__);
39
40 // EXPORTS
41 __webpack_require__.d(__webpack_exports__, {
42 ShortcutProvider: () => (/* reexport */ ShortcutProvider),
43 __unstableUseShortcutEventMatch: () => (/* reexport */ useShortcutEventMatch),
44 store: () => (/* reexport */ store),
45 useShortcut: () => (/* reexport */ useShortcut)
46 });
47
48 // NAMESPACE OBJECT: ./packages/keyboard-shortcuts/build-module/store/actions.js
49 var actions_namespaceObject = {};
50 __webpack_require__.r(actions_namespaceObject);
51 __webpack_require__.d(actions_namespaceObject, {
52 registerShortcut: () => (registerShortcut),
53 unregisterShortcut: () => (unregisterShortcut)
54 });
55
56 // NAMESPACE OBJECT: ./packages/keyboard-shortcuts/build-module/store/selectors.js
57 var selectors_namespaceObject = {};
58 __webpack_require__.r(selectors_namespaceObject);
59 __webpack_require__.d(selectors_namespaceObject, {
60 getAllShortcutKeyCombinations: () => (getAllShortcutKeyCombinations),
61 getAllShortcutRawKeyCombinations: () => (getAllShortcutRawKeyCombinations),
62 getCategoryShortcuts: () => (getCategoryShortcuts),
63 getShortcutAliases: () => (getShortcutAliases),
64 getShortcutDescription: () => (getShortcutDescription),
65 getShortcutKeyCombination: () => (getShortcutKeyCombination),
66 getShortcutRepresentation: () => (getShortcutRepresentation)
67 });
68
69 ;// CONCATENATED MODULE: external ["wp","data"]
70 const external_wp_data_namespaceObject = window["wp"]["data"];
71 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/reducer.js
72 /**
73 * Reducer returning the registered shortcuts
74 *
75 * @param {Object} state Current state.
76 * @param {Object} action Dispatched action.
77 *
78 * @return {Object} Updated state.
79 */
80 function reducer(state = {}, action) {
81 switch (action.type) {
82 case 'REGISTER_SHORTCUT':
83 return {
84 ...state,
85 [action.name]: {
86 category: action.category,
87 keyCombination: action.keyCombination,
88 aliases: action.aliases,
89 description: action.description
90 }
91 };
92 case 'UNREGISTER_SHORTCUT':
93 const {
94 [action.name]: actionName,
95 ...remainingState
96 } = state;
97 return remainingState;
98 }
99 return state;
100 }
101 /* harmony default export */ const store_reducer = (reducer);
102
103 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/actions.js
104 /** @typedef {import('@wordpress/keycodes').WPKeycodeModifier} WPKeycodeModifier */
105
106 /**
107 * Keyboard key combination.
108 *
109 * @typedef {Object} WPShortcutKeyCombination
110 *
111 * @property {string} character Character.
112 * @property {WPKeycodeModifier|undefined} modifier Modifier.
113 */
114
115 /**
116 * Configuration of a registered keyboard shortcut.
117 *
118 * @typedef {Object} WPShortcutConfig
119 *
120 * @property {string} name Shortcut name.
121 * @property {string} category Shortcut category.
122 * @property {string} description Shortcut description.
123 * @property {WPShortcutKeyCombination} keyCombination Shortcut key combination.
124 * @property {WPShortcutKeyCombination[]} [aliases] Shortcut aliases.
125 */
126
127 /**
128 * Returns an action object used to register a new keyboard shortcut.
129 *
130 * @param {WPShortcutConfig} config Shortcut config.
131 *
132 * @example
133 *
134 *```js
135 * import { useEffect } from 'react';
136 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
137 * import { useSelect, useDispatch } from '@wordpress/data';
138 * import { __ } from '@wordpress/i18n';
139 *
140 * const ExampleComponent = () => {
141 * const { registerShortcut } = useDispatch( keyboardShortcutsStore );
142 *
143 * useEffect( () => {
144 * registerShortcut( {
145 * name: 'custom/my-custom-shortcut',
146 * category: 'my-category',
147 * description: __( 'My custom shortcut' ),
148 * keyCombination: {
149 * modifier: 'primary',
150 * character: 'j',
151 * },
152 * } );
153 * }, [] );
154 *
155 * const shortcut = useSelect(
156 * ( select ) =>
157 * select( keyboardShortcutsStore ).getShortcutKeyCombination(
158 * 'custom/my-custom-shortcut'
159 * ),
160 * []
161 * );
162 *
163 * return shortcut ? (
164 * <p>{ __( 'Shortcut is registered.' ) }</p>
165 * ) : (
166 * <p>{ __( 'Shortcut is not registered.' ) }</p>
167 * );
168 * };
169 *```
170 * @return {Object} action.
171 */
172 function registerShortcut({
173 name,
174 category,
175 description,
176 keyCombination,
177 aliases
178 }) {
179 return {
180 type: 'REGISTER_SHORTCUT',
181 name,
182 category,
183 keyCombination,
184 aliases,
185 description
186 };
187 }
188
189 /**
190 * Returns an action object used to unregister a keyboard shortcut.
191 *
192 * @param {string} name Shortcut name.
193 *
194 * @example
195 *
196 *```js
197 * import { useEffect } from 'react';
198 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
199 * import { useSelect, useDispatch } from '@wordpress/data';
200 * import { __ } from '@wordpress/i18n';
201 *
202 * const ExampleComponent = () => {
203 * const { unregisterShortcut } = useDispatch( keyboardShortcutsStore );
204 *
205 * useEffect( () => {
206 * unregisterShortcut( 'core/editor/next-region' );
207 * }, [] );
208 *
209 * const shortcut = useSelect(
210 * ( select ) =>
211 * select( keyboardShortcutsStore ).getShortcutKeyCombination(
212 * 'core/editor/next-region'
213 * ),
214 * []
215 * );
216 *
217 * return shortcut ? (
218 * <p>{ __( 'Shortcut is not unregistered.' ) }</p>
219 * ) : (
220 * <p>{ __( 'Shortcut is unregistered.' ) }</p>
221 * );
222 * };
223 *```
224 * @return {Object} action.
225 */
226 function unregisterShortcut(name) {
227 return {
228 type: 'UNREGISTER_SHORTCUT',
229 name
230 };
231 }
232
233 ;// CONCATENATED MODULE: external ["wp","keycodes"]
234 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
235 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/selectors.js
236 /**
237 * WordPress dependencies
238 */
239
240
241
242 /** @typedef {import('./actions').WPShortcutKeyCombination} WPShortcutKeyCombination */
243
244 /** @typedef {import('@wordpress/keycodes').WPKeycodeHandlerByModifier} WPKeycodeHandlerByModifier */
245
246 /**
247 * Shared reference to an empty array for cases where it is important to avoid
248 * returning a new array reference on every invocation.
249 *
250 * @type {Array<any>}
251 */
252 const EMPTY_ARRAY = [];
253
254 /**
255 * Shortcut formatting methods.
256 *
257 * @property {WPKeycodeHandlerByModifier} display Display formatting.
258 * @property {WPKeycodeHandlerByModifier} rawShortcut Raw shortcut formatting.
259 * @property {WPKeycodeHandlerByModifier} ariaLabel ARIA label formatting.
260 */
261 const FORMATTING_METHODS = {
262 display: external_wp_keycodes_namespaceObject.displayShortcut,
263 raw: external_wp_keycodes_namespaceObject.rawShortcut,
264 ariaLabel: external_wp_keycodes_namespaceObject.shortcutAriaLabel
265 };
266
267 /**
268 * Returns a string representing the key combination.
269 *
270 * @param {?WPShortcutKeyCombination} shortcut Key combination.
271 * @param {keyof FORMATTING_METHODS} representation Type of representation
272 * (display, raw, ariaLabel).
273 *
274 * @return {string?} Shortcut representation.
275 */
276 function getKeyCombinationRepresentation(shortcut, representation) {
277 if (!shortcut) {
278 return null;
279 }
280 return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier](shortcut.character) : shortcut.character;
281 }
282
283 /**
284 * Returns the main key combination for a given shortcut name.
285 *
286 * @param {Object} state Global state.
287 * @param {string} name Shortcut name.
288 *
289 * @example
290 *
291 *```js
292 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
293 * import { useSelect } from '@wordpress/data';
294 * import { createInterpolateElement } from '@wordpress/element';
295 * import { sprintf } from '@wordpress/i18n';
296 * const ExampleComponent = () => {
297 * const {character, modifier} = useSelect(
298 * ( select ) =>
299 * select( keyboardShortcutsStore ).getShortcutKeyCombination(
300 * 'core/editor/next-region'
301 * ),
302 * []
303 * );
304 *
305 * return (
306 * <div>
307 * { createInterpolateElement(
308 * sprintf(
309 * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
310 * character,
311 * modifier
312 * ),
313 * {
314 * code: <code />,
315 * }
316 * ) }
317 * </div>
318 * );
319 * };
320 *```
321 *
322 * @return {WPShortcutKeyCombination?} Key combination.
323 */
324 function getShortcutKeyCombination(state, name) {
325 return state[name] ? state[name].keyCombination : null;
326 }
327
328 /**
329 * Returns a string representing the main key combination for a given shortcut name.
330 *
331 * @param {Object} state Global state.
332 * @param {string} name Shortcut name.
333 * @param {keyof FORMATTING_METHODS} representation Type of representation
334 * (display, raw, ariaLabel).
335 * @example
336 *
337 *```js
338 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
339 * import { useSelect } from '@wordpress/data';
340 * import { sprintf } from '@wordpress/i18n';
341 *
342 * const ExampleComponent = () => {
343 * const {display, raw, ariaLabel} = useSelect(
344 * ( select ) =>{
345 * return {
346 * display: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region' ),
347 * raw: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region','raw' ),
348 * ariaLabel: select( keyboardShortcutsStore ).getShortcutRepresentation('core/editor/next-region', 'ariaLabel')
349 * }
350 * },
351 * []
352 * );
353 *
354 * return (
355 * <ul>
356 * <li>{ sprintf( 'display string: %s', display ) }</li>
357 * <li>{ sprintf( 'raw string: %s', raw ) }</li>
358 * <li>{ sprintf( 'ariaLabel string: %s', ariaLabel ) }</li>
359 * </ul>
360 * );
361 * };
362 *```
363 *
364 * @return {string?} Shortcut representation.
365 */
366 function getShortcutRepresentation(state, name, representation = 'display') {
367 const shortcut = getShortcutKeyCombination(state, name);
368 return getKeyCombinationRepresentation(shortcut, representation);
369 }
370
371 /**
372 * Returns the shortcut description given its name.
373 *
374 * @param {Object} state Global state.
375 * @param {string} name Shortcut name.
376 *
377 * @example
378 *
379 *```js
380 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
381 * import { useSelect } from '@wordpress/data';
382 * import { __ } from '@wordpress/i18n';
383 * const ExampleComponent = () => {
384 * const shortcutDescription = useSelect(
385 * ( select ) =>
386 * select( keyboardShortcutsStore ).getShortcutDescription( 'core/editor/next-region' ),
387 * []
388 * );
389 *
390 * return shortcutDescription ? (
391 * <div>{ shortcutDescription }</div>
392 * ) : (
393 * <div>{ __( 'No description.' ) }</div>
394 * );
395 * };
396 *```
397 * @return {string?} Shortcut description.
398 */
399 function getShortcutDescription(state, name) {
400 return state[name] ? state[name].description : null;
401 }
402
403 /**
404 * Returns the aliases for a given shortcut name.
405 *
406 * @param {Object} state Global state.
407 * @param {string} name Shortcut name.
408 * @example
409 *
410 *```js
411 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
412 * import { useSelect } from '@wordpress/data';
413 * import { createInterpolateElement } from '@wordpress/element';
414 * import { sprintf } from '@wordpress/i18n';
415 * const ExampleComponent = () => {
416 * const shortcutAliases = useSelect(
417 * ( select ) =>
418 * select( keyboardShortcutsStore ).getShortcutAliases(
419 * 'core/editor/next-region'
420 * ),
421 * []
422 * );
423 *
424 * return (
425 * shortcutAliases.length > 0 && (
426 * <ul>
427 * { shortcutAliases.map( ( { character, modifier }, index ) => (
428 * <li key={ index }>
429 * { createInterpolateElement(
430 * sprintf(
431 * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
432 * character,
433 * modifier
434 * ),
435 * {
436 * code: <code />,
437 * }
438 * ) }
439 * </li>
440 * ) ) }
441 * </ul>
442 * )
443 * );
444 * };
445 *```
446 *
447 * @return {WPShortcutKeyCombination[]} Key combinations.
448 */
449 function getShortcutAliases(state, name) {
450 return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
451 }
452
453 /**
454 * Returns the shortcuts that include aliases for a given shortcut name.
455 *
456 * @param {Object} state Global state.
457 * @param {string} name Shortcut name.
458 * @example
459 *
460 *```js
461 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
462 * import { useSelect } from '@wordpress/data';
463 * import { createInterpolateElement } from '@wordpress/element';
464 * import { sprintf } from '@wordpress/i18n';
465 *
466 * const ExampleComponent = () => {
467 * const allShortcutKeyCombinations = useSelect(
468 * ( select ) =>
469 * select( keyboardShortcutsStore ).getAllShortcutKeyCombinations(
470 * 'core/editor/next-region'
471 * ),
472 * []
473 * );
474 *
475 * return (
476 * allShortcutKeyCombinations.length > 0 && (
477 * <ul>
478 * { allShortcutKeyCombinations.map(
479 * ( { character, modifier }, index ) => (
480 * <li key={ index }>
481 * { createInterpolateElement(
482 * sprintf(
483 * 'Character: <code>%s</code> / Modifier: <code>%s</code>',
484 * character,
485 * modifier
486 * ),
487 * {
488 * code: <code />,
489 * }
490 * ) }
491 * </li>
492 * )
493 * ) }
494 * </ul>
495 * )
496 * );
497 * };
498 *```
499 *
500 * @return {WPShortcutKeyCombination[]} Key combinations.
501 */
502 const getAllShortcutKeyCombinations = (0,external_wp_data_namespaceObject.createSelector)((state, name) => {
503 return [getShortcutKeyCombination(state, name), ...getShortcutAliases(state, name)].filter(Boolean);
504 }, (state, name) => [state[name]]);
505
506 /**
507 * Returns the raw representation of all the keyboard combinations of a given shortcut name.
508 *
509 * @param {Object} state Global state.
510 * @param {string} name Shortcut name.
511 *
512 * @example
513 *
514 *```js
515 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
516 * import { useSelect } from '@wordpress/data';
517 * import { createInterpolateElement } from '@wordpress/element';
518 * import { sprintf } from '@wordpress/i18n';
519 *
520 * const ExampleComponent = () => {
521 * const allShortcutRawKeyCombinations = useSelect(
522 * ( select ) =>
523 * select( keyboardShortcutsStore ).getAllShortcutRawKeyCombinations(
524 * 'core/editor/next-region'
525 * ),
526 * []
527 * );
528 *
529 * return (
530 * allShortcutRawKeyCombinations.length > 0 && (
531 * <ul>
532 * { allShortcutRawKeyCombinations.map(
533 * ( shortcutRawKeyCombination, index ) => (
534 * <li key={ index }>
535 * { createInterpolateElement(
536 * sprintf(
537 * ' <code>%s</code>',
538 * shortcutRawKeyCombination
539 * ),
540 * {
541 * code: <code />,
542 * }
543 * ) }
544 * </li>
545 * )
546 * ) }
547 * </ul>
548 * )
549 * );
550 * };
551 *```
552 *
553 * @return {string[]} Shortcuts.
554 */
555 const getAllShortcutRawKeyCombinations = (0,external_wp_data_namespaceObject.createSelector)((state, name) => {
556 return getAllShortcutKeyCombinations(state, name).map(combination => getKeyCombinationRepresentation(combination, 'raw'));
557 }, (state, name) => [state[name]]);
558
559 /**
560 * Returns the shortcut names list for a given category name.
561 *
562 * @param {Object} state Global state.
563 * @param {string} name Category name.
564 * @example
565 *
566 *```js
567 * import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
568 * import { useSelect } from '@wordpress/data';
569 *
570 * const ExampleComponent = () => {
571 * const categoryShortcuts = useSelect(
572 * ( select ) =>
573 * select( keyboardShortcutsStore ).getCategoryShortcuts(
574 * 'block'
575 * ),
576 * []
577 * );
578 *
579 * return (
580 * categoryShortcuts.length > 0 && (
581 * <ul>
582 * { categoryShortcuts.map( ( categoryShortcut ) => (
583 * <li key={ categoryShortcut }>{ categoryShortcut }</li>
584 * ) ) }
585 * </ul>
586 * )
587 * );
588 * };
589 *```
590 * @return {string[]} Shortcut names.
591 */
592 const getCategoryShortcuts = (0,external_wp_data_namespaceObject.createSelector)((state, categoryName) => {
593 return Object.entries(state).filter(([, shortcut]) => shortcut.category === categoryName).map(([name]) => name);
594 }, state => [state]);
595
596 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/store/index.js
597 /**
598 * WordPress dependencies
599 */
600
601
602 /**
603 * Internal dependencies
604 */
605
606
607
608 const STORE_NAME = 'core/keyboard-shortcuts';
609
610 /**
611 * Store definition for the keyboard shortcuts namespace.
612 *
613 * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
614 *
615 * @type {Object}
616 */
617 const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
618 reducer: store_reducer,
619 actions: actions_namespaceObject,
620 selectors: selectors_namespaceObject
621 });
622 (0,external_wp_data_namespaceObject.register)(store);
623
624 ;// CONCATENATED MODULE: external ["wp","element"]
625 const external_wp_element_namespaceObject = window["wp"]["element"];
626 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.js
627 /**
628 * WordPress dependencies
629 */
630
631
632
633 /**
634 * Internal dependencies
635 */
636
637
638 /**
639 * Returns a function to check if a keyboard event matches a shortcut name.
640 *
641 * @return {Function} A function to check if a keyboard event matches a
642 * predefined shortcut combination.
643 */
644 function useShortcutEventMatch() {
645 const {
646 getAllShortcutKeyCombinations
647 } = (0,external_wp_data_namespaceObject.useSelect)(store);
648
649 /**
650 * A function to check if a keyboard event matches a predefined shortcut
651 * combination.
652 *
653 * @param {string} name Shortcut name.
654 * @param {KeyboardEvent} event Event to check.
655 *
656 * @return {boolean} True if the event matches any shortcuts, false if not.
657 */
658 function isMatch(name, event) {
659 return getAllShortcutKeyCombinations(name).some(({
660 modifier,
661 character
662 }) => {
663 return external_wp_keycodes_namespaceObject.isKeyboardEvent[modifier](event, character);
664 });
665 }
666 return isMatch;
667 }
668
669 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/context.js
670 /**
671 * WordPress dependencies
672 */
673
674 const globalShortcuts = new Set();
675 const globalListener = event => {
676 for (const keyboardShortcut of globalShortcuts) {
677 keyboardShortcut(event);
678 }
679 };
680 const context = (0,external_wp_element_namespaceObject.createContext)({
681 add: shortcut => {
682 if (globalShortcuts.size === 0) {
683 document.addEventListener('keydown', globalListener);
684 }
685 globalShortcuts.add(shortcut);
686 },
687 delete: shortcut => {
688 globalShortcuts.delete(shortcut);
689 if (globalShortcuts.size === 0) {
690 document.removeEventListener('keydown', globalListener);
691 }
692 }
693 });
694
695 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/hooks/use-shortcut.js
696 /**
697 * WordPress dependencies
698 */
699
700
701 /**
702 * Internal dependencies
703 */
704
705
706
707 /**
708 * Attach a keyboard shortcut handler.
709 *
710 * @param {string} name Shortcut name.
711 * @param {Function} callback Shortcut callback.
712 * @param {Object} options Shortcut options.
713 * @param {boolean} options.isDisabled Whether to disable to shortut.
714 */
715 function useShortcut(name, callback, {
716 isDisabled = false
717 } = {}) {
718 const shortcuts = (0,external_wp_element_namespaceObject.useContext)(context);
719 const isMatch = useShortcutEventMatch();
720 const callbackRef = (0,external_wp_element_namespaceObject.useRef)();
721 (0,external_wp_element_namespaceObject.useEffect)(() => {
722 callbackRef.current = callback;
723 }, [callback]);
724 (0,external_wp_element_namespaceObject.useEffect)(() => {
725 if (isDisabled) {
726 return;
727 }
728 function _callback(event) {
729 if (isMatch(name, event)) {
730 callbackRef.current(event);
731 }
732 }
733 shortcuts.add(_callback);
734 return () => {
735 shortcuts.delete(_callback);
736 };
737 }, [name, isDisabled, shortcuts]);
738 }
739
740 ;// CONCATENATED MODULE: external "ReactJSXRuntime"
741 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
742 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/components/shortcut-provider.js
743 /**
744 * WordPress dependencies
745 */
746
747
748 /**
749 * Internal dependencies
750 */
751
752
753 const {
754 Provider
755 } = context;
756
757 /**
758 * Handles callbacks added to context by `useShortcut`.
759 * Adding a provider allows to register contextual shortcuts
760 * that are only active when a certain part of the UI is focused.
761 *
762 * @param {Object} props Props to pass to `div`.
763 *
764 * @return {Element} Component.
765 */
766 function ShortcutProvider(props) {
767 const [keyboardShortcuts] = (0,external_wp_element_namespaceObject.useState)(() => new Set());
768 function onKeyDown(event) {
769 if (props.onKeyDown) {
770 props.onKeyDown(event);
771 }
772 for (const keyboardShortcut of keyboardShortcuts) {
773 keyboardShortcut(event);
774 }
775 }
776
777 /* eslint-disable jsx-a11y/no-static-element-interactions */
778 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(Provider, {
779 value: keyboardShortcuts,
780 children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", {
781 ...props,
782 onKeyDown: onKeyDown
783 })
784 });
785 /* eslint-enable jsx-a11y/no-static-element-interactions */
786 }
787
788 ;// CONCATENATED MODULE: ./packages/keyboard-shortcuts/build-module/index.js
789
790
791
792
793
794 (window.wp = window.wp || {}).keyboardShortcuts = __webpack_exports__;
795 /******/ })()
796 ;