changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
21:48c4eec2b7e6 | 22:8c2e4d02f4ef |
---|---|
1 /******/ (() => { // webpackBootstrap |
1 /******/ (() => { // webpackBootstrap |
2 /******/ var __webpack_modules__ = ({ |
2 /******/ var __webpack_modules__ = ({ |
3 |
3 |
4 /***/ 6689: |
4 /***/ 1933: |
5 /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { |
5 /***/ ((module, exports, __webpack_require__) => { |
6 |
6 |
7 "use strict"; |
7 var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */ |
8 /* harmony export */ __webpack_require__.d(__webpack_exports__, { |
8 /** |
9 /* harmony export */ createUndoManager: () => (/* binding */ createUndoManager) |
9 * Copyright 2012-2017 Craig Campbell |
10 /* harmony export */ }); |
10 * |
11 /* harmony import */ var _wordpress_is_shallow_equal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(923); |
11 * Licensed under the Apache License, Version 2.0 (the "License"); |
12 /* harmony import */ var _wordpress_is_shallow_equal__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_is_shallow_equal__WEBPACK_IMPORTED_MODULE_0__); |
12 * you may not use this file except in compliance with the License. |
13 /** |
13 * You may obtain a copy of the License at |
14 * WordPress dependencies |
14 * |
15 */ |
15 * http://www.apache.org/licenses/LICENSE-2.0 |
16 |
16 * |
17 |
17 * Unless required by applicable law or agreed to in writing, software |
18 /** @typedef {import('./types').HistoryRecord} HistoryRecord */ |
18 * distributed under the License is distributed on an "AS IS" BASIS, |
19 /** @typedef {import('./types').HistoryChange} HistoryChange */ |
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
20 /** @typedef {import('./types').HistoryChanges} HistoryChanges */ |
20 * See the License for the specific language governing permissions and |
21 /** @typedef {import('./types').UndoManager} UndoManager */ |
21 * limitations under the License. |
22 |
22 * |
23 /** |
23 * Mousetrap is a simple keyboard shortcut library for Javascript with |
24 * Merge changes for a single item into a record of changes. |
24 * no external dependencies |
25 * |
25 * |
26 * @param {Record< string, HistoryChange >} changes1 Previous changes |
26 * @version 1.6.5 |
27 * @param {Record< string, HistoryChange >} changes2 NextChanges |
27 * @url craig.is/killing/mice |
28 * |
28 */ |
29 * @return {Record< string, HistoryChange >} Merged changes |
29 (function(window, document, undefined) { |
30 */ |
30 |
31 function mergeHistoryChanges(changes1, changes2) { |
31 // Check if mousetrap is used inside browser, if not, return |
32 /** |
32 if (!window) { |
33 * @type {Record< string, HistoryChange >} |
33 return; |
34 */ |
34 } |
35 const newChanges = { |
35 |
36 ...changes1 |
36 /** |
37 }; |
37 * mapping of special keycodes to their corresponding keys |
38 Object.entries(changes2).forEach(([key, value]) => { |
38 * |
39 if (newChanges[key]) { |
39 * everything in this dictionary cannot use keypress events |
40 newChanges[key] = { |
40 * so it has to be here to map to the correct keycodes for |
41 ...newChanges[key], |
41 * keyup/keydown events |
42 to: value.to |
42 * |
43 }; |
43 * @type {Object} |
44 } else { |
44 */ |
45 newChanges[key] = value; |
45 var _MAP = { |
46 } |
46 8: 'backspace', |
47 }); |
47 9: 'tab', |
48 return newChanges; |
48 13: 'enter', |
49 } |
49 16: 'shift', |
50 |
50 17: 'ctrl', |
51 /** |
51 18: 'alt', |
52 * Adds history changes for a single item into a record of changes. |
52 20: 'capslock', |
53 * |
53 27: 'esc', |
54 * @param {HistoryRecord} record The record to merge into. |
54 32: 'space', |
55 * @param {HistoryChanges} changes The changes to merge. |
55 33: 'pageup', |
56 */ |
56 34: 'pagedown', |
57 const addHistoryChangesIntoRecord = (record, changes) => { |
57 35: 'end', |
58 const existingChangesIndex = record?.findIndex(({ |
58 36: 'home', |
59 id: recordIdentifier |
59 37: 'left', |
60 }) => { |
60 38: 'up', |
61 return typeof recordIdentifier === 'string' ? recordIdentifier === changes.id : _wordpress_is_shallow_equal__WEBPACK_IMPORTED_MODULE_0___default()(recordIdentifier, changes.id); |
61 39: 'right', |
62 }); |
62 40: 'down', |
63 const nextRecord = [...record]; |
63 45: 'ins', |
64 if (existingChangesIndex !== -1) { |
64 46: 'del', |
65 // If the edit is already in the stack leave the initial "from" value. |
65 91: 'meta', |
66 nextRecord[existingChangesIndex] = { |
66 93: 'meta', |
67 id: changes.id, |
67 224: 'meta' |
68 changes: mergeHistoryChanges(nextRecord[existingChangesIndex].changes, changes.changes) |
|
69 }; |
68 }; |
70 } else { |
69 |
71 nextRecord.push(changes); |
|
72 } |
|
73 return nextRecord; |
|
74 }; |
|
75 |
|
76 /** |
|
77 * Creates an undo manager. |
|
78 * |
|
79 * @return {UndoManager} Undo manager. |
|
80 */ |
|
81 function createUndoManager() { |
|
82 /** |
|
83 * @type {HistoryRecord[]} |
|
84 */ |
|
85 let history = []; |
|
86 /** |
|
87 * @type {HistoryRecord} |
|
88 */ |
|
89 let stagedRecord = []; |
|
90 /** |
|
91 * @type {number} |
|
92 */ |
|
93 let offset = 0; |
|
94 const dropPendingRedos = () => { |
|
95 history = history.slice(0, offset || undefined); |
|
96 offset = 0; |
|
97 }; |
|
98 const appendStagedRecordToLatestHistoryRecord = () => { |
|
99 var _history$index; |
|
100 const index = history.length === 0 ? 0 : history.length - 1; |
|
101 let latestRecord = (_history$index = history[index]) !== null && _history$index !== void 0 ? _history$index : []; |
|
102 stagedRecord.forEach(changes => { |
|
103 latestRecord = addHistoryChangesIntoRecord(latestRecord, changes); |
|
104 }); |
|
105 stagedRecord = []; |
|
106 history[index] = latestRecord; |
|
107 }; |
|
108 |
|
109 /** |
|
110 * Checks whether a record is empty. |
|
111 * A record is considered empty if it the changes keep the same values. |
|
112 * Also updates to function values are ignored. |
|
113 * |
|
114 * @param {HistoryRecord} record |
|
115 * @return {boolean} Whether the record is empty. |
|
116 */ |
|
117 const isRecordEmpty = record => { |
|
118 const filteredRecord = record.filter(({ |
|
119 changes |
|
120 }) => { |
|
121 return Object.values(changes).some(({ |
|
122 from, |
|
123 to |
|
124 }) => typeof from !== 'function' && typeof to !== 'function' && !_wordpress_is_shallow_equal__WEBPACK_IMPORTED_MODULE_0___default()(from, to)); |
|
125 }); |
|
126 return !filteredRecord.length; |
|
127 }; |
|
128 return { |
|
129 /** |
70 /** |
130 * Record changes into the history. |
71 * mapping for special characters so they can support |
131 * |
72 * |
132 * @param {HistoryRecord=} record A record of changes to record. |
73 * this dictionary is only used incase you want to bind a |
133 * @param {boolean} isStaged Whether to immediately create an undo point or not. |
74 * keyup or keydown event to one of these keys |
75 * |
|
76 * @type {Object} |
|
134 */ |
77 */ |
135 addRecord(record, isStaged = false) { |
78 var _KEYCODE_MAP = { |
136 const isEmpty = !record || isRecordEmpty(record); |
79 106: '*', |
137 if (isStaged) { |
80 107: '+', |
138 if (isEmpty) { |
81 109: '-', |
139 return; |
82 110: '.', |
83 111 : '/', |
|
84 186: ';', |
|
85 187: '=', |
|
86 188: ',', |
|
87 189: '-', |
|
88 190: '.', |
|
89 191: '/', |
|
90 192: '`', |
|
91 219: '[', |
|
92 220: '\\', |
|
93 221: ']', |
|
94 222: '\'' |
|
95 }; |
|
96 |
|
97 /** |
|
98 * this is a mapping of keys that require shift on a US keypad |
|
99 * back to the non shift equivelents |
|
100 * |
|
101 * this is so you can use keyup events with these keys |
|
102 * |
|
103 * note that this will only work reliably on US keyboards |
|
104 * |
|
105 * @type {Object} |
|
106 */ |
|
107 var _SHIFT_MAP = { |
|
108 '~': '`', |
|
109 '!': '1', |
|
110 '@': '2', |
|
111 '#': '3', |
|
112 '$': '4', |
|
113 '%': '5', |
|
114 '^': '6', |
|
115 '&': '7', |
|
116 '*': '8', |
|
117 '(': '9', |
|
118 ')': '0', |
|
119 '_': '-', |
|
120 '+': '=', |
|
121 ':': ';', |
|
122 '\"': '\'', |
|
123 '<': ',', |
|
124 '>': '.', |
|
125 '?': '/', |
|
126 '|': '\\' |
|
127 }; |
|
128 |
|
129 /** |
|
130 * this is a list of special strings you can use to map |
|
131 * to modifier keys when you specify your keyboard shortcuts |
|
132 * |
|
133 * @type {Object} |
|
134 */ |
|
135 var _SPECIAL_ALIASES = { |
|
136 'option': 'alt', |
|
137 'command': 'meta', |
|
138 'return': 'enter', |
|
139 'escape': 'esc', |
|
140 'plus': '+', |
|
141 'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl' |
|
142 }; |
|
143 |
|
144 /** |
|
145 * variable to store the flipped version of _MAP from above |
|
146 * needed to check if we should use keypress or not when no action |
|
147 * is specified |
|
148 * |
|
149 * @type {Object|undefined} |
|
150 */ |
|
151 var _REVERSE_MAP; |
|
152 |
|
153 /** |
|
154 * loop through the f keys, f1 to f19 and add them to the map |
|
155 * programatically |
|
156 */ |
|
157 for (var i = 1; i < 20; ++i) { |
|
158 _MAP[111 + i] = 'f' + i; |
|
159 } |
|
160 |
|
161 /** |
|
162 * loop through to map numbers on the numeric keypad |
|
163 */ |
|
164 for (i = 0; i <= 9; ++i) { |
|
165 |
|
166 // This needs to use a string cause otherwise since 0 is falsey |
|
167 // mousetrap will never fire for numpad 0 pressed as part of a keydown |
|
168 // event. |
|
169 // |
|
170 // @see https://github.com/ccampbell/mousetrap/pull/258 |
|
171 _MAP[i + 96] = i.toString(); |
|
172 } |
|
173 |
|
174 /** |
|
175 * cross browser add event method |
|
176 * |
|
177 * @param {Element|HTMLDocument} object |
|
178 * @param {string} type |
|
179 * @param {Function} callback |
|
180 * @returns void |
|
181 */ |
|
182 function _addEvent(object, type, callback) { |
|
183 if (object.addEventListener) { |
|
184 object.addEventListener(type, callback, false); |
|
185 return; |
|
140 } |
186 } |
141 record.forEach(changes => { |
187 |
142 stagedRecord = addHistoryChangesIntoRecord(stagedRecord, changes); |
188 object.attachEvent('on' + type, callback); |
143 }); |
189 } |
144 } else { |
190 |
145 dropPendingRedos(); |
191 /** |
146 if (stagedRecord.length) { |
192 * takes the event and returns the key character |
147 appendStagedRecordToLatestHistoryRecord(); |
193 * |
194 * @param {Event} e |
|
195 * @return {string} |
|
196 */ |
|
197 function _characterFromEvent(e) { |
|
198 |
|
199 // for keypress events we should return the character as is |
|
200 if (e.type == 'keypress') { |
|
201 var character = String.fromCharCode(e.which); |
|
202 |
|
203 // if the shift key is not pressed then it is safe to assume |
|
204 // that we want the character to be lowercase. this means if |
|
205 // you accidentally have caps lock on then your key bindings |
|
206 // will continue to work |
|
207 // |
|
208 // the only side effect that might not be desired is if you |
|
209 // bind something like 'A' cause you want to trigger an |
|
210 // event when capital A is pressed caps lock will no longer |
|
211 // trigger the event. shift+a will though. |
|
212 if (!e.shiftKey) { |
|
213 character = character.toLowerCase(); |
|
214 } |
|
215 |
|
216 return character; |
|
148 } |
217 } |
149 if (isEmpty) { |
218 |
150 return; |
219 // for non keypress events the special maps are needed |
220 if (_MAP[e.which]) { |
|
221 return _MAP[e.which]; |
|
151 } |
222 } |
152 history.push(record); |
223 |
153 } |
224 if (_KEYCODE_MAP[e.which]) { |
154 }, |
225 return _KEYCODE_MAP[e.which]; |
155 undo() { |
226 } |
156 if (stagedRecord.length) { |
227 |
157 dropPendingRedos(); |
228 // if it is not in the special map |
158 appendStagedRecordToLatestHistoryRecord(); |
229 |
159 } |
230 // with keydown and keyup events the character seems to always |
160 const undoRecord = history[history.length - 1 + offset]; |
231 // come in as an uppercase character whether you are pressing shift |
161 if (!undoRecord) { |
232 // or not. we should make sure it is always lowercase for comparisons |
162 return; |
233 return String.fromCharCode(e.which).toLowerCase(); |
163 } |
234 } |
164 offset -= 1; |
235 |
165 return undoRecord; |
236 /** |
166 }, |
237 * checks if two arrays are equal |
167 redo() { |
238 * |
168 const redoRecord = history[history.length + offset]; |
239 * @param {Array} modifiers1 |
169 if (!redoRecord) { |
240 * @param {Array} modifiers2 |
170 return; |
241 * @returns {boolean} |
171 } |
242 */ |
172 offset += 1; |
243 function _modifiersMatch(modifiers1, modifiers2) { |
173 return redoRecord; |
244 return modifiers1.sort().join(',') === modifiers2.sort().join(','); |
174 }, |
245 } |
175 hasUndo() { |
246 |
176 return !!history[history.length - 1 + offset]; |
247 /** |
177 }, |
248 * takes a key event and figures out what the modifiers are |
178 hasRedo() { |
249 * |
179 return !!history[history.length + offset]; |
250 * @param {Event} e |
180 } |
251 * @returns {Array} |
181 }; |
252 */ |
182 } |
253 function _eventModifiers(e) { |
254 var modifiers = []; |
|
255 |
|
256 if (e.shiftKey) { |
|
257 modifiers.push('shift'); |
|
258 } |
|
259 |
|
260 if (e.altKey) { |
|
261 modifiers.push('alt'); |
|
262 } |
|
263 |
|
264 if (e.ctrlKey) { |
|
265 modifiers.push('ctrl'); |
|
266 } |
|
267 |
|
268 if (e.metaKey) { |
|
269 modifiers.push('meta'); |
|
270 } |
|
271 |
|
272 return modifiers; |
|
273 } |
|
274 |
|
275 /** |
|
276 * prevents default for this event |
|
277 * |
|
278 * @param {Event} e |
|
279 * @returns void |
|
280 */ |
|
281 function _preventDefault(e) { |
|
282 if (e.preventDefault) { |
|
283 e.preventDefault(); |
|
284 return; |
|
285 } |
|
286 |
|
287 e.returnValue = false; |
|
288 } |
|
289 |
|
290 /** |
|
291 * stops propogation for this event |
|
292 * |
|
293 * @param {Event} e |
|
294 * @returns void |
|
295 */ |
|
296 function _stopPropagation(e) { |
|
297 if (e.stopPropagation) { |
|
298 e.stopPropagation(); |
|
299 return; |
|
300 } |
|
301 |
|
302 e.cancelBubble = true; |
|
303 } |
|
304 |
|
305 /** |
|
306 * determines if the keycode specified is a modifier key or not |
|
307 * |
|
308 * @param {string} key |
|
309 * @returns {boolean} |
|
310 */ |
|
311 function _isModifier(key) { |
|
312 return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta'; |
|
313 } |
|
314 |
|
315 /** |
|
316 * reverses the map lookup so that we can look for specific keys |
|
317 * to see what can and can't use keypress |
|
318 * |
|
319 * @return {Object} |
|
320 */ |
|
321 function _getReverseMap() { |
|
322 if (!_REVERSE_MAP) { |
|
323 _REVERSE_MAP = {}; |
|
324 for (var key in _MAP) { |
|
325 |
|
326 // pull out the numeric keypad from here cause keypress should |
|
327 // be able to detect the keys from the character |
|
328 if (key > 95 && key < 112) { |
|
329 continue; |
|
330 } |
|
331 |
|
332 if (_MAP.hasOwnProperty(key)) { |
|
333 _REVERSE_MAP[_MAP[key]] = key; |
|
334 } |
|
335 } |
|
336 } |
|
337 return _REVERSE_MAP; |
|
338 } |
|
339 |
|
340 /** |
|
341 * picks the best action based on the key combination |
|
342 * |
|
343 * @param {string} key - character for key |
|
344 * @param {Array} modifiers |
|
345 * @param {string=} action passed in |
|
346 */ |
|
347 function _pickBestAction(key, modifiers, action) { |
|
348 |
|
349 // if no action was picked in we should try to pick the one |
|
350 // that we think would work best for this key |
|
351 if (!action) { |
|
352 action = _getReverseMap()[key] ? 'keydown' : 'keypress'; |
|
353 } |
|
354 |
|
355 // modifier keys don't work as expected with keypress, |
|
356 // switch to keydown |
|
357 if (action == 'keypress' && modifiers.length) { |
|
358 action = 'keydown'; |
|
359 } |
|
360 |
|
361 return action; |
|
362 } |
|
363 |
|
364 /** |
|
365 * Converts from a string key combination to an array |
|
366 * |
|
367 * @param {string} combination like "command+shift+l" |
|
368 * @return {Array} |
|
369 */ |
|
370 function _keysFromString(combination) { |
|
371 if (combination === '+') { |
|
372 return ['+']; |
|
373 } |
|
374 |
|
375 combination = combination.replace(/\+{2}/g, '+plus'); |
|
376 return combination.split('+'); |
|
377 } |
|
378 |
|
379 /** |
|
380 * Gets info for a specific key combination |
|
381 * |
|
382 * @param {string} combination key combination ("command+s" or "a" or "*") |
|
383 * @param {string=} action |
|
384 * @returns {Object} |
|
385 */ |
|
386 function _getKeyInfo(combination, action) { |
|
387 var keys; |
|
388 var key; |
|
389 var i; |
|
390 var modifiers = []; |
|
391 |
|
392 // take the keys from this pattern and figure out what the actual |
|
393 // pattern is all about |
|
394 keys = _keysFromString(combination); |
|
395 |
|
396 for (i = 0; i < keys.length; ++i) { |
|
397 key = keys[i]; |
|
398 |
|
399 // normalize key names |
|
400 if (_SPECIAL_ALIASES[key]) { |
|
401 key = _SPECIAL_ALIASES[key]; |
|
402 } |
|
403 |
|
404 // if this is not a keypress event then we should |
|
405 // be smart about using shift keys |
|
406 // this will only work for US keyboards however |
|
407 if (action && action != 'keypress' && _SHIFT_MAP[key]) { |
|
408 key = _SHIFT_MAP[key]; |
|
409 modifiers.push('shift'); |
|
410 } |
|
411 |
|
412 // if this key is a modifier then add it to the list of modifiers |
|
413 if (_isModifier(key)) { |
|
414 modifiers.push(key); |
|
415 } |
|
416 } |
|
417 |
|
418 // depending on what the key combination is |
|
419 // we will try to pick the best event for it |
|
420 action = _pickBestAction(key, modifiers, action); |
|
421 |
|
422 return { |
|
423 key: key, |
|
424 modifiers: modifiers, |
|
425 action: action |
|
426 }; |
|
427 } |
|
428 |
|
429 function _belongsTo(element, ancestor) { |
|
430 if (element === null || element === document) { |
|
431 return false; |
|
432 } |
|
433 |
|
434 if (element === ancestor) { |
|
435 return true; |
|
436 } |
|
437 |
|
438 return _belongsTo(element.parentNode, ancestor); |
|
439 } |
|
440 |
|
441 function Mousetrap(targetElement) { |
|
442 var self = this; |
|
443 |
|
444 targetElement = targetElement || document; |
|
445 |
|
446 if (!(self instanceof Mousetrap)) { |
|
447 return new Mousetrap(targetElement); |
|
448 } |
|
449 |
|
450 /** |
|
451 * element to attach key events to |
|
452 * |
|
453 * @type {Element} |
|
454 */ |
|
455 self.target = targetElement; |
|
456 |
|
457 /** |
|
458 * a list of all the callbacks setup via Mousetrap.bind() |
|
459 * |
|
460 * @type {Object} |
|
461 */ |
|
462 self._callbacks = {}; |
|
463 |
|
464 /** |
|
465 * direct map of string combinations to callbacks used for trigger() |
|
466 * |
|
467 * @type {Object} |
|
468 */ |
|
469 self._directMap = {}; |
|
470 |
|
471 /** |
|
472 * keeps track of what level each sequence is at since multiple |
|
473 * sequences can start out with the same sequence |
|
474 * |
|
475 * @type {Object} |
|
476 */ |
|
477 var _sequenceLevels = {}; |
|
478 |
|
479 /** |
|
480 * variable to store the setTimeout call |
|
481 * |
|
482 * @type {null|number} |
|
483 */ |
|
484 var _resetTimer; |
|
485 |
|
486 /** |
|
487 * temporary state where we will ignore the next keyup |
|
488 * |
|
489 * @type {boolean|string} |
|
490 */ |
|
491 var _ignoreNextKeyup = false; |
|
492 |
|
493 /** |
|
494 * temporary state where we will ignore the next keypress |
|
495 * |
|
496 * @type {boolean} |
|
497 */ |
|
498 var _ignoreNextKeypress = false; |
|
499 |
|
500 /** |
|
501 * are we currently inside of a sequence? |
|
502 * type of action ("keyup" or "keydown" or "keypress") or false |
|
503 * |
|
504 * @type {boolean|string} |
|
505 */ |
|
506 var _nextExpectedAction = false; |
|
507 |
|
508 /** |
|
509 * resets all sequence counters except for the ones passed in |
|
510 * |
|
511 * @param {Object} doNotReset |
|
512 * @returns void |
|
513 */ |
|
514 function _resetSequences(doNotReset) { |
|
515 doNotReset = doNotReset || {}; |
|
516 |
|
517 var activeSequences = false, |
|
518 key; |
|
519 |
|
520 for (key in _sequenceLevels) { |
|
521 if (doNotReset[key]) { |
|
522 activeSequences = true; |
|
523 continue; |
|
524 } |
|
525 _sequenceLevels[key] = 0; |
|
526 } |
|
527 |
|
528 if (!activeSequences) { |
|
529 _nextExpectedAction = false; |
|
530 } |
|
531 } |
|
532 |
|
533 /** |
|
534 * finds all callbacks that match based on the keycode, modifiers, |
|
535 * and action |
|
536 * |
|
537 * @param {string} character |
|
538 * @param {Array} modifiers |
|
539 * @param {Event|Object} e |
|
540 * @param {string=} sequenceName - name of the sequence we are looking for |
|
541 * @param {string=} combination |
|
542 * @param {number=} level |
|
543 * @returns {Array} |
|
544 */ |
|
545 function _getMatches(character, modifiers, e, sequenceName, combination, level) { |
|
546 var i; |
|
547 var callback; |
|
548 var matches = []; |
|
549 var action = e.type; |
|
550 |
|
551 // if there are no events related to this keycode |
|
552 if (!self._callbacks[character]) { |
|
553 return []; |
|
554 } |
|
555 |
|
556 // if a modifier key is coming up on its own we should allow it |
|
557 if (action == 'keyup' && _isModifier(character)) { |
|
558 modifiers = [character]; |
|
559 } |
|
560 |
|
561 // loop through all callbacks for the key that was pressed |
|
562 // and see if any of them match |
|
563 for (i = 0; i < self._callbacks[character].length; ++i) { |
|
564 callback = self._callbacks[character][i]; |
|
565 |
|
566 // if a sequence name is not specified, but this is a sequence at |
|
567 // the wrong level then move onto the next match |
|
568 if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) { |
|
569 continue; |
|
570 } |
|
571 |
|
572 // if the action we are looking for doesn't match the action we got |
|
573 // then we should keep going |
|
574 if (action != callback.action) { |
|
575 continue; |
|
576 } |
|
577 |
|
578 // if this is a keypress event and the meta key and control key |
|
579 // are not pressed that means that we need to only look at the |
|
580 // character, otherwise check the modifiers as well |
|
581 // |
|
582 // chrome will not fire a keypress if meta or control is down |
|
583 // safari will fire a keypress if meta or meta+shift is down |
|
584 // firefox will fire a keypress if meta or control is down |
|
585 if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) { |
|
586 |
|
587 // when you bind a combination or sequence a second time it |
|
588 // should overwrite the first one. if a sequenceName or |
|
589 // combination is specified in this call it does just that |
|
590 // |
|
591 // @todo make deleting its own method? |
|
592 var deleteCombo = !sequenceName && callback.combo == combination; |
|
593 var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level; |
|
594 if (deleteCombo || deleteSequence) { |
|
595 self._callbacks[character].splice(i, 1); |
|
596 } |
|
597 |
|
598 matches.push(callback); |
|
599 } |
|
600 } |
|
601 |
|
602 return matches; |
|
603 } |
|
604 |
|
605 /** |
|
606 * actually calls the callback function |
|
607 * |
|
608 * if your callback function returns false this will use the jquery |
|
609 * convention - prevent default and stop propogation on the event |
|
610 * |
|
611 * @param {Function} callback |
|
612 * @param {Event} e |
|
613 * @returns void |
|
614 */ |
|
615 function _fireCallback(callback, e, combo, sequence) { |
|
616 |
|
617 // if this event should not happen stop here |
|
618 if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) { |
|
619 return; |
|
620 } |
|
621 |
|
622 if (callback(e, combo) === false) { |
|
623 _preventDefault(e); |
|
624 _stopPropagation(e); |
|
625 } |
|
626 } |
|
627 |
|
628 /** |
|
629 * handles a character key event |
|
630 * |
|
631 * @param {string} character |
|
632 * @param {Array} modifiers |
|
633 * @param {Event} e |
|
634 * @returns void |
|
635 */ |
|
636 self._handleKey = function(character, modifiers, e) { |
|
637 var callbacks = _getMatches(character, modifiers, e); |
|
638 var i; |
|
639 var doNotReset = {}; |
|
640 var maxLevel = 0; |
|
641 var processedSequenceCallback = false; |
|
642 |
|
643 // Calculate the maxLevel for sequences so we can only execute the longest callback sequence |
|
644 for (i = 0; i < callbacks.length; ++i) { |
|
645 if (callbacks[i].seq) { |
|
646 maxLevel = Math.max(maxLevel, callbacks[i].level); |
|
647 } |
|
648 } |
|
649 |
|
650 // loop through matching callbacks for this key event |
|
651 for (i = 0; i < callbacks.length; ++i) { |
|
652 |
|
653 // fire for all sequence callbacks |
|
654 // this is because if for example you have multiple sequences |
|
655 // bound such as "g i" and "g t" they both need to fire the |
|
656 // callback for matching g cause otherwise you can only ever |
|
657 // match the first one |
|
658 if (callbacks[i].seq) { |
|
659 |
|
660 // only fire callbacks for the maxLevel to prevent |
|
661 // subsequences from also firing |
|
662 // |
|
663 // for example 'a option b' should not cause 'option b' to fire |
|
664 // even though 'option b' is part of the other sequence |
|
665 // |
|
666 // any sequences that do not match here will be discarded |
|
667 // below by the _resetSequences call |
|
668 if (callbacks[i].level != maxLevel) { |
|
669 continue; |
|
670 } |
|
671 |
|
672 processedSequenceCallback = true; |
|
673 |
|
674 // keep a list of which sequences were matches for later |
|
675 doNotReset[callbacks[i].seq] = 1; |
|
676 _fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq); |
|
677 continue; |
|
678 } |
|
679 |
|
680 // if there were no sequence matches but we are still here |
|
681 // that means this is a regular match so we should fire that |
|
682 if (!processedSequenceCallback) { |
|
683 _fireCallback(callbacks[i].callback, e, callbacks[i].combo); |
|
684 } |
|
685 } |
|
686 |
|
687 // if the key you pressed matches the type of sequence without |
|
688 // being a modifier (ie "keyup" or "keypress") then we should |
|
689 // reset all sequences that were not matched by this event |
|
690 // |
|
691 // this is so, for example, if you have the sequence "h a t" and you |
|
692 // type "h e a r t" it does not match. in this case the "e" will |
|
693 // cause the sequence to reset |
|
694 // |
|
695 // modifier keys are ignored because you can have a sequence |
|
696 // that contains modifiers such as "enter ctrl+space" and in most |
|
697 // cases the modifier key will be pressed before the next key |
|
698 // |
|
699 // also if you have a sequence such as "ctrl+b a" then pressing the |
|
700 // "b" key will trigger a "keypress" and a "keydown" |
|
701 // |
|
702 // the "keydown" is expected when there is a modifier, but the |
|
703 // "keypress" ends up matching the _nextExpectedAction since it occurs |
|
704 // after and that causes the sequence to reset |
|
705 // |
|
706 // we ignore keypresses in a sequence that directly follow a keydown |
|
707 // for the same character |
|
708 var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress; |
|
709 if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) { |
|
710 _resetSequences(doNotReset); |
|
711 } |
|
712 |
|
713 _ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown'; |
|
714 }; |
|
715 |
|
716 /** |
|
717 * handles a keydown event |
|
718 * |
|
719 * @param {Event} e |
|
720 * @returns void |
|
721 */ |
|
722 function _handleKeyEvent(e) { |
|
723 |
|
724 // normalize e.which for key events |
|
725 // @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion |
|
726 if (typeof e.which !== 'number') { |
|
727 e.which = e.keyCode; |
|
728 } |
|
729 |
|
730 var character = _characterFromEvent(e); |
|
731 |
|
732 // no character found then stop |
|
733 if (!character) { |
|
734 return; |
|
735 } |
|
736 |
|
737 // need to use === for the character check because the character can be 0 |
|
738 if (e.type == 'keyup' && _ignoreNextKeyup === character) { |
|
739 _ignoreNextKeyup = false; |
|
740 return; |
|
741 } |
|
742 |
|
743 self.handleKey(character, _eventModifiers(e), e); |
|
744 } |
|
745 |
|
746 /** |
|
747 * called to set a 1 second timeout on the specified sequence |
|
748 * |
|
749 * this is so after each key press in the sequence you have 1 second |
|
750 * to press the next key before you have to start over |
|
751 * |
|
752 * @returns void |
|
753 */ |
|
754 function _resetSequenceTimer() { |
|
755 clearTimeout(_resetTimer); |
|
756 _resetTimer = setTimeout(_resetSequences, 1000); |
|
757 } |
|
758 |
|
759 /** |
|
760 * binds a key sequence to an event |
|
761 * |
|
762 * @param {string} combo - combo specified in bind call |
|
763 * @param {Array} keys |
|
764 * @param {Function} callback |
|
765 * @param {string=} action |
|
766 * @returns void |
|
767 */ |
|
768 function _bindSequence(combo, keys, callback, action) { |
|
769 |
|
770 // start off by adding a sequence level record for this combination |
|
771 // and setting the level to 0 |
|
772 _sequenceLevels[combo] = 0; |
|
773 |
|
774 /** |
|
775 * callback to increase the sequence level for this sequence and reset |
|
776 * all other sequences that were active |
|
777 * |
|
778 * @param {string} nextAction |
|
779 * @returns {Function} |
|
780 */ |
|
781 function _increaseSequence(nextAction) { |
|
782 return function() { |
|
783 _nextExpectedAction = nextAction; |
|
784 ++_sequenceLevels[combo]; |
|
785 _resetSequenceTimer(); |
|
786 }; |
|
787 } |
|
788 |
|
789 /** |
|
790 * wraps the specified callback inside of another function in order |
|
791 * to reset all sequence counters as soon as this sequence is done |
|
792 * |
|
793 * @param {Event} e |
|
794 * @returns void |
|
795 */ |
|
796 function _callbackAndReset(e) { |
|
797 _fireCallback(callback, e, combo); |
|
798 |
|
799 // we should ignore the next key up if the action is key down |
|
800 // or keypress. this is so if you finish a sequence and |
|
801 // release the key the final key will not trigger a keyup |
|
802 if (action !== 'keyup') { |
|
803 _ignoreNextKeyup = _characterFromEvent(e); |
|
804 } |
|
805 |
|
806 // weird race condition if a sequence ends with the key |
|
807 // another sequence begins with |
|
808 setTimeout(_resetSequences, 10); |
|
809 } |
|
810 |
|
811 // loop through keys one at a time and bind the appropriate callback |
|
812 // function. for any key leading up to the final one it should |
|
813 // increase the sequence. after the final, it should reset all sequences |
|
814 // |
|
815 // if an action is specified in the original bind call then that will |
|
816 // be used throughout. otherwise we will pass the action that the |
|
817 // next key in the sequence should match. this allows a sequence |
|
818 // to mix and match keypress and keydown events depending on which |
|
819 // ones are better suited to the key provided |
|
820 for (var i = 0; i < keys.length; ++i) { |
|
821 var isFinal = i + 1 === keys.length; |
|
822 var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action); |
|
823 _bindSingle(keys[i], wrappedCallback, action, combo, i); |
|
824 } |
|
825 } |
|
826 |
|
827 /** |
|
828 * binds a single keyboard combination |
|
829 * |
|
830 * @param {string} combination |
|
831 * @param {Function} callback |
|
832 * @param {string=} action |
|
833 * @param {string=} sequenceName - name of sequence if part of sequence |
|
834 * @param {number=} level - what part of the sequence the command is |
|
835 * @returns void |
|
836 */ |
|
837 function _bindSingle(combination, callback, action, sequenceName, level) { |
|
838 |
|
839 // store a direct mapped reference for use with Mousetrap.trigger |
|
840 self._directMap[combination + ':' + action] = callback; |
|
841 |
|
842 // make sure multiple spaces in a row become a single space |
|
843 combination = combination.replace(/\s+/g, ' '); |
|
844 |
|
845 var sequence = combination.split(' '); |
|
846 var info; |
|
847 |
|
848 // if this pattern is a sequence of keys then run through this method |
|
849 // to reprocess each pattern one key at a time |
|
850 if (sequence.length > 1) { |
|
851 _bindSequence(combination, sequence, callback, action); |
|
852 return; |
|
853 } |
|
854 |
|
855 info = _getKeyInfo(combination, action); |
|
856 |
|
857 // make sure to initialize array if this is the first time |
|
858 // a callback is added for this key |
|
859 self._callbacks[info.key] = self._callbacks[info.key] || []; |
|
860 |
|
861 // remove an existing match if there is one |
|
862 _getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level); |
|
863 |
|
864 // add this call back to the array |
|
865 // if it is a sequence put it at the beginning |
|
866 // if not put it at the end |
|
867 // |
|
868 // this is important because the way these are processed expects |
|
869 // the sequence ones to come first |
|
870 self._callbacks[info.key][sequenceName ? 'unshift' : 'push']({ |
|
871 callback: callback, |
|
872 modifiers: info.modifiers, |
|
873 action: info.action, |
|
874 seq: sequenceName, |
|
875 level: level, |
|
876 combo: combination |
|
877 }); |
|
878 } |
|
879 |
|
880 /** |
|
881 * binds multiple combinations to the same callback |
|
882 * |
|
883 * @param {Array} combinations |
|
884 * @param {Function} callback |
|
885 * @param {string|undefined} action |
|
886 * @returns void |
|
887 */ |
|
888 self._bindMultiple = function(combinations, callback, action) { |
|
889 for (var i = 0; i < combinations.length; ++i) { |
|
890 _bindSingle(combinations[i], callback, action); |
|
891 } |
|
892 }; |
|
893 |
|
894 // start! |
|
895 _addEvent(targetElement, 'keypress', _handleKeyEvent); |
|
896 _addEvent(targetElement, 'keydown', _handleKeyEvent); |
|
897 _addEvent(targetElement, 'keyup', _handleKeyEvent); |
|
898 } |
|
899 |
|
900 /** |
|
901 * binds an event to mousetrap |
|
902 * |
|
903 * can be a single key, a combination of keys separated with +, |
|
904 * an array of keys, or a sequence of keys separated by spaces |
|
905 * |
|
906 * be sure to list the modifier keys first to make sure that the |
|
907 * correct key ends up getting bound (the last key in the pattern) |
|
908 * |
|
909 * @param {string|Array} keys |
|
910 * @param {Function} callback |
|
911 * @param {string=} action - 'keypress', 'keydown', or 'keyup' |
|
912 * @returns void |
|
913 */ |
|
914 Mousetrap.prototype.bind = function(keys, callback, action) { |
|
915 var self = this; |
|
916 keys = keys instanceof Array ? keys : [keys]; |
|
917 self._bindMultiple.call(self, keys, callback, action); |
|
918 return self; |
|
919 }; |
|
920 |
|
921 /** |
|
922 * unbinds an event to mousetrap |
|
923 * |
|
924 * the unbinding sets the callback function of the specified key combo |
|
925 * to an empty function and deletes the corresponding key in the |
|
926 * _directMap dict. |
|
927 * |
|
928 * TODO: actually remove this from the _callbacks dictionary instead |
|
929 * of binding an empty function |
|
930 * |
|
931 * the keycombo+action has to be exactly the same as |
|
932 * it was defined in the bind method |
|
933 * |
|
934 * @param {string|Array} keys |
|
935 * @param {string} action |
|
936 * @returns void |
|
937 */ |
|
938 Mousetrap.prototype.unbind = function(keys, action) { |
|
939 var self = this; |
|
940 return self.bind.call(self, keys, function() {}, action); |
|
941 }; |
|
942 |
|
943 /** |
|
944 * triggers an event that has already been bound |
|
945 * |
|
946 * @param {string} keys |
|
947 * @param {string=} action |
|
948 * @returns void |
|
949 */ |
|
950 Mousetrap.prototype.trigger = function(keys, action) { |
|
951 var self = this; |
|
952 if (self._directMap[keys + ':' + action]) { |
|
953 self._directMap[keys + ':' + action]({}, keys); |
|
954 } |
|
955 return self; |
|
956 }; |
|
957 |
|
958 /** |
|
959 * resets the library back to its initial state. this is useful |
|
960 * if you want to clear out the current keyboard shortcuts and bind |
|
961 * new ones - for example if you switch to another page |
|
962 * |
|
963 * @returns void |
|
964 */ |
|
965 Mousetrap.prototype.reset = function() { |
|
966 var self = this; |
|
967 self._callbacks = {}; |
|
968 self._directMap = {}; |
|
969 return self; |
|
970 }; |
|
971 |
|
972 /** |
|
973 * should we stop this event before firing off callbacks |
|
974 * |
|
975 * @param {Event} e |
|
976 * @param {Element} element |
|
977 * @return {boolean} |
|
978 */ |
|
979 Mousetrap.prototype.stopCallback = function(e, element) { |
|
980 var self = this; |
|
981 |
|
982 // if the element has the class "mousetrap" then no need to stop |
|
983 if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { |
|
984 return false; |
|
985 } |
|
986 |
|
987 if (_belongsTo(element, self.target)) { |
|
988 return false; |
|
989 } |
|
990 |
|
991 // Events originating from a shadow DOM are re-targetted and `e.target` is the shadow host, |
|
992 // not the initial event target in the shadow tree. Note that not all events cross the |
|
993 // shadow boundary. |
|
994 // For shadow trees with `mode: 'open'`, the initial event target is the first element in |
|
995 // the event’s composed path. For shadow trees with `mode: 'closed'`, the initial event |
|
996 // target cannot be obtained. |
|
997 if ('composedPath' in e && typeof e.composedPath === 'function') { |
|
998 // For open shadow trees, update `element` so that the following check works. |
|
999 var initialEventTarget = e.composedPath()[0]; |
|
1000 if (initialEventTarget !== e.target) { |
|
1001 element = initialEventTarget; |
|
1002 } |
|
1003 } |
|
1004 |
|
1005 // stop for input, select, and textarea |
|
1006 return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable; |
|
1007 }; |
|
1008 |
|
1009 /** |
|
1010 * exposes _handleKey publicly so it can be overwritten by extensions |
|
1011 */ |
|
1012 Mousetrap.prototype.handleKey = function() { |
|
1013 var self = this; |
|
1014 return self._handleKey.apply(self, arguments); |
|
1015 }; |
|
1016 |
|
1017 /** |
|
1018 * allow custom key mappings |
|
1019 */ |
|
1020 Mousetrap.addKeycodes = function(object) { |
|
1021 for (var key in object) { |
|
1022 if (object.hasOwnProperty(key)) { |
|
1023 _MAP[key] = object[key]; |
|
1024 } |
|
1025 } |
|
1026 _REVERSE_MAP = null; |
|
1027 }; |
|
1028 |
|
1029 /** |
|
1030 * Init the global mousetrap functions |
|
1031 * |
|
1032 * This method is needed to allow the global mousetrap functions to work |
|
1033 * now that mousetrap is a constructor function. |
|
1034 */ |
|
1035 Mousetrap.init = function() { |
|
1036 var documentMousetrap = Mousetrap(document); |
|
1037 for (var method in documentMousetrap) { |
|
1038 if (method.charAt(0) !== '_') { |
|
1039 Mousetrap[method] = (function(method) { |
|
1040 return function() { |
|
1041 return documentMousetrap[method].apply(documentMousetrap, arguments); |
|
1042 }; |
|
1043 } (method)); |
|
1044 } |
|
1045 } |
|
1046 }; |
|
1047 |
|
1048 Mousetrap.init(); |
|
1049 |
|
1050 // expose mousetrap to the global object |
|
1051 window.Mousetrap = Mousetrap; |
|
1052 |
|
1053 // expose as a common js module |
|
1054 if ( true && module.exports) { |
|
1055 module.exports = Mousetrap; |
|
1056 } |
|
1057 |
|
1058 // expose mousetrap as an AMD module |
|
1059 if (true) { |
|
1060 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() { |
|
1061 return Mousetrap; |
|
1062 }).call(exports, __webpack_require__, exports, module), |
|
1063 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
|
1064 } |
|
1065 }) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null); |
|
183 |
1066 |
184 |
1067 |
185 /***/ }), |
1068 /***/ }), |
186 |
1069 |
187 /***/ 3758: |
1070 /***/ 3758: |
1073 .default; |
1956 .default; |
1074 }); |
1957 }); |
1075 |
1958 |
1076 /***/ }), |
1959 /***/ }), |
1077 |
1960 |
1078 /***/ 1933: |
|
1079 /***/ ((module, exports, __webpack_require__) => { |
|
1080 |
|
1081 var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */ |
|
1082 /** |
|
1083 * Copyright 2012-2017 Craig Campbell |
|
1084 * |
|
1085 * Licensed under the Apache License, Version 2.0 (the "License"); |
|
1086 * you may not use this file except in compliance with the License. |
|
1087 * You may obtain a copy of the License at |
|
1088 * |
|
1089 * http://www.apache.org/licenses/LICENSE-2.0 |
|
1090 * |
|
1091 * Unless required by applicable law or agreed to in writing, software |
|
1092 * distributed under the License is distributed on an "AS IS" BASIS, |
|
1093 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
1094 * See the License for the specific language governing permissions and |
|
1095 * limitations under the License. |
|
1096 * |
|
1097 * Mousetrap is a simple keyboard shortcut library for Javascript with |
|
1098 * no external dependencies |
|
1099 * |
|
1100 * @version 1.6.5 |
|
1101 * @url craig.is/killing/mice |
|
1102 */ |
|
1103 (function(window, document, undefined) { |
|
1104 |
|
1105 // Check if mousetrap is used inside browser, if not, return |
|
1106 if (!window) { |
|
1107 return; |
|
1108 } |
|
1109 |
|
1110 /** |
|
1111 * mapping of special keycodes to their corresponding keys |
|
1112 * |
|
1113 * everything in this dictionary cannot use keypress events |
|
1114 * so it has to be here to map to the correct keycodes for |
|
1115 * keyup/keydown events |
|
1116 * |
|
1117 * @type {Object} |
|
1118 */ |
|
1119 var _MAP = { |
|
1120 8: 'backspace', |
|
1121 9: 'tab', |
|
1122 13: 'enter', |
|
1123 16: 'shift', |
|
1124 17: 'ctrl', |
|
1125 18: 'alt', |
|
1126 20: 'capslock', |
|
1127 27: 'esc', |
|
1128 32: 'space', |
|
1129 33: 'pageup', |
|
1130 34: 'pagedown', |
|
1131 35: 'end', |
|
1132 36: 'home', |
|
1133 37: 'left', |
|
1134 38: 'up', |
|
1135 39: 'right', |
|
1136 40: 'down', |
|
1137 45: 'ins', |
|
1138 46: 'del', |
|
1139 91: 'meta', |
|
1140 93: 'meta', |
|
1141 224: 'meta' |
|
1142 }; |
|
1143 |
|
1144 /** |
|
1145 * mapping for special characters so they can support |
|
1146 * |
|
1147 * this dictionary is only used incase you want to bind a |
|
1148 * keyup or keydown event to one of these keys |
|
1149 * |
|
1150 * @type {Object} |
|
1151 */ |
|
1152 var _KEYCODE_MAP = { |
|
1153 106: '*', |
|
1154 107: '+', |
|
1155 109: '-', |
|
1156 110: '.', |
|
1157 111 : '/', |
|
1158 186: ';', |
|
1159 187: '=', |
|
1160 188: ',', |
|
1161 189: '-', |
|
1162 190: '.', |
|
1163 191: '/', |
|
1164 192: '`', |
|
1165 219: '[', |
|
1166 220: '\\', |
|
1167 221: ']', |
|
1168 222: '\'' |
|
1169 }; |
|
1170 |
|
1171 /** |
|
1172 * this is a mapping of keys that require shift on a US keypad |
|
1173 * back to the non shift equivelents |
|
1174 * |
|
1175 * this is so you can use keyup events with these keys |
|
1176 * |
|
1177 * note that this will only work reliably on US keyboards |
|
1178 * |
|
1179 * @type {Object} |
|
1180 */ |
|
1181 var _SHIFT_MAP = { |
|
1182 '~': '`', |
|
1183 '!': '1', |
|
1184 '@': '2', |
|
1185 '#': '3', |
|
1186 '$': '4', |
|
1187 '%': '5', |
|
1188 '^': '6', |
|
1189 '&': '7', |
|
1190 '*': '8', |
|
1191 '(': '9', |
|
1192 ')': '0', |
|
1193 '_': '-', |
|
1194 '+': '=', |
|
1195 ':': ';', |
|
1196 '\"': '\'', |
|
1197 '<': ',', |
|
1198 '>': '.', |
|
1199 '?': '/', |
|
1200 '|': '\\' |
|
1201 }; |
|
1202 |
|
1203 /** |
|
1204 * this is a list of special strings you can use to map |
|
1205 * to modifier keys when you specify your keyboard shortcuts |
|
1206 * |
|
1207 * @type {Object} |
|
1208 */ |
|
1209 var _SPECIAL_ALIASES = { |
|
1210 'option': 'alt', |
|
1211 'command': 'meta', |
|
1212 'return': 'enter', |
|
1213 'escape': 'esc', |
|
1214 'plus': '+', |
|
1215 'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl' |
|
1216 }; |
|
1217 |
|
1218 /** |
|
1219 * variable to store the flipped version of _MAP from above |
|
1220 * needed to check if we should use keypress or not when no action |
|
1221 * is specified |
|
1222 * |
|
1223 * @type {Object|undefined} |
|
1224 */ |
|
1225 var _REVERSE_MAP; |
|
1226 |
|
1227 /** |
|
1228 * loop through the f keys, f1 to f19 and add them to the map |
|
1229 * programatically |
|
1230 */ |
|
1231 for (var i = 1; i < 20; ++i) { |
|
1232 _MAP[111 + i] = 'f' + i; |
|
1233 } |
|
1234 |
|
1235 /** |
|
1236 * loop through to map numbers on the numeric keypad |
|
1237 */ |
|
1238 for (i = 0; i <= 9; ++i) { |
|
1239 |
|
1240 // This needs to use a string cause otherwise since 0 is falsey |
|
1241 // mousetrap will never fire for numpad 0 pressed as part of a keydown |
|
1242 // event. |
|
1243 // |
|
1244 // @see https://github.com/ccampbell/mousetrap/pull/258 |
|
1245 _MAP[i + 96] = i.toString(); |
|
1246 } |
|
1247 |
|
1248 /** |
|
1249 * cross browser add event method |
|
1250 * |
|
1251 * @param {Element|HTMLDocument} object |
|
1252 * @param {string} type |
|
1253 * @param {Function} callback |
|
1254 * @returns void |
|
1255 */ |
|
1256 function _addEvent(object, type, callback) { |
|
1257 if (object.addEventListener) { |
|
1258 object.addEventListener(type, callback, false); |
|
1259 return; |
|
1260 } |
|
1261 |
|
1262 object.attachEvent('on' + type, callback); |
|
1263 } |
|
1264 |
|
1265 /** |
|
1266 * takes the event and returns the key character |
|
1267 * |
|
1268 * @param {Event} e |
|
1269 * @return {string} |
|
1270 */ |
|
1271 function _characterFromEvent(e) { |
|
1272 |
|
1273 // for keypress events we should return the character as is |
|
1274 if (e.type == 'keypress') { |
|
1275 var character = String.fromCharCode(e.which); |
|
1276 |
|
1277 // if the shift key is not pressed then it is safe to assume |
|
1278 // that we want the character to be lowercase. this means if |
|
1279 // you accidentally have caps lock on then your key bindings |
|
1280 // will continue to work |
|
1281 // |
|
1282 // the only side effect that might not be desired is if you |
|
1283 // bind something like 'A' cause you want to trigger an |
|
1284 // event when capital A is pressed caps lock will no longer |
|
1285 // trigger the event. shift+a will though. |
|
1286 if (!e.shiftKey) { |
|
1287 character = character.toLowerCase(); |
|
1288 } |
|
1289 |
|
1290 return character; |
|
1291 } |
|
1292 |
|
1293 // for non keypress events the special maps are needed |
|
1294 if (_MAP[e.which]) { |
|
1295 return _MAP[e.which]; |
|
1296 } |
|
1297 |
|
1298 if (_KEYCODE_MAP[e.which]) { |
|
1299 return _KEYCODE_MAP[e.which]; |
|
1300 } |
|
1301 |
|
1302 // if it is not in the special map |
|
1303 |
|
1304 // with keydown and keyup events the character seems to always |
|
1305 // come in as an uppercase character whether you are pressing shift |
|
1306 // or not. we should make sure it is always lowercase for comparisons |
|
1307 return String.fromCharCode(e.which).toLowerCase(); |
|
1308 } |
|
1309 |
|
1310 /** |
|
1311 * checks if two arrays are equal |
|
1312 * |
|
1313 * @param {Array} modifiers1 |
|
1314 * @param {Array} modifiers2 |
|
1315 * @returns {boolean} |
|
1316 */ |
|
1317 function _modifiersMatch(modifiers1, modifiers2) { |
|
1318 return modifiers1.sort().join(',') === modifiers2.sort().join(','); |
|
1319 } |
|
1320 |
|
1321 /** |
|
1322 * takes a key event and figures out what the modifiers are |
|
1323 * |
|
1324 * @param {Event} e |
|
1325 * @returns {Array} |
|
1326 */ |
|
1327 function _eventModifiers(e) { |
|
1328 var modifiers = []; |
|
1329 |
|
1330 if (e.shiftKey) { |
|
1331 modifiers.push('shift'); |
|
1332 } |
|
1333 |
|
1334 if (e.altKey) { |
|
1335 modifiers.push('alt'); |
|
1336 } |
|
1337 |
|
1338 if (e.ctrlKey) { |
|
1339 modifiers.push('ctrl'); |
|
1340 } |
|
1341 |
|
1342 if (e.metaKey) { |
|
1343 modifiers.push('meta'); |
|
1344 } |
|
1345 |
|
1346 return modifiers; |
|
1347 } |
|
1348 |
|
1349 /** |
|
1350 * prevents default for this event |
|
1351 * |
|
1352 * @param {Event} e |
|
1353 * @returns void |
|
1354 */ |
|
1355 function _preventDefault(e) { |
|
1356 if (e.preventDefault) { |
|
1357 e.preventDefault(); |
|
1358 return; |
|
1359 } |
|
1360 |
|
1361 e.returnValue = false; |
|
1362 } |
|
1363 |
|
1364 /** |
|
1365 * stops propogation for this event |
|
1366 * |
|
1367 * @param {Event} e |
|
1368 * @returns void |
|
1369 */ |
|
1370 function _stopPropagation(e) { |
|
1371 if (e.stopPropagation) { |
|
1372 e.stopPropagation(); |
|
1373 return; |
|
1374 } |
|
1375 |
|
1376 e.cancelBubble = true; |
|
1377 } |
|
1378 |
|
1379 /** |
|
1380 * determines if the keycode specified is a modifier key or not |
|
1381 * |
|
1382 * @param {string} key |
|
1383 * @returns {boolean} |
|
1384 */ |
|
1385 function _isModifier(key) { |
|
1386 return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta'; |
|
1387 } |
|
1388 |
|
1389 /** |
|
1390 * reverses the map lookup so that we can look for specific keys |
|
1391 * to see what can and can't use keypress |
|
1392 * |
|
1393 * @return {Object} |
|
1394 */ |
|
1395 function _getReverseMap() { |
|
1396 if (!_REVERSE_MAP) { |
|
1397 _REVERSE_MAP = {}; |
|
1398 for (var key in _MAP) { |
|
1399 |
|
1400 // pull out the numeric keypad from here cause keypress should |
|
1401 // be able to detect the keys from the character |
|
1402 if (key > 95 && key < 112) { |
|
1403 continue; |
|
1404 } |
|
1405 |
|
1406 if (_MAP.hasOwnProperty(key)) { |
|
1407 _REVERSE_MAP[_MAP[key]] = key; |
|
1408 } |
|
1409 } |
|
1410 } |
|
1411 return _REVERSE_MAP; |
|
1412 } |
|
1413 |
|
1414 /** |
|
1415 * picks the best action based on the key combination |
|
1416 * |
|
1417 * @param {string} key - character for key |
|
1418 * @param {Array} modifiers |
|
1419 * @param {string=} action passed in |
|
1420 */ |
|
1421 function _pickBestAction(key, modifiers, action) { |
|
1422 |
|
1423 // if no action was picked in we should try to pick the one |
|
1424 // that we think would work best for this key |
|
1425 if (!action) { |
|
1426 action = _getReverseMap()[key] ? 'keydown' : 'keypress'; |
|
1427 } |
|
1428 |
|
1429 // modifier keys don't work as expected with keypress, |
|
1430 // switch to keydown |
|
1431 if (action == 'keypress' && modifiers.length) { |
|
1432 action = 'keydown'; |
|
1433 } |
|
1434 |
|
1435 return action; |
|
1436 } |
|
1437 |
|
1438 /** |
|
1439 * Converts from a string key combination to an array |
|
1440 * |
|
1441 * @param {string} combination like "command+shift+l" |
|
1442 * @return {Array} |
|
1443 */ |
|
1444 function _keysFromString(combination) { |
|
1445 if (combination === '+') { |
|
1446 return ['+']; |
|
1447 } |
|
1448 |
|
1449 combination = combination.replace(/\+{2}/g, '+plus'); |
|
1450 return combination.split('+'); |
|
1451 } |
|
1452 |
|
1453 /** |
|
1454 * Gets info for a specific key combination |
|
1455 * |
|
1456 * @param {string} combination key combination ("command+s" or "a" or "*") |
|
1457 * @param {string=} action |
|
1458 * @returns {Object} |
|
1459 */ |
|
1460 function _getKeyInfo(combination, action) { |
|
1461 var keys; |
|
1462 var key; |
|
1463 var i; |
|
1464 var modifiers = []; |
|
1465 |
|
1466 // take the keys from this pattern and figure out what the actual |
|
1467 // pattern is all about |
|
1468 keys = _keysFromString(combination); |
|
1469 |
|
1470 for (i = 0; i < keys.length; ++i) { |
|
1471 key = keys[i]; |
|
1472 |
|
1473 // normalize key names |
|
1474 if (_SPECIAL_ALIASES[key]) { |
|
1475 key = _SPECIAL_ALIASES[key]; |
|
1476 } |
|
1477 |
|
1478 // if this is not a keypress event then we should |
|
1479 // be smart about using shift keys |
|
1480 // this will only work for US keyboards however |
|
1481 if (action && action != 'keypress' && _SHIFT_MAP[key]) { |
|
1482 key = _SHIFT_MAP[key]; |
|
1483 modifiers.push('shift'); |
|
1484 } |
|
1485 |
|
1486 // if this key is a modifier then add it to the list of modifiers |
|
1487 if (_isModifier(key)) { |
|
1488 modifiers.push(key); |
|
1489 } |
|
1490 } |
|
1491 |
|
1492 // depending on what the key combination is |
|
1493 // we will try to pick the best event for it |
|
1494 action = _pickBestAction(key, modifiers, action); |
|
1495 |
|
1496 return { |
|
1497 key: key, |
|
1498 modifiers: modifiers, |
|
1499 action: action |
|
1500 }; |
|
1501 } |
|
1502 |
|
1503 function _belongsTo(element, ancestor) { |
|
1504 if (element === null || element === document) { |
|
1505 return false; |
|
1506 } |
|
1507 |
|
1508 if (element === ancestor) { |
|
1509 return true; |
|
1510 } |
|
1511 |
|
1512 return _belongsTo(element.parentNode, ancestor); |
|
1513 } |
|
1514 |
|
1515 function Mousetrap(targetElement) { |
|
1516 var self = this; |
|
1517 |
|
1518 targetElement = targetElement || document; |
|
1519 |
|
1520 if (!(self instanceof Mousetrap)) { |
|
1521 return new Mousetrap(targetElement); |
|
1522 } |
|
1523 |
|
1524 /** |
|
1525 * element to attach key events to |
|
1526 * |
|
1527 * @type {Element} |
|
1528 */ |
|
1529 self.target = targetElement; |
|
1530 |
|
1531 /** |
|
1532 * a list of all the callbacks setup via Mousetrap.bind() |
|
1533 * |
|
1534 * @type {Object} |
|
1535 */ |
|
1536 self._callbacks = {}; |
|
1537 |
|
1538 /** |
|
1539 * direct map of string combinations to callbacks used for trigger() |
|
1540 * |
|
1541 * @type {Object} |
|
1542 */ |
|
1543 self._directMap = {}; |
|
1544 |
|
1545 /** |
|
1546 * keeps track of what level each sequence is at since multiple |
|
1547 * sequences can start out with the same sequence |
|
1548 * |
|
1549 * @type {Object} |
|
1550 */ |
|
1551 var _sequenceLevels = {}; |
|
1552 |
|
1553 /** |
|
1554 * variable to store the setTimeout call |
|
1555 * |
|
1556 * @type {null|number} |
|
1557 */ |
|
1558 var _resetTimer; |
|
1559 |
|
1560 /** |
|
1561 * temporary state where we will ignore the next keyup |
|
1562 * |
|
1563 * @type {boolean|string} |
|
1564 */ |
|
1565 var _ignoreNextKeyup = false; |
|
1566 |
|
1567 /** |
|
1568 * temporary state where we will ignore the next keypress |
|
1569 * |
|
1570 * @type {boolean} |
|
1571 */ |
|
1572 var _ignoreNextKeypress = false; |
|
1573 |
|
1574 /** |
|
1575 * are we currently inside of a sequence? |
|
1576 * type of action ("keyup" or "keydown" or "keypress") or false |
|
1577 * |
|
1578 * @type {boolean|string} |
|
1579 */ |
|
1580 var _nextExpectedAction = false; |
|
1581 |
|
1582 /** |
|
1583 * resets all sequence counters except for the ones passed in |
|
1584 * |
|
1585 * @param {Object} doNotReset |
|
1586 * @returns void |
|
1587 */ |
|
1588 function _resetSequences(doNotReset) { |
|
1589 doNotReset = doNotReset || {}; |
|
1590 |
|
1591 var activeSequences = false, |
|
1592 key; |
|
1593 |
|
1594 for (key in _sequenceLevels) { |
|
1595 if (doNotReset[key]) { |
|
1596 activeSequences = true; |
|
1597 continue; |
|
1598 } |
|
1599 _sequenceLevels[key] = 0; |
|
1600 } |
|
1601 |
|
1602 if (!activeSequences) { |
|
1603 _nextExpectedAction = false; |
|
1604 } |
|
1605 } |
|
1606 |
|
1607 /** |
|
1608 * finds all callbacks that match based on the keycode, modifiers, |
|
1609 * and action |
|
1610 * |
|
1611 * @param {string} character |
|
1612 * @param {Array} modifiers |
|
1613 * @param {Event|Object} e |
|
1614 * @param {string=} sequenceName - name of the sequence we are looking for |
|
1615 * @param {string=} combination |
|
1616 * @param {number=} level |
|
1617 * @returns {Array} |
|
1618 */ |
|
1619 function _getMatches(character, modifiers, e, sequenceName, combination, level) { |
|
1620 var i; |
|
1621 var callback; |
|
1622 var matches = []; |
|
1623 var action = e.type; |
|
1624 |
|
1625 // if there are no events related to this keycode |
|
1626 if (!self._callbacks[character]) { |
|
1627 return []; |
|
1628 } |
|
1629 |
|
1630 // if a modifier key is coming up on its own we should allow it |
|
1631 if (action == 'keyup' && _isModifier(character)) { |
|
1632 modifiers = [character]; |
|
1633 } |
|
1634 |
|
1635 // loop through all callbacks for the key that was pressed |
|
1636 // and see if any of them match |
|
1637 for (i = 0; i < self._callbacks[character].length; ++i) { |
|
1638 callback = self._callbacks[character][i]; |
|
1639 |
|
1640 // if a sequence name is not specified, but this is a sequence at |
|
1641 // the wrong level then move onto the next match |
|
1642 if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) { |
|
1643 continue; |
|
1644 } |
|
1645 |
|
1646 // if the action we are looking for doesn't match the action we got |
|
1647 // then we should keep going |
|
1648 if (action != callback.action) { |
|
1649 continue; |
|
1650 } |
|
1651 |
|
1652 // if this is a keypress event and the meta key and control key |
|
1653 // are not pressed that means that we need to only look at the |
|
1654 // character, otherwise check the modifiers as well |
|
1655 // |
|
1656 // chrome will not fire a keypress if meta or control is down |
|
1657 // safari will fire a keypress if meta or meta+shift is down |
|
1658 // firefox will fire a keypress if meta or control is down |
|
1659 if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) { |
|
1660 |
|
1661 // when you bind a combination or sequence a second time it |
|
1662 // should overwrite the first one. if a sequenceName or |
|
1663 // combination is specified in this call it does just that |
|
1664 // |
|
1665 // @todo make deleting its own method? |
|
1666 var deleteCombo = !sequenceName && callback.combo == combination; |
|
1667 var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level; |
|
1668 if (deleteCombo || deleteSequence) { |
|
1669 self._callbacks[character].splice(i, 1); |
|
1670 } |
|
1671 |
|
1672 matches.push(callback); |
|
1673 } |
|
1674 } |
|
1675 |
|
1676 return matches; |
|
1677 } |
|
1678 |
|
1679 /** |
|
1680 * actually calls the callback function |
|
1681 * |
|
1682 * if your callback function returns false this will use the jquery |
|
1683 * convention - prevent default and stop propogation on the event |
|
1684 * |
|
1685 * @param {Function} callback |
|
1686 * @param {Event} e |
|
1687 * @returns void |
|
1688 */ |
|
1689 function _fireCallback(callback, e, combo, sequence) { |
|
1690 |
|
1691 // if this event should not happen stop here |
|
1692 if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) { |
|
1693 return; |
|
1694 } |
|
1695 |
|
1696 if (callback(e, combo) === false) { |
|
1697 _preventDefault(e); |
|
1698 _stopPropagation(e); |
|
1699 } |
|
1700 } |
|
1701 |
|
1702 /** |
|
1703 * handles a character key event |
|
1704 * |
|
1705 * @param {string} character |
|
1706 * @param {Array} modifiers |
|
1707 * @param {Event} e |
|
1708 * @returns void |
|
1709 */ |
|
1710 self._handleKey = function(character, modifiers, e) { |
|
1711 var callbacks = _getMatches(character, modifiers, e); |
|
1712 var i; |
|
1713 var doNotReset = {}; |
|
1714 var maxLevel = 0; |
|
1715 var processedSequenceCallback = false; |
|
1716 |
|
1717 // Calculate the maxLevel for sequences so we can only execute the longest callback sequence |
|
1718 for (i = 0; i < callbacks.length; ++i) { |
|
1719 if (callbacks[i].seq) { |
|
1720 maxLevel = Math.max(maxLevel, callbacks[i].level); |
|
1721 } |
|
1722 } |
|
1723 |
|
1724 // loop through matching callbacks for this key event |
|
1725 for (i = 0; i < callbacks.length; ++i) { |
|
1726 |
|
1727 // fire for all sequence callbacks |
|
1728 // this is because if for example you have multiple sequences |
|
1729 // bound such as "g i" and "g t" they both need to fire the |
|
1730 // callback for matching g cause otherwise you can only ever |
|
1731 // match the first one |
|
1732 if (callbacks[i].seq) { |
|
1733 |
|
1734 // only fire callbacks for the maxLevel to prevent |
|
1735 // subsequences from also firing |
|
1736 // |
|
1737 // for example 'a option b' should not cause 'option b' to fire |
|
1738 // even though 'option b' is part of the other sequence |
|
1739 // |
|
1740 // any sequences that do not match here will be discarded |
|
1741 // below by the _resetSequences call |
|
1742 if (callbacks[i].level != maxLevel) { |
|
1743 continue; |
|
1744 } |
|
1745 |
|
1746 processedSequenceCallback = true; |
|
1747 |
|
1748 // keep a list of which sequences were matches for later |
|
1749 doNotReset[callbacks[i].seq] = 1; |
|
1750 _fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq); |
|
1751 continue; |
|
1752 } |
|
1753 |
|
1754 // if there were no sequence matches but we are still here |
|
1755 // that means this is a regular match so we should fire that |
|
1756 if (!processedSequenceCallback) { |
|
1757 _fireCallback(callbacks[i].callback, e, callbacks[i].combo); |
|
1758 } |
|
1759 } |
|
1760 |
|
1761 // if the key you pressed matches the type of sequence without |
|
1762 // being a modifier (ie "keyup" or "keypress") then we should |
|
1763 // reset all sequences that were not matched by this event |
|
1764 // |
|
1765 // this is so, for example, if you have the sequence "h a t" and you |
|
1766 // type "h e a r t" it does not match. in this case the "e" will |
|
1767 // cause the sequence to reset |
|
1768 // |
|
1769 // modifier keys are ignored because you can have a sequence |
|
1770 // that contains modifiers such as "enter ctrl+space" and in most |
|
1771 // cases the modifier key will be pressed before the next key |
|
1772 // |
|
1773 // also if you have a sequence such as "ctrl+b a" then pressing the |
|
1774 // "b" key will trigger a "keypress" and a "keydown" |
|
1775 // |
|
1776 // the "keydown" is expected when there is a modifier, but the |
|
1777 // "keypress" ends up matching the _nextExpectedAction since it occurs |
|
1778 // after and that causes the sequence to reset |
|
1779 // |
|
1780 // we ignore keypresses in a sequence that directly follow a keydown |
|
1781 // for the same character |
|
1782 var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress; |
|
1783 if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) { |
|
1784 _resetSequences(doNotReset); |
|
1785 } |
|
1786 |
|
1787 _ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown'; |
|
1788 }; |
|
1789 |
|
1790 /** |
|
1791 * handles a keydown event |
|
1792 * |
|
1793 * @param {Event} e |
|
1794 * @returns void |
|
1795 */ |
|
1796 function _handleKeyEvent(e) { |
|
1797 |
|
1798 // normalize e.which for key events |
|
1799 // @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion |
|
1800 if (typeof e.which !== 'number') { |
|
1801 e.which = e.keyCode; |
|
1802 } |
|
1803 |
|
1804 var character = _characterFromEvent(e); |
|
1805 |
|
1806 // no character found then stop |
|
1807 if (!character) { |
|
1808 return; |
|
1809 } |
|
1810 |
|
1811 // need to use === for the character check because the character can be 0 |
|
1812 if (e.type == 'keyup' && _ignoreNextKeyup === character) { |
|
1813 _ignoreNextKeyup = false; |
|
1814 return; |
|
1815 } |
|
1816 |
|
1817 self.handleKey(character, _eventModifiers(e), e); |
|
1818 } |
|
1819 |
|
1820 /** |
|
1821 * called to set a 1 second timeout on the specified sequence |
|
1822 * |
|
1823 * this is so after each key press in the sequence you have 1 second |
|
1824 * to press the next key before you have to start over |
|
1825 * |
|
1826 * @returns void |
|
1827 */ |
|
1828 function _resetSequenceTimer() { |
|
1829 clearTimeout(_resetTimer); |
|
1830 _resetTimer = setTimeout(_resetSequences, 1000); |
|
1831 } |
|
1832 |
|
1833 /** |
|
1834 * binds a key sequence to an event |
|
1835 * |
|
1836 * @param {string} combo - combo specified in bind call |
|
1837 * @param {Array} keys |
|
1838 * @param {Function} callback |
|
1839 * @param {string=} action |
|
1840 * @returns void |
|
1841 */ |
|
1842 function _bindSequence(combo, keys, callback, action) { |
|
1843 |
|
1844 // start off by adding a sequence level record for this combination |
|
1845 // and setting the level to 0 |
|
1846 _sequenceLevels[combo] = 0; |
|
1847 |
|
1848 /** |
|
1849 * callback to increase the sequence level for this sequence and reset |
|
1850 * all other sequences that were active |
|
1851 * |
|
1852 * @param {string} nextAction |
|
1853 * @returns {Function} |
|
1854 */ |
|
1855 function _increaseSequence(nextAction) { |
|
1856 return function() { |
|
1857 _nextExpectedAction = nextAction; |
|
1858 ++_sequenceLevels[combo]; |
|
1859 _resetSequenceTimer(); |
|
1860 }; |
|
1861 } |
|
1862 |
|
1863 /** |
|
1864 * wraps the specified callback inside of another function in order |
|
1865 * to reset all sequence counters as soon as this sequence is done |
|
1866 * |
|
1867 * @param {Event} e |
|
1868 * @returns void |
|
1869 */ |
|
1870 function _callbackAndReset(e) { |
|
1871 _fireCallback(callback, e, combo); |
|
1872 |
|
1873 // we should ignore the next key up if the action is key down |
|
1874 // or keypress. this is so if you finish a sequence and |
|
1875 // release the key the final key will not trigger a keyup |
|
1876 if (action !== 'keyup') { |
|
1877 _ignoreNextKeyup = _characterFromEvent(e); |
|
1878 } |
|
1879 |
|
1880 // weird race condition if a sequence ends with the key |
|
1881 // another sequence begins with |
|
1882 setTimeout(_resetSequences, 10); |
|
1883 } |
|
1884 |
|
1885 // loop through keys one at a time and bind the appropriate callback |
|
1886 // function. for any key leading up to the final one it should |
|
1887 // increase the sequence. after the final, it should reset all sequences |
|
1888 // |
|
1889 // if an action is specified in the original bind call then that will |
|
1890 // be used throughout. otherwise we will pass the action that the |
|
1891 // next key in the sequence should match. this allows a sequence |
|
1892 // to mix and match keypress and keydown events depending on which |
|
1893 // ones are better suited to the key provided |
|
1894 for (var i = 0; i < keys.length; ++i) { |
|
1895 var isFinal = i + 1 === keys.length; |
|
1896 var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action); |
|
1897 _bindSingle(keys[i], wrappedCallback, action, combo, i); |
|
1898 } |
|
1899 } |
|
1900 |
|
1901 /** |
|
1902 * binds a single keyboard combination |
|
1903 * |
|
1904 * @param {string} combination |
|
1905 * @param {Function} callback |
|
1906 * @param {string=} action |
|
1907 * @param {string=} sequenceName - name of sequence if part of sequence |
|
1908 * @param {number=} level - what part of the sequence the command is |
|
1909 * @returns void |
|
1910 */ |
|
1911 function _bindSingle(combination, callback, action, sequenceName, level) { |
|
1912 |
|
1913 // store a direct mapped reference for use with Mousetrap.trigger |
|
1914 self._directMap[combination + ':' + action] = callback; |
|
1915 |
|
1916 // make sure multiple spaces in a row become a single space |
|
1917 combination = combination.replace(/\s+/g, ' '); |
|
1918 |
|
1919 var sequence = combination.split(' '); |
|
1920 var info; |
|
1921 |
|
1922 // if this pattern is a sequence of keys then run through this method |
|
1923 // to reprocess each pattern one key at a time |
|
1924 if (sequence.length > 1) { |
|
1925 _bindSequence(combination, sequence, callback, action); |
|
1926 return; |
|
1927 } |
|
1928 |
|
1929 info = _getKeyInfo(combination, action); |
|
1930 |
|
1931 // make sure to initialize array if this is the first time |
|
1932 // a callback is added for this key |
|
1933 self._callbacks[info.key] = self._callbacks[info.key] || []; |
|
1934 |
|
1935 // remove an existing match if there is one |
|
1936 _getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level); |
|
1937 |
|
1938 // add this call back to the array |
|
1939 // if it is a sequence put it at the beginning |
|
1940 // if not put it at the end |
|
1941 // |
|
1942 // this is important because the way these are processed expects |
|
1943 // the sequence ones to come first |
|
1944 self._callbacks[info.key][sequenceName ? 'unshift' : 'push']({ |
|
1945 callback: callback, |
|
1946 modifiers: info.modifiers, |
|
1947 action: info.action, |
|
1948 seq: sequenceName, |
|
1949 level: level, |
|
1950 combo: combination |
|
1951 }); |
|
1952 } |
|
1953 |
|
1954 /** |
|
1955 * binds multiple combinations to the same callback |
|
1956 * |
|
1957 * @param {Array} combinations |
|
1958 * @param {Function} callback |
|
1959 * @param {string|undefined} action |
|
1960 * @returns void |
|
1961 */ |
|
1962 self._bindMultiple = function(combinations, callback, action) { |
|
1963 for (var i = 0; i < combinations.length; ++i) { |
|
1964 _bindSingle(combinations[i], callback, action); |
|
1965 } |
|
1966 }; |
|
1967 |
|
1968 // start! |
|
1969 _addEvent(targetElement, 'keypress', _handleKeyEvent); |
|
1970 _addEvent(targetElement, 'keydown', _handleKeyEvent); |
|
1971 _addEvent(targetElement, 'keyup', _handleKeyEvent); |
|
1972 } |
|
1973 |
|
1974 /** |
|
1975 * binds an event to mousetrap |
|
1976 * |
|
1977 * can be a single key, a combination of keys separated with +, |
|
1978 * an array of keys, or a sequence of keys separated by spaces |
|
1979 * |
|
1980 * be sure to list the modifier keys first to make sure that the |
|
1981 * correct key ends up getting bound (the last key in the pattern) |
|
1982 * |
|
1983 * @param {string|Array} keys |
|
1984 * @param {Function} callback |
|
1985 * @param {string=} action - 'keypress', 'keydown', or 'keyup' |
|
1986 * @returns void |
|
1987 */ |
|
1988 Mousetrap.prototype.bind = function(keys, callback, action) { |
|
1989 var self = this; |
|
1990 keys = keys instanceof Array ? keys : [keys]; |
|
1991 self._bindMultiple.call(self, keys, callback, action); |
|
1992 return self; |
|
1993 }; |
|
1994 |
|
1995 /** |
|
1996 * unbinds an event to mousetrap |
|
1997 * |
|
1998 * the unbinding sets the callback function of the specified key combo |
|
1999 * to an empty function and deletes the corresponding key in the |
|
2000 * _directMap dict. |
|
2001 * |
|
2002 * TODO: actually remove this from the _callbacks dictionary instead |
|
2003 * of binding an empty function |
|
2004 * |
|
2005 * the keycombo+action has to be exactly the same as |
|
2006 * it was defined in the bind method |
|
2007 * |
|
2008 * @param {string|Array} keys |
|
2009 * @param {string} action |
|
2010 * @returns void |
|
2011 */ |
|
2012 Mousetrap.prototype.unbind = function(keys, action) { |
|
2013 var self = this; |
|
2014 return self.bind.call(self, keys, function() {}, action); |
|
2015 }; |
|
2016 |
|
2017 /** |
|
2018 * triggers an event that has already been bound |
|
2019 * |
|
2020 * @param {string} keys |
|
2021 * @param {string=} action |
|
2022 * @returns void |
|
2023 */ |
|
2024 Mousetrap.prototype.trigger = function(keys, action) { |
|
2025 var self = this; |
|
2026 if (self._directMap[keys + ':' + action]) { |
|
2027 self._directMap[keys + ':' + action]({}, keys); |
|
2028 } |
|
2029 return self; |
|
2030 }; |
|
2031 |
|
2032 /** |
|
2033 * resets the library back to its initial state. this is useful |
|
2034 * if you want to clear out the current keyboard shortcuts and bind |
|
2035 * new ones - for example if you switch to another page |
|
2036 * |
|
2037 * @returns void |
|
2038 */ |
|
2039 Mousetrap.prototype.reset = function() { |
|
2040 var self = this; |
|
2041 self._callbacks = {}; |
|
2042 self._directMap = {}; |
|
2043 return self; |
|
2044 }; |
|
2045 |
|
2046 /** |
|
2047 * should we stop this event before firing off callbacks |
|
2048 * |
|
2049 * @param {Event} e |
|
2050 * @param {Element} element |
|
2051 * @return {boolean} |
|
2052 */ |
|
2053 Mousetrap.prototype.stopCallback = function(e, element) { |
|
2054 var self = this; |
|
2055 |
|
2056 // if the element has the class "mousetrap" then no need to stop |
|
2057 if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) { |
|
2058 return false; |
|
2059 } |
|
2060 |
|
2061 if (_belongsTo(element, self.target)) { |
|
2062 return false; |
|
2063 } |
|
2064 |
|
2065 // Events originating from a shadow DOM are re-targetted and `e.target` is the shadow host, |
|
2066 // not the initial event target in the shadow tree. Note that not all events cross the |
|
2067 // shadow boundary. |
|
2068 // For shadow trees with `mode: 'open'`, the initial event target is the first element in |
|
2069 // the event’s composed path. For shadow trees with `mode: 'closed'`, the initial event |
|
2070 // target cannot be obtained. |
|
2071 if ('composedPath' in e && typeof e.composedPath === 'function') { |
|
2072 // For open shadow trees, update `element` so that the following check works. |
|
2073 var initialEventTarget = e.composedPath()[0]; |
|
2074 if (initialEventTarget !== e.target) { |
|
2075 element = initialEventTarget; |
|
2076 } |
|
2077 } |
|
2078 |
|
2079 // stop for input, select, and textarea |
|
2080 return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable; |
|
2081 }; |
|
2082 |
|
2083 /** |
|
2084 * exposes _handleKey publicly so it can be overwritten by extensions |
|
2085 */ |
|
2086 Mousetrap.prototype.handleKey = function() { |
|
2087 var self = this; |
|
2088 return self._handleKey.apply(self, arguments); |
|
2089 }; |
|
2090 |
|
2091 /** |
|
2092 * allow custom key mappings |
|
2093 */ |
|
2094 Mousetrap.addKeycodes = function(object) { |
|
2095 for (var key in object) { |
|
2096 if (object.hasOwnProperty(key)) { |
|
2097 _MAP[key] = object[key]; |
|
2098 } |
|
2099 } |
|
2100 _REVERSE_MAP = null; |
|
2101 }; |
|
2102 |
|
2103 /** |
|
2104 * Init the global mousetrap functions |
|
2105 * |
|
2106 * This method is needed to allow the global mousetrap functions to work |
|
2107 * now that mousetrap is a constructor function. |
|
2108 */ |
|
2109 Mousetrap.init = function() { |
|
2110 var documentMousetrap = Mousetrap(document); |
|
2111 for (var method in documentMousetrap) { |
|
2112 if (method.charAt(0) !== '_') { |
|
2113 Mousetrap[method] = (function(method) { |
|
2114 return function() { |
|
2115 return documentMousetrap[method].apply(documentMousetrap, arguments); |
|
2116 }; |
|
2117 } (method)); |
|
2118 } |
|
2119 } |
|
2120 }; |
|
2121 |
|
2122 Mousetrap.init(); |
|
2123 |
|
2124 // expose mousetrap to the global object |
|
2125 window.Mousetrap = Mousetrap; |
|
2126 |
|
2127 // expose as a common js module |
|
2128 if ( true && module.exports) { |
|
2129 module.exports = Mousetrap; |
|
2130 } |
|
2131 |
|
2132 // expose mousetrap as an AMD module |
|
2133 if (true) { |
|
2134 !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() { |
|
2135 return Mousetrap; |
|
2136 }).call(exports, __webpack_require__, exports, module), |
|
2137 __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
|
2138 } |
|
2139 }) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null); |
|
2140 |
|
2141 |
|
2142 /***/ }), |
|
2143 |
|
2144 /***/ 5760: |
1961 /***/ 5760: |
2145 /***/ (() => { |
1962 /***/ (() => { |
2146 |
1963 |
2147 /** |
1964 /** |
2148 * adds a bindGlobal method to Mousetrap that allows you to |
1965 * adds a bindGlobal method to Mousetrap that allows you to |
2189 }; |
2006 }; |
2190 |
2007 |
2191 Mousetrap.init(); |
2008 Mousetrap.init(); |
2192 }) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined); |
2009 }) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined); |
2193 |
2010 |
2194 |
|
2195 /***/ }), |
|
2196 |
|
2197 /***/ 923: |
|
2198 /***/ ((module) => { |
|
2199 |
|
2200 "use strict"; |
|
2201 module.exports = window["wp"]["isShallowEqual"]; |
|
2202 |
2011 |
2203 /***/ }) |
2012 /***/ }) |
2204 |
2013 |
2205 /******/ }); |
2014 /******/ }); |
2206 /************************************************************************/ |
2015 /************************************************************************/ |
2269 /******/ }; |
2078 /******/ }; |
2270 /******/ })(); |
2079 /******/ })(); |
2271 /******/ |
2080 /******/ |
2272 /************************************************************************/ |
2081 /************************************************************************/ |
2273 var __webpack_exports__ = {}; |
2082 var __webpack_exports__ = {}; |
2274 // This entry need to be wrapped in an IIFE because it need to be in strict mode. |
2083 // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. |
2275 (() => { |
2084 (() => { |
2276 "use strict"; |
2085 "use strict"; |
2277 // ESM COMPAT FLAG |
2086 // ESM COMPAT FLAG |
2278 __webpack_require__.r(__webpack_exports__); |
2087 __webpack_require__.r(__webpack_exports__); |
2279 |
2088 |
2297 useCopyOnClick: () => (/* reexport */ useCopyOnClick), |
2106 useCopyOnClick: () => (/* reexport */ useCopyOnClick), |
2298 useCopyToClipboard: () => (/* reexport */ useCopyToClipboard), |
2107 useCopyToClipboard: () => (/* reexport */ useCopyToClipboard), |
2299 useDebounce: () => (/* reexport */ useDebounce), |
2108 useDebounce: () => (/* reexport */ useDebounce), |
2300 useDebouncedInput: () => (/* reexport */ useDebouncedInput), |
2109 useDebouncedInput: () => (/* reexport */ useDebouncedInput), |
2301 useDisabled: () => (/* reexport */ useDisabled), |
2110 useDisabled: () => (/* reexport */ useDisabled), |
2111 useEvent: () => (/* reexport */ useEvent), |
|
2302 useFocusOnMount: () => (/* reexport */ useFocusOnMount), |
2112 useFocusOnMount: () => (/* reexport */ useFocusOnMount), |
2303 useFocusReturn: () => (/* reexport */ use_focus_return), |
2113 useFocusReturn: () => (/* reexport */ use_focus_return), |
2304 useFocusableIframe: () => (/* reexport */ useFocusableIframe), |
2114 useFocusableIframe: () => (/* reexport */ useFocusableIframe), |
2305 useInstanceId: () => (/* reexport */ use_instance_id), |
2115 useInstanceId: () => (/* reexport */ use_instance_id), |
2306 useIsomorphicLayoutEffect: () => (/* reexport */ use_isomorphic_layout_effect), |
2116 useIsomorphicLayoutEffect: () => (/* reexport */ use_isomorphic_layout_effect), |
2309 useMergeRefs: () => (/* reexport */ useMergeRefs), |
2119 useMergeRefs: () => (/* reexport */ useMergeRefs), |
2310 useObservableValue: () => (/* reexport */ useObservableValue), |
2120 useObservableValue: () => (/* reexport */ useObservableValue), |
2311 usePrevious: () => (/* reexport */ usePrevious), |
2121 usePrevious: () => (/* reexport */ usePrevious), |
2312 useReducedMotion: () => (/* reexport */ use_reduced_motion), |
2122 useReducedMotion: () => (/* reexport */ use_reduced_motion), |
2313 useRefEffect: () => (/* reexport */ useRefEffect), |
2123 useRefEffect: () => (/* reexport */ useRefEffect), |
2314 useResizeObserver: () => (/* reexport */ useResizeAware), |
2124 useResizeObserver: () => (/* reexport */ use_resize_observer_useResizeObserver), |
2315 useStateWithHistory: () => (/* reexport */ useStateWithHistory), |
2125 useStateWithHistory: () => (/* reexport */ useStateWithHistory), |
2316 useThrottle: () => (/* reexport */ useThrottle), |
2126 useThrottle: () => (/* reexport */ useThrottle), |
2317 useViewportMatch: () => (/* reexport */ use_viewport_match), |
2127 useViewportMatch: () => (/* reexport */ use_viewport_match), |
2318 useWarnOnChange: () => (/* reexport */ use_warn_on_change), |
2128 useWarnOnChange: () => (/* reexport */ use_warn_on_change), |
2319 withGlobalEvents: () => (/* reexport */ withGlobalEvents), |
2129 withGlobalEvents: () => (/* reexport */ withGlobalEvents), |
2320 withInstanceId: () => (/* reexport */ with_instance_id), |
2130 withInstanceId: () => (/* reexport */ with_instance_id), |
2321 withSafeTimeout: () => (/* reexport */ with_safe_timeout), |
2131 withSafeTimeout: () => (/* reexport */ with_safe_timeout), |
2322 withState: () => (/* reexport */ withState) |
2132 withState: () => (/* reexport */ withState) |
2323 }); |
2133 }); |
2324 |
2134 |
2325 ;// CONCATENATED MODULE: ./node_modules/tslib/tslib.es6.mjs |
2135 ;// ./node_modules/tslib/tslib.es6.mjs |
2326 /****************************************************************************** |
2136 /****************************************************************************** |
2327 Copyright (c) Microsoft Corporation. |
2137 Copyright (c) Microsoft Corporation. |
2328 |
2138 |
2329 Permission to use, copy, modify, and/or distribute this software for any |
2139 Permission to use, copy, modify, and/or distribute this software for any |
2330 purpose with or without fee is hereby granted. |
2140 purpose with or without fee is hereby granted. |
2335 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
2145 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM |
2336 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
2146 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR |
2337 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
2147 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
2338 PERFORMANCE OF THIS SOFTWARE. |
2148 PERFORMANCE OF THIS SOFTWARE. |
2339 ***************************************************************************** */ |
2149 ***************************************************************************** */ |
2340 /* global Reflect, Promise, SuppressedError, Symbol */ |
2150 /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ |
2341 |
2151 |
2342 var extendStatics = function(d, b) { |
2152 var extendStatics = function(d, b) { |
2343 extendStatics = Object.setPrototypeOf || |
2153 extendStatics = Object.setPrototypeOf || |
2344 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
2154 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || |
2345 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
2155 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; |
2446 step((generator = generator.apply(thisArg, _arguments || [])).next()); |
2256 step((generator = generator.apply(thisArg, _arguments || [])).next()); |
2447 }); |
2257 }); |
2448 } |
2258 } |
2449 |
2259 |
2450 function __generator(thisArg, body) { |
2260 function __generator(thisArg, body) { |
2451 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; |
2261 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); |
2452 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
2262 return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
2453 function verb(n) { return function (v) { return step([n, v]); }; } |
2263 function verb(n) { return function (v) { return step([n, v]); }; } |
2454 function step(op) { |
2264 function step(op) { |
2455 if (f) throw new TypeError("Generator is already executing."); |
2265 if (f) throw new TypeError("Generator is already executing."); |
2456 while (g && (g = 0, op[0] && (_ = 0)), _) try { |
2266 while (g && (g = 0, op[0] && (_ = 0)), _) try { |
2457 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; |
2267 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; |
2551 } |
2361 } |
2552 |
2362 |
2553 function __asyncGenerator(thisArg, _arguments, generator) { |
2363 function __asyncGenerator(thisArg, _arguments, generator) { |
2554 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); |
2364 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); |
2555 var g = generator.apply(thisArg, _arguments || []), i, q = []; |
2365 var g = generator.apply(thisArg, _arguments || []), i, q = []; |
2556 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; |
2366 return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i; |
2557 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } |
2367 function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; } |
2368 function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } } |
|
2558 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } |
2369 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } |
2559 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } |
2370 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } |
2560 function fulfill(value) { resume("next", value); } |
2371 function fulfill(value) { resume("next", value); } |
2561 function reject(value) { resume("throw", value); } |
2372 function reject(value) { resume("throw", value); } |
2562 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } |
2373 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } |
2585 Object.defineProperty(o, "default", { enumerable: true, value: v }); |
2396 Object.defineProperty(o, "default", { enumerable: true, value: v }); |
2586 }) : function(o, v) { |
2397 }) : function(o, v) { |
2587 o["default"] = v; |
2398 o["default"] = v; |
2588 }; |
2399 }; |
2589 |
2400 |
2401 var ownKeys = function(o) { |
|
2402 ownKeys = Object.getOwnPropertyNames || function (o) { |
|
2403 var ar = []; |
|
2404 for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; |
|
2405 return ar; |
|
2406 }; |
|
2407 return ownKeys(o); |
|
2408 }; |
|
2409 |
|
2590 function __importStar(mod) { |
2410 function __importStar(mod) { |
2591 if (mod && mod.__esModule) return mod; |
2411 if (mod && mod.__esModule) return mod; |
2592 var result = {}; |
2412 var result = {}; |
2593 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); |
2413 if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); |
2594 __setModuleDefault(result, mod); |
2414 __setModuleDefault(result, mod); |
2595 return result; |
2415 return result; |
2596 } |
2416 } |
2597 |
2417 |
2598 function __importDefault(mod) { |
2418 function __importDefault(mod) { |
2618 } |
2438 } |
2619 |
2439 |
2620 function __addDisposableResource(env, value, async) { |
2440 function __addDisposableResource(env, value, async) { |
2621 if (value !== null && value !== void 0) { |
2441 if (value !== null && value !== void 0) { |
2622 if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); |
2442 if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected."); |
2623 var dispose; |
2443 var dispose, inner; |
2624 if (async) { |
2444 if (async) { |
2625 if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); |
2445 if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined."); |
2626 dispose = value[Symbol.asyncDispose]; |
2446 dispose = value[Symbol.asyncDispose]; |
2627 } |
2447 } |
2628 if (dispose === void 0) { |
2448 if (dispose === void 0) { |
2629 if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); |
2449 if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined."); |
2630 dispose = value[Symbol.dispose]; |
2450 dispose = value[Symbol.dispose]; |
2451 if (async) inner = dispose; |
|
2631 } |
2452 } |
2632 if (typeof dispose !== "function") throw new TypeError("Object not disposable."); |
2453 if (typeof dispose !== "function") throw new TypeError("Object not disposable."); |
2454 if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } }; |
|
2633 env.stack.push({ value: value, dispose: dispose, async: async }); |
2455 env.stack.push({ value: value, dispose: dispose, async: async }); |
2634 } |
2456 } |
2635 else if (async) { |
2457 else if (async) { |
2636 env.stack.push({ async: true }); |
2458 env.stack.push({ async: true }); |
2637 } |
2459 } |
2646 function __disposeResources(env) { |
2468 function __disposeResources(env) { |
2647 function fail(e) { |
2469 function fail(e) { |
2648 env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; |
2470 env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e; |
2649 env.hasError = true; |
2471 env.hasError = true; |
2650 } |
2472 } |
2473 var r, s = 0; |
|
2651 function next() { |
2474 function next() { |
2652 while (env.stack.length) { |
2475 while (r = env.stack.pop()) { |
2653 var rec = env.stack.pop(); |
|
2654 try { |
2476 try { |
2655 var result = rec.dispose && rec.dispose.call(rec.value); |
2477 if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next); |
2656 if (rec.async) return Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); |
2478 if (r.dispose) { |
2479 var result = r.dispose.call(r.value); |
|
2480 if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); }); |
|
2481 } |
|
2482 else s |= 1; |
|
2657 } |
2483 } |
2658 catch (e) { |
2484 catch (e) { |
2659 fail(e); |
2485 fail(e); |
2660 } |
2486 } |
2661 } |
2487 } |
2488 if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve(); |
|
2662 if (env.hasError) throw env.error; |
2489 if (env.hasError) throw env.error; |
2663 } |
2490 } |
2664 return next(); |
2491 return next(); |
2492 } |
|
2493 |
|
2494 function __rewriteRelativeImportExtension(path, preserveJsx) { |
|
2495 if (typeof path === "string" && /^\.\.?\//.test(path)) { |
|
2496 return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) { |
|
2497 return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js"); |
|
2498 }); |
|
2499 } |
|
2500 return path; |
|
2665 } |
2501 } |
2666 |
2502 |
2667 /* harmony default export */ const tslib_es6 = ({ |
2503 /* harmony default export */ const tslib_es6 = ({ |
2668 __extends, |
2504 __extends, |
2669 __assign, |
2505 __assign, |
2670 __rest, |
2506 __rest, |
2671 __decorate, |
2507 __decorate, |
2672 __param, |
2508 __param, |
2509 __esDecorate, |
|
2510 __runInitializers, |
|
2511 __propKey, |
|
2512 __setFunctionName, |
|
2673 __metadata, |
2513 __metadata, |
2674 __awaiter, |
2514 __awaiter, |
2675 __generator, |
2515 __generator, |
2676 __createBinding, |
2516 __createBinding, |
2677 __exportStar, |
2517 __exportStar, |
2690 __classPrivateFieldGet, |
2530 __classPrivateFieldGet, |
2691 __classPrivateFieldSet, |
2531 __classPrivateFieldSet, |
2692 __classPrivateFieldIn, |
2532 __classPrivateFieldIn, |
2693 __addDisposableResource, |
2533 __addDisposableResource, |
2694 __disposeResources, |
2534 __disposeResources, |
2535 __rewriteRelativeImportExtension, |
|
2695 }); |
2536 }); |
2696 |
2537 |
2697 ;// CONCATENATED MODULE: ./node_modules/lower-case/dist.es2015/index.js |
2538 ;// ./node_modules/lower-case/dist.es2015/index.js |
2698 /** |
2539 /** |
2699 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt |
2540 * Source: ftp://ftp.unicode.org/Public/UCD/latest/ucd/SpecialCasing.txt |
2700 */ |
2541 */ |
2701 var SUPPORTED_LOCALE = { |
2542 var SUPPORTED_LOCALE = { |
2702 tr: { |
2543 tr: { |
2741 */ |
2582 */ |
2742 function lowerCase(str) { |
2583 function lowerCase(str) { |
2743 return str.toLowerCase(); |
2584 return str.toLowerCase(); |
2744 } |
2585 } |
2745 |
2586 |
2746 ;// CONCATENATED MODULE: ./node_modules/no-case/dist.es2015/index.js |
2587 ;// ./node_modules/no-case/dist.es2015/index.js |
2747 |
2588 |
2748 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case"). |
2589 // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case"). |
2749 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g]; |
2590 var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g]; |
2750 // Remove all non-word characters. |
2591 // Remove all non-word characters. |
2751 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi; |
2592 var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi; |
2773 if (re instanceof RegExp) |
2614 if (re instanceof RegExp) |
2774 return input.replace(re, value); |
2615 return input.replace(re, value); |
2775 return re.reduce(function (input, re) { return input.replace(re, value); }, input); |
2616 return re.reduce(function (input, re) { return input.replace(re, value); }, input); |
2776 } |
2617 } |
2777 |
2618 |
2778 ;// CONCATENATED MODULE: ./node_modules/pascal-case/dist.es2015/index.js |
2619 ;// ./node_modules/pascal-case/dist.es2015/index.js |
2779 |
2620 |
2780 |
2621 |
2781 function pascalCaseTransform(input, index) { |
2622 function pascalCaseTransform(input, index) { |
2782 var firstChar = input.charAt(0); |
2623 var firstChar = input.charAt(0); |
2783 var lowerChars = input.substr(1).toLowerCase(); |
2624 var lowerChars = input.substr(1).toLowerCase(); |
2792 function pascalCase(input, options) { |
2633 function pascalCase(input, options) { |
2793 if (options === void 0) { options = {}; } |
2634 if (options === void 0) { options = {}; } |
2794 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options)); |
2635 return noCase(input, __assign({ delimiter: "", transform: pascalCaseTransform }, options)); |
2795 } |
2636 } |
2796 |
2637 |
2797 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/create-higher-order-component/index.js |
2638 ;// ./node_modules/@wordpress/compose/build-module/utils/create-higher-order-component/index.js |
2798 /** |
2639 /** |
2799 * External dependencies |
2640 * External dependencies |
2800 */ |
2641 */ |
2801 |
2642 |
2802 /** |
2643 /** |
2831 const inner = Inner.displayName || Inner.name || 'Component'; |
2672 const inner = Inner.displayName || Inner.name || 'Component'; |
2832 const outer = pascalCase(name !== null && name !== void 0 ? name : ''); |
2673 const outer = pascalCase(name !== null && name !== void 0 ? name : ''); |
2833 return `${outer}(${inner})`; |
2674 return `${outer}(${inner})`; |
2834 }; |
2675 }; |
2835 |
2676 |
2836 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/debounce/index.js |
2677 ;// ./node_modules/@wordpress/compose/build-module/utils/debounce/index.js |
2837 /** |
2678 /** |
2838 * Parts of this source were derived and modified from lodash, |
2679 * Parts of this source were derived and modified from lodash, |
2839 * released under the MIT license. |
2680 * released under the MIT license. |
2840 * |
2681 * |
2841 * https://github.com/lodash/lodash |
2682 * https://github.com/lodash/lodash |
3025 debounced.flush = flush; |
2866 debounced.flush = flush; |
3026 debounced.pending = pending; |
2867 debounced.pending = pending; |
3027 return debounced; |
2868 return debounced; |
3028 }; |
2869 }; |
3029 |
2870 |
3030 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/throttle/index.js |
2871 ;// ./node_modules/@wordpress/compose/build-module/utils/throttle/index.js |
3031 /** |
2872 /** |
3032 * Parts of this source were derived and modified from lodash, |
2873 * Parts of this source were derived and modified from lodash, |
3033 * released under the MIT license. |
2874 * released under the MIT license. |
3034 * |
2875 * |
3035 * https://github.com/lodash/lodash |
2876 * https://github.com/lodash/lodash |
3111 trailing, |
2952 trailing, |
3112 maxWait: wait |
2953 maxWait: wait |
3113 }); |
2954 }); |
3114 }; |
2955 }; |
3115 |
2956 |
3116 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/observable-map/index.js |
2957 ;// ./node_modules/@wordpress/compose/build-module/utils/observable-map/index.js |
3117 /** |
2958 /** |
3118 * A constructor (factory) for `ObservableMap`, a map-like key/value data structure |
2959 * A constructor (factory) for `ObservableMap`, a map-like key/value data structure |
3119 * where the individual entries are observable: using the `subscribe` method, you can |
2960 * where the individual entries are observable: using the `subscribe` method, you can |
3120 * subscribe to updates for a particular keys. Each subscriber always observes one |
2961 * subscribe to updates for a particular keys. Each subscriber always observes one |
3121 * specific key and is not notified about any unrelated changes (for different keys) |
2962 * specific key and is not notified about any unrelated changes (for different keys) |
3164 }; |
3005 }; |
3165 } |
3006 } |
3166 }; |
3007 }; |
3167 } |
3008 } |
3168 |
3009 |
3169 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pipe.js |
3010 ;// ./node_modules/@wordpress/compose/build-module/higher-order/pipe.js |
3170 /** |
3011 /** |
3171 * Parts of this source were derived and modified from lodash, |
3012 * Parts of this source were derived and modified from lodash, |
3172 * released under the MIT license. |
3013 * released under the MIT license. |
3173 * |
3014 * |
3174 * https://github.com/lodash/lodash |
3015 * https://github.com/lodash/lodash |
3234 */ |
3075 */ |
3235 const pipe = basePipe(); |
3076 const pipe = basePipe(); |
3236 |
3077 |
3237 /* harmony default export */ const higher_order_pipe = (pipe); |
3078 /* harmony default export */ const higher_order_pipe = (pipe); |
3238 |
3079 |
3239 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/compose.js |
3080 ;// ./node_modules/@wordpress/compose/build-module/higher-order/compose.js |
3240 /** |
3081 /** |
3241 * Internal dependencies |
3082 * Internal dependencies |
3242 */ |
3083 */ |
3243 |
3084 |
3244 |
3085 |
3251 * @see https://lodash.com/docs/4#flow-right |
3092 * @see https://lodash.com/docs/4#flow-right |
3252 */ |
3093 */ |
3253 const compose = basePipe(true); |
3094 const compose = basePipe(true); |
3254 /* harmony default export */ const higher_order_compose = (compose); |
3095 /* harmony default export */ const higher_order_compose = (compose); |
3255 |
3096 |
3256 ;// CONCATENATED MODULE: external "ReactJSXRuntime" |
3097 ;// external "ReactJSXRuntime" |
3257 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
3098 const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"]; |
3258 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/if-condition/index.js |
3099 ;// ./node_modules/@wordpress/compose/build-module/higher-order/if-condition/index.js |
3259 /** |
3100 /** |
3260 * External dependencies |
3101 * External dependencies |
3261 */ |
3102 */ |
3262 |
3103 |
3263 /** |
3104 /** |
3293 }); |
3134 }); |
3294 }, 'ifCondition'); |
3135 }, 'ifCondition'); |
3295 } |
3136 } |
3296 /* harmony default export */ const if_condition = (ifCondition); |
3137 /* harmony default export */ const if_condition = (ifCondition); |
3297 |
3138 |
3298 // EXTERNAL MODULE: external ["wp","isShallowEqual"] |
3139 ;// external ["wp","isShallowEqual"] |
3299 var external_wp_isShallowEqual_ = __webpack_require__(923); |
3140 const external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"]; |
3300 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_); |
3141 var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject); |
3301 ;// CONCATENATED MODULE: external ["wp","element"] |
3142 ;// external ["wp","element"] |
3302 const external_wp_element_namespaceObject = window["wp"]["element"]; |
3143 const external_wp_element_namespaceObject = window["wp"]["element"]; |
3303 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pure/index.js |
3144 ;// ./node_modules/@wordpress/compose/build-module/higher-order/pure/index.js |
3304 /** |
3145 /** |
3305 * External dependencies |
3146 * External dependencies |
3306 */ |
3147 */ |
3307 |
3148 |
3308 /** |
3149 /** |
3342 } |
3183 } |
3343 }; |
3184 }; |
3344 }, 'pure'); |
3185 }, 'pure'); |
3345 /* harmony default export */ const higher_order_pure = (pure); |
3186 /* harmony default export */ const higher_order_pure = (pure); |
3346 |
3187 |
3347 ;// CONCATENATED MODULE: external ["wp","deprecated"] |
3188 ;// external ["wp","deprecated"] |
3348 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
3189 const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"]; |
3349 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
3190 var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject); |
3350 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/listener.js |
3191 ;// ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/listener.js |
3351 /** |
3192 /** |
3352 * Class responsible for orchestrating event handling on the global window, |
3193 * Class responsible for orchestrating event handling on the global window, |
3353 * binding a single event to be shared across all handling instances, and |
3194 * binding a single event to be shared across all handling instances, and |
3354 * removing the handler when no instances are listening for the event. |
3195 * removing the handler when no instances are listening for the event. |
3355 */ |
3196 */ |
3357 constructor() { |
3198 constructor() { |
3358 /** @type {any} */ |
3199 /** @type {any} */ |
3359 this.listeners = {}; |
3200 this.listeners = {}; |
3360 this.handleEvent = this.handleEvent.bind(this); |
3201 this.handleEvent = this.handleEvent.bind(this); |
3361 } |
3202 } |
3362 add( /** @type {any} */eventType, /** @type {any} */instance) { |
3203 add(/** @type {any} */eventType, /** @type {any} */instance) { |
3363 if (!this.listeners[eventType]) { |
3204 if (!this.listeners[eventType]) { |
3364 // Adding first listener for this type, so bind event. |
3205 // Adding first listener for this type, so bind event. |
3365 window.addEventListener(eventType, this.handleEvent); |
3206 window.addEventListener(eventType, this.handleEvent); |
3366 this.listeners[eventType] = []; |
3207 this.listeners[eventType] = []; |
3367 } |
3208 } |
3368 this.listeners[eventType].push(instance); |
3209 this.listeners[eventType].push(instance); |
3369 } |
3210 } |
3370 remove( /** @type {any} */eventType, /** @type {any} */instance) { |
3211 remove(/** @type {any} */eventType, /** @type {any} */instance) { |
3371 if (!this.listeners[eventType]) { |
3212 if (!this.listeners[eventType]) { |
3372 return; |
3213 return; |
3373 } |
3214 } |
3374 this.listeners[eventType] = this.listeners[eventType].filter(( /** @type {any} */listener) => listener !== instance); |
3215 this.listeners[eventType] = this.listeners[eventType].filter((/** @type {any} */listener) => listener !== instance); |
3375 if (!this.listeners[eventType].length) { |
3216 if (!this.listeners[eventType].length) { |
3376 // Removing last listener for this type, so unbind event. |
3217 // Removing last listener for this type, so unbind event. |
3377 window.removeEventListener(eventType, this.handleEvent); |
3218 window.removeEventListener(eventType, this.handleEvent); |
3378 delete this.listeners[eventType]; |
3219 delete this.listeners[eventType]; |
3379 } |
3220 } |
3380 } |
3221 } |
3381 handleEvent( /** @type {any} */event) { |
3222 handleEvent(/** @type {any} */event) { |
3382 this.listeners[event.type]?.forEach(( /** @type {any} */instance) => { |
3223 this.listeners[event.type]?.forEach((/** @type {any} */instance) => { |
3383 instance.handleEvent(event); |
3224 instance.handleEvent(event); |
3384 }); |
3225 }); |
3385 } |
3226 } |
3386 } |
3227 } |
3387 /* harmony default export */ const listener = (Listener); |
3228 /* harmony default export */ const listener = (Listener); |
3388 |
3229 |
3389 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js |
3230 ;// ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js |
3390 /** |
3231 /** |
3391 * WordPress dependencies |
3232 * WordPress dependencies |
3392 */ |
3233 */ |
3393 |
3234 |
3394 |
3235 |
3432 }); |
3273 }); |
3433 |
3274 |
3434 // @ts-ignore We don't need to fix the type-related issues because this is deprecated. |
3275 // @ts-ignore We don't need to fix the type-related issues because this is deprecated. |
3435 return createHigherOrderComponent(WrappedComponent => { |
3276 return createHigherOrderComponent(WrappedComponent => { |
3436 class Wrapper extends external_wp_element_namespaceObject.Component { |
3277 class Wrapper extends external_wp_element_namespaceObject.Component { |
3437 constructor( /** @type {any} */props) { |
3278 constructor(/** @type {any} */props) { |
3438 super(props); |
3279 super(props); |
3439 this.handleEvent = this.handleEvent.bind(this); |
3280 this.handleEvent = this.handleEvent.bind(this); |
3440 this.handleRef = this.handleRef.bind(this); |
3281 this.handleRef = this.handleRef.bind(this); |
3441 } |
3282 } |
3442 componentDidMount() { |
3283 componentDidMount() { |
3447 componentWillUnmount() { |
3288 componentWillUnmount() { |
3448 Object.keys(eventTypesToHandlers).forEach(eventType => { |
3289 Object.keys(eventTypesToHandlers).forEach(eventType => { |
3449 with_global_events_listener.remove(eventType, this); |
3290 with_global_events_listener.remove(eventType, this); |
3450 }); |
3291 }); |
3451 } |
3292 } |
3452 handleEvent( /** @type {any} */event) { |
3293 handleEvent(/** @type {any} */event) { |
3453 const handler = eventTypesToHandlers[( /** @type {keyof GlobalEventHandlersEventMap} */ |
3294 const handler = eventTypesToHandlers[(/** @type {keyof GlobalEventHandlersEventMap} */ |
3454 event.type |
3295 event.type |
3455 |
3296 |
3456 /* eslint-enable jsdoc/no-undefined-types */)]; |
3297 /* eslint-enable jsdoc/no-undefined-types */)]; |
3457 if (typeof this.wrappedRef[handler] === 'function') { |
3298 if (typeof this.wrappedRef[handler] === 'function') { |
3458 this.wrappedRef[handler](event); |
3299 this.wrappedRef[handler](event); |
3459 } |
3300 } |
3460 } |
3301 } |
3461 handleRef( /** @type {any} */el) { |
3302 handleRef(/** @type {any} */el) { |
3462 this.wrappedRef = el; |
3303 this.wrappedRef = el; |
3463 // Any component using `withGlobalEvents` that is not setting a `ref` |
3304 // Any component using `withGlobalEvents` that is not setting a `ref` |
3464 // will cause `this.props.forwardedRef` to be `null`, so we need this |
3305 // will cause `this.props.forwardedRef` to be `null`, so we need this |
3465 // check. |
3306 // check. |
3466 if (this.props.forwardedRef) { |
3307 if (this.props.forwardedRef) { |
3481 }); |
3322 }); |
3482 }); |
3323 }); |
3483 }, 'withGlobalEvents'); |
3324 }, 'withGlobalEvents'); |
3484 } |
3325 } |
3485 |
3326 |
3486 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-instance-id/index.js |
3327 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-instance-id/index.js |
3487 /** |
3328 /** |
3488 * WordPress dependencies |
3329 * WordPress dependencies |
3489 */ |
3330 */ |
3490 |
3331 |
3491 const instanceMap = new WeakMap(); |
3332 const instanceMap = new WeakMap(); |
3532 return prefix ? `${prefix}-${id}` : id; |
3373 return prefix ? `${prefix}-${id}` : id; |
3533 }, [object, preferredId, prefix]); |
3374 }, [object, preferredId, prefix]); |
3534 } |
3375 } |
3535 /* harmony default export */ const use_instance_id = (useInstanceId); |
3376 /* harmony default export */ const use_instance_id = (useInstanceId); |
3536 |
3377 |
3537 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js |
3378 ;// ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js |
3538 /** |
3379 /** |
3539 * Internal dependencies |
3380 * Internal dependencies |
3540 */ |
3381 */ |
3541 |
3382 |
3542 |
3383 |
3543 |
3384 |
3544 |
3385 |
3545 /** |
3386 /** |
3546 * A Higher Order Component used to be provide a unique instance ID by |
3387 * A Higher Order Component used to provide a unique instance ID by component. |
3547 * component. |
|
3548 */ |
3388 */ |
3549 const withInstanceId = createHigherOrderComponent(WrappedComponent => { |
3389 const withInstanceId = createHigherOrderComponent(WrappedComponent => { |
3550 return props => { |
3390 return props => { |
3551 const instanceId = use_instance_id(WrappedComponent); |
3391 const instanceId = use_instance_id(WrappedComponent); |
3552 // @ts-ignore |
3392 // @ts-ignore |
3556 }); |
3396 }); |
3557 }; |
3397 }; |
3558 }, 'instanceId'); |
3398 }, 'instanceId'); |
3559 /* harmony default export */ const with_instance_id = (withInstanceId); |
3399 /* harmony default export */ const with_instance_id = (withInstanceId); |
3560 |
3400 |
3561 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js |
3401 ;// ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js |
3562 /** |
3402 /** |
3563 * WordPress dependencies |
3403 * WordPress dependencies |
3564 */ |
3404 */ |
3565 |
3405 |
3566 |
3406 |
3619 } |
3459 } |
3620 }; |
3460 }; |
3621 }, 'withSafeTimeout'); |
3461 }, 'withSafeTimeout'); |
3622 /* harmony default export */ const with_safe_timeout = (withSafeTimeout); |
3462 /* harmony default export */ const with_safe_timeout = (withSafeTimeout); |
3623 |
3463 |
3624 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js |
3464 ;// ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js |
3625 /** |
3465 /** |
3626 * WordPress dependencies |
3466 * WordPress dependencies |
3627 */ |
3467 */ |
3628 |
3468 |
3629 |
3469 |
3649 since: '5.8', |
3489 since: '5.8', |
3650 alternative: 'wp.element.useState' |
3490 alternative: 'wp.element.useState' |
3651 }); |
3491 }); |
3652 return createHigherOrderComponent(OriginalComponent => { |
3492 return createHigherOrderComponent(OriginalComponent => { |
3653 return class WrappedComponent extends external_wp_element_namespaceObject.Component { |
3493 return class WrappedComponent extends external_wp_element_namespaceObject.Component { |
3654 constructor( /** @type {any} */props) { |
3494 constructor(/** @type {any} */props) { |
3655 super(props); |
3495 super(props); |
3656 this.setState = this.setState.bind(this); |
3496 this.setState = this.setState.bind(this); |
3657 this.state = initialState; |
3497 this.state = initialState; |
3658 } |
3498 } |
3659 render() { |
3499 render() { |
3665 } |
3505 } |
3666 }; |
3506 }; |
3667 }, 'withState'); |
3507 }, 'withState'); |
3668 } |
3508 } |
3669 |
3509 |
3670 ;// CONCATENATED MODULE: external ["wp","dom"] |
3510 ;// external ["wp","dom"] |
3671 const external_wp_dom_namespaceObject = window["wp"]["dom"]; |
3511 const external_wp_dom_namespaceObject = window["wp"]["dom"]; |
3672 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-ref-effect/index.js |
3512 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-ref-effect/index.js |
3673 /** |
3513 /** |
3674 * External dependencies |
3514 * External dependencies |
3675 */ |
3515 */ |
3676 |
3516 |
3677 /** |
3517 /** |
3697 * @param dependencies Dependencies of the callback. |
3537 * @param dependencies Dependencies of the callback. |
3698 * |
3538 * |
3699 * @return Ref callback. |
3539 * @return Ref callback. |
3700 */ |
3540 */ |
3701 function useRefEffect(callback, dependencies) { |
3541 function useRefEffect(callback, dependencies) { |
3702 const cleanup = (0,external_wp_element_namespaceObject.useRef)(); |
3542 const cleanupRef = (0,external_wp_element_namespaceObject.useRef)(); |
3703 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
3543 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
3704 if (node) { |
3544 if (node) { |
3705 cleanup.current = callback(node); |
3545 cleanupRef.current = callback(node); |
3706 } else if (cleanup.current) { |
3546 } else if (cleanupRef.current) { |
3707 cleanup.current(); |
3547 cleanupRef.current(); |
3708 } |
3548 } |
3709 }, dependencies); |
3549 }, dependencies); |
3710 } |
3550 } |
3711 |
3551 |
3712 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-constrained-tabbing/index.js |
3552 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-constrained-tabbing/index.js |
3713 /** |
3553 /** |
3714 * WordPress dependencies |
3554 * WordPress dependencies |
3715 */ |
3555 */ |
3716 |
3556 |
3717 |
3557 |
3740 * ); |
3580 * ); |
3741 * } |
3581 * } |
3742 * ``` |
3582 * ``` |
3743 */ |
3583 */ |
3744 function useConstrainedTabbing() { |
3584 function useConstrainedTabbing() { |
3745 return useRefEffect(( /** @type {HTMLElement} */node) => { |
3585 return useRefEffect((/** @type {HTMLElement} */node) => { |
3746 function onKeyDown( /** @type {KeyboardEvent} */event) { |
3586 function onKeyDown(/** @type {KeyboardEvent} */event) { |
3747 const { |
3587 const { |
3748 key, |
3588 key, |
3749 shiftKey, |
3589 shiftKey, |
3750 target |
3590 target |
3751 } = event; |
3591 } = event; |
3752 if (key !== 'Tab') { |
3592 if (key !== 'Tab') { |
3753 return; |
3593 return; |
3754 } |
3594 } |
3755 const action = shiftKey ? 'findPrevious' : 'findNext'; |
3595 const action = shiftKey ? 'findPrevious' : 'findNext'; |
3756 const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action]( /** @type {HTMLElement} */target) || null; |
3596 const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action](/** @type {HTMLElement} */target) || null; |
3757 |
3597 |
3758 // When the target element contains the element that is about to |
3598 // When the target element contains the element that is about to |
3759 // receive focus, for example when the target is a tabbable |
3599 // receive focus, for example when the target is a tabbable |
3760 // container, browsers may disagree on where to move focus next. |
3600 // container, browsers may disagree on where to move focus next. |
3761 // In this case we can't rely on native browsers behavior. We need |
3601 // In this case we can't rely on native browsers behavior. We need |
3762 // to manage focus instead. |
3602 // to manage focus instead. |
3763 // See https://github.com/WordPress/gutenberg/issues/46041. |
3603 // See https://github.com/WordPress/gutenberg/issues/46041. |
3764 if ( /** @type {HTMLElement} */target.contains(nextElement)) { |
3604 if (/** @type {HTMLElement} */target.contains(nextElement)) { |
3765 event.preventDefault(); |
3605 event.preventDefault(); |
3766 nextElement?.focus(); |
3606 nextElement?.focus(); |
3767 return; |
3607 return; |
3768 } |
3608 } |
3769 |
3609 |
3799 /* harmony default export */ const use_constrained_tabbing = (useConstrainedTabbing); |
3639 /* harmony default export */ const use_constrained_tabbing = (useConstrainedTabbing); |
3800 |
3640 |
3801 // EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js |
3641 // EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js |
3802 var dist_clipboard = __webpack_require__(3758); |
3642 var dist_clipboard = __webpack_require__(3758); |
3803 var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard); |
3643 var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard); |
3804 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-on-click/index.js |
3644 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-copy-on-click/index.js |
3805 /** |
3645 /** |
3806 * External dependencies |
3646 * External dependencies |
3807 */ |
3647 */ |
3808 |
3648 |
3809 |
3649 |
3833 since: '5.8', |
3673 since: '5.8', |
3834 alternative: 'wp.compose.useCopyToClipboard' |
3674 alternative: 'wp.compose.useCopyToClipboard' |
3835 }); |
3675 }); |
3836 |
3676 |
3837 /** @type {import('react').MutableRefObject<Clipboard | undefined>} */ |
3677 /** @type {import('react').MutableRefObject<Clipboard | undefined>} */ |
3838 const clipboard = (0,external_wp_element_namespaceObject.useRef)(); |
3678 const clipboardRef = (0,external_wp_element_namespaceObject.useRef)(); |
3839 const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false); |
3679 const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false); |
3840 (0,external_wp_element_namespaceObject.useEffect)(() => { |
3680 (0,external_wp_element_namespaceObject.useEffect)(() => { |
3841 /** @type {number | undefined} */ |
3681 /** @type {number | undefined} */ |
3842 let timeoutId; |
3682 let timeoutId; |
3843 if (!ref.current) { |
3683 if (!ref.current) { |
3844 return; |
3684 return; |
3845 } |
3685 } |
3846 |
3686 |
3847 // Clipboard listens to click events. |
3687 // Clipboard listens to click events. |
3848 clipboard.current = new (clipboard_default())(ref.current, { |
3688 clipboardRef.current = new (clipboard_default())(ref.current, { |
3849 text: () => typeof text === 'function' ? text() : text |
3689 text: () => typeof text === 'function' ? text() : text |
3850 }); |
3690 }); |
3851 clipboard.current.on('success', ({ |
3691 clipboardRef.current.on('success', ({ |
3852 clearSelection, |
3692 clearSelection, |
3853 trigger |
3693 trigger |
3854 }) => { |
3694 }) => { |
3855 // Clearing selection will move focus back to the triggering button, |
3695 // Clearing selection will move focus back to the triggering button, |
3856 // ensuring that it is not reset to the body, and further that it is |
3696 // ensuring that it is not reset to the body, and further that it is |
3866 clearTimeout(timeoutId); |
3706 clearTimeout(timeoutId); |
3867 timeoutId = setTimeout(() => setHasCopied(false), timeout); |
3707 timeoutId = setTimeout(() => setHasCopied(false), timeout); |
3868 } |
3708 } |
3869 }); |
3709 }); |
3870 return () => { |
3710 return () => { |
3871 if (clipboard.current) { |
3711 if (clipboardRef.current) { |
3872 clipboard.current.destroy(); |
3712 clipboardRef.current.destroy(); |
3873 } |
3713 } |
3874 clearTimeout(timeoutId); |
3714 clearTimeout(timeoutId); |
3875 }; |
3715 }; |
3876 }, [text, timeout, setHasCopied]); |
3716 }, [text, timeout, setHasCopied]); |
3877 return hasCopied; |
3717 return hasCopied; |
3878 } |
3718 } |
3879 |
3719 |
3880 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-to-clipboard/index.js |
3720 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-copy-to-clipboard/index.js |
3881 /** |
3721 /** |
3882 * External dependencies |
3722 * External dependencies |
3883 */ |
3723 */ |
3884 |
3724 |
3885 |
3725 |
3898 * @param {T} value |
3738 * @param {T} value |
3899 * @return {import('react').RefObject<T>} The updated ref |
3739 * @return {import('react').RefObject<T>} The updated ref |
3900 */ |
3740 */ |
3901 function useUpdatedRef(value) { |
3741 function useUpdatedRef(value) { |
3902 const ref = (0,external_wp_element_namespaceObject.useRef)(value); |
3742 const ref = (0,external_wp_element_namespaceObject.useRef)(value); |
3903 ref.current = value; |
3743 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
3744 ref.current = value; |
|
3745 }, [value]); |
|
3904 return ref; |
3746 return ref; |
3905 } |
3747 } |
3906 |
3748 |
3907 /** |
3749 /** |
3908 * Copies the given text to the clipboard when the element is clicked. |
3750 * Copies the given text to the clipboard when the element is clicked. |
3941 clipboard.destroy(); |
3783 clipboard.destroy(); |
3942 }; |
3784 }; |
3943 }, []); |
3785 }, []); |
3944 } |
3786 } |
3945 |
3787 |
3946 ;// CONCATENATED MODULE: external ["wp","keycodes"] |
3788 ;// external ["wp","keycodes"] |
3947 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; |
3789 const external_wp_keycodes_namespaceObject = window["wp"]["keycodes"]; |
3948 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-on-mount/index.js |
3790 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-focus-on-mount/index.js |
3949 /** |
3791 /** |
3950 * WordPress dependencies |
3792 * WordPress dependencies |
3951 */ |
3793 */ |
3952 |
3794 |
3953 |
3795 |
3995 preventScroll: true |
3837 preventScroll: true |
3996 }); |
3838 }); |
3997 }; |
3839 }; |
3998 |
3840 |
3999 /** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */ |
3841 /** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */ |
4000 const timerId = (0,external_wp_element_namespaceObject.useRef)(); |
3842 const timerIdRef = (0,external_wp_element_namespaceObject.useRef)(); |
4001 (0,external_wp_element_namespaceObject.useEffect)(() => { |
3843 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4002 focusOnMountRef.current = focusOnMount; |
3844 focusOnMountRef.current = focusOnMount; |
4003 }, [focusOnMount]); |
3845 }, [focusOnMount]); |
4004 return useRefEffect(node => { |
3846 return useRefEffect(node => { |
4005 var _node$ownerDocument$a; |
3847 var _node$ownerDocument$a; |
4007 return; |
3849 return; |
4008 } |
3850 } |
4009 if (node.contains((_node$ownerDocument$a = node.ownerDocument?.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) { |
3851 if (node.contains((_node$ownerDocument$a = node.ownerDocument?.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) { |
4010 return; |
3852 return; |
4011 } |
3853 } |
4012 if (focusOnMountRef.current === 'firstElement') { |
3854 if (focusOnMountRef.current !== 'firstElement') { |
4013 timerId.current = setTimeout(() => { |
3855 setFocus(node); |
4014 const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0]; |
|
4015 if (firstTabbable) { |
|
4016 setFocus(firstTabbable); |
|
4017 } |
|
4018 }, 0); |
|
4019 return; |
3856 return; |
4020 } |
3857 } |
4021 setFocus(node); |
3858 timerIdRef.current = setTimeout(() => { |
3859 const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0]; |
|
3860 if (firstTabbable) { |
|
3861 setFocus(firstTabbable); |
|
3862 } |
|
3863 }, 0); |
|
4022 return () => { |
3864 return () => { |
4023 if (timerId.current) { |
3865 if (timerIdRef.current) { |
4024 clearTimeout(timerId.current); |
3866 clearTimeout(timerIdRef.current); |
4025 } |
3867 } |
4026 }; |
3868 }; |
4027 }, []); |
3869 }, []); |
4028 } |
3870 } |
4029 |
3871 |
4030 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-return/index.js |
3872 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-focus-return/index.js |
4031 /** |
3873 /** |
4032 * WordPress dependencies |
3874 * WordPress dependencies |
4033 */ |
3875 */ |
4034 |
3876 |
4035 |
3877 |
4067 (0,external_wp_element_namespaceObject.useEffect)(() => { |
3909 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4068 onFocusReturnRef.current = onFocusReturn; |
3910 onFocusReturnRef.current = onFocusReturn; |
4069 }, [onFocusReturn]); |
3911 }, [onFocusReturn]); |
4070 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
3912 return (0,external_wp_element_namespaceObject.useCallback)(node => { |
4071 if (node) { |
3913 if (node) { |
3914 var _activeDocument$activ; |
|
4072 // Set ref to be used when unmounting. |
3915 // Set ref to be used when unmounting. |
4073 ref.current = node; |
3916 ref.current = node; |
4074 |
3917 |
4075 // Only set when the node mounts. |
3918 // Only set when the node mounts. |
4076 if (focusedBeforeMount.current) { |
3919 if (focusedBeforeMount.current) { |
4077 return; |
3920 return; |
4078 } |
3921 } |
4079 focusedBeforeMount.current = node.ownerDocument.activeElement; |
3922 const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument; |
3923 focusedBeforeMount.current = (_activeDocument$activ = activeDocument?.activeElement) !== null && _activeDocument$activ !== void 0 ? _activeDocument$activ : null; |
|
4080 } else if (focusedBeforeMount.current) { |
3924 } else if (focusedBeforeMount.current) { |
4081 const isFocused = ref.current?.contains(ref.current?.ownerDocument.activeElement); |
3925 const isFocused = ref.current?.contains(ref.current?.ownerDocument.activeElement); |
4082 if (ref.current?.isConnected && !isFocused) { |
3926 if (ref.current?.isConnected && !isFocused) { |
4083 var _origin; |
3927 var _origin; |
4084 (_origin = origin) !== null && _origin !== void 0 ? _origin : origin = focusedBeforeMount.current; |
3928 (_origin = origin) !== null && _origin !== void 0 ? _origin : origin = focusedBeforeMount.current; |
4098 } |
3942 } |
4099 }, []); |
3943 }, []); |
4100 } |
3944 } |
4101 /* harmony default export */ const use_focus_return = (useFocusReturn); |
3945 /* harmony default export */ const use_focus_return = (useFocusReturn); |
4102 |
3946 |
4103 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-outside/index.js |
3947 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-focus-outside/index.js |
4104 /** |
3948 /** |
4105 * WordPress dependencies |
3949 * WordPress dependencies |
4106 */ |
3950 */ |
4107 |
3951 |
4108 |
3952 |
4150 * |
3994 * |
4151 * @return An object containing event handlers. Bind the event handlers to a |
3995 * @return An object containing event handlers. Bind the event handlers to a |
4152 * wrapping element element to capture when focus moves outside that element. |
3996 * wrapping element element to capture when focus moves outside that element. |
4153 */ |
3997 */ |
4154 function useFocusOutside(onFocusOutside) { |
3998 function useFocusOutside(onFocusOutside) { |
4155 const currentOnFocusOutside = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside); |
3999 const currentOnFocusOutsideRef = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside); |
4156 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4000 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4157 currentOnFocusOutside.current = onFocusOutside; |
4001 currentOnFocusOutsideRef.current = onFocusOutside; |
4158 }, [onFocusOutside]); |
4002 }, [onFocusOutside]); |
4159 const preventBlurCheck = (0,external_wp_element_namespaceObject.useRef)(false); |
4003 const preventBlurCheckRef = (0,external_wp_element_namespaceObject.useRef)(false); |
4160 const blurCheckTimeoutId = (0,external_wp_element_namespaceObject.useRef)(); |
4004 const blurCheckTimeoutIdRef = (0,external_wp_element_namespaceObject.useRef)(); |
4161 |
4005 |
4162 /** |
4006 /** |
4163 * Cancel a blur check timeout. |
4007 * Cancel a blur check timeout. |
4164 */ |
4008 */ |
4165 const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => { |
4009 const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => { |
4166 clearTimeout(blurCheckTimeoutId.current); |
4010 clearTimeout(blurCheckTimeoutIdRef.current); |
4167 }, []); |
4011 }, []); |
4168 |
4012 |
4169 // Cancel blur checks on unmount. |
4013 // Cancel blur checks on unmount. |
4170 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4014 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4171 return () => cancelBlurCheck(); |
4015 return () => cancelBlurCheck(); |
4193 type, |
4037 type, |
4194 target |
4038 target |
4195 } = event; |
4039 } = event; |
4196 const isInteractionEnd = ['mouseup', 'touchend'].includes(type); |
4040 const isInteractionEnd = ['mouseup', 'touchend'].includes(type); |
4197 if (isInteractionEnd) { |
4041 if (isInteractionEnd) { |
4198 preventBlurCheck.current = false; |
4042 preventBlurCheckRef.current = false; |
4199 } else if (isFocusNormalizedButton(target)) { |
4043 } else if (isFocusNormalizedButton(target)) { |
4200 preventBlurCheck.current = true; |
4044 preventBlurCheckRef.current = true; |
4201 } |
4045 } |
4202 }, []); |
4046 }, []); |
4203 |
4047 |
4204 /** |
4048 /** |
4205 * A callback triggered when a blur event occurs on the element the handler |
4049 * A callback triggered when a blur event occurs on the element the handler |
4212 // React does not allow using an event reference asynchronously |
4056 // React does not allow using an event reference asynchronously |
4213 // due to recycling behavior, except when explicitly persisted. |
4057 // due to recycling behavior, except when explicitly persisted. |
4214 event.persist(); |
4058 event.persist(); |
4215 |
4059 |
4216 // Skip blur check if clicking button. See `normalizeButtonFocus`. |
4060 // Skip blur check if clicking button. See `normalizeButtonFocus`. |
4217 if (preventBlurCheck.current) { |
4061 if (preventBlurCheckRef.current) { |
4218 return; |
4062 return; |
4219 } |
4063 } |
4220 |
4064 |
4221 // The usage of this attribute should be avoided. The only use case |
4065 // The usage of this attribute should be avoided. The only use case |
4222 // would be when we load modals that are not React components and |
4066 // would be when we load modals that are not React components and |
4227 // on all other cases. |
4071 // on all other cases. |
4228 const ignoreForRelatedTarget = event.target.getAttribute('data-unstable-ignore-focus-outside-for-relatedtarget'); |
4072 const ignoreForRelatedTarget = event.target.getAttribute('data-unstable-ignore-focus-outside-for-relatedtarget'); |
4229 if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) { |
4073 if (ignoreForRelatedTarget && event.relatedTarget?.closest(ignoreForRelatedTarget)) { |
4230 return; |
4074 return; |
4231 } |
4075 } |
4232 blurCheckTimeoutId.current = setTimeout(() => { |
4076 blurCheckTimeoutIdRef.current = setTimeout(() => { |
4233 // If document is not focused then focus should remain |
4077 // If document is not focused then focus should remain |
4234 // inside the wrapped component and therefore we cancel |
4078 // inside the wrapped component and therefore we cancel |
4235 // this blur event thereby leaving focus in place. |
4079 // this blur event thereby leaving focus in place. |
4236 // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus. |
4080 // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus. |
4237 if (!document.hasFocus()) { |
4081 if (!document.hasFocus()) { |
4238 event.preventDefault(); |
4082 event.preventDefault(); |
4239 return; |
4083 return; |
4240 } |
4084 } |
4241 if ('function' === typeof currentOnFocusOutside.current) { |
4085 if ('function' === typeof currentOnFocusOutsideRef.current) { |
4242 currentOnFocusOutside.current(event); |
4086 currentOnFocusOutsideRef.current(event); |
4243 } |
4087 } |
4244 }, 0); |
4088 }, 0); |
4245 }, []); |
4089 }, []); |
4246 return { |
4090 return { |
4247 onFocus: cancelBlurCheck, |
4091 onFocus: cancelBlurCheck, |
4251 onTouchEnd: normalizeButtonFocus, |
4095 onTouchEnd: normalizeButtonFocus, |
4252 onBlur: queueBlurCheck |
4096 onBlur: queueBlurCheck |
4253 }; |
4097 }; |
4254 } |
4098 } |
4255 |
4099 |
4256 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-merge-refs/index.js |
4100 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-merge-refs/index.js |
4257 /** |
4101 /** |
4258 * WordPress dependencies |
4102 * WordPress dependencies |
4259 */ |
4103 */ |
4260 |
4104 |
4261 |
4105 |
4324 * |
4168 * |
4325 * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback. |
4169 * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback. |
4326 */ |
4170 */ |
4327 function useMergeRefs(refs) { |
4171 function useMergeRefs(refs) { |
4328 const element = (0,external_wp_element_namespaceObject.useRef)(); |
4172 const element = (0,external_wp_element_namespaceObject.useRef)(); |
4329 const isAttached = (0,external_wp_element_namespaceObject.useRef)(false); |
4173 const isAttachedRef = (0,external_wp_element_namespaceObject.useRef)(false); |
4330 const didElementChange = (0,external_wp_element_namespaceObject.useRef)(false); |
4174 const didElementChangeRef = (0,external_wp_element_namespaceObject.useRef)(false); |
4331 /* eslint-disable jsdoc/no-undefined-types */ |
4175 /* eslint-disable jsdoc/no-undefined-types */ |
4332 /** @type {import('react').MutableRefObject<TRef[]>} */ |
4176 /** @type {import('react').MutableRefObject<TRef[]>} */ |
4333 /* eslint-enable jsdoc/no-undefined-types */ |
4177 /* eslint-enable jsdoc/no-undefined-types */ |
4334 const previousRefs = (0,external_wp_element_namespaceObject.useRef)([]); |
4178 const previousRefsRef = (0,external_wp_element_namespaceObject.useRef)([]); |
4335 const currentRefs = (0,external_wp_element_namespaceObject.useRef)(refs); |
4179 const currentRefsRef = (0,external_wp_element_namespaceObject.useRef)(refs); |
4336 |
4180 |
4337 // Update on render before the ref callback is called, so the ref callback |
4181 // Update on render before the ref callback is called, so the ref callback |
4338 // always has access to the current refs. |
4182 // always has access to the current refs. |
4339 currentRefs.current = refs; |
4183 currentRefsRef.current = refs; |
4340 |
4184 |
4341 // If any of the refs change, call the previous ref with `null` and the new |
4185 // If any of the refs change, call the previous ref with `null` and the new |
4342 // ref with the node, except when the element changes in the same cycle, in |
4186 // ref with the node, except when the element changes in the same cycle, in |
4343 // which case the ref callbacks will already have been called. |
4187 // which case the ref callbacks will already have been called. |
4344 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
4188 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
4345 if (didElementChange.current === false && isAttached.current === true) { |
4189 if (didElementChangeRef.current === false && isAttachedRef.current === true) { |
4346 refs.forEach((ref, index) => { |
4190 refs.forEach((ref, index) => { |
4347 const previousRef = previousRefs.current[index]; |
4191 const previousRef = previousRefsRef.current[index]; |
4348 if (ref !== previousRef) { |
4192 if (ref !== previousRef) { |
4349 assignRef(previousRef, null); |
4193 assignRef(previousRef, null); |
4350 assignRef(ref, element.current); |
4194 assignRef(ref, element.current); |
4351 } |
4195 } |
4352 }); |
4196 }); |
4353 } |
4197 } |
4354 previousRefs.current = refs; |
4198 previousRefsRef.current = refs; |
4355 }, refs); |
4199 }, refs); |
4356 |
4200 |
4357 // No dependencies, must be reset after every render so ref callbacks are |
4201 // No dependencies, must be reset after every render so ref callbacks are |
4358 // correctly called after a ref change. |
4202 // correctly called after a ref change. |
4359 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
4203 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
4360 didElementChange.current = false; |
4204 didElementChangeRef.current = false; |
4361 }); |
4205 }); |
4362 |
4206 |
4363 // There should be no dependencies so that `callback` is only called when |
4207 // There should be no dependencies so that `callback` is only called when |
4364 // the node changes. |
4208 // the node changes. |
4365 return (0,external_wp_element_namespaceObject.useCallback)(value => { |
4209 return (0,external_wp_element_namespaceObject.useCallback)(value => { |
4366 // Update the element so it can be used when calling ref callbacks on a |
4210 // Update the element so it can be used when calling ref callbacks on a |
4367 // dependency change. |
4211 // dependency change. |
4368 assignRef(element, value); |
4212 assignRef(element, value); |
4369 didElementChange.current = true; |
4213 didElementChangeRef.current = true; |
4370 isAttached.current = value !== null; |
4214 isAttachedRef.current = value !== null; |
4371 |
4215 |
4372 // When an element changes, the current ref callback should be called |
4216 // When an element changes, the current ref callback should be called |
4373 // with the new element and the previous one with `null`. |
4217 // with the new element and the previous one with `null`. |
4374 const refsToAssign = value ? currentRefs.current : previousRefs.current; |
4218 const refsToAssign = value ? currentRefsRef.current : previousRefsRef.current; |
4375 |
4219 |
4376 // Update the latest refs. |
4220 // Update the latest refs. |
4377 for (const ref of refsToAssign) { |
4221 for (const ref of refsToAssign) { |
4378 assignRef(ref, value); |
4222 assignRef(ref, value); |
4379 } |
4223 } |
4380 }, []); |
4224 }, []); |
4381 } |
4225 } |
4382 |
4226 |
4383 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dialog/index.js |
4227 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-dialog/index.js |
4384 /** |
4228 /** |
4385 * External dependencies |
4229 * External dependencies |
4386 */ |
4230 */ |
4387 |
4231 |
4388 /** |
4232 /** |
4445 tabIndex: -1 |
4289 tabIndex: -1 |
4446 }]; |
4290 }]; |
4447 } |
4291 } |
4448 /* harmony default export */ const use_dialog = (useDialog); |
4292 /* harmony default export */ const use_dialog = (useDialog); |
4449 |
4293 |
4450 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-disabled/index.js |
4294 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-disabled/index.js |
4451 /** |
4295 /** |
4452 * Internal dependencies |
4296 * Internal dependencies |
4453 */ |
4297 */ |
4454 |
4298 |
4455 |
4299 |
4528 updates.forEach(update => update()); |
4372 updates.forEach(update => update()); |
4529 }; |
4373 }; |
4530 }, [isDisabledProp]); |
4374 }, [isDisabledProp]); |
4531 } |
4375 } |
4532 |
4376 |
4533 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-isomorphic-layout-effect/index.js |
4377 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-event/index.js |
4378 /** |
|
4379 * WordPress dependencies |
|
4380 */ |
|
4381 |
|
4382 |
|
4383 /** |
|
4384 * Any function. |
|
4385 */ |
|
4386 |
|
4387 /** |
|
4388 * Creates a stable callback function that has access to the latest state and |
|
4389 * can be used within event handlers and effect callbacks. Throws when used in |
|
4390 * the render phase. |
|
4391 * |
|
4392 * @param callback The callback function to wrap. |
|
4393 * |
|
4394 * @example |
|
4395 * |
|
4396 * ```tsx |
|
4397 * function Component( props ) { |
|
4398 * const onClick = useEvent( props.onClick ); |
|
4399 * useEffect( () => { |
|
4400 * onClick(); |
|
4401 * // Won't trigger the effect again when props.onClick is updated. |
|
4402 * }, [ onClick ] ); |
|
4403 * // Won't re-render Button when props.onClick is updated (if `Button` is |
|
4404 * // wrapped in `React.memo`). |
|
4405 * return <Button onClick={ onClick } />; |
|
4406 * } |
|
4407 * ``` |
|
4408 */ |
|
4409 function useEvent( |
|
4410 /** |
|
4411 * The callback function to wrap. |
|
4412 */ |
|
4413 callback) { |
|
4414 const ref = (0,external_wp_element_namespaceObject.useRef)(() => { |
|
4415 throw new Error('Callbacks created with `useEvent` cannot be called during rendering.'); |
|
4416 }); |
|
4417 (0,external_wp_element_namespaceObject.useInsertionEffect)(() => { |
|
4418 ref.current = callback; |
|
4419 }); |
|
4420 return (0,external_wp_element_namespaceObject.useCallback)((...args) => ref.current?.(...args), []); |
|
4421 } |
|
4422 |
|
4423 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-isomorphic-layout-effect/index.js |
|
4534 /** |
4424 /** |
4535 * WordPress dependencies |
4425 * WordPress dependencies |
4536 */ |
4426 */ |
4537 |
4427 |
4538 |
4428 |
4542 * throws a warning when using useLayoutEffect in that environment. |
4432 * throws a warning when using useLayoutEffect in that environment. |
4543 */ |
4433 */ |
4544 const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect; |
4434 const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect; |
4545 /* harmony default export */ const use_isomorphic_layout_effect = (useIsomorphicLayoutEffect); |
4435 /* harmony default export */ const use_isomorphic_layout_effect = (useIsomorphicLayoutEffect); |
4546 |
4436 |
4547 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dragging/index.js |
4437 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-dragging/index.js |
4548 /** |
4438 /** |
4549 * WordPress dependencies |
4439 * WordPress dependencies |
4550 */ |
4440 */ |
4551 |
4441 |
4552 |
4442 |
4620 // EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js |
4510 // EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js |
4621 var mousetrap_mousetrap = __webpack_require__(1933); |
4511 var mousetrap_mousetrap = __webpack_require__(1933); |
4622 var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap); |
4512 var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap); |
4623 // EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js |
4513 // EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js |
4624 var mousetrap_global_bind = __webpack_require__(5760); |
4514 var mousetrap_global_bind = __webpack_require__(5760); |
4625 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-keyboard-shortcut/index.js |
4515 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-keyboard-shortcut/index.js |
4626 /** |
4516 /** |
4627 * External dependencies |
4517 * External dependencies |
4628 */ |
4518 */ |
4629 |
4519 |
4630 |
4520 |
4654 * |
4544 * |
4655 * @param {string[]|string} shortcuts Keyboard Shortcuts. |
4545 * @param {string[]|string} shortcuts Keyboard Shortcuts. |
4656 * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback. |
4546 * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback. |
4657 * @param {WPKeyboardShortcutConfig} options Shortcut options. |
4547 * @param {WPKeyboardShortcutConfig} options Shortcut options. |
4658 */ |
4548 */ |
4659 function useKeyboardShortcut( /* eslint-enable jsdoc/valid-types */ |
4549 function useKeyboardShortcut(/* eslint-enable jsdoc/valid-types */ |
4660 shortcuts, callback, { |
4550 shortcuts, callback, { |
4661 bindGlobal = false, |
4551 bindGlobal = false, |
4662 eventName = 'keydown', |
4552 eventName = 'keydown', |
4663 isDisabled = false, |
4553 isDisabled = false, |
4664 // This is important for performance considerations. |
4554 // This is important for performance considerations. |
4665 target |
4555 target |
4666 } = {}) { |
4556 } = {}) { |
4667 const currentCallback = (0,external_wp_element_namespaceObject.useRef)(callback); |
4557 const currentCallbackRef = (0,external_wp_element_namespaceObject.useRef)(callback); |
4668 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4558 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4669 currentCallback.current = callback; |
4559 currentCallbackRef.current = callback; |
4670 }, [callback]); |
4560 }, [callback]); |
4671 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4561 (0,external_wp_element_namespaceObject.useEffect)(() => { |
4672 if (isDisabled) { |
4562 if (isDisabled) { |
4673 return; |
4563 return; |
4674 } |
4564 } |
4692 if ((0,external_wp_keycodes_namespaceObject.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) { |
4582 if ((0,external_wp_keycodes_namespaceObject.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) { |
4693 throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`); |
4583 throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`); |
4694 } |
4584 } |
4695 const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; |
4585 const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; |
4696 // @ts-ignore `bindGlobal` is an undocumented property |
4586 // @ts-ignore `bindGlobal` is an undocumented property |
4697 mousetrap[bindFn](shortcut, ( /* eslint-disable jsdoc/valid-types */ |
4587 mousetrap[bindFn](shortcut, (/* eslint-disable jsdoc/valid-types */ |
4698 /** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */...args) => /* eslint-enable jsdoc/valid-types */ |
4588 /** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */...args) => /* eslint-enable jsdoc/valid-types */ |
4699 currentCallback.current(...args), eventName); |
4589 currentCallbackRef.current(...args), eventName); |
4700 }); |
4590 }); |
4701 return () => { |
4591 return () => { |
4702 mousetrap.reset(); |
4592 mousetrap.reset(); |
4703 }; |
4593 }; |
4704 }, [shortcuts, bindGlobal, eventName, target, isDisabled]); |
4594 }, [shortcuts, bindGlobal, eventName, target, isDisabled]); |
4705 } |
4595 } |
4706 /* harmony default export */ const use_keyboard_shortcut = (useKeyboardShortcut); |
4596 /* harmony default export */ const use_keyboard_shortcut = (useKeyboardShortcut); |
4707 |
4597 |
4708 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-media-query/index.js |
4598 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-media-query/index.js |
4709 /** |
4599 /** |
4710 * WordPress dependencies |
4600 * WordPress dependencies |
4711 */ |
4601 */ |
4712 |
4602 |
4713 const matchMediaCache = new Map(); |
4603 const matchMediaCache = new Map(); |
4763 }; |
4653 }; |
4764 }, [query]); |
4654 }, [query]); |
4765 return (0,external_wp_element_namespaceObject.useSyncExternalStore)(source.subscribe, source.getValue, () => false); |
4655 return (0,external_wp_element_namespaceObject.useSyncExternalStore)(source.subscribe, source.getValue, () => false); |
4766 } |
4656 } |
4767 |
4657 |
4768 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-previous/index.js |
4658 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-previous/index.js |
4769 /** |
4659 /** |
4770 * WordPress dependencies |
4660 * WordPress dependencies |
4771 */ |
4661 */ |
4772 |
4662 |
4773 |
4663 |
4789 |
4679 |
4790 // Return previous value (happens before update in useEffect above). |
4680 // Return previous value (happens before update in useEffect above). |
4791 return ref.current; |
4681 return ref.current; |
4792 } |
4682 } |
4793 |
4683 |
4794 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-reduced-motion/index.js |
4684 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-reduced-motion/index.js |
4795 /** |
4685 /** |
4796 * Internal dependencies |
4686 * Internal dependencies |
4797 */ |
4687 */ |
4798 |
4688 |
4799 |
4689 |
4803 * @return {boolean} Reduced motion preference value. |
4693 * @return {boolean} Reduced motion preference value. |
4804 */ |
4694 */ |
4805 const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)'); |
4695 const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)'); |
4806 /* harmony default export */ const use_reduced_motion = (useReducedMotion); |
4696 /* harmony default export */ const use_reduced_motion = (useReducedMotion); |
4807 |
4697 |
4808 // EXTERNAL MODULE: ./node_modules/@wordpress/undo-manager/build-module/index.js |
4698 ;// ./node_modules/@wordpress/undo-manager/build-module/index.js |
4809 var build_module = __webpack_require__(6689); |
4699 /** |
4810 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-state-with-history/index.js |
4700 * WordPress dependencies |
4701 */ |
|
4702 |
|
4703 |
|
4704 /** @typedef {import('./types').HistoryRecord} HistoryRecord */ |
|
4705 /** @typedef {import('./types').HistoryChange} HistoryChange */ |
|
4706 /** @typedef {import('./types').HistoryChanges} HistoryChanges */ |
|
4707 /** @typedef {import('./types').UndoManager} UndoManager */ |
|
4708 |
|
4709 /** |
|
4710 * Merge changes for a single item into a record of changes. |
|
4711 * |
|
4712 * @param {Record< string, HistoryChange >} changes1 Previous changes |
|
4713 * @param {Record< string, HistoryChange >} changes2 NextChanges |
|
4714 * |
|
4715 * @return {Record< string, HistoryChange >} Merged changes |
|
4716 */ |
|
4717 function mergeHistoryChanges(changes1, changes2) { |
|
4718 /** |
|
4719 * @type {Record< string, HistoryChange >} |
|
4720 */ |
|
4721 const newChanges = { |
|
4722 ...changes1 |
|
4723 }; |
|
4724 Object.entries(changes2).forEach(([key, value]) => { |
|
4725 if (newChanges[key]) { |
|
4726 newChanges[key] = { |
|
4727 ...newChanges[key], |
|
4728 to: value.to |
|
4729 }; |
|
4730 } else { |
|
4731 newChanges[key] = value; |
|
4732 } |
|
4733 }); |
|
4734 return newChanges; |
|
4735 } |
|
4736 |
|
4737 /** |
|
4738 * Adds history changes for a single item into a record of changes. |
|
4739 * |
|
4740 * @param {HistoryRecord} record The record to merge into. |
|
4741 * @param {HistoryChanges} changes The changes to merge. |
|
4742 */ |
|
4743 const addHistoryChangesIntoRecord = (record, changes) => { |
|
4744 const existingChangesIndex = record?.findIndex(({ |
|
4745 id: recordIdentifier |
|
4746 }) => { |
|
4747 return typeof recordIdentifier === 'string' ? recordIdentifier === changes.id : external_wp_isShallowEqual_default()(recordIdentifier, changes.id); |
|
4748 }); |
|
4749 const nextRecord = [...record]; |
|
4750 if (existingChangesIndex !== -1) { |
|
4751 // If the edit is already in the stack leave the initial "from" value. |
|
4752 nextRecord[existingChangesIndex] = { |
|
4753 id: changes.id, |
|
4754 changes: mergeHistoryChanges(nextRecord[existingChangesIndex].changes, changes.changes) |
|
4755 }; |
|
4756 } else { |
|
4757 nextRecord.push(changes); |
|
4758 } |
|
4759 return nextRecord; |
|
4760 }; |
|
4761 |
|
4762 /** |
|
4763 * Creates an undo manager. |
|
4764 * |
|
4765 * @return {UndoManager} Undo manager. |
|
4766 */ |
|
4767 function createUndoManager() { |
|
4768 /** |
|
4769 * @type {HistoryRecord[]} |
|
4770 */ |
|
4771 let history = []; |
|
4772 /** |
|
4773 * @type {HistoryRecord} |
|
4774 */ |
|
4775 let stagedRecord = []; |
|
4776 /** |
|
4777 * @type {number} |
|
4778 */ |
|
4779 let offset = 0; |
|
4780 const dropPendingRedos = () => { |
|
4781 history = history.slice(0, offset || undefined); |
|
4782 offset = 0; |
|
4783 }; |
|
4784 const appendStagedRecordToLatestHistoryRecord = () => { |
|
4785 var _history$index; |
|
4786 const index = history.length === 0 ? 0 : history.length - 1; |
|
4787 let latestRecord = (_history$index = history[index]) !== null && _history$index !== void 0 ? _history$index : []; |
|
4788 stagedRecord.forEach(changes => { |
|
4789 latestRecord = addHistoryChangesIntoRecord(latestRecord, changes); |
|
4790 }); |
|
4791 stagedRecord = []; |
|
4792 history[index] = latestRecord; |
|
4793 }; |
|
4794 |
|
4795 /** |
|
4796 * Checks whether a record is empty. |
|
4797 * A record is considered empty if it the changes keep the same values. |
|
4798 * Also updates to function values are ignored. |
|
4799 * |
|
4800 * @param {HistoryRecord} record |
|
4801 * @return {boolean} Whether the record is empty. |
|
4802 */ |
|
4803 const isRecordEmpty = record => { |
|
4804 const filteredRecord = record.filter(({ |
|
4805 changes |
|
4806 }) => { |
|
4807 return Object.values(changes).some(({ |
|
4808 from, |
|
4809 to |
|
4810 }) => typeof from !== 'function' && typeof to !== 'function' && !external_wp_isShallowEqual_default()(from, to)); |
|
4811 }); |
|
4812 return !filteredRecord.length; |
|
4813 }; |
|
4814 return { |
|
4815 /** |
|
4816 * Record changes into the history. |
|
4817 * |
|
4818 * @param {HistoryRecord=} record A record of changes to record. |
|
4819 * @param {boolean} isStaged Whether to immediately create an undo point or not. |
|
4820 */ |
|
4821 addRecord(record, isStaged = false) { |
|
4822 const isEmpty = !record || isRecordEmpty(record); |
|
4823 if (isStaged) { |
|
4824 if (isEmpty) { |
|
4825 return; |
|
4826 } |
|
4827 record.forEach(changes => { |
|
4828 stagedRecord = addHistoryChangesIntoRecord(stagedRecord, changes); |
|
4829 }); |
|
4830 } else { |
|
4831 dropPendingRedos(); |
|
4832 if (stagedRecord.length) { |
|
4833 appendStagedRecordToLatestHistoryRecord(); |
|
4834 } |
|
4835 if (isEmpty) { |
|
4836 return; |
|
4837 } |
|
4838 history.push(record); |
|
4839 } |
|
4840 }, |
|
4841 undo() { |
|
4842 if (stagedRecord.length) { |
|
4843 dropPendingRedos(); |
|
4844 appendStagedRecordToLatestHistoryRecord(); |
|
4845 } |
|
4846 const undoRecord = history[history.length - 1 + offset]; |
|
4847 if (!undoRecord) { |
|
4848 return; |
|
4849 } |
|
4850 offset -= 1; |
|
4851 return undoRecord; |
|
4852 }, |
|
4853 redo() { |
|
4854 const redoRecord = history[history.length + offset]; |
|
4855 if (!redoRecord) { |
|
4856 return; |
|
4857 } |
|
4858 offset += 1; |
|
4859 return redoRecord; |
|
4860 }, |
|
4861 hasUndo() { |
|
4862 return !!history[history.length - 1 + offset]; |
|
4863 }, |
|
4864 hasRedo() { |
|
4865 return !!history[history.length + offset]; |
|
4866 } |
|
4867 }; |
|
4868 } |
|
4869 |
|
4870 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-state-with-history/index.js |
|
4811 /** |
4871 /** |
4812 * WordPress dependencies |
4872 * WordPress dependencies |
4813 */ |
4873 */ |
4814 |
4874 |
4815 |
4875 |
4856 } |
4916 } |
4857 return state; |
4917 return state; |
4858 } |
4918 } |
4859 function initReducer(value) { |
4919 function initReducer(value) { |
4860 return { |
4920 return { |
4861 manager: (0,build_module.createUndoManager)(), |
4921 manager: createUndoManager(), |
4862 value |
4922 value |
4863 }; |
4923 }; |
4864 } |
4924 } |
4865 |
4925 |
4866 /** |
4926 /** |
4893 }); |
4953 }); |
4894 }, []) |
4954 }, []) |
4895 }; |
4955 }; |
4896 } |
4956 } |
4897 |
4957 |
4898 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-viewport-match/index.js |
4958 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-viewport-match/index.js |
4899 /** |
4959 /** |
4900 * WordPress dependencies |
4960 * WordPress dependencies |
4901 */ |
4961 */ |
4902 |
4962 |
4903 |
4963 |
4905 * Internal dependencies |
4965 * Internal dependencies |
4906 */ |
4966 */ |
4907 |
4967 |
4908 |
4968 |
4909 /** |
4969 /** |
4910 * @typedef {"huge" | "wide" | "large" | "medium" | "small" | "mobile"} WPBreakpoint |
4970 * @typedef {"xhuge" | "huge" | "wide" | "xlarge" | "large" | "medium" | "small" | "mobile"} WPBreakpoint |
4911 */ |
4971 */ |
4912 |
4972 |
4913 /** |
4973 /** |
4914 * Hash of breakpoint names with pixel width at which it becomes effective. |
4974 * Hash of breakpoint names with pixel width at which it becomes effective. |
4915 * |
4975 * |
4916 * @see _breakpoints.scss |
4976 * @see _breakpoints.scss |
4917 * |
4977 * |
4918 * @type {Record<WPBreakpoint, number>} |
4978 * @type {Record<WPBreakpoint, number>} |
4919 */ |
4979 */ |
4920 const BREAKPOINTS = { |
4980 const BREAKPOINTS = { |
4981 xhuge: 1920, |
|
4921 huge: 1440, |
4982 huge: 1440, |
4922 wide: 1280, |
4983 wide: 1280, |
4984 xlarge: 1080, |
|
4923 large: 960, |
4985 large: 960, |
4924 medium: 782, |
4986 medium: 782, |
4925 small: 600, |
4987 small: 600, |
4926 mobile: 480 |
4988 mobile: 480 |
4927 }; |
4989 }; |
4947 */ |
5009 */ |
4948 const OPERATOR_EVALUATORS = { |
5010 const OPERATOR_EVALUATORS = { |
4949 '>=': (breakpointValue, width) => width >= breakpointValue, |
5011 '>=': (breakpointValue, width) => width >= breakpointValue, |
4950 '<': (breakpointValue, width) => width < breakpointValue |
5012 '<': (breakpointValue, width) => width < breakpointValue |
4951 }; |
5013 }; |
4952 const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)( /** @type {null | number} */null); |
5014 const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)(/** @type {null | number} */null); |
4953 |
5015 |
4954 /** |
5016 /** |
4955 * Returns true if the viewport matches the given query, or false otherwise. |
5017 * Returns true if the viewport matches the given query, or false otherwise. |
4956 * |
5018 * |
4957 * @param {WPBreakpoint} breakpoint Breakpoint size name. |
5019 * @param {WPBreakpoint} breakpoint Breakpoint size name. |
4976 return mediaQueryResult; |
5038 return mediaQueryResult; |
4977 }; |
5039 }; |
4978 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider; |
5040 useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider; |
4979 /* harmony default export */ const use_viewport_match = (useViewportMatch); |
5041 /* harmony default export */ const use_viewport_match = (useViewportMatch); |
4980 |
5042 |
4981 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js |
5043 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/use-resize-observer.js |
5044 /** |
|
5045 * WordPress dependencies |
|
5046 */ |
|
5047 |
|
5048 /** |
|
5049 * Internal dependencies |
|
5050 */ |
|
5051 |
|
5052 |
|
5053 // This is the current implementation of `useResizeObserver`. |
|
5054 // |
|
5055 // The legacy implementation is still supported for backwards compatibility. |
|
5056 // This is achieved by overloading the exported function with both signatures, |
|
5057 // and detecting which API is being used at runtime. |
|
5058 function useResizeObserver(callback, resizeObserverOptions = {}) { |
|
5059 const callbackEvent = useEvent(callback); |
|
5060 const observedElementRef = (0,external_wp_element_namespaceObject.useRef)(); |
|
5061 const resizeObserverRef = (0,external_wp_element_namespaceObject.useRef)(); |
|
5062 return useEvent(element => { |
|
5063 var _resizeObserverRef$cu; |
|
5064 if (element === observedElementRef.current) { |
|
5065 return; |
|
5066 } |
|
5067 |
|
5068 // Set up `ResizeObserver`. |
|
5069 (_resizeObserverRef$cu = resizeObserverRef.current) !== null && _resizeObserverRef$cu !== void 0 ? _resizeObserverRef$cu : resizeObserverRef.current = new ResizeObserver(callbackEvent); |
|
5070 const { |
|
5071 current: resizeObserver |
|
5072 } = resizeObserverRef; |
|
5073 |
|
5074 // Unobserve previous element. |
|
5075 if (observedElementRef.current) { |
|
5076 resizeObserver.unobserve(observedElementRef.current); |
|
5077 } |
|
5078 |
|
5079 // Observe new element. |
|
5080 observedElementRef.current = element; |
|
5081 if (element) { |
|
5082 resizeObserver.observe(element, resizeObserverOptions); |
|
5083 } |
|
5084 }); |
|
5085 } |
|
5086 |
|
5087 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/legacy/index.js |
|
4982 /** |
5088 /** |
4983 * External dependencies |
5089 * External dependencies |
4984 */ |
5090 */ |
4985 |
5091 |
4986 /** |
5092 /** |
4987 * WordPress dependencies |
5093 * WordPress dependencies |
4988 */ |
5094 */ |
4989 |
5095 |
4990 |
5096 /** |
4991 // This of course could've been more streamlined with internal state instead of |
5097 * Internal dependencies |
4992 // refs, but then host hooks / components could not opt out of renders. |
5098 */ |
4993 // This could've been exported to its own module, but the current build doesn't |
5099 |
4994 // seem to work with module imports and I had no more time to spend on this... |
|
4995 function useResolvedElement(subscriber, refOrElement) { |
|
4996 const callbackRefElement = (0,external_wp_element_namespaceObject.useRef)(null); |
|
4997 const lastReportRef = (0,external_wp_element_namespaceObject.useRef)(null); |
|
4998 const cleanupRef = (0,external_wp_element_namespaceObject.useRef)(); |
|
4999 const callSubscriber = (0,external_wp_element_namespaceObject.useCallback)(() => { |
|
5000 let element = null; |
|
5001 if (callbackRefElement.current) { |
|
5002 element = callbackRefElement.current; |
|
5003 } else if (refOrElement) { |
|
5004 if (refOrElement instanceof HTMLElement) { |
|
5005 element = refOrElement; |
|
5006 } else { |
|
5007 element = refOrElement.current; |
|
5008 } |
|
5009 } |
|
5010 if (lastReportRef.current && lastReportRef.current.element === element && lastReportRef.current.reporter === callSubscriber) { |
|
5011 return; |
|
5012 } |
|
5013 if (cleanupRef.current) { |
|
5014 cleanupRef.current(); |
|
5015 // Making sure the cleanup is not called accidentally multiple times. |
|
5016 cleanupRef.current = null; |
|
5017 } |
|
5018 lastReportRef.current = { |
|
5019 reporter: callSubscriber, |
|
5020 element |
|
5021 }; |
|
5022 |
|
5023 // Only calling the subscriber, if there's an actual element to report. |
|
5024 if (element) { |
|
5025 cleanupRef.current = subscriber(element); |
|
5026 } |
|
5027 }, [refOrElement, subscriber]); |
|
5028 |
|
5029 // On each render, we check whether a ref changed, or if we got a new raw |
|
5030 // element. |
|
5031 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
5032 // With this we're *technically* supporting cases where ref objects' current value changes, but only if there's a |
|
5033 // render accompanying that change as well. |
|
5034 // To guarantee we always have the right element, one must use the ref callback provided instead, but we support |
|
5035 // RefObjects to make the hook API more convenient in certain cases. |
|
5036 callSubscriber(); |
|
5037 }, [callSubscriber]); |
|
5038 return (0,external_wp_element_namespaceObject.useCallback)(element => { |
|
5039 callbackRefElement.current = element; |
|
5040 callSubscriber(); |
|
5041 }, [callSubscriber]); |
|
5042 } |
|
5043 |
|
5044 // Declaring my own type here instead of using the one provided by TS (available since 4.2.2), because this way I'm not |
|
5045 // forcing consumers to use a specific TS version. |
|
5046 |
5100 |
5047 // We're only using the first element of the size sequences, until future versions of the spec solidify on how |
5101 // We're only using the first element of the size sequences, until future versions of the spec solidify on how |
5048 // exactly it'll be used for fragments in multi-column scenarios: |
5102 // exactly it'll be used for fragments in multi-column scenarios: |
5049 // From the spec: |
5103 // From the spec: |
5050 // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments, |
5104 // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments, |
5067 // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote. |
5121 // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote. |
5068 // For this reason I decided to only return the requested size, |
5122 // For this reason I decided to only return the requested size, |
5069 // even though it seems we have access to results for all box types. |
5123 // even though it seems we have access to results for all box types. |
5070 // This also means that we get to keep the current api, being able to return a simple { width, height } pair, |
5124 // This also means that we get to keep the current api, being able to return a simple { width, height } pair, |
5071 // regardless of box option. |
5125 // regardless of box option. |
5072 const extractSize = (entry, boxProp, sizeType) => { |
5126 const extractSize = entry => { |
5073 if (!entry[boxProp]) { |
5127 let entrySize; |
5074 if (boxProp === 'contentBoxSize') { |
5128 if (!entry.contentBoxSize) { |
5075 // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec. |
5129 // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec. |
5076 // See the 6th step in the description for the RO algorithm: |
5130 // See the 6th step in the description for the RO algorithm: |
5077 // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h |
5131 // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h |
5078 // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box". |
5132 // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box". |
5079 // In real browser implementations of course these objects differ, but the width/height values should be equivalent. |
5133 // In real browser implementations of course these objects differ, but the width/height values should be equivalent. |
5080 return entry.contentRect[sizeType === 'inlineSize' ? 'width' : 'height']; |
5134 entrySize = [entry.contentRect.width, entry.contentRect.height]; |
5081 } |
5135 } else if (entry.contentBoxSize[0]) { |
5082 return undefined; |
5136 const contentBoxSize = entry.contentBoxSize[0]; |
5137 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize]; |
|
5138 } else { |
|
5139 // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy |
|
5140 // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`. |
|
5141 const contentBoxSize = entry.contentBoxSize; |
|
5142 entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize]; |
|
5083 } |
5143 } |
5084 |
5144 const [width, height] = entrySize.map(d => Math.round(d)); |
5085 // A couple bytes smaller than calling Array.isArray() and just as effective here. |
5145 return { |
5086 return entry[boxProp][0] ? entry[boxProp][0][sizeType] : |
5146 width, |
5087 // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's current |
5147 height |
5088 // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`. |
5148 }; |
5089 // @ts-ignore |
|
5090 entry[boxProp][sizeType]; |
|
5091 }; |
5149 }; |
5092 function useResizeObserver(opts = {}) { |
5150 const RESIZE_ELEMENT_STYLES = { |
5093 // Saving the callback as a ref. With this, I don't need to put onResize in the |
5151 position: 'absolute', |
5094 // effect dep array, and just passing in an anonymous function without memoising |
5152 top: 0, |
5095 // will not reinstantiate the hook's ResizeObserver. |
5153 left: 0, |
5096 const onResize = opts.onResize; |
5154 right: 0, |
5097 const onResizeRef = (0,external_wp_element_namespaceObject.useRef)(undefined); |
5155 bottom: 0, |
5098 onResizeRef.current = onResize; |
5156 pointerEvents: 'none', |
5099 const round = opts.round || Math.round; |
5157 opacity: 0, |
5100 |
5158 overflow: 'hidden', |
5101 // Using a single instance throughout the hook's lifetime |
5159 zIndex: -1 |
5102 const resizeObserverRef = (0,external_wp_element_namespaceObject.useRef)(); |
5160 }; |
5103 const [size, setSize] = (0,external_wp_element_namespaceObject.useState)({ |
5161 function ResizeElement({ |
5104 width: undefined, |
5162 onResize |
5105 height: undefined |
5163 }) { |
5164 const resizeElementRef = useResizeObserver(entries => { |
|
5165 const newSize = extractSize(entries.at(-1)); // Entries are never empty. |
|
5166 onResize(newSize); |
|
5106 }); |
5167 }); |
5107 |
5168 return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { |
5108 // In certain edge cases the RO might want to report a size change just after |
5169 ref: resizeElementRef, |
5109 // the component unmounted. |
5170 style: RESIZE_ELEMENT_STYLES, |
5110 const didUnmount = (0,external_wp_element_namespaceObject.useRef)(false); |
5171 "aria-hidden": "true" |
5111 (0,external_wp_element_namespaceObject.useEffect)(() => { |
|
5112 didUnmount.current = false; |
|
5113 return () => { |
|
5114 didUnmount.current = true; |
|
5115 }; |
|
5116 }, []); |
|
5117 |
|
5118 // Using a ref to track the previous width / height to avoid unnecessary renders. |
|
5119 const previous = (0,external_wp_element_namespaceObject.useRef)({ |
|
5120 width: undefined, |
|
5121 height: undefined |
|
5122 }); |
5172 }); |
5123 |
5173 } |
5124 // This block is kinda like a useEffect, only it's called whenever a new |
5174 function sizeEquals(a, b) { |
5125 // element could be resolved based on the ref option. It also has a cleanup |
5175 return a.width === b.width && a.height === b.height; |
5126 // function. |
5176 } |
5127 const refCallback = useResolvedElement((0,external_wp_element_namespaceObject.useCallback)(element => { |
5177 const NULL_SIZE = { |
5128 // We only use a single Resize Observer instance, and we're instantiating it on demand, only once there's something to observe. |
5178 width: null, |
5129 // This instance is also recreated when the `box` option changes, so that a new observation is fired if there was a previously observed element with a different box option. |
5179 height: null |
5130 if (!resizeObserverRef.current || resizeObserverRef.current.box !== opts.box || resizeObserverRef.current.round !== round) { |
5180 }; |
5131 resizeObserverRef.current = { |
5181 |
5132 box: opts.box, |
5182 /** |
5133 round, |
5183 * Hook which allows to listen to the resize event of any target element when it changes size. |
5134 instance: new ResizeObserver(entries => { |
5184 * _Note: `useResizeObserver` will report `null` sizes until after first render. |
5135 const entry = entries[0]; |
|
5136 let boxProp = 'borderBoxSize'; |
|
5137 if (opts.box === 'border-box') { |
|
5138 boxProp = 'borderBoxSize'; |
|
5139 } else { |
|
5140 boxProp = opts.box === 'device-pixel-content-box' ? 'devicePixelContentBoxSize' : 'contentBoxSize'; |
|
5141 } |
|
5142 const reportedWidth = extractSize(entry, boxProp, 'inlineSize'); |
|
5143 const reportedHeight = extractSize(entry, boxProp, 'blockSize'); |
|
5144 const newWidth = reportedWidth ? round(reportedWidth) : undefined; |
|
5145 const newHeight = reportedHeight ? round(reportedHeight) : undefined; |
|
5146 if (previous.current.width !== newWidth || previous.current.height !== newHeight) { |
|
5147 const newSize = { |
|
5148 width: newWidth, |
|
5149 height: newHeight |
|
5150 }; |
|
5151 previous.current.width = newWidth; |
|
5152 previous.current.height = newHeight; |
|
5153 if (onResizeRef.current) { |
|
5154 onResizeRef.current(newSize); |
|
5155 } else if (!didUnmount.current) { |
|
5156 setSize(newSize); |
|
5157 } |
|
5158 } |
|
5159 }) |
|
5160 }; |
|
5161 } |
|
5162 resizeObserverRef.current.instance.observe(element, { |
|
5163 box: opts.box |
|
5164 }); |
|
5165 return () => { |
|
5166 if (resizeObserverRef.current) { |
|
5167 resizeObserverRef.current.instance.unobserve(element); |
|
5168 } |
|
5169 }; |
|
5170 }, [opts.box, round]), opts.ref); |
|
5171 return (0,external_wp_element_namespaceObject.useMemo)(() => ({ |
|
5172 ref: refCallback, |
|
5173 width: size.width, |
|
5174 height: size.height |
|
5175 }), [refCallback, size ? size.width : null, size ? size.height : null]); |
|
5176 } |
|
5177 |
|
5178 /** |
|
5179 * Hook which allows to listen the resize event of any target element when it changes sizes. |
|
5180 * _Note: `useResizeObserver` will report `null` until after first render. |
|
5181 * |
5185 * |
5182 * @example |
5186 * @example |
5183 * |
5187 * |
5184 * ```js |
5188 * ```js |
5185 * const App = () => { |
5189 * const App = () => { |
5192 * </div> |
5196 * </div> |
5193 * ); |
5197 * ); |
5194 * }; |
5198 * }; |
5195 * ``` |
5199 * ``` |
5196 */ |
5200 */ |
5197 function useResizeAware() { |
5201 function useLegacyResizeObserver() { |
5198 const { |
5202 const [size, setSize] = (0,external_wp_element_namespaceObject.useState)(NULL_SIZE); |
5199 ref, |
5203 |
5200 width, |
5204 // Using a ref to track the previous width / height to avoid unnecessary renders. |
5201 height |
5205 const previousSizeRef = (0,external_wp_element_namespaceObject.useRef)(NULL_SIZE); |
5202 } = useResizeObserver(); |
5206 const handleResize = (0,external_wp_element_namespaceObject.useCallback)(newSize => { |
5203 const sizes = (0,external_wp_element_namespaceObject.useMemo)(() => { |
5207 if (!sizeEquals(previousSizeRef.current, newSize)) { |
5204 return { |
5208 previousSizeRef.current = newSize; |
5205 width: width !== null && width !== void 0 ? width : null, |
5209 setSize(newSize); |
5206 height: height !== null && height !== void 0 ? height : null |
5210 } |
5207 }; |
5211 }, []); |
5208 }, [width, height]); |
5212 const resizeElement = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(ResizeElement, { |
5209 const resizeListener = /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)("div", { |
5213 onResize: handleResize |
5210 style: { |
|
5211 position: 'absolute', |
|
5212 top: 0, |
|
5213 left: 0, |
|
5214 right: 0, |
|
5215 bottom: 0, |
|
5216 pointerEvents: 'none', |
|
5217 opacity: 0, |
|
5218 overflow: 'hidden', |
|
5219 zIndex: -1 |
|
5220 }, |
|
5221 "aria-hidden": "true", |
|
5222 ref: ref |
|
5223 }); |
5214 }); |
5224 return [resizeListener, sizes]; |
5215 return [resizeElement, size]; |
5225 } |
5216 } |
5226 |
5217 |
5227 ;// CONCATENATED MODULE: external ["wp","priorityQueue"] |
5218 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js |
5219 /** |
|
5220 * Internal dependencies |
|
5221 */ |
|
5222 |
|
5223 |
|
5224 /** |
|
5225 * External dependencies |
|
5226 */ |
|
5227 |
|
5228 /** |
|
5229 * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API) |
|
5230 * for an HTML or SVG element. |
|
5231 * |
|
5232 * Pass the returned setter as a callback ref to the React element you want |
|
5233 * to observe, or use it in layout effects for advanced use cases. |
|
5234 * |
|
5235 * @example |
|
5236 * |
|
5237 * ```tsx |
|
5238 * const setElement = useResizeObserver( |
|
5239 * ( resizeObserverEntries ) => console.log( resizeObserverEntries ), |
|
5240 * { box: 'border-box' } |
|
5241 * ); |
|
5242 * <div ref={ setElement } />; |
|
5243 * |
|
5244 * // The setter can be used in other ways, for example: |
|
5245 * useLayoutEffect( () => { |
|
5246 * setElement( document.querySelector( `data-element-id="${ elementId }"` ) ); |
|
5247 * }, [ elementId ] ); |
|
5248 * ``` |
|
5249 * |
|
5250 * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback). |
|
5251 * @param options Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored. |
|
5252 */ |
|
5253 |
|
5254 /** |
|
5255 * **This is a legacy API and should not be used.** |
|
5256 * |
|
5257 * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`. |
|
5258 * |
|
5259 * Hook which allows to listen to the resize event of any target element when it changes size. |
|
5260 * _Note: `useResizeObserver` will report `null` sizes until after first render. |
|
5261 * |
|
5262 * @example |
|
5263 * |
|
5264 * ```js |
|
5265 * const App = () => { |
|
5266 * const [ resizeListener, sizes ] = useResizeObserver(); |
|
5267 * |
|
5268 * return ( |
|
5269 * <div> |
|
5270 * { resizeListener } |
|
5271 * Your content here |
|
5272 * </div> |
|
5273 * ); |
|
5274 * }; |
|
5275 * ``` |
|
5276 */ |
|
5277 |
|
5278 function use_resize_observer_useResizeObserver(callback, options = {}) { |
|
5279 return callback ? useResizeObserver(callback, options) : useLegacyResizeObserver(); |
|
5280 } |
|
5281 |
|
5282 ;// external ["wp","priorityQueue"] |
|
5228 const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
5283 const external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"]; |
5229 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-async-list/index.js |
5284 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-async-list/index.js |
5230 /** |
5285 /** |
5231 * WordPress dependencies |
5286 * WordPress dependencies |
5232 */ |
5287 */ |
5233 |
5288 |
5234 |
5289 |
5235 /** |
5290 /** |
5236 * Returns the first items from list that are present on state. |
5291 * Returns the first items from list that are present on state. |
5237 * |
5292 * |
5238 * @param list New array. |
5293 * @param list New array. |
5239 * @param state Current state. |
5294 * @param state Current state. |
5240 * @return First items present iin state. |
5295 * @return First items present in state. |
5241 */ |
5296 */ |
5242 function getFirstItemsPresentInState(list, state) { |
5297 function getFirstItemsPresentInState(list, state) { |
5243 const firstItems = []; |
5298 const firstItems = []; |
5244 for (let i = 0; i < list.length; i++) { |
5299 for (let i = 0; i < list.length; i++) { |
5245 const item = list[i]; |
5300 const item = list[i]; |
5286 }, [list]); |
5341 }, [list]); |
5287 return current; |
5342 return current; |
5288 } |
5343 } |
5289 /* harmony default export */ const use_async_list = (useAsyncList); |
5344 /* harmony default export */ const use_async_list = (useAsyncList); |
5290 |
5345 |
5291 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-warn-on-change/index.js |
5346 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-warn-on-change/index.js |
5292 /** |
5347 /** |
5293 * Internal dependencies |
5348 * Internal dependencies |
5294 */ |
5349 */ |
5295 |
5350 |
5296 |
5351 |
5297 // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case |
5352 // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in this case |
5298 // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript |
5353 // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript |
5299 /* eslint-disable jsdoc/check-types */ |
5354 /* eslint-disable jsdoc/check-types */ |
5300 /** |
5355 /** |
5301 * Hook that performs a shallow comparison between the preview value of an object |
5356 * Hook that performs a shallow comparison between the preview value of an object |
5302 * and the new one, if there's a difference, it prints it to the console. |
5357 * and the new one, if there's a difference, it prints it to the console. |
5316 * @param {string} prefix Just a prefix to show when console logging. |
5371 * @param {string} prefix Just a prefix to show when console logging. |
5317 */ |
5372 */ |
5318 function useWarnOnChange(object, prefix = 'Change detection') { |
5373 function useWarnOnChange(object, prefix = 'Change detection') { |
5319 const previousValues = usePrevious(object); |
5374 const previousValues = usePrevious(object); |
5320 Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => { |
5375 Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => { |
5321 if (value !== object[( /** @type {keyof typeof object} */key)]) { |
5376 if (value !== object[(/** @type {keyof typeof object} */key)]) { |
5322 // eslint-disable-next-line no-console |
5377 // eslint-disable-next-line no-console |
5323 console.warn(`${prefix}: ${key} key changed:`, value, object[( /** @type {keyof typeof object} */key)] |
5378 console.warn(`${prefix}: ${key} key changed:`, value, object[(/** @type {keyof typeof object} */key)] |
5324 /* eslint-enable jsdoc/check-types */); |
5379 /* eslint-enable jsdoc/check-types */); |
5325 } |
5380 } |
5326 }); |
5381 }); |
5327 } |
5382 } |
5328 /* harmony default export */ const use_warn_on_change = (useWarnOnChange); |
5383 /* harmony default export */ const use_warn_on_change = (useWarnOnChange); |
5329 |
5384 |
5330 ;// CONCATENATED MODULE: external "React" |
5385 ;// external "React" |
5331 const external_React_namespaceObject = window["React"]; |
5386 const external_React_namespaceObject = window["React"]; |
5332 ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
5387 ;// ./node_modules/use-memo-one/dist/use-memo-one.esm.js |
5333 |
5388 |
5334 |
5389 |
5335 function areInputsEqual(newInputs, lastInputs) { |
5390 function areInputsEqual(newInputs, lastInputs) { |
5336 if (newInputs.length !== lastInputs.length) { |
5391 if (newInputs.length !== lastInputs.length) { |
5337 return false; |
5392 return false; |
5374 var useMemo = (/* unused pure expression or super */ null && (useMemoOne)); |
5429 var useMemo = (/* unused pure expression or super */ null && (useMemoOne)); |
5375 var useCallback = (/* unused pure expression or super */ null && (useCallbackOne)); |
5430 var useCallback = (/* unused pure expression or super */ null && (useCallbackOne)); |
5376 |
5431 |
5377 |
5432 |
5378 |
5433 |
5379 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-debounce/index.js |
5434 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-debounce/index.js |
5380 /** |
5435 /** |
5381 * External dependencies |
5436 * External dependencies |
5382 */ |
5437 */ |
5383 |
5438 |
5384 |
5439 |
5411 const debounced = useMemoOne(() => debounce(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]); |
5466 const debounced = useMemoOne(() => debounce(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]); |
5412 (0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]); |
5467 (0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]); |
5413 return debounced; |
5468 return debounced; |
5414 } |
5469 } |
5415 |
5470 |
5416 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-debounced-input/index.js |
5471 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-debounced-input/index.js |
5417 /** |
5472 /** |
5418 * WordPress dependencies |
5473 * WordPress dependencies |
5419 */ |
5474 */ |
5420 |
5475 |
5421 |
5476 |
5438 setDebouncedInput(input); |
5493 setDebouncedInput(input); |
5439 }, [input, setDebouncedInput]); |
5494 }, [input, setDebouncedInput]); |
5440 return [input, setInput, debouncedInput]; |
5495 return [input, setInput, debouncedInput]; |
5441 } |
5496 } |
5442 |
5497 |
5443 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-throttle/index.js |
5498 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-throttle/index.js |
5444 /** |
5499 /** |
5445 * External dependencies |
5500 * External dependencies |
5446 */ |
5501 */ |
5447 |
5502 |
5448 |
5503 |
5475 const throttled = useMemoOne(() => throttle(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]); |
5530 const throttled = useMemoOne(() => throttle(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]); |
5476 (0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]); |
5531 (0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]); |
5477 return throttled; |
5532 return throttled; |
5478 } |
5533 } |
5479 |
5534 |
5480 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-drop-zone/index.js |
5535 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-drop-zone/index.js |
5481 /** |
|
5482 * WordPress dependencies |
|
5483 */ |
|
5484 |
|
5485 |
|
5486 /** |
5536 /** |
5487 * Internal dependencies |
5537 * Internal dependencies |
5488 */ |
5538 */ |
5489 |
5539 |
5490 |
5540 |
5491 /* eslint-disable jsdoc/valid-types */ |
|
5492 /** |
|
5493 * @template T |
|
5494 * @param {T} value |
|
5495 * @return {import('react').MutableRefObject<T|null>} A ref with the value. |
|
5496 */ |
|
5497 function useFreshRef(value) { |
|
5498 /* eslint-enable jsdoc/valid-types */ |
|
5499 /* eslint-disable jsdoc/no-undefined-types */ |
|
5500 /** @type {import('react').MutableRefObject<T>} */ |
|
5501 /* eslint-enable jsdoc/no-undefined-types */ |
|
5502 // Disable reason: We're doing something pretty JavaScript-y here where the |
|
5503 // ref will always have a current value that is not null or undefined but it |
|
5504 // needs to start as undefined. We don't want to change the return type so |
|
5505 // it's easier to just ts-ignore this specific line that's complaining about |
|
5506 // undefined not being part of T. |
|
5507 // @ts-ignore |
|
5508 const ref = (0,external_wp_element_namespaceObject.useRef)(); |
|
5509 ref.current = value; |
|
5510 return ref; |
|
5511 } |
|
5512 |
5541 |
5513 /** |
5542 /** |
5514 * A hook to facilitate drag and drop handling. |
5543 * A hook to facilitate drag and drop handling. |
5515 * |
5544 * |
5516 * @param {Object} props Named parameters. |
5545 * @param {Object} props Named parameters. |
5533 onDragEnter: _onDragEnter, |
5562 onDragEnter: _onDragEnter, |
5534 onDragLeave: _onDragLeave, |
5563 onDragLeave: _onDragLeave, |
5535 onDragEnd: _onDragEnd, |
5564 onDragEnd: _onDragEnd, |
5536 onDragOver: _onDragOver |
5565 onDragOver: _onDragOver |
5537 }) { |
5566 }) { |
5538 const onDropRef = useFreshRef(_onDrop); |
5567 const onDropEvent = useEvent(_onDrop); |
5539 const onDragStartRef = useFreshRef(_onDragStart); |
5568 const onDragStartEvent = useEvent(_onDragStart); |
5540 const onDragEnterRef = useFreshRef(_onDragEnter); |
5569 const onDragEnterEvent = useEvent(_onDragEnter); |
5541 const onDragLeaveRef = useFreshRef(_onDragLeave); |
5570 const onDragLeaveEvent = useEvent(_onDragLeave); |
5542 const onDragEndRef = useFreshRef(_onDragEnd); |
5571 const onDragEndEvent = useEvent(_onDragEnd); |
5543 const onDragOverRef = useFreshRef(_onDragOver); |
5572 const onDragOverEvent = useEvent(_onDragOver); |
5544 return useRefEffect(elem => { |
5573 return useRefEffect(elem => { |
5545 if (isDisabled) { |
5574 if (isDisabled) { |
5546 return; |
5575 return; |
5547 } |
5576 } |
5548 |
5577 |
5577 return elementToCheck === element; |
5606 return elementToCheck === element; |
5578 } |
5607 } |
5579 } while (elementToCheck = elementToCheck.parentElement); |
5608 } while (elementToCheck = elementToCheck.parentElement); |
5580 return false; |
5609 return false; |
5581 } |
5610 } |
5582 function maybeDragStart( /** @type {DragEvent} */event) { |
5611 function maybeDragStart(/** @type {DragEvent} */event) { |
5583 if (isDragging) { |
5612 if (isDragging) { |
5584 return; |
5613 return; |
5585 } |
5614 } |
5586 isDragging = true; |
5615 isDragging = true; |
5587 |
5616 |
5589 // HTML drag events where the drag origin is outside the browser |
5618 // HTML drag events where the drag origin is outside the browser |
5590 // window. In Firefox it may also not fire if the originating |
5619 // window. In Firefox it may also not fire if the originating |
5591 // node is removed. |
5620 // node is removed. |
5592 ownerDocument.addEventListener('dragend', maybeDragEnd); |
5621 ownerDocument.addEventListener('dragend', maybeDragEnd); |
5593 ownerDocument.addEventListener('mousemove', maybeDragEnd); |
5622 ownerDocument.addEventListener('mousemove', maybeDragEnd); |
5594 if (onDragStartRef.current) { |
5623 if (_onDragStart) { |
5595 onDragStartRef.current(event); |
5624 onDragStartEvent(event); |
5596 } |
5625 } |
5597 } |
5626 } |
5598 function onDragEnter( /** @type {DragEvent} */event) { |
5627 function onDragEnter(/** @type {DragEvent} */event) { |
5599 event.preventDefault(); |
5628 event.preventDefault(); |
5600 |
5629 |
5601 // The `dragenter` event will also fire when entering child |
5630 // The `dragenter` event will also fire when entering child |
5602 // elements, but we only want to call `onDragEnter` when |
5631 // elements, but we only want to call `onDragEnter` when |
5603 // entering the drop zone, which means the `relatedTarget` |
5632 // entering the drop zone, which means the `relatedTarget` |
5604 // (element that has been left) should be outside the drop zone. |
5633 // (element that has been left) should be outside the drop zone. |
5605 if (element.contains( /** @type {Node} */event.relatedTarget)) { |
5634 if (element.contains(/** @type {Node} */event.relatedTarget)) { |
5606 return; |
5635 return; |
5607 } |
5636 } |
5608 if (onDragEnterRef.current) { |
5637 if (_onDragEnter) { |
5609 onDragEnterRef.current(event); |
5638 onDragEnterEvent(event); |
5610 } |
5639 } |
5611 } |
5640 } |
5612 function onDragOver( /** @type {DragEvent} */event) { |
5641 function onDragOver(/** @type {DragEvent} */event) { |
5613 // Only call onDragOver for the innermost hovered drop zones. |
5642 // Only call onDragOver for the innermost hovered drop zones. |
5614 if (!event.defaultPrevented && onDragOverRef.current) { |
5643 if (!event.defaultPrevented && _onDragOver) { |
5615 onDragOverRef.current(event); |
5644 onDragOverEvent(event); |
5616 } |
5645 } |
5617 |
5646 |
5618 // Prevent the browser default while also signalling to parent |
5647 // Prevent the browser default while also signalling to parent |
5619 // drop zones that `onDragOver` is already handled. |
5648 // drop zones that `onDragOver` is already handled. |
5620 event.preventDefault(); |
5649 event.preventDefault(); |
5621 } |
5650 } |
5622 function onDragLeave( /** @type {DragEvent} */event) { |
5651 function onDragLeave(/** @type {DragEvent} */event) { |
5623 // The `dragleave` event will also fire when leaving child |
5652 // The `dragleave` event will also fire when leaving child |
5624 // elements, but we only want to call `onDragLeave` when |
5653 // elements, but we only want to call `onDragLeave` when |
5625 // leaving the drop zone, which means the `relatedTarget` |
5654 // leaving the drop zone, which means the `relatedTarget` |
5626 // (element that has been entered) should be outside the drop |
5655 // (element that has been entered) should be outside the drop |
5627 // zone. |
5656 // zone. |
5628 // Note: This is not entirely reliable in Safari due to this bug |
5657 // Note: This is not entirely reliable in Safari due to this bug |
5629 // https://bugs.webkit.org/show_bug.cgi?id=66547 |
5658 // https://bugs.webkit.org/show_bug.cgi?id=66547 |
5659 |
|
5630 if (isElementInZone(event.relatedTarget)) { |
5660 if (isElementInZone(event.relatedTarget)) { |
5631 return; |
5661 return; |
5632 } |
5662 } |
5633 if (onDragLeaveRef.current) { |
5663 if (_onDragLeave) { |
5634 onDragLeaveRef.current(event); |
5664 onDragLeaveEvent(event); |
5635 } |
5665 } |
5636 } |
5666 } |
5637 function onDrop( /** @type {DragEvent} */event) { |
5667 function onDrop(/** @type {DragEvent} */event) { |
5638 // Don't handle drop if an inner drop zone already handled it. |
5668 // Don't handle drop if an inner drop zone already handled it. |
5639 if (event.defaultPrevented) { |
5669 if (event.defaultPrevented) { |
5640 return; |
5670 return; |
5641 } |
5671 } |
5642 |
5672 |
5647 // This seemingly useless line has been shown to resolve a |
5677 // This seemingly useless line has been shown to resolve a |
5648 // Safari issue where files dragged directly from the dock are |
5678 // Safari issue where files dragged directly from the dock are |
5649 // not recognized. |
5679 // not recognized. |
5650 // eslint-disable-next-line no-unused-expressions |
5680 // eslint-disable-next-line no-unused-expressions |
5651 event.dataTransfer && event.dataTransfer.files.length; |
5681 event.dataTransfer && event.dataTransfer.files.length; |
5652 if (onDropRef.current) { |
5682 if (_onDrop) { |
5653 onDropRef.current(event); |
5683 onDropEvent(event); |
5654 } |
5684 } |
5655 maybeDragEnd(event); |
5685 maybeDragEnd(event); |
5656 } |
5686 } |
5657 function maybeDragEnd( /** @type {MouseEvent} */event) { |
5687 function maybeDragEnd(/** @type {MouseEvent} */event) { |
5658 if (!isDragging) { |
5688 if (!isDragging) { |
5659 return; |
5689 return; |
5660 } |
5690 } |
5661 isDragging = false; |
5691 isDragging = false; |
5662 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
5692 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
5663 ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
5693 ownerDocument.removeEventListener('mousemove', maybeDragEnd); |
5664 if (onDragEndRef.current) { |
5694 if (_onDragEnd) { |
5665 onDragEndRef.current(event); |
5695 onDragEndEvent(event); |
5666 } |
5696 } |
5667 } |
5697 } |
5668 element.dataset.isDropZone = 'true'; |
5698 element.setAttribute('data-is-drop-zone', 'true'); |
5669 element.addEventListener('drop', onDrop); |
5699 element.addEventListener('drop', onDrop); |
5670 element.addEventListener('dragenter', onDragEnter); |
5700 element.addEventListener('dragenter', onDragEnter); |
5671 element.addEventListener('dragover', onDragOver); |
5701 element.addEventListener('dragover', onDragOver); |
5672 element.addEventListener('dragleave', onDragLeave); |
5702 element.addEventListener('dragleave', onDragLeave); |
5673 // The `dragstart` event doesn't fire if the drag started outside |
5703 // The `dragstart` event doesn't fire if the drag started outside |
5674 // the document. |
5704 // the document. |
5675 ownerDocument.addEventListener('dragenter', maybeDragStart); |
5705 ownerDocument.addEventListener('dragenter', maybeDragStart); |
5676 return () => { |
5706 return () => { |
5677 delete element.dataset.isDropZone; |
5707 element.removeAttribute('data-is-drop-zone'); |
5678 element.removeEventListener('drop', onDrop); |
5708 element.removeEventListener('drop', onDrop); |
5679 element.removeEventListener('dragenter', onDragEnter); |
5709 element.removeEventListener('dragenter', onDragEnter); |
5680 element.removeEventListener('dragover', onDragOver); |
5710 element.removeEventListener('dragover', onDragOver); |
5681 element.removeEventListener('dragleave', onDragLeave); |
5711 element.removeEventListener('dragleave', onDragLeave); |
5682 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
5712 ownerDocument.removeEventListener('dragend', maybeDragEnd); |
5685 }; |
5715 }; |
5686 }, [isDisabled, dropZoneElement] // Refresh when the passed in dropZoneElement changes. |
5716 }, [isDisabled, dropZoneElement] // Refresh when the passed in dropZoneElement changes. |
5687 ); |
5717 ); |
5688 } |
5718 } |
5689 |
5719 |
5690 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focusable-iframe/index.js |
5720 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-focusable-iframe/index.js |
5691 /** |
5721 /** |
5692 * External dependencies |
5722 * External dependencies |
5693 */ |
5723 */ |
5694 |
5724 |
5695 /** |
5725 /** |
5732 defaultView.removeEventListener('blur', checkFocus); |
5762 defaultView.removeEventListener('blur', checkFocus); |
5733 }; |
5763 }; |
5734 }, []); |
5764 }, []); |
5735 } |
5765 } |
5736 |
5766 |
5737 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-fixed-window-list/index.js |
5767 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-fixed-window-list/index.js |
5738 /** |
5768 /** |
5739 * WordPress dependencies |
5769 * WordPress dependencies |
5740 */ |
5770 */ |
5741 |
5771 |
5742 |
5772 |
5780 const useWindowing = (_options$useWindowing = options?.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true; |
5810 const useWindowing = (_options$useWindowing = options?.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true; |
5781 const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({ |
5811 const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({ |
5782 visibleItems: initWindowSize, |
5812 visibleItems: initWindowSize, |
5783 start: 0, |
5813 start: 0, |
5784 end: initWindowSize, |
5814 end: initWindowSize, |
5785 itemInView: ( /** @type {number} */index) => { |
5815 itemInView: (/** @type {number} */index) => { |
5786 return index >= 0 && index <= initWindowSize; |
5816 return index >= 0 && index <= initWindowSize; |
5787 } |
5817 } |
5788 }); |
5818 }); |
5789 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
5819 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
5790 if (!useWindowing) { |
5820 if (!useWindowing) { |
5791 return; |
5821 return; |
5792 } |
5822 } |
5793 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
5823 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
5794 const measureWindow = ( /** @type {boolean | undefined} */initRender) => { |
5824 const measureWindow = (/** @type {boolean | undefined} */initRender) => { |
5795 var _options$windowOversc; |
5825 var _options$windowOversc; |
5796 if (!scrollContainer) { |
5826 if (!scrollContainer) { |
5797 return; |
5827 return; |
5798 } |
5828 } |
5799 const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); |
5829 const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); |
5805 setFixedListWindow(lastWindow => { |
5835 setFixedListWindow(lastWindow => { |
5806 const nextWindow = { |
5836 const nextWindow = { |
5807 visibleItems, |
5837 visibleItems, |
5808 start, |
5838 start, |
5809 end, |
5839 end, |
5810 itemInView: ( /** @type {number} */index) => { |
5840 itemInView: (/** @type {number} */index) => { |
5811 return start <= index && index <= end; |
5841 return start <= index && index <= end; |
5812 } |
5842 } |
5813 }; |
5843 }; |
5814 if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) { |
5844 if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) { |
5815 return nextWindow; |
5845 return nextWindow; |
5832 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
5862 (0,external_wp_element_namespaceObject.useLayoutEffect)(() => { |
5833 if (!useWindowing) { |
5863 if (!useWindowing) { |
5834 return; |
5864 return; |
5835 } |
5865 } |
5836 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
5866 const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current); |
5837 const handleKeyDown = ( /** @type {KeyboardEvent} */event) => { |
5867 const handleKeyDown = (/** @type {KeyboardEvent} */event) => { |
5838 switch (event.keyCode) { |
5868 switch (event.keyCode) { |
5839 case external_wp_keycodes_namespaceObject.HOME: |
5869 case external_wp_keycodes_namespaceObject.HOME: |
5840 { |
5870 { |
5841 return scrollContainer?.scrollTo({ |
5871 return scrollContainer?.scrollTo({ |
5842 top: 0 |
5872 top: 0 |
5868 }; |
5898 }; |
5869 }, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems, useWindowing, options?.expandedState]); |
5899 }, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems, useWindowing, options?.expandedState]); |
5870 return [fixedListWindow, setFixedListWindow]; |
5900 return [fixedListWindow, setFixedListWindow]; |
5871 } |
5901 } |
5872 |
5902 |
5873 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-observable-value/index.js |
5903 ;// ./node_modules/@wordpress/compose/build-module/hooks/use-observable-value/index.js |
5874 /** |
5904 /** |
5875 * WordPress dependencies |
5905 * WordPress dependencies |
5876 */ |
5906 */ |
5877 |
5907 |
5878 |
5908 |
5895 function useObservableValue(map, name) { |
5925 function useObservableValue(map, name) { |
5896 const [subscribe, getValue] = (0,external_wp_element_namespaceObject.useMemo)(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]); |
5926 const [subscribe, getValue] = (0,external_wp_element_namespaceObject.useMemo)(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]); |
5897 return (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); |
5927 return (0,external_wp_element_namespaceObject.useSyncExternalStore)(subscribe, getValue, getValue); |
5898 } |
5928 } |
5899 |
5929 |
5900 ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/index.js |
5930 ;// ./node_modules/@wordpress/compose/build-module/index.js |
5901 // The `createHigherOrderComponent` helper and helper types. |
5931 // The `createHigherOrderComponent` helper and helper types. |
5902 |
5932 |
5903 // The `debounce` helper and its types. |
5933 // The `debounce` helper and its types. |
5904 |
5934 |
5905 // The `throttle` helper and its types. |
5935 // The `throttle` helper and its types. |
5918 |
5948 |
5919 |
5949 |
5920 |
5950 |
5921 |
5951 |
5922 // Hooks. |
5952 // Hooks. |
5953 |
|
5923 |
5954 |
5924 |
5955 |
5925 |
5956 |
5926 |
5957 |
5927 |
5958 |