UNPKG

react-kiwi-dropdown

Version:

| Name | Type | Description | | --------------------------- | -------------------- | ----------- | | options | array | | selectedOption | string | | onCha

1 lines 27 kB
{"ast":null,"code":"/** @license React v0.13.6\n * scheduler.development.js\n *\n * Copyright (c) Facebook, Inc. and its affiliates.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n'use strict';\n\nif (process.env.NODE_ENV !== \"production\") {\n (function () {\n 'use strict';\n\n Object.defineProperty(exports, '__esModule', {\n value: true\n });\n var enableSchedulerDebugging = false;\n /* eslint-disable no-var */\n // TODO: Use symbols?\n\n var ImmediatePriority = 1;\n var UserBlockingPriority = 2;\n var NormalPriority = 3;\n var LowPriority = 4;\n var IdlePriority = 5; // Max 31 bit integer. The max integer size in V8 for 32-bit systems.\n // Math.pow(2, 30) - 1\n // 0b111111111111111111111111111111\n\n var maxSigned31BitInt = 1073741823; // Times out immediately\n\n var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out\n\n var USER_BLOCKING_PRIORITY = 250;\n var NORMAL_PRIORITY_TIMEOUT = 5000;\n var LOW_PRIORITY_TIMEOUT = 10000; // Never times out\n\n var IDLE_PRIORITY = maxSigned31BitInt; // Callbacks are stored as a circular, doubly linked list.\n\n var firstCallbackNode = null;\n var currentDidTimeout = false; // Pausing the scheduler is useful for debugging.\n\n var isSchedulerPaused = false;\n var currentPriorityLevel = NormalPriority;\n var currentEventStartTime = -1;\n var currentExpirationTime = -1; // This is set when a callback is being executed, to prevent re-entrancy.\n\n var isExecutingCallback = false;\n var isHostCallbackScheduled = false;\n var hasNativePerformanceNow = typeof performance === 'object' && typeof performance.now === 'function';\n\n function ensureHostCallbackIsScheduled() {\n if (isExecutingCallback) {\n // Don't schedule work yet; wait until the next time we yield.\n return;\n } // Schedule the host callback using the earliest expiration in the list.\n\n\n var expirationTime = firstCallbackNode.expirationTime;\n\n if (!isHostCallbackScheduled) {\n isHostCallbackScheduled = true;\n } else {\n // Cancel the existing host callback.\n cancelHostCallback();\n }\n\n requestHostCallback(flushWork, expirationTime);\n }\n\n function flushFirstCallback() {\n var flushedNode = firstCallbackNode; // Remove the node from the list before calling the callback. That way the\n // list is in a consistent state even if the callback throws.\n\n var next = firstCallbackNode.next;\n\n if (firstCallbackNode === next) {\n // This is the last callback in the list.\n firstCallbackNode = null;\n next = null;\n } else {\n var lastCallbackNode = firstCallbackNode.previous;\n firstCallbackNode = lastCallbackNode.next = next;\n next.previous = lastCallbackNode;\n }\n\n flushedNode.next = flushedNode.previous = null; // Now it's safe to call the callback.\n\n var callback = flushedNode.callback;\n var expirationTime = flushedNode.expirationTime;\n var priorityLevel = flushedNode.priorityLevel;\n var previousPriorityLevel = currentPriorityLevel;\n var previousExpirationTime = currentExpirationTime;\n currentPriorityLevel = priorityLevel;\n currentExpirationTime = expirationTime;\n var continuationCallback;\n\n try {\n continuationCallback = callback();\n } finally {\n currentPriorityLevel = previousPriorityLevel;\n currentExpirationTime = previousExpirationTime;\n } // A callback may return a continuation. The continuation should be scheduled\n // with the same priority and expiration as the just-finished callback.\n\n\n if (typeof continuationCallback === 'function') {\n var continuationNode = {\n callback: continuationCallback,\n priorityLevel: priorityLevel,\n expirationTime: expirationTime,\n next: null,\n previous: null\n }; // Insert the new callback into the list, sorted by its expiration. This is\n // almost the same as the code in `scheduleCallback`, except the callback\n // is inserted into the list *before* callbacks of equal expiration instead\n // of after.\n\n if (firstCallbackNode === null) {\n // This is the first callback in the list.\n firstCallbackNode = continuationNode.next = continuationNode.previous = continuationNode;\n } else {\n var nextAfterContinuation = null;\n var node = firstCallbackNode;\n\n do {\n if (node.expirationTime >= expirationTime) {\n // This callback expires at or after the continuation. We will insert\n // the continuation *before* this callback.\n nextAfterContinuation = node;\n break;\n }\n\n node = node.next;\n } while (node !== firstCallbackNode);\n\n if (nextAfterContinuation === null) {\n // No equal or lower priority callback was found, which means the new\n // callback is the lowest priority callback in the list.\n nextAfterContinuation = firstCallbackNode;\n } else if (nextAfterContinuation === firstCallbackNode) {\n // The new callback is the highest priority callback in the list.\n firstCallbackNode = continuationNode;\n ensureHostCallbackIsScheduled();\n }\n\n var previous = nextAfterContinuation.previous;\n previous.next = nextAfterContinuation.previous = continuationNode;\n continuationNode.next = nextAfterContinuation;\n continuationNode.previous = previous;\n }\n }\n }\n\n function flushImmediateWork() {\n if ( // Confirm we've exited the outer most event handler\n currentEventStartTime === -1 && firstCallbackNode !== null && firstCallbackNode.priorityLevel === ImmediatePriority) {\n isExecutingCallback = true;\n\n try {\n do {\n flushFirstCallback();\n } while ( // Keep flushing until there are no more immediate callbacks\n firstCallbackNode !== null && firstCallbackNode.priorityLevel === ImmediatePriority);\n } finally {\n isExecutingCallback = false;\n\n if (firstCallbackNode !== null) {\n // There's still work remaining. Request another callback.\n ensureHostCallbackIsScheduled();\n } else {\n isHostCallbackScheduled = false;\n }\n }\n }\n }\n\n function flushWork(didTimeout) {\n // Exit right away if we're currently paused\n if (enableSchedulerDebugging && isSchedulerPaused) {\n return;\n }\n\n isExecutingCallback = true;\n var previousDidTimeout = currentDidTimeout;\n currentDidTimeout = didTimeout;\n\n try {\n if (didTimeout) {\n // Flush all the expired callbacks without yielding.\n while (firstCallbackNode !== null && !(enableSchedulerDebugging && isSchedulerPaused)) {\n // TODO Wrap in feature flag\n // Read the current time. Flush all the callbacks that expire at or\n // earlier than that time. Then read the current time again and repeat.\n // This optimizes for as few performance.now calls as possible.\n var currentTime = exports.unstable_now();\n\n if (firstCallbackNode.expirationTime <= currentTime) {\n do {\n flushFirstCallback();\n } while (firstCallbackNode !== null && firstCallbackNode.expirationTime <= currentTime && !(enableSchedulerDebugging && isSchedulerPaused));\n\n continue;\n }\n\n break;\n }\n } else {\n // Keep flushing callbacks until we run out of time in the frame.\n if (firstCallbackNode !== null) {\n do {\n if (enableSchedulerDebugging && isSchedulerPaused) {\n break;\n }\n\n flushFirstCallback();\n } while (firstCallbackNode !== null && !shouldYieldToHost());\n }\n }\n } finally {\n isExecutingCallback = false;\n currentDidTimeout = previousDidTimeout;\n\n if (firstCallbackNode !== null) {\n // There's still work remaining. Request another callback.\n ensureHostCallbackIsScheduled();\n } else {\n isHostCallbackScheduled = false;\n } // Before exiting, flush all the immediate work that was scheduled.\n\n\n flushImmediateWork();\n }\n }\n\n function unstable_runWithPriority(priorityLevel, eventHandler) {\n switch (priorityLevel) {\n case ImmediatePriority:\n case UserBlockingPriority:\n case NormalPriority:\n case LowPriority:\n case IdlePriority:\n break;\n\n default:\n priorityLevel = NormalPriority;\n }\n\n var previousPriorityLevel = currentPriorityLevel;\n var previousEventStartTime = currentEventStartTime;\n currentPriorityLevel = priorityLevel;\n currentEventStartTime = exports.unstable_now();\n\n try {\n return eventHandler();\n } finally {\n currentPriorityLevel = previousPriorityLevel;\n currentEventStartTime = previousEventStartTime; // Before exiting, flush all the immediate work that was scheduled.\n\n flushImmediateWork();\n }\n }\n\n function unstable_next(eventHandler) {\n var priorityLevel = void 0;\n\n switch (currentPriorityLevel) {\n case ImmediatePriority:\n case UserBlockingPriority:\n case NormalPriority:\n // Shift down to normal priority\n priorityLevel = NormalPriority;\n break;\n\n default:\n // Anything lower than normal priority should remain at the current level.\n priorityLevel = currentPriorityLevel;\n break;\n }\n\n var previousPriorityLevel = currentPriorityLevel;\n var previousEventStartTime = currentEventStartTime;\n currentPriorityLevel = priorityLevel;\n currentEventStartTime = exports.unstable_now();\n\n try {\n return eventHandler();\n } finally {\n currentPriorityLevel = previousPriorityLevel;\n currentEventStartTime = previousEventStartTime; // Before exiting, flush all the immediate work that was scheduled.\n\n flushImmediateWork();\n }\n }\n\n function unstable_wrapCallback(callback) {\n var parentPriorityLevel = currentPriorityLevel;\n return function () {\n // This is a fork of runWithPriority, inlined for performance.\n var previousPriorityLevel = currentPriorityLevel;\n var previousEventStartTime = currentEventStartTime;\n currentPriorityLevel = parentPriorityLevel;\n currentEventStartTime = exports.unstable_now();\n\n try {\n return callback.apply(this, arguments);\n } finally {\n currentPriorityLevel = previousPriorityLevel;\n currentEventStartTime = previousEventStartTime;\n flushImmediateWork();\n }\n };\n }\n\n function unstable_scheduleCallback(callback, deprecated_options) {\n var startTime = currentEventStartTime !== -1 ? currentEventStartTime : exports.unstable_now();\n var expirationTime;\n\n if (typeof deprecated_options === 'object' && deprecated_options !== null && typeof deprecated_options.timeout === 'number') {\n // FIXME: Remove this branch once we lift expiration times out of React.\n expirationTime = startTime + deprecated_options.timeout;\n } else {\n switch (currentPriorityLevel) {\n case ImmediatePriority:\n expirationTime = startTime + IMMEDIATE_PRIORITY_TIMEOUT;\n break;\n\n case UserBlockingPriority:\n expirationTime = startTime + USER_BLOCKING_PRIORITY;\n break;\n\n case IdlePriority:\n expirationTime = startTime + IDLE_PRIORITY;\n break;\n\n case LowPriority:\n expirationTime = startTime + LOW_PRIORITY_TIMEOUT;\n break;\n\n case NormalPriority:\n default:\n expirationTime = startTime + NORMAL_PRIORITY_TIMEOUT;\n }\n }\n\n var newNode = {\n callback: callback,\n priorityLevel: currentPriorityLevel,\n expirationTime: expirationTime,\n next: null,\n previous: null\n }; // Insert the new callback into the list, ordered first by expiration, then\n // by insertion. So the new callback is inserted any other callback with\n // equal expiration.\n\n if (firstCallbackNode === null) {\n // This is the first callback in the list.\n firstCallbackNode = newNode.next = newNode.previous = newNode;\n ensureHostCallbackIsScheduled();\n } else {\n var next = null;\n var node = firstCallbackNode;\n\n do {\n if (node.expirationTime > expirationTime) {\n // The new callback expires before this one.\n next = node;\n break;\n }\n\n node = node.next;\n } while (node !== firstCallbackNode);\n\n if (next === null) {\n // No callback with a later expiration was found, which means the new\n // callback has the latest expiration in the list.\n next = firstCallbackNode;\n } else if (next === firstCallbackNode) {\n // The new callback has the earliest expiration in the entire list.\n firstCallbackNode = newNode;\n ensureHostCallbackIsScheduled();\n }\n\n var previous = next.previous;\n previous.next = next.previous = newNode;\n newNode.next = next;\n newNode.previous = previous;\n }\n\n return newNode;\n }\n\n function unstable_pauseExecution() {\n isSchedulerPaused = true;\n }\n\n function unstable_continueExecution() {\n isSchedulerPaused = false;\n\n if (firstCallbackNode !== null) {\n ensureHostCallbackIsScheduled();\n }\n }\n\n function unstable_getFirstCallbackNode() {\n return firstCallbackNode;\n }\n\n function unstable_cancelCallback(callbackNode) {\n var next = callbackNode.next;\n\n if (next === null) {\n // Already cancelled.\n return;\n }\n\n if (next === callbackNode) {\n // This is the only scheduled callback. Clear the list.\n firstCallbackNode = null;\n } else {\n // Remove the callback from its position in the list.\n if (callbackNode === firstCallbackNode) {\n firstCallbackNode = next;\n }\n\n var previous = callbackNode.previous;\n previous.next = next;\n next.previous = previous;\n }\n\n callbackNode.next = callbackNode.previous = null;\n }\n\n function unstable_getCurrentPriorityLevel() {\n return currentPriorityLevel;\n }\n\n function unstable_shouldYield() {\n return !currentDidTimeout && (firstCallbackNode !== null && firstCallbackNode.expirationTime < currentExpirationTime || shouldYieldToHost());\n } // The remaining code is essentially a polyfill for requestIdleCallback. It\n // works by scheduling a requestAnimationFrame, storing the time for the start\n // of the frame, then scheduling a postMessage which gets scheduled after paint.\n // Within the postMessage handler do as much work as possible until time + frame\n // rate. By separating the idle call into a separate event tick we ensure that\n // layout, paint and other browser work is counted against the available time.\n // The frame rate is dynamically adjusted.\n // We capture a local reference to any global, in case it gets polyfilled after\n // this module is initially evaluated. We want to be using a\n // consistent implementation.\n\n\n var localDate = Date; // This initialization code may run even on server environments if a component\n // just imports ReactDOM (e.g. for findDOMNode). Some environments might not\n // have setTimeout or clearTimeout. However, we always expect them to be defined\n // on the client. https://github.com/facebook/react/pull/13088\n\n var localSetTimeout = typeof setTimeout === 'function' ? setTimeout : undefined;\n var localClearTimeout = typeof clearTimeout === 'function' ? clearTimeout : undefined; // We don't expect either of these to necessarily be defined, but we will error\n // later if they are missing on the client.\n\n var localRequestAnimationFrame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : undefined;\n var localCancelAnimationFrame = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : undefined; // requestAnimationFrame does not run when the tab is in the background. If\n // we're backgrounded we prefer for that work to happen so that the page\n // continues to load in the background. So we also schedule a 'setTimeout' as\n // a fallback.\n // TODO: Need a better heuristic for backgrounded work.\n\n var ANIMATION_FRAME_TIMEOUT = 100;\n var rAFID;\n var rAFTimeoutID;\n\n var requestAnimationFrameWithTimeout = function (callback) {\n // schedule rAF and also a setTimeout\n rAFID = localRequestAnimationFrame(function (timestamp) {\n // cancel the setTimeout\n localClearTimeout(rAFTimeoutID);\n callback(timestamp);\n });\n rAFTimeoutID = localSetTimeout(function () {\n // cancel the requestAnimationFrame\n localCancelAnimationFrame(rAFID);\n callback(exports.unstable_now());\n }, ANIMATION_FRAME_TIMEOUT);\n };\n\n if (hasNativePerformanceNow) {\n var Performance = performance;\n\n exports.unstable_now = function () {\n return Performance.now();\n };\n } else {\n exports.unstable_now = function () {\n return localDate.now();\n };\n }\n\n var requestHostCallback;\n var cancelHostCallback;\n var shouldYieldToHost;\n var globalValue = null;\n\n if (typeof window !== 'undefined') {\n globalValue = window;\n } else if (typeof global !== 'undefined') {\n globalValue = global;\n }\n\n if (globalValue && globalValue._schedMock) {\n // Dynamic injection, only for testing purposes.\n var globalImpl = globalValue._schedMock;\n requestHostCallback = globalImpl[0];\n cancelHostCallback = globalImpl[1];\n shouldYieldToHost = globalImpl[2];\n exports.unstable_now = globalImpl[3];\n } else if ( // If Scheduler runs in a non-DOM environment, it falls back to a naive\n // implementation using setTimeout.\n typeof window === 'undefined' || // Check if MessageChannel is supported, too.\n typeof MessageChannel !== 'function') {\n // If this accidentally gets imported in a non-browser environment, e.g. JavaScriptCore,\n // fallback to a naive implementation.\n var _callback = null;\n\n var _flushCallback = function (didTimeout) {\n if (_callback !== null) {\n try {\n _callback(didTimeout);\n } finally {\n _callback = null;\n }\n }\n };\n\n requestHostCallback = function (cb, ms) {\n if (_callback !== null) {\n // Protect against re-entrancy.\n setTimeout(requestHostCallback, 0, cb);\n } else {\n _callback = cb;\n setTimeout(_flushCallback, 0, false);\n }\n };\n\n cancelHostCallback = function () {\n _callback = null;\n };\n\n shouldYieldToHost = function () {\n return false;\n };\n } else {\n if (typeof console !== 'undefined') {\n // TODO: Remove fb.me link\n if (typeof localRequestAnimationFrame !== 'function') {\n console.error(\"This browser doesn't support requestAnimationFrame. \" + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');\n }\n\n if (typeof localCancelAnimationFrame !== 'function') {\n console.error(\"This browser doesn't support cancelAnimationFrame. \" + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');\n }\n }\n\n var scheduledHostCallback = null;\n var isMessageEventScheduled = false;\n var timeoutTime = -1;\n var isAnimationFrameScheduled = false;\n var isFlushingHostCallback = false;\n var frameDeadline = 0; // We start out assuming that we run at 30fps but then the heuristic tracking\n // will adjust this value to a faster fps if we get more frequent animation\n // frames.\n\n var previousFrameTime = 33;\n var activeFrameTime = 33;\n\n shouldYieldToHost = function () {\n return frameDeadline <= exports.unstable_now();\n }; // We use the postMessage trick to defer idle work until after the repaint.\n\n\n var channel = new MessageChannel();\n var port = channel.port2;\n\n channel.port1.onmessage = function (event) {\n isMessageEventScheduled = false;\n var prevScheduledCallback = scheduledHostCallback;\n var prevTimeoutTime = timeoutTime;\n scheduledHostCallback = null;\n timeoutTime = -1;\n var currentTime = exports.unstable_now();\n var didTimeout = false;\n\n if (frameDeadline - currentTime <= 0) {\n // There's no time left in this idle period. Check if the callback has\n // a timeout and whether it's been exceeded.\n if (prevTimeoutTime !== -1 && prevTimeoutTime <= currentTime) {\n // Exceeded the timeout. Invoke the callback even though there's no\n // time left.\n didTimeout = true;\n } else {\n // No timeout.\n if (!isAnimationFrameScheduled) {\n // Schedule another animation callback so we retry later.\n isAnimationFrameScheduled = true;\n requestAnimationFrameWithTimeout(animationTick);\n } // Exit without invoking the callback.\n\n\n scheduledHostCallback = prevScheduledCallback;\n timeoutTime = prevTimeoutTime;\n return;\n }\n }\n\n if (prevScheduledCallback !== null) {\n isFlushingHostCallback = true;\n\n try {\n prevScheduledCallback(didTimeout);\n } finally {\n isFlushingHostCallback = false;\n }\n }\n };\n\n var animationTick = function (rafTime) {\n if (scheduledHostCallback !== null) {\n // Eagerly schedule the next animation callback at the beginning of the\n // frame. If the scheduler queue is not empty at the end of the frame, it\n // will continue flushing inside that callback. If the queue *is* empty,\n // then it will exit immediately. Posting the callback at the start of the\n // frame ensures it's fired within the earliest possible frame. If we\n // waited until the end of the frame to post the callback, we risk the\n // browser skipping a frame and not firing the callback until the frame\n // after that.\n requestAnimationFrameWithTimeout(animationTick);\n } else {\n // No pending work. Exit.\n isAnimationFrameScheduled = false;\n return;\n }\n\n var nextFrameTime = rafTime - frameDeadline + activeFrameTime;\n\n if (nextFrameTime < activeFrameTime && previousFrameTime < activeFrameTime) {\n if (nextFrameTime < 8) {\n // Defensive coding. We don't support higher frame rates than 120hz.\n // If the calculated frame time gets lower than 8, it is probably a bug.\n nextFrameTime = 8;\n } // If one frame goes long, then the next one can be short to catch up.\n // If two frames are short in a row, then that's an indication that we\n // actually have a higher frame rate than what we're currently optimizing.\n // We adjust our heuristic dynamically accordingly. For example, if we're\n // running on 120hz display or 90hz VR display.\n // Take the max of the two in case one of them was an anomaly due to\n // missed frame deadlines.\n\n\n activeFrameTime = nextFrameTime < previousFrameTime ? previousFrameTime : nextFrameTime;\n } else {\n previousFrameTime = nextFrameTime;\n }\n\n frameDeadline = rafTime + activeFrameTime;\n\n if (!isMessageEventScheduled) {\n isMessageEventScheduled = true;\n port.postMessage(undefined);\n }\n };\n\n requestHostCallback = function (callback, absoluteTimeout) {\n scheduledHostCallback = callback;\n timeoutTime = absoluteTimeout;\n\n if (isFlushingHostCallback || absoluteTimeout < 0) {\n // Don't wait for the next frame. Continue working ASAP, in a new event.\n port.postMessage(undefined);\n } else if (!isAnimationFrameScheduled) {\n // If rAF didn't already schedule one, we need to schedule a frame.\n // TODO: If this rAF doesn't materialize because the browser throttles, we\n // might want to still have setTimeout trigger rIC as a backup to ensure\n // that we keep performing work.\n isAnimationFrameScheduled = true;\n requestAnimationFrameWithTimeout(animationTick);\n }\n };\n\n cancelHostCallback = function () {\n scheduledHostCallback = null;\n isMessageEventScheduled = false;\n timeoutTime = -1;\n };\n }\n\n exports.unstable_ImmediatePriority = ImmediatePriority;\n exports.unstable_UserBlockingPriority = UserBlockingPriority;\n exports.unstable_NormalPriority = NormalPriority;\n exports.unstable_IdlePriority = IdlePriority;\n exports.unstable_LowPriority = LowPriority;\n exports.unstable_runWithPriority = unstable_runWithPriority;\n exports.unstable_next = unstable_next;\n exports.unstable_scheduleCallback = unstable_scheduleCallback;\n exports.unstable_cancelCallback = unstable_cancelCallback;\n exports.unstable_wrapCallback = unstable_wrapCallback;\n exports.unstable_getCurrentPriorityLevel = unstable_getCurrentPriorityLevel;\n exports.unstable_shouldYield = unstable_shouldYield;\n exports.unstable_continueExecution = unstable_continueExecution;\n exports.unstable_pauseExecution = unstable_pauseExecution;\n exports.unstable_getFirstCallbackNode = unstable_getFirstCallbackNode;\n })();\n}","map":null,"metadata":{},"sourceType":"script"}