@availity/authorize
Version:
Check user permissions to see if the current user is authorized to see your content.
1,506 lines (1,224 loc) • 1.11 MB
JavaScript
import React, { Component } from 'react';
import { avUserPermissionsApi, avRegionsApi } from '@availity/api-axios';
function Loader() {
return React.createElement(
"div",
{ className: "loading-indicator" },
React.createElement(
"span",
{ className: "loading-bullet" },
"\u2022"
),
' ',
React.createElement(
"span",
{ className: "loading-bullet" },
"\u2022"
),
' ',
React.createElement(
"span",
{ className: "loading-bullet" },
"\u2022"
)
);
}
// https://gist.github.com/Alex1990/046a6553dc83e22dd6f4
/**
* Get the current active element safely.
* Ref: https://github.com/jquery/jquery-ui/blob/2b84531ae9331f60e4d739fabca6d78abde89ae1/ui/safe-active-element.js
*/
function safeActiveElement(doc) {
doc = doc || document;
var activeElement = void 0;
try {
activeElement = document.activeElement;
if (!activeElement || !activeElement.nodeName) {
activeElement = doc.body;
}
} catch (error) {
activeElement = doc.body;
}
return activeElement;
}
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var _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;
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var defaultProps = {
tag: 'div',
renderChildren: true,
loader: Loader
};
var BlockUi$1 = function (_Component) {
inherits(BlockUi, _Component);
function BlockUi(props) {
classCallCheck(this, BlockUi);
var _this = possibleConstructorReturn(this, (BlockUi.__proto__ || Object.getPrototypeOf(BlockUi)).call(this, props));
_this.tabbedUpTop = _this.tabbedUpTop.bind(_this);
_this.tabbedDownTop = _this.tabbedDownTop.bind(_this);
_this.tabbedUpBottom = _this.tabbedUpBottom.bind(_this);
_this.tabbedDownBottom = _this.tabbedDownBottom.bind(_this);
_this.setHelper = _this.setRef.bind(_this, 'helper');
_this.setBlocker = _this.setRef.bind(_this, 'blocker');
_this.setTopFocus = _this.setRef.bind(_this, 'topFocus');
_this.setContainer = _this.setRef.bind(_this, 'container');
_this.setMessageContainer = _this.setRef.bind(_this, 'messageContainer');
_this.handleScroll = _this.handleScroll.bind(_this);
_this.state = { top: '50%' };
return _this;
}
createClass(BlockUi, [{
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var _this2 = this;
if (nextProps.blocking !== this.props.blocking) {
if (nextProps.blocking) {
// blocking started
if (this.helper && this.helper.parentNode && this.helper.parentNode.contains && this.helper.parentNode.contains(safeActiveElement())) {
this.focused = safeActiveElement();
// https://www.tjvantoll.com/2013/08/30/bugs-with-document-activeelement-in-internet-explorer/#blurring-the-body-switches-windows-in-ie9-and-ie10
if (this.focused && this.focused !== document.body) {
(window.setImmediate || setTimeout)(function () {
return _this2.focused && typeof _this2.focused.blur === 'function' && _this2.focused.blur();
});
}
}
} else {
this.detachListeners();
var ae = safeActiveElement();
if (this.focused && (!ae || ae === document.body || ae === this.topFocus)) {
if (typeof this.focused.focus === 'function') {
this.focused.focus();
}
this.focused = null;
}
}
}
if (nextProps.keepInView && (nextProps.keepInView !== this.props.keepInView || nextProps.blocking && nextProps.blocking !== this.props.blocking)) {
this.attachListeners();
this.keepInView(nextProps);
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
this.detachListeners();
}
}, {
key: 'setRef',
value: function setRef(name, ref) {
this[name] = ref;
}
}, {
key: 'attachListeners',
value: function attachListeners() {
window.addEventListener('scroll', this.handleScroll);
}
}, {
key: 'detachListeners',
value: function detachListeners() {
window.removeEventListener('scroll', this.handleScroll);
}
}, {
key: 'blockingTab',
value: function blockingTab(e) {
var withShift = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
// eslint-disable-next-line eqeqeq
return this.props.blocking && (e.key === 'Tab' || e.keyCode === 9) && e.shiftKey == withShift;
}
}, {
key: 'tabbedUpTop',
value: function tabbedUpTop(e) {
if (this.blockingTab(e)) {
this.blocker.focus();
}
}
}, {
key: 'tabbedDownTop',
value: function tabbedDownTop(e) {
if (this.blockingTab(e)) {
e.preventDefault();
this.blocker.focus();
}
}
}, {
key: 'tabbedUpBottom',
value: function tabbedUpBottom(e) {
if (this.blockingTab(e, true)) {
this.topFocus.focus();
}
}
}, {
key: 'tabbedDownBottom',
value: function tabbedDownBottom(e) {
if (this.blockingTab(e, true)) {
e.preventDefault();
this.topFocus.focus();
}
}
}, {
key: 'keepInView',
value: function keepInView() {
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.props;
if (props.blocking && props.keepInView && this.container) {
var containerBounds = this.container.getBoundingClientRect();
var windowHeight = window.innerHeight;
if (containerBounds.top > windowHeight || containerBounds.bottom < 0) return;
if (containerBounds.top >= 0 && containerBounds.bottom <= windowHeight) {
if (this.state.top !== '50%') {
this.setState({ top: '50%' });
}
return;
}
var messageBoundsHeight = this.messageContainer ? this.messageContainer.getBoundingClientRect().height : 0;
var top = Math.max(Math.min(windowHeight, containerBounds.bottom) - Math.max(containerBounds.top, 0), messageBoundsHeight) / 2;
if (containerBounds.top < 0) {
top = Math.min(top - containerBounds.top, containerBounds.height - messageBoundsHeight / 2);
}
if (this.state.top !== top) {
this.setState({ top: top });
}
}
}
}, {
key: 'handleScroll',
value: function handleScroll() {
this.keepInView();
}
}, {
key: 'render',
value: function render() {
var _props = this.props,
Tag = _props.tag,
blocking = _props.blocking,
className = _props.className,
children = _props.children,
message = _props.message,
Loader$$1 = _props.loader,
renderChildren = _props.renderChildren,
keepInView = _props.keepInView,
attributes = objectWithoutProperties(_props, ['tag', 'blocking', 'className', 'children', 'message', 'loader', 'renderChildren', 'keepInView']);
var classes = blocking ? 'block-ui ' + className : className;
var renderChilds = !blocking || renderChildren;
return React.createElement(
Tag,
_extends$1({}, attributes, { className: classes, 'aria-busy': blocking }),
blocking && React.createElement('div', { tabIndex: '0', onKeyUp: this.tabbedUpTop, onKeyDown: this.tabbedDownTop, ref: this.setTopFocus }),
renderChilds && children,
blocking && React.createElement(
'div',
{ className: 'block-ui-container',
tabIndex: '0',
ref: this.setBlocker,
onKeyUp: this.tabbedUpBottom,
onKeyDown: this.tabbedDownBottom
},
React.createElement('div', { className: 'block-ui-overlay', ref: this.setContainer }),
React.createElement(
'div',
{ className: 'block-ui-message-container',
ref: this.setMessageContainer,
style: { top: keepInView ? this.state.top : undefined }
},
React.createElement(
'div',
{ className: 'block-ui-message' },
message,
React.isValidElement(Loader$$1) ? Loader$$1 : React.createElement(Loader$$1, null)
)
)
),
React.createElement('span', { ref: this.setHelper })
);
}
}]);
return BlockUi;
}(Component);
BlockUi$1.defaultProps = defaultProps;
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (!css || typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css_248z = ".loading-indicator {\n text-align: center;\n}\n.loading-bullet {\n display: inline-block;\n opacity: 0;\n font-size: 2em;\n color: #02a17c;\n}\n.block-ui {\n position: relative;\n min-height: 3em;\n}\n.block-ui-container {\n position: absolute;\n z-index: 1010;\n top: 0;\n right: 0;\n bottom: 0;\n left: 0;\n height: 100%;\n min-height: 2em;\n cursor: wait;\n overflow: hidden;\n}\n.block-ui-container:focus {\n outline: none;\n}\n.block-ui-overlay {\n width: 100%;\n height: 100%;\n opacity: 0.5;\n filter: alpha(opacity=50);\n background-color: white;\n}\n.block-ui-message-container {\n position: absolute;\n top: 50%;\n left: 0;\n right: 0;\n text-align: center;\n transform: translateY(-50%);\n z-index: 10001;\n}\n.block-ui-message {\n color: #333;\n background: none;\n z-index: 1011;\n}\n\n/* CSS Animations */\n@-webkit-keyframes fadeInRTL1 {\n 0% {\n opacity: 0;\n -webkit-transform: translateX(20px);\n transform: translateX(20px);\n }\n 30% {\n opacity: 1;\n -webkit-transform: translateX(0px);\n transform: translateX(0px);\n }\n 60% {\n opacity: 1;\n }\n 80% {\n opacity: 0;\n }\n}\n@keyframes fadeInRTL1 {\n 0% {\n opacity: 0;\n -webkit-transform: translateX(20px);\n transform: translateX(20px);\n }\n 30% {\n opacity: 1;\n -webkit-transform: translateX(0px);\n transform: translateX(0px);\n }\n 60% {\n opacity: 1;\n }\n 80% {\n opacity: 0;\n }\n}\n@-webkit-keyframes fadeInRTL2 {\n 0% {\n opacity: 0;\n }\n 10% {\n opacity: 0;\n -webkit-transform: translateX(20px);\n transform: translateX(20px);\n }\n 40% {\n opacity: 1;\n -webkit-transform: translateX(0px);\n transform: translateX(0px);\n }\n 60% {\n opacity: 1;\n }\n 80% {\n opacity: 0;\n }\n}\n@keyframes fadeInRTL2 {\n 0% {\n opacity: 0;\n }\n 10% {\n opacity: 0;\n -webkit-transform: translateX(20px);\n transform: translateX(20px);\n }\n 40% {\n opacity: 1;\n -webkit-transform: translateX(0px);\n transform: translateX(0px);\n }\n 60% {\n opacity: 1;\n }\n 80% {\n opacity: 0;\n }\n}\n@-webkit-keyframes fadeInRTL3 {\n 0% {\n opacity: 0;\n }\n 20% {\n opacity: 0;\n -webkit-transform: translateX(20px);\n transform: translateX(20px);\n }\n 50% {\n opacity: 1;\n -webkit-transform: translateX(0px);\n transform: translateX(0px);\n }\n 60% {\n opacity: 1;\n }\n 80% {\n opacity: 0;\n }\n}\n@keyframes fadeInRTL3 {\n 0% {\n opacity: 0;\n }\n 20% {\n opacity: 0;\n -webkit-transform: translateX(20px);\n transform: translateX(20px);\n }\n 50% {\n opacity: 1;\n -webkit-transform: translateX(0px);\n transform: translateX(0px);\n }\n 60% {\n opacity: 1;\n }\n 80% {\n opacity: 0;\n }\n}\n.loading-bullet {\n display: inline-block;\n opacity: 0;\n -webkit-animation: 3s ease .5s infinite fadeInRTL1;\n animation: 3s ease .5s infinite fadeInRTL1;\n}\n.loading-bullet + .loading-bullet {\n -webkit-animation-name: fadeInRTL2;\n animation-name: fadeInRTL2;\n}\n.loading-bullet + .loading-bullet + .loading-bullet {\n -webkit-animation-name: fadeInRTL3;\n animation-name: fadeInRTL3;\n}\n";
styleInject(css_248z);
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
var Subscribable = /*#__PURE__*/function () {
function Subscribable() {
this.listeners = [];
}
var _proto = Subscribable.prototype;
_proto.subscribe = function subscribe(listener) {
var _this = this;
var callback = listener || function () {
return undefined;
};
this.listeners.push(callback);
this.onSubscribe();
return function () {
_this.listeners = _this.listeners.filter(function (x) {
return x !== callback;
});
_this.onUnsubscribe();
};
};
_proto.hasListeners = function hasListeners() {
return this.listeners.length > 0;
};
_proto.onSubscribe = function onSubscribe() {// Do nothing
};
_proto.onUnsubscribe = function onUnsubscribe() {// Do nothing
};
return Subscribable;
}();
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);
}
// TYPES
// UTILS
var isServer = typeof window === 'undefined';
function noop() {
return undefined;
}
function isValidTimeout(value) {
return typeof value === 'number' && value >= 0 && value !== Infinity;
}
function timeUntilStale(updatedAt, staleTime) {
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
}
function parseQueryArgs(arg1, arg2, arg3) {
if (!isQueryKey(arg1)) {
return arg1;
}
if (typeof arg2 === 'function') {
return _extends({}, arg3, {
queryKey: arg1,
queryFn: arg2
});
}
return _extends({}, arg2, {
queryKey: arg1
});
}
/**
* This function returns `a` if `b` is deeply equal.
* If not, it will replace any deeply equal children of `b` with those of `a`.
* This can be used for structural sharing between JSON values for example.
*/
function replaceEqualDeep(a, b) {
if (a === b) {
return a;
}
var array = Array.isArray(a) && Array.isArray(b);
if (array || isPlainObject(a) && isPlainObject(b)) {
var aSize = array ? a.length : Object.keys(a).length;
var bItems = array ? b : Object.keys(b);
var bSize = bItems.length;
var copy = array ? [] : {};
var equalItems = 0;
for (var i = 0; i < bSize; i++) {
var key = array ? i : bItems[i];
copy[key] = replaceEqualDeep(a[key], b[key]);
if (copy[key] === a[key]) {
equalItems++;
}
}
return aSize === bSize && equalItems === aSize ? a : copy;
}
return b;
}
/**
* Shallow compare objects. Only works with objects that always have the same properties.
*/
function shallowEqualObjects(a, b) {
if (a && !b || b && !a) {
return false;
}
for (var key in a) {
if (a[key] !== b[key]) {
return false;
}
}
return true;
} // Copied from: https://github.com/jonschlinkert/is-plain-object
function isPlainObject(o) {
if (!hasObjectPrototype(o)) {
return false;
} // If has modified constructor
var ctor = o.constructor;
if (typeof ctor === 'undefined') {
return true;
} // If has modified prototype
var prot = ctor.prototype;
if (!hasObjectPrototype(prot)) {
return false;
} // If constructor does not have an Object-specific method
if (!prot.hasOwnProperty('isPrototypeOf')) {
return false;
} // Most likely a plain Object
return true;
}
function hasObjectPrototype(o) {
return Object.prototype.toString.call(o) === '[object Object]';
}
function isQueryKey(value) {
return typeof value === 'string' || Array.isArray(value);
}
/**
* Schedules a microtask.
* This can be useful to schedule state updates after rendering.
*/
function scheduleMicrotask(callback) {
Promise.resolve().then(callback).catch(function (error) {
return setTimeout(function () {
throw error;
});
});
}
var FocusManager = /*#__PURE__*/function (_Subscribable) {
_inheritsLoose(FocusManager, _Subscribable);
function FocusManager() {
var _this;
_this = _Subscribable.call(this) || this;
_this.setup = function (onFocus) {
var _window;
if (!isServer && ((_window = window) == null ? void 0 : _window.addEventListener)) {
var listener = function listener() {
return onFocus();
}; // Listen to visibillitychange and focus
window.addEventListener('visibilitychange', listener, false);
window.addEventListener('focus', listener, false);
return function () {
// Be sure to unsubscribe if a new handler is set
window.removeEventListener('visibilitychange', listener);
window.removeEventListener('focus', listener);
};
}
};
return _this;
}
var _proto = FocusManager.prototype;
_proto.onSubscribe = function onSubscribe() {
if (!this.cleanup) {
this.setEventListener(this.setup);
}
};
_proto.onUnsubscribe = function onUnsubscribe() {
if (!this.hasListeners()) {
var _this$cleanup;
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
this.cleanup = undefined;
}
};
_proto.setEventListener = function setEventListener(setup) {
var _this$cleanup2,
_this2 = this;
this.setup = setup;
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
this.cleanup = setup(function (focused) {
if (typeof focused === 'boolean') {
_this2.setFocused(focused);
} else {
_this2.onFocus();
}
});
};
_proto.setFocused = function setFocused(focused) {
this.focused = focused;
if (focused) {
this.onFocus();
}
};
_proto.onFocus = function onFocus() {
this.listeners.forEach(function (listener) {
listener();
});
};
_proto.isFocused = function isFocused() {
if (typeof this.focused === 'boolean') {
return this.focused;
} // document global can be unavailable in react native
if (typeof document === 'undefined') {
return true;
}
return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
};
return FocusManager;
}(Subscribable);
var focusManager = new FocusManager();
var CancelledError = function CancelledError(options) {
this.revert = options == null ? void 0 : options.revert;
this.silent = options == null ? void 0 : options.silent;
};
function isCancelledError(value) {
return value instanceof CancelledError;
} // CLASS
// CLASS
var NotifyManager = /*#__PURE__*/function () {
function NotifyManager() {
this.queue = [];
this.transactions = 0;
this.notifyFn = function (callback) {
callback();
};
this.batchNotifyFn = function (callback) {
callback();
};
}
var _proto = NotifyManager.prototype;
_proto.batch = function batch(callback) {
var result;
this.transactions++;
try {
result = callback();
} finally {
this.transactions--;
if (!this.transactions) {
this.flush();
}
}
return result;
};
_proto.schedule = function schedule(callback) {
var _this = this;
if (this.transactions) {
this.queue.push(callback);
} else {
scheduleMicrotask(function () {
_this.notifyFn(callback);
});
}
}
/**
* All calls to the wrapped function will be batched.
*/
;
_proto.batchCalls = function batchCalls(callback) {
var _this2 = this;
return function () {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this2.schedule(function () {
callback.apply(void 0, args);
});
};
};
_proto.flush = function flush() {
var _this3 = this;
var queue = this.queue;
this.queue = [];
if (queue.length) {
scheduleMicrotask(function () {
_this3.batchNotifyFn(function () {
queue.forEach(function (callback) {
_this3.notifyFn(callback);
});
});
});
}
}
/**
* Use this method to set a custom notify function.
* This can be used to for example wrap notifications with `React.act` while running tests.
*/
;
_proto.setNotifyFunction = function setNotifyFunction(fn) {
this.notifyFn = fn;
}
/**
* Use this method to set a custom function to batch notifications together into a single tick.
* By default React Query will use the batch function provided by ReactDOM or React Native.
*/
;
_proto.setBatchNotifyFunction = function setBatchNotifyFunction(fn) {
this.batchNotifyFn = fn;
};
return NotifyManager;
}(); // SINGLETON
var notifyManager = new NotifyManager();
// TYPES
// FUNCTIONS
var logger$1 = console;
function getLogger() {
return logger$1;
}
function setLogger(newLogger) {
logger$1 = newLogger;
}
var QueryObserver = /*#__PURE__*/function (_Subscribable) {
_inheritsLoose(QueryObserver, _Subscribable);
function QueryObserver(client, options) {
var _this;
_this = _Subscribable.call(this) || this;
_this.client = client;
_this.options = options;
_this.trackedProps = [];
_this.previousSelectError = null;
_this.bindMethods();
_this.setOptions(options);
return _this;
}
var _proto = QueryObserver.prototype;
_proto.bindMethods = function bindMethods() {
this.remove = this.remove.bind(this);
this.refetch = this.refetch.bind(this);
};
_proto.onSubscribe = function onSubscribe() {
if (this.listeners.length === 1) {
this.currentQuery.addObserver(this);
if (shouldFetchOnMount(this.currentQuery, this.options)) {
this.executeFetch();
}
this.updateTimers();
}
};
_proto.onUnsubscribe = function onUnsubscribe() {
if (!this.listeners.length) {
this.destroy();
}
};
_proto.shouldFetchOnReconnect = function shouldFetchOnReconnect() {
return _shouldFetchOnReconnect(this.currentQuery, this.options);
};
_proto.shouldFetchOnWindowFocus = function shouldFetchOnWindowFocus() {
return _shouldFetchOnWindowFocus(this.currentQuery, this.options);
};
_proto.destroy = function destroy() {
this.listeners = [];
this.clearTimers();
this.currentQuery.removeObserver(this);
};
_proto.setOptions = function setOptions(options, notifyOptions) {
var prevOptions = this.options;
var prevQuery = this.currentQuery;
this.options = this.client.defaultQueryObserverOptions(options);
if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
throw new Error('Expected enabled to be a boolean');
} // Keep previous query key if the user does not supply one
if (!this.options.queryKey) {
this.options.queryKey = prevOptions.queryKey;
}
this.updateQuery();
var mounted = this.hasListeners(); // Fetch if there are subscribers
if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
this.executeFetch();
} // Update result
this.updateResult(notifyOptions); // Update stale interval if needed
if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
this.updateStaleTimeout();
}
var nextRefetchInterval = this.computeRefetchInterval(); // Update refetch interval if needed
if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
this.updateRefetchInterval(nextRefetchInterval);
}
};
_proto.getOptimisticResult = function getOptimisticResult(options) {
var defaultedOptions = this.client.defaultQueryObserverOptions(options);
var query = this.client.getQueryCache().build(this.client, defaultedOptions);
return this.createResult(query, defaultedOptions);
};
_proto.getCurrentResult = function getCurrentResult() {
return this.currentResult;
};
_proto.trackResult = function trackResult(result, defaultedOptions) {
var _this2 = this;
var trackedResult = {};
var trackProp = function trackProp(key) {
if (!_this2.trackedProps.includes(key)) {
_this2.trackedProps.push(key);
}
};
Object.keys(result).forEach(function (key) {
Object.defineProperty(trackedResult, key, {
configurable: false,
enumerable: true,
get: function get() {
trackProp(key);
return result[key];
}
});
});
if (defaultedOptions.useErrorBoundary || defaultedOptions.suspense) {
trackProp('error');
}
return trackedResult;
};
_proto.getNextResult = function getNextResult(options) {
var _this3 = this;
return new Promise(function (resolve, reject) {
var unsubscribe = _this3.subscribe(function (result) {
if (!result.isFetching) {
unsubscribe();
if (result.isError && (options == null ? void 0 : options.throwOnError)) {
reject(result.error);
} else {
resolve(result);
}
}
});
});
};
_proto.getCurrentQuery = function getCurrentQuery() {
return this.currentQuery;
};
_proto.remove = function remove() {
this.client.getQueryCache().remove(this.currentQuery);
};
_proto.refetch = function refetch(options) {
return this.fetch(_extends({}, options, {
meta: {
refetchPage: options == null ? void 0 : options.refetchPage
}
}));
};
_proto.fetchOptimistic = function fetchOptimistic(options) {
var _this4 = this;
var defaultedOptions = this.client.defaultQueryObserverOptions(options);
var query = this.client.getQueryCache().build(this.client, defaultedOptions);
return query.fetch().then(function () {
return _this4.createResult(query, defaultedOptions);
});
};
_proto.fetch = function fetch(fetchOptions) {
var _this5 = this;
return this.executeFetch(fetchOptions).then(function () {
_this5.updateResult();
return _this5.currentResult;
});
};
_proto.executeFetch = function executeFetch(fetchOptions) {
// Make sure we reference the latest query as the current one might have been removed
this.updateQuery(); // Fetch
var promise = this.currentQuery.fetch(this.options, fetchOptions);
if (!(fetchOptions == null ? void 0 : fetchOptions.throwOnError)) {
promise = promise.catch(noop);
}
return promise;
};
_proto.updateStaleTimeout = function updateStaleTimeout() {
var _this6 = this;
this.clearStaleTimeout();
if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
return;
}
var time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
// To mitigate this issue we always add 1 ms to the timeout.
var timeout = time + 1;
this.staleTimeoutId = setTimeout(function () {
if (!_this6.currentResult.isStale) {
_this6.updateResult();
}
}, timeout);
};
_proto.computeRefetchInterval = function computeRefetchInterval() {
var _this$options$refetch;
return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
};
_proto.updateRefetchInterval = function updateRefetchInterval(nextInterval) {
var _this7 = this;
this.clearRefetchInterval();
this.currentRefetchInterval = nextInterval;
if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
return;
}
this.refetchIntervalId = setInterval(function () {
if (_this7.options.refetchIntervalInBackground || focusManager.isFocused()) {
_this7.executeFetch();
}
}, this.currentRefetchInterval);
};
_proto.updateTimers = function updateTimers() {
this.updateStaleTimeout();
this.updateRefetchInterval(this.computeRefetchInterval());
};
_proto.clearTimers = function clearTimers() {
this.clearStaleTimeout();
this.clearRefetchInterval();
};
_proto.clearStaleTimeout = function clearStaleTimeout() {
clearTimeout(this.staleTimeoutId);
this.staleTimeoutId = undefined;
};
_proto.clearRefetchInterval = function clearRefetchInterval() {
clearInterval(this.refetchIntervalId);
this.refetchIntervalId = undefined;
};
_proto.createResult = function createResult(query, options) {
var prevQuery = this.currentQuery;
var prevOptions = this.options;
var prevResult = this.currentResult;
var prevResultState = this.currentResultState;
var prevResultOptions = this.currentResultOptions;
var queryChange = query !== prevQuery;
var queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
var prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
var state = query.state;
var dataUpdatedAt = state.dataUpdatedAt,
error = state.error,
errorUpdatedAt = state.errorUpdatedAt,
isFetching = state.isFetching,
status = state.status;
var isPreviousData = false;
var isPlaceholderData = false;
var data; // Optimistically set result in fetching state if needed
if (options.optimisticResults) {
var mounted = this.hasListeners();
var fetchOnMount = !mounted && shouldFetchOnMount(query, options);
var fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
if (fetchOnMount || fetchOptionally) {
isFetching = true;
if (!dataUpdatedAt) {
status = 'loading';
}
}
} // Keep previous data if needed
if (options.keepPreviousData && !state.dataUpdateCount && (prevQueryResult == null ? void 0 : prevQueryResult.isSuccess) && status !== 'error') {
data = prevQueryResult.data;
dataUpdatedAt = prevQueryResult.dataUpdatedAt;
status = prevQueryResult.status;
isPreviousData = true;
} // Select data if needed
else if (options.select && typeof state.data !== 'undefined') {
var _this$previousSelect;
// Memoize select result
if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === ((_this$previousSelect = this.previousSelect) == null ? void 0 : _this$previousSelect.fn) && !this.previousSelectError) {
data = this.previousSelect.result;
} else {
try {
data = options.select(state.data);
if (options.structuralSharing !== false) {
data = replaceEqualDeep(prevResult == null ? void 0 : prevResult.data, data);
}
this.previousSelect = {
fn: options.select,
result: data
};
this.previousSelectError = null;
} catch (selectError) {
getLogger().error(selectError);
error = selectError;
this.previousSelectError = selectError;
errorUpdatedAt = Date.now();
status = 'error';
}
}
} // Use query data
else {
data = state.data;
} // Show placeholder data if needed
if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && (status === 'loading' || status === 'idle')) {
var placeholderData; // Memoize placeholder data
if ((prevResult == null ? void 0 : prevResult.isPlaceholderData) && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
placeholderData = prevResult.data;
} else {
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
if (options.select && typeof placeholderData !== 'undefined') {
try {
placeholderData = options.select(placeholderData);
if (options.structuralSharing !== false) {
placeholderData = replaceEqualDeep(prevResult == null ? void 0 : prevResult.data, placeholderData);
}
this.previousSelectError = null;
} catch (selectError) {
getLogger().error(selectError);
error = selectError;
this.previousSelectError = selectError;
errorUpdatedAt = Date.now();
status = 'error';
}
}
}
if (typeof placeholderData !== 'undefined') {
status = 'success';
data = placeholderData;
isPlaceholderData = true;
}
}
var result = {
status: status,
isLoading: status === 'loading',
isSuccess: status === 'success',
isError: status === 'error',
isIdle: status === 'idle',
data: data,
dataUpdatedAt: dataUpdatedAt,
error: error,
errorUpdatedAt: errorUpdatedAt,
failureCount: state.fetchFailureCount,
isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
isFetching: isFetching,
isRefetching: isFetching && status !== 'loading',
isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
isPlaceholderData: isPlaceholderData,
isPreviousData: isPreviousData,
isRefetchError: status === 'error' && state.dataUpdatedAt !== 0,
isStale: isStale(query, options),
refetch: this.refetch,
remove: this.remove
};
return result;
};
_proto.shouldNotifyListeners = function shouldNotifyListeners(result, prevResult) {
if (!prevResult) {
return true;
}
var _this$options = this.options,
notifyOnChangeProps = _this$options.notifyOnChangeProps,
notifyOnChangePropsExclusions = _this$options.notifyOnChangePropsExclusions;
if (!notifyOnChangeProps && !notifyOnChangePropsExclusions) {
return true;
}
if (notifyOnChangeProps === 'tracked' && !this.trackedProps.length) {
return true;
}
var includedProps = notifyOnChangeProps === 'tracked' ? this.trackedProps : notifyOnChangeProps;
return Object.keys(result).some(function (key) {
var typedKey = key;
var changed = result[typedKey] !== prevResult[typedKey];
var isIncluded = includedProps == null ? void 0 : includedProps.some(function (x) {
return x === key;
});
var isExcluded = notifyOnChangePropsExclusions == null ? void 0 : notifyOnChangePropsExclusions.some(function (x) {
return x === key;
});
return changed && !isExcluded && (!includedProps || isIncluded);
});
};
_proto.updateResult = function updateResult(notifyOptions) {
var prevResult = this.currentResult;
this.currentResult = this.createResult(this.currentQuery, this.options);
this.currentResultState = this.currentQuery.state;
this.currentResultOptions = this.options; // Only notify if something has changed
if (shallowEqualObjects(this.currentResult, prevResult)) {
return;
} // Determine which callbacks to trigger
var defaultNotifyOptions = {
cache: true
};
if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && this.shouldNotifyListeners(this.currentResult, prevResult)) {
defaultNotifyOptions.listeners = true;
}
this.notify(_extends({}, defaultNotifyOptions, notifyOptions));
};
_proto.updateQuery = function updateQuery() {
var query = this.client.getQueryCache().build(this.client, this.options);
if (query === this.currentQuery) {
return;
}
var prevQuery = this.currentQuery;
this.currentQuery = query;
this.currentQueryInitialState = query.state;
this.previousQueryResult = this.currentResult;
if (this.hasListeners()) {
prevQuery == null ? void 0 : prevQuery.removeObserver(this);
query.addObserver(this);
}
};
_proto.onQueryUpdate = function onQueryUpdate(action) {
var notifyOptions = {};
if (action.type === 'success') {
notifyOptions.onSuccess = true;
} else if (action.type === 'error' && !isCancelledError(action.error)) {
notifyOptions.onError = true;
}
this.updateResult(notifyOptions);
if (this.hasListeners()) {
this.updateTimers();
}
};
_proto.notify = function notify(notifyOptions) {
var _this8 = this;
notifyManager.batch(function () {
// First trigger the configuration callbacks
if (notifyOptions.onSuccess) {
_this8.options.onSuccess == null ? void 0 : _this8.options.onSuccess(_this8.currentResult.data);
_this8.options.onSettled == null ? void 0 : _this8.options.onSettled(_this8.currentResult.data, null);
} else if (notifyOptions.onError) {
_this8.options.onError == null ? void 0 : _this8.options.onError(_this8.currentResult.error);
_this8.options.onSettled == null ? void 0 : _this8.options.onSettled(undefined, _this8.currentResult.error);
} // Then trigger the listeners
if (notifyOptions.listeners) {
_this8.listeners.forEach(function (listener) {
listener(_this8.currentResult);
});
} // Then the cache listeners
if (notifyOptions.cache) {
_this8.client.getQueryCache().notify({
query: _this8.currentQuery,
type: 'observerResultsUpdated'
});
}
});
};
return QueryObserver;
}(Subscribable);
function shouldLoadOnMount(query, options) {
return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
}
function shouldRefetchOnMount(query, options) {
return options.enabled !== false && query.state.dataUpdatedAt > 0 && (options.refetchOnMount === 'always' || options.refetchOnMount !== false && isStale(query, options));
}
function shouldFetchOnMount(query, options) {
return shouldLoadOnMount(query, options) || shouldRefetchOnMount(query, options);
}
function _shouldFetchOnReconnect(query, options) {
return options.enabled !== false && (options.refetchOnReconnect === 'always' || options.refetchOnReconnect !== false && isStale(query, options));
}
function _shouldFetchOnWindowFocus(query, options) {
return options.enabled !== false && (options.refetchOnWindowFocus === 'always' || options.refetchOnWindowFocus !== false && isStale(query, options));
}
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
}
function isStale(query, options) {
return query.isStaleByTime(options.staleTime);
}
var reactDom = {exports: {}};
var reactDom_production_min = {};
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
/* eslint-disable no-unused-vars */
var getOwnPropertySymbols = Object.getOwnPropertySymbols;
var hasOwnProperty = Object.prototype.hasOwnProperty;
var propIsEnumerable = Object.prototype.propertyIsEnumerable;
function toObject(val) {
if (val === null || val === undefined) {
throw new TypeError('Object.assign cannot be called with null or undefined');
}
return Object(val);
}
function shouldUseNative() {
try {
if (!Object.assign) {
return false;
}
// Detect buggy property enumeration order in older V8 versions.
// https://bugs.chromium.org/p/v8/issues/detail?id=4118
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
test1[5] = 'de';
if (Object.getOwnPropertyNames(test1)[0] === '5') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test2 = {};
for (var i = 0; i < 10; i++) {
test2['_' + String.fromCharCode(i)] = i;
}
var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
return test2[n];
});
if (order2.join('') !== '0123456789') {
return false;
}
// https://bugs.chromium.org/p/v8/issues/detail?id=3056
var test3 = {};
'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
test3[letter] = letter;
});
if (Object.keys(Object.assign({}, test3)).join('') !==
'abcdefghijklmnopqrst') {
return false;
}
return true;
} catch (err) {
// We don't expect any of the above to throw, but better to be safe.
return false;
}
}
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
var from;
var to = toObject(target);
var symbols;
for (var s = 1; s < arguments.length; s++) {
from = Object(arguments[s]);
for (var key in from) {
if (hasOwnProperty.call(from, key)) {
to[key] = from[key];
}
}
if (getOwnPropertySymbols) {
symbols = getOwnPropertySymbols(from);
for (var i = 0; i < symbols.length; i++) {
if (propIsEnumerable.call(from, symbols[i])) {
to[symbols[i]] = from[symbols[i]];
}
}
}
}
return to;
};
var scheduler = {exports: {}};
var scheduler_production_min = {};
/** @license React v0.20.2
* scheduler.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.
*/
(function (exports) {
var f,g,h,k;if("object"===typeof performance&&"function"===typeof performance.now){var l=performance;exports.unstable_now=function(){return l.now()};}else {var p=Date,q=p.now();exports.unstable_now=function(){return p.now()-q};}
if("undefined"===typeof window||"function"!==typeof MessageChannel){var t=null,u=null,w=function(){if(null!==t)try{var a=exports.unstable_now();t(!0,a);t=null;}catch(b){throw setTimeout(w,0),b;}};f=function(a){null!==t?setTimeout(f,0,a):(t=a,setTimeout(w,0));};g=function(a,b){u=setTimeout(a,b);};h=function(){clearTimeout(u);};exports.unstable_shouldYield=function(){return !1};k=exports.unstable_forceFrameRate=function(){};}else {var x=window.setTimeout,y=window.clearTimeout;if("undefined"!==typeof console){var z=
window.cancelAnimationFrame;"function"!==typeof window.requestAnimationFrame&&console.error("This browser doesn't support requestAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills");"function"!==typeof z&&console.error("This browser doesn't support cancelAnimationFrame. Make sure that you load a polyfill in older browsers. https://reactjs.org/link/react-polyfills");}var A=!1,B=null,C=-1,D=5,E=0;exports.unstable_shouldYield=function(){return exports.unstable_now()>=
E};k=function(){};exports.unstable_forceFrameRate=function(a){0>a||125<a?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):D=0<a?Mat