kollapsminoriteten/wp-includes/js/dist/keyboard-shortcuts.js

293 lines
9.2 KiB
JavaScript
Raw Permalink Normal View History

2024-04-17 11:32:24 +02:00
/******/ (() => { // webpackBootstrap
2022-06-16 14:03:35 +02:00
/******/ "use strict";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define getter functions for harmony exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.d = (exports, definition) => {
2022-06-16 14:03:35 +02:00
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
2024-04-17 11:32:24 +02:00
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
/******/ /* webpack/runtime/make namespace object */
2024-04-17 11:32:24 +02:00
/******/ (() => {
2022-06-16 14:03:35 +02:00
/******/ // define __esModule on exports
2024-04-17 11:32:24 +02:00
/******/ __webpack_require__.r = (exports) => {
2022-06-16 14:03:35 +02:00
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
2020-05-06 17:23:38 +02:00
/******/ };
2024-04-17 11:32:24 +02:00
/******/ })();
2022-06-16 14:03:35 +02:00
/******/
2020-05-06 17:23:38 +02:00
/************************************************************************/
2022-06-16 14:03:35 +02:00
var __webpack_exports__ = {};
2021-07-23 11:58:50 +02:00
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
// EXPORTS
2022-06-16 14:03:35 +02:00
__webpack_require__.d(__webpack_exports__, {
2024-04-17 11:32:24 +02:00
ShortcutProvider: () => (/* reexport */ ShortcutProvider),
__unstableUseShortcutEventMatch: () => (/* reexport */ useShortcutEventMatch),
store: () => (/* reexport */ store),
useShortcut: () => (/* reexport */ useShortcut)
2022-06-16 14:03:35 +02:00
});
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
var actions_namespaceObject = {};
__webpack_require__.r(actions_namespaceObject);
2022-06-16 14:03:35 +02:00
__webpack_require__.d(actions_namespaceObject, {
2024-04-17 11:32:24 +02:00
registerShortcut: () => (registerShortcut),
unregisterShortcut: () => (unregisterShortcut)
2022-06-16 14:03:35 +02:00
});
2020-05-06 17:23:38 +02:00
2021-07-23 11:58:50 +02:00
// NAMESPACE OBJECT: ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
var selectors_namespaceObject = {};
__webpack_require__.r(selectors_namespaceObject);
2022-06-16 14:03:35 +02:00
__webpack_require__.d(selectors_namespaceObject, {
2024-04-17 11:32:24 +02:00
getAllShortcutKeyCombinations: () => (getAllShortcutKeyCombinations),
getAllShortcutRawKeyCombinations: () => (getAllShortcutRawKeyCombinations),
getCategoryShortcuts: () => (getCategoryShortcuts),
getShortcutAliases: () => (getShortcutAliases),
getShortcutDescription: () => (getShortcutDescription),
getShortcutKeyCombination: () => (getShortcutKeyCombination),
getShortcutRepresentation: () => (getShortcutRepresentation)
2022-06-16 14:03:35 +02:00
});
2020-05-06 17:23:38 +02:00
2025-04-25 12:30:07 +02:00
;// external ["wp","data"]
2024-04-17 11:32:24 +02:00
const external_wp_data_namespaceObject = window["wp"]["data"];
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/reducer.js
2023-09-26 10:33:34 +02:00
function reducer(state = {}, action) {
2021-07-23 11:58:50 +02:00
switch (action.type) {
2025-12-12 13:15:55 +01:00
case "REGISTER_SHORTCUT":
2023-12-07 09:44:11 +01:00
return {
...state,
2021-07-23 11:58:50 +02:00
[action.name]: {
category: action.category,
keyCombination: action.keyCombination,
aliases: action.aliases,
description: action.description
}
};
2025-12-12 13:15:55 +01:00
case "UNREGISTER_SHORTCUT":
const { [action.name]: actionName, ...remainingState } = state;
2022-12-15 17:47:31 +01:00
return remainingState;
2021-07-23 11:58:50 +02:00
}
return state;
2020-05-06 17:23:38 +02:00
}
2025-12-12 13:15:55 +01:00
var reducer_default = reducer;
2020-05-06 17:23:38 +02:00
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/actions.js
2023-09-26 10:33:34 +02:00
function registerShortcut({
name,
category,
description,
keyCombination,
aliases
}) {
2021-07-23 11:58:50 +02:00
return {
2025-12-12 13:15:55 +01:00
type: "REGISTER_SHORTCUT",
2021-07-23 11:58:50 +02:00
name,
category,
keyCombination,
aliases,
description
};
}
function unregisterShortcut(name) {
return {
2025-12-12 13:15:55 +01:00
type: "UNREGISTER_SHORTCUT",
2021-07-23 11:58:50 +02:00
name
};
2020-05-06 17:23:38 +02:00
}
2025-12-12 13:15:55 +01:00
2025-04-25 12:30:07 +02:00
;// external ["wp","keycodes"]
2024-04-17 11:32:24 +02:00
const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/selectors.js
2021-07-23 11:58:50 +02:00
2025-02-28 08:42:11 +01:00
2022-06-16 14:03:35 +02:00
const EMPTY_ARRAY = [];
const FORMATTING_METHODS = {
display: external_wp_keycodes_namespaceObject.displayShortcut,
raw: external_wp_keycodes_namespaceObject.rawShortcut,
ariaLabel: external_wp_keycodes_namespaceObject.shortcutAriaLabel
};
function getKeyCombinationRepresentation(shortcut, representation) {
if (!shortcut) {
return null;
}
2025-12-12 13:15:55 +01:00
return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier](
shortcut.character
) : shortcut.character;
2022-06-16 14:03:35 +02:00
}
function getShortcutKeyCombination(state, name) {
return state[name] ? state[name].keyCombination : null;
}
2025-12-12 13:15:55 +01:00
function getShortcutRepresentation(state, name, representation = "display") {
2022-06-16 14:03:35 +02:00
const shortcut = getShortcutKeyCombination(state, name);
return getKeyCombinationRepresentation(shortcut, representation);
2021-07-23 11:58:50 +02:00
}
2022-06-16 14:03:35 +02:00
function getShortcutDescription(state, name) {
return state[name] ? state[name].description : null;
2021-07-23 11:58:50 +02:00
}
2022-06-16 14:03:35 +02:00
function getShortcutAliases(state, name) {
return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY;
}
2025-12-12 13:15:55 +01:00
const getAllShortcutKeyCombinations = (0,external_wp_data_namespaceObject.createSelector)(
(state, name) => {
return [
getShortcutKeyCombination(state, name),
...getShortcutAliases(state, name)
].filter(Boolean);
},
(state, name) => [state[name]]
);
const getAllShortcutRawKeyCombinations = (0,external_wp_data_namespaceObject.createSelector)(
(state, name) => {
return getAllShortcutKeyCombinations(state, name).map(
(combination) => getKeyCombinationRepresentation(combination, "raw")
);
},
(state, name) => [state[name]]
);
const getCategoryShortcuts = (0,external_wp_data_namespaceObject.createSelector)(
(state, categoryName) => {
return Object.entries(state).filter(([, shortcut]) => shortcut.category === categoryName).map(([name]) => name);
},
(state) => [state]
);
2023-12-07 09:44:11 +01:00
2020-05-06 17:23:38 +02:00
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/store/index.js
2023-12-07 09:44:11 +01:00
2020-05-06 17:23:38 +02:00
2025-12-12 13:15:55 +01:00
const STORE_NAME = "core/keyboard-shortcuts";
2022-06-16 14:03:35 +02:00
const store = (0,external_wp_data_namespaceObject.createReduxStore)(STORE_NAME, {
2025-12-12 13:15:55 +01:00
reducer: reducer_default,
2022-06-16 14:03:35 +02:00
actions: actions_namespaceObject,
selectors: selectors_namespaceObject
});
(0,external_wp_data_namespaceObject.register)(store);
2020-05-06 17:23:38 +02:00
2025-12-12 13:15:55 +01:00
2025-04-25 12:30:07 +02:00
;// external ["wp","element"]
2024-04-17 11:32:24 +02:00
const external_wp_element_namespaceObject = window["wp"]["element"];
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.js
2023-12-07 09:44:11 +01:00
2020-05-06 17:23:38 +02:00
2022-06-16 14:03:35 +02:00
function useShortcutEventMatch() {
2025-12-12 13:15:55 +01:00
const { getAllShortcutKeyCombinations } = (0,external_wp_data_namespaceObject.useSelect)(
store
);
2022-06-16 14:03:35 +02:00
function isMatch(name, event) {
2025-12-12 13:15:55 +01:00
return getAllShortcutKeyCombinations(name).some(
({ modifier, character }) => {
return external_wp_keycodes_namespaceObject.isKeyboardEvent[modifier](event, character);
}
);
2022-06-16 14:03:35 +02:00
}
return isMatch;
}
2020-05-06 17:23:38 +02:00
2025-12-12 13:15:55 +01:00
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/context.js
2020-05-06 17:23:38 +02:00
2025-12-12 13:15:55 +01:00
const globalShortcuts = /* @__PURE__ */ new Set();
const globalListener = (event) => {
2023-12-07 09:44:11 +01:00
for (const keyboardShortcut of globalShortcuts) {
keyboardShortcut(event);
}
};
const context = (0,external_wp_element_namespaceObject.createContext)({
2025-12-12 13:15:55 +01:00
add: (shortcut) => {
2023-12-07 09:44:11 +01:00
if (globalShortcuts.size === 0) {
2025-12-12 13:15:55 +01:00
document.addEventListener("keydown", globalListener);
2023-12-07 09:44:11 +01:00
}
globalShortcuts.add(shortcut);
},
2025-12-12 13:15:55 +01:00
delete: (shortcut) => {
2023-12-07 09:44:11 +01:00
globalShortcuts.delete(shortcut);
if (globalShortcuts.size === 0) {
2025-12-12 13:15:55 +01:00
document.removeEventListener("keydown", globalListener);
2023-12-07 09:44:11 +01:00
}
}
});
2025-12-12 13:15:55 +01:00
context.displayName = "KeyboardShortcutsContext";
2020-05-06 17:23:38 +02:00
2023-12-07 09:44:11 +01:00
2025-12-12 13:15:55 +01:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/hooks/use-shortcut.js
2020-05-06 17:23:38 +02:00
2025-12-12 13:15:55 +01:00
function useShortcut(name, callback, { isDisabled = false } = {}) {
2022-06-16 14:03:35 +02:00
const shortcuts = (0,external_wp_element_namespaceObject.useContext)(context);
const isMatch = useShortcutEventMatch();
const callbackRef = (0,external_wp_element_namespaceObject.useRef)();
2023-12-07 09:44:11 +01:00
(0,external_wp_element_namespaceObject.useEffect)(() => {
callbackRef.current = callback;
}, [callback]);
2022-06-16 14:03:35 +02:00
(0,external_wp_element_namespaceObject.useEffect)(() => {
if (isDisabled) {
return;
}
function _callback(event) {
if (isMatch(name, event)) {
callbackRef.current(event);
}
}
2023-12-07 09:44:11 +01:00
shortcuts.add(_callback);
2022-06-16 14:03:35 +02:00
return () => {
2023-12-07 09:44:11 +01:00
shortcuts.delete(_callback);
2022-06-16 14:03:35 +02:00
};
2023-12-07 09:44:11 +01:00
}, [name, isDisabled, shortcuts]);
2022-06-16 14:03:35 +02:00
}
2022-04-02 10:26:41 +02:00
2025-12-12 13:15:55 +01:00
2025-04-25 12:30:07 +02:00
;// external "ReactJSXRuntime"
2025-02-28 08:42:11 +01:00
const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/components/shortcut-provider.js
2022-06-16 14:03:35 +02:00
2025-02-28 08:42:11 +01:00
2023-12-07 09:44:11 +01:00
2025-12-12 13:15:55 +01:00
const { Provider } = context;
2022-06-16 14:03:35 +02:00
function ShortcutProvider(props) {
2025-12-12 13:15:55 +01:00
const [keyboardShortcuts] = (0,external_wp_element_namespaceObject.useState)(() => /* @__PURE__ */ new Set());
2022-06-16 14:03:35 +02:00
function onKeyDown(event) {
2025-02-28 08:42:11 +01:00
if (props.onKeyDown) {
props.onKeyDown(event);
}
2023-12-07 09:44:11 +01:00
for (const keyboardShortcut of keyboardShortcuts) {
2022-06-16 14:03:35 +02:00
keyboardShortcut(event);
}
}
2025-12-12 13:15:55 +01:00
return /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)(Provider, { value: keyboardShortcuts, children: /* @__PURE__ */ (0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { ...props, onKeyDown }) });
2022-06-16 14:03:35 +02:00
}
2025-12-12 13:15:55 +01:00
2025-04-25 12:30:07 +02:00
;// ./node_modules/@wordpress/keyboard-shortcuts/build-module/index.js
2022-06-16 14:03:35 +02:00
2022-04-02 10:26:41 +02:00
2020-05-06 17:23:38 +02:00
2025-12-12 13:15:55 +01:00
2022-06-16 14:03:35 +02:00
(window.wp = window.wp || {}).keyboardShortcuts = __webpack_exports__;
/******/ })()
;