@bigbinary/neeto-tags-frontend 0.0.15 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,3993 @@
1
- import"./main.css";import"common/i18n";import e,{useState as t,useEffect as n}from"react";import{Toastr as r,Tag as o,Pane as a,Typography as i,Dropdown as c,Button as u,PageLoader as l,Table as s,Alert as f}from"@bigbinary/neetoui";import{QueryClient as d,QueryCache as m,useQuery as p,useMutation as h,QueryClientProvider as g}from"react-query";import y from"axios";import{MenuHorizontal as v,Plus as b}from"@bigbinary/neeto-icons";import{MenuBar as w,Container as E,Header as T,SubHeader as x}from"@bigbinary/neetoui/layouts";import{useTranslation as S}from"react-i18next";import{Formik as L,Form as k}from"formik";import{Input as N,Textarea as P,ActionBlock as _}from"@bigbinary/neetoui/formik";import*as C from"yup";function O(){
2
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
3
- O=function(){return e};var e={},t=Object.prototype,n=t.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",a=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function c(e,t,n){return Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{c({},"")}catch(e){c=function(e,t,n){return e[t]=n}}function u(e,t,n,r){var o=t&&t.prototype instanceof f?t:f,a=Object.create(o.prototype),i=new x(r||[]);return a._invoke=function(e,t,n){var r="suspendedStart";return function(o,a){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw a;return L()}for(n.method=o,n.arg=a;;){var i=n.delegate;if(i){var c=w(i,n);if(c){if(c===s)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var u=l(e,t,n);if("normal"===u.type){if(r=n.done?"completed":"suspendedYield",u.arg===s)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(r="completed",n.method="throw",n.arg=u.arg)}}}(e,n,i),a}function l(e,t,n){try{return{type:"normal",arg:e.call(t,n)}}catch(e){return{type:"throw",arg:e}}}e.wrap=u;var s={};function f(){}function d(){}function m(){}var p={};c(p,o,(function(){return this}));var h=Object.getPrototypeOf,g=h&&h(h(S([])));g&&g!==t&&n.call(g,o)&&(p=g);var y=m.prototype=f.prototype=Object.create(p);function v(e){["next","throw","return"].forEach((function(t){c(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){function r(o,a,i,c){var u=l(e[o],e,a);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?t.resolve(f.__await).then((function(e){r("next",e,i,c)}),(function(e){r("throw",e,i,c)})):t.resolve(f).then((function(e){s.value=e,i(s)}),(function(e){return r("throw",e,i,c)}))}c(u.arg)}var o;this._invoke=function(e,n){function a(){return new t((function(t,o){r(e,n,t,o)}))}return o=o?o.then(a,a):a()}}function w(e,t){var n=e.iterator[t.method];if(void 0===n){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,w(e,t),"throw"===t.method))return s;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=l(n,e.iterator,t.arg);if("throw"===r.type)return t.method="throw",t.arg=r.arg,t.delegate=null,s;var o=r.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,s):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,s)}function E(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function x(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(E,this),this.reset(!0)}function S(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,a=function t(){for(;++r<e.length;)if(n.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:L}}function L(){return{value:void 0,done:!0}}return d.prototype=m,c(y,"constructor",m),c(m,"constructor",d),d.displayName=c(m,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,c(e,i,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},v(b.prototype),c(b.prototype,a,(function(){return this})),e.AsyncIterator=b,e.async=function(t,n,r,o,a){void 0===a&&(a=Promise);var i=new b(u(t,n,r,o),a);return e.isGeneratorFunction(n)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},v(y),c(y,i,"Generator"),c(y,o,(function(){return this})),c(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var n in e)t.push(n);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},e.values=S,x.prototype={constructor:x,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&n.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(n,r){return i.type="throw",i.arg=e,t.next=n,r&&(t.method="next",t.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return r("end");if(a.tryLoc<=this.prev){var c=n.call(a,"catchLoc"),u=n.call(a,"finallyLoc");if(c&&u){if(this.prev<a.catchLoc)return r(a.catchLoc,!0);if(this.prev<a.finallyLoc)return r(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return r(a.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return r(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,s):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),s},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),T(n),s}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var o=r.arg;T(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:S(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},e}function A(e,t,n,r,o,a,i){try{var c=e[a](i),u=c.value}catch(e){return void n(e)}c.done?t(u):Promise.resolve(u).then(r,o)}function j(e){return function(){var t=this,n=arguments;return new Promise((function(r,o){var a=e.apply(t,n);function i(e){A(a,r,o,i,c,"next",e)}function c(e){A(a,r,o,i,c,"throw",e)}i(void 0)}))}}function I(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null==n)return;var r,o,a=[],i=!0,c=!1;try{for(n=n.call(e);!(i=(r=n.next()).done)&&(a.push(r.value),!t||a.length!==t);i=!0);}catch(e){c=!0,o=e}finally{try{i||null==n.return||n.return()}finally{if(c)throw o}}return a}(e,t)||D(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function F(e){return function(e){if(Array.isArray(e))return M(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||D(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function D(e,t){if(e){if("string"==typeof e)return M(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?M(e,t):void 0}}function M(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}y.defaults.baseURL="/";var B=function(e){return e?(e.success=200===e.status,e.data):e},G=function(e){var t,n;return 401===(null===(t=e.response)||void 0===t?void 0:t.status)&&(delete y.defaults.headers["X-Auth-Email"],delete y.defaults.headers["X-Auth-Token"],setTimeout((function(){window.location.href="/login"}),300)),function(e){if("Network Error"===e.message)throw new Error("No internet connection.")}(e),Promise.reject(null==e||null===(n=e.response)||void 0===n?void 0:n.data)},q=new d({queryCache:new m({onError:function(e){return r.error(e)}})}),X=[{title:"Name",dataIndex:"name",key:"name",render:function(t){return e.createElement(o,{label:t,color:"blue"})},width:"30%"},{title:"Description",dataIndex:"description",key:"description",render:function(e){return e||"--"},width:"40%"}],R=C.object({name:C.string().typeError("Name must be a string.").required("Name is a required field.").max(50,"Name should not exceed 50 characters."),description:C.string().typeError("Description must be a string.").nullable().max(255,"Description should not exceed 255 characters.")}),z="CREATE_TAG",Q="EDIT_TAG",U={name:"",description:""},H=function(e,t,n,r){return y.get(e,{params:{term:t,limit:n,page_no:r}})},J=function(e,t){return y.post(e,t)},V=function(e,t,n){return y.put("".concat(e,"/").concat(t),n)},Y=function(e,t){return y.delete("".concat(e,"/").concat(t))},K=function(){return h((function(e){var t=e.url,n=e.payload;return J(t,n)}),{onSuccess:function(){q.invalidateQueries(["tag-key"])}})},W=function(){return h((function(e){var t=e.url,n=e.id,r=e.payload;return V(t,n,r)}),{onSuccess:function(){q.invalidateQueries(["tag-key"])}})},$=function(t){var n=t.tag,o=t.type,c=t.onClose,u=t.tagType,l=t.goToFirstPage,s=o===Q,f=s?n:U,d=S().t,m=function(e){var t=e.isEdit,n=e.tagType,o=e.onClose,a=e.goToFirstPage,i=(t?W:K)(),c=i.mutate,u=i.isLoading,l=S().t;return{handleSubmit:function(e,i){var u,s=i.resetForm;e.description=null==e||null===(u=e.description)||void 0===u?void 0:u.trim();var f={payload:{tag:e}};f.url=n.url,t&&(f.id=e.id),c(f,{onSuccess:function(){!t&&a(),o(),r.success(l(t?"updateSuccess":"createSuccess"))},onError:function(e){var t=e.errors;s(),r.error(null==t?void 0:t.join(", "))}})},isSubmitting:u}}({isEdit:s,tagType:u,onClose:c,goToFirstPage:l}),p=m.handleSubmit;return e.createElement(a,{isOpen:!!o,onClose:c},e.createElement(a.Header,null,e.createElement(i,{style:"h2",weight:"semibold"},d(s?"editItem":"addNew",{what:d("tag")}))),e.createElement(L,{initialValues:f,validateOnBlur:!1,validateOnChange:!1,onSubmit:p,validationSchema:R},(function(t){var n=t.isSubmitting;return e.createElement(e.Fragment,null,e.createElement(a.Body,null,e.createElement(k,{className:"flex w-full flex-col space-y-4",noValidate:!0},e.createElement(N,{required:!0,autoFocus:!0,name:"name",label:"".concat(d("tag")," ").concat(d("name")),"data-cy":"tag-name-text-field",maxLength:50}),e.createElement(P,{name:"description",label:d("description"),rows:3,"data-cy":"tag-description-text-area",maxLength:255}))),e.createElement(a.Footer,{className:"flex items-center space-x-2"},e.createElement(_,{className:"flex items-center space-x-2",cancelButtonProps:{onClick:c},submitButtonProps:{loading:n}})))})))},Z=function(t){var n=t.tagTypes,r=t.showMenu,o=t.tagType,a=t.setTagType,i=S().t;return e.createElement(w,{showMenu:r,title:i("title")},Object.values(n).map((function(t){return e.createElement(w.Item,{key:t.id,label:t.label,description:t.description,active:o.id===t.id,onClick:function(){a(t)}})})))},ee=function(t,n,r){return[].concat(F(t),[{id:"actions",width:"10%",render:function(t,o){return e.createElement(c,{icon:v,buttonProps:{style:"text"},position:"bottom-end",autoWidth:!0,strategy:"fixed"},e.createElement("li",{className:"neeto-tag-dropdown__item"},e.createElement(u,{onClick:function(){return n(o)},label:"Edit",style:"text",className:"neeto-tag-dropdown__button"})),e.createElement("li",{className:"neeto-tag-dropdown__item"},e.createElement(u,{label:"Delete",onClick:function(){return r(o)},style:"danger-text",className:"neeto-tag-dropdown__button","data-cy":"tags-delete-button"})))}}])};var te=function(e){var o=e.tagTypes,a=I(t(o[0]),2),i=a[0],c=a[1],u=I(t([]),2),l=u[0],s=u[1],f=I(t(0),2),d=f[0],m=f[1],g=I(t(null),2),y=g[0],v=g[1],b=I(t(""),2),w=b[0],E=b[1],T=I(t(1),2),x=T[0],L=T[1],k=I(t(!0),2),N=k[0],P=k[1],_=I(t(null),2),C=_[0],A=_[1],F=I(t(!1),2),D=F[0],M=F[1],B=function(e,r){var o=I(t(e),2),a=o[0],i=o[1];return n((function(){var t=setTimeout((function(){return i(e)}),r||500);return function(){clearTimeout(t)}}),[e,r]),a}(w,500),G=S().t,X=function(e,t,n,r){return p(["tag-key",e,t,n,r],j(O().mark((function o(){return O().wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,H(e,t,n,r);case 2:return o.abrupt("return",o.sent);case 3:case"end":return o.stop()}}),o)}))),{staleTime:32e5,keepPreviousData:!0})}(i.url,B,10,x),R=X.data,z=X.isSuccess,U=X.isPreviousdata,J=X.isLoading,V=h((function(e){var t=e.url,n=e.id;return Y(t,n)}),{onSuccess:function(){q.invalidateQueries(["tag-key"])}}),K=V.mutate,W=V.isLoading;return n((function(){if(z){var e=R.tags,t=R.total_count;m(t),s(e)}}),[z,R]),n((function(){v(null),L(1)}),[i]),{tags:l,tagsCount:d,tagType:i,isLoading:J,isPreviousdata:U,setTagType:c,selectedTag:y,setSelectedTag:v,searchTerm:w,setSearchTerm:E,pageIndex:x,setPageIndex:L,goToFirstPage:function(){1!==x&&L(1)},handleEdit:function(e){v(e),A(Q)},handleDelete:function(e){v(e),M(!0)},handleAlertClose:function(){M(!1),v(null)},isMenuOpen:N,setIsMenuOpen:P,paneType:C,setPaneType:A,isDeleteAlertOpen:D,handleConfirmDelete:function(){var e={url:i.url,id:null==y?void 0:y.id};K(e,{onSuccess:function(){M(!1),1===l.length&&L((function(e){return e-1})),r.success(G("deleteSuccess"))},onError:function(e){var t=e.errors;r.error(null==t?void 0:t.join(", "))}})},isDeleting:W}},ne=function(t){var n=t.tagTypes,r=t.breadcrumbs,o=t.displayMenu,a=te({tagTypes:n}),c=a.tagType,d=a.setTagType,m=a.tags,p=a.tagsCount,h=a.isLoading,g=a.selectedTag,y=a.setSelectedTag,v=a.searchTerm,w=a.setSearchTerm,L=a.pageIndex,k=a.setPageIndex,N=a.goToFirstPage,P=a.handleEdit,_=a.handleDelete,C=a.handleAlertClose,O=a.isMenuOpen,A=a.setIsMenuOpen,j=a.paneType,I=a.setPaneType,D=a.isDeleteAlertOpen,M=a.handleConfirmDelete,B=S().t;return e.createElement(e.Fragment,null,e.createElement("div",{className:"neeto-tag-wrapper"},o&&e.createElement(Z,{tagTypes:n,showMenu:O,tagType:c,setTagType:d}),e.createElement(E,null,e.createElement(T,{title:"".concat(c.label," ").concat(B("title")),menuBarToggle:o?function(){return A((function(e){return!e}))}:null,searchProps:{value:v,onChange:function(e){var t=e.target.value;t.trim()&&N(),w(t)},placeholder:B("search",{where:B("title")})},actionBlock:e.createElement(u,{icon:b,size:"large",label:B("addNew",{what:B("tag")}),onClick:function(){y(null),I(z)},"data-cy":"add-new-tag-button"}),breadcrumbs:r}),h?e.createElement(l,null):e.createElement("div",{className:"w-full flex-grow"},e.createElement(x,{leftActionBlock:e.createElement(i,{component:"h4",className:"neeto-ui-gray-800 font-semibold"},"".concat(p," ").concat(c.label," Tag(s)"))}),e.createElement("div",{className:"neeto-tags--table__wrapper"},e.createElement(s,{fixedHeight:!0,rowData:m,columnData:ee(c.columns?[].concat(F(X),F(c.columns)):X,P,_),defaultPageSize:10,currentPageNumber:L,handlePageChange:k,totalCount:p,allowRowClick:!1,rowSelection:!1,paginationProps:{showSizeChanger:!1},scroll:{x:"100%"}}))))),e.createElement($,{type:j,tagType:c,tag:g,onClose:function(){return I(null)},goToFirstPage:N}),e.createElement(f,{isOpen:D,title:"".concat(B("delete")," ").concat(null==g?void 0:g.name),message:e.createElement(e.Fragment,null,B("deleteItem",{type:B("tag")})," ",e.createElement("strong",null,null==g?void 0:g.name),"? ",B("cannotBeUndone")),onSubmit:M,onClose:C,submitButtonLabel:B("proceed"),cancelButtonLabel:B("cancel")}))},re=function(r){var o=r.tagTypes,a=r.breadcrumbs,i=r.displayMenu,c=void 0===i||i,u=I(t(!0),2),s=u[0],f=u[1];return n((function(){!function(){var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:function(){return null};y.defaults.headers={Accept:"application/json","Content-Type":"application/json","X-CSRF-TOKEN":null===(e=document.querySelector('[name="csrf-token"]'))||void 0===e?void 0:e.getAttribute("content")};var n=JSON.parse(localStorage.getItem("authToken")),r=JSON.parse(localStorage.getItem("authEmail"));n&&r&&(y.defaults.headers["X-Auth-Email"]=r,y.defaults.headers["X-Auth-Token"]=n),t(!1)}(f),y.interceptors.response.use(B,G)}),[]),s?e.createElement(l,null):e.createElement(g,{client:q},e.createElement(ne,{tagTypes:o,breadcrumbs:a,displayMenu:c}))};export{re as NeetoTags};
1
+ import './main.css';
2
+
3
+ import React, { createContext, useContext, useState, useRef, useEffect } from 'react';
4
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
5
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
6
+ import { MenuHorizontal, Plus } from '@bigbinary/neeto-icons';
7
+ import { Tag, Toastr, Pane, Typography, Dropdown, Button, PageLoader, Table, Alert } from '@bigbinary/neetoui';
8
+ import { MenuBar, Container, Header, SubHeader } from '@bigbinary/neetoui/layouts';
9
+ import '@babel/runtime/helpers/objectWithoutProperties';
10
+ import '@babel/runtime/helpers/typeof';
11
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
12
+ import _classCallCheck from '@babel/runtime/helpers/classCallCheck';
13
+ import _createClass from '@babel/runtime/helpers/createClass';
14
+ import { Input, Textarea, ActionBlock } from '@bigbinary/neetoui/formik';
15
+ import { Formik, Form } from 'formik';
16
+ import * as yup from 'yup';
17
+ import _inheritsLoose from '@babel/runtime/helpers/esm/inheritsLoose';
18
+ import _extends from '@babel/runtime/helpers/esm/extends';
19
+ import ReactDOM from 'react-dom';
20
+ import axios from 'axios';
21
+
22
+ var matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
23
+ var htmlEntities = {
24
+ '&amp;': '&',
25
+ '&#38;': '&',
26
+ '&lt;': '<',
27
+ '&#60;': '<',
28
+ '&gt;': '>',
29
+ '&#62;': '>',
30
+ '&apos;': "'",
31
+ '&#39;': "'",
32
+ '&quot;': '"',
33
+ '&#34;': '"'
34
+ };
35
+
36
+ var unescapeHtmlEntity = function unescapeHtmlEntity(m) {
37
+ return htmlEntities[m];
38
+ };
39
+
40
+ var unescape = function unescape(text) {
41
+ return text.replace(matchHtmlEntity, unescapeHtmlEntity);
42
+ };
43
+
44
+ var defaultOptions = {
45
+ bindI18n: 'languageChanged',
46
+ bindI18nStore: '',
47
+ transEmptyNodeValue: '',
48
+ transSupportBasicHtmlNodes: true,
49
+ transWrapTextNodes: '',
50
+ transKeepBasicHtmlNodesFor: ['br', 'strong', 'i', 'p'],
51
+ useSuspense: true,
52
+ unescape: unescape
53
+ };
54
+ var i18nInstance;
55
+ var I18nContext = createContext();
56
+ function getDefaults() {
57
+ return defaultOptions;
58
+ }
59
+ var ReportNamespaces = function () {
60
+ function ReportNamespaces() {
61
+ _classCallCheck(this, ReportNamespaces);
62
+
63
+ this.usedNamespaces = {};
64
+ }
65
+
66
+ _createClass(ReportNamespaces, [{
67
+ key: "addUsedNamespaces",
68
+ value: function addUsedNamespaces(namespaces) {
69
+ var _this = this;
70
+
71
+ namespaces.forEach(function (ns) {
72
+ if (!_this.usedNamespaces[ns]) _this.usedNamespaces[ns] = true;
73
+ });
74
+ }
75
+ }, {
76
+ key: "getUsedNamespaces",
77
+ value: function getUsedNamespaces() {
78
+ return Object.keys(this.usedNamespaces);
79
+ }
80
+ }]);
81
+
82
+ return ReportNamespaces;
83
+ }();
84
+ function getI18n() {
85
+ return i18nInstance;
86
+ }
87
+
88
+ function warn() {
89
+ if (console && console.warn) {
90
+ var _console;
91
+
92
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
93
+ args[_key] = arguments[_key];
94
+ }
95
+
96
+ if (typeof args[0] === 'string') args[0] = "react-i18next:: ".concat(args[0]);
97
+
98
+ (_console = console).warn.apply(_console, args);
99
+ }
100
+ }
101
+ var alreadyWarned = {};
102
+ function warnOnce() {
103
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
104
+ args[_key2] = arguments[_key2];
105
+ }
106
+
107
+ if (typeof args[0] === 'string' && alreadyWarned[args[0]]) return;
108
+ if (typeof args[0] === 'string') alreadyWarned[args[0]] = new Date();
109
+ warn.apply(void 0, args);
110
+ }
111
+ function loadNamespaces(i18n, ns, cb) {
112
+ i18n.loadNamespaces(ns, function () {
113
+ if (i18n.isInitialized) {
114
+ cb();
115
+ } else {
116
+ var initialized = function initialized() {
117
+ setTimeout(function () {
118
+ i18n.off('initialized', initialized);
119
+ }, 0);
120
+ cb();
121
+ };
122
+
123
+ i18n.on('initialized', initialized);
124
+ }
125
+ });
126
+ }
127
+
128
+ function oldI18nextHasLoadedNamespace(ns, i18n) {
129
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
130
+ var lng = i18n.languages[0];
131
+ var fallbackLng = i18n.options ? i18n.options.fallbackLng : false;
132
+ var lastLng = i18n.languages[i18n.languages.length - 1];
133
+ if (lng.toLowerCase() === 'cimode') return true;
134
+
135
+ var loadNotPending = function loadNotPending(l, n) {
136
+ var loadState = i18n.services.backendConnector.state["".concat(l, "|").concat(n)];
137
+ return loadState === -1 || loadState === 2;
138
+ };
139
+
140
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18n.services.backendConnector.backend && i18n.isLanguageChangingTo && !loadNotPending(i18n.isLanguageChangingTo, ns)) return false;
141
+ if (i18n.hasResourceBundle(lng, ns)) return true;
142
+ if (!i18n.services.backendConnector.backend || i18n.options.resources && !i18n.options.partialBundledLanguages) return true;
143
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
144
+ return false;
145
+ }
146
+
147
+ function hasLoadedNamespace(ns, i18n) {
148
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
149
+
150
+ if (!i18n.languages || !i18n.languages.length) {
151
+ warnOnce('i18n.languages were undefined or empty', i18n.languages);
152
+ return true;
153
+ }
154
+
155
+ var isNewerI18next = i18n.options.ignoreJSONStructure !== undefined;
156
+
157
+ if (!isNewerI18next) {
158
+ return oldI18nextHasLoadedNamespace(ns, i18n, options);
159
+ }
160
+
161
+ return i18n.hasLoadedNamespace(ns, {
162
+ precheck: function precheck(i18nInstance, loadNotPending) {
163
+ if (options.bindI18n && options.bindI18n.indexOf('languageChanging') > -1 && i18nInstance.services.backendConnector.backend && i18nInstance.isLanguageChangingTo && !loadNotPending(i18nInstance.isLanguageChangingTo, ns)) return false;
164
+ }
165
+ });
166
+ }
167
+
168
+ function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
169
+
170
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys$1(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys$1(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
171
+
172
+ var usePrevious = function usePrevious(value, ignore) {
173
+ var ref = useRef();
174
+ useEffect(function () {
175
+ ref.current = ignore ? ref.current : value;
176
+ }, [value, ignore]);
177
+ return ref.current;
178
+ };
179
+
180
+ function useTranslation(ns) {
181
+ var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
182
+ var i18nFromProps = props.i18n;
183
+
184
+ var _ref = useContext(I18nContext) || {},
185
+ i18nFromContext = _ref.i18n,
186
+ defaultNSFromContext = _ref.defaultNS;
187
+
188
+ var i18n = i18nFromProps || i18nFromContext || getI18n();
189
+ if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
190
+
191
+ if (!i18n) {
192
+ warnOnce('You will need to pass in an i18next instance by using initReactI18next');
193
+
194
+ var notReadyT = function notReadyT(k) {
195
+ return Array.isArray(k) ? k[k.length - 1] : k;
196
+ };
197
+
198
+ var retNotReady = [notReadyT, {}, false];
199
+ retNotReady.t = notReadyT;
200
+ retNotReady.i18n = {};
201
+ retNotReady.ready = false;
202
+ return retNotReady;
203
+ }
204
+
205
+ if (i18n.options.react && i18n.options.react.wait !== undefined) warnOnce('It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.');
206
+
207
+ var i18nOptions = _objectSpread$1(_objectSpread$1(_objectSpread$1({}, getDefaults()), i18n.options.react), props);
208
+
209
+ var useSuspense = i18nOptions.useSuspense,
210
+ keyPrefix = i18nOptions.keyPrefix;
211
+ var namespaces = ns || defaultNSFromContext || i18n.options && i18n.options.defaultNS;
212
+ namespaces = typeof namespaces === 'string' ? [namespaces] : namespaces || ['translation'];
213
+ if (i18n.reportNamespaces.addUsedNamespaces) i18n.reportNamespaces.addUsedNamespaces(namespaces);
214
+ var ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every(function (n) {
215
+ return hasLoadedNamespace(n, i18n, i18nOptions);
216
+ });
217
+
218
+ function getT() {
219
+ return i18n.getFixedT(null, i18nOptions.nsMode === 'fallback' ? namespaces : namespaces[0], keyPrefix);
220
+ }
221
+
222
+ var _useState = useState(getT),
223
+ _useState2 = _slicedToArray(_useState, 2),
224
+ t = _useState2[0],
225
+ setT = _useState2[1];
226
+
227
+ var joinedNS = namespaces.join();
228
+ var previousJoinedNS = usePrevious(joinedNS);
229
+ var isMounted = useRef(true);
230
+ useEffect(function () {
231
+ var bindI18n = i18nOptions.bindI18n,
232
+ bindI18nStore = i18nOptions.bindI18nStore;
233
+ isMounted.current = true;
234
+
235
+ if (!ready && !useSuspense) {
236
+ loadNamespaces(i18n, namespaces, function () {
237
+ if (isMounted.current) setT(getT);
238
+ });
239
+ }
240
+
241
+ if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
242
+ setT(getT);
243
+ }
244
+
245
+ function boundReset() {
246
+ if (isMounted.current) setT(getT);
247
+ }
248
+
249
+ if (bindI18n && i18n) i18n.on(bindI18n, boundReset);
250
+ if (bindI18nStore && i18n) i18n.store.on(bindI18nStore, boundReset);
251
+ return function () {
252
+ isMounted.current = false;
253
+ if (bindI18n && i18n) bindI18n.split(' ').forEach(function (e) {
254
+ return i18n.off(e, boundReset);
255
+ });
256
+ if (bindI18nStore && i18n) bindI18nStore.split(' ').forEach(function (e) {
257
+ return i18n.store.off(e, boundReset);
258
+ });
259
+ };
260
+ }, [i18n, joinedNS]);
261
+ var isInitial = useRef(true);
262
+ useEffect(function () {
263
+ if (isMounted.current && !isInitial.current) {
264
+ setT(getT);
265
+ }
266
+
267
+ isInitial.current = false;
268
+ }, [i18n]);
269
+ var ret = [t, i18n, ready];
270
+ ret.t = t;
271
+ ret.i18n = i18n;
272
+ ret.ready = ready;
273
+ if (ready) return ret;
274
+ if (!ready && !useSuspense) return ret;
275
+ throw new Promise(function (resolve) {
276
+ loadNamespaces(i18n, namespaces, function () {
277
+ resolve();
278
+ });
279
+ });
280
+ }
281
+
282
+ var DEFAULT_PAGE_INDEX = 1;
283
+ var DEFAULT_PAGE_SIZE = 10;
284
+ var COMMON_COLUMNS = [{
285
+ title: "Name",
286
+ dataIndex: "name",
287
+ key: "name",
288
+ render: function render(name) {
289
+ return /*#__PURE__*/React.createElement(Tag, {
290
+ label: name,
291
+ color: "blue"
292
+ });
293
+ },
294
+ width: "30%"
295
+ }, {
296
+ title: "Description",
297
+ dataIndex: "description",
298
+ key: "description",
299
+ render: function render(description) {
300
+ return description || "--";
301
+ },
302
+ width: "40%"
303
+ }];
304
+ var TAG_SCHEMA = yup.object({
305
+ name: yup.string().typeError("Name must be a string.").required("Name is a required field.").max(50, "Name should not exceed 50 characters."),
306
+ description: yup.string().typeError("Description must be a string.").nullable().max(255, "Description should not exceed 255 characters.")
307
+ });
308
+ var PANE_TYPES = {
309
+ CREATE: "CREATE_TAG",
310
+ EDIT: "EDIT_TAG"
311
+ };
312
+ var INITIAL_TAG_VALUES = {
313
+ name: "",
314
+ description: ""
315
+ };
316
+
317
+ var Subscribable = /*#__PURE__*/function () {
318
+ function Subscribable() {
319
+ this.listeners = [];
320
+ }
321
+
322
+ var _proto = Subscribable.prototype;
323
+
324
+ _proto.subscribe = function subscribe(listener) {
325
+ var _this = this;
326
+
327
+ var callback = listener || function () {
328
+ return undefined;
329
+ };
330
+
331
+ this.listeners.push(callback);
332
+ this.onSubscribe();
333
+ return function () {
334
+ _this.listeners = _this.listeners.filter(function (x) {
335
+ return x !== callback;
336
+ });
337
+
338
+ _this.onUnsubscribe();
339
+ };
340
+ };
341
+
342
+ _proto.hasListeners = function hasListeners() {
343
+ return this.listeners.length > 0;
344
+ };
345
+
346
+ _proto.onSubscribe = function onSubscribe() {// Do nothing
347
+ };
348
+
349
+ _proto.onUnsubscribe = function onUnsubscribe() {// Do nothing
350
+ };
351
+
352
+ return Subscribable;
353
+ }();
354
+
355
+ // TYPES
356
+ // UTILS
357
+ var isServer = typeof window === 'undefined';
358
+ function noop() {
359
+ return undefined;
360
+ }
361
+ function functionalUpdate(updater, input) {
362
+ return typeof updater === 'function' ? updater(input) : updater;
363
+ }
364
+ function isValidTimeout(value) {
365
+ return typeof value === 'number' && value >= 0 && value !== Infinity;
366
+ }
367
+ function ensureQueryKeyArray(value) {
368
+ return Array.isArray(value) ? value : [value];
369
+ }
370
+ function timeUntilStale(updatedAt, staleTime) {
371
+ return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
372
+ }
373
+ function parseQueryArgs(arg1, arg2, arg3) {
374
+ if (!isQueryKey(arg1)) {
375
+ return arg1;
376
+ }
377
+
378
+ if (typeof arg2 === 'function') {
379
+ return _extends({}, arg3, {
380
+ queryKey: arg1,
381
+ queryFn: arg2
382
+ });
383
+ }
384
+
385
+ return _extends({}, arg2, {
386
+ queryKey: arg1
387
+ });
388
+ }
389
+ function parseMutationArgs(arg1, arg2, arg3) {
390
+ if (isQueryKey(arg1)) {
391
+ if (typeof arg2 === 'function') {
392
+ return _extends({}, arg3, {
393
+ mutationKey: arg1,
394
+ mutationFn: arg2
395
+ });
396
+ }
397
+
398
+ return _extends({}, arg2, {
399
+ mutationKey: arg1
400
+ });
401
+ }
402
+
403
+ if (typeof arg1 === 'function') {
404
+ return _extends({}, arg2, {
405
+ mutationFn: arg1
406
+ });
407
+ }
408
+
409
+ return _extends({}, arg1);
410
+ }
411
+ function parseFilterArgs(arg1, arg2, arg3) {
412
+ return isQueryKey(arg1) ? [_extends({}, arg2, {
413
+ queryKey: arg1
414
+ }), arg3] : [arg1 || {}, arg2];
415
+ }
416
+ function mapQueryStatusFilter(active, inactive) {
417
+ if (active === true && inactive === true || active == null && inactive == null) {
418
+ return 'all';
419
+ } else if (active === false && inactive === false) {
420
+ return 'none';
421
+ } else {
422
+ // At this point, active|inactive can only be true|false or false|true
423
+ // so, when only one value is provided, the missing one has to be the negated value
424
+ var isActive = active != null ? active : !inactive;
425
+ return isActive ? 'active' : 'inactive';
426
+ }
427
+ }
428
+ function matchQuery(filters, query) {
429
+ var active = filters.active,
430
+ exact = filters.exact,
431
+ fetching = filters.fetching,
432
+ inactive = filters.inactive,
433
+ predicate = filters.predicate,
434
+ queryKey = filters.queryKey,
435
+ stale = filters.stale;
436
+
437
+ if (isQueryKey(queryKey)) {
438
+ if (exact) {
439
+ if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
440
+ return false;
441
+ }
442
+ } else if (!partialMatchKey(query.queryKey, queryKey)) {
443
+ return false;
444
+ }
445
+ }
446
+
447
+ var queryStatusFilter = mapQueryStatusFilter(active, inactive);
448
+
449
+ if (queryStatusFilter === 'none') {
450
+ return false;
451
+ } else if (queryStatusFilter !== 'all') {
452
+ var isActive = query.isActive();
453
+
454
+ if (queryStatusFilter === 'active' && !isActive) {
455
+ return false;
456
+ }
457
+
458
+ if (queryStatusFilter === 'inactive' && isActive) {
459
+ return false;
460
+ }
461
+ }
462
+
463
+ if (typeof stale === 'boolean' && query.isStale() !== stale) {
464
+ return false;
465
+ }
466
+
467
+ if (typeof fetching === 'boolean' && query.isFetching() !== fetching) {
468
+ return false;
469
+ }
470
+
471
+ if (predicate && !predicate(query)) {
472
+ return false;
473
+ }
474
+
475
+ return true;
476
+ }
477
+ function matchMutation(filters, mutation) {
478
+ var exact = filters.exact,
479
+ fetching = filters.fetching,
480
+ predicate = filters.predicate,
481
+ mutationKey = filters.mutationKey;
482
+
483
+ if (isQueryKey(mutationKey)) {
484
+ if (!mutation.options.mutationKey) {
485
+ return false;
486
+ }
487
+
488
+ if (exact) {
489
+ if (hashQueryKey(mutation.options.mutationKey) !== hashQueryKey(mutationKey)) {
490
+ return false;
491
+ }
492
+ } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
493
+ return false;
494
+ }
495
+ }
496
+
497
+ if (typeof fetching === 'boolean' && mutation.state.status === 'loading' !== fetching) {
498
+ return false;
499
+ }
500
+
501
+ if (predicate && !predicate(mutation)) {
502
+ return false;
503
+ }
504
+
505
+ return true;
506
+ }
507
+ function hashQueryKeyByOptions(queryKey, options) {
508
+ var hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashQueryKey;
509
+ return hashFn(queryKey);
510
+ }
511
+ /**
512
+ * Default query keys hash function.
513
+ */
514
+
515
+ function hashQueryKey(queryKey) {
516
+ var asArray = ensureQueryKeyArray(queryKey);
517
+ return stableValueHash(asArray);
518
+ }
519
+ /**
520
+ * Hashes the value into a stable hash.
521
+ */
522
+
523
+ function stableValueHash(value) {
524
+ return JSON.stringify(value, function (_, val) {
525
+ return isPlainObject(val) ? Object.keys(val).sort().reduce(function (result, key) {
526
+ result[key] = val[key];
527
+ return result;
528
+ }, {}) : val;
529
+ });
530
+ }
531
+ /**
532
+ * Checks if key `b` partially matches with key `a`.
533
+ */
534
+
535
+ function partialMatchKey(a, b) {
536
+ return partialDeepEqual(ensureQueryKeyArray(a), ensureQueryKeyArray(b));
537
+ }
538
+ /**
539
+ * Checks if `b` partially matches with `a`.
540
+ */
541
+
542
+ function partialDeepEqual(a, b) {
543
+ if (a === b) {
544
+ return true;
545
+ }
546
+
547
+ if (typeof a !== typeof b) {
548
+ return false;
549
+ }
550
+
551
+ if (a && b && typeof a === 'object' && typeof b === 'object') {
552
+ return !Object.keys(b).some(function (key) {
553
+ return !partialDeepEqual(a[key], b[key]);
554
+ });
555
+ }
556
+
557
+ return false;
558
+ }
559
+ /**
560
+ * This function returns `a` if `b` is deeply equal.
561
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
562
+ * This can be used for structural sharing between JSON values for example.
563
+ */
564
+
565
+ function replaceEqualDeep(a, b) {
566
+ if (a === b) {
567
+ return a;
568
+ }
569
+
570
+ var array = Array.isArray(a) && Array.isArray(b);
571
+
572
+ if (array || isPlainObject(a) && isPlainObject(b)) {
573
+ var aSize = array ? a.length : Object.keys(a).length;
574
+ var bItems = array ? b : Object.keys(b);
575
+ var bSize = bItems.length;
576
+ var copy = array ? [] : {};
577
+ var equalItems = 0;
578
+
579
+ for (var i = 0; i < bSize; i++) {
580
+ var key = array ? i : bItems[i];
581
+ copy[key] = replaceEqualDeep(a[key], b[key]);
582
+
583
+ if (copy[key] === a[key]) {
584
+ equalItems++;
585
+ }
586
+ }
587
+
588
+ return aSize === bSize && equalItems === aSize ? a : copy;
589
+ }
590
+
591
+ return b;
592
+ }
593
+ /**
594
+ * Shallow compare objects. Only works with objects that always have the same properties.
595
+ */
596
+
597
+ function shallowEqualObjects(a, b) {
598
+ if (a && !b || b && !a) {
599
+ return false;
600
+ }
601
+
602
+ for (var key in a) {
603
+ if (a[key] !== b[key]) {
604
+ return false;
605
+ }
606
+ }
607
+
608
+ return true;
609
+ } // Copied from: https://github.com/jonschlinkert/is-plain-object
610
+
611
+ function isPlainObject(o) {
612
+ if (!hasObjectPrototype(o)) {
613
+ return false;
614
+ } // If has modified constructor
615
+
616
+
617
+ var ctor = o.constructor;
618
+
619
+ if (typeof ctor === 'undefined') {
620
+ return true;
621
+ } // If has modified prototype
622
+
623
+
624
+ var prot = ctor.prototype;
625
+
626
+ if (!hasObjectPrototype(prot)) {
627
+ return false;
628
+ } // If constructor does not have an Object-specific method
629
+
630
+
631
+ if (!prot.hasOwnProperty('isPrototypeOf')) {
632
+ return false;
633
+ } // Most likely a plain Object
634
+
635
+
636
+ return true;
637
+ }
638
+
639
+ function hasObjectPrototype(o) {
640
+ return Object.prototype.toString.call(o) === '[object Object]';
641
+ }
642
+
643
+ function isQueryKey(value) {
644
+ return typeof value === 'string' || Array.isArray(value);
645
+ }
646
+ function sleep(timeout) {
647
+ return new Promise(function (resolve) {
648
+ setTimeout(resolve, timeout);
649
+ });
650
+ }
651
+ /**
652
+ * Schedules a microtask.
653
+ * This can be useful to schedule state updates after rendering.
654
+ */
655
+
656
+ function scheduleMicrotask(callback) {
657
+ Promise.resolve().then(callback).catch(function (error) {
658
+ return setTimeout(function () {
659
+ throw error;
660
+ });
661
+ });
662
+ }
663
+ function getAbortController() {
664
+ if (typeof AbortController === 'function') {
665
+ return new AbortController();
666
+ }
667
+ }
668
+
669
+ var FocusManager = /*#__PURE__*/function (_Subscribable) {
670
+ _inheritsLoose(FocusManager, _Subscribable);
671
+
672
+ function FocusManager() {
673
+ var _this;
674
+
675
+ _this = _Subscribable.call(this) || this;
676
+
677
+ _this.setup = function (onFocus) {
678
+ var _window;
679
+
680
+ if (!isServer && ((_window = window) == null ? void 0 : _window.addEventListener)) {
681
+ var listener = function listener() {
682
+ return onFocus();
683
+ }; // Listen to visibillitychange and focus
684
+
685
+
686
+ window.addEventListener('visibilitychange', listener, false);
687
+ window.addEventListener('focus', listener, false);
688
+ return function () {
689
+ // Be sure to unsubscribe if a new handler is set
690
+ window.removeEventListener('visibilitychange', listener);
691
+ window.removeEventListener('focus', listener);
692
+ };
693
+ }
694
+ };
695
+
696
+ return _this;
697
+ }
698
+
699
+ var _proto = FocusManager.prototype;
700
+
701
+ _proto.onSubscribe = function onSubscribe() {
702
+ if (!this.cleanup) {
703
+ this.setEventListener(this.setup);
704
+ }
705
+ };
706
+
707
+ _proto.onUnsubscribe = function onUnsubscribe() {
708
+ if (!this.hasListeners()) {
709
+ var _this$cleanup;
710
+
711
+ (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
712
+ this.cleanup = undefined;
713
+ }
714
+ };
715
+
716
+ _proto.setEventListener = function setEventListener(setup) {
717
+ var _this$cleanup2,
718
+ _this2 = this;
719
+
720
+ this.setup = setup;
721
+ (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
722
+ this.cleanup = setup(function (focused) {
723
+ if (typeof focused === 'boolean') {
724
+ _this2.setFocused(focused);
725
+ } else {
726
+ _this2.onFocus();
727
+ }
728
+ });
729
+ };
730
+
731
+ _proto.setFocused = function setFocused(focused) {
732
+ this.focused = focused;
733
+
734
+ if (focused) {
735
+ this.onFocus();
736
+ }
737
+ };
738
+
739
+ _proto.onFocus = function onFocus() {
740
+ this.listeners.forEach(function (listener) {
741
+ listener();
742
+ });
743
+ };
744
+
745
+ _proto.isFocused = function isFocused() {
746
+ if (typeof this.focused === 'boolean') {
747
+ return this.focused;
748
+ } // document global can be unavailable in react native
749
+
750
+
751
+ if (typeof document === 'undefined') {
752
+ return true;
753
+ }
754
+
755
+ return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
756
+ };
757
+
758
+ return FocusManager;
759
+ }(Subscribable);
760
+ var focusManager = new FocusManager();
761
+
762
+ var OnlineManager = /*#__PURE__*/function (_Subscribable) {
763
+ _inheritsLoose(OnlineManager, _Subscribable);
764
+
765
+ function OnlineManager() {
766
+ var _this;
767
+
768
+ _this = _Subscribable.call(this) || this;
769
+
770
+ _this.setup = function (onOnline) {
771
+ var _window;
772
+
773
+ if (!isServer && ((_window = window) == null ? void 0 : _window.addEventListener)) {
774
+ var listener = function listener() {
775
+ return onOnline();
776
+ }; // Listen to online
777
+
778
+
779
+ window.addEventListener('online', listener, false);
780
+ window.addEventListener('offline', listener, false);
781
+ return function () {
782
+ // Be sure to unsubscribe if a new handler is set
783
+ window.removeEventListener('online', listener);
784
+ window.removeEventListener('offline', listener);
785
+ };
786
+ }
787
+ };
788
+
789
+ return _this;
790
+ }
791
+
792
+ var _proto = OnlineManager.prototype;
793
+
794
+ _proto.onSubscribe = function onSubscribe() {
795
+ if (!this.cleanup) {
796
+ this.setEventListener(this.setup);
797
+ }
798
+ };
799
+
800
+ _proto.onUnsubscribe = function onUnsubscribe() {
801
+ if (!this.hasListeners()) {
802
+ var _this$cleanup;
803
+
804
+ (_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
805
+ this.cleanup = undefined;
806
+ }
807
+ };
808
+
809
+ _proto.setEventListener = function setEventListener(setup) {
810
+ var _this$cleanup2,
811
+ _this2 = this;
812
+
813
+ this.setup = setup;
814
+ (_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
815
+ this.cleanup = setup(function (online) {
816
+ if (typeof online === 'boolean') {
817
+ _this2.setOnline(online);
818
+ } else {
819
+ _this2.onOnline();
820
+ }
821
+ });
822
+ };
823
+
824
+ _proto.setOnline = function setOnline(online) {
825
+ this.online = online;
826
+
827
+ if (online) {
828
+ this.onOnline();
829
+ }
830
+ };
831
+
832
+ _proto.onOnline = function onOnline() {
833
+ this.listeners.forEach(function (listener) {
834
+ listener();
835
+ });
836
+ };
837
+
838
+ _proto.isOnline = function isOnline() {
839
+ if (typeof this.online === 'boolean') {
840
+ return this.online;
841
+ }
842
+
843
+ if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
844
+ return true;
845
+ }
846
+
847
+ return navigator.onLine;
848
+ };
849
+
850
+ return OnlineManager;
851
+ }(Subscribable);
852
+ var onlineManager = new OnlineManager();
853
+
854
+ function defaultRetryDelay(failureCount) {
855
+ return Math.min(1000 * Math.pow(2, failureCount), 30000);
856
+ }
857
+
858
+ function isCancelable(value) {
859
+ return typeof (value == null ? void 0 : value.cancel) === 'function';
860
+ }
861
+ var CancelledError = function CancelledError(options) {
862
+ this.revert = options == null ? void 0 : options.revert;
863
+ this.silent = options == null ? void 0 : options.silent;
864
+ };
865
+ function isCancelledError(value) {
866
+ return value instanceof CancelledError;
867
+ } // CLASS
868
+
869
+ var Retryer = function Retryer(config) {
870
+ var _this = this;
871
+
872
+ var cancelRetry = false;
873
+ var cancelFn;
874
+ var continueFn;
875
+ var promiseResolve;
876
+ var promiseReject;
877
+ this.abort = config.abort;
878
+
879
+ this.cancel = function (cancelOptions) {
880
+ return cancelFn == null ? void 0 : cancelFn(cancelOptions);
881
+ };
882
+
883
+ this.cancelRetry = function () {
884
+ cancelRetry = true;
885
+ };
886
+
887
+ this.continueRetry = function () {
888
+ cancelRetry = false;
889
+ };
890
+
891
+ this.continue = function () {
892
+ return continueFn == null ? void 0 : continueFn();
893
+ };
894
+
895
+ this.failureCount = 0;
896
+ this.isPaused = false;
897
+ this.isResolved = false;
898
+ this.isTransportCancelable = false;
899
+ this.promise = new Promise(function (outerResolve, outerReject) {
900
+ promiseResolve = outerResolve;
901
+ promiseReject = outerReject;
902
+ });
903
+
904
+ var resolve = function resolve(value) {
905
+ if (!_this.isResolved) {
906
+ _this.isResolved = true;
907
+ config.onSuccess == null ? void 0 : config.onSuccess(value);
908
+ continueFn == null ? void 0 : continueFn();
909
+ promiseResolve(value);
910
+ }
911
+ };
912
+
913
+ var reject = function reject(value) {
914
+ if (!_this.isResolved) {
915
+ _this.isResolved = true;
916
+ config.onError == null ? void 0 : config.onError(value);
917
+ continueFn == null ? void 0 : continueFn();
918
+ promiseReject(value);
919
+ }
920
+ };
921
+
922
+ var pause = function pause() {
923
+ return new Promise(function (continueResolve) {
924
+ continueFn = continueResolve;
925
+ _this.isPaused = true;
926
+ config.onPause == null ? void 0 : config.onPause();
927
+ }).then(function () {
928
+ continueFn = undefined;
929
+ _this.isPaused = false;
930
+ config.onContinue == null ? void 0 : config.onContinue();
931
+ });
932
+ }; // Create loop function
933
+
934
+
935
+ var run = function run() {
936
+ // Do nothing if already resolved
937
+ if (_this.isResolved) {
938
+ return;
939
+ }
940
+
941
+ var promiseOrValue; // Execute query
942
+
943
+ try {
944
+ promiseOrValue = config.fn();
945
+ } catch (error) {
946
+ promiseOrValue = Promise.reject(error);
947
+ } // Create callback to cancel this fetch
948
+
949
+
950
+ cancelFn = function cancelFn(cancelOptions) {
951
+ if (!_this.isResolved) {
952
+ reject(new CancelledError(cancelOptions));
953
+ _this.abort == null ? void 0 : _this.abort(); // Cancel transport if supported
954
+
955
+ if (isCancelable(promiseOrValue)) {
956
+ try {
957
+ promiseOrValue.cancel();
958
+ } catch (_unused) {}
959
+ }
960
+ }
961
+ }; // Check if the transport layer support cancellation
962
+
963
+
964
+ _this.isTransportCancelable = isCancelable(promiseOrValue);
965
+ Promise.resolve(promiseOrValue).then(resolve).catch(function (error) {
966
+ var _config$retry, _config$retryDelay;
967
+
968
+ // Stop if the fetch is already resolved
969
+ if (_this.isResolved) {
970
+ return;
971
+ } // Do we need to retry the request?
972
+
973
+
974
+ var retry = (_config$retry = config.retry) != null ? _config$retry : 3;
975
+ var retryDelay = (_config$retryDelay = config.retryDelay) != null ? _config$retryDelay : defaultRetryDelay;
976
+ var delay = typeof retryDelay === 'function' ? retryDelay(_this.failureCount, error) : retryDelay;
977
+ var shouldRetry = retry === true || typeof retry === 'number' && _this.failureCount < retry || typeof retry === 'function' && retry(_this.failureCount, error);
978
+
979
+ if (cancelRetry || !shouldRetry) {
980
+ // We are done if the query does not need to be retried
981
+ reject(error);
982
+ return;
983
+ }
984
+
985
+ _this.failureCount++; // Notify on fail
986
+
987
+ config.onFail == null ? void 0 : config.onFail(_this.failureCount, error); // Delay
988
+
989
+ sleep(delay) // Pause if the document is not visible or when the device is offline
990
+ .then(function () {
991
+ if (!focusManager.isFocused() || !onlineManager.isOnline()) {
992
+ return pause();
993
+ }
994
+ }).then(function () {
995
+ if (cancelRetry) {
996
+ reject(error);
997
+ } else {
998
+ run();
999
+ }
1000
+ });
1001
+ });
1002
+ }; // Start loop
1003
+
1004
+
1005
+ run();
1006
+ };
1007
+
1008
+ // CLASS
1009
+ var NotifyManager = /*#__PURE__*/function () {
1010
+ function NotifyManager() {
1011
+ this.queue = [];
1012
+ this.transactions = 0;
1013
+
1014
+ this.notifyFn = function (callback) {
1015
+ callback();
1016
+ };
1017
+
1018
+ this.batchNotifyFn = function (callback) {
1019
+ callback();
1020
+ };
1021
+ }
1022
+
1023
+ var _proto = NotifyManager.prototype;
1024
+
1025
+ _proto.batch = function batch(callback) {
1026
+ var result;
1027
+ this.transactions++;
1028
+
1029
+ try {
1030
+ result = callback();
1031
+ } finally {
1032
+ this.transactions--;
1033
+
1034
+ if (!this.transactions) {
1035
+ this.flush();
1036
+ }
1037
+ }
1038
+
1039
+ return result;
1040
+ };
1041
+
1042
+ _proto.schedule = function schedule(callback) {
1043
+ var _this = this;
1044
+
1045
+ if (this.transactions) {
1046
+ this.queue.push(callback);
1047
+ } else {
1048
+ scheduleMicrotask(function () {
1049
+ _this.notifyFn(callback);
1050
+ });
1051
+ }
1052
+ }
1053
+ /**
1054
+ * All calls to the wrapped function will be batched.
1055
+ */
1056
+ ;
1057
+
1058
+ _proto.batchCalls = function batchCalls(callback) {
1059
+ var _this2 = this;
1060
+
1061
+ return function () {
1062
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
1063
+ args[_key] = arguments[_key];
1064
+ }
1065
+
1066
+ _this2.schedule(function () {
1067
+ callback.apply(void 0, args);
1068
+ });
1069
+ };
1070
+ };
1071
+
1072
+ _proto.flush = function flush() {
1073
+ var _this3 = this;
1074
+
1075
+ var queue = this.queue;
1076
+ this.queue = [];
1077
+
1078
+ if (queue.length) {
1079
+ scheduleMicrotask(function () {
1080
+ _this3.batchNotifyFn(function () {
1081
+ queue.forEach(function (callback) {
1082
+ _this3.notifyFn(callback);
1083
+ });
1084
+ });
1085
+ });
1086
+ }
1087
+ }
1088
+ /**
1089
+ * Use this method to set a custom notify function.
1090
+ * This can be used to for example wrap notifications with `React.act` while running tests.
1091
+ */
1092
+ ;
1093
+
1094
+ _proto.setNotifyFunction = function setNotifyFunction(fn) {
1095
+ this.notifyFn = fn;
1096
+ }
1097
+ /**
1098
+ * Use this method to set a custom function to batch notifications together into a single tick.
1099
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
1100
+ */
1101
+ ;
1102
+
1103
+ _proto.setBatchNotifyFunction = function setBatchNotifyFunction(fn) {
1104
+ this.batchNotifyFn = fn;
1105
+ };
1106
+
1107
+ return NotifyManager;
1108
+ }(); // SINGLETON
1109
+
1110
+ var notifyManager = new NotifyManager();
1111
+
1112
+ // TYPES
1113
+ // FUNCTIONS
1114
+ var logger$1 = console;
1115
+ function getLogger() {
1116
+ return logger$1;
1117
+ }
1118
+ function setLogger(newLogger) {
1119
+ logger$1 = newLogger;
1120
+ }
1121
+
1122
+ // CLASS
1123
+ var Query = /*#__PURE__*/function () {
1124
+ function Query(config) {
1125
+ this.abortSignalConsumed = false;
1126
+ this.hadObservers = false;
1127
+ this.defaultOptions = config.defaultOptions;
1128
+ this.setOptions(config.options);
1129
+ this.observers = [];
1130
+ this.cache = config.cache;
1131
+ this.queryKey = config.queryKey;
1132
+ this.queryHash = config.queryHash;
1133
+ this.initialState = config.state || this.getDefaultState(this.options);
1134
+ this.state = this.initialState;
1135
+ this.meta = config.meta;
1136
+ this.scheduleGc();
1137
+ }
1138
+
1139
+ var _proto = Query.prototype;
1140
+
1141
+ _proto.setOptions = function setOptions(options) {
1142
+ var _this$options$cacheTi;
1143
+
1144
+ this.options = _extends({}, this.defaultOptions, options);
1145
+ this.meta = options == null ? void 0 : options.meta; // Default to 5 minutes if not cache time is set
1146
+
1147
+ this.cacheTime = Math.max(this.cacheTime || 0, (_this$options$cacheTi = this.options.cacheTime) != null ? _this$options$cacheTi : 5 * 60 * 1000);
1148
+ };
1149
+
1150
+ _proto.setDefaultOptions = function setDefaultOptions(options) {
1151
+ this.defaultOptions = options;
1152
+ };
1153
+
1154
+ _proto.scheduleGc = function scheduleGc() {
1155
+ var _this = this;
1156
+
1157
+ this.clearGcTimeout();
1158
+
1159
+ if (isValidTimeout(this.cacheTime)) {
1160
+ this.gcTimeout = setTimeout(function () {
1161
+ _this.optionalRemove();
1162
+ }, this.cacheTime);
1163
+ }
1164
+ };
1165
+
1166
+ _proto.clearGcTimeout = function clearGcTimeout() {
1167
+ clearTimeout(this.gcTimeout);
1168
+ this.gcTimeout = undefined;
1169
+ };
1170
+
1171
+ _proto.optionalRemove = function optionalRemove() {
1172
+ if (!this.observers.length) {
1173
+ if (this.state.isFetching) {
1174
+ if (this.hadObservers) {
1175
+ this.scheduleGc();
1176
+ }
1177
+ } else {
1178
+ this.cache.remove(this);
1179
+ }
1180
+ }
1181
+ };
1182
+
1183
+ _proto.setData = function setData(updater, options) {
1184
+ var _this$options$isDataE, _this$options;
1185
+
1186
+ var prevData = this.state.data; // Get the new data
1187
+
1188
+ var data = functionalUpdate(updater, prevData); // Use prev data if an isDataEqual function is defined and returns `true`
1189
+
1190
+ if ((_this$options$isDataE = (_this$options = this.options).isDataEqual) == null ? void 0 : _this$options$isDataE.call(_this$options, prevData, data)) {
1191
+ data = prevData;
1192
+ } else if (this.options.structuralSharing !== false) {
1193
+ // Structurally share data between prev and new data if needed
1194
+ data = replaceEqualDeep(prevData, data);
1195
+ } // Set data and mark it as cached
1196
+
1197
+
1198
+ this.dispatch({
1199
+ data: data,
1200
+ type: 'success',
1201
+ dataUpdatedAt: options == null ? void 0 : options.updatedAt
1202
+ });
1203
+ return data;
1204
+ };
1205
+
1206
+ _proto.setState = function setState(state, setStateOptions) {
1207
+ this.dispatch({
1208
+ type: 'setState',
1209
+ state: state,
1210
+ setStateOptions: setStateOptions
1211
+ });
1212
+ };
1213
+
1214
+ _proto.cancel = function cancel(options) {
1215
+ var _this$retryer;
1216
+
1217
+ var promise = this.promise;
1218
+ (_this$retryer = this.retryer) == null ? void 0 : _this$retryer.cancel(options);
1219
+ return promise ? promise.then(noop).catch(noop) : Promise.resolve();
1220
+ };
1221
+
1222
+ _proto.destroy = function destroy() {
1223
+ this.clearGcTimeout();
1224
+ this.cancel({
1225
+ silent: true
1226
+ });
1227
+ };
1228
+
1229
+ _proto.reset = function reset() {
1230
+ this.destroy();
1231
+ this.setState(this.initialState);
1232
+ };
1233
+
1234
+ _proto.isActive = function isActive() {
1235
+ return this.observers.some(function (observer) {
1236
+ return observer.options.enabled !== false;
1237
+ });
1238
+ };
1239
+
1240
+ _proto.isFetching = function isFetching() {
1241
+ return this.state.isFetching;
1242
+ };
1243
+
1244
+ _proto.isStale = function isStale() {
1245
+ return this.state.isInvalidated || !this.state.dataUpdatedAt || this.observers.some(function (observer) {
1246
+ return observer.getCurrentResult().isStale;
1247
+ });
1248
+ };
1249
+
1250
+ _proto.isStaleByTime = function isStaleByTime(staleTime) {
1251
+ if (staleTime === void 0) {
1252
+ staleTime = 0;
1253
+ }
1254
+
1255
+ return this.state.isInvalidated || !this.state.dataUpdatedAt || !timeUntilStale(this.state.dataUpdatedAt, staleTime);
1256
+ };
1257
+
1258
+ _proto.onFocus = function onFocus() {
1259
+ var _this$retryer2;
1260
+
1261
+ var observer = this.observers.find(function (x) {
1262
+ return x.shouldFetchOnWindowFocus();
1263
+ });
1264
+
1265
+ if (observer) {
1266
+ observer.refetch();
1267
+ } // Continue fetch if currently paused
1268
+
1269
+
1270
+ (_this$retryer2 = this.retryer) == null ? void 0 : _this$retryer2.continue();
1271
+ };
1272
+
1273
+ _proto.onOnline = function onOnline() {
1274
+ var _this$retryer3;
1275
+
1276
+ var observer = this.observers.find(function (x) {
1277
+ return x.shouldFetchOnReconnect();
1278
+ });
1279
+
1280
+ if (observer) {
1281
+ observer.refetch();
1282
+ } // Continue fetch if currently paused
1283
+
1284
+
1285
+ (_this$retryer3 = this.retryer) == null ? void 0 : _this$retryer3.continue();
1286
+ };
1287
+
1288
+ _proto.addObserver = function addObserver(observer) {
1289
+ if (this.observers.indexOf(observer) === -1) {
1290
+ this.observers.push(observer);
1291
+ this.hadObservers = true; // Stop the query from being garbage collected
1292
+
1293
+ this.clearGcTimeout();
1294
+ this.cache.notify({
1295
+ type: 'observerAdded',
1296
+ query: this,
1297
+ observer: observer
1298
+ });
1299
+ }
1300
+ };
1301
+
1302
+ _proto.removeObserver = function removeObserver(observer) {
1303
+ if (this.observers.indexOf(observer) !== -1) {
1304
+ this.observers = this.observers.filter(function (x) {
1305
+ return x !== observer;
1306
+ });
1307
+
1308
+ if (!this.observers.length) {
1309
+ // If the transport layer does not support cancellation
1310
+ // we'll let the query continue so the result can be cached
1311
+ if (this.retryer) {
1312
+ if (this.retryer.isTransportCancelable || this.abortSignalConsumed) {
1313
+ this.retryer.cancel({
1314
+ revert: true
1315
+ });
1316
+ } else {
1317
+ this.retryer.cancelRetry();
1318
+ }
1319
+ }
1320
+
1321
+ if (this.cacheTime) {
1322
+ this.scheduleGc();
1323
+ } else {
1324
+ this.cache.remove(this);
1325
+ }
1326
+ }
1327
+
1328
+ this.cache.notify({
1329
+ type: 'observerRemoved',
1330
+ query: this,
1331
+ observer: observer
1332
+ });
1333
+ }
1334
+ };
1335
+
1336
+ _proto.getObserversCount = function getObserversCount() {
1337
+ return this.observers.length;
1338
+ };
1339
+
1340
+ _proto.invalidate = function invalidate() {
1341
+ if (!this.state.isInvalidated) {
1342
+ this.dispatch({
1343
+ type: 'invalidate'
1344
+ });
1345
+ }
1346
+ };
1347
+
1348
+ _proto.fetch = function fetch(options, fetchOptions) {
1349
+ var _this2 = this,
1350
+ _this$options$behavio,
1351
+ _context$fetchOptions,
1352
+ _abortController$abor;
1353
+
1354
+ if (this.state.isFetching) {
1355
+ if (this.state.dataUpdatedAt && (fetchOptions == null ? void 0 : fetchOptions.cancelRefetch)) {
1356
+ // Silently cancel current fetch if the user wants to cancel refetches
1357
+ this.cancel({
1358
+ silent: true
1359
+ });
1360
+ } else if (this.promise) {
1361
+ var _this$retryer4;
1362
+
1363
+ // make sure that retries that were potentially cancelled due to unmounts can continue
1364
+ (_this$retryer4 = this.retryer) == null ? void 0 : _this$retryer4.continueRetry(); // Return current promise if we are already fetching
1365
+
1366
+ return this.promise;
1367
+ }
1368
+ } // Update config if passed, otherwise the config from the last execution is used
1369
+
1370
+
1371
+ if (options) {
1372
+ this.setOptions(options);
1373
+ } // Use the options from the first observer with a query function if no function is found.
1374
+ // This can happen when the query is hydrated or created with setQueryData.
1375
+
1376
+
1377
+ if (!this.options.queryFn) {
1378
+ var observer = this.observers.find(function (x) {
1379
+ return x.options.queryFn;
1380
+ });
1381
+
1382
+ if (observer) {
1383
+ this.setOptions(observer.options);
1384
+ }
1385
+ }
1386
+
1387
+ var queryKey = ensureQueryKeyArray(this.queryKey);
1388
+ var abortController = getAbortController(); // Create query function context
1389
+
1390
+ var queryFnContext = {
1391
+ queryKey: queryKey,
1392
+ pageParam: undefined,
1393
+ meta: this.meta
1394
+ };
1395
+ Object.defineProperty(queryFnContext, 'signal', {
1396
+ enumerable: true,
1397
+ get: function get() {
1398
+ if (abortController) {
1399
+ _this2.abortSignalConsumed = true;
1400
+ return abortController.signal;
1401
+ }
1402
+
1403
+ return undefined;
1404
+ }
1405
+ }); // Create fetch function
1406
+
1407
+ var fetchFn = function fetchFn() {
1408
+ if (!_this2.options.queryFn) {
1409
+ return Promise.reject('Missing queryFn');
1410
+ }
1411
+
1412
+ _this2.abortSignalConsumed = false;
1413
+ return _this2.options.queryFn(queryFnContext);
1414
+ }; // Trigger behavior hook
1415
+
1416
+
1417
+ var context = {
1418
+ fetchOptions: fetchOptions,
1419
+ options: this.options,
1420
+ queryKey: queryKey,
1421
+ state: this.state,
1422
+ fetchFn: fetchFn,
1423
+ meta: this.meta
1424
+ };
1425
+
1426
+ if ((_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch) {
1427
+ var _this$options$behavio2;
1428
+
1429
+ (_this$options$behavio2 = this.options.behavior) == null ? void 0 : _this$options$behavio2.onFetch(context);
1430
+ } // Store state in case the current fetch needs to be reverted
1431
+
1432
+
1433
+ this.revertState = this.state; // Set to fetching state if not already in it
1434
+
1435
+ if (!this.state.isFetching || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) == null ? void 0 : _context$fetchOptions.meta)) {
1436
+ var _context$fetchOptions2;
1437
+
1438
+ this.dispatch({
1439
+ type: 'fetch',
1440
+ meta: (_context$fetchOptions2 = context.fetchOptions) == null ? void 0 : _context$fetchOptions2.meta
1441
+ });
1442
+ } // Try to fetch the data
1443
+
1444
+
1445
+ this.retryer = new Retryer({
1446
+ fn: context.fetchFn,
1447
+ abort: abortController == null ? void 0 : (_abortController$abor = abortController.abort) == null ? void 0 : _abortController$abor.bind(abortController),
1448
+ onSuccess: function onSuccess(data) {
1449
+ _this2.setData(data); // Notify cache callback
1450
+
1451
+
1452
+ _this2.cache.config.onSuccess == null ? void 0 : _this2.cache.config.onSuccess(data, _this2); // Remove query after fetching if cache time is 0
1453
+
1454
+ if (_this2.cacheTime === 0) {
1455
+ _this2.optionalRemove();
1456
+ }
1457
+ },
1458
+ onError: function onError(error) {
1459
+ // Optimistically update state if needed
1460
+ if (!(isCancelledError(error) && error.silent)) {
1461
+ _this2.dispatch({
1462
+ type: 'error',
1463
+ error: error
1464
+ });
1465
+ }
1466
+
1467
+ if (!isCancelledError(error)) {
1468
+ // Notify cache callback
1469
+ _this2.cache.config.onError == null ? void 0 : _this2.cache.config.onError(error, _this2); // Log error
1470
+
1471
+ getLogger().error(error);
1472
+ } // Remove query after fetching if cache time is 0
1473
+
1474
+
1475
+ if (_this2.cacheTime === 0) {
1476
+ _this2.optionalRemove();
1477
+ }
1478
+ },
1479
+ onFail: function onFail() {
1480
+ _this2.dispatch({
1481
+ type: 'failed'
1482
+ });
1483
+ },
1484
+ onPause: function onPause() {
1485
+ _this2.dispatch({
1486
+ type: 'pause'
1487
+ });
1488
+ },
1489
+ onContinue: function onContinue() {
1490
+ _this2.dispatch({
1491
+ type: 'continue'
1492
+ });
1493
+ },
1494
+ retry: context.options.retry,
1495
+ retryDelay: context.options.retryDelay
1496
+ });
1497
+ this.promise = this.retryer.promise;
1498
+ return this.promise;
1499
+ };
1500
+
1501
+ _proto.dispatch = function dispatch(action) {
1502
+ var _this3 = this;
1503
+
1504
+ this.state = this.reducer(this.state, action);
1505
+ notifyManager.batch(function () {
1506
+ _this3.observers.forEach(function (observer) {
1507
+ observer.onQueryUpdate(action);
1508
+ });
1509
+
1510
+ _this3.cache.notify({
1511
+ query: _this3,
1512
+ type: 'queryUpdated',
1513
+ action: action
1514
+ });
1515
+ });
1516
+ };
1517
+
1518
+ _proto.getDefaultState = function getDefaultState(options) {
1519
+ var data = typeof options.initialData === 'function' ? options.initialData() : options.initialData;
1520
+ var hasInitialData = typeof options.initialData !== 'undefined';
1521
+ var initialDataUpdatedAt = hasInitialData ? typeof options.initialDataUpdatedAt === 'function' ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
1522
+ var hasData = typeof data !== 'undefined';
1523
+ return {
1524
+ data: data,
1525
+ dataUpdateCount: 0,
1526
+ dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
1527
+ error: null,
1528
+ errorUpdateCount: 0,
1529
+ errorUpdatedAt: 0,
1530
+ fetchFailureCount: 0,
1531
+ fetchMeta: null,
1532
+ isFetching: false,
1533
+ isInvalidated: false,
1534
+ isPaused: false,
1535
+ status: hasData ? 'success' : 'idle'
1536
+ };
1537
+ };
1538
+
1539
+ _proto.reducer = function reducer(state, action) {
1540
+ var _action$meta, _action$dataUpdatedAt;
1541
+
1542
+ switch (action.type) {
1543
+ case 'failed':
1544
+ return _extends({}, state, {
1545
+ fetchFailureCount: state.fetchFailureCount + 1
1546
+ });
1547
+
1548
+ case 'pause':
1549
+ return _extends({}, state, {
1550
+ isPaused: true
1551
+ });
1552
+
1553
+ case 'continue':
1554
+ return _extends({}, state, {
1555
+ isPaused: false
1556
+ });
1557
+
1558
+ case 'fetch':
1559
+ return _extends({}, state, {
1560
+ fetchFailureCount: 0,
1561
+ fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
1562
+ isFetching: true,
1563
+ isPaused: false
1564
+ }, !state.dataUpdatedAt && {
1565
+ error: null,
1566
+ status: 'loading'
1567
+ });
1568
+
1569
+ case 'success':
1570
+ return _extends({}, state, {
1571
+ data: action.data,
1572
+ dataUpdateCount: state.dataUpdateCount + 1,
1573
+ dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
1574
+ error: null,
1575
+ fetchFailureCount: 0,
1576
+ isFetching: false,
1577
+ isInvalidated: false,
1578
+ isPaused: false,
1579
+ status: 'success'
1580
+ });
1581
+
1582
+ case 'error':
1583
+ var error = action.error;
1584
+
1585
+ if (isCancelledError(error) && error.revert && this.revertState) {
1586
+ return _extends({}, this.revertState);
1587
+ }
1588
+
1589
+ return _extends({}, state, {
1590
+ error: error,
1591
+ errorUpdateCount: state.errorUpdateCount + 1,
1592
+ errorUpdatedAt: Date.now(),
1593
+ fetchFailureCount: state.fetchFailureCount + 1,
1594
+ isFetching: false,
1595
+ isPaused: false,
1596
+ status: 'error'
1597
+ });
1598
+
1599
+ case 'invalidate':
1600
+ return _extends({}, state, {
1601
+ isInvalidated: true
1602
+ });
1603
+
1604
+ case 'setState':
1605
+ return _extends({}, state, action.state);
1606
+
1607
+ default:
1608
+ return state;
1609
+ }
1610
+ };
1611
+
1612
+ return Query;
1613
+ }();
1614
+
1615
+ // CLASS
1616
+ var QueryCache = /*#__PURE__*/function (_Subscribable) {
1617
+ _inheritsLoose(QueryCache, _Subscribable);
1618
+
1619
+ function QueryCache(config) {
1620
+ var _this;
1621
+
1622
+ _this = _Subscribable.call(this) || this;
1623
+ _this.config = config || {};
1624
+ _this.queries = [];
1625
+ _this.queriesMap = {};
1626
+ return _this;
1627
+ }
1628
+
1629
+ var _proto = QueryCache.prototype;
1630
+
1631
+ _proto.build = function build(client, options, state) {
1632
+ var _options$queryHash;
1633
+
1634
+ var queryKey = options.queryKey;
1635
+ var queryHash = (_options$queryHash = options.queryHash) != null ? _options$queryHash : hashQueryKeyByOptions(queryKey, options);
1636
+ var query = this.get(queryHash);
1637
+
1638
+ if (!query) {
1639
+ query = new Query({
1640
+ cache: this,
1641
+ queryKey: queryKey,
1642
+ queryHash: queryHash,
1643
+ options: client.defaultQueryOptions(options),
1644
+ state: state,
1645
+ defaultOptions: client.getQueryDefaults(queryKey),
1646
+ meta: options.meta
1647
+ });
1648
+ this.add(query);
1649
+ }
1650
+
1651
+ return query;
1652
+ };
1653
+
1654
+ _proto.add = function add(query) {
1655
+ if (!this.queriesMap[query.queryHash]) {
1656
+ this.queriesMap[query.queryHash] = query;
1657
+ this.queries.push(query);
1658
+ this.notify({
1659
+ type: 'queryAdded',
1660
+ query: query
1661
+ });
1662
+ }
1663
+ };
1664
+
1665
+ _proto.remove = function remove(query) {
1666
+ var queryInMap = this.queriesMap[query.queryHash];
1667
+
1668
+ if (queryInMap) {
1669
+ query.destroy();
1670
+ this.queries = this.queries.filter(function (x) {
1671
+ return x !== query;
1672
+ });
1673
+
1674
+ if (queryInMap === query) {
1675
+ delete this.queriesMap[query.queryHash];
1676
+ }
1677
+
1678
+ this.notify({
1679
+ type: 'queryRemoved',
1680
+ query: query
1681
+ });
1682
+ }
1683
+ };
1684
+
1685
+ _proto.clear = function clear() {
1686
+ var _this2 = this;
1687
+
1688
+ notifyManager.batch(function () {
1689
+ _this2.queries.forEach(function (query) {
1690
+ _this2.remove(query);
1691
+ });
1692
+ });
1693
+ };
1694
+
1695
+ _proto.get = function get(queryHash) {
1696
+ return this.queriesMap[queryHash];
1697
+ };
1698
+
1699
+ _proto.getAll = function getAll() {
1700
+ return this.queries;
1701
+ };
1702
+
1703
+ _proto.find = function find(arg1, arg2) {
1704
+ var _parseFilterArgs = parseFilterArgs(arg1, arg2),
1705
+ filters = _parseFilterArgs[0];
1706
+
1707
+ if (typeof filters.exact === 'undefined') {
1708
+ filters.exact = true;
1709
+ }
1710
+
1711
+ return this.queries.find(function (query) {
1712
+ return matchQuery(filters, query);
1713
+ });
1714
+ };
1715
+
1716
+ _proto.findAll = function findAll(arg1, arg2) {
1717
+ var _parseFilterArgs2 = parseFilterArgs(arg1, arg2),
1718
+ filters = _parseFilterArgs2[0];
1719
+
1720
+ return Object.keys(filters).length > 0 ? this.queries.filter(function (query) {
1721
+ return matchQuery(filters, query);
1722
+ }) : this.queries;
1723
+ };
1724
+
1725
+ _proto.notify = function notify(event) {
1726
+ var _this3 = this;
1727
+
1728
+ notifyManager.batch(function () {
1729
+ _this3.listeners.forEach(function (listener) {
1730
+ listener(event);
1731
+ });
1732
+ });
1733
+ };
1734
+
1735
+ _proto.onFocus = function onFocus() {
1736
+ var _this4 = this;
1737
+
1738
+ notifyManager.batch(function () {
1739
+ _this4.queries.forEach(function (query) {
1740
+ query.onFocus();
1741
+ });
1742
+ });
1743
+ };
1744
+
1745
+ _proto.onOnline = function onOnline() {
1746
+ var _this5 = this;
1747
+
1748
+ notifyManager.batch(function () {
1749
+ _this5.queries.forEach(function (query) {
1750
+ query.onOnline();
1751
+ });
1752
+ });
1753
+ };
1754
+
1755
+ return QueryCache;
1756
+ }(Subscribable);
1757
+
1758
+ // CLASS
1759
+ var Mutation = /*#__PURE__*/function () {
1760
+ function Mutation(config) {
1761
+ this.options = _extends({}, config.defaultOptions, config.options);
1762
+ this.mutationId = config.mutationId;
1763
+ this.mutationCache = config.mutationCache;
1764
+ this.observers = [];
1765
+ this.state = config.state || getDefaultState();
1766
+ this.meta = config.meta;
1767
+ }
1768
+
1769
+ var _proto = Mutation.prototype;
1770
+
1771
+ _proto.setState = function setState(state) {
1772
+ this.dispatch({
1773
+ type: 'setState',
1774
+ state: state
1775
+ });
1776
+ };
1777
+
1778
+ _proto.addObserver = function addObserver(observer) {
1779
+ if (this.observers.indexOf(observer) === -1) {
1780
+ this.observers.push(observer);
1781
+ }
1782
+ };
1783
+
1784
+ _proto.removeObserver = function removeObserver(observer) {
1785
+ this.observers = this.observers.filter(function (x) {
1786
+ return x !== observer;
1787
+ });
1788
+ };
1789
+
1790
+ _proto.cancel = function cancel() {
1791
+ if (this.retryer) {
1792
+ this.retryer.cancel();
1793
+ return this.retryer.promise.then(noop).catch(noop);
1794
+ }
1795
+
1796
+ return Promise.resolve();
1797
+ };
1798
+
1799
+ _proto.continue = function _continue() {
1800
+ if (this.retryer) {
1801
+ this.retryer.continue();
1802
+ return this.retryer.promise;
1803
+ }
1804
+
1805
+ return this.execute();
1806
+ };
1807
+
1808
+ _proto.execute = function execute() {
1809
+ var _this = this;
1810
+
1811
+ var data;
1812
+ var restored = this.state.status === 'loading';
1813
+ var promise = Promise.resolve();
1814
+
1815
+ if (!restored) {
1816
+ this.dispatch({
1817
+ type: 'loading',
1818
+ variables: this.options.variables
1819
+ });
1820
+ promise = promise.then(function () {
1821
+ // Notify cache callback
1822
+ _this.mutationCache.config.onMutate == null ? void 0 : _this.mutationCache.config.onMutate(_this.state.variables, _this);
1823
+ }).then(function () {
1824
+ return _this.options.onMutate == null ? void 0 : _this.options.onMutate(_this.state.variables);
1825
+ }).then(function (context) {
1826
+ if (context !== _this.state.context) {
1827
+ _this.dispatch({
1828
+ type: 'loading',
1829
+ context: context,
1830
+ variables: _this.state.variables
1831
+ });
1832
+ }
1833
+ });
1834
+ }
1835
+
1836
+ return promise.then(function () {
1837
+ return _this.executeMutation();
1838
+ }).then(function (result) {
1839
+ data = result; // Notify cache callback
1840
+
1841
+ _this.mutationCache.config.onSuccess == null ? void 0 : _this.mutationCache.config.onSuccess(data, _this.state.variables, _this.state.context, _this);
1842
+ }).then(function () {
1843
+ return _this.options.onSuccess == null ? void 0 : _this.options.onSuccess(data, _this.state.variables, _this.state.context);
1844
+ }).then(function () {
1845
+ return _this.options.onSettled == null ? void 0 : _this.options.onSettled(data, null, _this.state.variables, _this.state.context);
1846
+ }).then(function () {
1847
+ _this.dispatch({
1848
+ type: 'success',
1849
+ data: data
1850
+ });
1851
+
1852
+ return data;
1853
+ }).catch(function (error) {
1854
+ // Notify cache callback
1855
+ _this.mutationCache.config.onError == null ? void 0 : _this.mutationCache.config.onError(error, _this.state.variables, _this.state.context, _this); // Log error
1856
+
1857
+ getLogger().error(error);
1858
+ return Promise.resolve().then(function () {
1859
+ return _this.options.onError == null ? void 0 : _this.options.onError(error, _this.state.variables, _this.state.context);
1860
+ }).then(function () {
1861
+ return _this.options.onSettled == null ? void 0 : _this.options.onSettled(undefined, error, _this.state.variables, _this.state.context);
1862
+ }).then(function () {
1863
+ _this.dispatch({
1864
+ type: 'error',
1865
+ error: error
1866
+ });
1867
+
1868
+ throw error;
1869
+ });
1870
+ });
1871
+ };
1872
+
1873
+ _proto.executeMutation = function executeMutation() {
1874
+ var _this2 = this,
1875
+ _this$options$retry;
1876
+
1877
+ this.retryer = new Retryer({
1878
+ fn: function fn() {
1879
+ if (!_this2.options.mutationFn) {
1880
+ return Promise.reject('No mutationFn found');
1881
+ }
1882
+
1883
+ return _this2.options.mutationFn(_this2.state.variables);
1884
+ },
1885
+ onFail: function onFail() {
1886
+ _this2.dispatch({
1887
+ type: 'failed'
1888
+ });
1889
+ },
1890
+ onPause: function onPause() {
1891
+ _this2.dispatch({
1892
+ type: 'pause'
1893
+ });
1894
+ },
1895
+ onContinue: function onContinue() {
1896
+ _this2.dispatch({
1897
+ type: 'continue'
1898
+ });
1899
+ },
1900
+ retry: (_this$options$retry = this.options.retry) != null ? _this$options$retry : 0,
1901
+ retryDelay: this.options.retryDelay
1902
+ });
1903
+ return this.retryer.promise;
1904
+ };
1905
+
1906
+ _proto.dispatch = function dispatch(action) {
1907
+ var _this3 = this;
1908
+
1909
+ this.state = reducer(this.state, action);
1910
+ notifyManager.batch(function () {
1911
+ _this3.observers.forEach(function (observer) {
1912
+ observer.onMutationUpdate(action);
1913
+ });
1914
+
1915
+ _this3.mutationCache.notify(_this3);
1916
+ });
1917
+ };
1918
+
1919
+ return Mutation;
1920
+ }();
1921
+ function getDefaultState() {
1922
+ return {
1923
+ context: undefined,
1924
+ data: undefined,
1925
+ error: null,
1926
+ failureCount: 0,
1927
+ isPaused: false,
1928
+ status: 'idle',
1929
+ variables: undefined
1930
+ };
1931
+ }
1932
+
1933
+ function reducer(state, action) {
1934
+ switch (action.type) {
1935
+ case 'failed':
1936
+ return _extends({}, state, {
1937
+ failureCount: state.failureCount + 1
1938
+ });
1939
+
1940
+ case 'pause':
1941
+ return _extends({}, state, {
1942
+ isPaused: true
1943
+ });
1944
+
1945
+ case 'continue':
1946
+ return _extends({}, state, {
1947
+ isPaused: false
1948
+ });
1949
+
1950
+ case 'loading':
1951
+ return _extends({}, state, {
1952
+ context: action.context,
1953
+ data: undefined,
1954
+ error: null,
1955
+ isPaused: false,
1956
+ status: 'loading',
1957
+ variables: action.variables
1958
+ });
1959
+
1960
+ case 'success':
1961
+ return _extends({}, state, {
1962
+ data: action.data,
1963
+ error: null,
1964
+ status: 'success',
1965
+ isPaused: false
1966
+ });
1967
+
1968
+ case 'error':
1969
+ return _extends({}, state, {
1970
+ data: undefined,
1971
+ error: action.error,
1972
+ failureCount: state.failureCount + 1,
1973
+ isPaused: false,
1974
+ status: 'error'
1975
+ });
1976
+
1977
+ case 'setState':
1978
+ return _extends({}, state, action.state);
1979
+
1980
+ default:
1981
+ return state;
1982
+ }
1983
+ }
1984
+
1985
+ // CLASS
1986
+ var MutationCache = /*#__PURE__*/function (_Subscribable) {
1987
+ _inheritsLoose(MutationCache, _Subscribable);
1988
+
1989
+ function MutationCache(config) {
1990
+ var _this;
1991
+
1992
+ _this = _Subscribable.call(this) || this;
1993
+ _this.config = config || {};
1994
+ _this.mutations = [];
1995
+ _this.mutationId = 0;
1996
+ return _this;
1997
+ }
1998
+
1999
+ var _proto = MutationCache.prototype;
2000
+
2001
+ _proto.build = function build(client, options, state) {
2002
+ var mutation = new Mutation({
2003
+ mutationCache: this,
2004
+ mutationId: ++this.mutationId,
2005
+ options: client.defaultMutationOptions(options),
2006
+ state: state,
2007
+ defaultOptions: options.mutationKey ? client.getMutationDefaults(options.mutationKey) : undefined,
2008
+ meta: options.meta
2009
+ });
2010
+ this.add(mutation);
2011
+ return mutation;
2012
+ };
2013
+
2014
+ _proto.add = function add(mutation) {
2015
+ this.mutations.push(mutation);
2016
+ this.notify(mutation);
2017
+ };
2018
+
2019
+ _proto.remove = function remove(mutation) {
2020
+ this.mutations = this.mutations.filter(function (x) {
2021
+ return x !== mutation;
2022
+ });
2023
+ mutation.cancel();
2024
+ this.notify(mutation);
2025
+ };
2026
+
2027
+ _proto.clear = function clear() {
2028
+ var _this2 = this;
2029
+
2030
+ notifyManager.batch(function () {
2031
+ _this2.mutations.forEach(function (mutation) {
2032
+ _this2.remove(mutation);
2033
+ });
2034
+ });
2035
+ };
2036
+
2037
+ _proto.getAll = function getAll() {
2038
+ return this.mutations;
2039
+ };
2040
+
2041
+ _proto.find = function find(filters) {
2042
+ if (typeof filters.exact === 'undefined') {
2043
+ filters.exact = true;
2044
+ }
2045
+
2046
+ return this.mutations.find(function (mutation) {
2047
+ return matchMutation(filters, mutation);
2048
+ });
2049
+ };
2050
+
2051
+ _proto.findAll = function findAll(filters) {
2052
+ return this.mutations.filter(function (mutation) {
2053
+ return matchMutation(filters, mutation);
2054
+ });
2055
+ };
2056
+
2057
+ _proto.notify = function notify(mutation) {
2058
+ var _this3 = this;
2059
+
2060
+ notifyManager.batch(function () {
2061
+ _this3.listeners.forEach(function (listener) {
2062
+ listener(mutation);
2063
+ });
2064
+ });
2065
+ };
2066
+
2067
+ _proto.onFocus = function onFocus() {
2068
+ this.resumePausedMutations();
2069
+ };
2070
+
2071
+ _proto.onOnline = function onOnline() {
2072
+ this.resumePausedMutations();
2073
+ };
2074
+
2075
+ _proto.resumePausedMutations = function resumePausedMutations() {
2076
+ var pausedMutations = this.mutations.filter(function (x) {
2077
+ return x.state.isPaused;
2078
+ });
2079
+ return notifyManager.batch(function () {
2080
+ return pausedMutations.reduce(function (promise, mutation) {
2081
+ return promise.then(function () {
2082
+ return mutation.continue().catch(noop);
2083
+ });
2084
+ }, Promise.resolve());
2085
+ });
2086
+ };
2087
+
2088
+ return MutationCache;
2089
+ }(Subscribable);
2090
+
2091
+ function infiniteQueryBehavior() {
2092
+ return {
2093
+ onFetch: function onFetch(context) {
2094
+ context.fetchFn = function () {
2095
+ var _context$fetchOptions, _context$fetchOptions2, _context$fetchOptions3, _context$fetchOptions4, _context$state$data, _context$state$data2;
2096
+
2097
+ var refetchPage = (_context$fetchOptions = context.fetchOptions) == null ? void 0 : (_context$fetchOptions2 = _context$fetchOptions.meta) == null ? void 0 : _context$fetchOptions2.refetchPage;
2098
+ var fetchMore = (_context$fetchOptions3 = context.fetchOptions) == null ? void 0 : (_context$fetchOptions4 = _context$fetchOptions3.meta) == null ? void 0 : _context$fetchOptions4.fetchMore;
2099
+ var pageParam = fetchMore == null ? void 0 : fetchMore.pageParam;
2100
+ var isFetchingNextPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'forward';
2101
+ var isFetchingPreviousPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'backward';
2102
+ var oldPages = ((_context$state$data = context.state.data) == null ? void 0 : _context$state$data.pages) || [];
2103
+ var oldPageParams = ((_context$state$data2 = context.state.data) == null ? void 0 : _context$state$data2.pageParams) || [];
2104
+ var abortController = getAbortController();
2105
+ var abortSignal = abortController == null ? void 0 : abortController.signal;
2106
+ var newPageParams = oldPageParams;
2107
+ var cancelled = false; // Get query function
2108
+
2109
+ var queryFn = context.options.queryFn || function () {
2110
+ return Promise.reject('Missing queryFn');
2111
+ };
2112
+
2113
+ var buildNewPages = function buildNewPages(pages, param, page, previous) {
2114
+ newPageParams = previous ? [param].concat(newPageParams) : [].concat(newPageParams, [param]);
2115
+ return previous ? [page].concat(pages) : [].concat(pages, [page]);
2116
+ }; // Create function to fetch a page
2117
+
2118
+
2119
+ var fetchPage = function fetchPage(pages, manual, param, previous) {
2120
+ if (cancelled) {
2121
+ return Promise.reject('Cancelled');
2122
+ }
2123
+
2124
+ if (typeof param === 'undefined' && !manual && pages.length) {
2125
+ return Promise.resolve(pages);
2126
+ }
2127
+
2128
+ var queryFnContext = {
2129
+ queryKey: context.queryKey,
2130
+ signal: abortSignal,
2131
+ pageParam: param,
2132
+ meta: context.meta
2133
+ };
2134
+ var queryFnResult = queryFn(queryFnContext);
2135
+ var promise = Promise.resolve(queryFnResult).then(function (page) {
2136
+ return buildNewPages(pages, param, page, previous);
2137
+ });
2138
+
2139
+ if (isCancelable(queryFnResult)) {
2140
+ var promiseAsAny = promise;
2141
+ promiseAsAny.cancel = queryFnResult.cancel;
2142
+ }
2143
+
2144
+ return promise;
2145
+ };
2146
+
2147
+ var promise; // Fetch first page?
2148
+
2149
+ if (!oldPages.length) {
2150
+ promise = fetchPage([]);
2151
+ } // Fetch next page?
2152
+ else if (isFetchingNextPage) {
2153
+ var manual = typeof pageParam !== 'undefined';
2154
+ var param = manual ? pageParam : getNextPageParam(context.options, oldPages);
2155
+ promise = fetchPage(oldPages, manual, param);
2156
+ } // Fetch previous page?
2157
+ else if (isFetchingPreviousPage) {
2158
+ var _manual = typeof pageParam !== 'undefined';
2159
+
2160
+ var _param = _manual ? pageParam : getPreviousPageParam(context.options, oldPages);
2161
+
2162
+ promise = fetchPage(oldPages, _manual, _param, true);
2163
+ } // Refetch pages
2164
+ else {
2165
+ (function () {
2166
+ newPageParams = [];
2167
+ var manual = typeof context.options.getNextPageParam === 'undefined';
2168
+ var shouldFetchFirstPage = refetchPage && oldPages[0] ? refetchPage(oldPages[0], 0, oldPages) : true; // Fetch first page
2169
+
2170
+ promise = shouldFetchFirstPage ? fetchPage([], manual, oldPageParams[0]) : Promise.resolve(buildNewPages([], oldPageParams[0], oldPages[0])); // Fetch remaining pages
2171
+
2172
+ var _loop = function _loop(i) {
2173
+ promise = promise.then(function (pages) {
2174
+ var shouldFetchNextPage = refetchPage && oldPages[i] ? refetchPage(oldPages[i], i, oldPages) : true;
2175
+
2176
+ if (shouldFetchNextPage) {
2177
+ var _param2 = manual ? oldPageParams[i] : getNextPageParam(context.options, pages);
2178
+
2179
+ return fetchPage(pages, manual, _param2);
2180
+ }
2181
+
2182
+ return Promise.resolve(buildNewPages(pages, oldPageParams[i], oldPages[i]));
2183
+ });
2184
+ };
2185
+
2186
+ for (var i = 1; i < oldPages.length; i++) {
2187
+ _loop(i);
2188
+ }
2189
+ })();
2190
+ }
2191
+
2192
+ var finalPromise = promise.then(function (pages) {
2193
+ return {
2194
+ pages: pages,
2195
+ pageParams: newPageParams
2196
+ };
2197
+ });
2198
+ var finalPromiseAsAny = finalPromise;
2199
+
2200
+ finalPromiseAsAny.cancel = function () {
2201
+ cancelled = true;
2202
+ abortController == null ? void 0 : abortController.abort();
2203
+
2204
+ if (isCancelable(promise)) {
2205
+ promise.cancel();
2206
+ }
2207
+ };
2208
+
2209
+ return finalPromise;
2210
+ };
2211
+ }
2212
+ };
2213
+ }
2214
+ function getNextPageParam(options, pages) {
2215
+ return options.getNextPageParam == null ? void 0 : options.getNextPageParam(pages[pages.length - 1], pages);
2216
+ }
2217
+ function getPreviousPageParam(options, pages) {
2218
+ return options.getPreviousPageParam == null ? void 0 : options.getPreviousPageParam(pages[0], pages);
2219
+ }
2220
+
2221
+ // CLASS
2222
+ var QueryClient = /*#__PURE__*/function () {
2223
+ function QueryClient(config) {
2224
+ if (config === void 0) {
2225
+ config = {};
2226
+ }
2227
+
2228
+ this.queryCache = config.queryCache || new QueryCache();
2229
+ this.mutationCache = config.mutationCache || new MutationCache();
2230
+ this.defaultOptions = config.defaultOptions || {};
2231
+ this.queryDefaults = [];
2232
+ this.mutationDefaults = [];
2233
+ }
2234
+
2235
+ var _proto = QueryClient.prototype;
2236
+
2237
+ _proto.mount = function mount() {
2238
+ var _this = this;
2239
+
2240
+ this.unsubscribeFocus = focusManager.subscribe(function () {
2241
+ if (focusManager.isFocused() && onlineManager.isOnline()) {
2242
+ _this.mutationCache.onFocus();
2243
+
2244
+ _this.queryCache.onFocus();
2245
+ }
2246
+ });
2247
+ this.unsubscribeOnline = onlineManager.subscribe(function () {
2248
+ if (focusManager.isFocused() && onlineManager.isOnline()) {
2249
+ _this.mutationCache.onOnline();
2250
+
2251
+ _this.queryCache.onOnline();
2252
+ }
2253
+ });
2254
+ };
2255
+
2256
+ _proto.unmount = function unmount() {
2257
+ var _this$unsubscribeFocu, _this$unsubscribeOnli;
2258
+
2259
+ (_this$unsubscribeFocu = this.unsubscribeFocus) == null ? void 0 : _this$unsubscribeFocu.call(this);
2260
+ (_this$unsubscribeOnli = this.unsubscribeOnline) == null ? void 0 : _this$unsubscribeOnli.call(this);
2261
+ };
2262
+
2263
+ _proto.isFetching = function isFetching(arg1, arg2) {
2264
+ var _parseFilterArgs = parseFilterArgs(arg1, arg2),
2265
+ filters = _parseFilterArgs[0];
2266
+
2267
+ filters.fetching = true;
2268
+ return this.queryCache.findAll(filters).length;
2269
+ };
2270
+
2271
+ _proto.isMutating = function isMutating(filters) {
2272
+ return this.mutationCache.findAll(_extends({}, filters, {
2273
+ fetching: true
2274
+ })).length;
2275
+ };
2276
+
2277
+ _proto.getQueryData = function getQueryData(queryKey, filters) {
2278
+ var _this$queryCache$find;
2279
+
2280
+ return (_this$queryCache$find = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find.state.data;
2281
+ };
2282
+
2283
+ _proto.getQueriesData = function getQueriesData(queryKeyOrFilters) {
2284
+ return this.getQueryCache().findAll(queryKeyOrFilters).map(function (_ref) {
2285
+ var queryKey = _ref.queryKey,
2286
+ state = _ref.state;
2287
+ var data = state.data;
2288
+ return [queryKey, data];
2289
+ });
2290
+ };
2291
+
2292
+ _proto.setQueryData = function setQueryData(queryKey, updater, options) {
2293
+ var parsedOptions = parseQueryArgs(queryKey);
2294
+ var defaultedOptions = this.defaultQueryOptions(parsedOptions);
2295
+ return this.queryCache.build(this, defaultedOptions).setData(updater, options);
2296
+ };
2297
+
2298
+ _proto.setQueriesData = function setQueriesData(queryKeyOrFilters, updater, options) {
2299
+ var _this2 = this;
2300
+
2301
+ return notifyManager.batch(function () {
2302
+ return _this2.getQueryCache().findAll(queryKeyOrFilters).map(function (_ref2) {
2303
+ var queryKey = _ref2.queryKey;
2304
+ return [queryKey, _this2.setQueryData(queryKey, updater, options)];
2305
+ });
2306
+ });
2307
+ };
2308
+
2309
+ _proto.getQueryState = function getQueryState(queryKey, filters) {
2310
+ var _this$queryCache$find2;
2311
+
2312
+ return (_this$queryCache$find2 = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find2.state;
2313
+ };
2314
+
2315
+ _proto.removeQueries = function removeQueries(arg1, arg2) {
2316
+ var _parseFilterArgs2 = parseFilterArgs(arg1, arg2),
2317
+ filters = _parseFilterArgs2[0];
2318
+
2319
+ var queryCache = this.queryCache;
2320
+ notifyManager.batch(function () {
2321
+ queryCache.findAll(filters).forEach(function (query) {
2322
+ queryCache.remove(query);
2323
+ });
2324
+ });
2325
+ };
2326
+
2327
+ _proto.resetQueries = function resetQueries(arg1, arg2, arg3) {
2328
+ var _this3 = this;
2329
+
2330
+ var _parseFilterArgs3 = parseFilterArgs(arg1, arg2, arg3),
2331
+ filters = _parseFilterArgs3[0],
2332
+ options = _parseFilterArgs3[1];
2333
+
2334
+ var queryCache = this.queryCache;
2335
+
2336
+ var refetchFilters = _extends({}, filters, {
2337
+ active: true
2338
+ });
2339
+
2340
+ return notifyManager.batch(function () {
2341
+ queryCache.findAll(filters).forEach(function (query) {
2342
+ query.reset();
2343
+ });
2344
+ return _this3.refetchQueries(refetchFilters, options);
2345
+ });
2346
+ };
2347
+
2348
+ _proto.cancelQueries = function cancelQueries(arg1, arg2, arg3) {
2349
+ var _this4 = this;
2350
+
2351
+ var _parseFilterArgs4 = parseFilterArgs(arg1, arg2, arg3),
2352
+ filters = _parseFilterArgs4[0],
2353
+ _parseFilterArgs4$ = _parseFilterArgs4[1],
2354
+ cancelOptions = _parseFilterArgs4$ === void 0 ? {} : _parseFilterArgs4$;
2355
+
2356
+ if (typeof cancelOptions.revert === 'undefined') {
2357
+ cancelOptions.revert = true;
2358
+ }
2359
+
2360
+ var promises = notifyManager.batch(function () {
2361
+ return _this4.queryCache.findAll(filters).map(function (query) {
2362
+ return query.cancel(cancelOptions);
2363
+ });
2364
+ });
2365
+ return Promise.all(promises).then(noop).catch(noop);
2366
+ };
2367
+
2368
+ _proto.invalidateQueries = function invalidateQueries(arg1, arg2, arg3) {
2369
+ var _ref3,
2370
+ _filters$refetchActiv,
2371
+ _filters$refetchInact,
2372
+ _this5 = this;
2373
+
2374
+ var _parseFilterArgs5 = parseFilterArgs(arg1, arg2, arg3),
2375
+ filters = _parseFilterArgs5[0],
2376
+ options = _parseFilterArgs5[1];
2377
+
2378
+ var refetchFilters = _extends({}, filters, {
2379
+ // if filters.refetchActive is not provided and filters.active is explicitly false,
2380
+ // e.g. invalidateQueries({ active: false }), we don't want to refetch active queries
2381
+ active: (_ref3 = (_filters$refetchActiv = filters.refetchActive) != null ? _filters$refetchActiv : filters.active) != null ? _ref3 : true,
2382
+ inactive: (_filters$refetchInact = filters.refetchInactive) != null ? _filters$refetchInact : false
2383
+ });
2384
+
2385
+ return notifyManager.batch(function () {
2386
+ _this5.queryCache.findAll(filters).forEach(function (query) {
2387
+ query.invalidate();
2388
+ });
2389
+
2390
+ return _this5.refetchQueries(refetchFilters, options);
2391
+ });
2392
+ };
2393
+
2394
+ _proto.refetchQueries = function refetchQueries(arg1, arg2, arg3) {
2395
+ var _this6 = this;
2396
+
2397
+ var _parseFilterArgs6 = parseFilterArgs(arg1, arg2, arg3),
2398
+ filters = _parseFilterArgs6[0],
2399
+ options = _parseFilterArgs6[1];
2400
+
2401
+ var promises = notifyManager.batch(function () {
2402
+ return _this6.queryCache.findAll(filters).map(function (query) {
2403
+ return query.fetch(undefined, _extends({}, options, {
2404
+ meta: {
2405
+ refetchPage: filters == null ? void 0 : filters.refetchPage
2406
+ }
2407
+ }));
2408
+ });
2409
+ });
2410
+ var promise = Promise.all(promises).then(noop);
2411
+
2412
+ if (!(options == null ? void 0 : options.throwOnError)) {
2413
+ promise = promise.catch(noop);
2414
+ }
2415
+
2416
+ return promise;
2417
+ };
2418
+
2419
+ _proto.fetchQuery = function fetchQuery(arg1, arg2, arg3) {
2420
+ var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
2421
+ var defaultedOptions = this.defaultQueryOptions(parsedOptions); // https://github.com/tannerlinsley/react-query/issues/652
2422
+
2423
+ if (typeof defaultedOptions.retry === 'undefined') {
2424
+ defaultedOptions.retry = false;
2425
+ }
2426
+
2427
+ var query = this.queryCache.build(this, defaultedOptions);
2428
+ return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
2429
+ };
2430
+
2431
+ _proto.prefetchQuery = function prefetchQuery(arg1, arg2, arg3) {
2432
+ return this.fetchQuery(arg1, arg2, arg3).then(noop).catch(noop);
2433
+ };
2434
+
2435
+ _proto.fetchInfiniteQuery = function fetchInfiniteQuery(arg1, arg2, arg3) {
2436
+ var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
2437
+ parsedOptions.behavior = infiniteQueryBehavior();
2438
+ return this.fetchQuery(parsedOptions);
2439
+ };
2440
+
2441
+ _proto.prefetchInfiniteQuery = function prefetchInfiniteQuery(arg1, arg2, arg3) {
2442
+ return this.fetchInfiniteQuery(arg1, arg2, arg3).then(noop).catch(noop);
2443
+ };
2444
+
2445
+ _proto.cancelMutations = function cancelMutations() {
2446
+ var _this7 = this;
2447
+
2448
+ var promises = notifyManager.batch(function () {
2449
+ return _this7.mutationCache.getAll().map(function (mutation) {
2450
+ return mutation.cancel();
2451
+ });
2452
+ });
2453
+ return Promise.all(promises).then(noop).catch(noop);
2454
+ };
2455
+
2456
+ _proto.resumePausedMutations = function resumePausedMutations() {
2457
+ return this.getMutationCache().resumePausedMutations();
2458
+ };
2459
+
2460
+ _proto.executeMutation = function executeMutation(options) {
2461
+ return this.mutationCache.build(this, options).execute();
2462
+ };
2463
+
2464
+ _proto.getQueryCache = function getQueryCache() {
2465
+ return this.queryCache;
2466
+ };
2467
+
2468
+ _proto.getMutationCache = function getMutationCache() {
2469
+ return this.mutationCache;
2470
+ };
2471
+
2472
+ _proto.getDefaultOptions = function getDefaultOptions() {
2473
+ return this.defaultOptions;
2474
+ };
2475
+
2476
+ _proto.setDefaultOptions = function setDefaultOptions(options) {
2477
+ this.defaultOptions = options;
2478
+ };
2479
+
2480
+ _proto.setQueryDefaults = function setQueryDefaults(queryKey, options) {
2481
+ var result = this.queryDefaults.find(function (x) {
2482
+ return hashQueryKey(queryKey) === hashQueryKey(x.queryKey);
2483
+ });
2484
+
2485
+ if (result) {
2486
+ result.defaultOptions = options;
2487
+ } else {
2488
+ this.queryDefaults.push({
2489
+ queryKey: queryKey,
2490
+ defaultOptions: options
2491
+ });
2492
+ }
2493
+ };
2494
+
2495
+ _proto.getQueryDefaults = function getQueryDefaults(queryKey) {
2496
+ var _this$queryDefaults$f;
2497
+
2498
+ return queryKey ? (_this$queryDefaults$f = this.queryDefaults.find(function (x) {
2499
+ return partialMatchKey(queryKey, x.queryKey);
2500
+ })) == null ? void 0 : _this$queryDefaults$f.defaultOptions : undefined;
2501
+ };
2502
+
2503
+ _proto.setMutationDefaults = function setMutationDefaults(mutationKey, options) {
2504
+ var result = this.mutationDefaults.find(function (x) {
2505
+ return hashQueryKey(mutationKey) === hashQueryKey(x.mutationKey);
2506
+ });
2507
+
2508
+ if (result) {
2509
+ result.defaultOptions = options;
2510
+ } else {
2511
+ this.mutationDefaults.push({
2512
+ mutationKey: mutationKey,
2513
+ defaultOptions: options
2514
+ });
2515
+ }
2516
+ };
2517
+
2518
+ _proto.getMutationDefaults = function getMutationDefaults(mutationKey) {
2519
+ var _this$mutationDefault;
2520
+
2521
+ return mutationKey ? (_this$mutationDefault = this.mutationDefaults.find(function (x) {
2522
+ return partialMatchKey(mutationKey, x.mutationKey);
2523
+ })) == null ? void 0 : _this$mutationDefault.defaultOptions : undefined;
2524
+ };
2525
+
2526
+ _proto.defaultQueryOptions = function defaultQueryOptions(options) {
2527
+ if (options == null ? void 0 : options._defaulted) {
2528
+ return options;
2529
+ }
2530
+
2531
+ var defaultedOptions = _extends({}, this.defaultOptions.queries, this.getQueryDefaults(options == null ? void 0 : options.queryKey), options, {
2532
+ _defaulted: true
2533
+ });
2534
+
2535
+ if (!defaultedOptions.queryHash && defaultedOptions.queryKey) {
2536
+ defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
2537
+ }
2538
+
2539
+ return defaultedOptions;
2540
+ };
2541
+
2542
+ _proto.defaultQueryObserverOptions = function defaultQueryObserverOptions(options) {
2543
+ return this.defaultQueryOptions(options);
2544
+ };
2545
+
2546
+ _proto.defaultMutationOptions = function defaultMutationOptions(options) {
2547
+ if (options == null ? void 0 : options._defaulted) {
2548
+ return options;
2549
+ }
2550
+
2551
+ return _extends({}, this.defaultOptions.mutations, this.getMutationDefaults(options == null ? void 0 : options.mutationKey), options, {
2552
+ _defaulted: true
2553
+ });
2554
+ };
2555
+
2556
+ _proto.clear = function clear() {
2557
+ this.queryCache.clear();
2558
+ this.mutationCache.clear();
2559
+ };
2560
+
2561
+ return QueryClient;
2562
+ }();
2563
+
2564
+ var QueryObserver = /*#__PURE__*/function (_Subscribable) {
2565
+ _inheritsLoose(QueryObserver, _Subscribable);
2566
+
2567
+ function QueryObserver(client, options) {
2568
+ var _this;
2569
+
2570
+ _this = _Subscribable.call(this) || this;
2571
+ _this.client = client;
2572
+ _this.options = options;
2573
+ _this.trackedProps = [];
2574
+ _this.selectError = null;
2575
+
2576
+ _this.bindMethods();
2577
+
2578
+ _this.setOptions(options);
2579
+
2580
+ return _this;
2581
+ }
2582
+
2583
+ var _proto = QueryObserver.prototype;
2584
+
2585
+ _proto.bindMethods = function bindMethods() {
2586
+ this.remove = this.remove.bind(this);
2587
+ this.refetch = this.refetch.bind(this);
2588
+ };
2589
+
2590
+ _proto.onSubscribe = function onSubscribe() {
2591
+ if (this.listeners.length === 1) {
2592
+ this.currentQuery.addObserver(this);
2593
+
2594
+ if (shouldFetchOnMount(this.currentQuery, this.options)) {
2595
+ this.executeFetch();
2596
+ }
2597
+
2598
+ this.updateTimers();
2599
+ }
2600
+ };
2601
+
2602
+ _proto.onUnsubscribe = function onUnsubscribe() {
2603
+ if (!this.listeners.length) {
2604
+ this.destroy();
2605
+ }
2606
+ };
2607
+
2608
+ _proto.shouldFetchOnReconnect = function shouldFetchOnReconnect() {
2609
+ return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnReconnect);
2610
+ };
2611
+
2612
+ _proto.shouldFetchOnWindowFocus = function shouldFetchOnWindowFocus() {
2613
+ return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
2614
+ };
2615
+
2616
+ _proto.destroy = function destroy() {
2617
+ this.listeners = [];
2618
+ this.clearTimers();
2619
+ this.currentQuery.removeObserver(this);
2620
+ };
2621
+
2622
+ _proto.setOptions = function setOptions(options, notifyOptions) {
2623
+ var prevOptions = this.options;
2624
+ var prevQuery = this.currentQuery;
2625
+ this.options = this.client.defaultQueryObserverOptions(options);
2626
+
2627
+ if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
2628
+ throw new Error('Expected enabled to be a boolean');
2629
+ } // Keep previous query key if the user does not supply one
2630
+
2631
+
2632
+ if (!this.options.queryKey) {
2633
+ this.options.queryKey = prevOptions.queryKey;
2634
+ }
2635
+
2636
+ this.updateQuery();
2637
+ var mounted = this.hasListeners(); // Fetch if there are subscribers
2638
+
2639
+ if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
2640
+ this.executeFetch();
2641
+ } // Update result
2642
+
2643
+
2644
+ this.updateResult(notifyOptions); // Update stale interval if needed
2645
+
2646
+ if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
2647
+ this.updateStaleTimeout();
2648
+ }
2649
+
2650
+ var nextRefetchInterval = this.computeRefetchInterval(); // Update refetch interval if needed
2651
+
2652
+ if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
2653
+ this.updateRefetchInterval(nextRefetchInterval);
2654
+ }
2655
+ };
2656
+
2657
+ _proto.getOptimisticResult = function getOptimisticResult(options) {
2658
+ var defaultedOptions = this.client.defaultQueryObserverOptions(options);
2659
+ var query = this.client.getQueryCache().build(this.client, defaultedOptions);
2660
+ return this.createResult(query, defaultedOptions);
2661
+ };
2662
+
2663
+ _proto.getCurrentResult = function getCurrentResult() {
2664
+ return this.currentResult;
2665
+ };
2666
+
2667
+ _proto.trackResult = function trackResult(result, defaultedOptions) {
2668
+ var _this2 = this;
2669
+
2670
+ var trackedResult = {};
2671
+
2672
+ var trackProp = function trackProp(key) {
2673
+ if (!_this2.trackedProps.includes(key)) {
2674
+ _this2.trackedProps.push(key);
2675
+ }
2676
+ };
2677
+
2678
+ Object.keys(result).forEach(function (key) {
2679
+ Object.defineProperty(trackedResult, key, {
2680
+ configurable: false,
2681
+ enumerable: true,
2682
+ get: function get() {
2683
+ trackProp(key);
2684
+ return result[key];
2685
+ }
2686
+ });
2687
+ });
2688
+
2689
+ if (defaultedOptions.useErrorBoundary || defaultedOptions.suspense) {
2690
+ trackProp('error');
2691
+ }
2692
+
2693
+ return trackedResult;
2694
+ };
2695
+
2696
+ _proto.getNextResult = function getNextResult(options) {
2697
+ var _this3 = this;
2698
+
2699
+ return new Promise(function (resolve, reject) {
2700
+ var unsubscribe = _this3.subscribe(function (result) {
2701
+ if (!result.isFetching) {
2702
+ unsubscribe();
2703
+
2704
+ if (result.isError && (options == null ? void 0 : options.throwOnError)) {
2705
+ reject(result.error);
2706
+ } else {
2707
+ resolve(result);
2708
+ }
2709
+ }
2710
+ });
2711
+ });
2712
+ };
2713
+
2714
+ _proto.getCurrentQuery = function getCurrentQuery() {
2715
+ return this.currentQuery;
2716
+ };
2717
+
2718
+ _proto.remove = function remove() {
2719
+ this.client.getQueryCache().remove(this.currentQuery);
2720
+ };
2721
+
2722
+ _proto.refetch = function refetch(options) {
2723
+ return this.fetch(_extends({}, options, {
2724
+ meta: {
2725
+ refetchPage: options == null ? void 0 : options.refetchPage
2726
+ }
2727
+ }));
2728
+ };
2729
+
2730
+ _proto.fetchOptimistic = function fetchOptimistic(options) {
2731
+ var _this4 = this;
2732
+
2733
+ var defaultedOptions = this.client.defaultQueryObserverOptions(options);
2734
+ var query = this.client.getQueryCache().build(this.client, defaultedOptions);
2735
+ return query.fetch().then(function () {
2736
+ return _this4.createResult(query, defaultedOptions);
2737
+ });
2738
+ };
2739
+
2740
+ _proto.fetch = function fetch(fetchOptions) {
2741
+ var _this5 = this;
2742
+
2743
+ return this.executeFetch(fetchOptions).then(function () {
2744
+ _this5.updateResult();
2745
+
2746
+ return _this5.currentResult;
2747
+ });
2748
+ };
2749
+
2750
+ _proto.executeFetch = function executeFetch(fetchOptions) {
2751
+ // Make sure we reference the latest query as the current one might have been removed
2752
+ this.updateQuery(); // Fetch
2753
+
2754
+ var promise = this.currentQuery.fetch(this.options, fetchOptions);
2755
+
2756
+ if (!(fetchOptions == null ? void 0 : fetchOptions.throwOnError)) {
2757
+ promise = promise.catch(noop);
2758
+ }
2759
+
2760
+ return promise;
2761
+ };
2762
+
2763
+ _proto.updateStaleTimeout = function updateStaleTimeout() {
2764
+ var _this6 = this;
2765
+
2766
+ this.clearStaleTimeout();
2767
+
2768
+ if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
2769
+ return;
2770
+ }
2771
+
2772
+ var time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
2773
+ // To mitigate this issue we always add 1 ms to the timeout.
2774
+
2775
+ var timeout = time + 1;
2776
+ this.staleTimeoutId = setTimeout(function () {
2777
+ if (!_this6.currentResult.isStale) {
2778
+ _this6.updateResult();
2779
+ }
2780
+ }, timeout);
2781
+ };
2782
+
2783
+ _proto.computeRefetchInterval = function computeRefetchInterval() {
2784
+ var _this$options$refetch;
2785
+
2786
+ 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;
2787
+ };
2788
+
2789
+ _proto.updateRefetchInterval = function updateRefetchInterval(nextInterval) {
2790
+ var _this7 = this;
2791
+
2792
+ this.clearRefetchInterval();
2793
+ this.currentRefetchInterval = nextInterval;
2794
+
2795
+ if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
2796
+ return;
2797
+ }
2798
+
2799
+ this.refetchIntervalId = setInterval(function () {
2800
+ if (_this7.options.refetchIntervalInBackground || focusManager.isFocused()) {
2801
+ _this7.executeFetch();
2802
+ }
2803
+ }, this.currentRefetchInterval);
2804
+ };
2805
+
2806
+ _proto.updateTimers = function updateTimers() {
2807
+ this.updateStaleTimeout();
2808
+ this.updateRefetchInterval(this.computeRefetchInterval());
2809
+ };
2810
+
2811
+ _proto.clearTimers = function clearTimers() {
2812
+ this.clearStaleTimeout();
2813
+ this.clearRefetchInterval();
2814
+ };
2815
+
2816
+ _proto.clearStaleTimeout = function clearStaleTimeout() {
2817
+ clearTimeout(this.staleTimeoutId);
2818
+ this.staleTimeoutId = undefined;
2819
+ };
2820
+
2821
+ _proto.clearRefetchInterval = function clearRefetchInterval() {
2822
+ clearInterval(this.refetchIntervalId);
2823
+ this.refetchIntervalId = undefined;
2824
+ };
2825
+
2826
+ _proto.createResult = function createResult(query, options) {
2827
+ var prevQuery = this.currentQuery;
2828
+ var prevOptions = this.options;
2829
+ var prevResult = this.currentResult;
2830
+ var prevResultState = this.currentResultState;
2831
+ var prevResultOptions = this.currentResultOptions;
2832
+ var queryChange = query !== prevQuery;
2833
+ var queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
2834
+ var prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
2835
+ var state = query.state;
2836
+ var dataUpdatedAt = state.dataUpdatedAt,
2837
+ error = state.error,
2838
+ errorUpdatedAt = state.errorUpdatedAt,
2839
+ isFetching = state.isFetching,
2840
+ status = state.status;
2841
+ var isPreviousData = false;
2842
+ var isPlaceholderData = false;
2843
+ var data; // Optimistically set result in fetching state if needed
2844
+
2845
+ if (options.optimisticResults) {
2846
+ var mounted = this.hasListeners();
2847
+ var fetchOnMount = !mounted && shouldFetchOnMount(query, options);
2848
+ var fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
2849
+
2850
+ if (fetchOnMount || fetchOptionally) {
2851
+ isFetching = true;
2852
+
2853
+ if (!dataUpdatedAt) {
2854
+ status = 'loading';
2855
+ }
2856
+ }
2857
+ } // Keep previous data if needed
2858
+
2859
+
2860
+ if (options.keepPreviousData && !state.dataUpdateCount && (prevQueryResult == null ? void 0 : prevQueryResult.isSuccess) && status !== 'error') {
2861
+ data = prevQueryResult.data;
2862
+ dataUpdatedAt = prevQueryResult.dataUpdatedAt;
2863
+ status = prevQueryResult.status;
2864
+ isPreviousData = true;
2865
+ } // Select data if needed
2866
+ else if (options.select && typeof state.data !== 'undefined') {
2867
+ // Memoize select result
2868
+ if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
2869
+ data = this.selectResult;
2870
+ } else {
2871
+ try {
2872
+ this.selectFn = options.select;
2873
+ data = options.select(state.data);
2874
+
2875
+ if (options.structuralSharing !== false) {
2876
+ data = replaceEqualDeep(prevResult == null ? void 0 : prevResult.data, data);
2877
+ }
2878
+
2879
+ this.selectResult = data;
2880
+ this.selectError = null;
2881
+ } catch (selectError) {
2882
+ getLogger().error(selectError);
2883
+ this.selectError = selectError;
2884
+ }
2885
+ }
2886
+ } // Use query data
2887
+ else {
2888
+ data = state.data;
2889
+ } // Show placeholder data if needed
2890
+
2891
+
2892
+ if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && (status === 'loading' || status === 'idle')) {
2893
+ var placeholderData; // Memoize placeholder data
2894
+
2895
+ if ((prevResult == null ? void 0 : prevResult.isPlaceholderData) && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
2896
+ placeholderData = prevResult.data;
2897
+ } else {
2898
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
2899
+
2900
+ if (options.select && typeof placeholderData !== 'undefined') {
2901
+ try {
2902
+ placeholderData = options.select(placeholderData);
2903
+
2904
+ if (options.structuralSharing !== false) {
2905
+ placeholderData = replaceEqualDeep(prevResult == null ? void 0 : prevResult.data, placeholderData);
2906
+ }
2907
+
2908
+ this.selectError = null;
2909
+ } catch (selectError) {
2910
+ getLogger().error(selectError);
2911
+ this.selectError = selectError;
2912
+ }
2913
+ }
2914
+ }
2915
+
2916
+ if (typeof placeholderData !== 'undefined') {
2917
+ status = 'success';
2918
+ data = placeholderData;
2919
+ isPlaceholderData = true;
2920
+ }
2921
+ }
2922
+
2923
+ if (this.selectError) {
2924
+ error = this.selectError;
2925
+ data = this.selectResult;
2926
+ errorUpdatedAt = Date.now();
2927
+ status = 'error';
2928
+ }
2929
+
2930
+ var result = {
2931
+ status: status,
2932
+ isLoading: status === 'loading',
2933
+ isSuccess: status === 'success',
2934
+ isError: status === 'error',
2935
+ isIdle: status === 'idle',
2936
+ data: data,
2937
+ dataUpdatedAt: dataUpdatedAt,
2938
+ error: error,
2939
+ errorUpdatedAt: errorUpdatedAt,
2940
+ failureCount: state.fetchFailureCount,
2941
+ errorUpdateCount: state.errorUpdateCount,
2942
+ isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
2943
+ isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
2944
+ isFetching: isFetching,
2945
+ isRefetching: isFetching && status !== 'loading',
2946
+ isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
2947
+ isPlaceholderData: isPlaceholderData,
2948
+ isPreviousData: isPreviousData,
2949
+ isRefetchError: status === 'error' && state.dataUpdatedAt !== 0,
2950
+ isStale: isStale(query, options),
2951
+ refetch: this.refetch,
2952
+ remove: this.remove
2953
+ };
2954
+ return result;
2955
+ };
2956
+
2957
+ _proto.shouldNotifyListeners = function shouldNotifyListeners(result, prevResult) {
2958
+ if (!prevResult) {
2959
+ return true;
2960
+ }
2961
+
2962
+ var _this$options = this.options,
2963
+ notifyOnChangeProps = _this$options.notifyOnChangeProps,
2964
+ notifyOnChangePropsExclusions = _this$options.notifyOnChangePropsExclusions;
2965
+
2966
+ if (!notifyOnChangeProps && !notifyOnChangePropsExclusions) {
2967
+ return true;
2968
+ }
2969
+
2970
+ if (notifyOnChangeProps === 'tracked' && !this.trackedProps.length) {
2971
+ return true;
2972
+ }
2973
+
2974
+ var includedProps = notifyOnChangeProps === 'tracked' ? this.trackedProps : notifyOnChangeProps;
2975
+ return Object.keys(result).some(function (key) {
2976
+ var typedKey = key;
2977
+ var changed = result[typedKey] !== prevResult[typedKey];
2978
+ var isIncluded = includedProps == null ? void 0 : includedProps.some(function (x) {
2979
+ return x === key;
2980
+ });
2981
+ var isExcluded = notifyOnChangePropsExclusions == null ? void 0 : notifyOnChangePropsExclusions.some(function (x) {
2982
+ return x === key;
2983
+ });
2984
+ return changed && !isExcluded && (!includedProps || isIncluded);
2985
+ });
2986
+ };
2987
+
2988
+ _proto.updateResult = function updateResult(notifyOptions) {
2989
+ var prevResult = this.currentResult;
2990
+ this.currentResult = this.createResult(this.currentQuery, this.options);
2991
+ this.currentResultState = this.currentQuery.state;
2992
+ this.currentResultOptions = this.options; // Only notify if something has changed
2993
+
2994
+ if (shallowEqualObjects(this.currentResult, prevResult)) {
2995
+ return;
2996
+ } // Determine which callbacks to trigger
2997
+
2998
+
2999
+ var defaultNotifyOptions = {
3000
+ cache: true
3001
+ };
3002
+
3003
+ if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && this.shouldNotifyListeners(this.currentResult, prevResult)) {
3004
+ defaultNotifyOptions.listeners = true;
3005
+ }
3006
+
3007
+ this.notify(_extends({}, defaultNotifyOptions, notifyOptions));
3008
+ };
3009
+
3010
+ _proto.updateQuery = function updateQuery() {
3011
+ var query = this.client.getQueryCache().build(this.client, this.options);
3012
+
3013
+ if (query === this.currentQuery) {
3014
+ return;
3015
+ }
3016
+
3017
+ var prevQuery = this.currentQuery;
3018
+ this.currentQuery = query;
3019
+ this.currentQueryInitialState = query.state;
3020
+ this.previousQueryResult = this.currentResult;
3021
+
3022
+ if (this.hasListeners()) {
3023
+ prevQuery == null ? void 0 : prevQuery.removeObserver(this);
3024
+ query.addObserver(this);
3025
+ }
3026
+ };
3027
+
3028
+ _proto.onQueryUpdate = function onQueryUpdate(action) {
3029
+ var notifyOptions = {};
3030
+
3031
+ if (action.type === 'success') {
3032
+ notifyOptions.onSuccess = true;
3033
+ } else if (action.type === 'error' && !isCancelledError(action.error)) {
3034
+ notifyOptions.onError = true;
3035
+ }
3036
+
3037
+ this.updateResult(notifyOptions);
3038
+
3039
+ if (this.hasListeners()) {
3040
+ this.updateTimers();
3041
+ }
3042
+ };
3043
+
3044
+ _proto.notify = function notify(notifyOptions) {
3045
+ var _this8 = this;
3046
+
3047
+ notifyManager.batch(function () {
3048
+ // First trigger the configuration callbacks
3049
+ if (notifyOptions.onSuccess) {
3050
+ _this8.options.onSuccess == null ? void 0 : _this8.options.onSuccess(_this8.currentResult.data);
3051
+ _this8.options.onSettled == null ? void 0 : _this8.options.onSettled(_this8.currentResult.data, null);
3052
+ } else if (notifyOptions.onError) {
3053
+ _this8.options.onError == null ? void 0 : _this8.options.onError(_this8.currentResult.error);
3054
+ _this8.options.onSettled == null ? void 0 : _this8.options.onSettled(undefined, _this8.currentResult.error);
3055
+ } // Then trigger the listeners
3056
+
3057
+
3058
+ if (notifyOptions.listeners) {
3059
+ _this8.listeners.forEach(function (listener) {
3060
+ listener(_this8.currentResult);
3061
+ });
3062
+ } // Then the cache listeners
3063
+
3064
+
3065
+ if (notifyOptions.cache) {
3066
+ _this8.client.getQueryCache().notify({
3067
+ query: _this8.currentQuery,
3068
+ type: 'observerResultsUpdated'
3069
+ });
3070
+ }
3071
+ });
3072
+ };
3073
+
3074
+ return QueryObserver;
3075
+ }(Subscribable);
3076
+
3077
+ function shouldLoadOnMount(query, options) {
3078
+ return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
3079
+ }
3080
+
3081
+ function shouldFetchOnMount(query, options) {
3082
+ return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
3083
+ }
3084
+
3085
+ function shouldFetchOn(query, options, field) {
3086
+ if (options.enabled !== false) {
3087
+ var value = typeof field === 'function' ? field(query) : field;
3088
+ return value === 'always' || value !== false && isStale(query, options);
3089
+ }
3090
+
3091
+ return false;
3092
+ }
3093
+
3094
+ function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
3095
+ return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
3096
+ }
3097
+
3098
+ function isStale(query, options) {
3099
+ return query.isStaleByTime(options.staleTime);
3100
+ }
3101
+
3102
+ // CLASS
3103
+ var MutationObserver = /*#__PURE__*/function (_Subscribable) {
3104
+ _inheritsLoose(MutationObserver, _Subscribable);
3105
+
3106
+ function MutationObserver(client, options) {
3107
+ var _this;
3108
+
3109
+ _this = _Subscribable.call(this) || this;
3110
+ _this.client = client;
3111
+
3112
+ _this.setOptions(options);
3113
+
3114
+ _this.bindMethods();
3115
+
3116
+ _this.updateResult();
3117
+
3118
+ return _this;
3119
+ }
3120
+
3121
+ var _proto = MutationObserver.prototype;
3122
+
3123
+ _proto.bindMethods = function bindMethods() {
3124
+ this.mutate = this.mutate.bind(this);
3125
+ this.reset = this.reset.bind(this);
3126
+ };
3127
+
3128
+ _proto.setOptions = function setOptions(options) {
3129
+ this.options = this.client.defaultMutationOptions(options);
3130
+ };
3131
+
3132
+ _proto.onUnsubscribe = function onUnsubscribe() {
3133
+ if (!this.listeners.length) {
3134
+ var _this$currentMutation;
3135
+
3136
+ (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.removeObserver(this);
3137
+ }
3138
+ };
3139
+
3140
+ _proto.onMutationUpdate = function onMutationUpdate(action) {
3141
+ this.updateResult(); // Determine which callbacks to trigger
3142
+
3143
+ var notifyOptions = {
3144
+ listeners: true
3145
+ };
3146
+
3147
+ if (action.type === 'success') {
3148
+ notifyOptions.onSuccess = true;
3149
+ } else if (action.type === 'error') {
3150
+ notifyOptions.onError = true;
3151
+ }
3152
+
3153
+ this.notify(notifyOptions);
3154
+ };
3155
+
3156
+ _proto.getCurrentResult = function getCurrentResult() {
3157
+ return this.currentResult;
3158
+ };
3159
+
3160
+ _proto.reset = function reset() {
3161
+ this.currentMutation = undefined;
3162
+ this.updateResult();
3163
+ this.notify({
3164
+ listeners: true
3165
+ });
3166
+ };
3167
+
3168
+ _proto.mutate = function mutate(variables, options) {
3169
+ this.mutateOptions = options;
3170
+
3171
+ if (this.currentMutation) {
3172
+ this.currentMutation.removeObserver(this);
3173
+ }
3174
+
3175
+ this.currentMutation = this.client.getMutationCache().build(this.client, _extends({}, this.options, {
3176
+ variables: typeof variables !== 'undefined' ? variables : this.options.variables
3177
+ }));
3178
+ this.currentMutation.addObserver(this);
3179
+ return this.currentMutation.execute();
3180
+ };
3181
+
3182
+ _proto.updateResult = function updateResult() {
3183
+ var state = this.currentMutation ? this.currentMutation.state : getDefaultState();
3184
+
3185
+ var result = _extends({}, state, {
3186
+ isLoading: state.status === 'loading',
3187
+ isSuccess: state.status === 'success',
3188
+ isError: state.status === 'error',
3189
+ isIdle: state.status === 'idle',
3190
+ mutate: this.mutate,
3191
+ reset: this.reset
3192
+ });
3193
+
3194
+ this.currentResult = result;
3195
+ };
3196
+
3197
+ _proto.notify = function notify(options) {
3198
+ var _this2 = this;
3199
+
3200
+ notifyManager.batch(function () {
3201
+ // First trigger the mutate callbacks
3202
+ if (_this2.mutateOptions) {
3203
+ if (options.onSuccess) {
3204
+ _this2.mutateOptions.onSuccess == null ? void 0 : _this2.mutateOptions.onSuccess(_this2.currentResult.data, _this2.currentResult.variables, _this2.currentResult.context);
3205
+ _this2.mutateOptions.onSettled == null ? void 0 : _this2.mutateOptions.onSettled(_this2.currentResult.data, null, _this2.currentResult.variables, _this2.currentResult.context);
3206
+ } else if (options.onError) {
3207
+ _this2.mutateOptions.onError == null ? void 0 : _this2.mutateOptions.onError(_this2.currentResult.error, _this2.currentResult.variables, _this2.currentResult.context);
3208
+ _this2.mutateOptions.onSettled == null ? void 0 : _this2.mutateOptions.onSettled(undefined, _this2.currentResult.error, _this2.currentResult.variables, _this2.currentResult.context);
3209
+ }
3210
+ } // Then trigger the listeners
3211
+
3212
+
3213
+ if (options.listeners) {
3214
+ _this2.listeners.forEach(function (listener) {
3215
+ listener(_this2.currentResult);
3216
+ });
3217
+ }
3218
+ });
3219
+ };
3220
+
3221
+ return MutationObserver;
3222
+ }(Subscribable);
3223
+
3224
+ var unstable_batchedUpdates = ReactDOM.unstable_batchedUpdates;
3225
+
3226
+ notifyManager.setBatchNotifyFunction(unstable_batchedUpdates);
3227
+
3228
+ var logger = console;
3229
+
3230
+ setLogger(logger);
3231
+
3232
+ var defaultContext = /*#__PURE__*/React.createContext(undefined);
3233
+ var QueryClientSharingContext = /*#__PURE__*/React.createContext(false); // if contextSharing is on, we share the first and at least one
3234
+ // instance of the context across the window
3235
+ // to ensure that if React Query is used across
3236
+ // different bundles or microfrontends they will
3237
+ // all use the same **instance** of context, regardless
3238
+ // of module scoping.
3239
+
3240
+ function getQueryClientContext(contextSharing) {
3241
+ if (contextSharing && typeof window !== 'undefined') {
3242
+ if (!window.ReactQueryClientContext) {
3243
+ window.ReactQueryClientContext = defaultContext;
3244
+ }
3245
+
3246
+ return window.ReactQueryClientContext;
3247
+ }
3248
+
3249
+ return defaultContext;
3250
+ }
3251
+
3252
+ var useQueryClient = function useQueryClient() {
3253
+ var queryClient = React.useContext(getQueryClientContext(React.useContext(QueryClientSharingContext)));
3254
+
3255
+ if (!queryClient) {
3256
+ throw new Error('No QueryClient set, use QueryClientProvider to set one');
3257
+ }
3258
+
3259
+ return queryClient;
3260
+ };
3261
+ var QueryClientProvider = function QueryClientProvider(_ref) {
3262
+ var client = _ref.client,
3263
+ _ref$contextSharing = _ref.contextSharing,
3264
+ contextSharing = _ref$contextSharing === void 0 ? false : _ref$contextSharing,
3265
+ children = _ref.children;
3266
+ React.useEffect(function () {
3267
+ client.mount();
3268
+ return function () {
3269
+ client.unmount();
3270
+ };
3271
+ }, [client]);
3272
+ var Context = getQueryClientContext(contextSharing);
3273
+ return /*#__PURE__*/React.createElement(QueryClientSharingContext.Provider, {
3274
+ value: contextSharing
3275
+ }, /*#__PURE__*/React.createElement(Context.Provider, {
3276
+ value: client
3277
+ }, children));
3278
+ };
3279
+
3280
+ function createValue() {
3281
+ var _isReset = false;
3282
+ return {
3283
+ clearReset: function clearReset() {
3284
+ _isReset = false;
3285
+ },
3286
+ reset: function reset() {
3287
+ _isReset = true;
3288
+ },
3289
+ isReset: function isReset() {
3290
+ return _isReset;
3291
+ }
3292
+ };
3293
+ }
3294
+
3295
+ var QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue()); // HOOK
3296
+
3297
+ var useQueryErrorResetBoundary = function useQueryErrorResetBoundary() {
3298
+ return React.useContext(QueryErrorResetBoundaryContext);
3299
+ }; // COMPONENT
3300
+
3301
+ function shouldThrowError(suspense, _useErrorBoundary, params) {
3302
+ // Allow useErrorBoundary function to override throwing behavior on a per-error basis
3303
+ if (typeof _useErrorBoundary === 'function') {
3304
+ return _useErrorBoundary.apply(void 0, params);
3305
+ } // Allow useErrorBoundary to override suspense's throwing behavior
3306
+
3307
+
3308
+ if (typeof _useErrorBoundary === 'boolean') return _useErrorBoundary; // If suspense is enabled default to throwing errors
3309
+
3310
+ return !!suspense;
3311
+ }
3312
+
3313
+ function useMutation(arg1, arg2, arg3) {
3314
+ var mountedRef = React.useRef(false);
3315
+
3316
+ var _React$useState = React.useState(0),
3317
+ forceUpdate = _React$useState[1];
3318
+
3319
+ var options = parseMutationArgs(arg1, arg2, arg3);
3320
+ var queryClient = useQueryClient();
3321
+ var obsRef = React.useRef();
3322
+
3323
+ if (!obsRef.current) {
3324
+ obsRef.current = new MutationObserver(queryClient, options);
3325
+ } else {
3326
+ obsRef.current.setOptions(options);
3327
+ }
3328
+
3329
+ var currentResult = obsRef.current.getCurrentResult();
3330
+ React.useEffect(function () {
3331
+ mountedRef.current = true;
3332
+ var unsubscribe = obsRef.current.subscribe(notifyManager.batchCalls(function () {
3333
+ if (mountedRef.current) {
3334
+ forceUpdate(function (x) {
3335
+ return x + 1;
3336
+ });
3337
+ }
3338
+ }));
3339
+ return function () {
3340
+ mountedRef.current = false;
3341
+ unsubscribe();
3342
+ };
3343
+ }, []);
3344
+ var mutate = React.useCallback(function (variables, mutateOptions) {
3345
+ obsRef.current.mutate(variables, mutateOptions).catch(noop);
3346
+ }, []);
3347
+
3348
+ if (currentResult.error && shouldThrowError(undefined, obsRef.current.options.useErrorBoundary, [currentResult.error])) {
3349
+ throw currentResult.error;
3350
+ }
3351
+
3352
+ return _extends({}, currentResult, {
3353
+ mutate: mutate,
3354
+ mutateAsync: currentResult.mutate
3355
+ });
3356
+ }
3357
+
3358
+ function useBaseQuery(options, Observer) {
3359
+ var mountedRef = React.useRef(false);
3360
+
3361
+ var _React$useState = React.useState(0),
3362
+ forceUpdate = _React$useState[1];
3363
+
3364
+ var queryClient = useQueryClient();
3365
+ var errorResetBoundary = useQueryErrorResetBoundary();
3366
+ var defaultedOptions = queryClient.defaultQueryObserverOptions(options); // Make sure results are optimistically set in fetching state before subscribing or updating options
3367
+
3368
+ defaultedOptions.optimisticResults = true; // Include callbacks in batch renders
3369
+
3370
+ if (defaultedOptions.onError) {
3371
+ defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
3372
+ }
3373
+
3374
+ if (defaultedOptions.onSuccess) {
3375
+ defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
3376
+ }
3377
+
3378
+ if (defaultedOptions.onSettled) {
3379
+ defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
3380
+ }
3381
+
3382
+ if (defaultedOptions.suspense) {
3383
+ // Always set stale time when using suspense to prevent
3384
+ // fetching again when directly mounting after suspending
3385
+ if (typeof defaultedOptions.staleTime !== 'number') {
3386
+ defaultedOptions.staleTime = 1000;
3387
+ } // Set cache time to 1 if the option has been set to 0
3388
+ // when using suspense to prevent infinite loop of fetches
3389
+
3390
+
3391
+ if (defaultedOptions.cacheTime === 0) {
3392
+ defaultedOptions.cacheTime = 1;
3393
+ }
3394
+ }
3395
+
3396
+ if (defaultedOptions.suspense || defaultedOptions.useErrorBoundary) {
3397
+ // Prevent retrying failed query if the error boundary has not been reset yet
3398
+ if (!errorResetBoundary.isReset()) {
3399
+ defaultedOptions.retryOnMount = false;
3400
+ }
3401
+ }
3402
+
3403
+ var _React$useState2 = React.useState(function () {
3404
+ return new Observer(queryClient, defaultedOptions);
3405
+ }),
3406
+ observer = _React$useState2[0];
3407
+
3408
+ var result = observer.getOptimisticResult(defaultedOptions);
3409
+ React.useEffect(function () {
3410
+ mountedRef.current = true;
3411
+ errorResetBoundary.clearReset();
3412
+ var unsubscribe = observer.subscribe(notifyManager.batchCalls(function () {
3413
+ if (mountedRef.current) {
3414
+ forceUpdate(function (x) {
3415
+ return x + 1;
3416
+ });
3417
+ }
3418
+ })); // Update result to make sure we did not miss any query updates
3419
+ // between creating the observer and subscribing to it.
3420
+
3421
+ observer.updateResult();
3422
+ return function () {
3423
+ mountedRef.current = false;
3424
+ unsubscribe();
3425
+ };
3426
+ }, [errorResetBoundary, observer]);
3427
+ React.useEffect(function () {
3428
+ // Do not notify on updates because of changes in the options because
3429
+ // these changes should already be reflected in the optimistic result.
3430
+ observer.setOptions(defaultedOptions, {
3431
+ listeners: false
3432
+ });
3433
+ }, [defaultedOptions, observer]); // Handle suspense
3434
+
3435
+ if (defaultedOptions.suspense && result.isLoading) {
3436
+ throw observer.fetchOptimistic(defaultedOptions).then(function (_ref) {
3437
+ var data = _ref.data;
3438
+ defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
3439
+ defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
3440
+ }).catch(function (error) {
3441
+ errorResetBoundary.clearReset();
3442
+ defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
3443
+ defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
3444
+ });
3445
+ } // Handle error boundary
3446
+
3447
+
3448
+ if (result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(defaultedOptions.suspense, defaultedOptions.useErrorBoundary, [result.error, observer.getCurrentQuery()])) {
3449
+ throw result.error;
3450
+ } // Handle result property usage tracking
3451
+
3452
+
3453
+ if (defaultedOptions.notifyOnChangeProps === 'tracked') {
3454
+ result = observer.trackResult(result, defaultedOptions);
3455
+ }
3456
+
3457
+ return result;
3458
+ }
3459
+
3460
+ function useQuery(arg1, arg2, arg3) {
3461
+ var parsedOptions = parseQueryArgs(arg1, arg2, arg3);
3462
+ return useBaseQuery(parsedOptions, QueryObserver);
3463
+ }
3464
+
3465
+ var fetch = function fetch(_ref) {
3466
+ var url = _ref.url,
3467
+ term = _ref.term,
3468
+ limit = _ref.limit,
3469
+ page_no = _ref.page_no;
3470
+ return axios.get(url, {
3471
+ params: {
3472
+ term: term,
3473
+ limit: limit,
3474
+ page_no: page_no
3475
+ }
3476
+ });
3477
+ };
3478
+
3479
+ var create = function create(url, payload) {
3480
+ return axios.post(url, payload);
3481
+ };
3482
+
3483
+ var update = function update(url, id, payload) {
3484
+ return axios.put("".concat(url, "/").concat(id), payload);
3485
+ };
3486
+
3487
+ var destroy = function destroy(url, id) {
3488
+ return axios["delete"]("".concat(url, "/").concat(id));
3489
+ };
3490
+
3491
+ var tagsApi = {
3492
+ fetch: fetch,
3493
+ create: create,
3494
+ update: update,
3495
+ destroy: destroy
3496
+ };
3497
+
3498
+ var queryClient = new QueryClient({
3499
+ queryCache: new QueryCache({
3500
+ onError: function onError(error) {
3501
+ return Toastr.error(error);
3502
+ }
3503
+ })
3504
+ });
3505
+
3506
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3507
+
3508
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3509
+ var TAG_KEY = "tag-key";
3510
+ var STALE_TIME = 3200000;
3511
+
3512
+ var useFetchTags = function useFetchTags(params) {
3513
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3514
+ return useQuery([TAG_KEY, Object.values(params)], function () {
3515
+ return tagsApi.fetch(params);
3516
+ }, _objectSpread({
3517
+ staleTime: STALE_TIME,
3518
+ select: function select(response) {
3519
+ return response.data || response;
3520
+ }
3521
+ }, options));
3522
+ };
3523
+
3524
+ var useCreateTag = function useCreateTag() {
3525
+ return useMutation(function (_ref) {
3526
+ var url = _ref.url,
3527
+ payload = _ref.payload;
3528
+ return tagsApi.create(url, payload);
3529
+ }, {
3530
+ onSuccess: function onSuccess() {
3531
+ queryClient.invalidateQueries([TAG_KEY]);
3532
+ }
3533
+ });
3534
+ };
3535
+
3536
+ var useUpdateTag = function useUpdateTag() {
3537
+ return useMutation(function (_ref2) {
3538
+ var url = _ref2.url,
3539
+ id = _ref2.id,
3540
+ payload = _ref2.payload;
3541
+ return tagsApi.update(url, id, payload);
3542
+ }, {
3543
+ onSuccess: function onSuccess() {
3544
+ queryClient.invalidateQueries([TAG_KEY]);
3545
+ }
3546
+ });
3547
+ };
3548
+
3549
+ var useDeleteTag = function useDeleteTag() {
3550
+ return useMutation(function (_ref3) {
3551
+ var url = _ref3.url,
3552
+ id = _ref3.id;
3553
+ return tagsApi.destroy(url, id);
3554
+ }, {
3555
+ onSuccess: function onSuccess() {
3556
+ queryClient.invalidateQueries([TAG_KEY]);
3557
+ }
3558
+ });
3559
+ };
3560
+
3561
+ var useTagsForm = function useTagsForm(_ref) {
3562
+ var isEdit = _ref.isEdit,
3563
+ tagType = _ref.tagType,
3564
+ onClose = _ref.onClose,
3565
+ goToFirstPage = _ref.goToFirstPage;
3566
+ var tagModification = isEdit ? useUpdateTag : useCreateTag;
3567
+
3568
+ var _tagModification = tagModification(),
3569
+ mutate = _tagModification.mutate,
3570
+ isSubmitting = _tagModification.isLoading;
3571
+
3572
+ var _useTranslation = useTranslation(),
3573
+ t = _useTranslation.t;
3574
+
3575
+ var handleSubmit = function handleSubmit(values, _ref2) {
3576
+ var _values$description;
3577
+
3578
+ var resetForm = _ref2.resetForm;
3579
+ values.description = values === null || values === void 0 ? void 0 : (_values$description = values.description) === null || _values$description === void 0 ? void 0 : _values$description.trim();
3580
+ var tagData = {
3581
+ payload: {
3582
+ tag: values
3583
+ }
3584
+ };
3585
+ tagData.url = tagType.url;
3586
+
3587
+ if (isEdit) {
3588
+ tagData.id = values.id;
3589
+ }
3590
+
3591
+ mutate(tagData, {
3592
+ onSuccess: function onSuccess() {
3593
+ !isEdit && goToFirstPage();
3594
+ onClose();
3595
+ Toastr.success(isEdit ? t("updateSuccess") : t("createSuccess"));
3596
+ },
3597
+ onError: function onError(_ref3) {
3598
+ var errors = _ref3.errors;
3599
+ resetForm();
3600
+ Toastr.error(errors === null || errors === void 0 ? void 0 : errors.join(", "));
3601
+ }
3602
+ });
3603
+ };
3604
+
3605
+ return {
3606
+ handleSubmit: handleSubmit,
3607
+ isSubmitting: isSubmitting
3608
+ };
3609
+ };
3610
+
3611
+ var ManageTags = function ManageTags(_ref) {
3612
+ var tag = _ref.tag,
3613
+ type = _ref.type,
3614
+ onClose = _ref.onClose,
3615
+ tagType = _ref.tagType,
3616
+ goToFirstPage = _ref.goToFirstPage;
3617
+ var isEdit = type === PANE_TYPES.EDIT;
3618
+ var initValues = isEdit ? tag : INITIAL_TAG_VALUES;
3619
+
3620
+ var _useTranslation = useTranslation(),
3621
+ t = _useTranslation.t;
3622
+
3623
+ var _useTagsForm = useTagsForm({
3624
+ isEdit: isEdit,
3625
+ tagType: tagType,
3626
+ onClose: onClose,
3627
+ goToFirstPage: goToFirstPage
3628
+ }),
3629
+ handleSubmit = _useTagsForm.handleSubmit;
3630
+
3631
+ return /*#__PURE__*/React.createElement(Pane, {
3632
+ isOpen: !!type,
3633
+ onClose: onClose
3634
+ }, /*#__PURE__*/React.createElement(Pane.Header, null, /*#__PURE__*/React.createElement(Typography, {
3635
+ style: "h2",
3636
+ weight: "semibold"
3637
+ }, isEdit ? t("editItem", {
3638
+ what: t("tag")
3639
+ }) : t("addNew", {
3640
+ what: t("tag")
3641
+ }))), /*#__PURE__*/React.createElement(Formik, {
3642
+ initialValues: initValues,
3643
+ validateOnBlur: false,
3644
+ validateOnChange: false,
3645
+ onSubmit: handleSubmit,
3646
+ validationSchema: TAG_SCHEMA
3647
+ }, function (_ref2) {
3648
+ var isSubmitting = _ref2.isSubmitting;
3649
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Pane.Body, null, /*#__PURE__*/React.createElement(Form, {
3650
+ className: "flex w-full flex-col space-y-4",
3651
+ noValidate: true
3652
+ }, /*#__PURE__*/React.createElement(Input, {
3653
+ required: true,
3654
+ autoFocus: true,
3655
+ name: "name",
3656
+ label: "".concat(t("tag"), " ").concat(t("name")),
3657
+ "data-cy": "tag-name-text-field",
3658
+ maxLength: 50
3659
+ }), /*#__PURE__*/React.createElement(Textarea, {
3660
+ name: "description",
3661
+ label: t("description"),
3662
+ rows: 3,
3663
+ "data-cy": "tag-description-text-area",
3664
+ maxLength: 255
3665
+ }))), /*#__PURE__*/React.createElement(Pane.Footer, {
3666
+ className: "flex items-center space-x-2"
3667
+ }, /*#__PURE__*/React.createElement(ActionBlock, {
3668
+ className: "flex items-center space-x-2",
3669
+ cancelButtonProps: {
3670
+ onClick: onClose
3671
+ },
3672
+ submitButtonProps: {
3673
+ loading: isSubmitting
3674
+ }
3675
+ })));
3676
+ }));
3677
+ };
3678
+
3679
+ var Menu = function Menu(_ref) {
3680
+ var tagTypes = _ref.tagTypes,
3681
+ showMenu = _ref.showMenu,
3682
+ tagType = _ref.tagType,
3683
+ setTagType = _ref.setTagType;
3684
+
3685
+ var _useTranslation = useTranslation(),
3686
+ t = _useTranslation.t;
3687
+
3688
+ return /*#__PURE__*/React.createElement(MenuBar, {
3689
+ showMenu: showMenu,
3690
+ title: t("title")
3691
+ }, Object.values(tagTypes).map(function (tag) {
3692
+ return /*#__PURE__*/React.createElement(MenuBar.Item, {
3693
+ key: tag.id,
3694
+ label: tag.label,
3695
+ description: tag.description,
3696
+ active: tagType.id === tag.id,
3697
+ onClick: function onClick() {
3698
+ setTagType(tag);
3699
+ }
3700
+ });
3701
+ }));
3702
+ };
3703
+
3704
+ var renderColumnData = function renderColumnData(columns, handleEdit, handleDelete) {
3705
+ return [].concat(_toConsumableArray(columns), [{
3706
+ id: "actions",
3707
+ width: "10%",
3708
+ render: function render(_, tag) {
3709
+ return /*#__PURE__*/React.createElement(Dropdown, {
3710
+ icon: MenuHorizontal,
3711
+ buttonProps: {
3712
+ style: "text"
3713
+ },
3714
+ position: "bottom-end",
3715
+ autoWidth: true,
3716
+ strategy: "fixed"
3717
+ }, /*#__PURE__*/React.createElement("li", {
3718
+ className: "neeto-tag-dropdown__item"
3719
+ }, /*#__PURE__*/React.createElement(Button, {
3720
+ onClick: function onClick() {
3721
+ return handleEdit(tag);
3722
+ },
3723
+ label: "Edit",
3724
+ style: "text",
3725
+ className: "neeto-tag-dropdown__button"
3726
+ })), /*#__PURE__*/React.createElement("li", {
3727
+ className: "neeto-tag-dropdown__item"
3728
+ }, /*#__PURE__*/React.createElement(Button, {
3729
+ label: "Delete",
3730
+ onClick: function onClick() {
3731
+ return handleDelete(tag);
3732
+ },
3733
+ style: "danger-text",
3734
+ className: "neeto-tag-dropdown__button",
3735
+ "data-cy": "tags-delete-button"
3736
+ })));
3737
+ }
3738
+ }]);
3739
+ };
3740
+
3741
+ var devtools = {exports: {}};
3742
+
3743
+ {
3744
+ devtools.exports = {
3745
+ ReactQueryDevtools: function () {
3746
+ return null
3747
+ },
3748
+ ReactQueryDevtoolsPanel: function () {
3749
+ return null
3750
+ },
3751
+ };
3752
+ }
3753
+
3754
+ var withReactQuery = function withReactQuery(Component) {
3755
+ var QueryWrapper = function QueryWrapper(props) {
3756
+ return /*#__PURE__*/React.createElement(QueryClientProvider, {
3757
+ client: queryClient
3758
+ }, /*#__PURE__*/React.createElement(Component, props), /*#__PURE__*/React.createElement(devtools.exports.ReactQueryDevtools, {
3759
+ initialIsOpen: false,
3760
+ position: "bottom-right"
3761
+ }));
3762
+ };
3763
+
3764
+ return QueryWrapper;
3765
+ };
3766
+
3767
+ function useDebounce(value, delay) {
3768
+ var _useState = useState(value),
3769
+ _useState2 = _slicedToArray(_useState, 2),
3770
+ debouncedValue = _useState2[0],
3771
+ setDebouncedValue = _useState2[1];
3772
+
3773
+ useEffect(function () {
3774
+ var timer = setTimeout(function () {
3775
+ return setDebouncedValue(value);
3776
+ }, delay || 500);
3777
+ return function () {
3778
+ clearTimeout(timer);
3779
+ };
3780
+ }, [value, delay]);
3781
+ return debouncedValue;
3782
+ }
3783
+
3784
+ var Tags = function Tags(_ref) {
3785
+ var tagTypes = _ref.tagTypes,
3786
+ breadcrumbs = _ref.breadcrumbs,
3787
+ displayMenu = _ref.displayMenu;
3788
+
3789
+ var _useState = useState(tagTypes[0]),
3790
+ _useState2 = _slicedToArray(_useState, 2),
3791
+ tagType = _useState2[0],
3792
+ setTagType = _useState2[1];
3793
+
3794
+ var _useState3 = useState(null),
3795
+ _useState4 = _slicedToArray(_useState3, 2),
3796
+ selectedTag = _useState4[0],
3797
+ setSelectedTag = _useState4[1];
3798
+
3799
+ var _useState5 = useState(""),
3800
+ _useState6 = _slicedToArray(_useState5, 2),
3801
+ searchTerm = _useState6[0],
3802
+ setSearchTerm = _useState6[1];
3803
+
3804
+ var _useState7 = useState(DEFAULT_PAGE_INDEX),
3805
+ _useState8 = _slicedToArray(_useState7, 2),
3806
+ pageIndex = _useState8[0],
3807
+ setPageIndex = _useState8[1];
3808
+
3809
+ var _useState9 = useState(true),
3810
+ _useState10 = _slicedToArray(_useState9, 2),
3811
+ isMenuOpen = _useState10[0],
3812
+ setIsMenuOpen = _useState10[1];
3813
+
3814
+ var _useState11 = useState(null),
3815
+ _useState12 = _slicedToArray(_useState11, 2),
3816
+ paneType = _useState12[0],
3817
+ setPaneType = _useState12[1];
3818
+
3819
+ var _useState13 = useState(false),
3820
+ _useState14 = _slicedToArray(_useState13, 2),
3821
+ isDeleteAlertOpen = _useState14[0],
3822
+ setIsDeleteAlertOpen = _useState14[1];
3823
+
3824
+ var debouncedSearchTerm = useDebounce(searchTerm, 500);
3825
+
3826
+ var _useFetchTags = useFetchTags({
3827
+ url: tagType.url,
3828
+ term: debouncedSearchTerm,
3829
+ limit: DEFAULT_PAGE_SIZE,
3830
+ page_no: pageIndex
3831
+ }),
3832
+ data = _useFetchTags.data,
3833
+ isLoading = _useFetchTags.isLoading;
3834
+
3835
+ var _useTranslation = useTranslation(),
3836
+ t = _useTranslation.t;
3837
+
3838
+ var handleMenuToggle = function handleMenuToggle() {
3839
+ return setIsMenuOpen(function (isMenuOpen) {
3840
+ return !isMenuOpen;
3841
+ });
3842
+ };
3843
+
3844
+ var goToFirstPage = function goToFirstPage() {
3845
+ if (pageIndex !== DEFAULT_PAGE_INDEX) {
3846
+ setPageIndex(DEFAULT_PAGE_INDEX);
3847
+ }
3848
+ };
3849
+
3850
+ var handleEdit = function handleEdit(tag) {
3851
+ setSelectedTag(tag);
3852
+ setPaneType(PANE_TYPES.EDIT);
3853
+ };
3854
+
3855
+ var handleDelete = function handleDelete(tag) {
3856
+ setSelectedTag(tag);
3857
+ setIsDeleteAlertOpen(true);
3858
+ };
3859
+
3860
+ var handleAlertClose = function handleAlertClose() {
3861
+ setIsDeleteAlertOpen(false);
3862
+ setSelectedTag(null);
3863
+ };
3864
+
3865
+ var _useDeleteTag = useDeleteTag(),
3866
+ mutate = _useDeleteTag.mutate;
3867
+
3868
+ var handleConfirmDelete = function handleConfirmDelete() {
3869
+ var payload = {
3870
+ url: tagType.url,
3871
+ id: selectedTag === null || selectedTag === void 0 ? void 0 : selectedTag.id
3872
+ };
3873
+ mutate(payload, {
3874
+ onSuccess: function onSuccess() {
3875
+ setIsDeleteAlertOpen(false);
3876
+
3877
+ if (data.tags.length === 1) {
3878
+ setPageIndex(function (pageIndex) {
3879
+ return pageIndex - 1;
3880
+ });
3881
+ }
3882
+
3883
+ Toastr.success(t("deleteSuccess"));
3884
+ },
3885
+ onError: function onError(_ref2) {
3886
+ var errors = _ref2.errors;
3887
+ Toastr.error(errors === null || errors === void 0 ? void 0 : errors.join(", "));
3888
+ }
3889
+ });
3890
+ };
3891
+
3892
+ if (isLoading) {
3893
+ return /*#__PURE__*/React.createElement("div", {
3894
+ className: "w-full h-screen"
3895
+ }, /*#__PURE__*/React.createElement(PageLoader, null));
3896
+ }
3897
+
3898
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
3899
+ className: "neeto-tag-wrapper"
3900
+ }, displayMenu && /*#__PURE__*/React.createElement(Menu, {
3901
+ tagTypes: tagTypes,
3902
+ showMenu: isMenuOpen,
3903
+ tagType: tagType,
3904
+ setTagType: setTagType
3905
+ }), /*#__PURE__*/React.createElement(Container, null, /*#__PURE__*/React.createElement(Header, {
3906
+ title: "".concat(tagType.label, " ").concat(t("title")),
3907
+ menuBarToggle: displayMenu ? handleMenuToggle : null,
3908
+ searchProps: {
3909
+ value: searchTerm,
3910
+ onChange: function onChange(_ref3) {
3911
+ var value = _ref3.target.value;
3912
+ value.trim() && goToFirstPage();
3913
+ setSearchTerm(value);
3914
+ },
3915
+ placeholder: t("search", {
3916
+ where: t("title")
3917
+ })
3918
+ },
3919
+ actionBlock: /*#__PURE__*/React.createElement(Button, {
3920
+ icon: Plus,
3921
+ size: "large",
3922
+ label: t("addNew", {
3923
+ what: t("tag")
3924
+ }),
3925
+ onClick: function onClick() {
3926
+ setSelectedTag(null);
3927
+ setPaneType(PANE_TYPES.CREATE);
3928
+ },
3929
+ "data-cy": "add-new-tag-button"
3930
+ }),
3931
+ breadcrumbs: breadcrumbs
3932
+ }), isLoading ? /*#__PURE__*/React.createElement(PageLoader, null) : /*#__PURE__*/React.createElement("div", {
3933
+ className: "w-full flex-grow"
3934
+ }, /*#__PURE__*/React.createElement(SubHeader, {
3935
+ leftActionBlock: /*#__PURE__*/React.createElement(Typography, {
3936
+ component: "h4",
3937
+ className: "neeto-ui-gray-800 font-semibold"
3938
+ }, "".concat(data.tags.length, " ").concat(tagType.label, " Tag(s)"))
3939
+ }), /*#__PURE__*/React.createElement("div", {
3940
+ className: "neeto-tags--table__wrapper"
3941
+ }, /*#__PURE__*/React.createElement(Table, {
3942
+ fixedHeight: true,
3943
+ rowData: data.tags,
3944
+ columnData: renderColumnData(tagType.columns ? [].concat(_toConsumableArray(COMMON_COLUMNS), _toConsumableArray(tagType.columns)) : COMMON_COLUMNS, handleEdit, handleDelete),
3945
+ defaultPageSize: DEFAULT_PAGE_SIZE,
3946
+ currentPageNumber: pageIndex,
3947
+ handlePageChange: setPageIndex,
3948
+ totalCount: data.tags.length,
3949
+ allowRowClick: false,
3950
+ rowSelection: false,
3951
+ paginationProps: {
3952
+ showSizeChanger: false
3953
+ },
3954
+ scroll: {
3955
+ x: "100%"
3956
+ }
3957
+ }))))), /*#__PURE__*/React.createElement(ManageTags, {
3958
+ type: paneType,
3959
+ tagType: tagType,
3960
+ tag: selectedTag,
3961
+ onClose: function onClose() {
3962
+ return setPaneType(null);
3963
+ },
3964
+ goToFirstPage: goToFirstPage
3965
+ }), /*#__PURE__*/React.createElement(Alert, {
3966
+ isOpen: isDeleteAlertOpen,
3967
+ title: "".concat(t("delete"), " ").concat(selectedTag === null || selectedTag === void 0 ? void 0 : selectedTag.name),
3968
+ message: /*#__PURE__*/React.createElement(React.Fragment, null, t("deleteItem", {
3969
+ type: t("tag")
3970
+ }), " ", /*#__PURE__*/React.createElement("strong", null, selectedTag === null || selectedTag === void 0 ? void 0 : selectedTag.name), "? ", t("cannotBeUndone")),
3971
+ onSubmit: handleConfirmDelete,
3972
+ onClose: handleAlertClose,
3973
+ submitButtonLabel: t("proceed"),
3974
+ cancelButtonLabel: t("cancel")
3975
+ }));
3976
+ };
3977
+
3978
+ var Tags$1 = withReactQuery(Tags);
3979
+
3980
+ var App = function App(_ref) {
3981
+ var tagTypes = _ref.tagTypes,
3982
+ breadcrumbs = _ref.breadcrumbs,
3983
+ _ref$displayMenu = _ref.displayMenu,
3984
+ displayMenu = _ref$displayMenu === void 0 ? true : _ref$displayMenu;
3985
+ return /*#__PURE__*/React.createElement(Tags$1, {
3986
+ tagTypes: tagTypes,
3987
+ breadcrumbs: breadcrumbs,
3988
+ displayMenu: displayMenu
3989
+ });
3990
+ };
3991
+
3992
+ export { App as NeetoTags };
4
3993
  //# sourceMappingURL=index.js.map