@standardbeagle/data-router 1.1.0

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.
@@ -0,0 +1,11 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["@standardbeagle/data-router"]={},e.React)}(this,function(e,t){"use strict";var r,n=Object.defineProperty,a=(e,t,r)=>(((e,t,r)=>{t in e?n(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r})(e,"symbol"!=typeof t?t+"":t,r),r),o={exports:{}},s={};var i,u={};
2
+ /**
3
+ * @license React
4
+ * react-jsx-runtime.development.js
5
+ *
6
+ * Copyright (c) Facebook, Inc. and its affiliates.
7
+ *
8
+ * This source code is licensed under the MIT license found in the
9
+ * LICENSE file in the root directory of this source tree.
10
+ */"production"===process.env.NODE_ENV?o.exports=function(){if(r)return s;r=1;var e=t,n=Symbol.for("react.element"),a=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function c(e,t,r){var a,s={},c=null,l=null;for(a in void 0!==r&&(c=""+r),void 0!==t.key&&(c=""+t.key),void 0!==t.ref&&(l=t.ref),t)o.call(t,a)&&!u.hasOwnProperty(a)&&(s[a]=t[a]);if(e&&e.defaultProps)for(a in t=e.defaultProps)void 0===s[a]&&(s[a]=t[a]);return{$$typeof:n,type:e,key:c,ref:l,props:s,_owner:i.current}}return s.Fragment=a,s.jsx=c,s.jsxs=c,s}():o.exports=(i||(i=1,"production"!==process.env.NODE_ENV&&function(){var e,r=t,n=Symbol.for("react.element"),a=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),c=Symbol.for("react.provider"),l=Symbol.for("react.context"),p=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),f=Symbol.for("react.suspense_list"),y=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),m=Symbol.for("react.offscreen"),g=Symbol.iterator,v=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function b(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];!function(e,t,r){var n=v.ReactDebugCurrentFrame.getStackAddendum();""!==n&&(t+="%s",r=r.concat([n]));var a=r.map(function(e){return String(e)});a.unshift("Warning: "+t),Function.prototype.apply.call(console[e],console,a)}("error",e,r)}function x(e){return e.displayName||"Context"}function w(e){if(null==e)return null;if("number"==typeof e.tag&&b("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),"function"==typeof e)return e.displayName||e.name||null;if("string"==typeof e)return e;switch(e){case o:return"Fragment";case a:return"Portal";case i:return"Profiler";case s:return"StrictMode";case d:return"Suspense";case f:return"SuspenseList"}if("object"==typeof e)switch(e.$$typeof){case l:return x(e)+".Consumer";case c:return x(e._context)+".Provider";case p:return function(e,t,r){var n=e.displayName;if(n)return n;var a=t.displayName||t.name||"";return""!==a?r+"("+a+")":r}(e,e.render,"ForwardRef");case y:var t=e.displayName||null;return null!==t?t:w(e.type)||"Memo";case h:var r=e,n=r._payload,u=r._init;try{return w(u(n))}catch(m){return null}}return null}e=Symbol.for("react.module.reference");var C,E,S,O,A,k,_,D=Object.assign,P=0;function j(){}j.__reactDisabledLog=!0;var R,q=v.ReactCurrentDispatcher;function I(e,t,r){if(void 0===R)try{throw Error()}catch(a){var n=a.stack.trim().match(/\n( *(at )?)/);R=n&&n[1]||""}return"\n"+R+e}var T,$=!1,N="function"==typeof WeakMap?WeakMap:Map;function U(e,t){if(!e||$)return"";var r,n=T.get(e);if(void 0!==n)return n;$=!0;var a,o=Error.prepareStackTrace;Error.prepareStackTrace=void 0,a=q.current,q.current=null,function(){if(0===P){C=console.log,E=console.info,S=console.warn,O=console.error,A=console.group,k=console.groupCollapsed,_=console.groupEnd;var e={configurable:!0,enumerable:!0,value:j,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}P++}();try{if(t){var s=function(){throw Error()};if(Object.defineProperty(s.prototype,"props",{set:function(){throw Error()}}),"object"==typeof Reflect&&Reflect.construct){try{Reflect.construct(s,[])}catch(y){r=y}Reflect.construct(e,[],s)}else{try{s.call()}catch(y){r=y}e.call(s.prototype)}}else{try{throw Error()}catch(y){r=y}e()}}catch(h){if(h&&r&&"string"==typeof h.stack){for(var i=h.stack.split("\n"),u=r.stack.split("\n"),c=i.length-1,l=u.length-1;c>=1&&l>=0&&i[c]!==u[l];)l--;for(;c>=1&&l>=0;c--,l--)if(i[c]!==u[l]){if(1!==c||1!==l)do{if(c--,--l<0||i[c]!==u[l]){var p="\n"+i[c].replace(" at new "," at ");return e.displayName&&p.includes("<anonymous>")&&(p=p.replace("<anonymous>",e.displayName)),"function"==typeof e&&T.set(e,p),p}}while(c>=1&&l>=0);break}}}finally{$=!1,q.current=a,function(){if(0===--P){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:D({},e,{value:C}),info:D({},e,{value:E}),warn:D({},e,{value:S}),error:D({},e,{value:O}),group:D({},e,{value:A}),groupCollapsed:D({},e,{value:k}),groupEnd:D({},e,{value:_})})}P<0&&b("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}(),Error.prepareStackTrace=o}var d=e?e.displayName||e.name:"",f=d?I(d):"";return"function"==typeof e&&T.set(e,f),f}function M(e,t,r){if(null==e)return"";if("function"==typeof e)return U(e,!(!(n=e.prototype)||!n.isReactComponent));var n;if("string"==typeof e)return I(e);switch(e){case d:return I("Suspense");case f:return I("SuspenseList")}if("object"==typeof e)switch(e.$$typeof){case p:return U(e.render,!1);case y:return M(e.type,t,r);case h:var a=e,o=a._payload,s=a._init;try{return M(s(o),t,r)}catch(i){}}return""}T=new N;var Q=Object.prototype.hasOwnProperty,L={},F=v.ReactDebugCurrentFrame;function W(e){if(e){var t=e._owner,r=M(e.type,e._source,t?t.type:null);F.setExtraStackFrame(r)}else F.setExtraStackFrame(null)}var Y=Array.isArray;function B(e){return Y(e)}function z(e){return""+e}function X(e){if(function(e){try{return z(e),!1}catch(t){return!0}}(e))return b("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",function(e){return"function"==typeof Symbol&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object"}(e)),z(e)}var V,G,K,H=v.ReactCurrentOwner,Z={key:!0,ref:!0,__self:!0,__source:!0};function J(e,t,r,a,o){var s,i={},u=null,c=null;for(s in void 0!==r&&(X(r),u=""+r),function(e){if(Q.call(e,"key")){var t=Object.getOwnPropertyDescriptor(e,"key").get;if(t&&t.isReactWarning)return!1}return void 0!==e.key}(t)&&(X(t.key),u=""+t.key),function(e){if(Q.call(e,"ref")){var t=Object.getOwnPropertyDescriptor(e,"ref").get;if(t&&t.isReactWarning)return!1}return void 0!==e.ref}(t)&&(c=t.ref,function(e,t){if("string"==typeof e.ref&&H.current&&t&&H.current.stateNode!==t){var r=w(H.current.type);K[r]||(b('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref',w(H.current.type),e.ref),K[r]=!0)}}(t,o)),t)Q.call(t,s)&&!Z.hasOwnProperty(s)&&(i[s]=t[s]);if(e&&e.defaultProps){var l=e.defaultProps;for(s in l)void 0===i[s]&&(i[s]=l[s])}if(u||c){var p="function"==typeof e?e.displayName||e.name||"Unknown":e;u&&function(e,t){var r=function(){V||(V=!0,b("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"key",{get:r,configurable:!0})}(i,p),c&&function(e,t){var r=function(){G||(G=!0,b("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",t))};r.isReactWarning=!0,Object.defineProperty(e,"ref",{get:r,configurable:!0})}(i,p)}return function(e,t,r,a,o,s,i){var u={$$typeof:n,type:e,key:t,ref:r,props:i,_owner:s,_store:{}};return Object.defineProperty(u._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(u,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(u,"_source",{configurable:!1,enumerable:!1,writable:!1,value:o}),Object.freeze&&(Object.freeze(u.props),Object.freeze(u)),u}(e,u,c,o,a,H.current,i)}K={};var ee,te=v.ReactCurrentOwner,re=v.ReactDebugCurrentFrame;function ne(e){if(e){var t=e._owner,r=M(e.type,e._source,t?t.type:null);re.setExtraStackFrame(r)}else re.setExtraStackFrame(null)}function ae(e){return"object"==typeof e&&null!==e&&e.$$typeof===n}function oe(){if(te.current){var e=w(te.current.type);if(e)return"\n\nCheck the render method of `"+e+"`."}return""}ee=!1;var se={};function ie(e,t){if(e._store&&!e._store.validated&&null==e.key){e._store.validated=!0;var r=function(e){var t=oe();if(!t){var r="string"==typeof e?e:e.displayName||e.name;r&&(t="\n\nCheck the top-level render call using <"+r+">.")}return t}(t);if(!se[r]){se[r]=!0;var n="";e&&e._owner&&e._owner!==te.current&&(n=" It was passed a child from "+w(e._owner.type)+"."),ne(e),b('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',r,n),ne(null)}}}function ue(e,t){if("object"==typeof e)if(B(e))for(var r=0;r<e.length;r++){var n=e[r];ae(n)&&ie(n,t)}else if(ae(e))e._store&&(e._store.validated=!0);else if(e){var a=function(e){if(null===e||"object"!=typeof e)return null;var t=g&&e[g]||e["@@iterator"];return"function"==typeof t?t:null}(e);if("function"==typeof a&&a!==e.entries)for(var o,s=a.call(e);!(o=s.next()).done;)ae(o.value)&&ie(o.value,t)}}function ce(e){var t,r=e.type;if(null!=r&&"string"!=typeof r){if("function"==typeof r)t=r.propTypes;else{if("object"!=typeof r||r.$$typeof!==p&&r.$$typeof!==y)return;t=r.propTypes}if(t){var n=w(r);!function(e,t,r,n,a){var o=Function.call.bind(Q);for(var s in e)if(o(e,s)){var i=void 0;try{if("function"!=typeof e[s]){var u=Error((n||"React class")+": "+r+" type `"+s+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[s]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw u.name="Invariant Violation",u}i=e[s](t,s,n,r,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(c){i=c}!i||i instanceof Error||(W(a),b("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",n||"React class",r,s,typeof i),W(null)),i instanceof Error&&!(i.message in L)&&(L[i.message]=!0,W(a),b("Failed %s type: %s",r,i.message),W(null))}}(t,e.props,"prop",n,e)}else void 0===r.PropTypes||ee||(ee=!0,b("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",w(r)||"Unknown"));"function"!=typeof r.getDefaultProps||r.getDefaultProps.isReactClassApproved||b("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function le(t,r,a,u,g,v){var x=function(t){return"string"==typeof t||"function"==typeof t||t===o||t===i||t===s||t===d||t===f||t===m||"object"==typeof t&&null!==t&&(t.$$typeof===h||t.$$typeof===y||t.$$typeof===c||t.$$typeof===l||t.$$typeof===p||t.$$typeof===e||void 0!==t.getModuleId)}(t);if(!x){var C="";(void 0===t||"object"==typeof t&&null!==t&&0===Object.keys(t).length)&&(C+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var E,S=function(e){return void 0!==e?"\n\nCheck your code at "+e.fileName.replace(/^.*[\\\/]/,"")+":"+e.lineNumber+".":""}(g);C+=S||oe(),null===t?E="null":B(t)?E="array":void 0!==t&&t.$$typeof===n?(E="<"+(w(t.type)||"Unknown")+" />",C=" Did you accidentally export a JSX literal instead of a component?"):E=typeof t,b("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",E,C)}var O=J(t,r,a,g,v);if(null==O)return O;if(x){var A=r.children;if(void 0!==A)if(u)if(B(A)){for(var k=0;k<A.length;k++)ue(A[k],t);Object.freeze&&Object.freeze(A)}else b("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else ue(A,t)}return t===o?function(e){for(var t=Object.keys(e.props),r=0;r<t.length;r++){var n=t[r];if("children"!==n&&"key"!==n){ne(e),b("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),ne(null);break}}null!==e.ref&&(ne(e),b("Invalid attribute `ref` supplied to `React.Fragment`."),ne(null))}(O):ce(O),O}var pe=function(e,t,r){return le(e,t,r,!1)},de=function(e,t,r){return le(e,t,r,!0)};u.Fragment=o,u.jsx=pe,u.jsxs=de}()),u);var c=o.exports;function l(e,t,...r){if(void 0===t)throw new Error("invariant requires an error message argument");if(!e){let e;if(void 0===t)e=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{let n=0;e=new Error(t.replace(/%s/g,function(){return r[n++]})),e.name="Invariant Violation"}throw e.framesToPop=1,e}}const p=e=>"function"==typeof e,d=e=>e.toString(),f=e=>"string"==typeof e,y="||",h=e=>e,m=e=>null===e;function g(e,t=h,r){l(p(t)||m(t),"Expected payloadCreator to be a function, undefined or null");const n=m(t)||t===h?h:(e,...r)=>e instanceof Error?e:t(e,...r),a=p(r),o=e.toString(),s=(...t)=>{const o=n(...t),s={type:e};return o instanceof Error&&(s.error=!0),void 0!==o&&(s.payload=o),a&&(s.meta=r(...t)),s};return s.toString=()=>o,s}const v=e=>{if("object"!=typeof e||null===e)return!1;let t=e;for(;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t},b=e=>Array.isArray(e),x=e=>null==e,w=/\s/,C=/([-.:_])/,E=/([a-z][A-Z]|[A-Z][a-z])/,S=/[\W_]+(.|$)/g,O=/(.)([A-Z]+)/g,A=e=>w.test(e)?e.toLowerCase():C.test(e)?((e=>e.replace(S,(e,t)=>t?" "+t:""))(e)||e).toLowerCase():E.test(e)?(e=>e.replace(O,(e,t,r)=>t+" "+r.toLowerCase().split("").join(" ")))(e).toLowerCase():e.toLowerCase(),k=e=>(e=>A(e).replace(/[\W_]+(.|$)/g,(e,t)=>t?" "+t:"").trim())(e).replace(/\s(\w)/g,(e,t)=>t.toUpperCase()),_=e=>e.includes("/")?e.split("/").map(k).join("/"):k(e),D=(e,t)=>e.reduce((e,r)=>t(e,r),{}),P=e=>typeof Map<"u"&&e instanceof Map;function j(e){if(P(e))return Array.from(e.keys());if(typeof Reflect<"u"&&"function"==typeof Reflect.ownKeys)return Reflect.ownKeys(e);let t=Object.getOwnPropertyNames(e);return"function"==typeof Object.getOwnPropertySymbols&&(t=t.concat(Object.getOwnPropertySymbols(e))),t}function R(e,t){return P(t)?t.get(e):t[e]}const q=e=>function t(r,{namespace:n="/",prefix:a}={},o={},s=""){return j(r).forEach(i=>{const u=function(e){return s||!a||a&&new RegExp(`^${a}${n}`).test(e)?e:`${a}${n}${e}`}(function(e){if(!s)return e;const t=e.toString().split(y),r=s.split(y);return[].concat(...r.map(e=>t.map(t=>`${e}${n}${t}`))).join(y)}(i)),c=R(i,r);e(c)?t(c,{namespace:n,prefix:a},o,u):o[u]=c}),o},I=q(v);function T(e,{namespace:t="/",prefix:r}={}){function n(t,r,a){const o=_(a.shift());(e=>0===e.length)(a)?r[o]=e[t]:(r[o]||(r[o]={}),n(t,r[o],a))}const a={};return Object.getOwnPropertyNames(e).forEach(e=>{const o=r?e.replace(`${r}${t}`,""):e;return n(e,a,o.split(t))}),a}function $(e,t){return T(N(I(e,t)),t)}function N(e,{prefix:t,namespace:r="/"}={}){return D(Object.keys(e),(n,a)=>{const o=e[a];l(function(e){if(p(e)||x(e))return!0;if(b(e)){const[t=h,r]=e;return p(t)&&p(r)}return!1}(o),`Expected function, undefined, null, or array with payload and meta functions for ${a}`);const s=t?`${t}${r}${a}`:a,i=b(o)?g(s,...o):g(s,o);return{...n,[a]:i}})}function U(e,t){const r=N(D(e,(e,t)=>({...e,[t]:h})),t);return D(Object.keys(r),(e,t)=>({...e,[_(t)]:r[t]}))}const M=q(e=>(v(e)||P(e))&&!function(e){const t=j(e),r=t.every(e=>"next"===e||"throw"===e);return t.length>0&&t.length<=2&&r}(e));function Q(e){if(!e||"/"===e)return[];return(e.startsWith("/")?e.slice(1):e).split("/").filter(e=>e.length>0).map(e=>{const t=e.match(/^(.+)\[(\d+)\]$/);return t?{property:t[1],index:parseInt(t[2],10),isArray:!0}:{property:e}})}function L(e,t){if(t.startsWith("/"))return t;if(".."===t){const t=Q(e);if(0===t.length)return"/";const r=t.slice(0,-1).map(F).join("/");return""===r?"/":"/"+r}if(t.startsWith("../")){const r=(t.match(/\.\.\//g)||[]).length,n=t.replace(/^(\.\.\/)+/,""),a=Q(e),o=a.slice(0,Math.max(0,a.length-r));if(n){const e=Q(n),t=[...o,...e].map(F).join("/");return""===t?"/":"/"+t}const s=o.map(F).join("/");return""===s?"/":"/"+s}const r=[...Q(e),...Q(t)].map(F).join("/");return""===r?"/":"/"+r}function F(e){return e.isArray&&void 0!==e.index?`${e.property}[${e.index}]`:e.property}function W(e,t){if(!t||"/"===t)return e;const r=Q(t);let n=e;for(const a of r){if(null==n)return;if(a.isArray&&void 0!==a.index){const e=n[a.property];if(!Array.isArray(e)||a.index>=e.length)return;n=e[a.index]}else n=n[a.property]}return n}function Y(e,t,r,n="replace"){if(!t||"/"===t)return"merge"===n&&"object"==typeof e&&"object"==typeof r?{...e,...r}:"delete"===n?{}:r;const a=Q(t),o={...e};let s=o;for(let u=0;u<a.length-1;u++){const e=a[u];if(e.isArray&&void 0!==e.index){for(s[e.property]&&Array.isArray(s[e.property])||(s[e.property]=[]),s[e.property]=[...s[e.property]];s[e.property].length<=e.index;)s[e.property].push({});s=s[e.property][e.index]}else s[e.property]?s[e.property]={...s[e.property]}:s[e.property]={},s=s[e.property]}const i=a[a.length-1];if(i.isArray&&void 0!==i.index)if(s[i.property]&&Array.isArray(s[i.property])||(s[i.property]=[]),s[i.property]=[...s[i.property]],"delete"===n)s[i.property].splice(i.index,1);else if("append"===n)s[i.property].push(r);else{for(;s[i.property].length<=i.index;)s[i.property].push({});"merge"===n&&"object"==typeof s[i.property][i.index]&&"object"==typeof r?s[i.property][i.index]={...s[i.property][i.index],...r}:s[i.property][i.index]=r}else"delete"===n?delete s[i.property]:"append"===n?(s[i.property]&&Array.isArray(s[i.property])?s[i.property]=[...s[i.property]]:s[i.property]=[],s[i.property].push(r)):"merge"===n&&"object"==typeof s[i.property]&&"object"==typeof r?s[i.property]={...s[i.property],...r}:s[i.property]=r;return o}const B={data:{},xpath:"/",history:[],location:0,asyncStates:{},pendingOperations:new Set,commandQueue:{pending:[],executing:new Map,maxConcurrent:3},optimisticUpdates:{}},z=function(e,t,r={}){l(v(e)||P(e),"Expected handlers to be a plain object.");const n=M(e,r),a=j(n).map(e=>function(e,t=h,r){const n=d(e).split(y);l(!(e=>void 0===e)(r),`defaultState for reducer handling ${n.join(", ")} should be defined`),l(p(t)||v(t),"Expected reducer to be a function or object with next and throw reducers");const[a,o]=p(t)?[t,t]:[t.next,t.throw].map(e=>x(e)?h:e);return(e=r,t)=>{const{type:s}=t;return s&&n.includes(d(s))?(!0===t.error?o:a)(e,t):e}}(e,R(e,n),t)),o=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];var n="function"!=typeof t[0]&&t.shift(),a=t;if(typeof n>"u")throw new TypeError("The initial state may not be undefined. If you do not want to set a value for this reducer, you can use null instead of undefined.");return function(e,t){for(var r=arguments.length,o=Array(r>2?r-2:0),s=2;s<r;s++)o[s-2]=arguments[s];var i=typeof e>"u",u=typeof t>"u";return i&&u&&n?n:a.reduce(function(e,r,n){if(typeof r>"u")throw new TypeError("An undefined reducer was passed in at index "+n);return r.apply(void 0,[e,t].concat(o))},i&&!u&&n?n:e)}}(t,...a);return(e=t,r)=>o(e,r)}({NAVIGATE:(e,t)=>{let{history:r,location:n}=e;n>0&&(r=r.slice(0,r.length-n));const a=L(e.xpath,t.payload);return a===e.xpath?e:{...e,xpath:a,history:[e.xpath,...r],location:0}},BACK:(e,t)=>{const r=Math.max(1,t.payload),n=e.location+r;if(n>e.history.length)return e;const a=n-1,o=e.history[a];return o?{...e,xpath:o,location:n}:e},FORWARD:(e,t)=>{const r=Math.max(1,t.payload),n=e.location-r;if(n<0)return e;if(0===n)return e;const a=n-1,o=e.history[a];return o?{...e,xpath:o,location:n}:e},DATA_OPERATION:(e,t)=>{const{xpath:r,operation:n,data:a}=t.payload,o=L(e.xpath,r),s=Y(e.data,o,a,n);return{...e,data:s}},ASYNC_START:(e,t)=>{const{xpath:r,requestId:n,optimisticData:a}=t.payload,o=L(e.xpath,r);let s=e.data,i=e.optimisticUpdates;if(void 0!==a){const t=`${n}_${o}`;i={...e.optimisticUpdates,[t]:{id:t,xpath:o,originalData:e.data,optimisticData:a,rollbackOnError:!0}},s=Y(e.data,o,a,"replace")}return{...e,data:s,asyncStates:{...e.asyncStates,[o]:{status:"loading",timestamp:Date.now(),requestId:n}},pendingOperations:new Set([...e.pendingOperations,n]),optimisticUpdates:i}},ASYNC_SUCCESS:(e,t)=>{const{xpath:r,requestId:n,data:a,timestamp:o}=t.payload,s=L(e.xpath,r),i=Y(e.data,s,a,"replace"),u=new Set(e.pendingOperations);u.delete(n);const c=`${n}_${s}`,l={...e.optimisticUpdates};return delete l[c],{...e,data:i,asyncStates:{...e.asyncStates,[s]:{status:"success",timestamp:o,requestId:n}},pendingOperations:u,optimisticUpdates:l}},ASYNC_ERROR:(e,t)=>{const{xpath:r,requestId:n,error:a,shouldRollback:o}=t.payload,s=L(e.xpath,r),i=`${n}_${s}`,u=e.optimisticUpdates[i];let c=e.data;const l={...e.optimisticUpdates};o&&u&&(c=u.originalData,delete l[i]);const p=new Set(e.pendingOperations);return p.delete(n),{...e,data:c,asyncStates:{...e.asyncStates,[s]:{status:"error",error:a,timestamp:Date.now(),requestId:n}},pendingOperations:p,optimisticUpdates:l}},ASYNC_CANCEL:(e,t)=>{const{xpath:r,requestId:n}=t.payload,a=L(e.xpath,r),o=`${n}_${a}`,s=e.optimisticUpdates[o];let i=e.data;const u={...e.optimisticUpdates};s&&(i=s.originalData,delete u[o]);const c=new Set(e.pendingOperations);return c.delete(n),{...e,data:i,asyncStates:{...e.asyncStates,[a]:{status:"idle",timestamp:Date.now(),requestId:n}},pendingOperations:c,optimisticUpdates:u}},COMMAND_QUEUE_UPDATE:(e,t)=>{const{operation:r,command:n,commandId:a}=t.payload;switch(r){case"add":return n?{...e,commandQueue:{...e.commandQueue,pending:[...e.commandQueue.pending,n]}}:e;case"execute":if(!n)return e;const t=new Map(e.commandQueue.executing);return t.set(n.id,n),{...e,commandQueue:{...e.commandQueue,pending:e.commandQueue.pending.filter(e=>e.id!==n.id),executing:t}};case"remove":if(!a)return e;const r=new Map(e.commandQueue.executing);return r.delete(a),{...e,commandQueue:{...e.commandQueue,executing:r}};default:return e}}},B),X=t.createContext(B),V=t.createContext(null),G=t.createContext({xpath:"/",data:{},targetData:{},params:{}});const{navigate:K,back:H,forward:Z,dataOperation:J,asyncStart:ee,asyncSuccess:te,asyncError:re,asyncCancel:ne,commandQueueUpdate:ae}=function(e,...t){const r=v((e=>e[e.length-1])(t))?t.pop():{};return l(t.every(f)&&(f(e)||v(e)),"Expected optional object followed by string action types"),f(e)?U([e,...t],r):{...$(e,r),...U(t,r)}}({NAVIGATE:e=>e,BACK:(e=1)=>Math.max(1,e),FORWARD:(e=1)=>Math.max(1,e),DATA_OPERATION:(e,t,r)=>({xpath:e,operation:t,data:r}),ASYNC_START:(e,t,r,n="normal",a)=>({xpath:e,requestId:t,operation:r,priority:n,optimisticData:a}),ASYNC_SUCCESS:(e,t,r,n=Date.now())=>({xpath:e,requestId:t,data:r,timestamp:n}),ASYNC_ERROR:(e,t,r,n=!0)=>({xpath:e,requestId:t,error:r,shouldRollback:n}),ASYNC_CANCEL:(e,t)=>({xpath:e,requestId:t}),COMMAND_QUEUE_UPDATE:(e,t,r)=>({operation:e,command:t,commandId:r})});function oe(){return`req_${Date.now()}_${Math.random().toString(36).substr(2,9)}`}function se(){const e=t.useContext(V);if(!e)throw new Error("useNavigate must be used within a DataProvider");return t=>e(K(t))}function ie(){const e=t.useContext(V);if(!e)throw new Error("useDataManipulation must be used within a DataProvider");return{setData:(t,r,n="replace")=>{e(J(t,n,r))},mergeData:(t,r)=>{e(J(t,"merge",r))},replaceData:(t,r)=>{e(J(t,"replace",r))},appendData:(t,r)=>{e(J(t,"append",r))},deleteData:t=>{e(J(t,"delete",null))}}}class ue{constructor(e,t=3){a(this,"queue",{pending:[],executing:new Map,maxConcurrent:3}),a(this,"dispatch"),a(this,"destroyed",!1),this.dispatch=e,this.queue={...this.queue,maxConcurrent:t}}destroy(){this.destroyed=!0,this.queue.executing.forEach(e=>{e.abortController.abort()}),this.queue={pending:[],executing:new Map,maxConcurrent:this.queue.maxConcurrent}}createCommand(e,t,r,n="normal"){const a=new AbortController,o=oe(),s=r.then(e=>(this.removeFromExecuting(o),e),e=>{throw this.removeFromExecuting(o),e});return{id:o,xpath:e,operation:t,abortController:a,promise:s,timestamp:Date.now(),priority:n}}enqueue(e){this.destroyed||(this.queue={...this.queue,pending:[...this.queue.pending,e]},this.dispatch({type:"COMMAND_QUEUE_UPDATE",payload:{operation:"add",command:e}}),this.processQueue())}cancel(e){const t=this.queue.executing.get(e);t&&(t.abortController.abort(),this.removeFromExecuting(e)),this.queue={...this.queue,pending:this.queue.pending.filter(t=>t.id!==e)}}cancelByXPath(e){this.queue.executing.forEach((t,r)=>{t.xpath===e&&(t.abortController.abort(),this.removeFromExecuting(r))}),this.queue={...this.queue,pending:this.queue.pending.filter(t=>t.xpath!==e)}}processQueue(){if(!this.destroyed)for(;this.queue.executing.size<this.queue.maxConcurrent&&this.queue.pending.length>0;){const e=[...this.queue.pending].sort((e,t)=>{const r={high:3,normal:2,low:1};return r[t.priority]-r[e.priority]||e.timestamp-t.timestamp})[0];if(!e)break;this.executeCommand(e)}}executeCommand(e){if(this.destroyed)return;const t=new Map(this.queue.executing);t.set(e.id,e),this.queue={...this.queue,pending:this.queue.pending.filter(t=>t.id!==e.id),executing:t},this.dispatch({type:"COMMAND_QUEUE_UPDATE",payload:{operation:"execute",command:e}}),e.promise.catch(()=>{})}removeFromExecuting(e){const t=new Map(this.queue.executing);t.delete(e),this.queue={...this.queue,executing:t},this.dispatch({type:"COMMAND_QUEUE_UPDATE",payload:{operation:"remove",commandId:e}}),queueMicrotask(()=>this.processQueue())}updateQueue(e){this.queue=e}hasPendingOperations(e){return e?this.queue.pending.some(t=>t.xpath===e)||Array.from(this.queue.executing.values()).some(t=>t.xpath===e):this.queue.pending.length>0||this.queue.executing.size>0}getQueuedOperations(e){const t=[...this.queue.pending,...Array.from(this.queue.executing.values())];return e?t.filter(t=>t.xpath===e):t}}function ce(e,r={}){const n=t.useContext(X),a=t.useContext(V);if(!n||!a)throw new Error("useAsyncBatch must be used within a DataProvider");const{concurrency:o=3,failFast:s=!1,retryCount:i=1,retryDelay:u=1e3,onBatchComplete:c,onBatchError:l}=r,p=t.useRef(),d=t.useRef([]),f=t.useRef("idle"),y=t.useRef();p.current||(p.current=new ue(a,o),p.current.updateQueue(n.commandQueue)),t.useEffect(()=>()=>{var e;null==(e=p.current)||e.destroy()},[]);const h=t.useCallback(async(e,t=0)=>{var r,o;const s=L(n.xpath,e.xpath),c=oe();try{a(ee(s,c,"fetch",e.priority));const t=await e.fetcher();return a(te(s,c,t)),null==(r=e.onSuccess)||r.call(e,t),{xpath:e.xpath,status:"success",data:t}}catch(l){const r=l instanceof Error?l:new Error(String(l));if(t<i){const r=u*Math.pow(2,t);return await new Promise(e=>setTimeout(e,r)),h(e,t+1)}return a(re(s,c,r,!1)),null==(o=e.onError)||o.call(e,r),{xpath:e.xpath,status:"error",error:r}}},[n.xpath,a,i,u]),m=t.useCallback(async()=>{var t;if("loading"===f.current)throw new Error("Batch operation is already in progress");f.current="loading",y.current=oe(),d.current=e.map(e=>({xpath:e.xpath,status:"pending"}));try{const r=e.map(async(t,r)=>{try{const a=await h(t);if(d.current[r]=a,s&&"error"===a.status&&p.current)throw e.slice(r+1).forEach(e=>{const t=L(n.xpath,e.xpath);p.current.cancelByXPath(t)}),a.error;return a}catch(a){const e={xpath:t.xpath,status:"error",error:a instanceof Error?a:new Error(String(a))};if(d.current[r]=e,s)throw a;return e}}),a=(await Promise.allSettled(r)).map((t,r)=>"fulfilled"===t.status?t.value:{xpath:e[r].xpath,status:"error",error:t.reason instanceof Error?t.reason:new Error(String(t.reason))});d.current=a;const o=a.some(e=>"error"===e.status);if(f.current=o?"error":"success",o&&l){const e=null==(t=a.find(e=>"error"===e.status))?void 0:t.error;l(e||new Error("Batch operation failed"),a)}else!o&&c&&c(a);return a}catch(r){f.current="error";const e=r instanceof Error?r:new Error(String(r));throw l&&l(e,d.current),e}},[e,h,s,c,l,n.xpath]),g=t.useCallback(()=>{p.current&&y.current&&e.forEach(e=>{const t=L(n.xpath,e.xpath);p.current.cancelByXPath(t)}),f.current="idle",d.current=[]},[e,n.xpath]),v=t.useMemo(()=>{const t=e.length,r=d.current.filter(e=>"success"===e.status).length,n=d.current.filter(e=>"error"===e.status).length;return{total:t,completed:r,failed:n,pending:d.current.filter(e=>"pending"===e.status).length,percentage:t>0?Math.round((r+n)/t*100):0}},[e.length,d.current]);return{execute:m,cancel:g,isLoading:"loading"===f.current,isError:"error"===f.current,isSuccess:"success"===f.current,isIdle:"idle"===f.current,results:d.current,progress:v}}function le(e,r={}){const n=t.useContext(X),a=t.useContext(V);if(!n||!a)throw new Error("useOptimisticUpdates must be used within a DataProvider");const{onRollback:o,onCommit:s}=r,i=L(n.xpath,e),u=t.useCallback(e=>{const t=oe();return a({type:"ASYNC_START",payload:{xpath:i,requestId:t,operation:"mutate",priority:"normal",optimisticData:e}}),t},[i,a]),c=t.useCallback(e=>{const t=`${e}_${i}`,r=n.optimisticUpdates[t];r&&(a({type:"ASYNC_CANCEL",payload:{xpath:i,requestId:e}}),null==o||o(r.originalData))},[i,n.optimisticUpdates,a,o]),l=t.useCallback(e=>{const t=`${e}_${i}`,r=n.optimisticUpdates[t];r&&(a({type:"ASYNC_SUCCESS",payload:{xpath:i,requestId:e,data:r.optimisticData,timestamp:Date.now()}}),null==s||s(r.optimisticData))},[i,n.optimisticUpdates,a,s]),p=t.useCallback(()=>{Object.entries(n.optimisticUpdates).forEach(([e,t])=>{if(t.xpath===i){const t=e.split("_")[0];c(t)}})},[n.optimisticUpdates,i,c]),d=t.useCallback(e=>{const t=`${e}_${i}`,r=n.optimisticUpdates[t];return r?W(r.originalData,i):void 0},[n.optimisticUpdates,i]),f=Object.keys(n.optimisticUpdates).filter(e=>e.endsWith(`_${i}`)).map(e=>e.split("_")[0]);return{apply:u,rollback:c,commit:l,rollbackAll:p,getOriginalData:d,hasOptimisticUpdates:f.length>0,optimisticUpdateIds:f}}function pe(){const e=t.useContext(X),r=t.useContext(V);if(!e||!r)throw new Error("useInvalidation must be used within a DataProvider");const n=t.useRef();n.current||(n.current=new ue(r)),t.useEffect(()=>{var t;null==(t=n.current)||t.updateQueue(e.commandQueue)},[e.commandQueue]),t.useEffect(()=>()=>{var e;null==(e=n.current)||e.destroy()},[]);const a=t.useCallback((t,a={})=>{const{includeChildren:o=!1,includeParents:s=!1,clearData:i=!1}=a,u=L(e.xpath,t),c=new Set([u]);if(o&&Object.keys(e.asyncStates).forEach(e=>{(e.startsWith(u+"/")||e.startsWith(u+"["))&&c.add(e)}),s){const t=Q(u);for(let r=t.length-1;r>=0;r--){const n=t.slice(0,r),a=0===n.length?"/":"/"+n.map(e=>e.isArray&&void 0!==e.index?`${e.property}[${e.index}]`:e.property).join("/");e.asyncStates[a]&&c.add(a)}}c.forEach(t=>{var a;const o=e.asyncStates[t];null==(a=n.current)||a.cancelByXPath(t),o&&r({type:"ASYNC_CANCEL",payload:{xpath:t,requestId:o.requestId||oe()}}),i&&r({type:"DATA_OPERATION",payload:{xpath:t,operation:"delete",data:null}})})},[e,r]),o=t.useCallback((e,t={})=>{e.forEach(e=>a(e,t))},[a]),s=t.useCallback((t,r={})=>{const n=new RegExp(t.replace(/\*/g,".*").replace(/\[(\d+)\]/g,"\\[$1\\]").replace(/\[\*\]/g,"\\[\\d+\\]")),a=Object.keys(e.asyncStates).filter(e=>n.test(e));o(a,r)},[e.asyncStates,o]),i=t.useCallback(()=>{e.commandQueue.executing.forEach(e=>{e.abortController.abort()}),e.commandQueue.pending.forEach(e=>{e.abortController.abort()}),Object.keys(e.asyncStates).forEach(t=>{const n=e.asyncStates[t];r({type:"ASYNC_CANCEL",payload:{xpath:t,requestId:n.requestId||oe()}})}),r({type:"COMMAND_QUEUE_UPDATE",payload:{operation:"remove",commandId:"all"}})},[e,r]),u=t.useCallback(t=>{const n=L(e.xpath,t);e.asyncStates[n]&&r({type:"ASYNC_START",payload:{xpath:n,requestId:oe(),operation:"fetch",priority:"normal"}})},[e,r]),c=t.useCallback(e=>{e.forEach(e=>u(e))},[u]),l=t.useCallback(()=>Object.keys(e.asyncStates).filter(t=>{const r=e.asyncStates[t];return"idle"===r.status||"error"===r.status}).length,[e.asyncStates]);return{invalidate:a,invalidateMany:o,invalidatePattern:s,invalidateAll:i,revalidate:u,revalidateMany:c,getInvalidationCount:l}}const de=t.forwardRef(({to:e,children:t,...r},n)=>{const a=se();return c.jsx("a",{...r,href:"#",ref:n,onClick:t=>{t.defaultPrevented||(t.preventDefault(),a(e))},children:t})});de.displayName="Link",e.Button=function({dataAction:e="merge",targetXPath:t,navigateTo:r,children:n,onClick:a,type:o="submit",...s}){const{setData:i}=ie(),u=se();return c.jsx("button",{type:o,...s,onClick:n=>{if(a&&a(n),!n.defaultPrevented){if("submit"===o){const r=n.currentTarget.closest("form");if(r&&t){const n=new window.FormData(r),a={};for(const[e,t]of n.entries())a[e]?Array.isArray(a[e])?a[e].push(t):a[e]=[a[e],t]:a[e]=t;i(t,a,e)}}r&&u(r)}},children:n})},e.CommandQueueManager=ue,e.DataProvider=function({initialData:e={},initialXPath:r="/",children:n}){const a=t.useMemo(()=>({data:e,xpath:r,history:[],location:0,asyncStates:{},pendingOperations:new Set,commandQueue:{pending:[],executing:new Map,maxConcurrent:3},optimisticUpdates:{}}),[e,r]),[o,s]=t.useReducer(z,a),i=t.useMemo(()=>o,[o.data,o.xpath,o.history,o.location,o.asyncStates,o.pendingOperations,o.commandQueue,o.optimisticUpdates]),u=t.useMemo(()=>s,[s]),l=t.useMemo(()=>{const e=W(o.data,o.xpath),t=function(e,t){const r=Q(e),n=Q(t),a={};if(r.length!==n.length)return a;for(let o=0;o<r.length;o++){const e=r[o],t=n[o];if(e.property.startsWith(":"))a[e.property.slice(1)]=t.property;else if(e.property!==t.property)return{};if(e.isArray&&t.isArray){if(void 0!==e.index&&void 0!==t.index&&e.index!==t.index)return{}}else if(e.isArray!==t.isArray)return{}}return a}("*",o.xpath);return{xpath:o.xpath,data:o.data,targetData:e,params:t}},[o.data,o.xpath]);return c.jsx(X.Provider,{value:i,children:c.jsx(V.Provider,{value:u,children:c.jsx(G.Provider,{value:l,children:n})})})},e.Form=function({xpath:e="",operation:t="merge",onSubmit:r,children:n,...a}){const o=se(),{setData:s}=ie();return c.jsx("form",{...a,onSubmit:n=>{n.preventDefault();const a=n.currentTarget,i=new window.FormData(a),u={};for(const[e,t]of i.entries())u[e]?Array.isArray(u[e])?u[e].push(t):u[e]=[u[e],t]:u[e]=t;r?r(u,o):e&&s(e,u,t)},children:n})},e.Link=de,e.asyncCancel=ne,e.asyncError=re,e.asyncStart=ee,e.asyncSuccess=te,e.commandQueueUpdate=ae,e.generateRequestId=oe,e.useAsyncBatch=ce,e.useAsyncData=function(e,r,n={}){const a=t.useContext(X),o=t.useContext(V);if(!a||!o)throw new Error("useAsyncData must be used within a DataProvider");const{enabled:s=!0,staleTime:i=0,cacheTime:u=3e5,refetchOnWindowFocus:c=!1,refetchOnReconnect:l=!1,retryCount:p=3,retryDelay:d=1e3,onSuccess:f,onError:y}=n,h=L(a.xpath,e),m=a.asyncStates[h],g=W(a.data,h),v=t.useRef(),b=t.useRef(0),x=t.useRef();v.current||(v.current=new ue(o)),t.useEffect(()=>()=>{var e;null==(e=v.current)||e.destroy()},[]),t.useEffect(()=>{v.current&&v.current.updateQueue(a.commandQueue)},[a.commandQueue]);const w=t.useCallback(async e=>{try{o(ee(h,e,"fetch"));const t=await r();return o(te(h,e,t)),b.current=0,null==f||f(t),t}catch(t){const r=t instanceof Error?t:new Error(String(t));if(b.current<p){b.current++;const t=d*Math.pow(2,b.current-1);return await new Promise(e=>setTimeout(e,t)),w(e)}throw o(re(h,e,r,!1)),null==y||y(r),r}},[h,r,o,p,d,f,y]),C=t.useCallback(async()=>{const e=oe();if(x.current=e,v.current){const t=v.current.createCommand(h,"fetch",w(e),"normal");return v.current.enqueue(t),t.promise}return w(e)},[h,w]),E=t.useCallback(()=>{x.current&&v.current&&v.current.cancel(x.current)},[]),S=t.useCallback(()=>{v.current&&v.current.cancelByXPath(h),m&&o({type:"ASYNC_CANCEL",payload:{xpath:h,requestId:m.requestId||oe()}})},[h,m,o]),O=t.useCallback(()=>!(null==m?void 0:m.timestamp)||Date.now()-m.timestamp>i,[null==m?void 0:m.timestamp,i]);t.useEffect(()=>{!s||m&&"idle"!==m.status||C().catch(()=>{})},[s,h]),t.useEffect(()=>{if(!c)return;const e=()=>{s&&O()&&C().catch(()=>{})};return window.addEventListener("focus",e),()=>window.removeEventListener("focus",e)},[s,c,C,O]),t.useEffect(()=>{if(!l)return;const e=()=>{s&&O()&&C().catch(()=>{})};return window.addEventListener("online",e),()=>window.removeEventListener("online",e)},[s,l,C,O]),t.useEffect(()=>()=>{0===u&&S()},[u,S]);const A=(null==m?void 0:m.status)||"idle";return{data:g,isLoading:"loading"===A,isError:"error"===A,isSuccess:"success"===A,isIdle:"idle"===A,error:null==m?void 0:m.error,refetch:C,cancel:E,invalidate:S}},e.useAsyncMutation=function(e,r,n={}){const a=t.useContext(X),o=t.useContext(V);if(!a||!o)throw new Error("useAsyncMutation must be used within a DataProvider");const{optimisticUpdate:s,rollbackOnError:i=!0,invalidate:u=[],retryCount:c=0,retryDelay:l=1e3,onSuccess:p,onError:d,onSettled:f}=n,y=L(a.xpath,e),h=a.asyncStates[y],m=W(a.data,y),g=t.useRef(),v=t.useRef(0),b=t.useRef();g.current||(g.current=new ue(o),g.current.updateQueue(a.commandQueue)),t.useEffect(()=>()=>{var e;null==(e=g.current)||e.destroy()},[]);const x=t.useCallback(async(e,t)=>{try{let n;s&&void 0!==m&&(n=s(m,e)),o(ee(y,t,"mutate","high",n));const i=await r(e);return o(te(y,t,i)),u.length>0&&g.current&&u.forEach(e=>{const t=L(a.xpath,e);g.current.cancelByXPath(t),o({type:"ASYNC_CANCEL",payload:{xpath:t,requestId:oe()}})}),v.current=0,null==p||p(i,e),null==f||f(i,void 0,e),i}catch(n){const r=n instanceof Error?n:new Error(String(n));if(v.current<c){v.current++;const r=l*Math.pow(2,v.current-1);return await new Promise(e=>setTimeout(e,r)),x(e,t)}throw o(re(y,t,r,i)),null==d||d(r,e),null==f||f(void 0,r,e),r}},[y,r,s,m,o,u,a.xpath,c,l,i,p,d,f]),w=t.useCallback(async e=>{const t=oe();if(b.current=e,g.current){const r=g.current.createCommand(y,"mutate",x(e,t),"high");return g.current.enqueue(r),r.promise}return x(e,t)},[y,x]),C=t.useCallback(e=>w(e).catch(e=>{throw e}),[w]),E=t.useCallback(()=>{(null==h?void 0:h.requestId)&&g.current&&g.current.cancel(h.requestId),o({type:"ASYNC_CANCEL",payload:{xpath:y,requestId:(null==h?void 0:h.requestId)||oe()}}),v.current=0},[y,null==h?void 0:h.requestId,o]),S=(null==h?void 0:h.status)||"idle";return{mutate:C,mutateAsync:w,reset:E,isLoading:"loading"===S,isError:"error"===S,isSuccess:"success"===S,isIdle:"idle"===S,data:m,error:null==h?void 0:h.error}},e.useAsyncParallel=function(e,t){return ce(e.map(e=>({...e,priority:"normal"})),{...t,concurrency:e.length})},e.useAsyncSequential=function(e,t){return ce(e.map(e=>({...e,priority:"normal"})),{...t,concurrency:1})},e.useAsyncState=function(e){const r=t.useContext(X);if(!r)throw new Error("useAsyncState must be used within a DataProvider");const n=L(r.xpath,e),a=r.asyncStates[n],o=W(r.data,n),s=r.pendingOperations.has((null==a?void 0:a.requestId)||""),i=t.useMemo(()=>{if(a)return{...a,xpath:n,hasPendingOperation:s,isStale:(e=0)=>!a.timestamp||Date.now()-a.timestamp>e}},[a,n,s]),u=(null==a?void 0:a.status)||"idle";return{data:o,asyncState:i,isLoading:"loading"===u,isError:"error"===u,isSuccess:"success"===u,isIdle:"idle"===u,error:null==a?void 0:a.error,isPending:s,lastUpdated:null==a?void 0:a.timestamp}},e.useAsyncStates=function(e){const r=t.useContext(X);if(!r)throw new Error("useAsyncStates must be used within a DataProvider");return t.useMemo(()=>{const t={};return e.forEach(e=>{const n=L(r.xpath,e),a=r.asyncStates[n],o=W(r.data,n),s=r.pendingOperations.has((null==a?void 0:a.requestId)||""),i=a?{...a,xpath:n,hasPendingOperation:s,isStale:(e=0)=>!a.timestamp||Date.now()-a.timestamp>e}:void 0,u=(null==a?void 0:a.status)||"idle";t[e]={data:o,asyncState:i,isLoading:"loading"===u,isError:"error"===u,isSuccess:"success"===u,isIdle:"idle"===u,error:null==a?void 0:a.error,isPending:s,lastUpdated:null==a?void 0:a.timestamp}}),t},[r,e])},e.useAutoInvalidation=function(e,r={}){const{invalidateMany:n}=pe(),{debounceMs:a=100,onInvalidate:o,...s}=r,i=t.useCallback((()=>{let e;return t=>{clearTimeout(e),e=setTimeout(()=>{n(t,s),null==o||o(t)},a)}})(),[n,s,a,o]);return{trigger:()=>i(e),invalidateDependencies:()=>n(e,s)}},e.useData=function(){const e=t.useContext(X);if(!e)throw new Error("useData must be used within a DataProvider");return e.data},e.useDataAtXPath=function(e){const r=t.useContext(X);if(!r)throw new Error("useDataAtXPath must be used within a DataProvider");return W(r.data,e)},e.useDataManipulation=ie,e.useGlobalAsyncState=function(){const e=t.useContext(X);if(!e)throw new Error("useGlobalAsyncState must be used within a DataProvider");return t.useMemo(()=>{const t=Object.entries(e.asyncStates),r=e.pendingOperations.size,n=e.commandQueue.executing.size,a=e.commandQueue.pending.length;return{summary:{totalStates:t.length,loadingStates:t.filter(([,e])=>"loading"===e.status).length,errorStates:t.filter(([,e])=>"error"===e.status).length,successStates:t.filter(([,e])=>"success"===e.status).length,idleStates:t.filter(([,e])=>"idle"===e.status).length,pendingOperations:r,executingOperations:n,queuedOperations:a,hasAnyLoading:t.some(([,e])=>"loading"===e.status),hasAnyError:t.some(([,e])=>"error"===e.status),optimisticUpdateCount:Object.keys(e.optimisticUpdates).length},statesByStatus:{loading:t.filter(([,e])=>"loading"===e.status),error:t.filter(([,e])=>"error"===e.status),success:t.filter(([,e])=>"success"===e.status),idle:t.filter(([,e])=>"idle"===e.status)},asyncStates:e.asyncStates,pendingOperations:e.pendingOperations,commandQueue:e.commandQueue,optimisticUpdates:e.optimisticUpdates}},[e])},e.useHistory=function(){const e=t.useContext(X);if(!e)throw new Error("useHistory must be used within a DataProvider");return e.history},e.useInvalidation=pe,e.useNavigate=se,e.useNavigation=function(){const e=t.useContext(V),r=t.useContext(X);if(!e||!r)throw new Error("useNavigation must be used within a DataProvider");return{navigate:t=>e(K(t)),back:(t=1)=>e(H(t)),forward:(t=1)=>e(Z(t)),hasBack:r.location<r.history.length,hasForward:r.location>0,xpath:r.xpath,history:r.history,location:r.location}},e.useOptimisticList=function(e,r={}){const n=le(e,r),a=t.useContext(X),o=L(a.xpath,e),s=W(a.data,o)||[],i=t.useCallback((e,t)=>{const r=[...s];return void 0!==t&&t>=0&&t<=r.length?r.splice(t,0,e):r.push(e),n.apply(r)},[s,n]),u=t.useCallback((e,t)=>{if(e<0||e>=s.length)throw new Error(`Index ${e} is out of bounds for list of length ${s.length}`);const r=[...s];return r[e]=t,n.apply(r)},[s,n]),c=t.useCallback(e=>{if(e<0||e>=s.length)throw new Error(`Index ${e} is out of bounds for list of length ${s.length}`);const t=[...s];return t.splice(e,1),n.apply(t)},[s,n]),l=t.useCallback((e,t)=>{if(e<0||e>=s.length||t<0||t>=s.length)throw new Error("Move indices are out of bounds");const r=[...s],[a]=r.splice(e,1);return r.splice(t,0,a),n.apply(r)},[s,n]);return{...n,addItem:i,updateItem:u,removeItem:c,moveItem:l}},e.useOptimisticObject=function(e,r={}){const n=le(e,r),a=t.useContext(X),o=L(a.xpath,e),s=W(a.data,o)||{},i=t.useCallback((e,t)=>{const r={...s,[e]:t};return n.apply(r)},[s,n]),u=t.useCallback(e=>{const t={...s,...e};return n.apply(t)},[s,n]),c=t.useCallback(e=>{const t={...s};return delete t[e],n.apply(t)},[s,n]),l=t.useCallback(e=>{const t={...s};return Object.entries(e).forEach(([e,r])=>{"object"==typeof t[e]&&"object"==typeof r&&null!==t[e]&&null!==r?t[e]={...t[e],...r}:t[e]=r}),n.apply(t)},[s,n]);return{...n,updateProperty:i,updateProperties:u,removeProperty:c,mergeObject:l}},e.useOptimisticUpdates=le,e.useQueryInvalidation=function(){const e=t.useContext(X),{invalidatePattern:r,invalidateMany:n}=pe();return{invalidateQueries:t.useCallback(e=>{Array.isArray(e)?n(e):r(e)},[r,n]),invalidateQueriesMatching:t.useCallback(t=>{const r=Object.keys(e.asyncStates).filter(t);n(r)},[e.asyncStates,n]),getQueries:t.useCallback(t=>{if(!t)return Object.keys(e.asyncStates);if(Array.isArray(t))return t.filter(t=>e.asyncStates[t]);const r=new RegExp(t.replace(/\*/g,".*"));return Object.keys(e.asyncStates).filter(e=>r.test(e))},[e.asyncStates])}},e.useTargetData=function(){const e=t.useContext(G);if(!e)throw new Error("useTargetData must be used within a DataProvider");return e.targetData},e.useXPath=function(){const e=t.useContext(X);if(!e)throw new Error("useXPath must be used within a DataProvider");return e.xpath},Object.defineProperty(e,Symbol.toStringTag,{value:"Module"})});
11
+ //# sourceMappingURL=index.umd.cjs.map