UNPKG

react-query

Version:

Hooks for managing, caching and syncing asynchronous and remote data in React

1,596 lines (1,437 loc) 83.8 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-query')) : typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-query'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactQueryDevtools = {}, global.React, global.ReactQuery)); })(this, (function (exports, React, reactQuery) { 'use strict'; function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n["default"] = e; return Object.freeze(n); } var React__default = /*#__PURE__*/_interopDefaultLegacy(React); var React__namespace = /*#__PURE__*/_interopNamespace(React); function _extends$1() { _extends$1 = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); } var shim = {exports: {}}; var useSyncExternalStoreShim_production_min = {}; /** * @license React * use-sync-external-store-shim.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ var e = React__default["default"]; function h(a, b) { return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b; } var k = "function" === typeof Object.is ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue; function q(a, b) { var d = b(), f = l({ inst: { value: d, getSnapshot: b } }), c = f[0].inst, g = f[1]; n(function () { c.value = d; c.getSnapshot = b; r(c) && g({ inst: c }); }, [a, d, b]); m(function () { r(c) && g({ inst: c }); return a(function () { r(c) && g({ inst: c }); }); }, [a]); p(d); return d; } function r(a) { var b = a.getSnapshot; a = a.value; try { var d = b(); return !k(a, d); } catch (f) { return !0; } } function t(a, b) { return b(); } var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q; useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u; var useSyncExternalStoreShim_development = {}; /** * @license React * use-sync-external-store-shim.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ if (process.env.NODE_ENV !== "production") { (function () { /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === 'function') { __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error()); } var React = React__default["default"]; var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function error(format) { { { for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { args[_key2 - 1] = arguments[_key2]; } printWarning('error', format, args); } } } function printWarning(level, format, args) { // When changing this logic, you might want to also // update consoleWithStackDev.www.js as well. { var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; var stack = ReactDebugCurrentFrame.getStackAddendum(); if (stack !== '') { format += '%s'; args = args.concat([stack]); } // eslint-disable-next-line react-internal/safe-string-coercion var argsWithFormat = args.map(function (item) { return String(item); }); // Careful: RN currently depends on this prefix argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it // breaks IE9: https://github.com/facebook/react/issues/13610 // eslint-disable-next-line react-internal/no-production-logging Function.prototype.apply.call(console[level], console, argsWithFormat); } } /** * inlined Object.is polyfill to avoid requiring consumers ship their own * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is */ function is(x, y) { return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare ; } var objectIs = typeof Object.is === 'function' ? Object.is : is; // dispatch for CommonJS interop named imports. var useState = React.useState, useEffect = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue = React.useDebugValue; var didWarnOld18Alpha = false; var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works // because of a very particular set of implementation details and assumptions // -- change any one of them and it will break. The most important assumption // is that updates are always synchronous, because concurrent rendering is // only available in versions of React that also have a built-in // useSyncExternalStore API. And we only use this shim when the built-in API // does not exist. // // Do not assume that the clever hacks used by this hook also work in general. // The point of this shim is to replace the need for hacks by other libraries. function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of // React do not expose a way to check if we're hydrating. So users of the shim // will need to track that themselves and return the correct value // from `getSnapshot`. getServerSnapshot) { { if (!didWarnOld18Alpha) { if (React.startTransition !== undefined) { didWarnOld18Alpha = true; error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.'); } } } // Read the current snapshot from the store on every render. Again, this // breaks the rules of React, and only works here because of specific // implementation details, most importantly that updates are // always synchronous. var value = getSnapshot(); { if (!didWarnUncachedGetSnapshot) { var cachedValue = getSnapshot(); if (!objectIs(value, cachedValue)) { error('The result of getSnapshot should be cached to avoid an infinite loop'); didWarnUncachedGetSnapshot = true; } } } // Because updates are synchronous, we don't queue them. Instead we force a // re-render whenever the subscribed state changes by updating an some // arbitrary useState hook. Then, during render, we call getSnapshot to read // the current value. // // Because we don't actually use the state returned by the useState hook, we // can save a bit of memory by storing other stuff in that slot. // // To implement the early bailout, we need to track some things on a mutable // object. Usually, we would put that in a useRef hook, but we can stash it in // our useState hook instead. // // To force a re-render, we call forceUpdate({inst}). That works because the // new object always fails an equality check. var _useState = useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated // in the layout phase so we can access it during the tearing check that // happens on subscribe. useLayoutEffect(function () { inst.value = value; inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the // commit phase if there was an interleaved mutation. In concurrent mode // this can happen all the time, but even in synchronous mode, an earlier // effect may have mutated the store. if (checkIfSnapshotChanged(inst)) { // Force a re-render. forceUpdate({ inst: inst }); } }, [subscribe, value, getSnapshot]); useEffect(function () { // Check for changes right before subscribing. Subsequent changes will be // detected in the subscription handler. if (checkIfSnapshotChanged(inst)) { // Force a re-render. forceUpdate({ inst: inst }); } var handleStoreChange = function () { // TODO: Because there is no cross-renderer API for batching updates, it's // up to the consumer of this library to wrap their subscription event // with unstable_batchedUpdates. Should we try to detect when this isn't // the case and print a warning in development? // The store changed. Check if the snapshot changed since the last time we // read from the store. if (checkIfSnapshotChanged(inst)) { // Force a re-render. forceUpdate({ inst: inst }); } }; // Subscribe to the store and return a clean-up function. return subscribe(handleStoreChange); }, [subscribe]); useDebugValue(value); return value; } function checkIfSnapshotChanged(inst) { var latestGetSnapshot = inst.getSnapshot; var prevValue = inst.value; try { var nextValue = latestGetSnapshot(); return !objectIs(prevValue, nextValue); } catch (error) { return true; } } function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) { // Note: The shim does not use getServerSnapshot, because pre-18 versions of // React do not expose a way to check if we're hydrating. So users of the shim // will need to track that themselves and return the correct value // from `getSnapshot`. return getSnapshot(); } var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined'); var isServerEnvironment = !canUseDOM; var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore; var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim; useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2; /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === 'function') { __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error()); } })(); } if (process.env.NODE_ENV === 'production') { shim.exports = useSyncExternalStoreShim_production_min; } else { shim.exports = useSyncExternalStoreShim_development; } function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } var removeAccents$2 = {exports: {}}; var characterMap = { "À": "A", "Á": "A", "Â": "A", "Ã": "A", "Ä": "A", "Å": "A", "Ấ": "A", "Ắ": "A", "Ẳ": "A", "Ẵ": "A", "Ặ": "A", "Æ": "AE", "Ầ": "A", "Ằ": "A", "Ȃ": "A", "Ç": "C", "Ḉ": "C", "È": "E", "É": "E", "Ê": "E", "Ë": "E", "Ế": "E", "Ḗ": "E", "Ề": "E", "Ḕ": "E", "Ḝ": "E", "Ȇ": "E", "Ì": "I", "Í": "I", "Î": "I", "Ï": "I", "Ḯ": "I", "Ȋ": "I", "Ð": "D", "Ñ": "N", "Ò": "O", "Ó": "O", "Ô": "O", "Õ": "O", "Ö": "O", "Ø": "O", "Ố": "O", "Ṍ": "O", "Ṓ": "O", "Ȏ": "O", "Ù": "U", "Ú": "U", "Û": "U", "Ü": "U", "Ý": "Y", "à": "a", "á": "a", "â": "a", "ã": "a", "ä": "a", "å": "a", "ấ": "a", "ắ": "a", "ẳ": "a", "ẵ": "a", "ặ": "a", "æ": "ae", "ầ": "a", "ằ": "a", "ȃ": "a", "ç": "c", "ḉ": "c", "è": "e", "é": "e", "ê": "e", "ë": "e", "ế": "e", "ḗ": "e", "ề": "e", "ḕ": "e", "ḝ": "e", "ȇ": "e", "ì": "i", "í": "i", "î": "i", "ï": "i", "ḯ": "i", "ȋ": "i", "ð": "d", "ñ": "n", "ò": "o", "ó": "o", "ô": "o", "õ": "o", "ö": "o", "ø": "o", "ố": "o", "ṍ": "o", "ṓ": "o", "ȏ": "o", "ù": "u", "ú": "u", "û": "u", "ü": "u", "ý": "y", "ÿ": "y", "Ā": "A", "ā": "a", "Ă": "A", "ă": "a", "Ą": "A", "ą": "a", "Ć": "C", "ć": "c", "Ĉ": "C", "ĉ": "c", "Ċ": "C", "ċ": "c", "Č": "C", "č": "c", "C̆": "C", "c̆": "c", "Ď": "D", "ď": "d", "Đ": "D", "đ": "d", "Ē": "E", "ē": "e", "Ĕ": "E", "ĕ": "e", "Ė": "E", "ė": "e", "Ę": "E", "ę": "e", "Ě": "E", "ě": "e", "Ĝ": "G", "Ǵ": "G", "ĝ": "g", "ǵ": "g", "Ğ": "G", "ğ": "g", "Ġ": "G", "ġ": "g", "Ģ": "G", "ģ": "g", "Ĥ": "H", "ĥ": "h", "Ħ": "H", "ħ": "h", "Ḫ": "H", "ḫ": "h", "Ĩ": "I", "ĩ": "i", "Ī": "I", "ī": "i", "Ĭ": "I", "ĭ": "i", "Į": "I", "į": "i", "İ": "I", "ı": "i", "IJ": "IJ", "ij": "ij", "Ĵ": "J", "ĵ": "j", "Ķ": "K", "ķ": "k", "Ḱ": "K", "ḱ": "k", "K̆": "K", "k̆": "k", "Ĺ": "L", "ĺ": "l", "Ļ": "L", "ļ": "l", "Ľ": "L", "ľ": "l", "Ŀ": "L", "ŀ": "l", "Ł": "l", "ł": "l", "Ḿ": "M", "ḿ": "m", "M̆": "M", "m̆": "m", "Ń": "N", "ń": "n", "Ņ": "N", "ņ": "n", "Ň": "N", "ň": "n", "ʼn": "n", "N̆": "N", "n̆": "n", "Ō": "O", "ō": "o", "Ŏ": "O", "ŏ": "o", "Ő": "O", "ő": "o", "Œ": "OE", "œ": "oe", "P̆": "P", "p̆": "p", "Ŕ": "R", "ŕ": "r", "Ŗ": "R", "ŗ": "r", "Ř": "R", "ř": "r", "R̆": "R", "r̆": "r", "Ȓ": "R", "ȓ": "r", "Ś": "S", "ś": "s", "Ŝ": "S", "ŝ": "s", "Ş": "S", "Ș": "S", "ș": "s", "ş": "s", "Š": "S", "š": "s", "Ţ": "T", "ţ": "t", "ț": "t", "Ț": "T", "Ť": "T", "ť": "t", "Ŧ": "T", "ŧ": "t", "T̆": "T", "t̆": "t", "Ũ": "U", "ũ": "u", "Ū": "U", "ū": "u", "Ŭ": "U", "ŭ": "u", "Ů": "U", "ů": "u", "Ű": "U", "ű": "u", "Ų": "U", "ų": "u", "Ȗ": "U", "ȗ": "u", "V̆": "V", "v̆": "v", "Ŵ": "W", "ŵ": "w", "Ẃ": "W", "ẃ": "w", "X̆": "X", "x̆": "x", "Ŷ": "Y", "ŷ": "y", "Ÿ": "Y", "Y̆": "Y", "y̆": "y", "Ź": "Z", "ź": "z", "Ż": "Z", "ż": "z", "Ž": "Z", "ž": "z", "ſ": "s", "ƒ": "f", "Ơ": "O", "ơ": "o", "Ư": "U", "ư": "u", "Ǎ": "A", "ǎ": "a", "Ǐ": "I", "ǐ": "i", "Ǒ": "O", "ǒ": "o", "Ǔ": "U", "ǔ": "u", "Ǖ": "U", "ǖ": "u", "Ǘ": "U", "ǘ": "u", "Ǚ": "U", "ǚ": "u", "Ǜ": "U", "ǜ": "u", "Ứ": "U", "ứ": "u", "Ṹ": "U", "ṹ": "u", "Ǻ": "A", "ǻ": "a", "Ǽ": "AE", "ǽ": "ae", "Ǿ": "O", "ǿ": "o", "Þ": "TH", "þ": "th", "Ṕ": "P", "ṕ": "p", "Ṥ": "S", "ṥ": "s", "X́": "X", "x́": "x", "Ѓ": "Г", "ѓ": "г", "Ќ": "К", "ќ": "к", "A̋": "A", "a̋": "a", "E̋": "E", "e̋": "e", "I̋": "I", "i̋": "i", "Ǹ": "N", "ǹ": "n", "Ồ": "O", "ồ": "o", "Ṑ": "O", "ṑ": "o", "Ừ": "U", "ừ": "u", "Ẁ": "W", "ẁ": "w", "Ỳ": "Y", "ỳ": "y", "Ȁ": "A", "ȁ": "a", "Ȅ": "E", "ȅ": "e", "Ȉ": "I", "ȉ": "i", "Ȍ": "O", "ȍ": "o", "Ȑ": "R", "ȑ": "r", "Ȕ": "U", "ȕ": "u", "B̌": "B", "b̌": "b", "Č̣": "C", "č̣": "c", "Ê̌": "E", "ê̌": "e", "F̌": "F", "f̌": "f", "Ǧ": "G", "ǧ": "g", "Ȟ": "H", "ȟ": "h", "J̌": "J", "ǰ": "j", "Ǩ": "K", "ǩ": "k", "M̌": "M", "m̌": "m", "P̌": "P", "p̌": "p", "Q̌": "Q", "q̌": "q", "Ř̩": "R", "ř̩": "r", "Ṧ": "S", "ṧ": "s", "V̌": "V", "v̌": "v", "W̌": "W", "w̌": "w", "X̌": "X", "x̌": "x", "Y̌": "Y", "y̌": "y", "A̧": "A", "a̧": "a", "B̧": "B", "b̧": "b", "Ḑ": "D", "ḑ": "d", "Ȩ": "E", "ȩ": "e", "Ɛ̧": "E", "ɛ̧": "e", "Ḩ": "H", "ḩ": "h", "I̧": "I", "i̧": "i", "Ɨ̧": "I", "ɨ̧": "i", "M̧": "M", "m̧": "m", "O̧": "O", "o̧": "o", "Q̧": "Q", "q̧": "q", "U̧": "U", "u̧": "u", "X̧": "X", "x̧": "x", "Z̧": "Z", "z̧": "z" }; var chars = Object.keys(characterMap).join('|'); var allAccents = new RegExp(chars, 'g'); var firstAccent = new RegExp(chars, ''); var removeAccents = function (string) { return string.replace(allAccents, function (match) { return characterMap[match]; }); }; var hasAccents = function (string) { return !!string.match(firstAccent); }; removeAccents$2.exports = removeAccents; removeAccents$2.exports.has = hasAccents; removeAccents$2.exports.remove = removeAccents; var removeAccents$1 = removeAccents$2.exports; var rankings = { CASE_SENSITIVE_EQUAL: 7, EQUAL: 6, STARTS_WITH: 5, WORD_STARTS_WITH: 4, CONTAINS: 3, ACRONYM: 2, MATCHES: 1, NO_MATCH: 0 }; matchSorter.rankings = rankings; var defaultBaseSortFn = function (a, b) { return String(a.rankedValue).localeCompare(String(b.rankedValue)); }; /** * Takes an array of items and a value and returns a new array with the items that match the given value * @param {Array} items - the items to sort * @param {String} value - the value to use for ranking * @param {Object} options - Some options to configure the sorter * @return {Array} - the new sorted array */ function matchSorter(items, value, options) { if (options === void 0) { options = {}; } var _options = options, keys = _options.keys, _options$threshold = _options.threshold, threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold, _options$baseSort = _options.baseSort, baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort; var matchedItems = items.reduce(reduceItemsToRanked, []); return matchedItems.sort(function (a, b) { return sortRankedValues(a, b, baseSort); }).map(function (_ref) { var item = _ref.item; return item; }); function reduceItemsToRanked(matches, item, index) { var rankingInfo = getHighestRanking(item, keys, value, options); var rank = rankingInfo.rank, _rankingInfo$keyThres = rankingInfo.keyThreshold, keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres; if (rank >= keyThreshold) { matches.push(_extends({}, rankingInfo, { item: item, index: index })); } return matches; } } /** * Gets the highest ranking for value for the given item based on its values for the given keys * @param {*} item - the item to rank * @param {Array} keys - the keys to get values from the item for the ranking * @param {String} value - the value to rank against * @param {Object} options - options to control the ranking * @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking */ function getHighestRanking(item, keys, value, options) { if (!keys) { // if keys is not specified, then we assume the item given is ready to be matched var stringItem = item; return { // ends up being duplicate of 'item' in matches but consistent rankedValue: stringItem, rank: getMatchRanking(stringItem, value, options), keyIndex: -1, keyThreshold: options.threshold }; } var valuesToRank = getAllValuesToRank(item, keys); return valuesToRank.reduce(function (_ref2, _ref3, i) { var rank = _ref2.rank, rankedValue = _ref2.rankedValue, keyIndex = _ref2.keyIndex, keyThreshold = _ref2.keyThreshold; var itemValue = _ref3.itemValue, attributes = _ref3.attributes; var newRank = getMatchRanking(itemValue, value, options); var newRankedValue = rankedValue; var minRanking = attributes.minRanking, maxRanking = attributes.maxRanking, threshold = attributes.threshold; if (newRank < minRanking && newRank >= rankings.MATCHES) { newRank = minRanking; } else if (newRank > maxRanking) { newRank = maxRanking; } if (newRank > rank) { rank = newRank; keyIndex = i; keyThreshold = threshold; newRankedValue = itemValue; } return { rankedValue: newRankedValue, rank: rank, keyIndex: keyIndex, keyThreshold: keyThreshold }; }, { rankedValue: item, rank: rankings.NO_MATCH, keyIndex: -1, keyThreshold: options.threshold }); } /** * Gives a rankings score based on how well the two strings match. * @param {String} testString - the string to test against * @param {String} stringToRank - the string to rank * @param {Object} options - options for the match (like keepDiacritics for comparison) * @returns {Number} the ranking for how well stringToRank matches testString */ function getMatchRanking(testString, stringToRank, options) { testString = prepareValueForComparison(testString, options); stringToRank = prepareValueForComparison(stringToRank, options); // too long if (stringToRank.length > testString.length) { return rankings.NO_MATCH; } // case sensitive equals if (testString === stringToRank) { return rankings.CASE_SENSITIVE_EQUAL; } // Lower casing before further comparison testString = testString.toLowerCase(); stringToRank = stringToRank.toLowerCase(); // case insensitive equals if (testString === stringToRank) { return rankings.EQUAL; } // starts with if (testString.startsWith(stringToRank)) { return rankings.STARTS_WITH; } // word starts with if (testString.includes(" " + stringToRank)) { return rankings.WORD_STARTS_WITH; } // contains if (testString.includes(stringToRank)) { return rankings.CONTAINS; } else if (stringToRank.length === 1) { // If the only character in the given stringToRank // isn't even contained in the testString, then // it's definitely not a match. return rankings.NO_MATCH; } // acronym if (getAcronym(testString).includes(stringToRank)) { return rankings.ACRONYM; } // will return a number between rankings.MATCHES and // rankings.MATCHES + 1 depending on how close of a match it is. return getClosenessRanking(testString, stringToRank); } /** * Generates an acronym for a string. * * @param {String} string the string for which to produce the acronym * @returns {String} the acronym */ function getAcronym(string) { var acronym = ''; var wordsInString = string.split(' '); wordsInString.forEach(function (wordInString) { var splitByHyphenWords = wordInString.split('-'); splitByHyphenWords.forEach(function (splitByHyphenWord) { acronym += splitByHyphenWord.substr(0, 1); }); }); return acronym; } /** * Returns a score based on how spread apart the * characters from the stringToRank are within the testString. * A number close to rankings.MATCHES represents a loose match. A number close * to rankings.MATCHES + 1 represents a tighter match. * @param {String} testString - the string to test against * @param {String} stringToRank - the string to rank * @returns {Number} the number between rankings.MATCHES and * rankings.MATCHES + 1 for how well stringToRank matches testString */ function getClosenessRanking(testString, stringToRank) { var matchingInOrderCharCount = 0; var charNumber = 0; function findMatchingCharacter(matchChar, string, index) { for (var j = index; j < string.length; j++) { var stringChar = string[j]; if (stringChar === matchChar) { matchingInOrderCharCount += 1; return j + 1; } } return -1; } function getRanking(spread) { var inOrderPercentage = matchingInOrderCharCount / stringToRank.length; var ranking = rankings.MATCHES + inOrderPercentage * (1 / spread); return ranking; } var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0); if (firstIndex < 0) { return rankings.NO_MATCH; } charNumber = firstIndex; for (var i = 1; i < stringToRank.length; i++) { var matchChar = stringToRank[i]; charNumber = findMatchingCharacter(matchChar, testString, charNumber); var found = charNumber > -1; if (!found) { return rankings.NO_MATCH; } } var spread = charNumber - firstIndex; return getRanking(spread); } /** * Sorts items that have a rank, index, and keyIndex * @param {Object} a - the first item to sort * @param {Object} b - the second item to sort * @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal */ function sortRankedValues(a, b, baseSort) { var aFirst = -1; var bFirst = 1; var aRank = a.rank, aKeyIndex = a.keyIndex; var bRank = b.rank, bKeyIndex = b.keyIndex; if (aRank === bRank) { if (aKeyIndex === bKeyIndex) { // use the base sort function as a tie-breaker return baseSort(a, b); } else { return aKeyIndex < bKeyIndex ? aFirst : bFirst; } } else { return aRank > bRank ? aFirst : bFirst; } } /** * Prepares value for comparison by stringifying it, removing diacritics (if specified) * @param {String} value - the value to clean * @param {Object} options - {keepDiacritics: whether to remove diacritics} * @return {String} the prepared value */ function prepareValueForComparison(value, _ref4) { var keepDiacritics = _ref4.keepDiacritics; // value might not actually be a string at this point (we don't get to choose) // so part of preparing the value for comparison is ensure that it is a string value = "" + value; // toString if (!keepDiacritics) { value = removeAccents$1(value); } return value; } /** * Gets value for key in item at arbitrarily nested keypath * @param {Object} item - the item * @param {Object|Function} key - the potentially nested keypath or property callback * @return {Array} - an array containing the value(s) at the nested keypath */ function getItemValues(item, key) { if (typeof key === 'object') { key = key.key; } var value; if (typeof key === 'function') { value = key(item); // eslint-disable-next-line no-negated-condition } else { value = getNestedValue(key, item); } // concat because `value` can be a string or an array // eslint-disable-next-line return value != null ? [].concat(value) : null; } /** * Given key: "foo.bar.baz" * And obj: {foo: {bar: {baz: 'buzz'}}} * -> 'buzz' * @param key a dot-separated set of keys * @param obj the object to get the value from */ function getNestedValue(key, obj) { // @ts-expect-error really have no idea how to type this properly... return key.split('.').reduce(function (itemObj, nestedKey) { // @ts-expect-error lost on this one as well... return itemObj ? itemObj[nestedKey] : null; }, obj); } /** * Gets all the values for the given keys in the given item and returns an array of those values * @param item - the item from which the values will be retrieved * @param keys - the keys to use to retrieve the values * @return objects with {itemValue, attributes} */ function getAllValuesToRank(item, keys) { return keys.reduce(function (allVals, key) { var values = getItemValues(item, key); if (values) { values.forEach(function (itemValue) { allVals.push({ itemValue: itemValue, attributes: getKeyAttributes(key) }); }); } return allVals; }, []); } var defaultKeyAttributes = { maxRanking: Infinity, minRanking: -Infinity }; /** * Gets all the attributes for the given key * @param key - the key from which the attributes will be retrieved * @return object containing the key's attributes */ function getKeyAttributes(key) { if (typeof key === 'string') { return defaultKeyAttributes; } return _extends({}, defaultKeyAttributes, key); } const getItem = key => { try { const itemValue = localStorage.getItem(key); if (typeof itemValue === 'string') { return JSON.parse(itemValue); } return undefined; } catch { return undefined; } }; function useLocalStorage(key, defaultValue) { const [value, setValue] = React__default["default"].useState(); React__default["default"].useEffect(() => { const initialValue = getItem(key); if (typeof initialValue === 'undefined' || initialValue === null) { setValue(typeof defaultValue === 'function' ? defaultValue() : defaultValue); } else { setValue(initialValue); } }, [defaultValue, key]); const setter = React__default["default"].useCallback(updater => { setValue(old => { let newVal = updater; if (typeof updater == 'function') { newVal = updater(old); } try { localStorage.setItem(key, JSON.stringify(newVal)); } catch {} return newVal; }); }, [key]); return [value, setter]; } const defaultTheme = { background: '#0b1521', backgroundAlt: '#132337', foreground: 'white', gray: '#3f4e60', grayAlt: '#222e3e', inputBackgroundColor: '#fff', inputTextColor: '#000', success: '#00ab52', danger: '#ff0085', active: '#006bff', paused: '#8c49eb', warning: '#ffb200' }; const ThemeContext = /*#__PURE__*/React__default["default"].createContext(defaultTheme); function ThemeProvider({ theme, ...rest }) { return /*#__PURE__*/React__default["default"].createElement(ThemeContext.Provider, _extends$1({ value: theme }, rest)); } function useTheme() { return React__default["default"].useContext(ThemeContext); } function useMediaQuery(query) { // Keep track of the preference in state, start with the current match const [isMatch, setIsMatch] = React__default["default"].useState(() => { if (typeof window !== 'undefined') { return window.matchMedia(query).matches; } }); // Watch for changes React__default["default"].useEffect(() => { if (typeof window !== 'undefined') { // Create a matcher const matcher = window.matchMedia(query); // Create our handler const onChange = ({ matches }) => setIsMatch(matches); // Listen for changes matcher.addListener(onChange); return () => { // Stop listening for changes matcher.removeListener(onChange); }; } }, [isMatch, query, setIsMatch]); return isMatch; } const isServer$1 = typeof window === 'undefined'; function getQueryStatusColor({ queryState, observerCount, isStale, theme }) { return queryState.fetchStatus === 'fetching' ? theme.active : !observerCount ? theme.gray : queryState.fetchStatus === 'paused' ? theme.paused : isStale ? theme.warning : theme.success; } function getQueryStatusLabel(query) { return query.state.fetchStatus === 'fetching' ? 'fetching' : !query.getObserversCount() ? 'inactive' : query.state.fetchStatus === 'paused' ? 'paused' : query.isStale() ? 'stale' : 'fresh'; } function styled(type, newStyles, queries = {}) { return /*#__PURE__*/React__default["default"].forwardRef(({ style, ...rest }, ref) => { const theme = useTheme(); const mediaStyles = Object.entries(queries).reduce((current, [key, value]) => { // eslint-disable-next-line react-hooks/rules-of-hooks return useMediaQuery(key) ? { ...current, ...(typeof value === 'function' ? value(rest, theme) : value) } : current; }, {}); return /*#__PURE__*/React__default["default"].createElement(type, { ...rest, style: { ...(typeof newStyles === 'function' ? newStyles(rest, theme) : newStyles), ...style, ...mediaStyles }, ref }); }); } function useIsMounted() { const mountedRef = React__default["default"].useRef(false); const isMounted = React__default["default"].useCallback(() => mountedRef.current, []); React__default["default"][isServer$1 ? 'useEffect' : 'useLayoutEffect'](() => { mountedRef.current = true; return () => { mountedRef.current = false; }; }, []); return isMounted; } /** * Displays a string regardless the type of the data * @param {unknown} value Value to be stringified */ const displayValue = value => { const name = Object.getOwnPropertyNames(Object(value)); const newValue = typeof value === 'bigint' ? value.toString() + "n" : value; return JSON.stringify(newValue, name); }; const Panel = styled('div', (_props, theme) => ({ fontSize: 'clamp(12px, 1.5vw, 14px)', fontFamily: "sans-serif", display: 'flex', backgroundColor: theme.background, color: theme.foreground }), { '(max-width: 700px)': { flexDirection: 'column' }, '(max-width: 600px)': { fontSize: '.9em' // flexDirection: 'column', } }); const ActiveQueryPanel = styled('div', () => ({ flex: '1 1 500px', display: 'flex', flexDirection: 'column', overflow: 'auto', height: '100%' }), { '(max-width: 700px)': (_props, theme) => ({ borderTop: "2px solid " + theme.gray }) }); const Button = styled('button', (props, theme) => ({ appearance: 'none', fontSize: '.9em', fontWeight: 'bold', background: theme.gray, border: '0', borderRadius: '.3em', color: 'white', padding: '.5em', opacity: props.disabled ? '.5' : undefined, cursor: 'pointer' })); const QueryKeys = styled('span', { display: 'inline-block', fontSize: '0.9em' }); const QueryKey = styled('span', { display: 'inline-flex', alignItems: 'center', padding: '.2em .4em', fontWeight: 'bold', textShadow: '0 0 10px black', borderRadius: '.2em' }); const Code = styled('code', { fontSize: '.9em', color: 'inherit', background: 'inherit' }); const Input = styled('input', (_props, theme) => ({ backgroundColor: theme.inputBackgroundColor, border: 0, borderRadius: '.2em', color: theme.inputTextColor, fontSize: '.9em', lineHeight: "1.3", padding: '.3em .4em' })); const Select = styled('select', (_props, theme) => ({ display: "inline-block", fontSize: ".9em", fontFamily: "sans-serif", fontWeight: 'normal', lineHeight: "1.3", padding: ".3em 1.5em .3em .5em", height: 'auto', border: 0, borderRadius: ".2em", appearance: "none", WebkitAppearance: 'none', backgroundColor: theme.inputBackgroundColor, backgroundImage: "url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' fill='%23444444'><polygon points='0,25 100,25 50,75'/></svg>\")", backgroundRepeat: "no-repeat", backgroundPosition: "right .55em center", backgroundSize: ".65em auto, 100%", color: theme.inputTextColor }), { '(max-width: 500px)': { display: 'none' } }); const Entry = styled('div', { fontFamily: 'Menlo, monospace', fontSize: '1em', lineHeight: '1.7', outline: 'none', wordBreak: 'break-word' }); const Label = styled('span', { color: 'white' }); const LabelButton = styled('button', { cursor: 'pointer', color: 'white' }); const Value = styled('span', (_props, theme) => ({ color: theme.danger })); const SubEntries = styled('div', { marginLeft: '.1em', paddingLeft: '1em', borderLeft: '2px solid rgba(0,0,0,.15)' }); const Info = styled('span', { color: 'grey', fontSize: '.7em' }); const Expander = ({ expanded, style = {} }) => /*#__PURE__*/React__default["default"].createElement("span", { style: { display: 'inline-block', transition: 'all .1s ease', transform: "rotate(" + (expanded ? 90 : 0) + "deg) " + (style.transform || ''), ...style } }, "\u25B6"); /** * Chunk elements in the array by size * * when the array cannot be chunked evenly by size, the last chunk will be * filled with the remaining elements * * @example * chunkArray(['a','b', 'c', 'd', 'e'], 2) // returns [['a','b'], ['c', 'd'], ['e']] */ function chunkArray(array, size) { if (size < 1) return []; let i = 0; const result = []; while (i < array.length) { result.push(array.slice(i, i + size)); i = i + size; } return result; } const DefaultRenderer = ({ HandleEntry, label, value, subEntries = [], subEntryPages = [], type, expanded = false, toggleExpanded, pageSize }) => { const [expandedPages, setExpandedPages] = React__default["default"].useState([]); return /*#__PURE__*/React__default["default"].createElement(Entry, { key: label }, subEntryPages.length ? /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("button", { onClick: () => toggleExpanded() }, /*#__PURE__*/React__default["default"].createElement(Expander, { expanded: expanded }), " ", label, ' ', /*#__PURE__*/React__default["default"].createElement(Info, null, String(type).toLowerCase() === 'iterable' ? '(Iterable) ' : '', subEntries.length, " ", subEntries.length > 1 ? "items" : "item")), expanded ? subEntryPages.length === 1 ? /*#__PURE__*/React__default["default"].createElement(SubEntries, null, subEntries.map(entry => /*#__PURE__*/React__default["default"].createElement(HandleEntry, { key: entry.label, entry: entry }))) : /*#__PURE__*/React__default["default"].createElement(SubEntries, null, subEntryPages.map((entries, index) => /*#__PURE__*/React__default["default"].createElement("div", { key: index }, /*#__PURE__*/React__default["default"].createElement(Entry, null, /*#__PURE__*/React__default["default"].createElement(LabelButton, { onClick: () => setExpandedPages(old => old.includes(index) ? old.filter(d => d !== index) : [...old, index]) }, /*#__PURE__*/React__default["default"].createElement(Expander, { expanded: expanded }), " [", index * pageSize, " ...", ' ', index * pageSize + pageSize - 1, "]"), expandedPages.includes(index) ? /*#__PURE__*/React__default["default"].createElement(SubEntries, null, entries.map(entry => /*#__PURE__*/React__default["default"].createElement(HandleEntry, { key: entry.label, entry: entry }))) : null)))) : null) : /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(Label, null, label, ":"), " ", /*#__PURE__*/React__default["default"].createElement(Value, null, displayValue(value)))); }; function isIterable(x) { return Symbol.iterator in x; } function Explorer({ value, defaultExpanded, renderer = DefaultRenderer, pageSize = 100, ...rest }) { const [expanded, setExpanded] = React__default["default"].useState(Boolean(defaultExpanded)); const toggleExpanded = React__default["default"].useCallback(() => setExpanded(old => !old), []); let type = typeof value; let subEntries = []; const makeProperty = sub => { const subDefaultExpanded = defaultExpanded === true ? { [sub.label]: true } : defaultExpanded == null ? void 0 : defaultExpanded[sub.label]; return { ...sub, defaultExpanded: subDefaultExpanded }; }; if (Array.isArray(value)) { type = 'array'; subEntries = value.map((d, i) => makeProperty({ label: i.toString(), value: d })); } else if (value !== null && typeof value === 'object' && isIterable(value) && typeof value[Symbol.iterator] === 'function') { type = 'Iterable'; subEntries = Array.from(value, (val, i) => makeProperty({ label: i.toString(), value: val })); } else if (typeof value === 'object' && value !== null) { type = 'object'; subEntries = Object.entries(value).map(([key, val]) => makeProperty({ label: key, value: val })); } const subEntryPages = chunkArray(subEntries, pageSize); return renderer({ HandleEntry: ({ entry }) => /*#__PURE__*/React__default["default"].createElement(Explorer, _extends$1({ value: value, renderer: renderer }, rest, entry)), type, subEntries, subEntryPages, value, expanded, toggleExpanded, pageSize, ...rest }); } function Logo(props) { return /*#__PURE__*/React__namespace.createElement("svg", _extends$1({ width: "40px", height: "40px", viewBox: "0 0 190 190", version: "1.1" }, props), /*#__PURE__*/React__namespace.createElement("g", { stroke: "none", strokeWidth: "1", fill: "none", fillRule: "evenodd" }, /*#__PURE__*/React__namespace.createElement("g", { transform: "translate(-33.000000, 0.000000)" }, /*#__PURE__*/React__namespace.createElement("path", { d: "M72.7239712,61.3436237 C69.631224,46.362877 68.9675112,34.8727722 70.9666331,26.5293551 C72.1555965,21.5671678 74.3293088,17.5190846 77.6346064,14.5984631 C81.1241394,11.5150478 85.5360327,10.0020122 90.493257,10.0020122 C98.6712013,10.0020122 107.26826,13.7273214 116.455725,20.8044264 C120.20312,23.6910458 124.092437,27.170411 128.131651,31.2444746 C128.45314,30.8310265 128.816542,30.4410453 129.22143,30.0806152 C140.64098,19.9149716 150.255245,13.5989272 158.478408,11.1636507 C163.367899,9.715636 167.958526,9.57768202 172.138936,10.983031 C176.551631,12.4664684 180.06766,15.5329489 182.548314,19.8281091 C186.642288,26.9166735 187.721918,36.2310983 186.195595,47.7320243 C185.573451,52.4199112 184.50985,57.5263831 183.007094,63.0593153 C183.574045,63.1277086 184.142416,63.2532808 184.705041,63.4395297 C199.193932,68.2358678 209.453582,73.3937462 215.665021,79.2882839 C219.360669,82.7953831 221.773972,86.6998434 222.646365,91.0218204 C223.567176,95.5836746 222.669313,100.159332 220.191548,104.451297 C216.105211,111.529614 208.591643,117.11221 197.887587,121.534031 C193.589552,123.309539 188.726579,124.917559 183.293259,126.363748 C183.541176,126.92292 183.733521,127.516759 183.862138,128.139758 C186.954886,143.120505 187.618598,154.61061 185.619477,162.954027 C184.430513,167.916214 182.256801,171.964297 178.951503,174.884919 C175.46197,177.968334 171.050077,179.48137 166.092853,179.48137 C157.914908,179.48137 149.31785,175.756061 140.130385,168.678956 C136.343104,165.761613 132.410866,162.238839 128.325434,158.108619 C127.905075,158.765474 127.388968,159.376011 126.77857,159.919385 C115.35902,170.085028 105.744755,176.401073 97.5215915,178.836349 C92.6321009,180.284364 88.0414736,180.422318 83.8610636,179.016969 C79.4483686,177.533532 75.9323404,174.467051 73.4516862,170.171891 C69.3577116,163.083327 68.2780823,153.768902 69.8044053,142.267976 C70.449038,137.410634 71.56762,132.103898 73.1575891,126.339009 C72.5361041,126.276104 71.9120754,126.144816 71.2949591,125.940529 C56.8060684,121.144191 46.5464184,115.986312 40.3349789,110.091775 C36.6393312,106.584675 34.2260275,102.680215 33.3536352,98.3582381 C32.4328237,93.7963839 33.3306866,89.2207269 35.8084524,84.9287618 C39.8947886,77.8504443 47.4083565,72.2678481 58.1124133,67.8460273 C62.5385143,66.0176154 67.5637208,64.366822 73.1939394,62.8874674 C72.9933393,62.3969171 72.8349374,61.8811235 72.7239712,61.3436237 Z", fill: "#002C4B", fillRule: "nonzero", transform: "translate(128.000000, 95.000000) scale(-1, 1) translate(-128.000000, -95.000000) " }), /*#__PURE__*/React__namespace.createElement("path", { d: "M113.396882,64 L142.608177,64 C144.399254,64 146.053521,64.958025 146.944933,66.5115174 L161.577138,92.0115174 C162.461464,93.5526583 162.461464,95.4473417 161.577138,96.9884826 L146.944933,122.488483 C146.053521,124.041975 144.399254,125 142.608177,125 L113.396882,125 C111.605806,125 109.951539,124.041975 109.060126,122.488483 L94.4279211,96.9884826 C93.543596,95.4473417 93.543596,93.5526583 94.4279211,92.0115174 L109.060126,66.5115174 C109.951539,64.958025 111.605806,64 113.396882,64 Z M138.987827,70.2765273 C140.779849,70.2765273 142.434839,71.2355558 143.325899,72.7903404 L154.343038,92.0138131 C155.225607,93.5537825 155.225607,95.4462175 154.343038,96.9861869 L143.325899,116.20966 C142.434839,117.764444 140.779849,118.723473 138.987827,118.723473 L117.017233,118.723473 C115.225211,118.723473 113.570221,117.764444 112.67916,116.20966 L101.662022,96.9861869 C100.779452,95.4462175 100.779452,93.5537825 101.662022,92.0138131 L112.67916,72.7903404 C113.570221,71.2355558 115.225211,70.2765273 117.017233,70.2765273 L138.987827,70.2765273 Z M135.080648,77.1414791 L120.924411,77.1414791 C119.134228,77.1414791 117.480644,78.0985567 116.5889,79.6508285 L116.5889,79.6508285 L109.489217,92.0093494 C108.603232,93.5515958 108.603232,95.4484042 109.489217,96.9906506 L109.489217,96.9906506 L116.5889,109.349172 C117.480644,110.901443 119.134228,111.858521 120.924411,111.858521 L120.924411,111.858521 L135.080648,111.858521 C136.870831,111.858521 138.524416,110.901443 139.41616,109.349172 L139.41616,109.349172 L146.515843,96.9906506 C147.401828,95.4484042 147.401828,93.5515958 146.515843,92.0093494 L146.515843,92.0093494 L139.41616,79.6508285 C138.524416,78.0985567 136.870831,77.1414791 135.080648,77.1414791 L135.080648,77.1414791 Z M131.319186,83.7122186 C133.108028,83.7122186 134.760587,84.6678753 135.652827,86.2183156 L138.983552,92.0060969 C139.87203,93.5500005 139.87203,95.4499995 138.983552,96.9939031 L135.652827,102.781684 C134.760587,104.332125 133.108028,105.287781 131.319186,105.287781 L124.685874,105.287781 C122.897032,105.287781 121.244473,104.332125 120.352233,102.781684 L117.021508,96.9939031 C116.13303,95.4499995 116.13303,93.5500005 117.021508,92.0060969 L120.352233,86.2183156 C121.244473,84.6678753 122.897032,83.7122186 124.685874,83.7122186 L131.319186,83.7122186 Z M128.003794,90.1848875 C126.459294,90.1848875 125.034382,91.0072828 124.263005,92.3424437 C123.491732,93.6774232 123.491732,95.3225768 124.263005,96.6575563 C125.034382,97.9927172 126.459294,98.8151125 128.001266,98.8151125 L128.001266,98.8151125 C129.545766,98.8151125 130.970678,97.9927172 131.742055,96.6575563 C132.513327,95.3225768 132.513327,93.6774232 131.742055,92.3424437 C130.970678,91.0072828 129.545766,