| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 (function() { 2 "use strict"; 3 var wp; 4 (wp ||= {}).keyboardShortcuts = (() => { 5 var __create = Object.create; 6 var __defProp = Object.defineProperty; 7 var __getOwnPropDesc = Object.getOwnPropertyDescriptor; 8 var __getOwnPropNames = Object.getOwnPropertyNames; 9 var __getProtoOf = Object.getPrototypeOf; 10 var __hasOwnProp = Object.prototype.hasOwnProperty; 11 var __commonJS = (cb, mod) => function __require() { 12 return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; 13 }; 14 var __export = (target, all) => { 15 for (var name in all) 16 __defProp(target, name, { get: all[name], enumerable: true }); 17 }; 18 var __copyProps = (to, from, except, desc) => { 19 if (from && typeof from === "object" || typeof from === "function") { 20 for (let key of __getOwnPropNames(from)) 21 if (!__hasOwnProp.call(to, key) && key !== except) 22 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); 23 } 24 return to; 25 }; 26 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( 27 // If the importer is in node compatibility mode or this is not an ESM 28 // file that has been converted to a CommonJS file using a Babel- 29 // compatible transform (i.e. "__esModule" has not been set), then set 30 // "default" to the CommonJS "module.exports" for node compatibility. 31 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, 32 mod 33 )); 34 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); 35 36 // package-external:@wordpress/data 37 var require_data = __commonJS({ 38 "package-external:@wordpress/data"(exports, module) { 39 module.exports = window.wp.data; 40 } 41 }); 42 43 // package-external:@wordpress/keycodes 44 var require_keycodes = __commonJS({ 45 "package-external:@wordpress/keycodes"(exports, module) { 46 module.exports = window.wp.keycodes; 47 } 48 }); 49 50 // package-external:@wordpress/element 51 var require_element = __commonJS({ 52 "package-external:@wordpress/element"(exports, module) { 53 module.exports = window.wp.element; 54 } 55 }); 56 57 // vendor-external:react/jsx-runtime 58 var require_jsx_runtime = __commonJS({ 59 "vendor-external:react/jsx-runtime"(exports, module) { 60 module.exports = window.ReactJSXRuntime; 61 } 62 }); 63 64 // packages/keyboard-shortcuts/build-module/index.mjs 65 var index_exports = {}; 66 __export(index_exports, { 67 ShortcutProvider: () => ShortcutProvider, 68 __unstableUseShortcutEventMatch: () => useShortcutEventMatch, 69 store: () => store, 70 useShortcut: () => useShortcut 71 }); 72 73 // packages/keyboard-shortcuts/build-module/store/index.mjs 74 var import_data2 = __toESM(require_data(), 1); 75 76 // packages/keyboard-shortcuts/build-module/store/reducer.mjs 77 function reducer(state = {}, action) { 78 switch (action.type) { 79 case "REGISTER_SHORTCUT": 80 return { 81 ...state, 82 [action.name]: { 83 category: action.category, 84 keyCombination: action.keyCombination, 85 aliases: action.aliases, 86 description: action.description 87 } 88 }; 89 case "UNREGISTER_SHORTCUT": 90 const { [action.name]: actionName, ...remainingState } = state; 91 return remainingState; 92 } 93 return state; 94 } 95 var reducer_default = reducer; 96 97 // packages/keyboard-shortcuts/build-module/store/actions.mjs 98 var actions_exports = {}; 99 __export(actions_exports, { 100 registerShortcut: () => registerShortcut, 101 unregisterShortcut: () => unregisterShortcut 102 }); 103 function registerShortcut({ 104 name, 105 category, 106 description, 107 keyCombination, 108 aliases 109 }) { 110 return { 111 type: "REGISTER_SHORTCUT", 112 name, 113 category, 114 keyCombination, 115 aliases, 116 description 117 }; 118 } 119 function unregisterShortcut(name) { 120 return { 121 type: "UNREGISTER_SHORTCUT", 122 name 123 }; 124 } 125 126 // packages/keyboard-shortcuts/build-module/store/selectors.mjs 127 var selectors_exports = {}; 128 __export(selectors_exports, { 129 getAllShortcutKeyCombinations: () => getAllShortcutKeyCombinations, 130 getAllShortcutRawKeyCombinations: () => getAllShortcutRawKeyCombinations, 131 getCategoryShortcuts: () => getCategoryShortcuts, 132 getShortcutAliases: () => getShortcutAliases, 133 getShortcutDescription: () => getShortcutDescription, 134 getShortcutKeyCombination: () => getShortcutKeyCombination, 135 getShortcutRepresentation: () => getShortcutRepresentation 136 }); 137 var import_data = __toESM(require_data(), 1); 138 var import_keycodes = __toESM(require_keycodes(), 1); 139 var EMPTY_ARRAY = []; 140 var FORMATTING_METHODS = { 141 /** 142 * Display formatting. 143 */ 144 display: import_keycodes.displayShortcut, 145 /** 146 * Raw shortcut formatting. 147 */ 148 raw: import_keycodes.rawShortcut, 149 /** 150 * ARIA label formatting. 151 */ 152 ariaLabel: import_keycodes.shortcutAriaLabel 153 }; 154 function getKeyCombinationRepresentation(shortcut, representation) { 155 if (!shortcut) { 156 return null; 157 } 158 return shortcut.modifier ? FORMATTING_METHODS[representation][shortcut.modifier]( 159 shortcut.character 160 ) : shortcut.character; 161 } 162 function getShortcutKeyCombination(state, name) { 163 return state[name] ? state[name].keyCombination : null; 164 } 165 function getShortcutRepresentation(state, name, representation = "display") { 166 const shortcut = getShortcutKeyCombination(state, name); 167 return getKeyCombinationRepresentation(shortcut, representation); 168 } 169 function getShortcutDescription(state, name) { 170 return state[name] ? state[name].description : null; 171 } 172 function getShortcutAliases(state, name) { 173 return state[name] && state[name].aliases ? state[name].aliases : EMPTY_ARRAY; 174 } 175 var getAllShortcutKeyCombinations = (0, import_data.createSelector)( 176 (state, name) => { 177 return [ 178 getShortcutKeyCombination(state, name), 179 ...getShortcutAliases(state, name) 180 ].filter( 181 (combination) => !!combination 182 ); 183 }, 184 (state, name) => [state[name]] 185 ); 186 var getAllShortcutRawKeyCombinations = (0, import_data.createSelector)( 187 (state, name) => { 188 return getAllShortcutKeyCombinations(state, name).map( 189 (combination) => getKeyCombinationRepresentation(combination, "raw") 190 ); 191 }, 192 (state, name) => [state[name]] 193 ); 194 var getCategoryShortcuts = (0, import_data.createSelector)( 195 (state, categoryName) => { 196 return Object.entries(state).filter(([, shortcut]) => shortcut.category === categoryName).map(([name]) => name); 197 }, 198 (state) => [state] 199 ); 200 201 // packages/keyboard-shortcuts/build-module/store/index.mjs 202 var STORE_NAME = "core/keyboard-shortcuts"; 203 var store = (0, import_data2.createReduxStore)(STORE_NAME, { 204 reducer: reducer_default, 205 actions: actions_exports, 206 selectors: selectors_exports 207 }); 208 (0, import_data2.register)(store); 209 210 // packages/keyboard-shortcuts/build-module/hooks/use-shortcut.mjs 211 var import_element3 = __toESM(require_element(), 1); 212 213 // packages/keyboard-shortcuts/build-module/hooks/use-shortcut-event-match.mjs 214 var import_data3 = __toESM(require_data(), 1); 215 var import_element = __toESM(require_element(), 1); 216 var import_keycodes2 = __toESM(require_keycodes(), 1); 217 function useShortcutEventMatch() { 218 const { getAllShortcutKeyCombinations: getAllShortcutKeyCombinations2 } = (0, import_data3.useSelect)( 219 store 220 ); 221 return (0, import_element.useCallback)( 222 (name, event) => { 223 return getAllShortcutKeyCombinations2(name).some( 224 (combination) => { 225 if (!combination) { 226 return false; 227 } 228 return import_keycodes2.isKeyboardEvent[combination.modifier ?? "undefined"](event, combination.character); 229 } 230 ); 231 }, 232 [getAllShortcutKeyCombinations2] 233 ); 234 } 235 236 // packages/keyboard-shortcuts/build-module/context.mjs 237 var import_element2 = __toESM(require_element(), 1); 238 var globalShortcuts = /* @__PURE__ */ new Set(); 239 var globalListener = (event) => { 240 for (const keyboardShortcut of globalShortcuts) { 241 keyboardShortcut(event); 242 } 243 }; 244 var context = (0, import_element2.createContext)({ 245 add: (shortcut) => { 246 if (globalShortcuts.size === 0) { 247 document.addEventListener("keydown", globalListener); 248 } 249 globalShortcuts.add(shortcut); 250 }, 251 delete: (shortcut) => { 252 globalShortcuts.delete(shortcut); 253 if (globalShortcuts.size === 0) { 254 document.removeEventListener("keydown", globalListener); 255 } 256 } 257 }); 258 context.displayName = "KeyboardShortcutsContext"; 259 260 // packages/keyboard-shortcuts/build-module/hooks/use-shortcut.mjs 261 function useShortcut(name, callback, { isDisabled = false } = {}) { 262 const shortcuts = (0, import_element3.useContext)(context); 263 const isMatch = useShortcutEventMatch(); 264 const callbackRef = (0, import_element3.useRef)(); 265 (0, import_element3.useEffect)(() => { 266 callbackRef.current = callback; 267 }, [callback]); 268 (0, import_element3.useEffect)(() => { 269 if (isDisabled) { 270 return; 271 } 272 function _callback(event) { 273 if (isMatch(name, event) && callbackRef.current) { 274 callbackRef.current(event); 275 } 276 } 277 shortcuts.add(_callback); 278 return () => { 279 shortcuts.delete(_callback); 280 }; 281 }, [name, isDisabled, shortcuts, isMatch]); 282 } 283 284 // packages/keyboard-shortcuts/build-module/components/shortcut-provider.mjs 285 var import_element4 = __toESM(require_element(), 1); 286 var import_jsx_runtime = __toESM(require_jsx_runtime(), 1); 287 var { Provider } = context; 288 function ShortcutProvider(props) { 289 const [keyboardShortcuts] = (0, import_element4.useState)( 290 () => /* @__PURE__ */ new Set() 291 ); 292 function onKeyDown(event) { 293 if (props.onKeyDown) { 294 props.onKeyDown(event); 295 } 296 const nativeEvent = event.nativeEvent; 297 for (const keyboardShortcut of keyboardShortcuts) { 298 keyboardShortcut(nativeEvent); 299 } 300 } 301 return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, { value: keyboardShortcuts, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ...props, onKeyDown }) }); 302 } 303 return __toCommonJS(index_exports); 304 })(); 305 (window.wp ||= {}).keyboardShortcuts = wp.keyboardShortcuts; 306 })();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Mon Aug 24 08:20:24 2026 | Cross-referenced by PHPXref |