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