19
|
1 |
/******/ (function() { // webpackBootstrap
|
|
2 |
/******/ var __webpack_modules__ = ({
|
|
3 |
|
|
4 |
/***/ 8294:
|
|
5 |
/***/ (function(module) {
|
|
6 |
|
|
7 |
/*!
|
|
8 |
* clipboard.js v2.0.10
|
|
9 |
* https://clipboardjs.com/
|
|
10 |
*
|
|
11 |
* Licensed MIT © Zeno Rocha
|
|
12 |
*/
|
|
13 |
(function webpackUniversalModuleDefinition(root, factory) {
|
|
14 |
if(true)
|
|
15 |
module.exports = factory();
|
|
16 |
else {}
|
|
17 |
})(this, function() {
|
|
18 |
return /******/ (function() { // webpackBootstrap
|
|
19 |
/******/ var __webpack_modules__ = ({
|
|
20 |
|
|
21 |
/***/ 686:
|
|
22 |
/***/ (function(__unused_webpack_module, __webpack_exports__, __nested_webpack_require_623__) {
|
16
|
23 |
|
|
24 |
"use strict";
|
18
|
25 |
|
|
26 |
// EXPORTS
|
19
|
27 |
__nested_webpack_require_623__.d(__webpack_exports__, {
|
|
28 |
"default": function() { return /* binding */ clipboard; }
|
|
29 |
});
|
|
30 |
|
|
31 |
// EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js
|
|
32 |
var tiny_emitter = __nested_webpack_require_623__(279);
|
|
33 |
var tiny_emitter_default = /*#__PURE__*/__nested_webpack_require_623__.n(tiny_emitter);
|
|
34 |
// EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js
|
|
35 |
var listen = __nested_webpack_require_623__(370);
|
|
36 |
var listen_default = /*#__PURE__*/__nested_webpack_require_623__.n(listen);
|
|
37 |
// EXTERNAL MODULE: ./node_modules/select/src/select.js
|
|
38 |
var src_select = __nested_webpack_require_623__(817);
|
|
39 |
var select_default = /*#__PURE__*/__nested_webpack_require_623__.n(src_select);
|
|
40 |
;// CONCATENATED MODULE: ./src/common/command.js
|
18
|
41 |
/**
|
19
|
42 |
* Executes a given operation type.
|
|
43 |
* @param {String} type
|
|
44 |
* @return {Boolean}
|
18
|
45 |
*/
|
19
|
46 |
function command(type) {
|
|
47 |
try {
|
|
48 |
return document.execCommand(type);
|
|
49 |
} catch (err) {
|
|
50 |
return false;
|
18
|
51 |
}
|
19
|
52 |
}
|
|
53 |
;// CONCATENATED MODULE: ./src/actions/cut.js
|
18
|
54 |
|
|
55 |
|
|
56 |
/**
|
19
|
57 |
* Cut action wrapper.
|
|
58 |
* @param {String|HTMLElement} target
|
|
59 |
* @return {String}
|
18
|
60 |
*/
|
|
61 |
|
19
|
62 |
var ClipboardActionCut = function ClipboardActionCut(target) {
|
|
63 |
var selectedText = select_default()(target);
|
|
64 |
command('cut');
|
|
65 |
return selectedText;
|
|
66 |
};
|
|
67 |
|
|
68 |
/* harmony default export */ var actions_cut = (ClipboardActionCut);
|
|
69 |
;// CONCATENATED MODULE: ./src/common/create-fake-element.js
|
18
|
70 |
/**
|
19
|
71 |
* Creates a fake textarea element with a value.
|
|
72 |
* @param {String} value
|
|
73 |
* @return {HTMLElement}
|
16
|
74 |
*/
|
19
|
75 |
function createFakeElement(value) {
|
|
76 |
var isRTL = document.documentElement.getAttribute('dir') === 'rtl';
|
|
77 |
var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS
|
|
78 |
|
|
79 |
fakeElement.style.fontSize = '12pt'; // Reset box model
|
|
80 |
|
|
81 |
fakeElement.style.border = '0';
|
|
82 |
fakeElement.style.padding = '0';
|
|
83 |
fakeElement.style.margin = '0'; // Move element out of screen horizontally
|
|
84 |
|
|
85 |
fakeElement.style.position = 'absolute';
|
|
86 |
fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically
|
|
87 |
|
|
88 |
var yPosition = window.pageYOffset || document.documentElement.scrollTop;
|
|
89 |
fakeElement.style.top = "".concat(yPosition, "px");
|
|
90 |
fakeElement.setAttribute('readonly', '');
|
|
91 |
fakeElement.value = value;
|
|
92 |
return fakeElement;
|
16
|
93 |
}
|
19
|
94 |
;// CONCATENATED MODULE: ./src/actions/copy.js
|
16
|
95 |
|
|
96 |
|
|
97 |
|
|
98 |
/**
|
19
|
99 |
* Copy action wrapper.
|
|
100 |
* @param {String|HTMLElement} target
|
|
101 |
* @param {Object} options
|
|
102 |
* @return {String}
|
16
|
103 |
*/
|
|
104 |
|
19
|
105 |
var ClipboardActionCopy = function ClipboardActionCopy(target) {
|
|
106 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
107 |
container: document.body
|
|
108 |
};
|
|
109 |
var selectedText = '';
|
|
110 |
|
|
111 |
if (typeof target === 'string') {
|
|
112 |
var fakeElement = createFakeElement(target);
|
|
113 |
options.container.appendChild(fakeElement);
|
|
114 |
selectedText = select_default()(fakeElement);
|
|
115 |
command('copy');
|
|
116 |
fakeElement.remove();
|
|
117 |
} else {
|
|
118 |
selectedText = select_default()(target);
|
|
119 |
command('copy');
|
|
120 |
}
|
|
121 |
|
|
122 |
return selectedText;
|
|
123 |
};
|
|
124 |
|
|
125 |
/* harmony default export */ var actions_copy = (ClipboardActionCopy);
|
|
126 |
;// CONCATENATED MODULE: ./src/actions/default.js
|
|
127 |
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
18
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
/**
|
19
|
132 |
* Inner function which performs selection from either `text` or `target`
|
|
133 |
* properties and then executes copy or cut operations.
|
|
134 |
* @param {Object} options
|
18
|
135 |
*/
|
|
136 |
|
19
|
137 |
var ClipboardActionDefault = function ClipboardActionDefault() {
|
|
138 |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
139 |
// Defines base properties passed from constructor.
|
|
140 |
var _options$action = options.action,
|
|
141 |
action = _options$action === void 0 ? 'copy' : _options$action,
|
|
142 |
container = options.container,
|
|
143 |
target = options.target,
|
|
144 |
text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'.
|
|
145 |
|
|
146 |
if (action !== 'copy' && action !== 'cut') {
|
|
147 |
throw new Error('Invalid "action" value, use either "copy" or "cut"');
|
|
148 |
} // Sets the `target` property using an element that will be have its content copied.
|
|
149 |
|
|
150 |
|
|
151 |
if (target !== undefined) {
|
|
152 |
if (target && _typeof(target) === 'object' && target.nodeType === 1) {
|
|
153 |
if (action === 'copy' && target.hasAttribute('disabled')) {
|
|
154 |
throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
|
18
|
155 |
}
|
|
156 |
|
19
|
157 |
if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
|
|
158 |
throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
|
18
|
159 |
}
|
19
|
160 |
} else {
|
|
161 |
throw new Error('Invalid "target" value, use a valid Element');
|
18
|
162 |
}
|
19
|
163 |
} // Define selection strategy based on `text` property.
|
|
164 |
|
|
165 |
|
|
166 |
if (text) {
|
|
167 |
return actions_copy(text, {
|
|
168 |
container: container
|
|
169 |
});
|
|
170 |
} // Defines which selection strategy based on `target` property.
|
|
171 |
|
|
172 |
|
|
173 |
if (target) {
|
|
174 |
return action === 'cut' ? actions_cut(target) : actions_copy(target, {
|
|
175 |
container: container
|
|
176 |
});
|
18
|
177 |
}
|
19
|
178 |
};
|
|
179 |
|
|
180 |
/* harmony default export */ var actions_default = (ClipboardActionDefault);
|
|
181 |
;// CONCATENATED MODULE: ./src/clipboard.js
|
|
182 |
function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); }
|
|
183 |
|
|
184 |
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
185 |
|
|
186 |
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
187 |
|
|
188 |
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
189 |
|
|
190 |
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
191 |
|
|
192 |
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
193 |
|
|
194 |
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
195 |
|
|
196 |
function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
197 |
|
|
198 |
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
199 |
|
|
200 |
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
201 |
|
|
202 |
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
18
|
203 |
|
16
|
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
/**
|
19
|
210 |
* Helper function to retrieve attribute value.
|
|
211 |
* @param {String} suffix
|
|
212 |
* @param {Element} element
|
16
|
213 |
*/
|
|
214 |
|
19
|
215 |
function getAttributeValue(suffix, element) {
|
|
216 |
var attribute = "data-clipboard-".concat(suffix);
|
|
217 |
|
|
218 |
if (!element.hasAttribute(attribute)) {
|
|
219 |
return;
|
|
220 |
}
|
|
221 |
|
|
222 |
return element.getAttribute(attribute);
|
18
|
223 |
}
|
|
224 |
/**
|
19
|
225 |
* Base class which takes one or more elements, adds event listeners to them,
|
|
226 |
* and instantiates a new `ClipboardAction` on each click.
|
18
|
227 |
*/
|
|
228 |
|
19
|
229 |
|
|
230 |
var Clipboard = /*#__PURE__*/function (_Emitter) {
|
|
231 |
_inherits(Clipboard, _Emitter);
|
|
232 |
|
|
233 |
var _super = _createSuper(Clipboard);
|
|
234 |
|
|
235 |
/**
|
|
236 |
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
|
237 |
* @param {Object} options
|
|
238 |
*/
|
|
239 |
function Clipboard(trigger, options) {
|
|
240 |
var _this;
|
|
241 |
|
|
242 |
_classCallCheck(this, Clipboard);
|
|
243 |
|
|
244 |
_this = _super.call(this);
|
|
245 |
|
|
246 |
_this.resolveOptions(options);
|
|
247 |
|
|
248 |
_this.listenClick(trigger);
|
|
249 |
|
|
250 |
return _this;
|
18
|
251 |
}
|
19
|
252 |
/**
|
|
253 |
* Defines if attributes would be resolved using internal setter functions
|
|
254 |
* or custom functions that were passed in the constructor.
|
|
255 |
* @param {Object} options
|
|
256 |
*/
|
|
257 |
|
|
258 |
|
|
259 |
_createClass(Clipboard, [{
|
|
260 |
key: "resolveOptions",
|
|
261 |
value: function resolveOptions() {
|
|
262 |
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
263 |
this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
|
|
264 |
this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
|
|
265 |
this.text = typeof options.text === 'function' ? options.text : this.defaultText;
|
|
266 |
this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;
|
|
267 |
}
|
|
268 |
/**
|
|
269 |
* Adds a click event listener to the passed trigger.
|
|
270 |
* @param {String|HTMLElement|HTMLCollection|NodeList} trigger
|
|
271 |
*/
|
|
272 |
|
|
273 |
}, {
|
|
274 |
key: "listenClick",
|
|
275 |
value: function listenClick(trigger) {
|
|
276 |
var _this2 = this;
|
|
277 |
|
|
278 |
this.listener = listen_default()(trigger, 'click', function (e) {
|
|
279 |
return _this2.onClick(e);
|
|
280 |
});
|
|
281 |
}
|
|
282 |
/**
|
|
283 |
* Defines a new `ClipboardAction` on each click event.
|
|
284 |
* @param {Event} e
|
|
285 |
*/
|
|
286 |
|
|
287 |
}, {
|
|
288 |
key: "onClick",
|
|
289 |
value: function onClick(e) {
|
|
290 |
var trigger = e.delegateTarget || e.currentTarget;
|
|
291 |
var action = this.action(trigger) || 'copy';
|
|
292 |
var text = actions_default({
|
|
293 |
action: action,
|
|
294 |
container: this.container,
|
|
295 |
target: this.target(trigger),
|
|
296 |
text: this.text(trigger)
|
|
297 |
}); // Fires an event based on the copy operation result.
|
|
298 |
|
|
299 |
this.emit(text ? 'success' : 'error', {
|
|
300 |
action: action,
|
|
301 |
text: text,
|
|
302 |
trigger: trigger,
|
|
303 |
clearSelection: function clearSelection() {
|
|
304 |
if (trigger) {
|
|
305 |
trigger.focus();
|
|
306 |
}
|
|
307 |
|
|
308 |
document.activeElement.blur();
|
|
309 |
window.getSelection().removeAllRanges();
|
|
310 |
}
|
|
311 |
});
|
|
312 |
}
|
|
313 |
/**
|
|
314 |
* Default `action` lookup function.
|
|
315 |
* @param {Element} trigger
|
|
316 |
*/
|
|
317 |
|
|
318 |
}, {
|
|
319 |
key: "defaultAction",
|
|
320 |
value: function defaultAction(trigger) {
|
|
321 |
return getAttributeValue('action', trigger);
|
|
322 |
}
|
|
323 |
/**
|
|
324 |
* Default `target` lookup function.
|
|
325 |
* @param {Element} trigger
|
|
326 |
*/
|
|
327 |
|
|
328 |
}, {
|
|
329 |
key: "defaultTarget",
|
|
330 |
value: function defaultTarget(trigger) {
|
|
331 |
var selector = getAttributeValue('target', trigger);
|
|
332 |
|
|
333 |
if (selector) {
|
|
334 |
return document.querySelector(selector);
|
|
335 |
}
|
|
336 |
}
|
|
337 |
/**
|
|
338 |
* Allow fire programmatically a copy action
|
|
339 |
* @param {String|HTMLElement} target
|
|
340 |
* @param {Object} options
|
|
341 |
* @returns Text copied.
|
|
342 |
*/
|
|
343 |
|
|
344 |
}, {
|
|
345 |
key: "defaultText",
|
|
346 |
|
|
347 |
/**
|
|
348 |
* Default `text` lookup function.
|
|
349 |
* @param {Element} trigger
|
|
350 |
*/
|
|
351 |
value: function defaultText(trigger) {
|
|
352 |
return getAttributeValue('text', trigger);
|
|
353 |
}
|
|
354 |
/**
|
|
355 |
* Destroy lifecycle.
|
|
356 |
*/
|
|
357 |
|
|
358 |
}, {
|
|
359 |
key: "destroy",
|
|
360 |
value: function destroy() {
|
|
361 |
this.listener.destroy();
|
|
362 |
}
|
|
363 |
}], [{
|
|
364 |
key: "copy",
|
|
365 |
value: function copy(target) {
|
|
366 |
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
367 |
container: document.body
|
|
368 |
};
|
|
369 |
return actions_copy(target, options);
|
|
370 |
}
|
|
371 |
/**
|
|
372 |
* Allow fire programmatically a cut action
|
|
373 |
* @param {String|HTMLElement} target
|
|
374 |
* @returns Text cutted.
|
|
375 |
*/
|
|
376 |
|
|
377 |
}, {
|
|
378 |
key: "cut",
|
|
379 |
value: function cut(target) {
|
|
380 |
return actions_cut(target);
|
|
381 |
}
|
|
382 |
/**
|
|
383 |
* Returns the support of the given action, or all actions if no action is
|
|
384 |
* given.
|
|
385 |
* @param {String} [action]
|
|
386 |
*/
|
|
387 |
|
|
388 |
}, {
|
|
389 |
key: "isSupported",
|
|
390 |
value: function isSupported() {
|
|
391 |
var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
|
|
392 |
var actions = typeof action === 'string' ? [action] : action;
|
|
393 |
var support = !!document.queryCommandSupported;
|
|
394 |
actions.forEach(function (action) {
|
|
395 |
support = support && !!document.queryCommandSupported(action);
|
|
396 |
});
|
|
397 |
return support;
|
|
398 |
}
|
|
399 |
}]);
|
|
400 |
|
|
401 |
return Clipboard;
|
|
402 |
}((tiny_emitter_default()));
|
|
403 |
|
|
404 |
/* harmony default export */ var clipboard = (Clipboard);
|
|
405 |
|
|
406 |
/***/ }),
|
|
407 |
|
|
408 |
/***/ 828:
|
|
409 |
/***/ (function(module) {
|
|
410 |
|
|
411 |
var DOCUMENT_NODE_TYPE = 9;
|
18
|
412 |
|
|
413 |
/**
|
19
|
414 |
* A polyfill for Element.matches()
|
18
|
415 |
*/
|
19
|
416 |
if (typeof Element !== 'undefined' && !Element.prototype.matches) {
|
|
417 |
var proto = Element.prototype;
|
|
418 |
|
|
419 |
proto.matches = proto.matchesSelector ||
|
|
420 |
proto.mozMatchesSelector ||
|
|
421 |
proto.msMatchesSelector ||
|
|
422 |
proto.oMatchesSelector ||
|
|
423 |
proto.webkitMatchesSelector;
|
|
424 |
}
|
16
|
425 |
|
|
426 |
/**
|
19
|
427 |
* Finds the closest parent that matches a selector.
|
18
|
428 |
*
|
19
|
429 |
* @param {Element} element
|
|
430 |
* @param {String} selector
|
|
431 |
* @return {Function}
|
18
|
432 |
*/
|
19
|
433 |
function closest (element, selector) {
|
|
434 |
while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
|
|
435 |
if (typeof element.matches === 'function' &&
|
|
436 |
element.matches(selector)) {
|
|
437 |
return element;
|
|
438 |
}
|
|
439 |
element = element.parentNode;
|
|
440 |
}
|
18
|
441 |
}
|
|
442 |
|
19
|
443 |
module.exports = closest;
|
|
444 |
|
|
445 |
|
|
446 |
/***/ }),
|
|
447 |
|
|
448 |
/***/ 438:
|
|
449 |
/***/ (function(module, __unused_webpack_exports, __nested_webpack_require_15133__) {
|
|
450 |
|
|
451 |
var closest = __nested_webpack_require_15133__(828);
|
18
|
452 |
|
|
453 |
/**
|
19
|
454 |
* Delegates event to a selector.
|
18
|
455 |
*
|
19
|
456 |
* @param {Element} element
|
|
457 |
* @param {String} selector
|
|
458 |
* @param {String} type
|
|
459 |
* @param {Function} callback
|
|
460 |
* @param {Boolean} useCapture
|
|
461 |
* @return {Object}
|
16
|
462 |
*/
|
19
|
463 |
function _delegate(element, selector, type, callback, useCapture) {
|
|
464 |
var listenerFn = listener.apply(this, arguments);
|
|
465 |
|
|
466 |
element.addEventListener(type, listenerFn, useCapture);
|
|
467 |
|
|
468 |
return {
|
|
469 |
destroy: function() {
|
|
470 |
element.removeEventListener(type, listenerFn, useCapture);
|
|
471 |
}
|
18
|
472 |
}
|
19
|
473 |
}
|
|
474 |
|
|
475 |
/**
|
|
476 |
* Delegates event to a selector.
|
|
477 |
*
|
|
478 |
* @param {Element|String|Array} [elements]
|
|
479 |
* @param {String} selector
|
|
480 |
* @param {String} type
|
|
481 |
* @param {Function} callback
|
|
482 |
* @param {Boolean} useCapture
|
|
483 |
* @return {Object}
|
|
484 |
*/
|
|
485 |
function delegate(elements, selector, type, callback, useCapture) {
|
|
486 |
// Handle the regular Element usage
|
|
487 |
if (typeof elements.addEventListener === 'function') {
|
|
488 |
return _delegate.apply(null, arguments);
|
18
|
489 |
}
|
|
490 |
|
19
|
491 |
// Handle Element-less usage, it defaults to global delegation
|
|
492 |
if (typeof type === 'function') {
|
|
493 |
// Use `document` as the first parameter, then apply arguments
|
|
494 |
// This is a short way to .unshift `arguments` without running into deoptimizations
|
|
495 |
return _delegate.bind(null, document).apply(null, arguments);
|
18
|
496 |
}
|
|
497 |
|
19
|
498 |
// Handle Selector-based usage
|
|
499 |
if (typeof elements === 'string') {
|
|
500 |
elements = document.querySelectorAll(elements);
|
18
|
501 |
}
|
|
502 |
|
19
|
503 |
// Handle Array-like based usage
|
|
504 |
return Array.prototype.map.call(elements, function (element) {
|
|
505 |
return _delegate(element, selector, type, callback, useCapture);
|
|
506 |
});
|
18
|
507 |
}
|
|
508 |
|
19
|
509 |
/**
|
|
510 |
* Finds closest match and invokes callback.
|
|
511 |
*
|
|
512 |
* @param {Element} element
|
|
513 |
* @param {String} selector
|
|
514 |
* @param {String} type
|
|
515 |
* @param {Function} callback
|
|
516 |
* @return {Function}
|
|
517 |
*/
|
|
518 |
function listener(element, selector, type, callback) {
|
|
519 |
return function(e) {
|
|
520 |
e.delegateTarget = closest(e.target, selector);
|
|
521 |
|
|
522 |
if (e.delegateTarget) {
|
|
523 |
callback.call(element, e);
|
|
524 |
}
|
|
525 |
}
|
|
526 |
}
|
|
527 |
|
|
528 |
module.exports = delegate;
|
18
|
529 |
|
|
530 |
|
|
531 |
/***/ }),
|
|
532 |
|
19
|
533 |
/***/ 879:
|
|
534 |
/***/ (function(__unused_webpack_module, exports) {
|
|
535 |
|
|
536 |
/**
|
|
537 |
* Check if argument is a HTML element.
|
|
538 |
*
|
|
539 |
* @param {Object} value
|
|
540 |
* @return {Boolean}
|
|
541 |
*/
|
|
542 |
exports.node = function(value) {
|
|
543 |
return value !== undefined
|
|
544 |
&& value instanceof HTMLElement
|
|
545 |
&& value.nodeType === 1;
|
|
546 |
};
|
|
547 |
|
|
548 |
/**
|
|
549 |
* Check if argument is a list of HTML elements.
|
|
550 |
*
|
|
551 |
* @param {Object} value
|
|
552 |
* @return {Boolean}
|
|
553 |
*/
|
|
554 |
exports.nodeList = function(value) {
|
|
555 |
var type = Object.prototype.toString.call(value);
|
|
556 |
|
|
557 |
return value !== undefined
|
|
558 |
&& (type === '[object NodeList]' || type === '[object HTMLCollection]')
|
|
559 |
&& ('length' in value)
|
|
560 |
&& (value.length === 0 || exports.node(value[0]));
|
|
561 |
};
|
|
562 |
|
|
563 |
/**
|
|
564 |
* Check if argument is a string.
|
|
565 |
*
|
|
566 |
* @param {Object} value
|
|
567 |
* @return {Boolean}
|
|
568 |
*/
|
|
569 |
exports.string = function(value) {
|
|
570 |
return typeof value === 'string'
|
|
571 |
|| value instanceof String;
|
|
572 |
};
|
|
573 |
|
|
574 |
/**
|
|
575 |
* Check if argument is a function.
|
|
576 |
*
|
|
577 |
* @param {Object} value
|
|
578 |
* @return {Boolean}
|
|
579 |
*/
|
|
580 |
exports.fn = function(value) {
|
|
581 |
var type = Object.prototype.toString.call(value);
|
|
582 |
|
|
583 |
return type === '[object Function]';
|
|
584 |
};
|
|
585 |
|
18
|
586 |
|
|
587 |
/***/ }),
|
|
588 |
|
19
|
589 |
/***/ 370:
|
|
590 |
/***/ (function(module, __unused_webpack_exports, __nested_webpack_require_18497__) {
|
|
591 |
|
|
592 |
var is = __nested_webpack_require_18497__(879);
|
|
593 |
var delegate = __nested_webpack_require_18497__(438);
|
|
594 |
|
|
595 |
/**
|
|
596 |
* Validates all params and calls the right
|
|
597 |
* listener function based on its target type.
|
|
598 |
*
|
|
599 |
* @param {String|HTMLElement|HTMLCollection|NodeList} target
|
|
600 |
* @param {String} type
|
|
601 |
* @param {Function} callback
|
|
602 |
* @return {Object}
|
|
603 |
*/
|
|
604 |
function listen(target, type, callback) {
|
|
605 |
if (!target && !type && !callback) {
|
|
606 |
throw new Error('Missing required arguments');
|
|
607 |
}
|
|
608 |
|
|
609 |
if (!is.string(type)) {
|
|
610 |
throw new TypeError('Second argument must be a String');
|
|
611 |
}
|
|
612 |
|
|
613 |
if (!is.fn(callback)) {
|
|
614 |
throw new TypeError('Third argument must be a Function');
|
|
615 |
}
|
|
616 |
|
|
617 |
if (is.node(target)) {
|
|
618 |
return listenNode(target, type, callback);
|
|
619 |
}
|
|
620 |
else if (is.nodeList(target)) {
|
|
621 |
return listenNodeList(target, type, callback);
|
|
622 |
}
|
|
623 |
else if (is.string(target)) {
|
|
624 |
return listenSelector(target, type, callback);
|
|
625 |
}
|
|
626 |
else {
|
|
627 |
throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
|
|
628 |
}
|
|
629 |
}
|
|
630 |
|
|
631 |
/**
|
|
632 |
* Adds an event listener to a HTML element
|
|
633 |
* and returns a remove listener function.
|
|
634 |
*
|
|
635 |
* @param {HTMLElement} node
|
|
636 |
* @param {String} type
|
|
637 |
* @param {Function} callback
|
|
638 |
* @return {Object}
|
|
639 |
*/
|
|
640 |
function listenNode(node, type, callback) {
|
|
641 |
node.addEventListener(type, callback);
|
|
642 |
|
|
643 |
return {
|
|
644 |
destroy: function() {
|
|
645 |
node.removeEventListener(type, callback);
|
|
646 |
}
|
|
647 |
}
|
|
648 |
}
|
|
649 |
|
|
650 |
/**
|
|
651 |
* Add an event listener to a list of HTML elements
|
|
652 |
* and returns a remove listener function.
|
|
653 |
*
|
|
654 |
* @param {NodeList|HTMLCollection} nodeList
|
|
655 |
* @param {String} type
|
|
656 |
* @param {Function} callback
|
|
657 |
* @return {Object}
|
|
658 |
*/
|
|
659 |
function listenNodeList(nodeList, type, callback) {
|
|
660 |
Array.prototype.forEach.call(nodeList, function(node) {
|
|
661 |
node.addEventListener(type, callback);
|
|
662 |
});
|
|
663 |
|
|
664 |
return {
|
|
665 |
destroy: function() {
|
|
666 |
Array.prototype.forEach.call(nodeList, function(node) {
|
|
667 |
node.removeEventListener(type, callback);
|
|
668 |
});
|
|
669 |
}
|
|
670 |
}
|
|
671 |
}
|
|
672 |
|
|
673 |
/**
|
|
674 |
* Add an event listener to a selector
|
|
675 |
* and returns a remove listener function.
|
|
676 |
*
|
|
677 |
* @param {String} selector
|
|
678 |
* @param {String} type
|
|
679 |
* @param {Function} callback
|
|
680 |
* @return {Object}
|
|
681 |
*/
|
|
682 |
function listenSelector(selector, type, callback) {
|
|
683 |
return delegate(document.body, selector, type, callback);
|
|
684 |
}
|
|
685 |
|
|
686 |
module.exports = listen;
|
18
|
687 |
|
|
688 |
|
|
689 |
/***/ }),
|
|
690 |
|
19
|
691 |
/***/ 817:
|
|
692 |
/***/ (function(module) {
|
|
693 |
|
|
694 |
function select(element) {
|
|
695 |
var selectedText;
|
|
696 |
|
|
697 |
if (element.nodeName === 'SELECT') {
|
|
698 |
element.focus();
|
|
699 |
|
|
700 |
selectedText = element.value;
|
16
|
701 |
}
|
19
|
702 |
else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
|
|
703 |
var isReadOnly = element.hasAttribute('readonly');
|
|
704 |
|
|
705 |
if (!isReadOnly) {
|
|
706 |
element.setAttribute('readonly', '');
|
18
|
707 |
}
|
|
708 |
|
19
|
709 |
element.select();
|
|
710 |
element.setSelectionRange(0, element.value.length);
|
|
711 |
|
|
712 |
if (!isReadOnly) {
|
|
713 |
element.removeAttribute('readonly');
|
|
714 |
}
|
|
715 |
|
|
716 |
selectedText = element.value;
|
|
717 |
}
|
|
718 |
else {
|
|
719 |
if (element.hasAttribute('contenteditable')) {
|
|
720 |
element.focus();
|
18
|
721 |
}
|
|
722 |
|
19
|
723 |
var selection = window.getSelection();
|
|
724 |
var range = document.createRange();
|
|
725 |
|
|
726 |
range.selectNodeContents(element);
|
|
727 |
selection.removeAllRanges();
|
|
728 |
selection.addRange(range);
|
|
729 |
|
|
730 |
selectedText = selection.toString();
|
|
731 |
}
|
|
732 |
|
|
733 |
return selectedText;
|
|
734 |
}
|
|
735 |
|
|
736 |
module.exports = select;
|
18
|
737 |
|
16
|
738 |
|
|
739 |
/***/ }),
|
|
740 |
|
19
|
741 |
/***/ 279:
|
|
742 |
/***/ (function(module) {
|
|
743 |
|
|
744 |
function E () {
|
|
745 |
// Keep this empty so it's easier to inherit from
|
|
746 |
// (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
|
|
747 |
}
|
|
748 |
|
|
749 |
E.prototype = {
|
|
750 |
on: function (name, callback, ctx) {
|
|
751 |
var e = this.e || (this.e = {});
|
|
752 |
|
|
753 |
(e[name] || (e[name] = [])).push({
|
|
754 |
fn: callback,
|
|
755 |
ctx: ctx
|
|
756 |
});
|
|
757 |
|
|
758 |
return this;
|
|
759 |
},
|
|
760 |
|
|
761 |
once: function (name, callback, ctx) {
|
|
762 |
var self = this;
|
|
763 |
function listener () {
|
|
764 |
self.off(name, listener);
|
|
765 |
callback.apply(ctx, arguments);
|
|
766 |
};
|
|
767 |
|
|
768 |
listener._ = callback
|
|
769 |
return this.on(name, listener, ctx);
|
|
770 |
},
|
|
771 |
|
|
772 |
emit: function (name) {
|
|
773 |
var data = [].slice.call(arguments, 1);
|
|
774 |
var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
|
|
775 |
var i = 0;
|
|
776 |
var len = evtArr.length;
|
|
777 |
|
|
778 |
for (i; i < len; i++) {
|
|
779 |
evtArr[i].fn.apply(evtArr[i].ctx, data);
|
|
780 |
}
|
|
781 |
|
|
782 |
return this;
|
|
783 |
},
|
|
784 |
|
|
785 |
off: function (name, callback) {
|
|
786 |
var e = this.e || (this.e = {});
|
|
787 |
var evts = e[name];
|
|
788 |
var liveEvents = [];
|
|
789 |
|
|
790 |
if (evts && callback) {
|
|
791 |
for (var i = 0, len = evts.length; i < len; i++) {
|
|
792 |
if (evts[i].fn !== callback && evts[i].fn._ !== callback)
|
|
793 |
liveEvents.push(evts[i]);
|
|
794 |
}
|
|
795 |
}
|
|
796 |
|
|
797 |
// Remove event from queue to prevent memory leak
|
|
798 |
// Suggested by https://github.com/lazd
|
|
799 |
// Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
|
|
800 |
|
|
801 |
(liveEvents.length)
|
|
802 |
? e[name] = liveEvents
|
|
803 |
: delete e[name];
|
|
804 |
|
|
805 |
return this;
|
|
806 |
}
|
|
807 |
};
|
|
808 |
|
|
809 |
module.exports = E;
|
|
810 |
module.exports.TinyEmitter = E;
|
|
811 |
|
|
812 |
|
|
813 |
/***/ })
|
|
814 |
|
|
815 |
/******/ });
|
|
816 |
/************************************************************************/
|
|
817 |
/******/ // The module cache
|
|
818 |
/******/ var __webpack_module_cache__ = {};
|
|
819 |
/******/
|
|
820 |
/******/ // The require function
|
|
821 |
/******/ function __nested_webpack_require_23879__(moduleId) {
|
|
822 |
/******/ // Check if module is in cache
|
|
823 |
/******/ if(__webpack_module_cache__[moduleId]) {
|
|
824 |
/******/ return __webpack_module_cache__[moduleId].exports;
|
|
825 |
/******/ }
|
|
826 |
/******/ // Create a new module (and put it into the cache)
|
|
827 |
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
828 |
/******/ // no module.id needed
|
|
829 |
/******/ // no module.loaded needed
|
|
830 |
/******/ exports: {}
|
|
831 |
/******/ };
|
|
832 |
/******/
|
|
833 |
/******/ // Execute the module function
|
|
834 |
/******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_23879__);
|
|
835 |
/******/
|
|
836 |
/******/ // Return the exports of the module
|
|
837 |
/******/ return module.exports;
|
|
838 |
/******/ }
|
|
839 |
/******/
|
|
840 |
/************************************************************************/
|
|
841 |
/******/ /* webpack/runtime/compat get default export */
|
|
842 |
/******/ !function() {
|
|
843 |
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
844 |
/******/ __nested_webpack_require_23879__.n = function(module) {
|
|
845 |
/******/ var getter = module && module.__esModule ?
|
|
846 |
/******/ function() { return module['default']; } :
|
|
847 |
/******/ function() { return module; };
|
|
848 |
/******/ __nested_webpack_require_23879__.d(getter, { a: getter });
|
|
849 |
/******/ return getter;
|
|
850 |
/******/ };
|
|
851 |
/******/ }();
|
|
852 |
/******/
|
|
853 |
/******/ /* webpack/runtime/define property getters */
|
|
854 |
/******/ !function() {
|
|
855 |
/******/ // define getter functions for harmony exports
|
|
856 |
/******/ __nested_webpack_require_23879__.d = function(exports, definition) {
|
|
857 |
/******/ for(var key in definition) {
|
|
858 |
/******/ if(__nested_webpack_require_23879__.o(definition, key) && !__nested_webpack_require_23879__.o(exports, key)) {
|
|
859 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
860 |
/******/ }
|
|
861 |
/******/ }
|
|
862 |
/******/ };
|
|
863 |
/******/ }();
|
|
864 |
/******/
|
|
865 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
866 |
/******/ !function() {
|
|
867 |
/******/ __nested_webpack_require_23879__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
868 |
/******/ }();
|
|
869 |
/******/
|
|
870 |
/************************************************************************/
|
|
871 |
/******/ // module exports must be returned from runtime so entry inlining is disabled
|
|
872 |
/******/ // startup
|
|
873 |
/******/ // Load entry module and return exports
|
|
874 |
/******/ return __nested_webpack_require_23879__(686);
|
|
875 |
/******/ })()
|
|
876 |
.default;
|
|
877 |
});
|
18
|
878 |
|
|
879 |
/***/ }),
|
|
880 |
|
19
|
881 |
/***/ 7973:
|
16
|
882 |
/***/ (function(module, exports, __webpack_require__) {
|
|
883 |
|
|
884 |
var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */
|
|
885 |
/**
|
|
886 |
* Copyright 2012-2017 Craig Campbell
|
|
887 |
*
|
|
888 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
889 |
* you may not use this file except in compliance with the License.
|
|
890 |
* You may obtain a copy of the License at
|
|
891 |
*
|
|
892 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
893 |
*
|
|
894 |
* Unless required by applicable law or agreed to in writing, software
|
|
895 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
896 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
897 |
* See the License for the specific language governing permissions and
|
|
898 |
* limitations under the License.
|
|
899 |
*
|
|
900 |
* Mousetrap is a simple keyboard shortcut library for Javascript with
|
|
901 |
* no external dependencies
|
|
902 |
*
|
|
903 |
* @version 1.6.5
|
|
904 |
* @url craig.is/killing/mice
|
|
905 |
*/
|
|
906 |
(function(window, document, undefined) {
|
|
907 |
|
|
908 |
// Check if mousetrap is used inside browser, if not, return
|
|
909 |
if (!window) {
|
|
910 |
return;
|
|
911 |
}
|
|
912 |
|
|
913 |
/**
|
|
914 |
* mapping of special keycodes to their corresponding keys
|
|
915 |
*
|
|
916 |
* everything in this dictionary cannot use keypress events
|
|
917 |
* so it has to be here to map to the correct keycodes for
|
|
918 |
* keyup/keydown events
|
|
919 |
*
|
|
920 |
* @type {Object}
|
|
921 |
*/
|
|
922 |
var _MAP = {
|
|
923 |
8: 'backspace',
|
|
924 |
9: 'tab',
|
|
925 |
13: 'enter',
|
|
926 |
16: 'shift',
|
|
927 |
17: 'ctrl',
|
|
928 |
18: 'alt',
|
|
929 |
20: 'capslock',
|
|
930 |
27: 'esc',
|
|
931 |
32: 'space',
|
|
932 |
33: 'pageup',
|
|
933 |
34: 'pagedown',
|
|
934 |
35: 'end',
|
|
935 |
36: 'home',
|
|
936 |
37: 'left',
|
|
937 |
38: 'up',
|
|
938 |
39: 'right',
|
|
939 |
40: 'down',
|
|
940 |
45: 'ins',
|
|
941 |
46: 'del',
|
|
942 |
91: 'meta',
|
|
943 |
93: 'meta',
|
|
944 |
224: 'meta'
|
|
945 |
};
|
|
946 |
|
|
947 |
/**
|
|
948 |
* mapping for special characters so they can support
|
|
949 |
*
|
|
950 |
* this dictionary is only used incase you want to bind a
|
|
951 |
* keyup or keydown event to one of these keys
|
|
952 |
*
|
|
953 |
* @type {Object}
|
|
954 |
*/
|
|
955 |
var _KEYCODE_MAP = {
|
|
956 |
106: '*',
|
|
957 |
107: '+',
|
|
958 |
109: '-',
|
|
959 |
110: '.',
|
|
960 |
111 : '/',
|
|
961 |
186: ';',
|
|
962 |
187: '=',
|
|
963 |
188: ',',
|
|
964 |
189: '-',
|
|
965 |
190: '.',
|
|
966 |
191: '/',
|
|
967 |
192: '`',
|
|
968 |
219: '[',
|
|
969 |
220: '\\',
|
|
970 |
221: ']',
|
|
971 |
222: '\''
|
|
972 |
};
|
|
973 |
|
|
974 |
/**
|
|
975 |
* this is a mapping of keys that require shift on a US keypad
|
|
976 |
* back to the non shift equivelents
|
|
977 |
*
|
|
978 |
* this is so you can use keyup events with these keys
|
|
979 |
*
|
|
980 |
* note that this will only work reliably on US keyboards
|
|
981 |
*
|
|
982 |
* @type {Object}
|
|
983 |
*/
|
|
984 |
var _SHIFT_MAP = {
|
|
985 |
'~': '`',
|
|
986 |
'!': '1',
|
|
987 |
'@': '2',
|
|
988 |
'#': '3',
|
|
989 |
'$': '4',
|
|
990 |
'%': '5',
|
|
991 |
'^': '6',
|
|
992 |
'&': '7',
|
|
993 |
'*': '8',
|
|
994 |
'(': '9',
|
|
995 |
')': '0',
|
|
996 |
'_': '-',
|
|
997 |
'+': '=',
|
|
998 |
':': ';',
|
|
999 |
'\"': '\'',
|
|
1000 |
'<': ',',
|
|
1001 |
'>': '.',
|
|
1002 |
'?': '/',
|
|
1003 |
'|': '\\'
|
|
1004 |
};
|
|
1005 |
|
|
1006 |
/**
|
|
1007 |
* this is a list of special strings you can use to map
|
|
1008 |
* to modifier keys when you specify your keyboard shortcuts
|
|
1009 |
*
|
|
1010 |
* @type {Object}
|
|
1011 |
*/
|
|
1012 |
var _SPECIAL_ALIASES = {
|
|
1013 |
'option': 'alt',
|
|
1014 |
'command': 'meta',
|
|
1015 |
'return': 'enter',
|
|
1016 |
'escape': 'esc',
|
|
1017 |
'plus': '+',
|
|
1018 |
'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl'
|
|
1019 |
};
|
|
1020 |
|
|
1021 |
/**
|
|
1022 |
* variable to store the flipped version of _MAP from above
|
|
1023 |
* needed to check if we should use keypress or not when no action
|
|
1024 |
* is specified
|
|
1025 |
*
|
|
1026 |
* @type {Object|undefined}
|
|
1027 |
*/
|
|
1028 |
var _REVERSE_MAP;
|
|
1029 |
|
|
1030 |
/**
|
|
1031 |
* loop through the f keys, f1 to f19 and add them to the map
|
|
1032 |
* programatically
|
|
1033 |
*/
|
|
1034 |
for (var i = 1; i < 20; ++i) {
|
|
1035 |
_MAP[111 + i] = 'f' + i;
|
|
1036 |
}
|
|
1037 |
|
|
1038 |
/**
|
|
1039 |
* loop through to map numbers on the numeric keypad
|
|
1040 |
*/
|
|
1041 |
for (i = 0; i <= 9; ++i) {
|
|
1042 |
|
|
1043 |
// This needs to use a string cause otherwise since 0 is falsey
|
|
1044 |
// mousetrap will never fire for numpad 0 pressed as part of a keydown
|
|
1045 |
// event.
|
|
1046 |
//
|
|
1047 |
// @see https://github.com/ccampbell/mousetrap/pull/258
|
|
1048 |
_MAP[i + 96] = i.toString();
|
|
1049 |
}
|
|
1050 |
|
|
1051 |
/**
|
|
1052 |
* cross browser add event method
|
|
1053 |
*
|
|
1054 |
* @param {Element|HTMLDocument} object
|
|
1055 |
* @param {string} type
|
|
1056 |
* @param {Function} callback
|
|
1057 |
* @returns void
|
|
1058 |
*/
|
|
1059 |
function _addEvent(object, type, callback) {
|
|
1060 |
if (object.addEventListener) {
|
|
1061 |
object.addEventListener(type, callback, false);
|
|
1062 |
return;
|
|
1063 |
}
|
|
1064 |
|
|
1065 |
object.attachEvent('on' + type, callback);
|
|
1066 |
}
|
|
1067 |
|
|
1068 |
/**
|
|
1069 |
* takes the event and returns the key character
|
|
1070 |
*
|
|
1071 |
* @param {Event} e
|
|
1072 |
* @return {string}
|
|
1073 |
*/
|
|
1074 |
function _characterFromEvent(e) {
|
|
1075 |
|
|
1076 |
// for keypress events we should return the character as is
|
|
1077 |
if (e.type == 'keypress') {
|
|
1078 |
var character = String.fromCharCode(e.which);
|
|
1079 |
|
|
1080 |
// if the shift key is not pressed then it is safe to assume
|
|
1081 |
// that we want the character to be lowercase. this means if
|
|
1082 |
// you accidentally have caps lock on then your key bindings
|
|
1083 |
// will continue to work
|
|
1084 |
//
|
|
1085 |
// the only side effect that might not be desired is if you
|
|
1086 |
// bind something like 'A' cause you want to trigger an
|
|
1087 |
// event when capital A is pressed caps lock will no longer
|
|
1088 |
// trigger the event. shift+a will though.
|
|
1089 |
if (!e.shiftKey) {
|
|
1090 |
character = character.toLowerCase();
|
|
1091 |
}
|
|
1092 |
|
|
1093 |
return character;
|
|
1094 |
}
|
|
1095 |
|
|
1096 |
// for non keypress events the special maps are needed
|
|
1097 |
if (_MAP[e.which]) {
|
|
1098 |
return _MAP[e.which];
|
|
1099 |
}
|
|
1100 |
|
|
1101 |
if (_KEYCODE_MAP[e.which]) {
|
|
1102 |
return _KEYCODE_MAP[e.which];
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
// if it is not in the special map
|
|
1106 |
|
|
1107 |
// with keydown and keyup events the character seems to always
|
|
1108 |
// come in as an uppercase character whether you are pressing shift
|
|
1109 |
// or not. we should make sure it is always lowercase for comparisons
|
|
1110 |
return String.fromCharCode(e.which).toLowerCase();
|
|
1111 |
}
|
|
1112 |
|
|
1113 |
/**
|
|
1114 |
* checks if two arrays are equal
|
|
1115 |
*
|
|
1116 |
* @param {Array} modifiers1
|
|
1117 |
* @param {Array} modifiers2
|
|
1118 |
* @returns {boolean}
|
|
1119 |
*/
|
|
1120 |
function _modifiersMatch(modifiers1, modifiers2) {
|
|
1121 |
return modifiers1.sort().join(',') === modifiers2.sort().join(',');
|
|
1122 |
}
|
|
1123 |
|
|
1124 |
/**
|
|
1125 |
* takes a key event and figures out what the modifiers are
|
|
1126 |
*
|
|
1127 |
* @param {Event} e
|
|
1128 |
* @returns {Array}
|
|
1129 |
*/
|
|
1130 |
function _eventModifiers(e) {
|
|
1131 |
var modifiers = [];
|
|
1132 |
|
|
1133 |
if (e.shiftKey) {
|
|
1134 |
modifiers.push('shift');
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
if (e.altKey) {
|
|
1138 |
modifiers.push('alt');
|
|
1139 |
}
|
|
1140 |
|
|
1141 |
if (e.ctrlKey) {
|
|
1142 |
modifiers.push('ctrl');
|
|
1143 |
}
|
|
1144 |
|
|
1145 |
if (e.metaKey) {
|
|
1146 |
modifiers.push('meta');
|
|
1147 |
}
|
|
1148 |
|
|
1149 |
return modifiers;
|
|
1150 |
}
|
|
1151 |
|
|
1152 |
/**
|
|
1153 |
* prevents default for this event
|
|
1154 |
*
|
|
1155 |
* @param {Event} e
|
|
1156 |
* @returns void
|
|
1157 |
*/
|
|
1158 |
function _preventDefault(e) {
|
|
1159 |
if (e.preventDefault) {
|
|
1160 |
e.preventDefault();
|
|
1161 |
return;
|
|
1162 |
}
|
|
1163 |
|
|
1164 |
e.returnValue = false;
|
|
1165 |
}
|
|
1166 |
|
|
1167 |
/**
|
|
1168 |
* stops propogation for this event
|
|
1169 |
*
|
|
1170 |
* @param {Event} e
|
|
1171 |
* @returns void
|
|
1172 |
*/
|
|
1173 |
function _stopPropagation(e) {
|
|
1174 |
if (e.stopPropagation) {
|
|
1175 |
e.stopPropagation();
|
|
1176 |
return;
|
|
1177 |
}
|
|
1178 |
|
|
1179 |
e.cancelBubble = true;
|
|
1180 |
}
|
|
1181 |
|
|
1182 |
/**
|
|
1183 |
* determines if the keycode specified is a modifier key or not
|
|
1184 |
*
|
|
1185 |
* @param {string} key
|
|
1186 |
* @returns {boolean}
|
|
1187 |
*/
|
|
1188 |
function _isModifier(key) {
|
|
1189 |
return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta';
|
|
1190 |
}
|
|
1191 |
|
|
1192 |
/**
|
|
1193 |
* reverses the map lookup so that we can look for specific keys
|
|
1194 |
* to see what can and can't use keypress
|
|
1195 |
*
|
|
1196 |
* @return {Object}
|
|
1197 |
*/
|
|
1198 |
function _getReverseMap() {
|
|
1199 |
if (!_REVERSE_MAP) {
|
|
1200 |
_REVERSE_MAP = {};
|
|
1201 |
for (var key in _MAP) {
|
|
1202 |
|
|
1203 |
// pull out the numeric keypad from here cause keypress should
|
|
1204 |
// be able to detect the keys from the character
|
|
1205 |
if (key > 95 && key < 112) {
|
|
1206 |
continue;
|
|
1207 |
}
|
|
1208 |
|
|
1209 |
if (_MAP.hasOwnProperty(key)) {
|
|
1210 |
_REVERSE_MAP[_MAP[key]] = key;
|
|
1211 |
}
|
|
1212 |
}
|
|
1213 |
}
|
|
1214 |
return _REVERSE_MAP;
|
|
1215 |
}
|
|
1216 |
|
|
1217 |
/**
|
|
1218 |
* picks the best action based on the key combination
|
|
1219 |
*
|
|
1220 |
* @param {string} key - character for key
|
|
1221 |
* @param {Array} modifiers
|
|
1222 |
* @param {string=} action passed in
|
|
1223 |
*/
|
|
1224 |
function _pickBestAction(key, modifiers, action) {
|
|
1225 |
|
|
1226 |
// if no action was picked in we should try to pick the one
|
|
1227 |
// that we think would work best for this key
|
|
1228 |
if (!action) {
|
|
1229 |
action = _getReverseMap()[key] ? 'keydown' : 'keypress';
|
|
1230 |
}
|
|
1231 |
|
|
1232 |
// modifier keys don't work as expected with keypress,
|
|
1233 |
// switch to keydown
|
|
1234 |
if (action == 'keypress' && modifiers.length) {
|
|
1235 |
action = 'keydown';
|
|
1236 |
}
|
|
1237 |
|
|
1238 |
return action;
|
|
1239 |
}
|
|
1240 |
|
|
1241 |
/**
|
|
1242 |
* Converts from a string key combination to an array
|
|
1243 |
*
|
|
1244 |
* @param {string} combination like "command+shift+l"
|
|
1245 |
* @return {Array}
|
|
1246 |
*/
|
|
1247 |
function _keysFromString(combination) {
|
|
1248 |
if (combination === '+') {
|
|
1249 |
return ['+'];
|
|
1250 |
}
|
|
1251 |
|
|
1252 |
combination = combination.replace(/\+{2}/g, '+plus');
|
|
1253 |
return combination.split('+');
|
|
1254 |
}
|
|
1255 |
|
|
1256 |
/**
|
|
1257 |
* Gets info for a specific key combination
|
|
1258 |
*
|
|
1259 |
* @param {string} combination key combination ("command+s" or "a" or "*")
|
|
1260 |
* @param {string=} action
|
|
1261 |
* @returns {Object}
|
|
1262 |
*/
|
|
1263 |
function _getKeyInfo(combination, action) {
|
|
1264 |
var keys;
|
|
1265 |
var key;
|
|
1266 |
var i;
|
|
1267 |
var modifiers = [];
|
|
1268 |
|
|
1269 |
// take the keys from this pattern and figure out what the actual
|
|
1270 |
// pattern is all about
|
|
1271 |
keys = _keysFromString(combination);
|
|
1272 |
|
|
1273 |
for (i = 0; i < keys.length; ++i) {
|
|
1274 |
key = keys[i];
|
|
1275 |
|
|
1276 |
// normalize key names
|
|
1277 |
if (_SPECIAL_ALIASES[key]) {
|
|
1278 |
key = _SPECIAL_ALIASES[key];
|
|
1279 |
}
|
|
1280 |
|
|
1281 |
// if this is not a keypress event then we should
|
|
1282 |
// be smart about using shift keys
|
|
1283 |
// this will only work for US keyboards however
|
|
1284 |
if (action && action != 'keypress' && _SHIFT_MAP[key]) {
|
|
1285 |
key = _SHIFT_MAP[key];
|
|
1286 |
modifiers.push('shift');
|
|
1287 |
}
|
|
1288 |
|
|
1289 |
// if this key is a modifier then add it to the list of modifiers
|
|
1290 |
if (_isModifier(key)) {
|
|
1291 |
modifiers.push(key);
|
|
1292 |
}
|
|
1293 |
}
|
|
1294 |
|
|
1295 |
// depending on what the key combination is
|
|
1296 |
// we will try to pick the best event for it
|
|
1297 |
action = _pickBestAction(key, modifiers, action);
|
|
1298 |
|
|
1299 |
return {
|
|
1300 |
key: key,
|
|
1301 |
modifiers: modifiers,
|
|
1302 |
action: action
|
|
1303 |
};
|
|
1304 |
}
|
|
1305 |
|
|
1306 |
function _belongsTo(element, ancestor) {
|
|
1307 |
if (element === null || element === document) {
|
|
1308 |
return false;
|
|
1309 |
}
|
|
1310 |
|
|
1311 |
if (element === ancestor) {
|
|
1312 |
return true;
|
|
1313 |
}
|
|
1314 |
|
|
1315 |
return _belongsTo(element.parentNode, ancestor);
|
|
1316 |
}
|
|
1317 |
|
|
1318 |
function Mousetrap(targetElement) {
|
|
1319 |
var self = this;
|
|
1320 |
|
|
1321 |
targetElement = targetElement || document;
|
|
1322 |
|
|
1323 |
if (!(self instanceof Mousetrap)) {
|
|
1324 |
return new Mousetrap(targetElement);
|
|
1325 |
}
|
|
1326 |
|
|
1327 |
/**
|
|
1328 |
* element to attach key events to
|
|
1329 |
*
|
|
1330 |
* @type {Element}
|
|
1331 |
*/
|
|
1332 |
self.target = targetElement;
|
|
1333 |
|
|
1334 |
/**
|
|
1335 |
* a list of all the callbacks setup via Mousetrap.bind()
|
|
1336 |
*
|
|
1337 |
* @type {Object}
|
|
1338 |
*/
|
|
1339 |
self._callbacks = {};
|
|
1340 |
|
|
1341 |
/**
|
|
1342 |
* direct map of string combinations to callbacks used for trigger()
|
|
1343 |
*
|
|
1344 |
* @type {Object}
|
|
1345 |
*/
|
|
1346 |
self._directMap = {};
|
|
1347 |
|
|
1348 |
/**
|
|
1349 |
* keeps track of what level each sequence is at since multiple
|
|
1350 |
* sequences can start out with the same sequence
|
|
1351 |
*
|
|
1352 |
* @type {Object}
|
|
1353 |
*/
|
|
1354 |
var _sequenceLevels = {};
|
|
1355 |
|
|
1356 |
/**
|
|
1357 |
* variable to store the setTimeout call
|
|
1358 |
*
|
|
1359 |
* @type {null|number}
|
|
1360 |
*/
|
|
1361 |
var _resetTimer;
|
|
1362 |
|
|
1363 |
/**
|
|
1364 |
* temporary state where we will ignore the next keyup
|
|
1365 |
*
|
|
1366 |
* @type {boolean|string}
|
|
1367 |
*/
|
|
1368 |
var _ignoreNextKeyup = false;
|
|
1369 |
|
|
1370 |
/**
|
|
1371 |
* temporary state where we will ignore the next keypress
|
|
1372 |
*
|
|
1373 |
* @type {boolean}
|
|
1374 |
*/
|
|
1375 |
var _ignoreNextKeypress = false;
|
|
1376 |
|
|
1377 |
/**
|
|
1378 |
* are we currently inside of a sequence?
|
|
1379 |
* type of action ("keyup" or "keydown" or "keypress") or false
|
|
1380 |
*
|
|
1381 |
* @type {boolean|string}
|
|
1382 |
*/
|
|
1383 |
var _nextExpectedAction = false;
|
|
1384 |
|
|
1385 |
/**
|
|
1386 |
* resets all sequence counters except for the ones passed in
|
|
1387 |
*
|
|
1388 |
* @param {Object} doNotReset
|
|
1389 |
* @returns void
|
|
1390 |
*/
|
|
1391 |
function _resetSequences(doNotReset) {
|
|
1392 |
doNotReset = doNotReset || {};
|
|
1393 |
|
|
1394 |
var activeSequences = false,
|
|
1395 |
key;
|
|
1396 |
|
|
1397 |
for (key in _sequenceLevels) {
|
|
1398 |
if (doNotReset[key]) {
|
|
1399 |
activeSequences = true;
|
|
1400 |
continue;
|
|
1401 |
}
|
|
1402 |
_sequenceLevels[key] = 0;
|
|
1403 |
}
|
|
1404 |
|
|
1405 |
if (!activeSequences) {
|
|
1406 |
_nextExpectedAction = false;
|
|
1407 |
}
|
|
1408 |
}
|
|
1409 |
|
|
1410 |
/**
|
|
1411 |
* finds all callbacks that match based on the keycode, modifiers,
|
|
1412 |
* and action
|
|
1413 |
*
|
|
1414 |
* @param {string} character
|
|
1415 |
* @param {Array} modifiers
|
|
1416 |
* @param {Event|Object} e
|
|
1417 |
* @param {string=} sequenceName - name of the sequence we are looking for
|
|
1418 |
* @param {string=} combination
|
|
1419 |
* @param {number=} level
|
|
1420 |
* @returns {Array}
|
|
1421 |
*/
|
|
1422 |
function _getMatches(character, modifiers, e, sequenceName, combination, level) {
|
|
1423 |
var i;
|
|
1424 |
var callback;
|
|
1425 |
var matches = [];
|
|
1426 |
var action = e.type;
|
|
1427 |
|
|
1428 |
// if there are no events related to this keycode
|
|
1429 |
if (!self._callbacks[character]) {
|
|
1430 |
return [];
|
|
1431 |
}
|
|
1432 |
|
|
1433 |
// if a modifier key is coming up on its own we should allow it
|
|
1434 |
if (action == 'keyup' && _isModifier(character)) {
|
|
1435 |
modifiers = [character];
|
|
1436 |
}
|
|
1437 |
|
|
1438 |
// loop through all callbacks for the key that was pressed
|
|
1439 |
// and see if any of them match
|
|
1440 |
for (i = 0; i < self._callbacks[character].length; ++i) {
|
|
1441 |
callback = self._callbacks[character][i];
|
|
1442 |
|
|
1443 |
// if a sequence name is not specified, but this is a sequence at
|
|
1444 |
// the wrong level then move onto the next match
|
|
1445 |
if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) {
|
|
1446 |
continue;
|
|
1447 |
}
|
|
1448 |
|
|
1449 |
// if the action we are looking for doesn't match the action we got
|
|
1450 |
// then we should keep going
|
|
1451 |
if (action != callback.action) {
|
|
1452 |
continue;
|
|
1453 |
}
|
|
1454 |
|
|
1455 |
// if this is a keypress event and the meta key and control key
|
|
1456 |
// are not pressed that means that we need to only look at the
|
|
1457 |
// character, otherwise check the modifiers as well
|
|
1458 |
//
|
|
1459 |
// chrome will not fire a keypress if meta or control is down
|
|
1460 |
// safari will fire a keypress if meta or meta+shift is down
|
|
1461 |
// firefox will fire a keypress if meta or control is down
|
|
1462 |
if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) {
|
|
1463 |
|
|
1464 |
// when you bind a combination or sequence a second time it
|
|
1465 |
// should overwrite the first one. if a sequenceName or
|
|
1466 |
// combination is specified in this call it does just that
|
|
1467 |
//
|
|
1468 |
// @todo make deleting its own method?
|
|
1469 |
var deleteCombo = !sequenceName && callback.combo == combination;
|
|
1470 |
var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level;
|
|
1471 |
if (deleteCombo || deleteSequence) {
|
|
1472 |
self._callbacks[character].splice(i, 1);
|
|
1473 |
}
|
|
1474 |
|
|
1475 |
matches.push(callback);
|
|
1476 |
}
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
return matches;
|
|
1480 |
}
|
|
1481 |
|
|
1482 |
/**
|
|
1483 |
* actually calls the callback function
|
|
1484 |
*
|
|
1485 |
* if your callback function returns false this will use the jquery
|
|
1486 |
* convention - prevent default and stop propogation on the event
|
|
1487 |
*
|
|
1488 |
* @param {Function} callback
|
|
1489 |
* @param {Event} e
|
|
1490 |
* @returns void
|
|
1491 |
*/
|
|
1492 |
function _fireCallback(callback, e, combo, sequence) {
|
|
1493 |
|
|
1494 |
// if this event should not happen stop here
|
|
1495 |
if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
|
|
1496 |
return;
|
|
1497 |
}
|
|
1498 |
|
|
1499 |
if (callback(e, combo) === false) {
|
|
1500 |
_preventDefault(e);
|
|
1501 |
_stopPropagation(e);
|
|
1502 |
}
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
/**
|
|
1506 |
* handles a character key event
|
|
1507 |
*
|
|
1508 |
* @param {string} character
|
|
1509 |
* @param {Array} modifiers
|
|
1510 |
* @param {Event} e
|
|
1511 |
* @returns void
|
|
1512 |
*/
|
|
1513 |
self._handleKey = function(character, modifiers, e) {
|
|
1514 |
var callbacks = _getMatches(character, modifiers, e);
|
|
1515 |
var i;
|
|
1516 |
var doNotReset = {};
|
|
1517 |
var maxLevel = 0;
|
|
1518 |
var processedSequenceCallback = false;
|
|
1519 |
|
|
1520 |
// Calculate the maxLevel for sequences so we can only execute the longest callback sequence
|
|
1521 |
for (i = 0; i < callbacks.length; ++i) {
|
|
1522 |
if (callbacks[i].seq) {
|
|
1523 |
maxLevel = Math.max(maxLevel, callbacks[i].level);
|
|
1524 |
}
|
|
1525 |
}
|
|
1526 |
|
|
1527 |
// loop through matching callbacks for this key event
|
|
1528 |
for (i = 0; i < callbacks.length; ++i) {
|
|
1529 |
|
|
1530 |
// fire for all sequence callbacks
|
|
1531 |
// this is because if for example you have multiple sequences
|
|
1532 |
// bound such as "g i" and "g t" they both need to fire the
|
|
1533 |
// callback for matching g cause otherwise you can only ever
|
|
1534 |
// match the first one
|
|
1535 |
if (callbacks[i].seq) {
|
|
1536 |
|
|
1537 |
// only fire callbacks for the maxLevel to prevent
|
|
1538 |
// subsequences from also firing
|
|
1539 |
//
|
|
1540 |
// for example 'a option b' should not cause 'option b' to fire
|
|
1541 |
// even though 'option b' is part of the other sequence
|
|
1542 |
//
|
|
1543 |
// any sequences that do not match here will be discarded
|
|
1544 |
// below by the _resetSequences call
|
|
1545 |
if (callbacks[i].level != maxLevel) {
|
|
1546 |
continue;
|
|
1547 |
}
|
|
1548 |
|
|
1549 |
processedSequenceCallback = true;
|
|
1550 |
|
|
1551 |
// keep a list of which sequences were matches for later
|
|
1552 |
doNotReset[callbacks[i].seq] = 1;
|
|
1553 |
_fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq);
|
|
1554 |
continue;
|
|
1555 |
}
|
|
1556 |
|
|
1557 |
// if there were no sequence matches but we are still here
|
|
1558 |
// that means this is a regular match so we should fire that
|
|
1559 |
if (!processedSequenceCallback) {
|
|
1560 |
_fireCallback(callbacks[i].callback, e, callbacks[i].combo);
|
|
1561 |
}
|
|
1562 |
}
|
|
1563 |
|
|
1564 |
// if the key you pressed matches the type of sequence without
|
|
1565 |
// being a modifier (ie "keyup" or "keypress") then we should
|
|
1566 |
// reset all sequences that were not matched by this event
|
|
1567 |
//
|
|
1568 |
// this is so, for example, if you have the sequence "h a t" and you
|
|
1569 |
// type "h e a r t" it does not match. in this case the "e" will
|
|
1570 |
// cause the sequence to reset
|
|
1571 |
//
|
|
1572 |
// modifier keys are ignored because you can have a sequence
|
|
1573 |
// that contains modifiers such as "enter ctrl+space" and in most
|
|
1574 |
// cases the modifier key will be pressed before the next key
|
|
1575 |
//
|
|
1576 |
// also if you have a sequence such as "ctrl+b a" then pressing the
|
|
1577 |
// "b" key will trigger a "keypress" and a "keydown"
|
|
1578 |
//
|
|
1579 |
// the "keydown" is expected when there is a modifier, but the
|
|
1580 |
// "keypress" ends up matching the _nextExpectedAction since it occurs
|
|
1581 |
// after and that causes the sequence to reset
|
|
1582 |
//
|
|
1583 |
// we ignore keypresses in a sequence that directly follow a keydown
|
|
1584 |
// for the same character
|
|
1585 |
var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress;
|
|
1586 |
if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
|
|
1587 |
_resetSequences(doNotReset);
|
|
1588 |
}
|
|
1589 |
|
|
1590 |
_ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown';
|
|
1591 |
};
|
|
1592 |
|
|
1593 |
/**
|
|
1594 |
* handles a keydown event
|
|
1595 |
*
|
|
1596 |
* @param {Event} e
|
|
1597 |
* @returns void
|
|
1598 |
*/
|
|
1599 |
function _handleKeyEvent(e) {
|
|
1600 |
|
|
1601 |
// normalize e.which for key events
|
|
1602 |
// @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion
|
|
1603 |
if (typeof e.which !== 'number') {
|
|
1604 |
e.which = e.keyCode;
|
|
1605 |
}
|
|
1606 |
|
|
1607 |
var character = _characterFromEvent(e);
|
|
1608 |
|
|
1609 |
// no character found then stop
|
|
1610 |
if (!character) {
|
|
1611 |
return;
|
|
1612 |
}
|
|
1613 |
|
|
1614 |
// need to use === for the character check because the character can be 0
|
|
1615 |
if (e.type == 'keyup' && _ignoreNextKeyup === character) {
|
|
1616 |
_ignoreNextKeyup = false;
|
|
1617 |
return;
|
|
1618 |
}
|
|
1619 |
|
|
1620 |
self.handleKey(character, _eventModifiers(e), e);
|
|
1621 |
}
|
|
1622 |
|
|
1623 |
/**
|
|
1624 |
* called to set a 1 second timeout on the specified sequence
|
|
1625 |
*
|
|
1626 |
* this is so after each key press in the sequence you have 1 second
|
|
1627 |
* to press the next key before you have to start over
|
|
1628 |
*
|
|
1629 |
* @returns void
|
|
1630 |
*/
|
|
1631 |
function _resetSequenceTimer() {
|
|
1632 |
clearTimeout(_resetTimer);
|
|
1633 |
_resetTimer = setTimeout(_resetSequences, 1000);
|
|
1634 |
}
|
|
1635 |
|
|
1636 |
/**
|
|
1637 |
* binds a key sequence to an event
|
|
1638 |
*
|
|
1639 |
* @param {string} combo - combo specified in bind call
|
|
1640 |
* @param {Array} keys
|
|
1641 |
* @param {Function} callback
|
|
1642 |
* @param {string=} action
|
|
1643 |
* @returns void
|
|
1644 |
*/
|
|
1645 |
function _bindSequence(combo, keys, callback, action) {
|
|
1646 |
|
|
1647 |
// start off by adding a sequence level record for this combination
|
|
1648 |
// and setting the level to 0
|
|
1649 |
_sequenceLevels[combo] = 0;
|
|
1650 |
|
|
1651 |
/**
|
|
1652 |
* callback to increase the sequence level for this sequence and reset
|
|
1653 |
* all other sequences that were active
|
|
1654 |
*
|
|
1655 |
* @param {string} nextAction
|
|
1656 |
* @returns {Function}
|
|
1657 |
*/
|
|
1658 |
function _increaseSequence(nextAction) {
|
|
1659 |
return function() {
|
|
1660 |
_nextExpectedAction = nextAction;
|
|
1661 |
++_sequenceLevels[combo];
|
|
1662 |
_resetSequenceTimer();
|
|
1663 |
};
|
|
1664 |
}
|
|
1665 |
|
|
1666 |
/**
|
|
1667 |
* wraps the specified callback inside of another function in order
|
|
1668 |
* to reset all sequence counters as soon as this sequence is done
|
|
1669 |
*
|
|
1670 |
* @param {Event} e
|
|
1671 |
* @returns void
|
|
1672 |
*/
|
|
1673 |
function _callbackAndReset(e) {
|
|
1674 |
_fireCallback(callback, e, combo);
|
|
1675 |
|
|
1676 |
// we should ignore the next key up if the action is key down
|
|
1677 |
// or keypress. this is so if you finish a sequence and
|
|
1678 |
// release the key the final key will not trigger a keyup
|
|
1679 |
if (action !== 'keyup') {
|
|
1680 |
_ignoreNextKeyup = _characterFromEvent(e);
|
|
1681 |
}
|
|
1682 |
|
|
1683 |
// weird race condition if a sequence ends with the key
|
|
1684 |
// another sequence begins with
|
|
1685 |
setTimeout(_resetSequences, 10);
|
|
1686 |
}
|
|
1687 |
|
|
1688 |
// loop through keys one at a time and bind the appropriate callback
|
|
1689 |
// function. for any key leading up to the final one it should
|
|
1690 |
// increase the sequence. after the final, it should reset all sequences
|
|
1691 |
//
|
|
1692 |
// if an action is specified in the original bind call then that will
|
|
1693 |
// be used throughout. otherwise we will pass the action that the
|
|
1694 |
// next key in the sequence should match. this allows a sequence
|
|
1695 |
// to mix and match keypress and keydown events depending on which
|
|
1696 |
// ones are better suited to the key provided
|
|
1697 |
for (var i = 0; i < keys.length; ++i) {
|
|
1698 |
var isFinal = i + 1 === keys.length;
|
|
1699 |
var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action);
|
|
1700 |
_bindSingle(keys[i], wrappedCallback, action, combo, i);
|
|
1701 |
}
|
|
1702 |
}
|
|
1703 |
|
|
1704 |
/**
|
|
1705 |
* binds a single keyboard combination
|
|
1706 |
*
|
|
1707 |
* @param {string} combination
|
|
1708 |
* @param {Function} callback
|
|
1709 |
* @param {string=} action
|
|
1710 |
* @param {string=} sequenceName - name of sequence if part of sequence
|
|
1711 |
* @param {number=} level - what part of the sequence the command is
|
|
1712 |
* @returns void
|
|
1713 |
*/
|
|
1714 |
function _bindSingle(combination, callback, action, sequenceName, level) {
|
|
1715 |
|
|
1716 |
// store a direct mapped reference for use with Mousetrap.trigger
|
|
1717 |
self._directMap[combination + ':' + action] = callback;
|
|
1718 |
|
|
1719 |
// make sure multiple spaces in a row become a single space
|
|
1720 |
combination = combination.replace(/\s+/g, ' ');
|
|
1721 |
|
|
1722 |
var sequence = combination.split(' ');
|
|
1723 |
var info;
|
|
1724 |
|
|
1725 |
// if this pattern is a sequence of keys then run through this method
|
|
1726 |
// to reprocess each pattern one key at a time
|
|
1727 |
if (sequence.length > 1) {
|
|
1728 |
_bindSequence(combination, sequence, callback, action);
|
|
1729 |
return;
|
|
1730 |
}
|
|
1731 |
|
|
1732 |
info = _getKeyInfo(combination, action);
|
|
1733 |
|
|
1734 |
// make sure to initialize array if this is the first time
|
|
1735 |
// a callback is added for this key
|
|
1736 |
self._callbacks[info.key] = self._callbacks[info.key] || [];
|
|
1737 |
|
|
1738 |
// remove an existing match if there is one
|
|
1739 |
_getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level);
|
|
1740 |
|
|
1741 |
// add this call back to the array
|
|
1742 |
// if it is a sequence put it at the beginning
|
|
1743 |
// if not put it at the end
|
|
1744 |
//
|
|
1745 |
// this is important because the way these are processed expects
|
|
1746 |
// the sequence ones to come first
|
|
1747 |
self._callbacks[info.key][sequenceName ? 'unshift' : 'push']({
|
|
1748 |
callback: callback,
|
|
1749 |
modifiers: info.modifiers,
|
|
1750 |
action: info.action,
|
|
1751 |
seq: sequenceName,
|
|
1752 |
level: level,
|
|
1753 |
combo: combination
|
|
1754 |
});
|
|
1755 |
}
|
|
1756 |
|
|
1757 |
/**
|
|
1758 |
* binds multiple combinations to the same callback
|
|
1759 |
*
|
|
1760 |
* @param {Array} combinations
|
|
1761 |
* @param {Function} callback
|
|
1762 |
* @param {string|undefined} action
|
|
1763 |
* @returns void
|
|
1764 |
*/
|
|
1765 |
self._bindMultiple = function(combinations, callback, action) {
|
|
1766 |
for (var i = 0; i < combinations.length; ++i) {
|
|
1767 |
_bindSingle(combinations[i], callback, action);
|
|
1768 |
}
|
|
1769 |
};
|
|
1770 |
|
|
1771 |
// start!
|
|
1772 |
_addEvent(targetElement, 'keypress', _handleKeyEvent);
|
|
1773 |
_addEvent(targetElement, 'keydown', _handleKeyEvent);
|
|
1774 |
_addEvent(targetElement, 'keyup', _handleKeyEvent);
|
|
1775 |
}
|
|
1776 |
|
|
1777 |
/**
|
|
1778 |
* binds an event to mousetrap
|
|
1779 |
*
|
|
1780 |
* can be a single key, a combination of keys separated with +,
|
|
1781 |
* an array of keys, or a sequence of keys separated by spaces
|
|
1782 |
*
|
|
1783 |
* be sure to list the modifier keys first to make sure that the
|
|
1784 |
* correct key ends up getting bound (the last key in the pattern)
|
|
1785 |
*
|
|
1786 |
* @param {string|Array} keys
|
|
1787 |
* @param {Function} callback
|
|
1788 |
* @param {string=} action - 'keypress', 'keydown', or 'keyup'
|
|
1789 |
* @returns void
|
|
1790 |
*/
|
|
1791 |
Mousetrap.prototype.bind = function(keys, callback, action) {
|
|
1792 |
var self = this;
|
|
1793 |
keys = keys instanceof Array ? keys : [keys];
|
|
1794 |
self._bindMultiple.call(self, keys, callback, action);
|
|
1795 |
return self;
|
|
1796 |
};
|
|
1797 |
|
|
1798 |
/**
|
|
1799 |
* unbinds an event to mousetrap
|
|
1800 |
*
|
|
1801 |
* the unbinding sets the callback function of the specified key combo
|
|
1802 |
* to an empty function and deletes the corresponding key in the
|
|
1803 |
* _directMap dict.
|
|
1804 |
*
|
|
1805 |
* TODO: actually remove this from the _callbacks dictionary instead
|
|
1806 |
* of binding an empty function
|
|
1807 |
*
|
|
1808 |
* the keycombo+action has to be exactly the same as
|
|
1809 |
* it was defined in the bind method
|
|
1810 |
*
|
|
1811 |
* @param {string|Array} keys
|
|
1812 |
* @param {string} action
|
|
1813 |
* @returns void
|
|
1814 |
*/
|
|
1815 |
Mousetrap.prototype.unbind = function(keys, action) {
|
|
1816 |
var self = this;
|
|
1817 |
return self.bind.call(self, keys, function() {}, action);
|
|
1818 |
};
|
|
1819 |
|
|
1820 |
/**
|
|
1821 |
* triggers an event that has already been bound
|
|
1822 |
*
|
|
1823 |
* @param {string} keys
|
|
1824 |
* @param {string=} action
|
|
1825 |
* @returns void
|
|
1826 |
*/
|
|
1827 |
Mousetrap.prototype.trigger = function(keys, action) {
|
|
1828 |
var self = this;
|
|
1829 |
if (self._directMap[keys + ':' + action]) {
|
|
1830 |
self._directMap[keys + ':' + action]({}, keys);
|
|
1831 |
}
|
|
1832 |
return self;
|
|
1833 |
};
|
|
1834 |
|
|
1835 |
/**
|
|
1836 |
* resets the library back to its initial state. this is useful
|
|
1837 |
* if you want to clear out the current keyboard shortcuts and bind
|
|
1838 |
* new ones - for example if you switch to another page
|
|
1839 |
*
|
|
1840 |
* @returns void
|
|
1841 |
*/
|
|
1842 |
Mousetrap.prototype.reset = function() {
|
|
1843 |
var self = this;
|
|
1844 |
self._callbacks = {};
|
|
1845 |
self._directMap = {};
|
|
1846 |
return self;
|
|
1847 |
};
|
|
1848 |
|
|
1849 |
/**
|
|
1850 |
* should we stop this event before firing off callbacks
|
|
1851 |
*
|
|
1852 |
* @param {Event} e
|
|
1853 |
* @param {Element} element
|
|
1854 |
* @return {boolean}
|
|
1855 |
*/
|
|
1856 |
Mousetrap.prototype.stopCallback = function(e, element) {
|
|
1857 |
var self = this;
|
|
1858 |
|
|
1859 |
// if the element has the class "mousetrap" then no need to stop
|
|
1860 |
if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
|
|
1861 |
return false;
|
|
1862 |
}
|
|
1863 |
|
|
1864 |
if (_belongsTo(element, self.target)) {
|
|
1865 |
return false;
|
|
1866 |
}
|
|
1867 |
|
|
1868 |
// Events originating from a shadow DOM are re-targetted and `e.target` is the shadow host,
|
|
1869 |
// not the initial event target in the shadow tree. Note that not all events cross the
|
|
1870 |
// shadow boundary.
|
|
1871 |
// For shadow trees with `mode: 'open'`, the initial event target is the first element in
|
|
1872 |
// the event’s composed path. For shadow trees with `mode: 'closed'`, the initial event
|
|
1873 |
// target cannot be obtained.
|
|
1874 |
if ('composedPath' in e && typeof e.composedPath === 'function') {
|
|
1875 |
// For open shadow trees, update `element` so that the following check works.
|
|
1876 |
var initialEventTarget = e.composedPath()[0];
|
|
1877 |
if (initialEventTarget !== e.target) {
|
|
1878 |
element = initialEventTarget;
|
|
1879 |
}
|
|
1880 |
}
|
|
1881 |
|
|
1882 |
// stop for input, select, and textarea
|
|
1883 |
return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
|
|
1884 |
};
|
|
1885 |
|
|
1886 |
/**
|
|
1887 |
* exposes _handleKey publicly so it can be overwritten by extensions
|
|
1888 |
*/
|
|
1889 |
Mousetrap.prototype.handleKey = function() {
|
|
1890 |
var self = this;
|
|
1891 |
return self._handleKey.apply(self, arguments);
|
|
1892 |
};
|
|
1893 |
|
|
1894 |
/**
|
|
1895 |
* allow custom key mappings
|
|
1896 |
*/
|
|
1897 |
Mousetrap.addKeycodes = function(object) {
|
|
1898 |
for (var key in object) {
|
|
1899 |
if (object.hasOwnProperty(key)) {
|
|
1900 |
_MAP[key] = object[key];
|
|
1901 |
}
|
|
1902 |
}
|
|
1903 |
_REVERSE_MAP = null;
|
|
1904 |
};
|
|
1905 |
|
|
1906 |
/**
|
|
1907 |
* Init the global mousetrap functions
|
|
1908 |
*
|
|
1909 |
* This method is needed to allow the global mousetrap functions to work
|
|
1910 |
* now that mousetrap is a constructor function.
|
|
1911 |
*/
|
|
1912 |
Mousetrap.init = function() {
|
|
1913 |
var documentMousetrap = Mousetrap(document);
|
|
1914 |
for (var method in documentMousetrap) {
|
|
1915 |
if (method.charAt(0) !== '_') {
|
|
1916 |
Mousetrap[method] = (function(method) {
|
|
1917 |
return function() {
|
|
1918 |
return documentMousetrap[method].apply(documentMousetrap, arguments);
|
|
1919 |
};
|
|
1920 |
} (method));
|
|
1921 |
}
|
|
1922 |
}
|
|
1923 |
};
|
|
1924 |
|
|
1925 |
Mousetrap.init();
|
|
1926 |
|
|
1927 |
// expose mousetrap to the global object
|
|
1928 |
window.Mousetrap = Mousetrap;
|
|
1929 |
|
|
1930 |
// expose as a common js module
|
|
1931 |
if ( true && module.exports) {
|
|
1932 |
module.exports = Mousetrap;
|
|
1933 |
}
|
|
1934 |
|
|
1935 |
// expose mousetrap as an AMD module
|
|
1936 |
if (true) {
|
|
1937 |
!(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
|
|
1938 |
return Mousetrap;
|
|
1939 |
}).call(exports, __webpack_require__, exports, module),
|
19
|
1940 |
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
|
16
|
1941 |
}
|
|
1942 |
}) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null);
|
|
1943 |
|
|
1944 |
|
|
1945 |
/***/ }),
|
|
1946 |
|
19
|
1947 |
/***/ 5538:
|
|
1948 |
/***/ (function() {
|
|
1949 |
|
|
1950 |
/**
|
|
1951 |
* adds a bindGlobal method to Mousetrap that allows you to
|
|
1952 |
* bind specific keyboard shortcuts that will still work
|
|
1953 |
* inside a text input field
|
|
1954 |
*
|
|
1955 |
* usage:
|
|
1956 |
* Mousetrap.bindGlobal('ctrl+s', _saveChanges);
|
|
1957 |
*/
|
|
1958 |
/* global Mousetrap:true */
|
|
1959 |
(function(Mousetrap) {
|
|
1960 |
if (! Mousetrap) {
|
|
1961 |
return;
|
9
|
1962 |
}
|
19
|
1963 |
var _globalCallbacks = {};
|
|
1964 |
var _originalStopCallback = Mousetrap.prototype.stopCallback;
|
|
1965 |
|
|
1966 |
Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) {
|
|
1967 |
var self = this;
|
|
1968 |
|
|
1969 |
if (self.paused) {
|
|
1970 |
return true;
|
|
1971 |
}
|
|
1972 |
|
|
1973 |
if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
|
|
1974 |
return false;
|
|
1975 |
}
|
|
1976 |
|
|
1977 |
return _originalStopCallback.call(self, e, element, combo);
|
16
|
1978 |
};
|
19
|
1979 |
|
|
1980 |
Mousetrap.prototype.bindGlobal = function(keys, callback, action) {
|
|
1981 |
var self = this;
|
|
1982 |
self.bind(keys, callback, action);
|
|
1983 |
|
|
1984 |
if (keys instanceof Array) {
|
|
1985 |
for (var i = 0; i < keys.length; i++) {
|
|
1986 |
_globalCallbacks[keys[i]] = true;
|
|
1987 |
}
|
|
1988 |
return;
|
|
1989 |
}
|
|
1990 |
|
|
1991 |
_globalCallbacks[keys] = true;
|
|
1992 |
};
|
|
1993 |
|
|
1994 |
Mousetrap.init();
|
|
1995 |
}) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined);
|
9
|
1996 |
|
|
1997 |
|
|
1998 |
/***/ }),
|
|
1999 |
|
19
|
2000 |
/***/ 235:
|
|
2001 |
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
2002 |
|
|
2003 |
var e=__webpack_require__(9196),n={display:"block",opacity:0,position:"absolute",top:0,left:0,height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",zIndex:-1},t=function(t){var r=t.onResize,u=e.useRef();return function(n,t){var r=function(){return n.current&&n.current.contentDocument&&n.current.contentDocument.defaultView};function u(){t();var e=r();e&&e.addEventListener("resize",t)}e.useEffect((function(){return r()?u():n.current&&n.current.addEventListener&&n.current.addEventListener("load",u),function(){var e=r();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("resize",t)}}),[])}(u,(function(){return r(u)})),e.createElement("iframe",{style:n,src:"about:blank",ref:u,"aria-hidden":!0,tabIndex:-1,frameBorder:0})},r=function(e){return{width:null!=e?e.offsetWidth:null,height:null!=e?e.offsetHeight:null}};module.exports=function(n){void 0===n&&(n=r);var u=e.useState(n(null)),o=u[0],i=u[1],c=e.useCallback((function(e){return i(n(e.current))}),[n]);return[e.useMemo((function(){return e.createElement(t,{onResize:c})}),[c]),o]};
|
18
|
2004 |
|
|
2005 |
|
|
2006 |
/***/ }),
|
|
2007 |
|
19
|
2008 |
/***/ 9196:
|
18
|
2009 |
/***/ (function(module) {
|
|
2010 |
|
19
|
2011 |
"use strict";
|
|
2012 |
module.exports = window["React"];
|
18
|
2013 |
|
|
2014 |
/***/ })
|
|
2015 |
|
|
2016 |
/******/ });
|
|
2017 |
/************************************************************************/
|
|
2018 |
/******/ // The module cache
|
|
2019 |
/******/ var __webpack_module_cache__ = {};
|
|
2020 |
/******/
|
|
2021 |
/******/ // The require function
|
|
2022 |
/******/ function __webpack_require__(moduleId) {
|
|
2023 |
/******/ // Check if module is in cache
|
19
|
2024 |
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
2025 |
/******/ if (cachedModule !== undefined) {
|
|
2026 |
/******/ return cachedModule.exports;
|
18
|
2027 |
/******/ }
|
|
2028 |
/******/ // Create a new module (and put it into the cache)
|
|
2029 |
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
2030 |
/******/ // no module.id needed
|
|
2031 |
/******/ // no module.loaded needed
|
|
2032 |
/******/ exports: {}
|
|
2033 |
/******/ };
|
|
2034 |
/******/
|
|
2035 |
/******/ // Execute the module function
|
19
|
2036 |
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
18
|
2037 |
/******/
|
|
2038 |
/******/ // Return the exports of the module
|
|
2039 |
/******/ return module.exports;
|
|
2040 |
/******/ }
|
|
2041 |
/******/
|
|
2042 |
/************************************************************************/
|
|
2043 |
/******/ /* webpack/runtime/compat get default export */
|
|
2044 |
/******/ !function() {
|
|
2045 |
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
2046 |
/******/ __webpack_require__.n = function(module) {
|
|
2047 |
/******/ var getter = module && module.__esModule ?
|
|
2048 |
/******/ function() { return module['default']; } :
|
|
2049 |
/******/ function() { return module; };
|
|
2050 |
/******/ __webpack_require__.d(getter, { a: getter });
|
|
2051 |
/******/ return getter;
|
|
2052 |
/******/ };
|
|
2053 |
/******/ }();
|
|
2054 |
/******/
|
|
2055 |
/******/ /* webpack/runtime/define property getters */
|
|
2056 |
/******/ !function() {
|
|
2057 |
/******/ // define getter functions for harmony exports
|
|
2058 |
/******/ __webpack_require__.d = function(exports, definition) {
|
|
2059 |
/******/ for(var key in definition) {
|
|
2060 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
2061 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
2062 |
/******/ }
|
|
2063 |
/******/ }
|
|
2064 |
/******/ };
|
|
2065 |
/******/ }();
|
|
2066 |
/******/
|
|
2067 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
2068 |
/******/ !function() {
|
|
2069 |
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
|
|
2070 |
/******/ }();
|
|
2071 |
/******/
|
19
|
2072 |
/******/ /* webpack/runtime/make namespace object */
|
|
2073 |
/******/ !function() {
|
|
2074 |
/******/ // define __esModule on exports
|
|
2075 |
/******/ __webpack_require__.r = function(exports) {
|
|
2076 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
2077 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2078 |
/******/ }
|
|
2079 |
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
2080 |
/******/ };
|
|
2081 |
/******/ }();
|
|
2082 |
/******/
|
18
|
2083 |
/************************************************************************/
|
19
|
2084 |
var __webpack_exports__ = {};
|
|
2085 |
// This entry need to be wrapped in an IIFE because it need to be in strict mode.
|
|
2086 |
!function() {
|
|
2087 |
"use strict";
|
|
2088 |
// ESM COMPAT FLAG
|
|
2089 |
__webpack_require__.r(__webpack_exports__);
|
|
2090 |
|
|
2091 |
// EXPORTS
|
|
2092 |
__webpack_require__.d(__webpack_exports__, {
|
|
2093 |
"__experimentalUseDialog": function() { return /* reexport */ use_dialog; },
|
|
2094 |
"__experimentalUseDisabled": function() { return /* reexport */ useDisabled; },
|
|
2095 |
"__experimentalUseDragging": function() { return /* reexport */ useDragging; },
|
|
2096 |
"__experimentalUseDropZone": function() { return /* reexport */ useDropZone; },
|
|
2097 |
"__experimentalUseFixedWindowList": function() { return /* reexport */ useFixedWindowList; },
|
|
2098 |
"__experimentalUseFocusOutside": function() { return /* reexport */ useFocusOutside; },
|
|
2099 |
"compose": function() { return /* reexport */ compose; },
|
|
2100 |
"createHigherOrderComponent": function() { return /* reexport */ create_higher_order_component; },
|
|
2101 |
"ifCondition": function() { return /* reexport */ if_condition; },
|
|
2102 |
"pure": function() { return /* reexport */ higher_order_pure; },
|
|
2103 |
"useAsyncList": function() { return /* reexport */ use_async_list; },
|
|
2104 |
"useConstrainedTabbing": function() { return /* reexport */ use_constrained_tabbing; },
|
|
2105 |
"useCopyOnClick": function() { return /* reexport */ useCopyOnClick; },
|
|
2106 |
"useCopyToClipboard": function() { return /* reexport */ useCopyToClipboard; },
|
|
2107 |
"useDebounce": function() { return /* reexport */ useDebounce; },
|
|
2108 |
"useFocusOnMount": function() { return /* reexport */ useFocusOnMount; },
|
|
2109 |
"useFocusReturn": function() { return /* reexport */ use_focus_return; },
|
|
2110 |
"useFocusableIframe": function() { return /* reexport */ useFocusableIframe; },
|
|
2111 |
"useInstanceId": function() { return /* reexport */ useInstanceId; },
|
|
2112 |
"useIsomorphicLayoutEffect": function() { return /* reexport */ use_isomorphic_layout_effect; },
|
|
2113 |
"useKeyboardShortcut": function() { return /* reexport */ use_keyboard_shortcut; },
|
|
2114 |
"useMediaQuery": function() { return /* reexport */ useMediaQuery; },
|
|
2115 |
"useMergeRefs": function() { return /* reexport */ useMergeRefs; },
|
|
2116 |
"usePrevious": function() { return /* reexport */ usePrevious; },
|
|
2117 |
"useReducedMotion": function() { return /* reexport */ use_reduced_motion; },
|
|
2118 |
"useRefEffect": function() { return /* reexport */ useRefEffect; },
|
|
2119 |
"useResizeObserver": function() { return /* reexport */ use_resize_observer; },
|
|
2120 |
"useThrottle": function() { return /* reexport */ useThrottle; },
|
|
2121 |
"useViewportMatch": function() { return /* reexport */ use_viewport_match; },
|
|
2122 |
"useWarnOnChange": function() { return /* reexport */ use_warn_on_change; },
|
|
2123 |
"withGlobalEvents": function() { return /* reexport */ withGlobalEvents; },
|
|
2124 |
"withInstanceId": function() { return /* reexport */ with_instance_id; },
|
|
2125 |
"withSafeTimeout": function() { return /* reexport */ with_safe_timeout; },
|
|
2126 |
"withState": function() { return /* reexport */ withState; }
|
18
|
2127 |
});
|
|
2128 |
|
19
|
2129 |
;// CONCATENATED MODULE: external "lodash"
|
|
2130 |
var external_lodash_namespaceObject = window["lodash"];
|
|
2131 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/create-higher-order-component/index.js
|
|
2132 |
/**
|
|
2133 |
* External dependencies
|
|
2134 |
*/
|
|
2135 |
|
|
2136 |
|
|
2137 |
/**
|
|
2138 |
* Given a function mapping a component to an enhanced component and modifier
|
|
2139 |
* name, returns the enhanced component augmented with a generated displayName.
|
|
2140 |
*
|
|
2141 |
* @param mapComponent Function mapping component to enhanced component.
|
|
2142 |
* @param modifierName Seed name from which to generated display name.
|
|
2143 |
*
|
|
2144 |
* @return Component class with generated display name assigned.
|
|
2145 |
*/
|
|
2146 |
function createHigherOrderComponent(mapComponent, modifierName) {
|
|
2147 |
return Inner => {
|
|
2148 |
const Outer = mapComponent(Inner);
|
|
2149 |
const displayName = Inner.displayName || Inner.name || 'Component';
|
|
2150 |
Outer.displayName = `${(0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(modifierName))}(${displayName})`;
|
|
2151 |
return Outer;
|
|
2152 |
};
|
|
2153 |
}
|
|
2154 |
|
|
2155 |
/* harmony default export */ var create_higher_order_component = (createHigherOrderComponent);
|
|
2156 |
|
|
2157 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/compose.js
|
|
2158 |
/**
|
|
2159 |
* External dependencies
|
|
2160 |
*/
|
|
2161 |
|
|
2162 |
/**
|
|
2163 |
* Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
|
|
2164 |
* composition, where each successive invocation is supplied the return value of the previous.
|
|
2165 |
*
|
|
2166 |
* This is just a re-export of `lodash`'s `flowRight` function.
|
|
2167 |
*
|
|
2168 |
* @see https://docs-lodash.com/v4/flow-right/
|
|
2169 |
*/
|
|
2170 |
|
|
2171 |
/* harmony default export */ var compose = (external_lodash_namespaceObject.flowRight);
|
|
2172 |
|
|
2173 |
;// CONCATENATED MODULE: external ["wp","element"]
|
|
2174 |
var external_wp_element_namespaceObject = window["wp"]["element"];
|
|
2175 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/if-condition/index.js
|
|
2176 |
|
|
2177 |
|
|
2178 |
/**
|
|
2179 |
* Internal dependencies
|
|
2180 |
*/
|
|
2181 |
|
|
2182 |
/**
|
|
2183 |
* Higher-order component creator, creating a new component which renders if
|
|
2184 |
* the given condition is satisfied or with the given optional prop name.
|
|
2185 |
*
|
|
2186 |
* @example
|
|
2187 |
* ```ts
|
|
2188 |
* type Props = { foo: string };
|
|
2189 |
* const Component = ( props: Props ) => <div>{ props.foo }</div>;
|
|
2190 |
* const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );
|
|
2191 |
* <ConditionalComponent foo="" />; // => null
|
|
2192 |
* <ConditionalComponent foo="bar" />; // => <div>bar</div>;
|
|
2193 |
* ```
|
|
2194 |
*
|
|
2195 |
* @param predicate Function to test condition.
|
|
2196 |
*
|
|
2197 |
* @return Higher-order component.
|
|
2198 |
*/
|
|
2199 |
|
|
2200 |
const ifCondition = predicate => create_higher_order_component(WrappedComponent => props => {
|
|
2201 |
if (!predicate(props)) {
|
|
2202 |
return null;
|
|
2203 |
}
|
|
2204 |
|
|
2205 |
return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, props);
|
|
2206 |
}, 'ifCondition');
|
|
2207 |
|
|
2208 |
/* harmony default export */ var if_condition = (ifCondition);
|
|
2209 |
|
|
2210 |
;// CONCATENATED MODULE: external ["wp","isShallowEqual"]
|
|
2211 |
var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
|
|
2212 |
var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
|
|
2213 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pure/index.js
|
|
2214 |
|
|
2215 |
|
|
2216 |
/**
|
|
2217 |
* WordPress dependencies
|
|
2218 |
*/
|
|
2219 |
|
|
2220 |
|
|
2221 |
/**
|
|
2222 |
* Internal dependencies
|
|
2223 |
*/
|
|
2224 |
|
|
2225 |
|
|
2226 |
/**
|
|
2227 |
* External dependencies
|
|
2228 |
*/
|
|
2229 |
|
|
2230 |
/**
|
|
2231 |
* Given a component returns the enhanced component augmented with a component
|
|
2232 |
* only re-rendering when its props/state change
|
|
2233 |
*/
|
|
2234 |
const pure = create_higher_order_component(Wrapped => {
|
|
2235 |
if (Wrapped.prototype instanceof external_wp_element_namespaceObject.Component) {
|
|
2236 |
return class extends Wrapped {
|
|
2237 |
shouldComponentUpdate(nextProps, nextState) {
|
|
2238 |
return !external_wp_isShallowEqual_default()(nextProps, this.props) || !external_wp_isShallowEqual_default()(nextState, this.state);
|
|
2239 |
}
|
|
2240 |
|
|
2241 |
};
|
|
2242 |
}
|
|
2243 |
|
|
2244 |
return class extends external_wp_element_namespaceObject.Component {
|
|
2245 |
shouldComponentUpdate(nextProps) {
|
|
2246 |
return !external_wp_isShallowEqual_default()(nextProps, this.props);
|
|
2247 |
}
|
|
2248 |
|
|
2249 |
render() {
|
|
2250 |
return (0,external_wp_element_namespaceObject.createElement)(Wrapped, this.props);
|
|
2251 |
}
|
|
2252 |
|
|
2253 |
};
|
|
2254 |
}, 'pure');
|
|
2255 |
/* harmony default export */ var higher_order_pure = (pure);
|
|
2256 |
|
|
2257 |
;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
|
16
|
2258 |
function _extends() {
|
19
|
2259 |
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
16
|
2260 |
for (var i = 1; i < arguments.length; i++) {
|
|
2261 |
var source = arguments[i];
|
|
2262 |
|
|
2263 |
for (var key in source) {
|
|
2264 |
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
2265 |
target[key] = source[key];
|
|
2266 |
}
|
|
2267 |
}
|
|
2268 |
}
|
|
2269 |
|
|
2270 |
return target;
|
|
2271 |
};
|
|
2272 |
return _extends.apply(this, arguments);
|
9
|
2273 |
}
|
19
|
2274 |
;// CONCATENATED MODULE: external ["wp","deprecated"]
|
|
2275 |
var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
|
|
2276 |
var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
|
|
2277 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/listener.js
|
|
2278 |
/**
|
|
2279 |
* External dependencies
|
|
2280 |
*/
|
|
2281 |
|
|
2282 |
/**
|
|
2283 |
* Class responsible for orchestrating event handling on the global window,
|
|
2284 |
* binding a single event to be shared across all handling instances, and
|
|
2285 |
* removing the handler when no instances are listening for the event.
|
|
2286 |
*/
|
|
2287 |
|
|
2288 |
class Listener {
|
|
2289 |
constructor() {
|
|
2290 |
/** @type {any} */
|
|
2291 |
this.listeners = {};
|
|
2292 |
this.handleEvent = this.handleEvent.bind(this);
|
|
2293 |
}
|
|
2294 |
|
|
2295 |
add(
|
|
2296 |
/** @type {any} */
|
|
2297 |
eventType,
|
|
2298 |
/** @type {any} */
|
|
2299 |
instance) {
|
|
2300 |
if (!this.listeners[eventType]) {
|
|
2301 |
// Adding first listener for this type, so bind event.
|
|
2302 |
window.addEventListener(eventType, this.handleEvent);
|
|
2303 |
this.listeners[eventType] = [];
|
|
2304 |
}
|
|
2305 |
|
|
2306 |
this.listeners[eventType].push(instance);
|
|
2307 |
}
|
|
2308 |
|
|
2309 |
remove(
|
|
2310 |
/** @type {any} */
|
|
2311 |
eventType,
|
|
2312 |
/** @type {any} */
|
|
2313 |
instance) {
|
|
2314 |
this.listeners[eventType] = (0,external_lodash_namespaceObject.without)(this.listeners[eventType], instance);
|
|
2315 |
|
|
2316 |
if (!this.listeners[eventType].length) {
|
|
2317 |
// Removing last listener for this type, so unbind event.
|
|
2318 |
window.removeEventListener(eventType, this.handleEvent);
|
|
2319 |
delete this.listeners[eventType];
|
|
2320 |
}
|
|
2321 |
}
|
|
2322 |
|
|
2323 |
handleEvent(
|
|
2324 |
/** @type {any} */
|
|
2325 |
event) {
|
|
2326 |
(0,external_lodash_namespaceObject.forEach)(this.listeners[event.type], instance => {
|
|
2327 |
instance.handleEvent(event);
|
|
2328 |
});
|
|
2329 |
}
|
|
2330 |
|
|
2331 |
}
|
|
2332 |
|
|
2333 |
/* harmony default export */ var listener = (Listener);
|
|
2334 |
|
|
2335 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js
|
|
2336 |
|
|
2337 |
|
|
2338 |
|
|
2339 |
/**
|
|
2340 |
* External dependencies
|
|
2341 |
*/
|
|
2342 |
|
|
2343 |
/**
|
|
2344 |
* WordPress dependencies
|
|
2345 |
*/
|
|
2346 |
|
|
2347 |
|
|
2348 |
|
|
2349 |
/**
|
|
2350 |
* Internal dependencies
|
|
2351 |
*/
|
|
2352 |
|
|
2353 |
|
|
2354 |
|
|
2355 |
/**
|
|
2356 |
* Listener instance responsible for managing document event handling.
|
|
2357 |
*/
|
|
2358 |
|
|
2359 |
const with_global_events_listener = new listener();
|
|
2360 |
/* eslint-disable jsdoc/no-undefined-types */
|
|
2361 |
|
|
2362 |
/**
|
|
2363 |
* Higher-order component creator which, given an object of DOM event types and
|
|
2364 |
* values corresponding to a callback function name on the component, will
|
|
2365 |
* create or update a window event handler to invoke the callback when an event
|
|
2366 |
* occurs. On behalf of the consuming developer, the higher-order component
|
|
2367 |
* manages unbinding when the component unmounts, and binding at most a single
|
|
2368 |
* event handler for the entire application.
|
|
2369 |
*
|
|
2370 |
* @deprecated
|
|
2371 |
*
|
|
2372 |
* @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM
|
|
2373 |
* event type, the value a
|
|
2374 |
* name of the function on
|
|
2375 |
* the original component's
|
|
2376 |
* instance which handles
|
|
2377 |
* the event.
|
|
2378 |
*
|
|
2379 |
* @return {any} Higher-order component.
|
|
2380 |
*/
|
|
2381 |
|
|
2382 |
function withGlobalEvents(eventTypesToHandlers) {
|
|
2383 |
external_wp_deprecated_default()('wp.compose.withGlobalEvents', {
|
|
2384 |
since: '5.7',
|
|
2385 |
alternative: 'useEffect'
|
|
2386 |
}); // @ts-ignore We don't need to fix the type-related issues because this is deprecated.
|
|
2387 |
|
|
2388 |
return create_higher_order_component(WrappedComponent => {
|
|
2389 |
class Wrapper extends external_wp_element_namespaceObject.Component {
|
|
2390 |
constructor(
|
|
2391 |
/** @type {any} */
|
|
2392 |
props) {
|
|
2393 |
super(props);
|
|
2394 |
this.handleEvent = this.handleEvent.bind(this);
|
|
2395 |
this.handleRef = this.handleRef.bind(this);
|
|
2396 |
}
|
|
2397 |
|
|
2398 |
componentDidMount() {
|
|
2399 |
(0,external_lodash_namespaceObject.forEach)(eventTypesToHandlers, (_, eventType) => {
|
|
2400 |
with_global_events_listener.add(eventType, this);
|
|
2401 |
});
|
|
2402 |
}
|
|
2403 |
|
|
2404 |
componentWillUnmount() {
|
|
2405 |
(0,external_lodash_namespaceObject.forEach)(eventTypesToHandlers, (_, eventType) => {
|
|
2406 |
with_global_events_listener.remove(eventType, this);
|
|
2407 |
});
|
|
2408 |
}
|
|
2409 |
|
|
2410 |
handleEvent(
|
|
2411 |
/** @type {any} */
|
|
2412 |
event) {
|
|
2413 |
const handler = eventTypesToHandlers[
|
|
2414 |
/** @type {keyof GlobalEventHandlersEventMap} */
|
|
2415 |
event.type
|
|
2416 |
/* eslint-enable jsdoc/no-undefined-types */
|
|
2417 |
];
|
|
2418 |
|
|
2419 |
if (typeof this.wrappedRef[handler] === 'function') {
|
|
2420 |
this.wrappedRef[handler](event);
|
|
2421 |
}
|
|
2422 |
}
|
|
2423 |
|
|
2424 |
handleRef(
|
|
2425 |
/** @type {any} */
|
|
2426 |
el) {
|
|
2427 |
this.wrappedRef = el; // Any component using `withGlobalEvents` that is not setting a `ref`
|
|
2428 |
// will cause `this.props.forwardedRef` to be `null`, so we need this
|
|
2429 |
// check.
|
|
2430 |
|
|
2431 |
if (this.props.forwardedRef) {
|
|
2432 |
this.props.forwardedRef(el);
|
|
2433 |
}
|
|
2434 |
}
|
|
2435 |
|
|
2436 |
render() {
|
|
2437 |
return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, this.props.ownProps, {
|
|
2438 |
ref: this.handleRef
|
|
2439 |
}));
|
|
2440 |
}
|
|
2441 |
|
|
2442 |
}
|
|
2443 |
|
|
2444 |
return (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => {
|
|
2445 |
return (0,external_wp_element_namespaceObject.createElement)(Wrapper, {
|
|
2446 |
ownProps: props,
|
|
2447 |
forwardedRef: ref
|
|
2448 |
});
|
|
2449 |
});
|
|
2450 |
}, 'withGlobalEvents');
|
|
2451 |
}
|
|
2452 |
|
|
2453 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-instance-id/index.js
|
|
2454 |
// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case
|
|
2455 |
// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
|
|
2456 |
|
|
2457 |
/* eslint-disable jsdoc/check-types */
|
|
2458 |
|
|
2459 |
/**
|
|
2460 |
* WordPress dependencies
|
|
2461 |
*/
|
|
2462 |
|
|
2463 |
/**
|
|
2464 |
* @type {WeakMap<object, number>}
|
|
2465 |
*/
|
|
2466 |
|
|
2467 |
const instanceMap = new WeakMap();
|
|
2468 |
/**
|
|
2469 |
* Creates a new id for a given object.
|
|
2470 |
*
|
|
2471 |
* @param {object} object Object reference to create an id for.
|
|
2472 |
* @return {number} The instance id (index).
|
|
2473 |
*/
|
|
2474 |
|
|
2475 |
function createId(object) {
|
|
2476 |
const instances = instanceMap.get(object) || 0;
|
|
2477 |
instanceMap.set(object, instances + 1);
|
|
2478 |
return instances;
|
|
2479 |
}
|
|
2480 |
/**
|
|
2481 |
* Provides a unique instance ID.
|
|
2482 |
*
|
|
2483 |
* @param {object} object Object reference to create an id for.
|
|
2484 |
* @param {string} [prefix] Prefix for the unique id.
|
|
2485 |
* @param {string | number} [preferredId=''] Default ID to use.
|
|
2486 |
* @return {string | number} The unique instance id.
|
|
2487 |
*/
|
|
2488 |
|
|
2489 |
|
|
2490 |
function useInstanceId(object, prefix) {
|
|
2491 |
let preferredId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
|
|
2492 |
return (0,external_wp_element_namespaceObject.useMemo)(() => {
|
|
2493 |
if (preferredId) return preferredId;
|
|
2494 |
const id = createId(object);
|
|
2495 |
return prefix ? `${prefix}-${id}` : id;
|
|
2496 |
}, [object]);
|
|
2497 |
}
|
|
2498 |
/* eslint-enable jsdoc/check-types */
|
|
2499 |
|
|
2500 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js
|
|
2501 |
|
|
2502 |
|
|
2503 |
|
|
2504 |
/**
|
|
2505 |
* Internal dependencies
|
|
2506 |
*/
|
|
2507 |
|
|
2508 |
|
|
2509 |
/**
|
|
2510 |
* A Higher Order Component used to be provide a unique instance ID by
|
|
2511 |
* component.
|
|
2512 |
*/
|
|
2513 |
|
|
2514 |
const withInstanceId = create_higher_order_component(WrappedComponent => {
|
|
2515 |
return props => {
|
|
2516 |
const instanceId = useInstanceId(WrappedComponent); // @ts-ignore
|
|
2517 |
|
|
2518 |
return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, props, {
|
|
2519 |
instanceId: instanceId
|
|
2520 |
}));
|
|
2521 |
};
|
|
2522 |
}, 'withInstanceId');
|
|
2523 |
/* harmony default export */ var with_instance_id = (withInstanceId);
|
|
2524 |
|
|
2525 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js
|
|
2526 |
|
|
2527 |
|
|
2528 |
/**
|
|
2529 |
* External dependencies
|
|
2530 |
*/
|
|
2531 |
|
|
2532 |
|
|
2533 |
/**
|
|
2534 |
* WordPress dependencies
|
|
2535 |
*/
|
|
2536 |
|
|
2537 |
/**
|
|
2538 |
* Internal dependencies
|
|
2539 |
*/
|
|
2540 |
|
|
2541 |
|
|
2542 |
/**
|
|
2543 |
* We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
|
|
2544 |
* types here because those functions include functionality that is not handled
|
|
2545 |
* by this component, like the ability to pass extra arguments.
|
|
2546 |
*
|
|
2547 |
* In the case of this component, we only handle the simplest case where
|
|
2548 |
* `setTimeout` only accepts a function (not a string) and an optional delay.
|
|
2549 |
*/
|
|
2550 |
|
|
2551 |
/**
|
|
2552 |
* A higher-order component used to provide and manage delayed function calls
|
|
2553 |
* that ought to be bound to a component's lifecycle.
|
|
2554 |
*/
|
|
2555 |
const withSafeTimeout = create_higher_order_component(OriginalComponent => {
|
|
2556 |
return class WrappedComponent extends external_wp_element_namespaceObject.Component {
|
|
2557 |
constructor(props) {
|
|
2558 |
super(props);
|
|
2559 |
this.timeouts = [];
|
|
2560 |
this.setTimeout = this.setTimeout.bind(this);
|
|
2561 |
this.clearTimeout = this.clearTimeout.bind(this);
|
|
2562 |
}
|
|
2563 |
|
|
2564 |
componentWillUnmount() {
|
|
2565 |
this.timeouts.forEach(clearTimeout);
|
|
2566 |
}
|
|
2567 |
|
|
2568 |
setTimeout(fn, delay) {
|
|
2569 |
const id = setTimeout(() => {
|
|
2570 |
fn();
|
|
2571 |
this.clearTimeout(id);
|
|
2572 |
}, delay);
|
|
2573 |
this.timeouts.push(id);
|
|
2574 |
return id;
|
|
2575 |
}
|
|
2576 |
|
|
2577 |
clearTimeout(id) {
|
|
2578 |
clearTimeout(id);
|
|
2579 |
this.timeouts = (0,external_lodash_namespaceObject.without)(this.timeouts, id);
|
|
2580 |
}
|
|
2581 |
|
|
2582 |
render() {
|
|
2583 |
const props = { ...this.props,
|
|
2584 |
setTimeout: this.setTimeout,
|
|
2585 |
clearTimeout: this.clearTimeout
|
|
2586 |
};
|
|
2587 |
return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, props);
|
|
2588 |
}
|
|
2589 |
|
|
2590 |
};
|
|
2591 |
}, 'withSafeTimeout');
|
|
2592 |
/* harmony default export */ var with_safe_timeout = (withSafeTimeout);
|
|
2593 |
|
|
2594 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js
|
|
2595 |
|
|
2596 |
|
|
2597 |
|
|
2598 |
/**
|
|
2599 |
* WordPress dependencies
|
|
2600 |
*/
|
|
2601 |
|
|
2602 |
|
|
2603 |
/**
|
|
2604 |
* Internal dependencies
|
|
2605 |
*/
|
|
2606 |
|
|
2607 |
|
|
2608 |
/**
|
|
2609 |
* A Higher Order Component used to provide and manage internal component state
|
|
2610 |
* via props.
|
|
2611 |
*
|
|
2612 |
* @deprecated Use `useState` instead.
|
|
2613 |
*
|
|
2614 |
* @param {any} initialState Optional initial state of the component.
|
|
2615 |
*
|
|
2616 |
* @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.
|
|
2617 |
*/
|
|
2618 |
|
|
2619 |
function withState() {
|
|
2620 |
let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
2621 |
external_wp_deprecated_default()('wp.compose.withState', {
|
|
2622 |
since: '5.8',
|
|
2623 |
alternative: 'wp.element.useState'
|
|
2624 |
});
|
|
2625 |
return create_higher_order_component(OriginalComponent => {
|
|
2626 |
return class WrappedComponent extends external_wp_element_namespaceObject.Component {
|
|
2627 |
constructor(
|
|
2628 |
/** @type {any} */
|
|
2629 |
props) {
|
|
2630 |
super(props);
|
|
2631 |
this.setState = this.setState.bind(this);
|
|
2632 |
this.state = initialState;
|
|
2633 |
}
|
|
2634 |
|
|
2635 |
render() {
|
|
2636 |
return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, this.props, this.state, {
|
|
2637 |
setState: this.setState
|
|
2638 |
}));
|
|
2639 |
}
|
|
2640 |
|
|
2641 |
};
|
|
2642 |
}, 'withState');
|
|
2643 |
}
|
|
2644 |
|
|
2645 |
;// CONCATENATED MODULE: external ["wp","keycodes"]
|
|
2646 |
var external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
|
|
2647 |
;// CONCATENATED MODULE: external ["wp","dom"]
|
|
2648 |
var external_wp_dom_namespaceObject = window["wp"]["dom"];
|
|
2649 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-ref-effect/index.js
|
|
2650 |
/**
|
|
2651 |
* External dependencies
|
|
2652 |
*/
|
|
2653 |
|
|
2654 |
/**
|
|
2655 |
* WordPress dependencies
|
|
2656 |
*/
|
|
2657 |
|
|
2658 |
/**
|
|
2659 |
* Effect-like ref callback. Just like with `useEffect`, this allows you to
|
|
2660 |
* return a cleanup function to be run if the ref changes or one of the
|
|
2661 |
* dependencies changes. The ref is provided as an argument to the callback
|
|
2662 |
* functions. The main difference between this and `useEffect` is that
|
|
2663 |
* the `useEffect` callback is not called when the ref changes, but this is.
|
|
2664 |
* Pass the returned ref callback as the component's ref and merge multiple refs
|
|
2665 |
* with `useMergeRefs`.
|
|
2666 |
*
|
|
2667 |
* It's worth noting that if the dependencies array is empty, there's not
|
|
2668 |
* strictly a need to clean up event handlers for example, because the node is
|
|
2669 |
* to be removed. It *is* necessary if you add dependencies because the ref
|
|
2670 |
* callback will be called multiple times for the same node.
|
|
2671 |
*
|
|
2672 |
* @param callback Callback with ref as argument.
|
|
2673 |
* @param dependencies Dependencies of the callback.
|
|
2674 |
*
|
|
2675 |
* @return Ref callback.
|
|
2676 |
*/
|
|
2677 |
|
|
2678 |
function useRefEffect(callback, dependencies) {
|
|
2679 |
const cleanup = (0,external_wp_element_namespaceObject.useRef)();
|
|
2680 |
return (0,external_wp_element_namespaceObject.useCallback)(node => {
|
|
2681 |
if (node) {
|
|
2682 |
cleanup.current = callback(node);
|
|
2683 |
} else if (cleanup.current) {
|
|
2684 |
cleanup.current();
|
|
2685 |
}
|
|
2686 |
}, dependencies);
|
|
2687 |
}
|
|
2688 |
|
|
2689 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-constrained-tabbing/index.js
|
|
2690 |
/**
|
|
2691 |
* WordPress dependencies
|
|
2692 |
*/
|
|
2693 |
|
|
2694 |
|
|
2695 |
/**
|
|
2696 |
* Internal dependencies
|
|
2697 |
*/
|
|
2698 |
|
|
2699 |
|
|
2700 |
/**
|
|
2701 |
* In Dialogs/modals, the tabbing must be constrained to the content of
|
|
2702 |
* the wrapper element. This hook adds the behavior to the returned ref.
|
|
2703 |
*
|
|
2704 |
* @return {import('react').RefCallback<Element>} Element Ref.
|
|
2705 |
*
|
|
2706 |
* @example
|
|
2707 |
* ```js
|
|
2708 |
* import { useConstrainedTabbing } from '@wordpress/compose';
|
|
2709 |
*
|
|
2710 |
* const ConstrainedTabbingExample = () => {
|
|
2711 |
* const constrainedTabbingRef = useConstrainedTabbing()
|
|
2712 |
* return (
|
|
2713 |
* <div ref={ constrainedTabbingRef }>
|
|
2714 |
* <Button />
|
|
2715 |
* <Button />
|
|
2716 |
* </div>
|
|
2717 |
* );
|
|
2718 |
* }
|
|
2719 |
* ```
|
|
2720 |
*/
|
|
2721 |
|
|
2722 |
function useConstrainedTabbing() {
|
|
2723 |
return useRefEffect((
|
|
2724 |
/** @type {HTMLElement} */
|
|
2725 |
node) => {
|
|
2726 |
/** @type {number|undefined} */
|
|
2727 |
let timeoutId;
|
|
2728 |
|
|
2729 |
function onKeyDown(
|
|
2730 |
/** @type {KeyboardEvent} */
|
|
2731 |
event) {
|
|
2732 |
const {
|
|
2733 |
keyCode,
|
|
2734 |
shiftKey,
|
|
2735 |
target
|
|
2736 |
} = event;
|
|
2737 |
|
|
2738 |
if (keyCode !== external_wp_keycodes_namespaceObject.TAB) {
|
|
2739 |
return;
|
|
2740 |
}
|
|
2741 |
|
|
2742 |
const action = shiftKey ? 'findPrevious' : 'findNext';
|
|
2743 |
const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action](
|
|
2744 |
/** @type {HTMLElement} */
|
|
2745 |
target) || null; // If the element that is about to receive focus is outside the
|
|
2746 |
// area, move focus to a div and insert it at the start or end of
|
|
2747 |
// the area, depending on the direction. Without preventing default
|
|
2748 |
// behaviour, the browser will then move focus to the next element.
|
|
2749 |
|
|
2750 |
if (node.contains(nextElement)) {
|
|
2751 |
return;
|
|
2752 |
}
|
|
2753 |
|
|
2754 |
const domAction = shiftKey ? 'append' : 'prepend';
|
|
2755 |
const {
|
|
2756 |
ownerDocument
|
|
2757 |
} = node;
|
|
2758 |
const trap = ownerDocument.createElement('div');
|
|
2759 |
trap.tabIndex = -1;
|
|
2760 |
node[domAction](trap);
|
|
2761 |
trap.focus(); // Remove after the browser moves focus to the next element.
|
|
2762 |
|
|
2763 |
timeoutId = setTimeout(() => node.removeChild(trap));
|
|
2764 |
}
|
|
2765 |
|
|
2766 |
node.addEventListener('keydown', onKeyDown);
|
|
2767 |
return () => {
|
|
2768 |
node.removeEventListener('keydown', onKeyDown);
|
|
2769 |
clearTimeout(timeoutId);
|
|
2770 |
};
|
|
2771 |
}, []);
|
|
2772 |
}
|
|
2773 |
|
|
2774 |
/* harmony default export */ var use_constrained_tabbing = (useConstrainedTabbing);
|
|
2775 |
|
|
2776 |
// EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js
|
|
2777 |
var dist_clipboard = __webpack_require__(8294);
|
|
2778 |
var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard);
|
|
2779 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-on-click/index.js
|
|
2780 |
/**
|
|
2781 |
* External dependencies
|
|
2782 |
*/
|
|
2783 |
|
|
2784 |
/**
|
|
2785 |
* WordPress dependencies
|
|
2786 |
*/
|
|
2787 |
|
|
2788 |
|
|
2789 |
|
|
2790 |
/* eslint-disable jsdoc/no-undefined-types */
|
|
2791 |
|
|
2792 |
/**
|
|
2793 |
* Copies the text to the clipboard when the element is clicked.
|
|
2794 |
*
|
|
2795 |
* @deprecated
|
|
2796 |
*
|
|
2797 |
* @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.
|
|
2798 |
* @param {string|Function} text The text to copy.
|
|
2799 |
* @param {number} [timeout] Optional timeout to reset the returned
|
|
2800 |
* state. 4 seconds by default.
|
|
2801 |
*
|
|
2802 |
* @return {boolean} Whether or not the text has been copied. Resets after the
|
|
2803 |
* timeout.
|
|
2804 |
*/
|
|
2805 |
|
|
2806 |
function useCopyOnClick(ref, text) {
|
|
2807 |
let timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4000;
|
|
2808 |
|
|
2809 |
/* eslint-enable jsdoc/no-undefined-types */
|
|
2810 |
external_wp_deprecated_default()('wp.compose.useCopyOnClick', {
|
|
2811 |
since: '5.8',
|
|
2812 |
alternative: 'wp.compose.useCopyToClipboard'
|
|
2813 |
});
|
|
2814 |
/** @type {import('react').MutableRefObject<Clipboard | undefined>} */
|
|
2815 |
|
|
2816 |
const clipboard = (0,external_wp_element_namespaceObject.useRef)();
|
|
2817 |
const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false);
|
|
2818 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
2819 |
/** @type {number | undefined} */
|
|
2820 |
let timeoutId;
|
|
2821 |
|
|
2822 |
if (!ref.current) {
|
|
2823 |
return;
|
|
2824 |
} // Clipboard listens to click events.
|
|
2825 |
|
|
2826 |
|
|
2827 |
clipboard.current = new (clipboard_default())(ref.current, {
|
|
2828 |
text: () => typeof text === 'function' ? text() : text
|
|
2829 |
});
|
|
2830 |
clipboard.current.on('success', _ref => {
|
|
2831 |
let {
|
|
2832 |
clearSelection,
|
|
2833 |
trigger
|
|
2834 |
} = _ref;
|
|
2835 |
// Clearing selection will move focus back to the triggering button,
|
|
2836 |
// ensuring that it is not reset to the body, and further that it is
|
|
2837 |
// kept within the rendered node.
|
|
2838 |
clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
|
|
2839 |
|
|
2840 |
if (trigger) {
|
|
2841 |
/** @type {HTMLElement} */
|
|
2842 |
trigger.focus();
|
|
2843 |
}
|
|
2844 |
|
|
2845 |
if (timeout) {
|
|
2846 |
setHasCopied(true);
|
|
2847 |
clearTimeout(timeoutId);
|
|
2848 |
timeoutId = setTimeout(() => setHasCopied(false), timeout);
|
|
2849 |
}
|
|
2850 |
});
|
|
2851 |
return () => {
|
|
2852 |
if (clipboard.current) {
|
|
2853 |
clipboard.current.destroy();
|
|
2854 |
}
|
|
2855 |
|
|
2856 |
clearTimeout(timeoutId);
|
|
2857 |
};
|
|
2858 |
}, [text, timeout, setHasCopied]);
|
|
2859 |
return hasCopied;
|
|
2860 |
}
|
|
2861 |
|
|
2862 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-to-clipboard/index.js
|
|
2863 |
/**
|
|
2864 |
* External dependencies
|
|
2865 |
*/
|
|
2866 |
|
|
2867 |
/**
|
|
2868 |
* WordPress dependencies
|
|
2869 |
*/
|
|
2870 |
|
|
2871 |
|
|
2872 |
/**
|
|
2873 |
* Internal dependencies
|
|
2874 |
*/
|
|
2875 |
|
|
2876 |
|
|
2877 |
/**
|
|
2878 |
* @template T
|
|
2879 |
* @param {T} value
|
|
2880 |
* @return {import('react').RefObject<T>} The updated ref
|
|
2881 |
*/
|
|
2882 |
|
|
2883 |
function useUpdatedRef(value) {
|
|
2884 |
const ref = (0,external_wp_element_namespaceObject.useRef)(value);
|
|
2885 |
ref.current = value;
|
|
2886 |
return ref;
|
|
2887 |
}
|
|
2888 |
/**
|
|
2889 |
* Copies the given text to the clipboard when the element is clicked.
|
|
2890 |
*
|
|
2891 |
* @template {HTMLElement} TElementType
|
|
2892 |
* @param {string | (() => string)} text The text to copy. Use a function if not
|
|
2893 |
* already available and expensive to compute.
|
|
2894 |
* @param {Function} onSuccess Called when to text is copied.
|
|
2895 |
*
|
|
2896 |
* @return {import('react').Ref<TElementType>} A ref to assign to the target element.
|
|
2897 |
*/
|
|
2898 |
|
|
2899 |
|
|
2900 |
function useCopyToClipboard(text, onSuccess) {
|
|
2901 |
// Store the dependencies as refs and continuesly update them so they're
|
|
2902 |
// fresh when the callback is called.
|
|
2903 |
const textRef = useUpdatedRef(text);
|
|
2904 |
const onSuccessRef = useUpdatedRef(onSuccess);
|
|
2905 |
return useRefEffect(node => {
|
|
2906 |
// Clipboard listens to click events.
|
|
2907 |
const clipboard = new (clipboard_default())(node, {
|
|
2908 |
text() {
|
|
2909 |
return typeof textRef.current === 'function' ? textRef.current() : textRef.current || '';
|
|
2910 |
}
|
|
2911 |
|
|
2912 |
});
|
|
2913 |
clipboard.on('success', _ref => {
|
|
2914 |
let {
|
|
2915 |
clearSelection
|
|
2916 |
} = _ref;
|
|
2917 |
// Clearing selection will move focus back to the triggering
|
|
2918 |
// button, ensuring that it is not reset to the body, and
|
|
2919 |
// further that it is kept within the rendered node.
|
|
2920 |
clearSelection(); // Handle ClipboardJS focus bug, see
|
|
2921 |
// https://github.com/zenorocha/clipboard.js/issues/680
|
|
2922 |
|
|
2923 |
node.focus();
|
|
2924 |
|
|
2925 |
if (onSuccessRef.current) {
|
|
2926 |
onSuccessRef.current();
|
|
2927 |
}
|
|
2928 |
});
|
|
2929 |
return () => {
|
|
2930 |
clipboard.destroy();
|
|
2931 |
};
|
|
2932 |
}, []);
|
|
2933 |
}
|
|
2934 |
|
|
2935 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-on-mount/index.js
|
|
2936 |
/**
|
|
2937 |
* WordPress dependencies
|
|
2938 |
*/
|
|
2939 |
|
|
2940 |
|
|
2941 |
/**
|
|
2942 |
* Hook used to focus the first tabbable element on mount.
|
|
2943 |
*
|
|
2944 |
* @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.
|
|
2945 |
* @return {import('react').RefCallback<HTMLElement>} Ref callback.
|
|
2946 |
*
|
|
2947 |
* @example
|
|
2948 |
* ```js
|
|
2949 |
* import { useFocusOnMount } from '@wordpress/compose';
|
|
2950 |
*
|
|
2951 |
* const WithFocusOnMount = () => {
|
|
2952 |
* const ref = useFocusOnMount()
|
|
2953 |
* return (
|
|
2954 |
* <div ref={ ref }>
|
|
2955 |
* <Button />
|
|
2956 |
* <Button />
|
|
2957 |
* </div>
|
|
2958 |
* );
|
|
2959 |
* }
|
|
2960 |
* ```
|
|
2961 |
*/
|
|
2962 |
|
|
2963 |
function useFocusOnMount() {
|
|
2964 |
let focusOnMount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'firstElement';
|
|
2965 |
const focusOnMountRef = (0,external_wp_element_namespaceObject.useRef)(focusOnMount);
|
|
2966 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
2967 |
focusOnMountRef.current = focusOnMount;
|
|
2968 |
}, [focusOnMount]);
|
|
2969 |
return (0,external_wp_element_namespaceObject.useCallback)(node => {
|
|
2970 |
var _node$ownerDocument$a, _node$ownerDocument;
|
|
2971 |
|
|
2972 |
if (!node || focusOnMountRef.current === false) {
|
|
2973 |
return;
|
|
2974 |
}
|
|
2975 |
|
|
2976 |
if (node.contains((_node$ownerDocument$a = (_node$ownerDocument = node.ownerDocument) === null || _node$ownerDocument === void 0 ? void 0 : _node$ownerDocument.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) {
|
|
2977 |
return;
|
|
2978 |
}
|
|
2979 |
|
|
2980 |
let target = node;
|
|
2981 |
|
|
2982 |
if (focusOnMountRef.current === 'firstElement') {
|
|
2983 |
const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0];
|
|
2984 |
|
|
2985 |
if (firstTabbable) {
|
|
2986 |
target =
|
|
2987 |
/** @type {HTMLElement} */
|
|
2988 |
firstTabbable;
|
|
2989 |
}
|
|
2990 |
}
|
|
2991 |
|
|
2992 |
target.focus();
|
|
2993 |
}, []);
|
|
2994 |
}
|
|
2995 |
|
|
2996 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-return/index.js
|
|
2997 |
/**
|
|
2998 |
* WordPress dependencies
|
|
2999 |
*/
|
|
3000 |
|
|
3001 |
/**
|
|
3002 |
* When opening modals/sidebars/dialogs, the focus
|
|
3003 |
* must move to the opened area and return to the
|
|
3004 |
* previously focused element when closed.
|
|
3005 |
* The current hook implements the returning behavior.
|
|
3006 |
*
|
|
3007 |
* @param {() => void} [onFocusReturn] Overrides the default return behavior.
|
|
3008 |
* @return {import('react').RefCallback<HTMLElement>} Element Ref.
|
|
3009 |
*
|
|
3010 |
* @example
|
|
3011 |
* ```js
|
|
3012 |
* import { useFocusReturn } from '@wordpress/compose';
|
|
3013 |
*
|
|
3014 |
* const WithFocusReturn = () => {
|
|
3015 |
* const ref = useFocusReturn()
|
|
3016 |
* return (
|
|
3017 |
* <div ref={ ref }>
|
|
3018 |
* <Button />
|
|
3019 |
* <Button />
|
|
3020 |
* </div>
|
|
3021 |
* );
|
|
3022 |
* }
|
|
3023 |
* ```
|
|
3024 |
*/
|
|
3025 |
|
|
3026 |
function useFocusReturn(onFocusReturn) {
|
|
3027 |
/** @type {import('react').MutableRefObject<null | HTMLElement>} */
|
|
3028 |
const ref = (0,external_wp_element_namespaceObject.useRef)(null);
|
|
3029 |
/** @type {import('react').MutableRefObject<null | Element>} */
|
|
3030 |
|
|
3031 |
const focusedBeforeMount = (0,external_wp_element_namespaceObject.useRef)(null);
|
|
3032 |
const onFocusReturnRef = (0,external_wp_element_namespaceObject.useRef)(onFocusReturn);
|
|
3033 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3034 |
onFocusReturnRef.current = onFocusReturn;
|
|
3035 |
}, [onFocusReturn]);
|
|
3036 |
return (0,external_wp_element_namespaceObject.useCallback)(node => {
|
|
3037 |
if (node) {
|
|
3038 |
// Set ref to be used when unmounting.
|
|
3039 |
ref.current = node; // Only set when the node mounts.
|
|
3040 |
|
|
3041 |
if (focusedBeforeMount.current) {
|
|
3042 |
return;
|
|
3043 |
}
|
|
3044 |
|
|
3045 |
focusedBeforeMount.current = node.ownerDocument.activeElement;
|
|
3046 |
} else if (focusedBeforeMount.current) {
|
|
3047 |
var _ref$current, _ref$current2, _ref$current3;
|
|
3048 |
|
|
3049 |
const isFocused = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.ownerDocument.activeElement);
|
|
3050 |
|
|
3051 |
if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.isConnected && !isFocused) {
|
|
3052 |
return;
|
|
3053 |
} // Defer to the component's own explicit focus return behavior, if
|
|
3054 |
// specified. This allows for support that the `onFocusReturn`
|
|
3055 |
// decides to allow the default behavior to occur under some
|
|
3056 |
// conditions.
|
|
3057 |
|
|
3058 |
|
|
3059 |
if (onFocusReturnRef.current) {
|
|
3060 |
onFocusReturnRef.current();
|
|
3061 |
} else {
|
|
3062 |
var _focusedBeforeMount$c;
|
|
3063 |
|
|
3064 |
/** @type {null | HTMLElement} */
|
|
3065 |
(_focusedBeforeMount$c = focusedBeforeMount.current) === null || _focusedBeforeMount$c === void 0 ? void 0 : _focusedBeforeMount$c.focus();
|
|
3066 |
}
|
|
3067 |
}
|
|
3068 |
}, []);
|
|
3069 |
}
|
|
3070 |
|
|
3071 |
/* harmony default export */ var use_focus_return = (useFocusReturn);
|
|
3072 |
|
|
3073 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-outside/index.js
|
|
3074 |
/**
|
|
3075 |
* External dependencies
|
|
3076 |
*/
|
|
3077 |
|
|
3078 |
/**
|
|
3079 |
* WordPress dependencies
|
|
3080 |
*/
|
|
3081 |
|
|
3082 |
|
|
3083 |
/**
|
|
3084 |
* Input types which are classified as button types, for use in considering
|
|
3085 |
* whether element is a (focus-normalized) button.
|
|
3086 |
*
|
|
3087 |
* @type {string[]}
|
|
3088 |
*/
|
|
3089 |
|
|
3090 |
const INPUT_BUTTON_TYPES = ['button', 'submit'];
|
|
3091 |
/**
|
|
3092 |
* @typedef {HTMLButtonElement | HTMLLinkElement | HTMLInputElement} FocusNormalizedButton
|
|
3093 |
*/
|
|
3094 |
// Disable reason: Rule doesn't support predicate return types.
|
|
3095 |
|
|
3096 |
/* eslint-disable jsdoc/valid-types */
|
|
3097 |
|
|
3098 |
/**
|
|
3099 |
* Returns true if the given element is a button element subject to focus
|
|
3100 |
* normalization, or false otherwise.
|
|
3101 |
*
|
|
3102 |
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
3103 |
*
|
|
3104 |
* @param {EventTarget} eventTarget The target from a mouse or touch event.
|
|
3105 |
*
|
|
3106 |
* @return {eventTarget is FocusNormalizedButton} Whether element is a button.
|
|
3107 |
*/
|
|
3108 |
|
|
3109 |
function isFocusNormalizedButton(eventTarget) {
|
|
3110 |
if (!(eventTarget instanceof window.HTMLElement)) {
|
|
3111 |
return false;
|
|
3112 |
}
|
|
3113 |
|
|
3114 |
switch (eventTarget.nodeName) {
|
|
3115 |
case 'A':
|
|
3116 |
case 'BUTTON':
|
|
3117 |
return true;
|
|
3118 |
|
|
3119 |
case 'INPUT':
|
|
3120 |
return (0,external_lodash_namespaceObject.includes)(INPUT_BUTTON_TYPES,
|
|
3121 |
/** @type {HTMLInputElement} */
|
|
3122 |
eventTarget.type);
|
|
3123 |
}
|
|
3124 |
|
|
3125 |
return false;
|
|
3126 |
}
|
|
3127 |
/* eslint-enable jsdoc/valid-types */
|
|
3128 |
|
|
3129 |
/**
|
|
3130 |
* @typedef {import('react').SyntheticEvent} SyntheticEvent
|
|
3131 |
*/
|
|
3132 |
|
|
3133 |
/**
|
|
3134 |
* @callback EventCallback
|
|
3135 |
* @param {SyntheticEvent} event input related event.
|
|
3136 |
*/
|
|
3137 |
|
|
3138 |
/**
|
|
3139 |
* @typedef FocusOutsideReactElement
|
|
3140 |
* @property {EventCallback} handleFocusOutside callback for a focus outside event.
|
|
3141 |
*/
|
|
3142 |
|
|
3143 |
/**
|
|
3144 |
* @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef
|
|
3145 |
*/
|
|
3146 |
|
|
3147 |
/**
|
|
3148 |
* @typedef {Object} FocusOutsideReturnValue
|
|
3149 |
* @property {EventCallback} onFocus An event handler for focus events.
|
|
3150 |
* @property {EventCallback} onBlur An event handler for blur events.
|
|
3151 |
* @property {EventCallback} onMouseDown An event handler for mouse down events.
|
|
3152 |
* @property {EventCallback} onMouseUp An event handler for mouse up events.
|
|
3153 |
* @property {EventCallback} onTouchStart An event handler for touch start events.
|
|
3154 |
* @property {EventCallback} onTouchEnd An event handler for touch end events.
|
|
3155 |
*/
|
|
3156 |
|
|
3157 |
/**
|
|
3158 |
* A react hook that can be used to check whether focus has moved outside the
|
|
3159 |
* element the event handlers are bound to.
|
|
3160 |
*
|
|
3161 |
* @param {EventCallback} onFocusOutside A callback triggered when focus moves outside
|
|
3162 |
* the element the event handlers are bound to.
|
|
3163 |
*
|
|
3164 |
* @return {FocusOutsideReturnValue} An object containing event handlers. Bind the event handlers
|
|
3165 |
* to a wrapping element element to capture when focus moves
|
|
3166 |
* outside that element.
|
|
3167 |
*/
|
|
3168 |
|
|
3169 |
|
|
3170 |
function useFocusOutside(onFocusOutside) {
|
|
3171 |
const currentOnFocusOutside = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside);
|
|
3172 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3173 |
currentOnFocusOutside.current = onFocusOutside;
|
|
3174 |
}, [onFocusOutside]);
|
|
3175 |
const preventBlurCheck = (0,external_wp_element_namespaceObject.useRef)(false);
|
|
3176 |
/**
|
|
3177 |
* @type {import('react').MutableRefObject<number | undefined>}
|
|
3178 |
*/
|
|
3179 |
|
|
3180 |
const blurCheckTimeoutId = (0,external_wp_element_namespaceObject.useRef)();
|
|
3181 |
/**
|
|
3182 |
* Cancel a blur check timeout.
|
|
3183 |
*/
|
|
3184 |
|
|
3185 |
const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => {
|
|
3186 |
clearTimeout(blurCheckTimeoutId.current);
|
|
3187 |
}, []); // Cancel blur checks on unmount.
|
|
3188 |
|
|
3189 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3190 |
return () => cancelBlurCheck();
|
|
3191 |
}, []); // Cancel a blur check if the callback or ref is no longer provided.
|
|
3192 |
|
|
3193 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3194 |
if (!onFocusOutside) {
|
|
3195 |
cancelBlurCheck();
|
|
3196 |
}
|
|
3197 |
}, [onFocusOutside, cancelBlurCheck]);
|
|
3198 |
/**
|
|
3199 |
* Handles a mousedown or mouseup event to respectively assign and
|
|
3200 |
* unassign a flag for preventing blur check on button elements. Some
|
|
3201 |
* browsers, namely Firefox and Safari, do not emit a focus event on
|
|
3202 |
* button elements when clicked, while others do. The logic here
|
|
3203 |
* intends to normalize this as treating click on buttons as focus.
|
|
3204 |
*
|
|
3205 |
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
|
|
3206 |
*
|
|
3207 |
* @param {SyntheticEvent} event Event for mousedown or mouseup.
|
|
3208 |
*/
|
|
3209 |
|
|
3210 |
const normalizeButtonFocus = (0,external_wp_element_namespaceObject.useCallback)(event => {
|
|
3211 |
const {
|
|
3212 |
type,
|
|
3213 |
target
|
|
3214 |
} = event;
|
|
3215 |
const isInteractionEnd = (0,external_lodash_namespaceObject.includes)(['mouseup', 'touchend'], type);
|
|
3216 |
|
|
3217 |
if (isInteractionEnd) {
|
|
3218 |
preventBlurCheck.current = false;
|
|
3219 |
} else if (isFocusNormalizedButton(target)) {
|
|
3220 |
preventBlurCheck.current = true;
|
|
3221 |
}
|
|
3222 |
}, []);
|
|
3223 |
/**
|
|
3224 |
* A callback triggered when a blur event occurs on the element the handler
|
|
3225 |
* is bound to.
|
|
3226 |
*
|
|
3227 |
* Calls the `onFocusOutside` callback in an immediate timeout if focus has
|
|
3228 |
* move outside the bound element and is still within the document.
|
|
3229 |
*
|
|
3230 |
* @param {SyntheticEvent} event Blur event.
|
|
3231 |
*/
|
|
3232 |
|
|
3233 |
const queueBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(event => {
|
|
3234 |
// React does not allow using an event reference asynchronously
|
|
3235 |
// due to recycling behavior, except when explicitly persisted.
|
|
3236 |
event.persist(); // Skip blur check if clicking button. See `normalizeButtonFocus`.
|
|
3237 |
|
|
3238 |
if (preventBlurCheck.current) {
|
|
3239 |
return;
|
|
3240 |
}
|
|
3241 |
|
|
3242 |
blurCheckTimeoutId.current = setTimeout(() => {
|
|
3243 |
// If document is not focused then focus should remain
|
|
3244 |
// inside the wrapped component and therefore we cancel
|
|
3245 |
// this blur event thereby leaving focus in place.
|
|
3246 |
// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.
|
|
3247 |
if (!document.hasFocus()) {
|
|
3248 |
event.preventDefault();
|
|
3249 |
return;
|
|
3250 |
}
|
|
3251 |
|
|
3252 |
if ('function' === typeof currentOnFocusOutside.current) {
|
|
3253 |
currentOnFocusOutside.current(event);
|
|
3254 |
}
|
|
3255 |
}, 0);
|
|
3256 |
}, []);
|
|
3257 |
return {
|
|
3258 |
onFocus: cancelBlurCheck,
|
|
3259 |
onMouseDown: normalizeButtonFocus,
|
|
3260 |
onMouseUp: normalizeButtonFocus,
|
|
3261 |
onTouchStart: normalizeButtonFocus,
|
|
3262 |
onTouchEnd: normalizeButtonFocus,
|
|
3263 |
onBlur: queueBlurCheck
|
|
3264 |
};
|
|
3265 |
}
|
|
3266 |
|
|
3267 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-merge-refs/index.js
|
|
3268 |
/**
|
|
3269 |
* WordPress dependencies
|
|
3270 |
*/
|
|
3271 |
|
|
3272 |
/* eslint-disable jsdoc/valid-types */
|
|
3273 |
|
|
3274 |
/**
|
|
3275 |
* @template T
|
|
3276 |
* @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef
|
|
3277 |
*/
|
|
3278 |
|
|
3279 |
/* eslint-enable jsdoc/valid-types */
|
|
3280 |
|
|
3281 |
/**
|
|
3282 |
* @template T
|
|
3283 |
* @param {import('react').Ref<T>} ref
|
|
3284 |
* @param {T} value
|
|
3285 |
*/
|
|
3286 |
|
|
3287 |
function assignRef(ref, value) {
|
|
3288 |
if (typeof ref === 'function') {
|
|
3289 |
ref(value);
|
|
3290 |
} else if (ref && ref.hasOwnProperty('current')) {
|
|
3291 |
/* eslint-disable jsdoc/no-undefined-types */
|
|
3292 |
|
|
3293 |
/** @type {import('react').MutableRefObject<T>} */
|
|
3294 |
ref.current = value;
|
|
3295 |
/* eslint-enable jsdoc/no-undefined-types */
|
|
3296 |
}
|
|
3297 |
}
|
|
3298 |
/**
|
|
3299 |
* Merges refs into one ref callback.
|
|
3300 |
*
|
|
3301 |
* It also ensures that the merged ref callbacks are only called when they
|
|
3302 |
* change (as a result of a `useCallback` dependency update) OR when the ref
|
|
3303 |
* value changes, just as React does when passing a single ref callback to the
|
|
3304 |
* component.
|
|
3305 |
*
|
|
3306 |
* As expected, if you pass a new function on every render, the ref callback
|
|
3307 |
* will be called after every render.
|
|
3308 |
*
|
|
3309 |
* If you don't wish a ref callback to be called after every render, wrap it
|
|
3310 |
* with `useCallback( callback, dependencies )`. When a dependency changes, the
|
|
3311 |
* old ref callback will be called with `null` and the new ref callback will be
|
|
3312 |
* called with the same value.
|
|
3313 |
*
|
|
3314 |
* To make ref callbacks easier to use, you can also pass the result of
|
|
3315 |
* `useRefEffect`, which makes cleanup easier by allowing you to return a
|
|
3316 |
* cleanup function instead of handling `null`.
|
|
3317 |
*
|
|
3318 |
* It's also possible to _disable_ a ref (and its behaviour) by simply not
|
|
3319 |
* passing the ref.
|
|
3320 |
*
|
|
3321 |
* ```jsx
|
|
3322 |
* const ref = useRefEffect( ( node ) => {
|
|
3323 |
* node.addEventListener( ... );
|
|
3324 |
* return () => {
|
|
3325 |
* node.removeEventListener( ... );
|
|
3326 |
* };
|
|
3327 |
* }, [ ...dependencies ] );
|
|
3328 |
* const otherRef = useRef();
|
|
3329 |
* const mergedRefs useMergeRefs( [
|
|
3330 |
* enabled && ref,
|
|
3331 |
* otherRef,
|
|
3332 |
* ] );
|
|
3333 |
* return <div ref={ mergedRefs } />;
|
|
3334 |
* ```
|
|
3335 |
*
|
|
3336 |
* @template {import('react').Ref<any>} TRef
|
|
3337 |
* @param {Array<TRef>} refs The refs to be merged.
|
|
3338 |
*
|
|
3339 |
* @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.
|
|
3340 |
*/
|
|
3341 |
|
|
3342 |
|
|
3343 |
function useMergeRefs(refs) {
|
|
3344 |
const element = (0,external_wp_element_namespaceObject.useRef)();
|
|
3345 |
const didElementChange = (0,external_wp_element_namespaceObject.useRef)(false);
|
|
3346 |
/* eslint-disable jsdoc/no-undefined-types */
|
|
3347 |
|
|
3348 |
/** @type {import('react').MutableRefObject<TRef[]>} */
|
|
3349 |
|
|
3350 |
/* eslint-enable jsdoc/no-undefined-types */
|
|
3351 |
|
|
3352 |
const previousRefs = (0,external_wp_element_namespaceObject.useRef)([]);
|
|
3353 |
const currentRefs = (0,external_wp_element_namespaceObject.useRef)(refs); // Update on render before the ref callback is called, so the ref callback
|
|
3354 |
// always has access to the current refs.
|
|
3355 |
|
|
3356 |
currentRefs.current = refs; // If any of the refs change, call the previous ref with `null` and the new
|
|
3357 |
// ref with the node, except when the element changes in the same cycle, in
|
|
3358 |
// which case the ref callbacks will already have been called.
|
|
3359 |
|
|
3360 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
|
|
3361 |
if (didElementChange.current === false) {
|
|
3362 |
refs.forEach((ref, index) => {
|
|
3363 |
const previousRef = previousRefs.current[index];
|
|
3364 |
|
|
3365 |
if (ref !== previousRef) {
|
|
3366 |
assignRef(previousRef, null);
|
|
3367 |
assignRef(ref, element.current);
|
|
3368 |
}
|
|
3369 |
});
|
|
3370 |
}
|
|
3371 |
|
|
3372 |
previousRefs.current = refs;
|
|
3373 |
}, refs); // No dependencies, must be reset after every render so ref callbacks are
|
|
3374 |
// correctly called after a ref change.
|
|
3375 |
|
|
3376 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
|
|
3377 |
didElementChange.current = false;
|
|
3378 |
}); // There should be no dependencies so that `callback` is only called when
|
|
3379 |
// the node changes.
|
|
3380 |
|
|
3381 |
return (0,external_wp_element_namespaceObject.useCallback)(value => {
|
|
3382 |
// Update the element so it can be used when calling ref callbacks on a
|
|
3383 |
// dependency change.
|
|
3384 |
assignRef(element, value);
|
|
3385 |
didElementChange.current = true; // When an element changes, the current ref callback should be called
|
|
3386 |
// with the new element and the previous one with `null`.
|
|
3387 |
|
|
3388 |
const refsToAssign = value ? currentRefs.current : previousRefs.current; // Update the latest refs.
|
|
3389 |
|
|
3390 |
for (const ref of refsToAssign) {
|
|
3391 |
assignRef(ref, value);
|
|
3392 |
}
|
|
3393 |
}, []);
|
|
3394 |
}
|
|
3395 |
|
|
3396 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dialog/index.js
|
|
3397 |
/**
|
|
3398 |
* WordPress dependencies
|
|
3399 |
*/
|
|
3400 |
|
|
3401 |
|
|
3402 |
/**
|
|
3403 |
* Internal dependencies
|
|
3404 |
*/
|
|
3405 |
|
|
3406 |
|
|
3407 |
|
|
3408 |
|
|
3409 |
|
|
3410 |
|
|
3411 |
/* eslint-disable jsdoc/valid-types */
|
|
3412 |
|
|
3413 |
/**
|
|
3414 |
* @typedef DialogOptions
|
|
3415 |
* @property {Parameters<useFocusOnMount>[0]} focusOnMount Focus on mount arguments.
|
|
3416 |
* @property {() => void} onClose Function to call when the dialog is closed.
|
|
3417 |
*/
|
|
3418 |
|
|
3419 |
/* eslint-enable jsdoc/valid-types */
|
|
3420 |
|
|
3421 |
/**
|
|
3422 |
* Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:
|
|
3423 |
* - constrained tabbing.
|
|
3424 |
* - focus on mount.
|
|
3425 |
* - return focus on unmount.
|
|
3426 |
* - focus outside.
|
|
3427 |
*
|
|
3428 |
* @param {DialogOptions} options Dialog Options.
|
|
3429 |
*/
|
|
3430 |
|
|
3431 |
function useDialog(options) {
|
|
3432 |
/**
|
|
3433 |
* @type {import('react').MutableRefObject<DialogOptions | undefined>}
|
|
3434 |
*/
|
|
3435 |
const currentOptions = (0,external_wp_element_namespaceObject.useRef)();
|
|
3436 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3437 |
currentOptions.current = options;
|
|
3438 |
}, Object.values(options));
|
|
3439 |
const constrainedTabbingRef = use_constrained_tabbing();
|
|
3440 |
const focusOnMountRef = useFocusOnMount(options.focusOnMount);
|
|
3441 |
const focusReturnRef = use_focus_return();
|
|
3442 |
const focusOutsideProps = useFocusOutside(event => {
|
|
3443 |
var _currentOptions$curre, _currentOptions$curre2;
|
|
3444 |
|
|
3445 |
// This unstable prop is here only to manage backward compatibility
|
|
3446 |
// for the Popover component otherwise, the onClose should be enough.
|
|
3447 |
// @ts-ignore unstable property
|
|
3448 |
if ((_currentOptions$curre = currentOptions.current) !== null && _currentOptions$curre !== void 0 && _currentOptions$curre.__unstableOnClose) {
|
|
3449 |
// @ts-ignore unstable property
|
|
3450 |
currentOptions.current.__unstableOnClose('focus-outside', event);
|
|
3451 |
} else if ((_currentOptions$curre2 = currentOptions.current) !== null && _currentOptions$curre2 !== void 0 && _currentOptions$curre2.onClose) {
|
|
3452 |
currentOptions.current.onClose();
|
|
3453 |
}
|
|
3454 |
});
|
|
3455 |
const closeOnEscapeRef = (0,external_wp_element_namespaceObject.useCallback)(node => {
|
|
3456 |
if (!node) {
|
|
3457 |
return;
|
|
3458 |
}
|
|
3459 |
|
|
3460 |
node.addEventListener('keydown', (
|
|
3461 |
/** @type {KeyboardEvent} */
|
|
3462 |
event) => {
|
|
3463 |
var _currentOptions$curre3;
|
|
3464 |
|
|
3465 |
// Close on escape.
|
|
3466 |
if (event.keyCode === external_wp_keycodes_namespaceObject.ESCAPE && !event.defaultPrevented && (_currentOptions$curre3 = currentOptions.current) !== null && _currentOptions$curre3 !== void 0 && _currentOptions$curre3.onClose) {
|
|
3467 |
event.preventDefault();
|
|
3468 |
currentOptions.current.onClose();
|
|
3469 |
}
|
|
3470 |
});
|
|
3471 |
}, []);
|
|
3472 |
return [useMergeRefs([options.focusOnMount !== false ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), { ...focusOutsideProps,
|
|
3473 |
tabIndex: '-1'
|
|
3474 |
}];
|
|
3475 |
}
|
|
3476 |
|
|
3477 |
/* harmony default export */ var use_dialog = (useDialog);
|
|
3478 |
|
|
3479 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-disabled/index.js
|
|
3480 |
/**
|
|
3481 |
* External dependencies
|
|
3482 |
*/
|
|
3483 |
|
|
3484 |
/**
|
|
3485 |
* WordPress dependencies
|
|
3486 |
*/
|
|
3487 |
|
|
3488 |
|
|
3489 |
|
|
3490 |
/**
|
|
3491 |
* Names of control nodes which qualify for disabled behavior.
|
|
3492 |
*
|
|
3493 |
* See WHATWG HTML Standard: 4.10.18.5: "Enabling and disabling form controls: the disabled attribute".
|
|
3494 |
*
|
|
3495 |
* @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute
|
|
3496 |
*
|
|
3497 |
* @type {string[]}
|
|
3498 |
*/
|
|
3499 |
|
|
3500 |
const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA'];
|
|
3501 |
/**
|
|
3502 |
* In some circumstances, such as block previews, all focusable DOM elements
|
|
3503 |
* (input fields, links, buttons, etc.) need to be disabled. This hook adds the
|
|
3504 |
* behavior to disable nested DOM elements to the returned ref.
|
|
3505 |
*
|
|
3506 |
* @return {import('react').RefObject<HTMLElement>} Element Ref.
|
|
3507 |
*
|
|
3508 |
* @example
|
|
3509 |
* ```js
|
|
3510 |
* import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
|
|
3511 |
* const DisabledExample = () => {
|
|
3512 |
* const disabledRef = useDisabled();
|
|
3513 |
* return (
|
|
3514 |
* <div ref={ disabledRef }>
|
|
3515 |
* <a href="#">This link will have tabindex set to -1</a>
|
|
3516 |
* <input placeholder="This input will have the disabled attribute added to it." type="text" />
|
|
3517 |
* </div>
|
|
3518 |
* );
|
|
3519 |
* };
|
|
3520 |
* ```
|
|
3521 |
*/
|
|
3522 |
|
|
3523 |
function useDisabled() {
|
|
3524 |
/** @type {import('react').RefObject<HTMLElement>} */
|
|
3525 |
const node = (0,external_wp_element_namespaceObject.useRef)(null);
|
|
3526 |
|
|
3527 |
const disable = () => {
|
|
3528 |
if (!node.current) {
|
|
3529 |
return;
|
|
3530 |
}
|
|
3531 |
|
|
3532 |
external_wp_dom_namespaceObject.focus.focusable.find(node.current).forEach(focusable => {
|
|
3533 |
if ((0,external_lodash_namespaceObject.includes)(DISABLED_ELIGIBLE_NODE_NAMES, focusable.nodeName)) {
|
|
3534 |
focusable.setAttribute('disabled', '');
|
|
3535 |
}
|
|
3536 |
|
|
3537 |
if (focusable.nodeName === 'A') {
|
|
3538 |
focusable.setAttribute('tabindex', '-1');
|
|
3539 |
}
|
|
3540 |
|
|
3541 |
const tabIndex = focusable.getAttribute('tabindex');
|
|
3542 |
|
|
3543 |
if (tabIndex !== null && tabIndex !== '-1') {
|
|
3544 |
focusable.removeAttribute('tabindex');
|
|
3545 |
}
|
|
3546 |
|
|
3547 |
if (focusable.hasAttribute('contenteditable')) {
|
|
3548 |
focusable.setAttribute('contenteditable', 'false');
|
|
3549 |
}
|
|
3550 |
});
|
|
3551 |
}; // Debounce re-disable since disabling process itself will incur
|
|
3552 |
// additional mutations which should be ignored.
|
|
3553 |
|
|
3554 |
|
|
3555 |
const debouncedDisable = (0,external_wp_element_namespaceObject.useCallback)((0,external_lodash_namespaceObject.debounce)(disable, undefined, {
|
|
3556 |
leading: true
|
|
3557 |
}), []);
|
|
3558 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
|
|
3559 |
disable();
|
|
3560 |
/** @type {MutationObserver | undefined} */
|
|
3561 |
|
|
3562 |
let observer;
|
|
3563 |
|
|
3564 |
if (node.current) {
|
|
3565 |
observer = new window.MutationObserver(debouncedDisable);
|
|
3566 |
observer.observe(node.current, {
|
|
3567 |
childList: true,
|
|
3568 |
attributes: true,
|
|
3569 |
subtree: true
|
|
3570 |
});
|
|
3571 |
}
|
|
3572 |
|
|
3573 |
return () => {
|
|
3574 |
if (observer) {
|
|
3575 |
observer.disconnect();
|
|
3576 |
}
|
|
3577 |
|
|
3578 |
debouncedDisable.cancel();
|
|
3579 |
};
|
|
3580 |
}, []);
|
|
3581 |
return node;
|
|
3582 |
}
|
|
3583 |
|
|
3584 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-isomorphic-layout-effect/index.js
|
|
3585 |
/**
|
|
3586 |
* WordPress dependencies
|
|
3587 |
*/
|
|
3588 |
|
|
3589 |
/**
|
|
3590 |
* Preferred over direct usage of `useLayoutEffect` when supporting
|
|
3591 |
* server rendered components (SSR) because currently React
|
|
3592 |
* throws a warning when using useLayoutEffect in that environment.
|
|
3593 |
*/
|
|
3594 |
|
|
3595 |
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect;
|
|
3596 |
/* harmony default export */ var use_isomorphic_layout_effect = (useIsomorphicLayoutEffect);
|
|
3597 |
|
|
3598 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dragging/index.js
|
|
3599 |
/**
|
|
3600 |
* WordPress dependencies
|
|
3601 |
*/
|
|
3602 |
|
|
3603 |
/**
|
|
3604 |
* Internal dependencies
|
|
3605 |
*/
|
|
3606 |
|
|
3607 |
|
|
3608 |
/**
|
|
3609 |
* @param {Object} props
|
|
3610 |
* @param {(e: MouseEvent) => void} props.onDragStart
|
|
3611 |
* @param {(e: MouseEvent) => void} props.onDragMove
|
|
3612 |
* @param {(e: MouseEvent) => void} props.onDragEnd
|
|
3613 |
*/
|
|
3614 |
|
|
3615 |
function useDragging(_ref) {
|
|
3616 |
let {
|
|
3617 |
onDragStart,
|
|
3618 |
onDragMove,
|
|
3619 |
onDragEnd
|
|
3620 |
} = _ref;
|
|
3621 |
const [isDragging, setIsDragging] = (0,external_wp_element_namespaceObject.useState)(false);
|
|
3622 |
const eventsRef = (0,external_wp_element_namespaceObject.useRef)({
|
|
3623 |
onDragStart,
|
|
3624 |
onDragMove,
|
|
3625 |
onDragEnd
|
|
3626 |
});
|
|
3627 |
use_isomorphic_layout_effect(() => {
|
|
3628 |
eventsRef.current.onDragStart = onDragStart;
|
|
3629 |
eventsRef.current.onDragMove = onDragMove;
|
|
3630 |
eventsRef.current.onDragEnd = onDragEnd;
|
|
3631 |
}, [onDragStart, onDragMove, onDragEnd]);
|
|
3632 |
const onMouseMove = (0,external_wp_element_namespaceObject.useCallback)((
|
|
3633 |
/** @type {MouseEvent} */
|
|
3634 |
event) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []);
|
|
3635 |
const endDrag = (0,external_wp_element_namespaceObject.useCallback)((
|
|
3636 |
/** @type {MouseEvent} */
|
|
3637 |
event) => {
|
|
3638 |
if (eventsRef.current.onDragEnd) {
|
|
3639 |
eventsRef.current.onDragEnd(event);
|
|
3640 |
}
|
|
3641 |
|
|
3642 |
document.removeEventListener('mousemove', onMouseMove);
|
|
3643 |
document.removeEventListener('mouseup', endDrag);
|
|
3644 |
setIsDragging(false);
|
|
3645 |
}, []);
|
|
3646 |
const startDrag = (0,external_wp_element_namespaceObject.useCallback)((
|
|
3647 |
/** @type {MouseEvent} */
|
|
3648 |
event) => {
|
|
3649 |
if (eventsRef.current.onDragStart) {
|
|
3650 |
eventsRef.current.onDragStart(event);
|
|
3651 |
}
|
|
3652 |
|
|
3653 |
document.addEventListener('mousemove', onMouseMove);
|
|
3654 |
document.addEventListener('mouseup', endDrag);
|
|
3655 |
setIsDragging(true);
|
|
3656 |
}, []); // Remove the global events when unmounting if needed.
|
|
3657 |
|
|
3658 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3659 |
return () => {
|
|
3660 |
if (isDragging) {
|
|
3661 |
document.removeEventListener('mousemove', onMouseMove);
|
|
3662 |
document.removeEventListener('mouseup', endDrag);
|
|
3663 |
}
|
|
3664 |
};
|
|
3665 |
}, [isDragging]);
|
|
3666 |
return {
|
|
3667 |
startDrag,
|
|
3668 |
endDrag,
|
|
3669 |
isDragging
|
|
3670 |
};
|
|
3671 |
}
|
|
3672 |
|
|
3673 |
// EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js
|
|
3674 |
var mousetrap_mousetrap = __webpack_require__(7973);
|
|
3675 |
var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap);
|
|
3676 |
// EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
|
|
3677 |
var mousetrap_global_bind = __webpack_require__(5538);
|
|
3678 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-keyboard-shortcut/index.js
|
|
3679 |
/**
|
|
3680 |
* External dependencies
|
|
3681 |
*/
|
|
3682 |
|
|
3683 |
|
|
3684 |
|
|
3685 |
/**
|
|
3686 |
* WordPress dependencies
|
|
3687 |
*/
|
|
3688 |
|
|
3689 |
|
|
3690 |
/**
|
|
3691 |
* A block selection object.
|
|
3692 |
*
|
|
3693 |
* @typedef {Object} WPKeyboardShortcutConfig
|
|
3694 |
*
|
|
3695 |
* @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
|
|
3696 |
* @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
|
|
3697 |
* @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
|
|
3698 |
* @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.
|
|
3699 |
*/
|
|
3700 |
|
|
3701 |
/**
|
|
3702 |
* Return true if platform is MacOS.
|
|
3703 |
*
|
|
3704 |
* @param {Window} [_window] window object by default; used for DI testing.
|
|
3705 |
*
|
|
3706 |
* @return {boolean} True if MacOS; false otherwise.
|
|
3707 |
*/
|
|
3708 |
|
|
3709 |
function isAppleOS() {
|
|
3710 |
let _window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
|
|
3711 |
|
|
3712 |
const {
|
|
3713 |
platform
|
|
3714 |
} = _window.navigator;
|
|
3715 |
return platform.indexOf('Mac') !== -1 || (0,external_lodash_namespaceObject.includes)(['iPad', 'iPhone'], platform);
|
|
3716 |
}
|
|
3717 |
/* eslint-disable jsdoc/valid-types */
|
|
3718 |
|
|
3719 |
/**
|
|
3720 |
* Attach a keyboard shortcut handler.
|
|
3721 |
*
|
|
3722 |
* @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
|
|
3723 |
*
|
|
3724 |
* @param {string[]|string} shortcuts Keyboard Shortcuts.
|
|
3725 |
* @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
|
|
3726 |
* @param {WPKeyboardShortcutConfig} options Shortcut options.
|
|
3727 |
*/
|
|
3728 |
|
|
3729 |
|
|
3730 |
function useKeyboardShortcut(
|
|
3731 |
/* eslint-enable jsdoc/valid-types */
|
|
3732 |
shortcuts, callback) {
|
|
3733 |
let {
|
|
3734 |
bindGlobal = false,
|
|
3735 |
eventName = 'keydown',
|
|
3736 |
isDisabled = false,
|
|
3737 |
// This is important for performance considerations.
|
|
3738 |
target
|
|
3739 |
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
3740 |
const currentCallback = (0,external_wp_element_namespaceObject.useRef)(callback);
|
|
3741 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3742 |
currentCallback.current = callback;
|
|
3743 |
}, [callback]);
|
|
3744 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3745 |
if (isDisabled) {
|
|
3746 |
return;
|
|
3747 |
}
|
|
3748 |
|
|
3749 |
const mousetrap = new (mousetrap_default())(target && target.current ? target.current : // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
|
|
3750 |
// Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's
|
|
3751 |
// necessary to maintain the existing behavior.
|
|
3752 |
|
|
3753 |
/** @type {Element} */
|
|
3754 |
|
|
3755 |
/** @type {unknown} */
|
|
3756 |
document);
|
|
3757 |
(0,external_lodash_namespaceObject.castArray)(shortcuts).forEach(shortcut => {
|
|
3758 |
const keys = shortcut.split('+'); // Determines whether a key is a modifier by the length of the string.
|
|
3759 |
// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that
|
|
3760 |
// the modifiers are Shift and Cmd because they're not a single character.
|
|
3761 |
|
|
3762 |
const modifiers = new Set(keys.filter(value => value.length > 1));
|
|
3763 |
const hasAlt = modifiers.has('alt');
|
|
3764 |
const hasShift = modifiers.has('shift'); // This should be better moved to the shortcut registration instead.
|
|
3765 |
|
|
3766 |
if (isAppleOS() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
|
|
3767 |
throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`);
|
|
3768 |
}
|
|
3769 |
|
|
3770 |
const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; // @ts-ignore `bindGlobal` is an undocumented property
|
|
3771 |
|
|
3772 |
mousetrap[bindFn](shortcut, function () {
|
|
3773 |
return (
|
|
3774 |
/* eslint-enable jsdoc/valid-types */
|
|
3775 |
currentCallback.current(...arguments)
|
|
3776 |
);
|
|
3777 |
}, eventName);
|
|
3778 |
});
|
|
3779 |
return () => {
|
|
3780 |
mousetrap.reset();
|
|
3781 |
};
|
|
3782 |
}, [shortcuts, bindGlobal, eventName, target, isDisabled]);
|
|
3783 |
}
|
|
3784 |
|
|
3785 |
/* harmony default export */ var use_keyboard_shortcut = (useKeyboardShortcut);
|
|
3786 |
|
|
3787 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-media-query/index.js
|
|
3788 |
/**
|
|
3789 |
* WordPress dependencies
|
|
3790 |
*/
|
|
3791 |
|
|
3792 |
/**
|
|
3793 |
* Runs a media query and returns its value when it changes.
|
|
3794 |
*
|
|
3795 |
* @param {string} [query] Media Query.
|
|
3796 |
* @return {boolean} return value of the media query.
|
|
3797 |
*/
|
|
3798 |
|
|
3799 |
function useMediaQuery(query) {
|
|
3800 |
const [match, setMatch] = (0,external_wp_element_namespaceObject.useState)(() => !!(query && typeof window !== 'undefined' && window.matchMedia(query).matches));
|
|
3801 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3802 |
if (!query) {
|
|
3803 |
return;
|
|
3804 |
}
|
|
3805 |
|
|
3806 |
const updateMatch = () => setMatch(window.matchMedia(query).matches);
|
|
3807 |
|
|
3808 |
updateMatch();
|
|
3809 |
const list = window.matchMedia(query);
|
|
3810 |
list.addListener(updateMatch);
|
|
3811 |
return () => {
|
|
3812 |
list.removeListener(updateMatch);
|
|
3813 |
};
|
|
3814 |
}, [query]);
|
|
3815 |
return !!query && match;
|
|
3816 |
}
|
|
3817 |
|
|
3818 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-previous/index.js
|
|
3819 |
/**
|
|
3820 |
* WordPress dependencies
|
|
3821 |
*/
|
|
3822 |
|
|
3823 |
/**
|
|
3824 |
* Use something's value from the previous render.
|
|
3825 |
* Based on https://usehooks.com/usePrevious/.
|
|
3826 |
*
|
|
3827 |
* @param value The value to track.
|
|
3828 |
*
|
|
3829 |
* @return The value from the previous render.
|
|
3830 |
*/
|
|
3831 |
|
|
3832 |
function usePrevious(value) {
|
|
3833 |
const ref = (0,external_wp_element_namespaceObject.useRef)(); // Store current value in ref.
|
|
3834 |
|
|
3835 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
3836 |
ref.current = value;
|
|
3837 |
}, [value]); // Re-run when value changes.
|
|
3838 |
// Return previous value (happens before update in useEffect above).
|
|
3839 |
|
|
3840 |
return ref.current;
|
|
3841 |
}
|
|
3842 |
|
|
3843 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-reduced-motion/index.js
|
|
3844 |
/**
|
|
3845 |
* Internal dependencies
|
|
3846 |
*/
|
|
3847 |
|
|
3848 |
/**
|
|
3849 |
* Hook returning whether the user has a preference for reduced motion.
|
|
3850 |
*
|
|
3851 |
* @return {boolean} Reduced motion preference value.
|
|
3852 |
*/
|
|
3853 |
|
|
3854 |
const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)');
|
|
3855 |
|
|
3856 |
/* harmony default export */ var use_reduced_motion = (useReducedMotion);
|
|
3857 |
|
|
3858 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-viewport-match/index.js
|
|
3859 |
/**
|
|
3860 |
* WordPress dependencies
|
|
3861 |
*/
|
|
3862 |
|
|
3863 |
/**
|
|
3864 |
* Internal dependencies
|
|
3865 |
*/
|
|
3866 |
|
|
3867 |
|
|
3868 |
/**
|
|
3869 |
* @typedef {"huge" | "wide" | "large" | "medium" | "small" | "mobile"} WPBreakpoint
|
|
3870 |
*/
|
|
3871 |
|
|
3872 |
/**
|
|
3873 |
* Hash of breakpoint names with pixel width at which it becomes effective.
|
|
3874 |
*
|
|
3875 |
* @see _breakpoints.scss
|
|
3876 |
*
|
|
3877 |
* @type {Record<WPBreakpoint, number>}
|
|
3878 |
*/
|
|
3879 |
|
|
3880 |
const BREAKPOINTS = {
|
|
3881 |
huge: 1440,
|
|
3882 |
wide: 1280,
|
|
3883 |
large: 960,
|
|
3884 |
medium: 782,
|
|
3885 |
small: 600,
|
|
3886 |
mobile: 480
|
|
3887 |
};
|
|
3888 |
/**
|
|
3889 |
* @typedef {">=" | "<"} WPViewportOperator
|
|
3890 |
*/
|
|
3891 |
|
|
3892 |
/**
|
|
3893 |
* Object mapping media query operators to the condition to be used.
|
|
3894 |
*
|
|
3895 |
* @type {Record<WPViewportOperator, string>}
|
|
3896 |
*/
|
|
3897 |
|
|
3898 |
const CONDITIONS = {
|
|
3899 |
'>=': 'min-width',
|
|
3900 |
'<': 'max-width'
|
|
3901 |
};
|
|
3902 |
/**
|
|
3903 |
* Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.
|
|
3904 |
*
|
|
3905 |
* @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}
|
|
3906 |
*/
|
|
3907 |
|
|
3908 |
const OPERATOR_EVALUATORS = {
|
|
3909 |
'>=': (breakpointValue, width) => width >= breakpointValue,
|
|
3910 |
'<': (breakpointValue, width) => width < breakpointValue
|
|
3911 |
};
|
|
3912 |
const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)(
|
|
3913 |
/** @type {null | number} */
|
|
3914 |
null);
|
|
3915 |
/**
|
|
3916 |
* Returns true if the viewport matches the given query, or false otherwise.
|
|
3917 |
*
|
|
3918 |
* @param {WPBreakpoint} breakpoint Breakpoint size name.
|
|
3919 |
* @param {WPViewportOperator} [operator=">="] Viewport operator.
|
|
3920 |
*
|
|
3921 |
* @example
|
|
3922 |
*
|
|
3923 |
* ```js
|
|
3924 |
* useViewportMatch( 'huge', '<' );
|
|
3925 |
* useViewportMatch( 'medium' );
|
|
3926 |
* ```
|
|
3927 |
*
|
|
3928 |
* @return {boolean} Whether viewport matches query.
|
|
3929 |
*/
|
|
3930 |
|
|
3931 |
const useViewportMatch = function (breakpoint) {
|
|
3932 |
let operator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '>=';
|
|
3933 |
const simulatedWidth = (0,external_wp_element_namespaceObject.useContext)(ViewportMatchWidthContext);
|
|
3934 |
const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
|
|
3935 |
const mediaQueryResult = useMediaQuery(mediaQuery || undefined);
|
|
3936 |
|
|
3937 |
if (simulatedWidth) {
|
|
3938 |
return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth);
|
|
3939 |
}
|
|
3940 |
|
|
3941 |
return mediaQueryResult;
|
|
3942 |
};
|
|
3943 |
|
|
3944 |
useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
|
|
3945 |
/* harmony default export */ var use_viewport_match = (useViewportMatch);
|
|
3946 |
|
|
3947 |
// EXTERNAL MODULE: ./node_modules/react-resize-aware/dist/index.js
|
|
3948 |
var dist = __webpack_require__(235);
|
|
3949 |
var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
|
|
3950 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js
|
|
3951 |
/**
|
|
3952 |
* External dependencies
|
|
3953 |
*/
|
|
3954 |
|
|
3955 |
/**
|
|
3956 |
* Hook which allows to listen the resize event of any target element when it changes sizes.
|
|
3957 |
* _Note: `useResizeObserver` will report `null` until after first render_
|
|
3958 |
*
|
|
3959 |
* Simply a re-export of `react-resize-aware` so refer to its documentation <https://github.com/FezVrasta/react-resize-aware>
|
|
3960 |
* for more details.
|
|
3961 |
*
|
|
3962 |
* @see https://github.com/FezVrasta/react-resize-aware
|
|
3963 |
*
|
|
3964 |
* @example
|
|
3965 |
*
|
|
3966 |
* ```js
|
|
3967 |
* const App = () => {
|
|
3968 |
* const [ resizeListener, sizes ] = useResizeObserver();
|
|
3969 |
*
|
|
3970 |
* return (
|
|
3971 |
* <div>
|
|
3972 |
* { resizeListener }
|
|
3973 |
* Your content here
|
|
3974 |
* </div>
|
|
3975 |
* );
|
|
3976 |
* };
|
|
3977 |
* ```
|
|
3978 |
*
|
|
3979 |
*/
|
|
3980 |
|
|
3981 |
/* harmony default export */ var use_resize_observer = ((dist_default()));
|
|
3982 |
|
|
3983 |
;// CONCATENATED MODULE: external ["wp","priorityQueue"]
|
|
3984 |
var external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"];
|
|
3985 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-async-list/index.js
|
|
3986 |
/**
|
|
3987 |
* WordPress dependencies
|
|
3988 |
*/
|
|
3989 |
|
|
3990 |
|
|
3991 |
|
|
3992 |
/**
|
|
3993 |
* Returns the first items from list that are present on state.
|
|
3994 |
*
|
|
3995 |
* @param list New array.
|
|
3996 |
* @param state Current state.
|
|
3997 |
* @return First items present iin state.
|
|
3998 |
*/
|
|
3999 |
function getFirstItemsPresentInState(list, state) {
|
|
4000 |
const firstItems = [];
|
|
4001 |
|
|
4002 |
for (let i = 0; i < list.length; i++) {
|
|
4003 |
const item = list[i];
|
|
4004 |
|
|
4005 |
if (!state.includes(item)) {
|
|
4006 |
break;
|
|
4007 |
}
|
|
4008 |
|
|
4009 |
firstItems.push(item);
|
|
4010 |
}
|
|
4011 |
|
|
4012 |
return firstItems;
|
|
4013 |
}
|
|
4014 |
/**
|
|
4015 |
* React hook returns an array which items get asynchronously appended from a source array.
|
|
4016 |
* This behavior is useful if we want to render a list of items asynchronously for performance reasons.
|
|
4017 |
*
|
|
4018 |
* @param list Source array.
|
|
4019 |
* @param config Configuration object.
|
|
4020 |
*
|
|
4021 |
* @return Async array.
|
|
4022 |
*/
|
|
4023 |
|
|
4024 |
|
|
4025 |
function useAsyncList(list) {
|
|
4026 |
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
4027 |
step: 1
|
|
4028 |
};
|
|
4029 |
const {
|
|
4030 |
step = 1
|
|
4031 |
} = config;
|
|
4032 |
const [current, setCurrent] = (0,external_wp_element_namespaceObject.useState)([]);
|
|
4033 |
(0,external_wp_element_namespaceObject.useEffect)(() => {
|
|
4034 |
// On reset, we keep the first items that were previously rendered.
|
|
4035 |
let firstItems = getFirstItemsPresentInState(list, current);
|
|
4036 |
|
|
4037 |
if (firstItems.length < step) {
|
|
4038 |
firstItems = firstItems.concat(list.slice(firstItems.length, step));
|
|
4039 |
}
|
|
4040 |
|
|
4041 |
setCurrent(firstItems);
|
|
4042 |
let nextIndex = firstItems.length;
|
|
4043 |
const asyncQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)();
|
|
4044 |
|
|
4045 |
const append = () => {
|
|
4046 |
if (list.length <= nextIndex) {
|
|
4047 |
return;
|
|
4048 |
}
|
|
4049 |
|
|
4050 |
setCurrent(state => [...state, ...list.slice(nextIndex, nextIndex + step)]);
|
|
4051 |
nextIndex += step;
|
|
4052 |
asyncQueue.add({}, append);
|
|
4053 |
};
|
|
4054 |
|
|
4055 |
asyncQueue.add({}, append);
|
|
4056 |
return () => asyncQueue.reset();
|
|
4057 |
}, [list]);
|
|
4058 |
return current;
|
|
4059 |
}
|
|
4060 |
|
|
4061 |
/* harmony default export */ var use_async_list = (useAsyncList);
|
|
4062 |
|
|
4063 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-warn-on-change/index.js
|
|
4064 |
/**
|
|
4065 |
* Internal dependencies
|
|
4066 |
*/
|
|
4067 |
// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case
|
|
4068 |
// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
|
|
4069 |
|
|
4070 |
/* eslint-disable jsdoc/check-types */
|
|
4071 |
|
|
4072 |
/**
|
|
4073 |
* Hook that performs a shallow comparison between the preview value of an object
|
|
4074 |
* and the new one, if there's a difference, it prints it to the console.
|
|
4075 |
* this is useful in performance related work, to check why a component re-renders.
|
|
4076 |
*
|
|
4077 |
* @example
|
|
4078 |
*
|
|
4079 |
* ```jsx
|
|
4080 |
* function MyComponent(props) {
|
|
4081 |
* useWarnOnChange(props);
|
|
4082 |
*
|
|
4083 |
* return "Something";
|
|
4084 |
* }
|
|
4085 |
* ```
|
|
4086 |
*
|
|
4087 |
* @param {object} object Object which changes to compare.
|
|
4088 |
* @param {string} prefix Just a prefix to show when console logging.
|
|
4089 |
*/
|
|
4090 |
|
|
4091 |
function useWarnOnChange(object) {
|
|
4092 |
let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Change detection';
|
|
4093 |
const previousValues = usePrevious(object);
|
|
4094 |
Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(_ref => {
|
|
4095 |
let [key, value] = _ref;
|
|
4096 |
|
|
4097 |
if (value !== object[
|
|
4098 |
/** @type {keyof typeof object} */
|
|
4099 |
key]) {
|
|
4100 |
// eslint-disable-next-line no-console
|
|
4101 |
console.warn(`${prefix}: ${key} key changed:`, value, object[
|
|
4102 |
/** @type {keyof typeof object} */
|
|
4103 |
key]
|
|
4104 |
/* eslint-enable jsdoc/check-types */
|
|
4105 |
);
|
|
4106 |
}
|
|
4107 |
});
|
|
4108 |
}
|
|
4109 |
|
|
4110 |
/* harmony default export */ var use_warn_on_change = (useWarnOnChange);
|
|
4111 |
|
|
4112 |
// EXTERNAL MODULE: external "React"
|
|
4113 |
var external_React_ = __webpack_require__(9196);
|
|
4114 |
;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js
|
|
4115 |
|
|
4116 |
|
|
4117 |
function areInputsEqual(newInputs, lastInputs) {
|
|
4118 |
if (newInputs.length !== lastInputs.length) {
|
|
4119 |
return false;
|
|
4120 |
}
|
|
4121 |
|
|
4122 |
for (var i = 0; i < newInputs.length; i++) {
|
|
4123 |
if (newInputs[i] !== lastInputs[i]) {
|
|
4124 |
return false;
|
|
4125 |
}
|
|
4126 |
}
|
|
4127 |
|
|
4128 |
return true;
|
|
4129 |
}
|
|
4130 |
|
|
4131 |
function useMemoOne(getResult, inputs) {
|
|
4132 |
var initial = (0,external_React_.useState)(function () {
|
|
4133 |
return {
|
|
4134 |
inputs: inputs,
|
|
4135 |
result: getResult()
|
|
4136 |
};
|
|
4137 |
})[0];
|
|
4138 |
var isFirstRun = (0,external_React_.useRef)(true);
|
|
4139 |
var committed = (0,external_React_.useRef)(initial);
|
|
4140 |
var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs));
|
|
4141 |
var cache = useCache ? committed.current : {
|
|
4142 |
inputs: inputs,
|
|
4143 |
result: getResult()
|
|
4144 |
};
|
|
4145 |
(0,external_React_.useEffect)(function () {
|
|
4146 |
isFirstRun.current = false;
|
|
4147 |
committed.current = cache;
|
|
4148 |
}, [cache]);
|
|
4149 |
return cache.result;
|
|
4150 |
}
|
|
4151 |
function useCallbackOne(callback, inputs) {
|
|
4152 |
return useMemoOne(function () {
|
|
4153 |
return callback;
|
|
4154 |
}, inputs);
|
|
4155 |
}
|
|
4156 |
var useMemo = (/* unused pure expression or super */ null && (useMemoOne));
|
|
4157 |
var useCallback = (/* unused pure expression or super */ null && (useCallbackOne));
|
|
4158 |
|
|
4159 |
|
|
4160 |
|
|
4161 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-debounce/index.js
|
|
4162 |
/**
|
|
4163 |
* External dependencies
|
|
4164 |
*/
|
|
4165 |
|
|
4166 |
|
|
4167 |
/**
|
|
4168 |
* WordPress dependencies
|
|
4169 |
*/
|
|
4170 |
|
|
4171 |
|
|
4172 |
/* eslint-disable jsdoc/valid-types */
|
|
4173 |
|
|
4174 |
/**
|
|
4175 |
* Debounces a function with Lodash's `debounce`. A new debounced function will
|
|
4176 |
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
4177 |
* including the function to debounce, so please wrap functions created on
|
|
4178 |
* render in components in `useCallback`.
|
|
4179 |
*
|
|
4180 |
* @see https://docs-lodash.com/v4/debounce/
|
|
4181 |
*
|
|
4182 |
* @template {(...args: any[]) => void} TFunc
|
|
4183 |
*
|
|
4184 |
* @param {TFunc} fn The function to debounce.
|
|
4185 |
* @param {number} [wait] The number of milliseconds to delay.
|
|
4186 |
* @param {import('lodash').DebounceSettings} [options] The options object.
|
|
4187 |
* @return {import('lodash').DebouncedFunc<TFunc>} Debounced function.
|
|
4188 |
*/
|
|
4189 |
|
|
4190 |
function useDebounce(fn, wait, options) {
|
|
4191 |
/* eslint-enable jsdoc/valid-types */
|
|
4192 |
const debounced = useMemoOne(() => (0,external_lodash_namespaceObject.debounce)(fn, wait, options), [fn, wait, options]);
|
|
4193 |
(0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]);
|
|
4194 |
return debounced;
|
|
4195 |
}
|
|
4196 |
|
|
4197 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-throttle/index.js
|
|
4198 |
/**
|
|
4199 |
* External dependencies
|
|
4200 |
*/
|
|
4201 |
|
|
4202 |
|
|
4203 |
/**
|
|
4204 |
* WordPress dependencies
|
|
4205 |
*/
|
|
4206 |
|
|
4207 |
|
|
4208 |
/**
|
|
4209 |
* Throttles a function with Lodash's `throttle`. A new throttled function will
|
|
4210 |
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
4211 |
* including the function to throttle, so please wrap functions created on
|
|
4212 |
* render in components in `useCallback`.
|
|
4213 |
*
|
|
4214 |
* @see https://docs-lodash.com/v4/throttle/
|
|
4215 |
*
|
|
4216 |
* @template {(...args: any[]) => void} TFunc
|
|
4217 |
*
|
|
4218 |
* @param {TFunc} fn The function to throttle.
|
|
4219 |
* @param {number} [wait] The number of milliseconds to throttle invocations to.
|
|
4220 |
* @param {import('lodash').ThrottleSettings} [options] The options object. See linked documentation for details.
|
|
4221 |
* @return {import('lodash').DebouncedFunc<TFunc>} Throttled function.
|
|
4222 |
*/
|
|
4223 |
|
|
4224 |
function useThrottle(fn, wait, options) {
|
|
4225 |
const throttled = useMemoOne(() => (0,external_lodash_namespaceObject.throttle)(fn, wait, options), [fn, wait, options]);
|
|
4226 |
(0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]);
|
|
4227 |
return throttled;
|
|
4228 |
}
|
|
4229 |
|
|
4230 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-drop-zone/index.js
|
|
4231 |
/**
|
|
4232 |
* WordPress dependencies
|
|
4233 |
*/
|
|
4234 |
|
|
4235 |
/**
|
|
4236 |
* Internal dependencies
|
|
4237 |
*/
|
|
4238 |
|
|
4239 |
|
|
4240 |
/* eslint-disable jsdoc/valid-types */
|
|
4241 |
|
|
4242 |
/**
|
|
4243 |
* @template T
|
|
4244 |
* @param {T} value
|
|
4245 |
* @return {import('react').MutableRefObject<T|null>} A ref with the value.
|
|
4246 |
*/
|
|
4247 |
|
|
4248 |
function useFreshRef(value) {
|
|
4249 |
/* eslint-enable jsdoc/valid-types */
|
|
4250 |
|
|
4251 |
/* eslint-disable jsdoc/no-undefined-types */
|
|
4252 |
|
|
4253 |
/** @type {import('react').MutableRefObject<T>} */
|
|
4254 |
|
|
4255 |
/* eslint-enable jsdoc/no-undefined-types */
|
|
4256 |
// Disable reason: We're doing something pretty JavaScript-y here where the
|
|
4257 |
// ref will always have a current value that is not null or undefined but it
|
|
4258 |
// needs to start as undefined. We don't want to change the return type so
|
|
4259 |
// it's easier to just ts-ignore this specific line that's complaining about
|
|
4260 |
// undefined not being part of T.
|
|
4261 |
// @ts-ignore
|
|
4262 |
const ref = (0,external_wp_element_namespaceObject.useRef)();
|
|
4263 |
ref.current = value;
|
|
4264 |
return ref;
|
|
4265 |
}
|
|
4266 |
/**
|
|
4267 |
* A hook to facilitate drag and drop handling.
|
|
4268 |
*
|
|
4269 |
* @param {Object} props Named parameters.
|
|
4270 |
* @param {boolean} props.isDisabled Whether or not to disable the drop zone.
|
|
4271 |
* @param {(e: DragEvent) => void} props.onDragStart Called when dragging has started.
|
|
4272 |
* @param {(e: DragEvent) => void} props.onDragEnter Called when the zone is entered.
|
|
4273 |
* @param {(e: DragEvent) => void} props.onDragOver Called when the zone is moved within.
|
|
4274 |
* @param {(e: DragEvent) => void} props.onDragLeave Called when the zone is left.
|
|
4275 |
* @param {(e: MouseEvent) => void} props.onDragEnd Called when dragging has ended.
|
|
4276 |
* @param {(e: DragEvent) => void} props.onDrop Called when dropping in the zone.
|
|
4277 |
*
|
|
4278 |
* @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.
|
|
4279 |
*/
|
|
4280 |
|
|
4281 |
|
|
4282 |
function useDropZone(_ref) {
|
|
4283 |
let {
|
|
4284 |
isDisabled,
|
|
4285 |
onDrop: _onDrop,
|
|
4286 |
onDragStart: _onDragStart,
|
|
4287 |
onDragEnter: _onDragEnter,
|
|
4288 |
onDragLeave: _onDragLeave,
|
|
4289 |
onDragEnd: _onDragEnd,
|
|
4290 |
onDragOver: _onDragOver
|
|
4291 |
} = _ref;
|
|
4292 |
const onDropRef = useFreshRef(_onDrop);
|
|
4293 |
const onDragStartRef = useFreshRef(_onDragStart);
|
|
4294 |
const onDragEnterRef = useFreshRef(_onDragEnter);
|
|
4295 |
const onDragLeaveRef = useFreshRef(_onDragLeave);
|
|
4296 |
const onDragEndRef = useFreshRef(_onDragEnd);
|
|
4297 |
const onDragOverRef = useFreshRef(_onDragOver);
|
|
4298 |
return useRefEffect(element => {
|
|
4299 |
if (isDisabled) {
|
|
4300 |
return;
|
|
4301 |
}
|
|
4302 |
|
|
4303 |
let isDragging = false;
|
|
4304 |
const {
|
|
4305 |
ownerDocument
|
|
4306 |
} = element;
|
|
4307 |
/**
|
|
4308 |
* Checks if an element is in the drop zone.
|
|
4309 |
*
|
|
4310 |
* @param {EventTarget|null} targetToCheck
|
|
4311 |
*
|
|
4312 |
* @return {boolean} True if in drop zone, false if not.
|
|
4313 |
*/
|
|
4314 |
|
|
4315 |
function isElementInZone(targetToCheck) {
|
|
4316 |
const {
|
|
4317 |
defaultView
|
|
4318 |
} = ownerDocument;
|
|
4319 |
|
|
4320 |
if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) {
|
|
4321 |
return false;
|
|
4322 |
}
|
|
4323 |
/** @type {HTMLElement|null} */
|
|
4324 |
|
|
4325 |
|
|
4326 |
let elementToCheck = targetToCheck;
|
|
4327 |
|
|
4328 |
do {
|
|
4329 |
if (elementToCheck.dataset.isDropZone) {
|
|
4330 |
return elementToCheck === element;
|
|
4331 |
}
|
|
4332 |
} while (elementToCheck = elementToCheck.parentElement);
|
|
4333 |
|
|
4334 |
return false;
|
|
4335 |
}
|
|
4336 |
|
|
4337 |
function maybeDragStart(
|
|
4338 |
/** @type {DragEvent} */
|
|
4339 |
event) {
|
|
4340 |
if (isDragging) {
|
|
4341 |
return;
|
|
4342 |
}
|
|
4343 |
|
|
4344 |
isDragging = true;
|
|
4345 |
ownerDocument.removeEventListener('dragenter', maybeDragStart); // Note that `dragend` doesn't fire consistently for file and
|
|
4346 |
// HTML drag events where the drag origin is outside the browser
|
|
4347 |
// window. In Firefox it may also not fire if the originating
|
|
4348 |
// node is removed.
|
|
4349 |
|
|
4350 |
ownerDocument.addEventListener('dragend', maybeDragEnd);
|
|
4351 |
ownerDocument.addEventListener('mousemove', maybeDragEnd);
|
|
4352 |
|
|
4353 |
if (onDragStartRef.current) {
|
|
4354 |
onDragStartRef.current(event);
|
|
4355 |
}
|
|
4356 |
}
|
|
4357 |
|
|
4358 |
function onDragEnter(
|
|
4359 |
/** @type {DragEvent} */
|
|
4360 |
event) {
|
|
4361 |
event.preventDefault(); // The `dragenter` event will also fire when entering child
|
|
4362 |
// elements, but we only want to call `onDragEnter` when
|
|
4363 |
// entering the drop zone, which means the `relatedTarget`
|
|
4364 |
// (element that has been left) should be outside the drop zone.
|
|
4365 |
|
|
4366 |
if (element.contains(
|
|
4367 |
/** @type {Node} */
|
|
4368 |
event.relatedTarget)) {
|
|
4369 |
return;
|
|
4370 |
}
|
|
4371 |
|
|
4372 |
if (onDragEnterRef.current) {
|
|
4373 |
onDragEnterRef.current(event);
|
|
4374 |
}
|
|
4375 |
}
|
|
4376 |
|
|
4377 |
function onDragOver(
|
|
4378 |
/** @type {DragEvent} */
|
|
4379 |
event) {
|
|
4380 |
// Only call onDragOver for the innermost hovered drop zones.
|
|
4381 |
if (!event.defaultPrevented && onDragOverRef.current) {
|
|
4382 |
onDragOverRef.current(event);
|
|
4383 |
} // Prevent the browser default while also signalling to parent
|
|
4384 |
// drop zones that `onDragOver` is already handled.
|
|
4385 |
|
|
4386 |
|
|
4387 |
event.preventDefault();
|
|
4388 |
}
|
|
4389 |
|
|
4390 |
function onDragLeave(
|
|
4391 |
/** @type {DragEvent} */
|
|
4392 |
event) {
|
|
4393 |
// The `dragleave` event will also fire when leaving child
|
|
4394 |
// elements, but we only want to call `onDragLeave` when
|
|
4395 |
// leaving the drop zone, which means the `relatedTarget`
|
|
4396 |
// (element that has been entered) should be outside the drop
|
|
4397 |
// zone.
|
|
4398 |
if (isElementInZone(event.relatedTarget)) {
|
|
4399 |
return;
|
|
4400 |
}
|
|
4401 |
|
|
4402 |
if (onDragLeaveRef.current) {
|
|
4403 |
onDragLeaveRef.current(event);
|
|
4404 |
}
|
|
4405 |
}
|
|
4406 |
|
|
4407 |
function onDrop(
|
|
4408 |
/** @type {DragEvent} */
|
|
4409 |
event) {
|
|
4410 |
// Don't handle drop if an inner drop zone already handled it.
|
|
4411 |
if (event.defaultPrevented) {
|
|
4412 |
return;
|
|
4413 |
} // Prevent the browser default while also signalling to parent
|
|
4414 |
// drop zones that `onDrop` is already handled.
|
|
4415 |
|
|
4416 |
|
|
4417 |
event.preventDefault(); // This seemingly useless line has been shown to resolve a
|
|
4418 |
// Safari issue where files dragged directly from the dock are
|
|
4419 |
// not recognized.
|
|
4420 |
// eslint-disable-next-line no-unused-expressions
|
|
4421 |
|
|
4422 |
event.dataTransfer && event.dataTransfer.files.length;
|
|
4423 |
|
|
4424 |
if (onDropRef.current) {
|
|
4425 |
onDropRef.current(event);
|
|
4426 |
}
|
|
4427 |
|
|
4428 |
maybeDragEnd(event);
|
|
4429 |
}
|
|
4430 |
|
|
4431 |
function maybeDragEnd(
|
|
4432 |
/** @type {MouseEvent} */
|
|
4433 |
event) {
|
|
4434 |
if (!isDragging) {
|
|
4435 |
return;
|
|
4436 |
}
|
|
4437 |
|
|
4438 |
isDragging = false;
|
|
4439 |
ownerDocument.addEventListener('dragenter', maybeDragStart);
|
|
4440 |
ownerDocument.removeEventListener('dragend', maybeDragEnd);
|
|
4441 |
ownerDocument.removeEventListener('mousemove', maybeDragEnd);
|
|
4442 |
|
|
4443 |
if (onDragEndRef.current) {
|
|
4444 |
onDragEndRef.current(event);
|
|
4445 |
}
|
|
4446 |
}
|
|
4447 |
|
|
4448 |
element.dataset.isDropZone = 'true';
|
|
4449 |
element.addEventListener('drop', onDrop);
|
|
4450 |
element.addEventListener('dragenter', onDragEnter);
|
|
4451 |
element.addEventListener('dragover', onDragOver);
|
|
4452 |
element.addEventListener('dragleave', onDragLeave); // The `dragstart` event doesn't fire if the drag started outside
|
|
4453 |
// the document.
|
|
4454 |
|
|
4455 |
ownerDocument.addEventListener('dragenter', maybeDragStart);
|
|
4456 |
return () => {
|
|
4457 |
onDropRef.current = null;
|
|
4458 |
onDragStartRef.current = null;
|
|
4459 |
onDragEnterRef.current = null;
|
|
4460 |
onDragLeaveRef.current = null;
|
|
4461 |
onDragEndRef.current = null;
|
|
4462 |
onDragOverRef.current = null;
|
|
4463 |
delete element.dataset.isDropZone;
|
|
4464 |
element.removeEventListener('drop', onDrop);
|
|
4465 |
element.removeEventListener('dragenter', onDragEnter);
|
|
4466 |
element.removeEventListener('dragover', onDragOver);
|
|
4467 |
element.removeEventListener('dragleave', onDragLeave);
|
|
4468 |
ownerDocument.removeEventListener('dragend', maybeDragEnd);
|
|
4469 |
ownerDocument.removeEventListener('mousemove', maybeDragEnd);
|
|
4470 |
ownerDocument.addEventListener('dragenter', maybeDragStart);
|
|
4471 |
};
|
|
4472 |
}, [isDisabled]);
|
|
4473 |
}
|
|
4474 |
|
|
4475 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focusable-iframe/index.js
|
|
4476 |
/**
|
|
4477 |
* Internal dependencies
|
|
4478 |
*/
|
|
4479 |
|
|
4480 |
/**
|
|
4481 |
* Dispatches a bubbling focus event when the iframe receives focus. Use
|
|
4482 |
* `onFocus` as usual on the iframe or a parent element.
|
|
4483 |
*
|
|
4484 |
* @return {Object} Ref to pass to the iframe.
|
|
4485 |
*/
|
|
4486 |
|
|
4487 |
function useFocusableIframe() {
|
|
4488 |
return useRefEffect(element => {
|
|
4489 |
const {
|
|
4490 |
ownerDocument
|
|
4491 |
} = element;
|
|
4492 |
if (!ownerDocument) return;
|
|
4493 |
const {
|
|
4494 |
defaultView
|
|
4495 |
} = ownerDocument;
|
|
4496 |
if (!defaultView) return;
|
|
4497 |
/**
|
|
4498 |
* Checks whether the iframe is the activeElement, inferring that it has
|
|
4499 |
* then received focus, and dispatches a focus event.
|
|
4500 |
*/
|
|
4501 |
|
|
4502 |
function checkFocus() {
|
|
4503 |
if (ownerDocument && ownerDocument.activeElement === element) {
|
|
4504 |
/** @type {HTMLElement} */
|
|
4505 |
element.focus();
|
|
4506 |
}
|
|
4507 |
}
|
|
4508 |
|
|
4509 |
defaultView.addEventListener('blur', checkFocus);
|
|
4510 |
return () => {
|
|
4511 |
defaultView.removeEventListener('blur', checkFocus);
|
|
4512 |
};
|
|
4513 |
}, []);
|
|
4514 |
}
|
|
4515 |
|
|
4516 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-fixed-window-list/index.js
|
|
4517 |
/**
|
|
4518 |
* External dependencies
|
|
4519 |
*/
|
|
4520 |
|
|
4521 |
/**
|
|
4522 |
* WordPress dependencies
|
|
4523 |
*/
|
|
4524 |
|
|
4525 |
|
|
4526 |
|
|
4527 |
|
|
4528 |
const DEFAULT_INIT_WINDOW_SIZE = 30;
|
|
4529 |
/**
|
|
4530 |
* @typedef {Object} WPFixedWindowList
|
|
4531 |
*
|
|
4532 |
* @property {number} visibleItems Items visible in the current viewport
|
|
4533 |
* @property {number} start Start index of the window
|
|
4534 |
* @property {number} end End index of the window
|
|
4535 |
* @property {(index:number)=>boolean} itemInView Returns true if item is in the window
|
|
4536 |
*/
|
|
4537 |
|
|
4538 |
/**
|
|
4539 |
* @typedef {Object} WPFixedWindowListOptions
|
|
4540 |
*
|
|
4541 |
* @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.
|
|
4542 |
* @property {boolean} [useWindowing] When false avoids calculating the window size
|
|
4543 |
* @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.
|
|
4544 |
*/
|
|
4545 |
|
|
4546 |
/**
|
|
4547 |
*
|
|
4548 |
* @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.
|
|
4549 |
* @param { number } itemHeight Fixed item height in pixels
|
|
4550 |
* @param { number } totalItems Total items in list
|
|
4551 |
* @param { WPFixedWindowListOptions } [options] Options object
|
|
4552 |
* @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter
|
|
4553 |
*/
|
|
4554 |
|
|
4555 |
function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
|
|
4556 |
var _options$initWindowSi, _options$useWindowing;
|
|
4557 |
|
|
4558 |
const initWindowSize = (_options$initWindowSi = options === null || options === void 0 ? void 0 : options.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE;
|
|
4559 |
const useWindowing = (_options$useWindowing = options === null || options === void 0 ? void 0 : options.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true;
|
|
4560 |
const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({
|
|
4561 |
visibleItems: initWindowSize,
|
|
4562 |
start: 0,
|
|
4563 |
end: initWindowSize,
|
|
4564 |
itemInView: (
|
|
4565 |
/** @type {number} */
|
|
4566 |
index) => {
|
|
4567 |
return index >= 0 && index <= initWindowSize;
|
|
4568 |
}
|
|
4569 |
});
|
|
4570 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
|
|
4571 |
var _scrollContainer$owne, _scrollContainer$owne2, _scrollContainer$owne3, _scrollContainer$owne4;
|
|
4572 |
|
|
4573 |
if (!useWindowing) {
|
|
4574 |
return;
|
|
4575 |
}
|
|
4576 |
|
|
4577 |
const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current);
|
|
4578 |
|
|
4579 |
const measureWindow = (
|
|
4580 |
/** @type {boolean | undefined} */
|
|
4581 |
initRender) => {
|
|
4582 |
var _options$windowOversc;
|
|
4583 |
|
|
4584 |
if (!scrollContainer) {
|
|
4585 |
return;
|
|
4586 |
}
|
|
4587 |
|
|
4588 |
const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); // Aim to keep opening list view fast, afterward we can optimize for scrolling.
|
|
4589 |
|
|
4590 |
const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options === null || options === void 0 ? void 0 : options.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems;
|
|
4591 |
const firstViewableIndex = Math.floor(scrollContainer.scrollTop / itemHeight);
|
|
4592 |
const start = Math.max(0, firstViewableIndex - windowOverscan);
|
|
4593 |
const end = Math.min(totalItems - 1, firstViewableIndex + visibleItems + windowOverscan);
|
|
4594 |
setFixedListWindow(lastWindow => {
|
|
4595 |
const nextWindow = {
|
|
4596 |
visibleItems,
|
|
4597 |
start,
|
|
4598 |
end,
|
|
4599 |
itemInView: (
|
|
4600 |
/** @type {number} */
|
|
4601 |
index) => {
|
|
4602 |
return start <= index && index <= end;
|
|
4603 |
}
|
|
4604 |
};
|
|
4605 |
|
|
4606 |
if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) {
|
|
4607 |
return nextWindow;
|
|
4608 |
}
|
|
4609 |
|
|
4610 |
return lastWindow;
|
|
4611 |
});
|
|
4612 |
};
|
|
4613 |
|
|
4614 |
measureWindow(true);
|
|
4615 |
const debounceMeasureList = (0,external_lodash_namespaceObject.debounce)(() => {
|
|
4616 |
measureWindow();
|
|
4617 |
}, 16);
|
|
4618 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener('scroll', debounceMeasureList);
|
|
4619 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne = scrollContainer.ownerDocument) === null || _scrollContainer$owne === void 0 ? void 0 : (_scrollContainer$owne2 = _scrollContainer$owne.defaultView) === null || _scrollContainer$owne2 === void 0 ? void 0 : _scrollContainer$owne2.addEventListener('resize', debounceMeasureList);
|
|
4620 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne3 = scrollContainer.ownerDocument) === null || _scrollContainer$owne3 === void 0 ? void 0 : (_scrollContainer$owne4 = _scrollContainer$owne3.defaultView) === null || _scrollContainer$owne4 === void 0 ? void 0 : _scrollContainer$owne4.addEventListener('resize', debounceMeasureList);
|
|
4621 |
return () => {
|
|
4622 |
var _scrollContainer$owne5, _scrollContainer$owne6;
|
|
4623 |
|
|
4624 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('scroll', debounceMeasureList);
|
|
4625 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne5 = scrollContainer.ownerDocument) === null || _scrollContainer$owne5 === void 0 ? void 0 : (_scrollContainer$owne6 = _scrollContainer$owne5.defaultView) === null || _scrollContainer$owne6 === void 0 ? void 0 : _scrollContainer$owne6.removeEventListener('resize', debounceMeasureList);
|
|
4626 |
};
|
|
4627 |
}, [itemHeight, elementRef, totalItems]);
|
|
4628 |
(0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
|
|
4629 |
var _scrollContainer$owne7, _scrollContainer$owne8;
|
|
4630 |
|
|
4631 |
if (!useWindowing) {
|
|
4632 |
return;
|
|
4633 |
}
|
|
4634 |
|
|
4635 |
const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current);
|
|
4636 |
|
|
4637 |
const handleKeyDown = (
|
|
4638 |
/** @type {KeyboardEvent} */
|
|
4639 |
event) => {
|
|
4640 |
switch (event.keyCode) {
|
|
4641 |
case external_wp_keycodes_namespaceObject.HOME:
|
|
4642 |
{
|
|
4643 |
return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
|
|
4644 |
top: 0
|
|
4645 |
});
|
|
4646 |
}
|
|
4647 |
|
|
4648 |
case external_wp_keycodes_namespaceObject.END:
|
|
4649 |
{
|
|
4650 |
return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
|
|
4651 |
top: totalItems * itemHeight
|
|
4652 |
});
|
|
4653 |
}
|
|
4654 |
|
|
4655 |
case external_wp_keycodes_namespaceObject.PAGEUP:
|
|
4656 |
{
|
|
4657 |
return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
|
|
4658 |
top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight
|
|
4659 |
});
|
|
4660 |
}
|
|
4661 |
|
|
4662 |
case external_wp_keycodes_namespaceObject.PAGEDOWN:
|
|
4663 |
{
|
|
4664 |
return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
|
|
4665 |
top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight
|
|
4666 |
});
|
|
4667 |
}
|
|
4668 |
}
|
|
4669 |
};
|
|
4670 |
|
|
4671 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne7 = scrollContainer.ownerDocument) === null || _scrollContainer$owne7 === void 0 ? void 0 : (_scrollContainer$owne8 = _scrollContainer$owne7.defaultView) === null || _scrollContainer$owne8 === void 0 ? void 0 : _scrollContainer$owne8.addEventListener('keydown', handleKeyDown);
|
|
4672 |
return () => {
|
|
4673 |
var _scrollContainer$owne9, _scrollContainer$owne10;
|
|
4674 |
|
|
4675 |
scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne9 = scrollContainer.ownerDocument) === null || _scrollContainer$owne9 === void 0 ? void 0 : (_scrollContainer$owne10 = _scrollContainer$owne9.defaultView) === null || _scrollContainer$owne10 === void 0 ? void 0 : _scrollContainer$owne10.removeEventListener('keydown', handleKeyDown);
|
|
4676 |
};
|
|
4677 |
}, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems]);
|
|
4678 |
return [fixedListWindow, setFixedListWindow];
|
|
4679 |
}
|
|
4680 |
|
|
4681 |
;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/index.js
|
|
4682 |
// Utils.
|
|
4683 |
// Compose helper (aliased flowRight from Lodash)
|
|
4684 |
|
|
4685 |
// Higher-order components.
|
|
4686 |
|
|
4687 |
|
|
4688 |
|
|
4689 |
|
|
4690 |
|
|
4691 |
|
|
4692 |
// Hooks.
|
|
4693 |
|
|
4694 |
|
|
4695 |
|
|
4696 |
|
|
4697 |
|
|
4698 |
|
|
4699 |
|
|
4700 |
|
|
4701 |
|
|
4702 |
|
|
4703 |
|
|
4704 |
|
|
4705 |
|
|
4706 |
|
|
4707 |
|
|
4708 |
|
|
4709 |
|
|
4710 |
|
|
4711 |
|
|
4712 |
|
|
4713 |
|
|
4714 |
|
|
4715 |
|
|
4716 |
|
|
4717 |
|
|
4718 |
|
|
4719 |
|
|
4720 |
|
|
4721 |
}();
|
|
4722 |
(window.wp = window.wp || {}).compose = __webpack_exports__;
|
|
4723 |
/******/ })()
|
|
4724 |
; |