downshift 3.4.7 → 3.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/downshift.cjs.js +903 -891
- package/dist/downshift.esm.js +903 -891
- package/dist/downshift.native.cjs.js +841 -829
- package/dist/downshift.umd.js +1376 -1299
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/package.json +4 -1
- package/preact/dist/downshift.cjs.js +903 -892
- package/preact/dist/downshift.esm.js +903 -892
- package/preact/dist/downshift.umd.js +1086 -1050
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -1
- package/preact/dist/downshift.umd.min.js.map +1 -1
package/dist/downshift.umd.js
CHANGED
|
@@ -223,212 +223,240 @@
|
|
|
223
223
|
|
|
224
224
|
var reactIs_development = createCommonjsModule(function (module, exports) {
|
|
225
225
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
226
|
+
{
|
|
227
|
+
(function () {
|
|
228
|
+
|
|
229
|
+
Object.defineProperty(exports, '__esModule', {
|
|
230
|
+
value: true
|
|
231
|
+
}); // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
232
|
+
// nor polyfill, then a plain number is used for performance.
|
|
233
|
+
|
|
234
|
+
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
|
235
|
+
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
|
|
236
|
+
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
|
237
|
+
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
|
238
|
+
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
|
239
|
+
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
|
240
|
+
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
|
241
|
+
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary
|
|
242
|
+
// (unstable) APIs that have been removed. Can we remove the symbols?
|
|
243
|
+
|
|
244
|
+
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
|
|
245
|
+
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
|
246
|
+
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
|
247
|
+
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
|
248
|
+
var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8;
|
|
249
|
+
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
|
250
|
+
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
|
251
|
+
var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5;
|
|
252
|
+
var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6;
|
|
253
|
+
|
|
254
|
+
function isValidElementType(type) {
|
|
255
|
+
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
|
256
|
+
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Forked from fbjs/warning:
|
|
260
|
+
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
|
261
|
+
*
|
|
262
|
+
* Only change is we use console.warn instead of console.error,
|
|
263
|
+
* and do nothing when 'console' is not supported.
|
|
264
|
+
* This really simplifies the code.
|
|
265
|
+
* ---
|
|
266
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
267
|
+
* This can be used to log issues in development environments in critical
|
|
268
|
+
* paths. Removing the logging code for production environments will keep the
|
|
269
|
+
* same logic and follow the same code paths.
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
var lowPriorityWarning = function () {};
|
|
251
274
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
* and do nothing when 'console' is not supported.
|
|
258
|
-
* This really simplifies the code.
|
|
259
|
-
* ---
|
|
260
|
-
* Similar to invariant but only logs a warning if the condition is not met.
|
|
261
|
-
* This can be used to log issues in development environments in critical
|
|
262
|
-
* paths. Removing the logging code for production environments will keep the
|
|
263
|
-
* same logic and follow the same code paths.
|
|
264
|
-
*/
|
|
265
|
-
var lowPriorityWarning = function () {};
|
|
275
|
+
{
|
|
276
|
+
var printWarning = function (format) {
|
|
277
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
278
|
+
args[_key - 1] = arguments[_key];
|
|
279
|
+
}
|
|
266
280
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
281
|
+
var argIndex = 0;
|
|
282
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
283
|
+
return args[argIndex++];
|
|
284
|
+
});
|
|
272
285
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
});
|
|
286
|
+
if (typeof console !== 'undefined') {
|
|
287
|
+
console.warn(message);
|
|
288
|
+
}
|
|
277
289
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
290
|
+
try {
|
|
291
|
+
// --- Welcome to debugging React ---
|
|
292
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
293
|
+
// to find the callsite that caused this warning to fire.
|
|
294
|
+
throw new Error(message);
|
|
295
|
+
} catch (x) {}
|
|
296
|
+
};
|
|
281
297
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
throw new Error(message);
|
|
287
|
-
} catch (x) {}
|
|
288
|
-
};
|
|
298
|
+
lowPriorityWarning = function (condition, format) {
|
|
299
|
+
if (format === undefined) {
|
|
300
|
+
throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
301
|
+
}
|
|
289
302
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
303
|
+
if (!condition) {
|
|
304
|
+
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
305
|
+
args[_key2 - 2] = arguments[_key2];
|
|
306
|
+
}
|
|
294
307
|
|
|
295
|
-
|
|
296
|
-
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
297
|
-
args[_key2 - 2] = arguments[_key2];
|
|
308
|
+
printWarning.apply(undefined, [format].concat(args));
|
|
298
309
|
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
var lowPriorityWarning$1 = lowPriorityWarning;
|
|
299
313
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
var lowPriorityWarning$1 = lowPriorityWarning;
|
|
305
|
-
|
|
306
|
-
function typeOf(object) {
|
|
307
|
-
if (typeof object === 'object' && object !== null) {
|
|
308
|
-
var $$typeof = object.$$typeof;
|
|
309
|
-
|
|
310
|
-
switch ($$typeof) {
|
|
311
|
-
case REACT_ELEMENT_TYPE:
|
|
312
|
-
var type = object.type;
|
|
313
|
-
|
|
314
|
-
switch (type) {
|
|
315
|
-
case REACT_ASYNC_MODE_TYPE:
|
|
316
|
-
case REACT_CONCURRENT_MODE_TYPE:
|
|
317
|
-
case REACT_FRAGMENT_TYPE:
|
|
318
|
-
case REACT_PROFILER_TYPE:
|
|
319
|
-
case REACT_STRICT_MODE_TYPE:
|
|
320
|
-
case REACT_SUSPENSE_TYPE:
|
|
321
|
-
return type;
|
|
322
|
-
|
|
323
|
-
default:
|
|
324
|
-
var $$typeofType = type && type.$$typeof;
|
|
325
|
-
|
|
326
|
-
switch ($$typeofType) {
|
|
327
|
-
case REACT_CONTEXT_TYPE:
|
|
328
|
-
case REACT_FORWARD_REF_TYPE:
|
|
329
|
-
case REACT_PROVIDER_TYPE:
|
|
330
|
-
return $$typeofType;
|
|
331
|
-
|
|
332
|
-
default:
|
|
333
|
-
return $$typeof;
|
|
334
|
-
}
|
|
314
|
+
function typeOf(object) {
|
|
315
|
+
if (typeof object === 'object' && object !== null) {
|
|
316
|
+
var $$typeof = object.$$typeof;
|
|
335
317
|
|
|
336
|
-
|
|
318
|
+
switch ($$typeof) {
|
|
319
|
+
case REACT_ELEMENT_TYPE:
|
|
320
|
+
var type = object.type;
|
|
337
321
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
322
|
+
switch (type) {
|
|
323
|
+
case REACT_ASYNC_MODE_TYPE:
|
|
324
|
+
case REACT_CONCURRENT_MODE_TYPE:
|
|
325
|
+
case REACT_FRAGMENT_TYPE:
|
|
326
|
+
case REACT_PROFILER_TYPE:
|
|
327
|
+
case REACT_STRICT_MODE_TYPE:
|
|
328
|
+
case REACT_SUSPENSE_TYPE:
|
|
329
|
+
return type;
|
|
330
|
+
|
|
331
|
+
default:
|
|
332
|
+
var $$typeofType = type && type.$$typeof;
|
|
344
333
|
|
|
345
|
-
|
|
346
|
-
|
|
334
|
+
switch ($$typeofType) {
|
|
335
|
+
case REACT_CONTEXT_TYPE:
|
|
336
|
+
case REACT_FORWARD_REF_TYPE:
|
|
337
|
+
case REACT_PROVIDER_TYPE:
|
|
338
|
+
return $$typeofType;
|
|
347
339
|
|
|
340
|
+
default:
|
|
341
|
+
return $$typeof;
|
|
342
|
+
}
|
|
348
343
|
|
|
349
|
-
|
|
344
|
+
}
|
|
350
345
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
346
|
+
case REACT_LAZY_TYPE:
|
|
347
|
+
case REACT_MEMO_TYPE:
|
|
348
|
+
case REACT_PORTAL_TYPE:
|
|
349
|
+
return $$typeof;
|
|
350
|
+
}
|
|
356
351
|
}
|
|
357
|
-
}
|
|
358
|
-
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
|
359
|
-
}
|
|
360
352
|
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
353
|
+
return undefined;
|
|
354
|
+
} // AsyncMode is deprecated along with isAsyncMode
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
var AsyncMode = REACT_ASYNC_MODE_TYPE;
|
|
358
|
+
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
|
|
359
|
+
var ContextConsumer = REACT_CONTEXT_TYPE;
|
|
360
|
+
var ContextProvider = REACT_PROVIDER_TYPE;
|
|
361
|
+
var Element = REACT_ELEMENT_TYPE;
|
|
362
|
+
var ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
363
|
+
var Fragment = REACT_FRAGMENT_TYPE;
|
|
364
|
+
var Lazy = REACT_LAZY_TYPE;
|
|
365
|
+
var Memo = REACT_MEMO_TYPE;
|
|
366
|
+
var Portal = REACT_PORTAL_TYPE;
|
|
367
|
+
var Profiler = REACT_PROFILER_TYPE;
|
|
368
|
+
var StrictMode = REACT_STRICT_MODE_TYPE;
|
|
369
|
+
var Suspense = REACT_SUSPENSE_TYPE;
|
|
370
|
+
var hasWarnedAboutDeprecatedIsAsyncMode = false; // AsyncMode should be deprecated
|
|
371
|
+
|
|
372
|
+
function isAsyncMode(object) {
|
|
373
|
+
{
|
|
374
|
+
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
|
|
375
|
+
hasWarnedAboutDeprecatedIsAsyncMode = true;
|
|
376
|
+
lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
|
|
380
|
+
}
|
|
364
381
|
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
exports.ContextConsumer = REACT_CONTEXT_TYPE;
|
|
369
|
-
exports.ContextProvider = REACT_PROVIDER_TYPE;
|
|
370
|
-
exports.Element = REACT_ELEMENT_TYPE;
|
|
371
|
-
exports.ForwardRef = REACT_FORWARD_REF_TYPE;
|
|
372
|
-
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
373
|
-
exports.Lazy = REACT_LAZY_TYPE;
|
|
374
|
-
exports.Memo = REACT_MEMO_TYPE;
|
|
375
|
-
exports.Portal = REACT_PORTAL_TYPE;
|
|
376
|
-
exports.Profiler = REACT_PROFILER_TYPE;
|
|
377
|
-
exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
|
378
|
-
exports.Suspense = REACT_SUSPENSE_TYPE;
|
|
379
|
-
|
|
380
|
-
exports.isValidElementType = function (type) {
|
|
381
|
-
return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
|
|
382
|
-
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE);
|
|
383
|
-
};
|
|
382
|
+
function isConcurrentMode(object) {
|
|
383
|
+
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
|
|
384
|
+
}
|
|
384
385
|
|
|
385
|
-
|
|
386
|
-
|
|
386
|
+
function isContextConsumer(object) {
|
|
387
|
+
return typeOf(object) === REACT_CONTEXT_TYPE;
|
|
388
|
+
}
|
|
387
389
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
390
|
+
function isContextProvider(object) {
|
|
391
|
+
return typeOf(object) === REACT_PROVIDER_TYPE;
|
|
392
|
+
}
|
|
391
393
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
394
|
+
function isElement(object) {
|
|
395
|
+
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
396
|
+
}
|
|
395
397
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
398
|
+
function isForwardRef(object) {
|
|
399
|
+
return typeOf(object) === REACT_FORWARD_REF_TYPE;
|
|
400
|
+
}
|
|
399
401
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
402
|
+
function isFragment(object) {
|
|
403
|
+
return typeOf(object) === REACT_FRAGMENT_TYPE;
|
|
404
|
+
}
|
|
403
405
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
406
|
+
function isLazy(object) {
|
|
407
|
+
return typeOf(object) === REACT_LAZY_TYPE;
|
|
408
|
+
}
|
|
407
409
|
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
410
|
+
function isMemo(object) {
|
|
411
|
+
return typeOf(object) === REACT_MEMO_TYPE;
|
|
412
|
+
}
|
|
411
413
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
414
|
+
function isPortal(object) {
|
|
415
|
+
return typeOf(object) === REACT_PORTAL_TYPE;
|
|
416
|
+
}
|
|
415
417
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
function isProfiler(object) {
|
|
419
|
+
return typeOf(object) === REACT_PROFILER_TYPE;
|
|
420
|
+
}
|
|
419
421
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
422
|
+
function isStrictMode(object) {
|
|
423
|
+
return typeOf(object) === REACT_STRICT_MODE_TYPE;
|
|
424
|
+
}
|
|
423
425
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
426
|
+
function isSuspense(object) {
|
|
427
|
+
return typeOf(object) === REACT_SUSPENSE_TYPE;
|
|
428
|
+
}
|
|
427
429
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
430
|
+
exports.typeOf = typeOf;
|
|
431
|
+
exports.AsyncMode = AsyncMode;
|
|
432
|
+
exports.ConcurrentMode = ConcurrentMode;
|
|
433
|
+
exports.ContextConsumer = ContextConsumer;
|
|
434
|
+
exports.ContextProvider = ContextProvider;
|
|
435
|
+
exports.Element = Element;
|
|
436
|
+
exports.ForwardRef = ForwardRef;
|
|
437
|
+
exports.Fragment = Fragment;
|
|
438
|
+
exports.Lazy = Lazy;
|
|
439
|
+
exports.Memo = Memo;
|
|
440
|
+
exports.Portal = Portal;
|
|
441
|
+
exports.Profiler = Profiler;
|
|
442
|
+
exports.StrictMode = StrictMode;
|
|
443
|
+
exports.Suspense = Suspense;
|
|
444
|
+
exports.isValidElementType = isValidElementType;
|
|
445
|
+
exports.isAsyncMode = isAsyncMode;
|
|
446
|
+
exports.isConcurrentMode = isConcurrentMode;
|
|
447
|
+
exports.isContextConsumer = isContextConsumer;
|
|
448
|
+
exports.isContextProvider = isContextProvider;
|
|
449
|
+
exports.isElement = isElement;
|
|
450
|
+
exports.isForwardRef = isForwardRef;
|
|
451
|
+
exports.isFragment = isFragment;
|
|
452
|
+
exports.isLazy = isLazy;
|
|
453
|
+
exports.isMemo = isMemo;
|
|
454
|
+
exports.isPortal = isPortal;
|
|
455
|
+
exports.isProfiler = isProfiler;
|
|
456
|
+
exports.isStrictMode = isStrictMode;
|
|
457
|
+
exports.isSuspense = isSuspense;
|
|
458
|
+
})();
|
|
459
|
+
}
|
|
432
460
|
});
|
|
433
461
|
unwrapExports(reactIs_development);
|
|
434
462
|
var reactIs_development_1 = reactIs_development.typeOf;
|
|
@@ -462,7 +490,9 @@
|
|
|
462
490
|
|
|
463
491
|
var reactIs = createCommonjsModule(function (module) {
|
|
464
492
|
|
|
465
|
-
|
|
493
|
+
{
|
|
494
|
+
module.exports = reactIs_development;
|
|
495
|
+
}
|
|
466
496
|
});
|
|
467
497
|
var reactIs_1 = reactIs.isForwardRef;
|
|
468
498
|
|
|
@@ -533,7 +563,7 @@
|
|
|
533
563
|
}
|
|
534
564
|
}
|
|
535
565
|
|
|
536
|
-
var objectAssign = shouldUseNative() ? Object.assign : function (target) {
|
|
566
|
+
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
|
537
567
|
var from;
|
|
538
568
|
var to = toObject(target);
|
|
539
569
|
var symbols;
|
|
@@ -571,33 +601,28 @@
|
|
|
571
601
|
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
|
|
572
602
|
var ReactPropTypesSecret_1 = ReactPropTypesSecret;
|
|
573
603
|
|
|
574
|
-
/**
|
|
575
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
576
|
-
*
|
|
577
|
-
* This source code is licensed under the MIT license found in the
|
|
578
|
-
* LICENSE file in the root directory of this source tree.
|
|
579
|
-
*/
|
|
580
|
-
|
|
581
604
|
var printWarning = function () {};
|
|
582
605
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
606
|
+
{
|
|
607
|
+
var ReactPropTypesSecret$1 = ReactPropTypesSecret_1;
|
|
608
|
+
var loggedTypeFailures = {};
|
|
609
|
+
var has = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
586
610
|
|
|
587
|
-
|
|
588
|
-
|
|
611
|
+
printWarning = function (text) {
|
|
612
|
+
var message = 'Warning: ' + text;
|
|
589
613
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
614
|
+
if (typeof console !== 'undefined') {
|
|
615
|
+
console.error(message);
|
|
616
|
+
}
|
|
593
617
|
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
618
|
+
try {
|
|
619
|
+
// --- Welcome to debugging React ---
|
|
620
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
621
|
+
// to find the callsite that caused this warning to fire.
|
|
622
|
+
throw new Error(message);
|
|
623
|
+
} catch (x) {}
|
|
624
|
+
};
|
|
625
|
+
}
|
|
601
626
|
/**
|
|
602
627
|
* Assert that the values match with the type specs.
|
|
603
628
|
* Error messages are memorized and will only be shown once.
|
|
@@ -612,36 +637,38 @@
|
|
|
612
637
|
|
|
613
638
|
|
|
614
639
|
function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
try {
|
|
622
|
-
// This is intentionally an invariant that gets caught. It's the same
|
|
623
|
-
// behavior as without this statement except with a better message.
|
|
624
|
-
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
625
|
-
var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.');
|
|
626
|
-
err.name = 'Invariant Violation';
|
|
627
|
-
throw err;
|
|
628
|
-
}
|
|
640
|
+
{
|
|
641
|
+
for (var typeSpecName in typeSpecs) {
|
|
642
|
+
if (has(typeSpecs, typeSpecName)) {
|
|
643
|
+
var error; // Prop type validation may throw. In case they do, we don't want to
|
|
644
|
+
// fail the render phase where it didn't fail before. So we log it.
|
|
645
|
+
// After these have been cleaned up, we'll let them throw.
|
|
629
646
|
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
647
|
+
try {
|
|
648
|
+
// This is intentionally an invariant that gets caught. It's the same
|
|
649
|
+
// behavior as without this statement except with a better message.
|
|
650
|
+
if (typeof typeSpecs[typeSpecName] !== 'function') {
|
|
651
|
+
var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.');
|
|
652
|
+
err.name = 'Invariant Violation';
|
|
653
|
+
throw err;
|
|
654
|
+
}
|
|
634
655
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
656
|
+
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1);
|
|
657
|
+
} catch (ex) {
|
|
658
|
+
error = ex;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
if (error && !(error instanceof Error)) {
|
|
662
|
+
printWarning((componentName || 'React class') + ': type specification of ' + location + ' `' + typeSpecName + '` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).');
|
|
663
|
+
}
|
|
638
664
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
665
|
+
if (error instanceof Error && !(error.message in loggedTypeFailures)) {
|
|
666
|
+
// Only monitor this failure once because there tends to be a lot of the
|
|
667
|
+
// same error.
|
|
668
|
+
loggedTypeFailures[error.message] = true;
|
|
669
|
+
var stack = getStack ? getStack() : '';
|
|
670
|
+
printWarning('Failed ' + location + ' type: ' + error.message + (stack != null ? stack : ''));
|
|
671
|
+
}
|
|
645
672
|
}
|
|
646
673
|
}
|
|
647
674
|
}
|
|
@@ -654,36 +681,33 @@
|
|
|
654
681
|
|
|
655
682
|
|
|
656
683
|
checkPropTypes.resetWarningCache = function () {
|
|
657
|
-
|
|
684
|
+
{
|
|
685
|
+
loggedTypeFailures = {};
|
|
686
|
+
}
|
|
658
687
|
};
|
|
659
688
|
|
|
660
689
|
var checkPropTypes_1 = checkPropTypes;
|
|
661
690
|
|
|
662
|
-
/**
|
|
663
|
-
* Copyright (c) 2013-present, Facebook, Inc.
|
|
664
|
-
*
|
|
665
|
-
* This source code is licensed under the MIT license found in the
|
|
666
|
-
* LICENSE file in the root directory of this source tree.
|
|
667
|
-
*/
|
|
668
|
-
|
|
669
691
|
var has$1 = Function.call.bind(Object.prototype.hasOwnProperty);
|
|
670
692
|
|
|
671
693
|
var printWarning$1 = function () {};
|
|
672
694
|
|
|
673
|
-
|
|
674
|
-
|
|
695
|
+
{
|
|
696
|
+
printWarning$1 = function (text) {
|
|
697
|
+
var message = 'Warning: ' + text;
|
|
675
698
|
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
699
|
+
if (typeof console !== 'undefined') {
|
|
700
|
+
console.error(message);
|
|
701
|
+
}
|
|
679
702
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
703
|
+
try {
|
|
704
|
+
// --- Welcome to debugging React ---
|
|
705
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
706
|
+
// to find the callsite that caused this warning to fire.
|
|
707
|
+
throw new Error(message);
|
|
708
|
+
} catch (x) {}
|
|
709
|
+
};
|
|
710
|
+
}
|
|
687
711
|
|
|
688
712
|
function emptyFunctionThatReturnsNull() {
|
|
689
713
|
return null;
|
|
@@ -692,8 +716,7 @@
|
|
|
692
716
|
var factoryWithTypeCheckers = function (isValidElement, throwOnDirectAccess) {
|
|
693
717
|
/* global Symbol */
|
|
694
718
|
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
|
|
695
|
-
|
|
696
|
-
// Before Symbol spec.
|
|
719
|
+
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
|
|
697
720
|
|
|
698
721
|
/**
|
|
699
722
|
* Returns the iterator method function contained on the iterable object.
|
|
@@ -709,8 +732,9 @@
|
|
|
709
732
|
* @param {?object} maybeIterable
|
|
710
733
|
* @return {?function}
|
|
711
734
|
*/
|
|
735
|
+
|
|
712
736
|
function getIteratorFn(maybeIterable) {
|
|
713
|
-
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[
|
|
737
|
+
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
|
|
714
738
|
|
|
715
739
|
if (typeof iteratorFn === 'function') {
|
|
716
740
|
return iteratorFn;
|
|
@@ -775,161 +799,17 @@
|
|
|
775
799
|
object: createPrimitiveTypeChecker('object'),
|
|
776
800
|
string: createPrimitiveTypeChecker('string'),
|
|
777
801
|
symbol: createPrimitiveTypeChecker('symbol'),
|
|
778
|
-
any:
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
var propValue = props[propName];
|
|
788
|
-
|
|
789
|
-
if (!Array.isArray(propValue)) {
|
|
790
|
-
var propType = getPropType(propValue);
|
|
791
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
for (var i = 0; i < propValue.length; i++) {
|
|
795
|
-
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
|
|
796
|
-
|
|
797
|
-
if (error instanceof Error) {
|
|
798
|
-
return error;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
return null;
|
|
803
|
-
});
|
|
804
|
-
},
|
|
805
|
-
element: function () {
|
|
806
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
807
|
-
var propValue = props[propName];
|
|
808
|
-
|
|
809
|
-
if (!isValidElement(propValue)) {
|
|
810
|
-
var propType = getPropType(propValue);
|
|
811
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
return null;
|
|
815
|
-
});
|
|
816
|
-
}(),
|
|
817
|
-
elementType: function () {
|
|
818
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
819
|
-
var propValue = props[propName];
|
|
820
|
-
|
|
821
|
-
if (!reactIs.isValidElementType(propValue)) {
|
|
822
|
-
var propType = getPropType(propValue);
|
|
823
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
return null;
|
|
827
|
-
});
|
|
828
|
-
}(),
|
|
829
|
-
instanceOf: function (expectedClass) {
|
|
830
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
831
|
-
if (!(props[propName] instanceof expectedClass)) {
|
|
832
|
-
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
833
|
-
var actualClassName = getClassName(props[propName]);
|
|
834
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
835
|
-
}
|
|
836
|
-
|
|
837
|
-
return null;
|
|
838
|
-
});
|
|
839
|
-
},
|
|
840
|
-
node: function () {
|
|
841
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
842
|
-
if (!isNode(props[propName])) {
|
|
843
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
return null;
|
|
847
|
-
});
|
|
848
|
-
}(),
|
|
849
|
-
objectOf: function (typeChecker) {
|
|
850
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
851
|
-
if (typeof typeChecker !== 'function') {
|
|
852
|
-
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
var propValue = props[propName];
|
|
856
|
-
var propType = getPropType(propValue);
|
|
857
|
-
|
|
858
|
-
if (propType !== 'object') {
|
|
859
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
for (var key in propValue) {
|
|
863
|
-
if (has$1(propValue, key)) {
|
|
864
|
-
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
865
|
-
|
|
866
|
-
if (error instanceof Error) {
|
|
867
|
-
return error;
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
return null;
|
|
873
|
-
});
|
|
874
|
-
},
|
|
802
|
+
any: createAnyTypeChecker(),
|
|
803
|
+
arrayOf: createArrayOfTypeChecker,
|
|
804
|
+
element: createElementTypeChecker(),
|
|
805
|
+
elementType: createElementTypeTypeChecker(),
|
|
806
|
+
instanceOf: createInstanceTypeChecker,
|
|
807
|
+
node: createNodeChecker(),
|
|
808
|
+
objectOf: createObjectOfTypeChecker,
|
|
875
809
|
oneOf: createEnumTypeChecker,
|
|
876
810
|
oneOfType: createUnionTypeChecker,
|
|
877
|
-
shape:
|
|
878
|
-
|
|
879
|
-
var propValue = props[propName];
|
|
880
|
-
var propType = getPropType(propValue);
|
|
881
|
-
|
|
882
|
-
if (propType !== 'object') {
|
|
883
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
for (var key in shapeTypes) {
|
|
887
|
-
var checker = shapeTypes[key];
|
|
888
|
-
|
|
889
|
-
if (!checker) {
|
|
890
|
-
continue;
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
894
|
-
|
|
895
|
-
if (error) {
|
|
896
|
-
return error;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
return null;
|
|
901
|
-
});
|
|
902
|
-
},
|
|
903
|
-
exact: function (shapeTypes) {
|
|
904
|
-
return createChainableTypeChecker(function (props, propName, componentName, location, propFullName) {
|
|
905
|
-
var propValue = props[propName];
|
|
906
|
-
var propType = getPropType(propValue);
|
|
907
|
-
|
|
908
|
-
if (propType !== 'object') {
|
|
909
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
910
|
-
} // We need to check all keys in case some are required but missing from
|
|
911
|
-
// props.
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
var allKeys = objectAssign({}, props[propName], shapeTypes);
|
|
915
|
-
|
|
916
|
-
for (var key in allKeys) {
|
|
917
|
-
var checker = shapeTypes[key];
|
|
918
|
-
|
|
919
|
-
if (!checker) {
|
|
920
|
-
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' '));
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
924
|
-
|
|
925
|
-
if (error) {
|
|
926
|
-
return error;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
return null;
|
|
931
|
-
});
|
|
932
|
-
}
|
|
811
|
+
shape: createShapeTypeChecker,
|
|
812
|
+
exact: createStrictShapeTypeChecker
|
|
933
813
|
};
|
|
934
814
|
/**
|
|
935
815
|
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
@@ -969,8 +849,10 @@
|
|
|
969
849
|
PropTypeError.prototype = Error.prototype;
|
|
970
850
|
|
|
971
851
|
function createChainableTypeChecker(validate) {
|
|
972
|
-
|
|
973
|
-
|
|
852
|
+
{
|
|
853
|
+
var manualPropTypeCallCache = {};
|
|
854
|
+
var manualPropTypeWarningCount = 0;
|
|
855
|
+
}
|
|
974
856
|
|
|
975
857
|
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
976
858
|
componentName = componentName || ANONYMOUS;
|
|
@@ -1016,7 +898,7 @@
|
|
|
1016
898
|
}
|
|
1017
899
|
|
|
1018
900
|
function createPrimitiveTypeChecker(expectedType) {
|
|
1019
|
-
|
|
901
|
+
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
1020
902
|
var propValue = props[propName];
|
|
1021
903
|
var propType = getPropType(propValue);
|
|
1022
904
|
|
|
@@ -1029,21 +911,100 @@
|
|
|
1029
911
|
}
|
|
1030
912
|
|
|
1031
913
|
return null;
|
|
1032
|
-
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
return createChainableTypeChecker(validate);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
function createAnyTypeChecker() {
|
|
920
|
+
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
function createArrayOfTypeChecker(typeChecker) {
|
|
924
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
925
|
+
if (typeof typeChecker !== 'function') {
|
|
926
|
+
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
var propValue = props[propName];
|
|
930
|
+
|
|
931
|
+
if (!Array.isArray(propValue)) {
|
|
932
|
+
var propType = getPropType(propValue);
|
|
933
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
for (var i = 0; i < propValue.length; i++) {
|
|
937
|
+
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret_1);
|
|
938
|
+
|
|
939
|
+
if (error instanceof Error) {
|
|
940
|
+
return error;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
return createChainableTypeChecker(validate);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
function createElementTypeChecker() {
|
|
951
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
952
|
+
var propValue = props[propName];
|
|
953
|
+
|
|
954
|
+
if (!isValidElement(propValue)) {
|
|
955
|
+
var propType = getPropType(propValue);
|
|
956
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
return createChainableTypeChecker(validate);
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
function createElementTypeTypeChecker() {
|
|
966
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
967
|
+
var propValue = props[propName];
|
|
968
|
+
|
|
969
|
+
if (!reactIs.isValidElementType(propValue)) {
|
|
970
|
+
var propType = getPropType(propValue);
|
|
971
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement type.'));
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
return null;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
return createChainableTypeChecker(validate);
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function createInstanceTypeChecker(expectedClass) {
|
|
981
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
982
|
+
if (!(props[propName] instanceof expectedClass)) {
|
|
983
|
+
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
984
|
+
var actualClassName = getClassName(props[propName]);
|
|
985
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
return null;
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
return createChainableTypeChecker(validate);
|
|
1033
992
|
}
|
|
1034
993
|
|
|
1035
994
|
function createEnumTypeChecker(expectedValues) {
|
|
1036
995
|
if (!Array.isArray(expectedValues)) {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
996
|
+
{
|
|
997
|
+
if (arguments.length > 1) {
|
|
998
|
+
printWarning$1('Invalid arguments supplied to oneOf, expected an array, got ' + arguments.length + ' arguments. ' + 'A common mistake is to write oneOf(x, y, z) instead of oneOf([x, y, z]).');
|
|
999
|
+
} else {
|
|
1000
|
+
printWarning$1('Invalid argument supplied to oneOf, expected an array.');
|
|
1001
|
+
}
|
|
1041
1002
|
}
|
|
1042
1003
|
|
|
1043
1004
|
return emptyFunctionThatReturnsNull;
|
|
1044
1005
|
}
|
|
1045
1006
|
|
|
1046
|
-
|
|
1007
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
1047
1008
|
var propValue = props[propName];
|
|
1048
1009
|
|
|
1049
1010
|
for (var i = 0; i < expectedValues.length; i++) {
|
|
@@ -1052,7 +1013,7 @@
|
|
|
1052
1013
|
}
|
|
1053
1014
|
}
|
|
1054
1015
|
|
|
1055
|
-
var valuesString = JSON.stringify(expectedValues, function (key, value) {
|
|
1016
|
+
var valuesString = JSON.stringify(expectedValues, function replacer(key, value) {
|
|
1056
1017
|
var type = getPreciseType(value);
|
|
1057
1018
|
|
|
1058
1019
|
if (type === 'symbol') {
|
|
@@ -1062,19 +1023,50 @@
|
|
|
1062
1023
|
return value;
|
|
1063
1024
|
});
|
|
1064
1025
|
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + String(propValue) + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
1065
|
-
});
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
1069
|
-
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
1070
|
-
printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.');
|
|
1071
|
-
return emptyFunctionThatReturnsNull;
|
|
1072
1026
|
}
|
|
1073
1027
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1028
|
+
return createChainableTypeChecker(validate);
|
|
1029
|
+
}
|
|
1076
1030
|
|
|
1077
|
-
|
|
1031
|
+
function createObjectOfTypeChecker(typeChecker) {
|
|
1032
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
1033
|
+
if (typeof typeChecker !== 'function') {
|
|
1034
|
+
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
var propValue = props[propName];
|
|
1038
|
+
var propType = getPropType(propValue);
|
|
1039
|
+
|
|
1040
|
+
if (propType !== 'object') {
|
|
1041
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
for (var key in propValue) {
|
|
1045
|
+
if (has$1(propValue, key)) {
|
|
1046
|
+
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
1047
|
+
|
|
1048
|
+
if (error instanceof Error) {
|
|
1049
|
+
return error;
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
return null;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
return createChainableTypeChecker(validate);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
1061
|
+
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
1062
|
+
printWarning$1('Invalid argument supplied to oneOfType, expected an instance of array.') ;
|
|
1063
|
+
return emptyFunctionThatReturnsNull;
|
|
1064
|
+
}
|
|
1065
|
+
|
|
1066
|
+
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
1067
|
+
var checker = arrayOfTypeCheckers[i];
|
|
1068
|
+
|
|
1069
|
+
if (typeof checker !== 'function') {
|
|
1078
1070
|
printWarning$1('Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + 'received ' + getPostfixForTypeWarning(checker) + ' at index ' + i + '.');
|
|
1079
1071
|
return emptyFunctionThatReturnsNull;
|
|
1080
1072
|
}
|
|
@@ -1095,6 +1087,80 @@
|
|
|
1095
1087
|
return createChainableTypeChecker(validate);
|
|
1096
1088
|
}
|
|
1097
1089
|
|
|
1090
|
+
function createNodeChecker() {
|
|
1091
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
1092
|
+
if (!isNode(props[propName])) {
|
|
1093
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
return createChainableTypeChecker(validate);
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
function createShapeTypeChecker(shapeTypes) {
|
|
1103
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
1104
|
+
var propValue = props[propName];
|
|
1105
|
+
var propType = getPropType(propValue);
|
|
1106
|
+
|
|
1107
|
+
if (propType !== 'object') {
|
|
1108
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
for (var key in shapeTypes) {
|
|
1112
|
+
var checker = shapeTypes[key];
|
|
1113
|
+
|
|
1114
|
+
if (!checker) {
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
1119
|
+
|
|
1120
|
+
if (error) {
|
|
1121
|
+
return error;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
return null;
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
return createChainableTypeChecker(validate);
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function createStrictShapeTypeChecker(shapeTypes) {
|
|
1132
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
1133
|
+
var propValue = props[propName];
|
|
1134
|
+
var propType = getPropType(propValue);
|
|
1135
|
+
|
|
1136
|
+
if (propType !== 'object') {
|
|
1137
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
1138
|
+
} // We need to check all keys in case some are required but missing from
|
|
1139
|
+
// props.
|
|
1140
|
+
|
|
1141
|
+
|
|
1142
|
+
var allKeys = objectAssign({}, props[propName], shapeTypes);
|
|
1143
|
+
|
|
1144
|
+
for (var key in allKeys) {
|
|
1145
|
+
var checker = shapeTypes[key];
|
|
1146
|
+
|
|
1147
|
+
if (!checker) {
|
|
1148
|
+
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + '\nBad object: ' + JSON.stringify(props[propName], null, ' ') + '\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' '));
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret_1);
|
|
1152
|
+
|
|
1153
|
+
if (error) {
|
|
1154
|
+
return error;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
return null;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
return createChainableTypeChecker(validate);
|
|
1162
|
+
}
|
|
1163
|
+
|
|
1098
1164
|
function isNode(propValue) {
|
|
1099
1165
|
switch (typeof propValue) {
|
|
1100
1166
|
case 'number':
|
|
@@ -1257,9 +1323,13 @@
|
|
|
1257
1323
|
* This source code is licensed under the MIT license found in the
|
|
1258
1324
|
* LICENSE file in the root directory of this source tree.
|
|
1259
1325
|
*/
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1326
|
+
{
|
|
1327
|
+
var ReactIs = reactIs; // By explicitly using `prop-types` you are opting into new development behavior.
|
|
1328
|
+
// http://fb.me/prop-types-in-prod
|
|
1329
|
+
|
|
1330
|
+
var throwOnDirectAccess = true;
|
|
1331
|
+
module.exports = factoryWithTypeCheckers(ReactIs.isElement, throwOnDirectAccess);
|
|
1332
|
+
}
|
|
1263
1333
|
});
|
|
1264
1334
|
|
|
1265
1335
|
function isElement(el) {
|
|
@@ -1834,1051 +1904,1057 @@
|
|
|
1834
1904
|
|
|
1835
1905
|
var Downshift =
|
|
1836
1906
|
/*#__PURE__*/
|
|
1837
|
-
function (
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
function
|
|
1841
|
-
|
|
1907
|
+
function () {
|
|
1908
|
+
var Downshift =
|
|
1909
|
+
/*#__PURE__*/
|
|
1910
|
+
function (_Component) {
|
|
1911
|
+
_inheritsLoose(Downshift, _Component);
|
|
1912
|
+
|
|
1913
|
+
function Downshift(_props) {
|
|
1914
|
+
var _this = _Component.call(this, _props) || this;
|
|
1915
|
+
|
|
1916
|
+
_this.id = _this.props.id || "downshift-" + generateId();
|
|
1917
|
+
_this.menuId = _this.props.menuId || _this.id + "-menu";
|
|
1918
|
+
_this.labelId = _this.props.labelId || _this.id + "-label";
|
|
1919
|
+
_this.inputId = _this.props.inputId || _this.id + "-input";
|
|
1920
|
+
|
|
1921
|
+
_this.getItemId = _this.props.getItemId || function (index) {
|
|
1922
|
+
return _this.id + "-item-" + index;
|
|
1923
|
+
};
|
|
1842
1924
|
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1925
|
+
_this.input = null;
|
|
1926
|
+
_this.items = [];
|
|
1927
|
+
_this.itemCount = null;
|
|
1928
|
+
_this.previousResultCount = 0;
|
|
1929
|
+
_this.timeoutIds = [];
|
|
1847
1930
|
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1931
|
+
_this.internalSetTimeout = function (fn, time) {
|
|
1932
|
+
var id = setTimeout(function () {
|
|
1933
|
+
_this.timeoutIds = _this.timeoutIds.filter(function (i) {
|
|
1934
|
+
return i !== id;
|
|
1935
|
+
});
|
|
1936
|
+
fn();
|
|
1937
|
+
}, time);
|
|
1851
1938
|
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
_this.itemCount = null;
|
|
1855
|
-
_this.previousResultCount = 0;
|
|
1856
|
-
_this.timeoutIds = [];
|
|
1939
|
+
_this.timeoutIds.push(id);
|
|
1940
|
+
};
|
|
1857
1941
|
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
return i !== id;
|
|
1862
|
-
});
|
|
1863
|
-
fn();
|
|
1864
|
-
}, time);
|
|
1942
|
+
_this.setItemCount = function (count) {
|
|
1943
|
+
_this.itemCount = count;
|
|
1944
|
+
};
|
|
1865
1945
|
|
|
1866
|
-
_this.
|
|
1867
|
-
|
|
1946
|
+
_this.unsetItemCount = function () {
|
|
1947
|
+
_this.itemCount = null;
|
|
1948
|
+
};
|
|
1868
1949
|
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1950
|
+
_this.setHighlightedIndex = function (highlightedIndex, otherStateToSet) {
|
|
1951
|
+
if (highlightedIndex === void 0) {
|
|
1952
|
+
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
1953
|
+
}
|
|
1872
1954
|
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1955
|
+
if (otherStateToSet === void 0) {
|
|
1956
|
+
otherStateToSet = {};
|
|
1957
|
+
}
|
|
1876
1958
|
|
|
1877
|
-
|
|
1878
|
-
if (highlightedIndex === void 0) {
|
|
1879
|
-
highlightedIndex = _this.props.defaultHighlightedIndex;
|
|
1880
|
-
}
|
|
1959
|
+
otherStateToSet = pickState(otherStateToSet);
|
|
1881
1960
|
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1961
|
+
_this.internalSetState(_extends({
|
|
1962
|
+
highlightedIndex: highlightedIndex
|
|
1963
|
+
}, otherStateToSet));
|
|
1964
|
+
};
|
|
1885
1965
|
|
|
1886
|
-
|
|
1966
|
+
_this.clearSelection = function (cb) {
|
|
1967
|
+
_this.internalSetState({
|
|
1968
|
+
selectedItem: null,
|
|
1969
|
+
inputValue: '',
|
|
1970
|
+
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1971
|
+
isOpen: _this.props.defaultIsOpen
|
|
1972
|
+
}, cb);
|
|
1973
|
+
};
|
|
1887
1974
|
|
|
1888
|
-
_this.
|
|
1889
|
-
|
|
1890
|
-
}, otherStateToSet));
|
|
1891
|
-
};
|
|
1975
|
+
_this.selectItem = function (item, otherStateToSet, cb) {
|
|
1976
|
+
otherStateToSet = pickState(otherStateToSet);
|
|
1892
1977
|
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
}
|
|
1900
|
-
};
|
|
1978
|
+
_this.internalSetState(_extends({
|
|
1979
|
+
isOpen: _this.props.defaultIsOpen,
|
|
1980
|
+
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
1981
|
+
selectedItem: item,
|
|
1982
|
+
inputValue: _this.props.itemToString(item)
|
|
1983
|
+
}, otherStateToSet), cb);
|
|
1984
|
+
};
|
|
1901
1985
|
|
|
1902
|
-
|
|
1903
|
-
|
|
1986
|
+
_this.selectItemAtIndex = function (itemIndex, otherStateToSet, cb) {
|
|
1987
|
+
var item = _this.items[itemIndex];
|
|
1904
1988
|
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
selectedItem: item,
|
|
1909
|
-
inputValue: _this.props.itemToString(item)
|
|
1910
|
-
}, otherStateToSet), cb);
|
|
1911
|
-
};
|
|
1989
|
+
if (item == null) {
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1912
1992
|
|
|
1913
|
-
|
|
1914
|
-
|
|
1993
|
+
_this.selectItem(item, otherStateToSet, cb);
|
|
1994
|
+
};
|
|
1915
1995
|
|
|
1916
|
-
|
|
1917
|
-
return;
|
|
1918
|
-
}
|
|
1996
|
+
_this.selectHighlightedItem = function (otherStateToSet, cb) {
|
|
1997
|
+
return _this.selectItemAtIndex(_this.getState().highlightedIndex, otherStateToSet, cb);
|
|
1998
|
+
};
|
|
1919
1999
|
|
|
1920
|
-
_this.
|
|
1921
|
-
|
|
2000
|
+
_this.internalSetState = function (stateToSet, cb) {
|
|
2001
|
+
var isItemSelected, onChangeArg;
|
|
2002
|
+
var onStateChangeArg = {};
|
|
2003
|
+
var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
|
|
2004
|
+
// so someone controlling the `inputValue` state gets notified of
|
|
2005
|
+
// the input change as soon as possible. This avoids issues with
|
|
2006
|
+
// preserving the cursor position.
|
|
2007
|
+
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
2008
|
+
|
|
2009
|
+
if (!isStateToSetFunction && stateToSet.hasOwnProperty('inputValue')) {
|
|
2010
|
+
_this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
|
|
2011
|
+
}
|
|
1922
2012
|
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
2013
|
+
return _this.setState(function (state) {
|
|
2014
|
+
state = _this.getState(state);
|
|
2015
|
+
var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
|
|
1926
2016
|
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
var isStateToSetFunction = typeof stateToSet === 'function'; // we want to call `onInputValueChange` before the `setState` call
|
|
1931
|
-
// so someone controlling the `inputValue` state gets notified of
|
|
1932
|
-
// the input change as soon as possible. This avoids issues with
|
|
1933
|
-
// preserving the cursor position.
|
|
1934
|
-
// See https://github.com/downshift-js/downshift/issues/217 for more info.
|
|
2017
|
+
newStateToSet = _this.props.stateReducer(state, newStateToSet); // checks if an item is selected, regardless of if it's different from
|
|
2018
|
+
// what was selected before
|
|
2019
|
+
// used to determine if onSelect and onChange callbacks should be called
|
|
1935
2020
|
|
|
1936
|
-
|
|
1937
|
-
_this.props.onInputValueChange(stateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, stateToSet));
|
|
1938
|
-
}
|
|
2021
|
+
isItemSelected = newStateToSet.hasOwnProperty('selectedItem'); // this keeps track of the object we want to call with setState
|
|
1939
2022
|
|
|
1940
|
-
|
|
1941
|
-
state = _this.getState(state);
|
|
1942
|
-
var newStateToSet = isStateToSetFunction ? stateToSet(state) : stateToSet; // Your own function that could modify the state that will be set.
|
|
2023
|
+
var nextState = {}; // this is just used to tell whether the state changed
|
|
1943
2024
|
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
2025
|
+
var nextFullState = {}; // we need to call on change if the outside world is controlling any of our state
|
|
2026
|
+
// and we're trying to update that state. OR if the selection has changed and we're
|
|
2027
|
+
// trying to update the selection
|
|
1947
2028
|
|
|
1948
|
-
|
|
2029
|
+
if (isItemSelected && newStateToSet.selectedItem !== state.selectedItem) {
|
|
2030
|
+
onChangeArg = newStateToSet.selectedItem;
|
|
2031
|
+
}
|
|
1949
2032
|
|
|
1950
|
-
|
|
2033
|
+
newStateToSet.type = newStateToSet.type || unknown;
|
|
2034
|
+
Object.keys(newStateToSet).forEach(function (key) {
|
|
2035
|
+
// onStateChangeArg should only have the state that is
|
|
2036
|
+
// actually changing
|
|
2037
|
+
if (state[key] !== newStateToSet[key]) {
|
|
2038
|
+
onStateChangeArg[key] = newStateToSet[key];
|
|
2039
|
+
} // the type is useful for the onStateChangeArg
|
|
2040
|
+
// but we don't actually want to set it in internal state.
|
|
2041
|
+
// this is an undocumented feature for now... Not all internalSetState
|
|
2042
|
+
// calls support it and I'm not certain we want them to yet.
|
|
2043
|
+
// But it enables users controlling the isOpen state to know when
|
|
2044
|
+
// the isOpen state changes due to mouseup events which is quite handy.
|
|
2045
|
+
|
|
2046
|
+
|
|
2047
|
+
if (key === 'type') {
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
1951
2050
|
|
|
1952
|
-
|
|
1953
|
-
// and we're trying to update that state. OR if the selection has changed and we're
|
|
1954
|
-
// trying to update the selection
|
|
2051
|
+
nextFullState[key] = newStateToSet[key]; // if it's coming from props, then we don't care to set it internally
|
|
1955
2052
|
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
2053
|
+
if (!_this.isControlledProp(key)) {
|
|
2054
|
+
nextState[key] = newStateToSet[key];
|
|
2055
|
+
}
|
|
2056
|
+
}); // if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
2057
|
+
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
1959
2058
|
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
// onStateChangeArg should only have the state that is
|
|
1963
|
-
// actually changing
|
|
1964
|
-
if (state[key] !== newStateToSet[key]) {
|
|
1965
|
-
onStateChangeArg[key] = newStateToSet[key];
|
|
1966
|
-
} // the type is useful for the onStateChangeArg
|
|
1967
|
-
// but we don't actually want to set it in internal state.
|
|
1968
|
-
// this is an undocumented feature for now... Not all internalSetState
|
|
1969
|
-
// calls support it and I'm not certain we want them to yet.
|
|
1970
|
-
// But it enables users controlling the isOpen state to know when
|
|
1971
|
-
// the isOpen state changes due to mouseup events which is quite handy.
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
if (key === 'type') {
|
|
1975
|
-
return;
|
|
2059
|
+
if (isStateToSetFunction && newStateToSet.hasOwnProperty('inputValue')) {
|
|
2060
|
+
_this.props.onInputValueChange(newStateToSet.inputValue, _extends({}, _this.getStateAndHelpers(), {}, newStateToSet));
|
|
1976
2061
|
}
|
|
1977
2062
|
|
|
1978
|
-
|
|
2063
|
+
return nextState;
|
|
2064
|
+
}, function () {
|
|
2065
|
+
// call the provided callback if it's a function
|
|
2066
|
+
cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
|
|
2067
|
+
// we have relevant information to pass them.
|
|
1979
2068
|
|
|
1980
|
-
|
|
1981
|
-
nextState[key] = newStateToSet[key];
|
|
1982
|
-
}
|
|
1983
|
-
}); // if stateToSet is a function, then we weren't able to call onInputValueChange
|
|
1984
|
-
// earlier, so we'll call it now that we know what the inputValue state will be.
|
|
2069
|
+
var hasMoreStateThanType = Object.keys(onStateChangeArg).length > 1;
|
|
1985
2070
|
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
2071
|
+
if (hasMoreStateThanType) {
|
|
2072
|
+
_this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
|
|
2073
|
+
}
|
|
1989
2074
|
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
cbToCb(cb)(); // only call the onStateChange and onChange callbacks if
|
|
1994
|
-
// we have relevant information to pass them.
|
|
2075
|
+
if (isItemSelected) {
|
|
2076
|
+
_this.props.onSelect(stateToSet.selectedItem, _this.getStateAndHelpers());
|
|
2077
|
+
}
|
|
1995
2078
|
|
|
1996
|
-
|
|
2079
|
+
if (onChangeArg !== undefined) {
|
|
2080
|
+
_this.props.onChange(onChangeArg, _this.getStateAndHelpers());
|
|
2081
|
+
} // this is currently undocumented and therefore subject to change
|
|
2082
|
+
// We'll try to not break it, but just be warned.
|
|
1997
2083
|
|
|
1998
|
-
if (hasMoreStateThanType) {
|
|
1999
|
-
_this.props.onStateChange(onStateChangeArg, _this.getStateAndHelpers());
|
|
2000
|
-
}
|
|
2001
2084
|
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2085
|
+
_this.props.onUserAction(onStateChangeArg, _this.getStateAndHelpers());
|
|
2086
|
+
});
|
|
2087
|
+
};
|
|
2005
2088
|
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
// We'll try to not break it, but just be warned.
|
|
2089
|
+
_this.rootRef = function (node) {
|
|
2090
|
+
return _this._rootNode = node;
|
|
2091
|
+
};
|
|
2010
2092
|
|
|
2093
|
+
_this.getRootProps = function (_temp, _temp2) {
|
|
2094
|
+
var _extends2;
|
|
2011
2095
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2096
|
+
var _ref = _temp === void 0 ? {} : _temp,
|
|
2097
|
+
_ref$refKey = _ref.refKey,
|
|
2098
|
+
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
2099
|
+
ref = _ref.ref,
|
|
2100
|
+
rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
|
|
2015
2101
|
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2102
|
+
var _ref2 = _temp2 === void 0 ? {} : _temp2,
|
|
2103
|
+
_ref2$suppressRefErro = _ref2.suppressRefError,
|
|
2104
|
+
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
2019
2105
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2106
|
+
// this is used in the render to know whether the user has called getRootProps.
|
|
2107
|
+
// It uses that to know whether to apply the props automatically
|
|
2108
|
+
_this.getRootProps.called = true;
|
|
2109
|
+
_this.getRootProps.refKey = refKey;
|
|
2110
|
+
_this.getRootProps.suppressRefError = suppressRefError;
|
|
2022
2111
|
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
refKey = _ref$refKey === void 0 ? 'ref' : _ref$refKey,
|
|
2026
|
-
ref = _ref.ref,
|
|
2027
|
-
rest = _objectWithoutPropertiesLoose(_ref, ["refKey", "ref"]);
|
|
2112
|
+
var _this$getState = _this.getState(),
|
|
2113
|
+
isOpen = _this$getState.isOpen;
|
|
2028
2114
|
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
suppressRefError = _ref2$suppressRefErro === void 0 ? false : _ref2$suppressRefErro;
|
|
2115
|
+
return _extends((_extends2 = {}, _extends2[refKey] = handleRefs(ref, _this.rootRef), _extends2.role = 'combobox', _extends2['aria-expanded'] = isOpen, _extends2['aria-haspopup'] = 'listbox', _extends2['aria-owns'] = isOpen ? _this.menuId : null, _extends2['aria-labelledby'] = _this.labelId, _extends2), rest);
|
|
2116
|
+
};
|
|
2032
2117
|
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
_this.getRootProps.refKey = refKey;
|
|
2037
|
-
_this.getRootProps.suppressRefError = suppressRefError;
|
|
2118
|
+
_this.keyDownHandlers = {
|
|
2119
|
+
ArrowDown: function ArrowDown(event) {
|
|
2120
|
+
var _this2 = this;
|
|
2038
2121
|
|
|
2039
|
-
|
|
2040
|
-
isOpen = _this$getState.isOpen;
|
|
2122
|
+
event.preventDefault();
|
|
2041
2123
|
|
|
2042
|
-
|
|
2043
|
-
|
|
2124
|
+
if (this.getState().isOpen) {
|
|
2125
|
+
var amount = event.shiftKey ? 5 : 1;
|
|
2126
|
+
this.moveHighlightedIndex(amount, {
|
|
2127
|
+
type: keyDownArrowDown
|
|
2128
|
+
});
|
|
2129
|
+
} else {
|
|
2130
|
+
this.internalSetState({
|
|
2131
|
+
isOpen: true,
|
|
2132
|
+
type: keyDownArrowDown
|
|
2133
|
+
}, function () {
|
|
2134
|
+
var itemCount = _this2.getItemCount();
|
|
2135
|
+
|
|
2136
|
+
if (itemCount > 0) {
|
|
2137
|
+
_this2.setHighlightedIndex(getNextWrappingIndex(1, _this2.getState().highlightedIndex, itemCount), {
|
|
2138
|
+
type: keyDownArrowDown
|
|
2139
|
+
});
|
|
2140
|
+
}
|
|
2141
|
+
});
|
|
2142
|
+
}
|
|
2143
|
+
},
|
|
2144
|
+
ArrowUp: function ArrowUp(event) {
|
|
2145
|
+
var _this3 = this;
|
|
2044
2146
|
|
|
2045
|
-
|
|
2046
|
-
ArrowDown: function ArrowDown(event) {
|
|
2047
|
-
var _this2 = this;
|
|
2147
|
+
event.preventDefault();
|
|
2048
2148
|
|
|
2049
|
-
|
|
2149
|
+
if (this.getState().isOpen) {
|
|
2150
|
+
var amount = event.shiftKey ? -5 : -1;
|
|
2151
|
+
this.moveHighlightedIndex(amount, {
|
|
2152
|
+
type: keyDownArrowUp
|
|
2153
|
+
});
|
|
2154
|
+
} else {
|
|
2155
|
+
this.internalSetState({
|
|
2156
|
+
isOpen: true,
|
|
2157
|
+
type: keyDownArrowUp
|
|
2158
|
+
}, function () {
|
|
2159
|
+
var itemCount = _this3.getItemCount();
|
|
2160
|
+
|
|
2161
|
+
if (itemCount > 0) {
|
|
2162
|
+
_this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
|
|
2163
|
+
type: keyDownArrowDown
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
},
|
|
2169
|
+
Enter: function Enter(event) {
|
|
2170
|
+
var _this$getState2 = this.getState(),
|
|
2171
|
+
isOpen = _this$getState2.isOpen,
|
|
2172
|
+
highlightedIndex = _this$getState2.highlightedIndex;
|
|
2173
|
+
|
|
2174
|
+
if (isOpen && highlightedIndex != null) {
|
|
2175
|
+
event.preventDefault();
|
|
2176
|
+
var item = this.items[highlightedIndex];
|
|
2177
|
+
var itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
2178
|
+
|
|
2179
|
+
if (item == null || itemNode && itemNode.hasAttribute('disabled')) {
|
|
2180
|
+
return;
|
|
2181
|
+
}
|
|
2050
2182
|
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2183
|
+
this.selectHighlightedItem({
|
|
2184
|
+
type: keyDownEnter
|
|
2185
|
+
});
|
|
2186
|
+
}
|
|
2187
|
+
},
|
|
2188
|
+
Escape: function Escape(event) {
|
|
2189
|
+
event.preventDefault();
|
|
2190
|
+
this.reset({
|
|
2191
|
+
type: keyDownEscape,
|
|
2192
|
+
selectedItem: null,
|
|
2193
|
+
inputValue: ''
|
|
2055
2194
|
});
|
|
2056
|
-
}
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2195
|
+
}
|
|
2196
|
+
};
|
|
2197
|
+
_this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2198
|
+
' ': function _(event) {
|
|
2199
|
+
event.preventDefault();
|
|
2200
|
+
this.toggleMenu({
|
|
2201
|
+
type: keyDownSpaceButton
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2205
|
+
_this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2206
|
+
Home: function Home(event) {
|
|
2207
|
+
this.highlightFirstOrLastIndex(event, true, {
|
|
2208
|
+
type: keyDownHome
|
|
2209
|
+
});
|
|
2210
|
+
},
|
|
2211
|
+
End: function End(event) {
|
|
2212
|
+
this.highlightFirstOrLastIndex(event, false, {
|
|
2213
|
+
type: keyDownEnd
|
|
2068
2214
|
});
|
|
2069
2215
|
}
|
|
2070
|
-
}
|
|
2071
|
-
ArrowUp: function ArrowUp(event) {
|
|
2072
|
-
var _this3 = this;
|
|
2216
|
+
});
|
|
2073
2217
|
|
|
2218
|
+
_this.getToggleButtonProps = function (_temp3) {
|
|
2219
|
+
var _ref3 = _temp3 === void 0 ? {} : _temp3,
|
|
2220
|
+
onClick = _ref3.onClick,
|
|
2221
|
+
onPress = _ref3.onPress,
|
|
2222
|
+
onKeyDown = _ref3.onKeyDown,
|
|
2223
|
+
onKeyUp = _ref3.onKeyUp,
|
|
2224
|
+
onBlur = _ref3.onBlur,
|
|
2225
|
+
rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
|
|
2226
|
+
|
|
2227
|
+
var _this$getState3 = _this.getState(),
|
|
2228
|
+
isOpen = _this$getState3.isOpen;
|
|
2229
|
+
|
|
2230
|
+
var enabledEventHandlers = {
|
|
2231
|
+
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
2232
|
+
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
2233
|
+
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
2234
|
+
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
2235
|
+
};
|
|
2236
|
+
var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
2237
|
+
return _extends({
|
|
2238
|
+
type: 'button',
|
|
2239
|
+
role: 'button',
|
|
2240
|
+
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
2241
|
+
'aria-haspopup': true,
|
|
2242
|
+
'data-toggle': true
|
|
2243
|
+
}, eventHandlers, {}, rest);
|
|
2244
|
+
};
|
|
2245
|
+
|
|
2246
|
+
_this.buttonHandleKeyUp = function (event) {
|
|
2247
|
+
// Prevent click event from emitting in Firefox
|
|
2074
2248
|
event.preventDefault();
|
|
2249
|
+
};
|
|
2075
2250
|
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
} else {
|
|
2082
|
-
this.internalSetState({
|
|
2083
|
-
isOpen: true,
|
|
2084
|
-
type: keyDownArrowUp
|
|
2085
|
-
}, function () {
|
|
2086
|
-
var itemCount = _this3.getItemCount();
|
|
2087
|
-
|
|
2088
|
-
if (itemCount > 0) {
|
|
2089
|
-
_this3.setHighlightedIndex(getNextWrappingIndex(-1, _this3.getState().highlightedIndex, itemCount), {
|
|
2090
|
-
type: keyDownArrowDown
|
|
2091
|
-
});
|
|
2092
|
-
}
|
|
2093
|
-
});
|
|
2251
|
+
_this.buttonHandleKeyDown = function (event) {
|
|
2252
|
+
var key = normalizeArrowKey(event);
|
|
2253
|
+
|
|
2254
|
+
if (_this.buttonKeyDownHandlers[key]) {
|
|
2255
|
+
_this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
|
2094
2256
|
}
|
|
2095
|
-
}
|
|
2096
|
-
Enter: function Enter(event) {
|
|
2097
|
-
var _this$getState2 = this.getState(),
|
|
2098
|
-
isOpen = _this$getState2.isOpen,
|
|
2099
|
-
highlightedIndex = _this$getState2.highlightedIndex;
|
|
2257
|
+
};
|
|
2100
2258
|
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
var itemNode = this.getItemNodeFromIndex(highlightedIndex);
|
|
2259
|
+
_this.buttonHandleClick = function (event) {
|
|
2260
|
+
event.preventDefault(); // handle odd case for Safari and Firefox which
|
|
2261
|
+
// don't give the button the focus properly.
|
|
2105
2262
|
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2263
|
+
/* istanbul ignore if (can't reasonably test this) */
|
|
2264
|
+
|
|
2265
|
+
if ( _this.props.environment.document.activeElement === _this.props.environment.document.body) {
|
|
2266
|
+
event.target.focus();
|
|
2267
|
+
} // to simplify testing components that use downshift, we'll not wrap this in a setTimeout
|
|
2268
|
+
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
2269
|
+
// when building for production and should therefore have no impact on production code.
|
|
2109
2270
|
|
|
2110
|
-
|
|
2111
|
-
|
|
2271
|
+
|
|
2272
|
+
// Ensure that toggle of menu occurs after the potential blur event in iOS
|
|
2273
|
+
_this.internalSetTimeout(function () {
|
|
2274
|
+
return _this.toggleMenu({
|
|
2275
|
+
type: clickButton
|
|
2112
2276
|
});
|
|
2113
|
-
}
|
|
2114
|
-
},
|
|
2115
|
-
Escape: function Escape(event) {
|
|
2116
|
-
event.preventDefault();
|
|
2117
|
-
this.reset({
|
|
2118
|
-
type: keyDownEscape,
|
|
2119
|
-
selectedItem: null,
|
|
2120
|
-
inputValue: ''
|
|
2121
|
-
});
|
|
2122
|
-
}
|
|
2123
|
-
};
|
|
2124
|
-
_this.buttonKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2125
|
-
' ': function _(event) {
|
|
2126
|
-
event.preventDefault();
|
|
2127
|
-
this.toggleMenu({
|
|
2128
|
-
type: keyDownSpaceButton
|
|
2129
|
-
});
|
|
2130
|
-
}
|
|
2131
|
-
});
|
|
2132
|
-
_this.inputKeyDownHandlers = _extends({}, _this.keyDownHandlers, {
|
|
2133
|
-
Home: function Home(event) {
|
|
2134
|
-
this.highlightFirstOrLastIndex(event, true, {
|
|
2135
|
-
type: keyDownHome
|
|
2136
2277
|
});
|
|
2137
|
-
}
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2278
|
+
};
|
|
2279
|
+
|
|
2280
|
+
_this.buttonHandleBlur = function (event) {
|
|
2281
|
+
var blurTarget = event.target; // Save blur target for comparison with activeElement later
|
|
2282
|
+
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not body element
|
|
2283
|
+
|
|
2284
|
+
_this.internalSetTimeout(function () {
|
|
2285
|
+
if (!_this.isMouseDown && (_this.props.environment.document.activeElement == null || _this.props.environment.document.activeElement.id !== _this.inputId) && _this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
|
|
2286
|
+
) {
|
|
2287
|
+
_this.reset({
|
|
2288
|
+
type: blurButton
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2141
2291
|
});
|
|
2142
|
-
}
|
|
2143
|
-
});
|
|
2292
|
+
};
|
|
2144
2293
|
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
onKeyUp = _ref3.onKeyUp,
|
|
2151
|
-
onBlur = _ref3.onBlur,
|
|
2152
|
-
rest = _objectWithoutPropertiesLoose(_ref3, ["onClick", "onPress", "onKeyDown", "onKeyUp", "onBlur"]);
|
|
2153
|
-
|
|
2154
|
-
var _this$getState3 = _this.getState(),
|
|
2155
|
-
isOpen = _this$getState3.isOpen;
|
|
2156
|
-
|
|
2157
|
-
var enabledEventHandlers = {
|
|
2158
|
-
onClick: callAllEventHandlers(onClick, _this.buttonHandleClick),
|
|
2159
|
-
onKeyDown: callAllEventHandlers(onKeyDown, _this.buttonHandleKeyDown),
|
|
2160
|
-
onKeyUp: callAllEventHandlers(onKeyUp, _this.buttonHandleKeyUp),
|
|
2161
|
-
onBlur: callAllEventHandlers(onBlur, _this.buttonHandleBlur)
|
|
2294
|
+
_this.getLabelProps = function (props) {
|
|
2295
|
+
return _extends({
|
|
2296
|
+
htmlFor: _this.inputId,
|
|
2297
|
+
id: _this.labelId
|
|
2298
|
+
}, props);
|
|
2162
2299
|
};
|
|
2163
|
-
var eventHandlers = rest.disabled ? {} : enabledEventHandlers;
|
|
2164
|
-
return _extends({
|
|
2165
|
-
type: 'button',
|
|
2166
|
-
role: 'button',
|
|
2167
|
-
'aria-label': isOpen ? 'close menu' : 'open menu',
|
|
2168
|
-
'aria-haspopup': true,
|
|
2169
|
-
'data-toggle': true
|
|
2170
|
-
}, eventHandlers, {}, rest);
|
|
2171
|
-
};
|
|
2172
2300
|
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2301
|
+
_this.getInputProps = function (_temp4) {
|
|
2302
|
+
var _ref4 = _temp4 === void 0 ? {} : _temp4,
|
|
2303
|
+
onKeyDown = _ref4.onKeyDown,
|
|
2304
|
+
onBlur = _ref4.onBlur,
|
|
2305
|
+
onChange = _ref4.onChange,
|
|
2306
|
+
onInput = _ref4.onInput,
|
|
2307
|
+
onChangeText = _ref4.onChangeText,
|
|
2308
|
+
rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
|
|
2177
2309
|
|
|
2178
|
-
|
|
2179
|
-
|
|
2310
|
+
var onChangeKey;
|
|
2311
|
+
var eventHandlers = {};
|
|
2312
|
+
/* istanbul ignore next (preact) */
|
|
2180
2313
|
|
|
2181
|
-
|
|
2182
|
-
_this.buttonKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
|
2183
|
-
}
|
|
2184
|
-
};
|
|
2314
|
+
onChangeKey = 'onChange';
|
|
2185
2315
|
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2316
|
+
var _this$getState4 = _this.getState(),
|
|
2317
|
+
inputValue = _this$getState4.inputValue,
|
|
2318
|
+
isOpen = _this$getState4.isOpen,
|
|
2319
|
+
highlightedIndex = _this$getState4.highlightedIndex;
|
|
2189
2320
|
|
|
2190
|
-
|
|
2321
|
+
if (!rest.disabled) {
|
|
2322
|
+
var _eventHandlers;
|
|
2191
2323
|
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
// if the NODE_ENV is test. With the proper build system, this should be dead code eliminated
|
|
2196
|
-
// when building for production and should therefore have no impact on production code.
|
|
2324
|
+
eventHandlers = (_eventHandlers = {}, _eventHandlers[onChangeKey] = callAllEventHandlers(onChange, onInput, _this.inputHandleChange), _eventHandlers.onKeyDown = callAllEventHandlers(onKeyDown, _this.inputHandleKeyDown), _eventHandlers.onBlur = callAllEventHandlers(onBlur, _this.inputHandleBlur), _eventHandlers);
|
|
2325
|
+
}
|
|
2326
|
+
/* istanbul ignore if (react-native) */
|
|
2197
2327
|
|
|
2198
2328
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2329
|
+
return _extends({
|
|
2330
|
+
'aria-autocomplete': 'list',
|
|
2331
|
+
'aria-activedescendant': isOpen && typeof highlightedIndex === 'number' && highlightedIndex >= 0 ? _this.getItemId(highlightedIndex) : null,
|
|
2332
|
+
'aria-controls': isOpen ? _this.menuId : null,
|
|
2333
|
+
'aria-labelledby': _this.labelId,
|
|
2334
|
+
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
2335
|
+
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
2336
|
+
autoComplete: 'off',
|
|
2337
|
+
value: inputValue,
|
|
2338
|
+
id: _this.inputId
|
|
2339
|
+
}, eventHandlers, {}, rest);
|
|
2340
|
+
};
|
|
2341
|
+
|
|
2342
|
+
_this.inputHandleKeyDown = function (event) {
|
|
2343
|
+
var key = normalizeArrowKey(event);
|
|
2344
|
+
|
|
2345
|
+
if (key && _this.inputKeyDownHandlers[key]) {
|
|
2346
|
+
_this.inputKeyDownHandlers[key].call(_assertThisInitialized(_this), event);
|
|
2347
|
+
}
|
|
2348
|
+
};
|
|
2349
|
+
|
|
2350
|
+
_this.inputHandleChange = function (event) {
|
|
2351
|
+
_this.internalSetState({
|
|
2352
|
+
type: changeInput,
|
|
2353
|
+
isOpen: true,
|
|
2354
|
+
inputValue: event.target.value,
|
|
2355
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2203
2356
|
});
|
|
2204
|
-
}
|
|
2205
|
-
};
|
|
2357
|
+
};
|
|
2206
2358
|
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2359
|
+
_this.inputHandleBlur = function () {
|
|
2360
|
+
// Need setTimeout, so that when the user presses Tab, the activeElement is the next focused element, not the body element
|
|
2361
|
+
_this.internalSetTimeout(function () {
|
|
2362
|
+
var downshiftButtonIsActive = _this.props.environment.document && !!_this.props.environment.document.activeElement && !!_this.props.environment.document.activeElement.dataset && _this.props.environment.document.activeElement.dataset.toggle && _this._rootNode && _this._rootNode.contains(_this.props.environment.document.activeElement);
|
|
2210
2363
|
|
|
2211
|
-
|
|
2212
|
-
if (!_this.isMouseDown && (_this.props.environment.document.activeElement == null || _this.props.environment.document.activeElement.id !== _this.inputId) && _this.props.environment.document.activeElement !== blurTarget // Do nothing if we refocus the same element again (to solve issue in Safari on iOS)
|
|
2213
|
-
) {
|
|
2364
|
+
if (!_this.isMouseDown && !downshiftButtonIsActive) {
|
|
2214
2365
|
_this.reset({
|
|
2215
|
-
type:
|
|
2366
|
+
type: blurInput
|
|
2216
2367
|
});
|
|
2217
2368
|
}
|
|
2218
|
-
|
|
2219
|
-
|
|
2369
|
+
});
|
|
2370
|
+
};
|
|
2220
2371
|
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
id: _this.labelId
|
|
2225
|
-
}, props);
|
|
2226
|
-
};
|
|
2372
|
+
_this.menuRef = function (node) {
|
|
2373
|
+
_this._menuNode = node;
|
|
2374
|
+
};
|
|
2227
2375
|
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
onKeyDown = _ref4.onKeyDown,
|
|
2231
|
-
onBlur = _ref4.onBlur,
|
|
2232
|
-
onChange = _ref4.onChange,
|
|
2233
|
-
onInput = _ref4.onInput,
|
|
2234
|
-
onChangeText = _ref4.onChangeText,
|
|
2235
|
-
rest = _objectWithoutPropertiesLoose(_ref4, ["onKeyDown", "onBlur", "onChange", "onInput", "onChangeText"]);
|
|
2376
|
+
_this.getMenuProps = function (_temp5, _temp6) {
|
|
2377
|
+
var _extends3;
|
|
2236
2378
|
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2379
|
+
var _ref5 = _temp5 === void 0 ? {} : _temp5,
|
|
2380
|
+
_ref5$refKey = _ref5.refKey,
|
|
2381
|
+
refKey = _ref5$refKey === void 0 ? 'ref' : _ref5$refKey,
|
|
2382
|
+
ref = _ref5.ref,
|
|
2383
|
+
props = _objectWithoutPropertiesLoose(_ref5, ["refKey", "ref"]);
|
|
2240
2384
|
|
|
2241
|
-
|
|
2385
|
+
var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
|
2386
|
+
_ref6$suppressRefErro = _ref6.suppressRefError,
|
|
2387
|
+
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
2242
2388
|
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2389
|
+
_this.getMenuProps.called = true;
|
|
2390
|
+
_this.getMenuProps.refKey = refKey;
|
|
2391
|
+
_this.getMenuProps.suppressRefError = suppressRefError;
|
|
2392
|
+
return _extends((_extends3 = {}, _extends3[refKey] = handleRefs(ref, _this.menuRef), _extends3.role = 'listbox', _extends3['aria-labelledby'] = props && props['aria-label'] ? null : _this.labelId, _extends3.id = _this.menuId, _extends3), props);
|
|
2393
|
+
};
|
|
2247
2394
|
|
|
2248
|
-
|
|
2249
|
-
var
|
|
2395
|
+
_this.getItemProps = function (_temp7) {
|
|
2396
|
+
var _enabledEventHandlers;
|
|
2250
2397
|
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2398
|
+
var _ref7 = _temp7 === void 0 ? {} : _temp7,
|
|
2399
|
+
onMouseMove = _ref7.onMouseMove,
|
|
2400
|
+
onMouseDown = _ref7.onMouseDown,
|
|
2401
|
+
onClick = _ref7.onClick,
|
|
2402
|
+
onPress = _ref7.onPress,
|
|
2403
|
+
index = _ref7.index,
|
|
2404
|
+
_ref7$item = _ref7.item,
|
|
2405
|
+
item = _ref7$item === void 0 ? requiredProp('getItemProps', 'item') : _ref7$item,
|
|
2406
|
+
rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
|
|
2254
2407
|
|
|
2408
|
+
if (index === undefined) {
|
|
2409
|
+
_this.items.push(item);
|
|
2255
2410
|
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
'aria-labelledby': _this.labelId,
|
|
2261
|
-
// https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
|
|
2262
|
-
// revert back since autocomplete="nope" is ignored on latest Chrome and Opera
|
|
2263
|
-
autoComplete: 'off',
|
|
2264
|
-
value: inputValue,
|
|
2265
|
-
id: _this.inputId
|
|
2266
|
-
}, eventHandlers, {}, rest);
|
|
2267
|
-
};
|
|
2411
|
+
index = _this.items.indexOf(item);
|
|
2412
|
+
} else {
|
|
2413
|
+
_this.items[index] = item;
|
|
2414
|
+
}
|
|
2268
2415
|
|
|
2269
|
-
|
|
2270
|
-
|
|
2416
|
+
var onSelectKey = 'onClick';
|
|
2417
|
+
var customClickHandler = onClick;
|
|
2418
|
+
var enabledEventHandlers = (_enabledEventHandlers = {
|
|
2419
|
+
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
2420
|
+
// is only triggered on actual mouse movement while onMouseEnter
|
|
2421
|
+
// can fire on DOM changes, interrupting keyboard navigation
|
|
2422
|
+
onMouseMove: callAllEventHandlers(onMouseMove, function () {
|
|
2423
|
+
if (index === _this.getState().highlightedIndex) {
|
|
2424
|
+
return;
|
|
2425
|
+
}
|
|
2271
2426
|
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2427
|
+
_this.setHighlightedIndex(index, {
|
|
2428
|
+
type: itemMouseEnter
|
|
2429
|
+
}); // We never want to manually scroll when changing state based
|
|
2430
|
+
// on `onMouseMove` because we will be moving the element out
|
|
2431
|
+
// from under the user which is currently scrolling/moving the
|
|
2432
|
+
// cursor
|
|
2433
|
+
|
|
2434
|
+
|
|
2435
|
+
_this.avoidScrolling = true;
|
|
2436
|
+
|
|
2437
|
+
_this.internalSetTimeout(function () {
|
|
2438
|
+
return _this.avoidScrolling = false;
|
|
2439
|
+
}, 250);
|
|
2440
|
+
}),
|
|
2441
|
+
onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
|
|
2442
|
+
// This prevents the activeElement from being changed
|
|
2443
|
+
// to the item so it can remain with the current activeElement
|
|
2444
|
+
// which is a more common use case.
|
|
2445
|
+
event.preventDefault();
|
|
2446
|
+
})
|
|
2447
|
+
}, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
|
|
2448
|
+
_this.selectItemAtIndex(index, {
|
|
2449
|
+
type: clickItem
|
|
2450
|
+
});
|
|
2451
|
+
}), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
|
|
2452
|
+
// of the activeElement if clicking on disabled items
|
|
2276
2453
|
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2454
|
+
var eventHandlers = rest.disabled ? {
|
|
2455
|
+
onMouseDown: enabledEventHandlers.onMouseDown
|
|
2456
|
+
} : enabledEventHandlers;
|
|
2457
|
+
return _extends({
|
|
2458
|
+
id: _this.getItemId(index),
|
|
2459
|
+
role: 'option',
|
|
2460
|
+
'aria-selected': _this.getState().highlightedIndex === index
|
|
2461
|
+
}, eventHandlers, {}, rest);
|
|
2462
|
+
};
|
|
2285
2463
|
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
var downshiftButtonIsActive = _this.props.environment.document && !!_this.props.environment.document.activeElement && !!_this.props.environment.document.activeElement.dataset && _this.props.environment.document.activeElement.dataset.toggle && _this._rootNode && _this._rootNode.contains(_this.props.environment.document.activeElement);
|
|
2464
|
+
_this.clearItems = function () {
|
|
2465
|
+
_this.items = [];
|
|
2466
|
+
};
|
|
2290
2467
|
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
});
|
|
2468
|
+
_this.reset = function (otherStateToSet, cb) {
|
|
2469
|
+
if (otherStateToSet === void 0) {
|
|
2470
|
+
otherStateToSet = {};
|
|
2295
2471
|
}
|
|
2296
|
-
});
|
|
2297
|
-
};
|
|
2298
2472
|
|
|
2299
|
-
|
|
2300
|
-
_this._menuNode = node;
|
|
2301
|
-
};
|
|
2473
|
+
otherStateToSet = pickState(otherStateToSet);
|
|
2302
2474
|
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
var _ref6 = _temp6 === void 0 ? {} : _temp6,
|
|
2313
|
-
_ref6$suppressRefErro = _ref6.suppressRefError,
|
|
2314
|
-
suppressRefError = _ref6$suppressRefErro === void 0 ? false : _ref6$suppressRefErro;
|
|
2475
|
+
_this.internalSetState(function (_ref8) {
|
|
2476
|
+
var selectedItem = _ref8.selectedItem;
|
|
2477
|
+
return _extends({
|
|
2478
|
+
isOpen: _this.props.defaultIsOpen,
|
|
2479
|
+
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
2480
|
+
inputValue: _this.props.itemToString(selectedItem)
|
|
2481
|
+
}, otherStateToSet);
|
|
2482
|
+
}, cb);
|
|
2483
|
+
};
|
|
2315
2484
|
|
|
2316
|
-
_this.
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
};
|
|
2485
|
+
_this.toggleMenu = function (otherStateToSet, cb) {
|
|
2486
|
+
if (otherStateToSet === void 0) {
|
|
2487
|
+
otherStateToSet = {};
|
|
2488
|
+
}
|
|
2321
2489
|
|
|
2322
|
-
|
|
2323
|
-
|
|
2490
|
+
otherStateToSet = pickState(otherStateToSet);
|
|
2491
|
+
|
|
2492
|
+
_this.internalSetState(function (_ref9) {
|
|
2493
|
+
var isOpen = _ref9.isOpen;
|
|
2494
|
+
return _extends({
|
|
2495
|
+
isOpen: !isOpen
|
|
2496
|
+
}, isOpen && {
|
|
2497
|
+
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2498
|
+
}, {}, otherStateToSet);
|
|
2499
|
+
}, function () {
|
|
2500
|
+
var _this$getState5 = _this.getState(),
|
|
2501
|
+
isOpen = _this$getState5.isOpen,
|
|
2502
|
+
highlightedIndex = _this$getState5.highlightedIndex;
|
|
2503
|
+
|
|
2504
|
+
if (isOpen) {
|
|
2505
|
+
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
2506
|
+
_this.setHighlightedIndex(highlightedIndex, otherStateToSet);
|
|
2507
|
+
}
|
|
2508
|
+
}
|
|
2324
2509
|
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
onClick = _ref7.onClick,
|
|
2329
|
-
onPress = _ref7.onPress,
|
|
2330
|
-
index = _ref7.index,
|
|
2331
|
-
_ref7$item = _ref7.item,
|
|
2332
|
-
item = _ref7$item === void 0 ? requiredProp('getItemProps', 'item') : _ref7$item,
|
|
2333
|
-
rest = _objectWithoutPropertiesLoose(_ref7, ["onMouseMove", "onMouseDown", "onClick", "onPress", "index", "item"]);
|
|
2510
|
+
cbToCb(cb)();
|
|
2511
|
+
});
|
|
2512
|
+
};
|
|
2334
2513
|
|
|
2335
|
-
|
|
2336
|
-
_this.
|
|
2514
|
+
_this.openMenu = function (cb) {
|
|
2515
|
+
_this.internalSetState({
|
|
2516
|
+
isOpen: true
|
|
2517
|
+
}, cb);
|
|
2518
|
+
};
|
|
2337
2519
|
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
var onSelectKey = 'onClick';
|
|
2344
|
-
var customClickHandler = onClick;
|
|
2345
|
-
var enabledEventHandlers = (_enabledEventHandlers = {
|
|
2346
|
-
// onMouseMove is used over onMouseEnter here. onMouseMove
|
|
2347
|
-
// is only triggered on actual mouse movement while onMouseEnter
|
|
2348
|
-
// can fire on DOM changes, interrupting keyboard navigation
|
|
2349
|
-
onMouseMove: callAllEventHandlers(onMouseMove, function () {
|
|
2350
|
-
if (index === _this.getState().highlightedIndex) {
|
|
2351
|
-
return;
|
|
2352
|
-
}
|
|
2520
|
+
_this.closeMenu = function (cb) {
|
|
2521
|
+
_this.internalSetState({
|
|
2522
|
+
isOpen: false
|
|
2523
|
+
}, cb);
|
|
2524
|
+
};
|
|
2353
2525
|
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2526
|
+
_this.updateStatus = debounce(function () {
|
|
2527
|
+
var state = _this.getState();
|
|
2528
|
+
|
|
2529
|
+
var item = _this.items[state.highlightedIndex];
|
|
2530
|
+
|
|
2531
|
+
var resultCount = _this.getItemCount();
|
|
2532
|
+
|
|
2533
|
+
var status = _this.props.getA11yStatusMessage(_extends({
|
|
2534
|
+
itemToString: _this.props.itemToString,
|
|
2535
|
+
previousResultCount: _this.previousResultCount,
|
|
2536
|
+
resultCount: resultCount,
|
|
2537
|
+
highlightedItem: item
|
|
2538
|
+
}, state));
|
|
2539
|
+
|
|
2540
|
+
_this.previousResultCount = resultCount;
|
|
2541
|
+
setStatus(status, _this.props.environment.document);
|
|
2542
|
+
}, 200);
|
|
2543
|
+
|
|
2544
|
+
// fancy destructuring + defaults + aliases
|
|
2545
|
+
// this basically says each value of state should either be set to
|
|
2546
|
+
// the initial value or the default value if the initial value is not provided
|
|
2547
|
+
var _this$props = _this.props,
|
|
2548
|
+
defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
|
|
2549
|
+
_this$props$initialHi = _this$props.initialHighlightedIndex,
|
|
2550
|
+
_highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
|
|
2551
|
+
defaultIsOpen = _this$props.defaultIsOpen,
|
|
2552
|
+
_this$props$initialIs = _this$props.initialIsOpen,
|
|
2553
|
+
_isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
|
|
2554
|
+
_this$props$initialIn = _this$props.initialInputValue,
|
|
2555
|
+
_inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
|
|
2556
|
+
_this$props$initialSe = _this$props.initialSelectedItem,
|
|
2557
|
+
_selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
|
|
2558
|
+
|
|
2559
|
+
var _state = _this.getState({
|
|
2560
|
+
highlightedIndex: _highlightedIndex,
|
|
2561
|
+
isOpen: _isOpen,
|
|
2562
|
+
inputValue: _inputValue,
|
|
2563
|
+
selectedItem: _selectedItem
|
|
2564
|
+
});
|
|
2360
2565
|
|
|
2566
|
+
if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
|
|
2567
|
+
_state.inputValue = _this.props.itemToString(_state.selectedItem);
|
|
2568
|
+
}
|
|
2361
2569
|
|
|
2362
|
-
|
|
2570
|
+
_this.state = _state;
|
|
2571
|
+
return _this;
|
|
2572
|
+
}
|
|
2363
2573
|
|
|
2364
|
-
|
|
2365
|
-
return _this.avoidScrolling = false;
|
|
2366
|
-
}, 250);
|
|
2367
|
-
}),
|
|
2368
|
-
onMouseDown: callAllEventHandlers(onMouseDown, function (event) {
|
|
2369
|
-
// This prevents the activeElement from being changed
|
|
2370
|
-
// to the item so it can remain with the current activeElement
|
|
2371
|
-
// which is a more common use case.
|
|
2372
|
-
event.preventDefault();
|
|
2373
|
-
})
|
|
2374
|
-
}, _enabledEventHandlers[onSelectKey] = callAllEventHandlers(customClickHandler, function () {
|
|
2375
|
-
_this.selectItemAtIndex(index, {
|
|
2376
|
-
type: clickItem
|
|
2377
|
-
});
|
|
2378
|
-
}), _enabledEventHandlers); // Passing down the onMouseDown handler to prevent redirect
|
|
2379
|
-
// of the activeElement if clicking on disabled items
|
|
2574
|
+
var _proto = Downshift.prototype;
|
|
2380
2575
|
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
}
|
|
2576
|
+
/**
|
|
2577
|
+
* Clear all running timeouts
|
|
2578
|
+
*/
|
|
2579
|
+
_proto.internalClearTimeouts = function internalClearTimeouts() {
|
|
2580
|
+
this.timeoutIds.forEach(function (id) {
|
|
2581
|
+
clearTimeout(id);
|
|
2582
|
+
});
|
|
2583
|
+
this.timeoutIds = [];
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Gets the state based on internal state or props
|
|
2587
|
+
* If a state value is passed via props, then that
|
|
2588
|
+
* is the value given, otherwise it's retrieved from
|
|
2589
|
+
* stateToMerge
|
|
2590
|
+
*
|
|
2591
|
+
* This will perform a shallow merge of the given state object
|
|
2592
|
+
* with the state coming from props
|
|
2593
|
+
* (for the controlled component scenario)
|
|
2594
|
+
* This is used in state updater functions so they're referencing
|
|
2595
|
+
* the right state regardless of where it comes from.
|
|
2596
|
+
*
|
|
2597
|
+
* @param {Object} stateToMerge defaults to this.state
|
|
2598
|
+
* @return {Object} the state
|
|
2599
|
+
*/
|
|
2600
|
+
;
|
|
2390
2601
|
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
};
|
|
2602
|
+
_proto.getState = function getState(stateToMerge) {
|
|
2603
|
+
var _this4 = this;
|
|
2394
2604
|
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
otherStateToSet = {};
|
|
2605
|
+
if (stateToMerge === void 0) {
|
|
2606
|
+
stateToMerge = this.state;
|
|
2398
2607
|
}
|
|
2399
2608
|
|
|
2400
|
-
|
|
2609
|
+
return Object.keys(stateToMerge).reduce(function (state, key) {
|
|
2610
|
+
state[key] = _this4.isControlledProp(key) ? _this4.props[key] : stateToMerge[key];
|
|
2611
|
+
return state;
|
|
2612
|
+
}, {});
|
|
2613
|
+
}
|
|
2614
|
+
/**
|
|
2615
|
+
* This determines whether a prop is a "controlled prop" meaning it is
|
|
2616
|
+
* state which is controlled by the outside of this component rather
|
|
2617
|
+
* than within this component.
|
|
2618
|
+
* @param {String} key the key to check
|
|
2619
|
+
* @return {Boolean} whether it is a controlled controlled prop
|
|
2620
|
+
*/
|
|
2621
|
+
;
|
|
2401
2622
|
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
return _extends({
|
|
2405
|
-
isOpen: _this.props.defaultIsOpen,
|
|
2406
|
-
highlightedIndex: _this.props.defaultHighlightedIndex,
|
|
2407
|
-
inputValue: _this.props.itemToString(selectedItem)
|
|
2408
|
-
}, otherStateToSet);
|
|
2409
|
-
}, cb);
|
|
2623
|
+
_proto.isControlledProp = function isControlledProp(key) {
|
|
2624
|
+
return this.props[key] !== undefined;
|
|
2410
2625
|
};
|
|
2411
2626
|
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2627
|
+
_proto.getItemCount = function getItemCount() {
|
|
2628
|
+
// things read better this way. They're in priority order:
|
|
2629
|
+
// 1. `this.itemCount`
|
|
2630
|
+
// 2. `this.props.itemCount`
|
|
2631
|
+
// 3. `this.items.length`
|
|
2632
|
+
var itemCount = this.items.length;
|
|
2633
|
+
|
|
2634
|
+
if (this.itemCount != null) {
|
|
2635
|
+
itemCount = this.itemCount;
|
|
2636
|
+
} else if (this.props.itemCount !== undefined) {
|
|
2637
|
+
itemCount = this.props.itemCount;
|
|
2415
2638
|
}
|
|
2416
2639
|
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
_this.internalSetState(function (_ref9) {
|
|
2420
|
-
var isOpen = _ref9.isOpen;
|
|
2421
|
-
return _extends({
|
|
2422
|
-
isOpen: !isOpen
|
|
2423
|
-
}, isOpen && {
|
|
2424
|
-
highlightedIndex: _this.props.defaultHighlightedIndex
|
|
2425
|
-
}, {}, otherStateToSet);
|
|
2426
|
-
}, function () {
|
|
2427
|
-
var _this$getState5 = _this.getState(),
|
|
2428
|
-
isOpen = _this$getState5.isOpen,
|
|
2429
|
-
highlightedIndex = _this$getState5.highlightedIndex;
|
|
2430
|
-
|
|
2431
|
-
if (isOpen) {
|
|
2432
|
-
if (_this.getItemCount() > 0 && typeof highlightedIndex === 'number') {
|
|
2433
|
-
_this.setHighlightedIndex(highlightedIndex, otherStateToSet);
|
|
2434
|
-
}
|
|
2435
|
-
}
|
|
2436
|
-
|
|
2437
|
-
cbToCb(cb)();
|
|
2438
|
-
});
|
|
2640
|
+
return itemCount;
|
|
2439
2641
|
};
|
|
2440
2642
|
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
isOpen: true
|
|
2444
|
-
}, cb);
|
|
2643
|
+
_proto.getItemNodeFromIndex = function getItemNodeFromIndex(index) {
|
|
2644
|
+
return this.props.environment.document.getElementById(this.getItemId(index));
|
|
2445
2645
|
};
|
|
2446
2646
|
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2647
|
+
_proto.scrollHighlightedItemIntoView = function scrollHighlightedItemIntoView() {
|
|
2648
|
+
/* istanbul ignore else (react-native) */
|
|
2649
|
+
{
|
|
2650
|
+
var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
|
2651
|
+
this.props.scrollIntoView(node, this._menuNode);
|
|
2652
|
+
}
|
|
2451
2653
|
};
|
|
2452
2654
|
|
|
2453
|
-
|
|
2454
|
-
var
|
|
2455
|
-
|
|
2456
|
-
var item = _this.items[state.highlightedIndex];
|
|
2457
|
-
|
|
2458
|
-
var resultCount = _this.getItemCount();
|
|
2459
|
-
|
|
2460
|
-
var status = _this.props.getA11yStatusMessage(_extends({
|
|
2461
|
-
itemToString: _this.props.itemToString,
|
|
2462
|
-
previousResultCount: _this.previousResultCount,
|
|
2463
|
-
resultCount: resultCount,
|
|
2464
|
-
highlightedItem: item
|
|
2465
|
-
}, state));
|
|
2466
|
-
|
|
2467
|
-
_this.previousResultCount = resultCount;
|
|
2468
|
-
setStatus(status, _this.props.environment.document);
|
|
2469
|
-
}, 200);
|
|
2470
|
-
|
|
2471
|
-
// fancy destructuring + defaults + aliases
|
|
2472
|
-
// this basically says each value of state should either be set to
|
|
2473
|
-
// the initial value or the default value if the initial value is not provided
|
|
2474
|
-
var _this$props = _this.props,
|
|
2475
|
-
defaultHighlightedIndex = _this$props.defaultHighlightedIndex,
|
|
2476
|
-
_this$props$initialHi = _this$props.initialHighlightedIndex,
|
|
2477
|
-
_highlightedIndex = _this$props$initialHi === void 0 ? defaultHighlightedIndex : _this$props$initialHi,
|
|
2478
|
-
defaultIsOpen = _this$props.defaultIsOpen,
|
|
2479
|
-
_this$props$initialIs = _this$props.initialIsOpen,
|
|
2480
|
-
_isOpen = _this$props$initialIs === void 0 ? defaultIsOpen : _this$props$initialIs,
|
|
2481
|
-
_this$props$initialIn = _this$props.initialInputValue,
|
|
2482
|
-
_inputValue = _this$props$initialIn === void 0 ? '' : _this$props$initialIn,
|
|
2483
|
-
_this$props$initialSe = _this$props.initialSelectedItem,
|
|
2484
|
-
_selectedItem = _this$props$initialSe === void 0 ? null : _this$props$initialSe;
|
|
2485
|
-
|
|
2486
|
-
var _state = _this.getState({
|
|
2487
|
-
highlightedIndex: _highlightedIndex,
|
|
2488
|
-
isOpen: _isOpen,
|
|
2489
|
-
inputValue: _inputValue,
|
|
2490
|
-
selectedItem: _selectedItem
|
|
2491
|
-
});
|
|
2492
|
-
|
|
2493
|
-
if (_state.selectedItem != null && _this.props.initialInputValue === undefined) {
|
|
2494
|
-
_state.inputValue = _this.props.itemToString(_state.selectedItem);
|
|
2495
|
-
}
|
|
2496
|
-
|
|
2497
|
-
_this.state = _state;
|
|
2498
|
-
return _this;
|
|
2499
|
-
}
|
|
2500
|
-
|
|
2501
|
-
var _proto = Downshift.prototype;
|
|
2502
|
-
|
|
2503
|
-
/**
|
|
2504
|
-
* Clear all running timeouts
|
|
2505
|
-
*/
|
|
2506
|
-
_proto.internalClearTimeouts = function internalClearTimeouts() {
|
|
2507
|
-
this.timeoutIds.forEach(function (id) {
|
|
2508
|
-
clearTimeout(id);
|
|
2509
|
-
});
|
|
2510
|
-
this.timeoutIds = [];
|
|
2511
|
-
}
|
|
2512
|
-
/**
|
|
2513
|
-
* Gets the state based on internal state or props
|
|
2514
|
-
* If a state value is passed via props, then that
|
|
2515
|
-
* is the value given, otherwise it's retrieved from
|
|
2516
|
-
* stateToMerge
|
|
2517
|
-
*
|
|
2518
|
-
* This will perform a shallow merge of the given state object
|
|
2519
|
-
* with the state coming from props
|
|
2520
|
-
* (for the controlled component scenario)
|
|
2521
|
-
* This is used in state updater functions so they're referencing
|
|
2522
|
-
* the right state regardless of where it comes from.
|
|
2523
|
-
*
|
|
2524
|
-
* @param {Object} stateToMerge defaults to this.state
|
|
2525
|
-
* @return {Object} the state
|
|
2526
|
-
*/
|
|
2527
|
-
;
|
|
2528
|
-
|
|
2529
|
-
_proto.getState = function getState(stateToMerge) {
|
|
2530
|
-
var _this4 = this;
|
|
2531
|
-
|
|
2532
|
-
if (stateToMerge === void 0) {
|
|
2533
|
-
stateToMerge = this.state;
|
|
2534
|
-
}
|
|
2535
|
-
|
|
2536
|
-
return Object.keys(stateToMerge).reduce(function (state, key) {
|
|
2537
|
-
state[key] = _this4.isControlledProp(key) ? _this4.props[key] : stateToMerge[key];
|
|
2538
|
-
return state;
|
|
2539
|
-
}, {});
|
|
2540
|
-
}
|
|
2541
|
-
/**
|
|
2542
|
-
* This determines whether a prop is a "controlled prop" meaning it is
|
|
2543
|
-
* state which is controlled by the outside of this component rather
|
|
2544
|
-
* than within this component.
|
|
2545
|
-
* @param {String} key the key to check
|
|
2546
|
-
* @return {Boolean} whether it is a controlled controlled prop
|
|
2547
|
-
*/
|
|
2548
|
-
;
|
|
2549
|
-
|
|
2550
|
-
_proto.isControlledProp = function isControlledProp(key) {
|
|
2551
|
-
return this.props[key] !== undefined;
|
|
2552
|
-
};
|
|
2655
|
+
_proto.moveHighlightedIndex = function moveHighlightedIndex(amount, otherStateToSet) {
|
|
2656
|
+
var itemCount = this.getItemCount();
|
|
2553
2657
|
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
var itemCount = this.items.length;
|
|
2560
|
-
|
|
2561
|
-
if (this.itemCount != null) {
|
|
2562
|
-
itemCount = this.itemCount;
|
|
2563
|
-
} else if (this.props.itemCount !== undefined) {
|
|
2564
|
-
itemCount = this.props.itemCount;
|
|
2565
|
-
}
|
|
2658
|
+
if (itemCount > 0) {
|
|
2659
|
+
var nextHighlightedIndex = getNextWrappingIndex(amount, this.getState().highlightedIndex, itemCount);
|
|
2660
|
+
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
2661
|
+
}
|
|
2662
|
+
};
|
|
2566
2663
|
|
|
2567
|
-
|
|
2568
|
-
|
|
2664
|
+
_proto.highlightFirstOrLastIndex = function highlightFirstOrLastIndex(event, first, otherStateToSet) {
|
|
2665
|
+
var itemsLastIndex = this.getItemCount() - 1;
|
|
2569
2666
|
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2667
|
+
if (itemsLastIndex < 0 || !this.getState().isOpen) {
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2573
2670
|
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
var node = this.getItemNodeFromIndex(this.getState().highlightedIndex);
|
|
2578
|
-
this.props.scrollIntoView(node, this._menuNode);
|
|
2579
|
-
}
|
|
2580
|
-
};
|
|
2671
|
+
event.preventDefault();
|
|
2672
|
+
this.setHighlightedIndex(first ? 0 : itemsLastIndex, otherStateToSet);
|
|
2673
|
+
};
|
|
2581
2674
|
|
|
2582
|
-
|
|
2583
|
-
|
|
2675
|
+
_proto.getStateAndHelpers = function getStateAndHelpers() {
|
|
2676
|
+
var _this$getState6 = this.getState(),
|
|
2677
|
+
highlightedIndex = _this$getState6.highlightedIndex,
|
|
2678
|
+
inputValue = _this$getState6.inputValue,
|
|
2679
|
+
selectedItem = _this$getState6.selectedItem,
|
|
2680
|
+
isOpen = _this$getState6.isOpen;
|
|
2681
|
+
|
|
2682
|
+
var itemToString = this.props.itemToString;
|
|
2683
|
+
var id = this.id;
|
|
2684
|
+
var getRootProps = this.getRootProps,
|
|
2685
|
+
getToggleButtonProps = this.getToggleButtonProps,
|
|
2686
|
+
getLabelProps = this.getLabelProps,
|
|
2687
|
+
getMenuProps = this.getMenuProps,
|
|
2688
|
+
getInputProps = this.getInputProps,
|
|
2689
|
+
getItemProps = this.getItemProps,
|
|
2690
|
+
openMenu = this.openMenu,
|
|
2691
|
+
closeMenu = this.closeMenu,
|
|
2692
|
+
toggleMenu = this.toggleMenu,
|
|
2693
|
+
selectItem = this.selectItem,
|
|
2694
|
+
selectItemAtIndex = this.selectItemAtIndex,
|
|
2695
|
+
selectHighlightedItem = this.selectHighlightedItem,
|
|
2696
|
+
setHighlightedIndex = this.setHighlightedIndex,
|
|
2697
|
+
clearSelection = this.clearSelection,
|
|
2698
|
+
clearItems = this.clearItems,
|
|
2699
|
+
reset = this.reset,
|
|
2700
|
+
setItemCount = this.setItemCount,
|
|
2701
|
+
unsetItemCount = this.unsetItemCount,
|
|
2702
|
+
setState = this.internalSetState;
|
|
2703
|
+
return {
|
|
2704
|
+
// prop getters
|
|
2705
|
+
getRootProps: getRootProps,
|
|
2706
|
+
getToggleButtonProps: getToggleButtonProps,
|
|
2707
|
+
getLabelProps: getLabelProps,
|
|
2708
|
+
getMenuProps: getMenuProps,
|
|
2709
|
+
getInputProps: getInputProps,
|
|
2710
|
+
getItemProps: getItemProps,
|
|
2711
|
+
// actions
|
|
2712
|
+
reset: reset,
|
|
2713
|
+
openMenu: openMenu,
|
|
2714
|
+
closeMenu: closeMenu,
|
|
2715
|
+
toggleMenu: toggleMenu,
|
|
2716
|
+
selectItem: selectItem,
|
|
2717
|
+
selectItemAtIndex: selectItemAtIndex,
|
|
2718
|
+
selectHighlightedItem: selectHighlightedItem,
|
|
2719
|
+
setHighlightedIndex: setHighlightedIndex,
|
|
2720
|
+
clearSelection: clearSelection,
|
|
2721
|
+
clearItems: clearItems,
|
|
2722
|
+
setItemCount: setItemCount,
|
|
2723
|
+
unsetItemCount: unsetItemCount,
|
|
2724
|
+
setState: setState,
|
|
2725
|
+
// props
|
|
2726
|
+
itemToString: itemToString,
|
|
2727
|
+
// derived
|
|
2728
|
+
id: id,
|
|
2729
|
+
// state
|
|
2730
|
+
highlightedIndex: highlightedIndex,
|
|
2731
|
+
inputValue: inputValue,
|
|
2732
|
+
isOpen: isOpen,
|
|
2733
|
+
selectedItem: selectedItem
|
|
2734
|
+
};
|
|
2735
|
+
} //////////////////////////// ROOT
|
|
2736
|
+
;
|
|
2584
2737
|
|
|
2585
|
-
|
|
2586
|
-
var
|
|
2587
|
-
this.setHighlightedIndex(nextHighlightedIndex, otherStateToSet);
|
|
2588
|
-
}
|
|
2589
|
-
};
|
|
2738
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
2739
|
+
var _this5 = this;
|
|
2590
2740
|
|
|
2591
|
-
|
|
2592
|
-
|
|
2741
|
+
/* istanbul ignore if (react-native) */
|
|
2742
|
+
if ( this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
2743
|
+
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
2744
|
+
}
|
|
2745
|
+
/* istanbul ignore if (react-native) */
|
|
2593
2746
|
|
|
2594
|
-
if (itemsLastIndex < 0 || !this.getState().isOpen) {
|
|
2595
|
-
return;
|
|
2596
|
-
}
|
|
2597
2747
|
|
|
2598
|
-
|
|
2599
|
-
|
|
2600
|
-
|
|
2748
|
+
{
|
|
2749
|
+
var targetWithinDownshift = function (target, checkActiveElement) {
|
|
2750
|
+
if (checkActiveElement === void 0) {
|
|
2751
|
+
checkActiveElement = true;
|
|
2752
|
+
}
|
|
2601
2753
|
|
|
2602
|
-
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
var getRootProps = this.getRootProps,
|
|
2612
|
-
getToggleButtonProps = this.getToggleButtonProps,
|
|
2613
|
-
getLabelProps = this.getLabelProps,
|
|
2614
|
-
getMenuProps = this.getMenuProps,
|
|
2615
|
-
getInputProps = this.getInputProps,
|
|
2616
|
-
getItemProps = this.getItemProps,
|
|
2617
|
-
openMenu = this.openMenu,
|
|
2618
|
-
closeMenu = this.closeMenu,
|
|
2619
|
-
toggleMenu = this.toggleMenu,
|
|
2620
|
-
selectItem = this.selectItem,
|
|
2621
|
-
selectItemAtIndex = this.selectItemAtIndex,
|
|
2622
|
-
selectHighlightedItem = this.selectHighlightedItem,
|
|
2623
|
-
setHighlightedIndex = this.setHighlightedIndex,
|
|
2624
|
-
clearSelection = this.clearSelection,
|
|
2625
|
-
clearItems = this.clearItems,
|
|
2626
|
-
reset = this.reset,
|
|
2627
|
-
setItemCount = this.setItemCount,
|
|
2628
|
-
unsetItemCount = this.unsetItemCount,
|
|
2629
|
-
setState = this.internalSetState;
|
|
2630
|
-
return {
|
|
2631
|
-
// prop getters
|
|
2632
|
-
getRootProps: getRootProps,
|
|
2633
|
-
getToggleButtonProps: getToggleButtonProps,
|
|
2634
|
-
getLabelProps: getLabelProps,
|
|
2635
|
-
getMenuProps: getMenuProps,
|
|
2636
|
-
getInputProps: getInputProps,
|
|
2637
|
-
getItemProps: getItemProps,
|
|
2638
|
-
// actions
|
|
2639
|
-
reset: reset,
|
|
2640
|
-
openMenu: openMenu,
|
|
2641
|
-
closeMenu: closeMenu,
|
|
2642
|
-
toggleMenu: toggleMenu,
|
|
2643
|
-
selectItem: selectItem,
|
|
2644
|
-
selectItemAtIndex: selectItemAtIndex,
|
|
2645
|
-
selectHighlightedItem: selectHighlightedItem,
|
|
2646
|
-
setHighlightedIndex: setHighlightedIndex,
|
|
2647
|
-
clearSelection: clearSelection,
|
|
2648
|
-
clearItems: clearItems,
|
|
2649
|
-
setItemCount: setItemCount,
|
|
2650
|
-
unsetItemCount: unsetItemCount,
|
|
2651
|
-
setState: setState,
|
|
2652
|
-
// props
|
|
2653
|
-
itemToString: itemToString,
|
|
2654
|
-
// derived
|
|
2655
|
-
id: id,
|
|
2656
|
-
// state
|
|
2657
|
-
highlightedIndex: highlightedIndex,
|
|
2658
|
-
inputValue: inputValue,
|
|
2659
|
-
isOpen: isOpen,
|
|
2660
|
-
selectedItem: selectedItem
|
|
2661
|
-
};
|
|
2662
|
-
} //////////////////////////// ROOT
|
|
2663
|
-
;
|
|
2754
|
+
var document = _this5.props.environment.document;
|
|
2755
|
+
return [_this5._rootNode, _this5._menuNode].some(function (contextNode) {
|
|
2756
|
+
return contextNode && (isOrContainsNode(contextNode, target) || checkActiveElement && isOrContainsNode(contextNode, document.activeElement));
|
|
2757
|
+
});
|
|
2758
|
+
}; // this.isMouseDown helps us track whether the mouse is currently held down.
|
|
2759
|
+
// This is useful when the user clicks on an item in the list, but holds the mouse
|
|
2760
|
+
// down long enough for the list to disappear (because the blur event fires on the input)
|
|
2761
|
+
// this.isMouseDown is used in the blur handler on the input to determine whether the blur event should
|
|
2762
|
+
// trigger hiding the menu.
|
|
2664
2763
|
|
|
2665
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
2666
|
-
var _this5 = this;
|
|
2667
2764
|
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
}
|
|
2672
|
-
/* istanbul ignore if (react-native) */
|
|
2765
|
+
var onMouseDown = function () {
|
|
2766
|
+
_this5.isMouseDown = true;
|
|
2767
|
+
};
|
|
2673
2768
|
|
|
2769
|
+
var onMouseUp = function (event) {
|
|
2770
|
+
_this5.isMouseDown = false; // if the target element or the activeElement is within a downshift node
|
|
2771
|
+
// then we don't want to reset downshift
|
|
2674
2772
|
|
|
2675
|
-
|
|
2676
|
-
var targetWithinDownshift = function (target, checkActiveElement) {
|
|
2677
|
-
if (checkActiveElement === void 0) {
|
|
2678
|
-
checkActiveElement = true;
|
|
2679
|
-
}
|
|
2773
|
+
var contextWithinDownshift = targetWithinDownshift(event.target);
|
|
2680
2774
|
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2775
|
+
if (!contextWithinDownshift && _this5.getState().isOpen) {
|
|
2776
|
+
_this5.reset({
|
|
2777
|
+
type: mouseUp
|
|
2778
|
+
}, function () {
|
|
2779
|
+
return _this5.props.onOuterClick(_this5.getStateAndHelpers());
|
|
2780
|
+
});
|
|
2781
|
+
}
|
|
2782
|
+
}; // Touching an element in iOS gives focus and hover states, but touching out of
|
|
2783
|
+
// the element will remove hover, and persist the focus state, resulting in the
|
|
2784
|
+
// blur event not being triggered.
|
|
2785
|
+
// this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
|
|
2786
|
+
// If the user taps outside of Downshift, the component should be reset,
|
|
2787
|
+
// but not if the user is swiping
|
|
2690
2788
|
|
|
2691
2789
|
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2790
|
+
var onTouchStart = function () {
|
|
2791
|
+
_this5.isTouchMove = false;
|
|
2792
|
+
};
|
|
2695
2793
|
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2794
|
+
var onTouchMove = function () {
|
|
2795
|
+
_this5.isTouchMove = true;
|
|
2796
|
+
};
|
|
2699
2797
|
|
|
2700
|
-
var
|
|
2798
|
+
var onTouchEnd = function (event) {
|
|
2799
|
+
var contextWithinDownshift = targetWithinDownshift(event.target, false);
|
|
2701
2800
|
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
// the element will remove hover, and persist the focus state, resulting in the
|
|
2711
|
-
// blur event not being triggered.
|
|
2712
|
-
// this.isTouchMove helps us track whether the user is tapping or swiping on a touch screen.
|
|
2713
|
-
// If the user taps outside of Downshift, the component should be reset,
|
|
2714
|
-
// but not if the user is swiping
|
|
2801
|
+
if (!_this5.isTouchMove && !contextWithinDownshift && _this5.getState().isOpen) {
|
|
2802
|
+
_this5.reset({
|
|
2803
|
+
type: touchEnd
|
|
2804
|
+
}, function () {
|
|
2805
|
+
return _this5.props.onOuterClick(_this5.getStateAndHelpers());
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
};
|
|
2715
2809
|
|
|
2810
|
+
var environment = this.props.environment;
|
|
2811
|
+
environment.addEventListener('mousedown', onMouseDown);
|
|
2812
|
+
environment.addEventListener('mouseup', onMouseUp);
|
|
2813
|
+
environment.addEventListener('touchstart', onTouchStart);
|
|
2814
|
+
environment.addEventListener('touchmove', onTouchMove);
|
|
2815
|
+
environment.addEventListener('touchend', onTouchEnd);
|
|
2716
2816
|
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
};
|
|
2817
|
+
this.cleanup = function () {
|
|
2818
|
+
_this5.internalClearTimeouts();
|
|
2720
2819
|
|
|
2721
|
-
|
|
2722
|
-
_this5.isTouchMove = true;
|
|
2723
|
-
};
|
|
2820
|
+
_this5.updateStatus.cancel();
|
|
2724
2821
|
|
|
2725
|
-
|
|
2726
|
-
|
|
2822
|
+
environment.removeEventListener('mousedown', onMouseDown);
|
|
2823
|
+
environment.removeEventListener('mouseup', onMouseUp);
|
|
2824
|
+
environment.removeEventListener('touchstart', onTouchStart);
|
|
2825
|
+
environment.removeEventListener('touchmove', onTouchMove);
|
|
2826
|
+
environment.removeEventListener('touchend', onTouchEnd);
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
};
|
|
2727
2830
|
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
}, function () {
|
|
2732
|
-
return _this5.props.onOuterClick(_this5.getStateAndHelpers());
|
|
2733
|
-
});
|
|
2734
|
-
}
|
|
2735
|
-
};
|
|
2831
|
+
_proto.shouldScroll = function shouldScroll(prevState, prevProps) {
|
|
2832
|
+
var _ref10 = this.props.highlightedIndex === undefined ? this.getState() : this.props,
|
|
2833
|
+
currentHighlightedIndex = _ref10.highlightedIndex;
|
|
2736
2834
|
|
|
2737
|
-
var
|
|
2738
|
-
|
|
2739
|
-
environment.addEventListener('mouseup', onMouseUp);
|
|
2740
|
-
environment.addEventListener('touchstart', onTouchStart);
|
|
2741
|
-
environment.addEventListener('touchmove', onTouchMove);
|
|
2742
|
-
environment.addEventListener('touchend', onTouchEnd);
|
|
2835
|
+
var _ref11 = prevProps.highlightedIndex === undefined ? prevState : prevProps,
|
|
2836
|
+
prevHighlightedIndex = _ref11.highlightedIndex;
|
|
2743
2837
|
|
|
2744
|
-
|
|
2745
|
-
|
|
2838
|
+
var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
2839
|
+
return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
|
|
2840
|
+
};
|
|
2746
2841
|
|
|
2747
|
-
|
|
2842
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
|
|
2843
|
+
validateControlledUnchanged(prevProps, this.props);
|
|
2844
|
+
/* istanbul ignore if (react-native) */
|
|
2748
2845
|
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
environment.removeEventListener('touchmove', onTouchMove);
|
|
2753
|
-
environment.removeEventListener('touchend', onTouchEnd);
|
|
2754
|
-
};
|
|
2755
|
-
}
|
|
2756
|
-
};
|
|
2846
|
+
if ( this.getMenuProps.called && !this.getMenuProps.suppressRefError) {
|
|
2847
|
+
validateGetMenuPropsCalledCorrectly(this._menuNode, this.getMenuProps);
|
|
2848
|
+
}
|
|
2757
2849
|
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2850
|
+
if (this.isControlledProp('selectedItem') && this.props.selectedItemChanged(prevProps.selectedItem, this.props.selectedItem)) {
|
|
2851
|
+
this.internalSetState({
|
|
2852
|
+
type: controlledPropUpdatedSelectedItem,
|
|
2853
|
+
inputValue: this.props.itemToString(this.props.selectedItem)
|
|
2854
|
+
});
|
|
2855
|
+
}
|
|
2761
2856
|
|
|
2762
|
-
|
|
2763
|
-
|
|
2857
|
+
if (!this.avoidScrolling && this.shouldScroll(prevState, prevProps)) {
|
|
2858
|
+
this.scrollHighlightedItemIntoView();
|
|
2859
|
+
}
|
|
2860
|
+
/* istanbul ignore else (react-native) */
|
|
2764
2861
|
|
|
2765
|
-
var scrollWhenOpen = currentHighlightedIndex && this.getState().isOpen && !prevState.isOpen;
|
|
2766
|
-
return scrollWhenOpen || currentHighlightedIndex !== prevHighlightedIndex;
|
|
2767
|
-
};
|
|
2768
2862
|
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
/* istanbul ignore if (react-native) */
|
|
2863
|
+
this.updateStatus();
|
|
2864
|
+
};
|
|
2772
2865
|
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
}
|
|
2866
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
2867
|
+
this.cleanup(); // avoids memory leak
|
|
2868
|
+
};
|
|
2776
2869
|
|
|
2777
|
-
|
|
2778
|
-
this.
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
});
|
|
2782
|
-
}
|
|
2870
|
+
_proto.render = function render() {
|
|
2871
|
+
var children = unwrapArray(this.props.children, noop); // because the items are rerendered every time we call the children
|
|
2872
|
+
// we clear this out each render and it will be populated again as
|
|
2873
|
+
// getItemProps is called.
|
|
2783
2874
|
|
|
2784
|
-
|
|
2785
|
-
this.
|
|
2786
|
-
|
|
2787
|
-
|
|
2875
|
+
this.clearItems(); // we reset this so we know whether the user calls getRootProps during
|
|
2876
|
+
// this render. If they do then we don't need to do anything,
|
|
2877
|
+
// if they don't then we need to clone the element they return and
|
|
2878
|
+
// apply the props for them.
|
|
2788
2879
|
|
|
2880
|
+
this.getRootProps.called = false;
|
|
2881
|
+
this.getRootProps.refKey = undefined;
|
|
2882
|
+
this.getRootProps.suppressRefError = undefined; // we do something similar for getMenuProps
|
|
2789
2883
|
|
|
2790
|
-
|
|
2791
|
-
|
|
2884
|
+
this.getMenuProps.called = false;
|
|
2885
|
+
this.getMenuProps.refKey = undefined;
|
|
2886
|
+
this.getMenuProps.suppressRefError = undefined; // we do something similar for getLabelProps
|
|
2792
2887
|
|
|
2793
|
-
|
|
2794
|
-
this.cleanup(); // avoids memory leak
|
|
2795
|
-
};
|
|
2888
|
+
this.getLabelProps.called = false; // and something similar for getInputProps
|
|
2796
2889
|
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
// we clear this out each render and it will be populated again as
|
|
2800
|
-
// getItemProps is called.
|
|
2890
|
+
this.getInputProps.called = false;
|
|
2891
|
+
var element = unwrapArray(children(this.getStateAndHelpers()));
|
|
2801
2892
|
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
// apply the props for them.
|
|
2893
|
+
if (!element) {
|
|
2894
|
+
return null;
|
|
2895
|
+
}
|
|
2806
2896
|
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2897
|
+
if (this.getRootProps.called || this.props.suppressRefError) {
|
|
2898
|
+
if ( !this.getRootProps.suppressRefError && !this.props.suppressRefError) {
|
|
2899
|
+
validateGetRootPropsCalledCorrectly(element, this.getRootProps);
|
|
2900
|
+
}
|
|
2810
2901
|
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2902
|
+
return element;
|
|
2903
|
+
} else if (isDOMElement(element)) {
|
|
2904
|
+
// they didn't apply the root props, but we can clone
|
|
2905
|
+
// this and apply the props ourselves
|
|
2906
|
+
return react.cloneElement(element, this.getRootProps(getElementProps(element)));
|
|
2907
|
+
}
|
|
2908
|
+
/* istanbul ignore else */
|
|
2814
2909
|
|
|
2815
|
-
this.getLabelProps.called = false; // and something similar for getInputProps
|
|
2816
2910
|
|
|
2817
|
-
|
|
2818
|
-
|
|
2911
|
+
// they didn't apply the root props, but they need to
|
|
2912
|
+
// otherwise we can't query around the autocomplete
|
|
2913
|
+
throw new Error('downshift: If you return a non-DOM element, you must apply the getRootProps function');
|
|
2914
|
+
/* istanbul ignore next */
|
|
2915
|
+
};
|
|
2819
2916
|
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
}
|
|
2917
|
+
return Downshift;
|
|
2918
|
+
}(react.Component);
|
|
2823
2919
|
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2920
|
+
Downshift.defaultProps = {
|
|
2921
|
+
defaultHighlightedIndex: null,
|
|
2922
|
+
defaultIsOpen: false,
|
|
2923
|
+
getA11yStatusMessage: getA11yStatusMessage,
|
|
2924
|
+
itemToString: function itemToString(i) {
|
|
2925
|
+
if (i == null) {
|
|
2926
|
+
return '';
|
|
2827
2927
|
}
|
|
2828
2928
|
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
return react.cloneElement(element, this.getRootProps(getElementProps(element)));
|
|
2834
|
-
}
|
|
2835
|
-
/* istanbul ignore else */
|
|
2836
|
-
|
|
2929
|
+
if ( isPlainObject(i) && !i.hasOwnProperty('toString')) {
|
|
2930
|
+
// eslint-disable-next-line no-console
|
|
2931
|
+
console.warn('downshift: An object was passed to the default implementation of `itemToString`. You should probably provide your own `itemToString` implementation. Please refer to the `itemToString` API documentation.', 'The object that was passed:', i);
|
|
2932
|
+
}
|
|
2837
2933
|
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2934
|
+
return String(i);
|
|
2935
|
+
},
|
|
2936
|
+
onStateChange: noop,
|
|
2937
|
+
onInputValueChange: noop,
|
|
2938
|
+
onUserAction: noop,
|
|
2939
|
+
onChange: noop,
|
|
2940
|
+
onSelect: noop,
|
|
2941
|
+
onOuterClick: noop,
|
|
2942
|
+
selectedItemChanged: function selectedItemChanged(prevItem, item) {
|
|
2943
|
+
return prevItem !== item;
|
|
2944
|
+
},
|
|
2945
|
+
environment: typeof window === 'undefined'
|
|
2946
|
+
/* istanbul ignore next (ssr) */
|
|
2947
|
+
? {} : window,
|
|
2948
|
+
stateReducer: function stateReducer(state, stateToSet) {
|
|
2949
|
+
return stateToSet;
|
|
2950
|
+
},
|
|
2951
|
+
suppressRefError: false,
|
|
2952
|
+
scrollIntoView: scrollIntoView
|
|
2842
2953
|
};
|
|
2843
|
-
|
|
2954
|
+
Downshift.stateChangeTypes = stateChangeTypes;
|
|
2844
2955
|
return Downshift;
|
|
2845
|
-
}(
|
|
2846
|
-
|
|
2847
|
-
Downshift.defaultProps = {
|
|
2848
|
-
defaultHighlightedIndex: null,
|
|
2849
|
-
defaultIsOpen: false,
|
|
2850
|
-
getA11yStatusMessage: getA11yStatusMessage,
|
|
2851
|
-
itemToString: function itemToString(i) {
|
|
2852
|
-
if (i == null) {
|
|
2853
|
-
return '';
|
|
2854
|
-
}
|
|
2855
|
-
|
|
2856
|
-
if ( isPlainObject(i) && !i.hasOwnProperty('toString')) {
|
|
2857
|
-
// eslint-disable-next-line no-console
|
|
2858
|
-
console.warn('downshift: An object was passed to the default implementation of `itemToString`. You should probably provide your own `itemToString` implementation. Please refer to the `itemToString` API documentation.', 'The object that was passed:', i);
|
|
2859
|
-
}
|
|
2956
|
+
}();
|
|
2860
2957
|
|
|
2861
|
-
return String(i);
|
|
2862
|
-
},
|
|
2863
|
-
onStateChange: noop,
|
|
2864
|
-
onInputValueChange: noop,
|
|
2865
|
-
onUserAction: noop,
|
|
2866
|
-
onChange: noop,
|
|
2867
|
-
onSelect: noop,
|
|
2868
|
-
onOuterClick: noop,
|
|
2869
|
-
selectedItemChanged: function selectedItemChanged(prevItem, item) {
|
|
2870
|
-
return prevItem !== item;
|
|
2871
|
-
},
|
|
2872
|
-
environment: typeof window === 'undefined'
|
|
2873
|
-
/* istanbul ignore next (ssr) */
|
|
2874
|
-
? {} : window,
|
|
2875
|
-
stateReducer: function stateReducer(state, stateToSet) {
|
|
2876
|
-
return stateToSet;
|
|
2877
|
-
},
|
|
2878
|
-
suppressRefError: false,
|
|
2879
|
-
scrollIntoView: scrollIntoView
|
|
2880
|
-
};
|
|
2881
|
-
Downshift.stateChangeTypes = stateChangeTypes;
|
|
2882
2958
|
Downshift.propTypes = {
|
|
2883
2959
|
children: propTypes.func,
|
|
2884
2960
|
defaultHighlightedIndex: propTypes.number,
|
|
@@ -3522,6 +3598,7 @@
|
|
|
3522
3598
|
userProps = {};
|
|
3523
3599
|
}
|
|
3524
3600
|
|
|
3601
|
+
/* istanbul ignore else */
|
|
3525
3602
|
validatePropTypes(userProps); // Props defaults and destructuring.
|
|
3526
3603
|
|
|
3527
3604
|
var props = _extends({}, defaultProps, {}, userProps);
|