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