mobx-state-tree 7.3.2 → 8.0.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.
- package/dist/mobx-state-tree.js +2932 -4732
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +2933 -4733
- package/dist/mobx-state-tree.umd.js +2932 -4732
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/utility-types/enumeration.d.ts +3 -3
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mobxStateTree={},e.mobx)}(this,(function(e,t){"use strict";var r,n="warn";function i(e){n=e}function a(){return n}!function(e){e.afterCreate="afterCreate",e.afterAttach="afterAttach",e.afterCreationFinalization="afterCreationFinalization",e.beforeDetach="beforeDetach",e.beforeDestroy="beforeDestroy"}(r||(r={}));var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])})(e,t)};function u(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var l=function(){return(l=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function c(e,t){var r,n,i,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},o=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return o.next=u(0),o.throw=u(1),o.return=u(2),"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(l){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){a.label=u[1];break}if(6===u[0]&&a.label<i[1]){a.label=i[1],i=u;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(u);break}i[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,l])}}}function s(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function f(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,a=r.call(e),o=[];try{for(;(void 0===t||t-- >0)&&!(n=a.next()).done;)o.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=a.return)&&r.call(a)}finally{if(i)throw i.error}}return o}function p(e,t,r){if(r||2===arguments.length)for(var n,i=0,a=t.length;i<a;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}function b(e){return ge(e).type}function d(e,t){return ge(e).onPatch(t)}function h(e,t){ge(e).applyPatches(xe(t))}function y(e,t){return ge(e).applySnapshot(t)}function v(e,t){void 0===t&&(t=!0);var r=ge(e);return t?r.snapshot:r.type.getSnapshot(r,!1)}function g(e){return ge(e).root.storedValue}function m(e){return ge(e).path}function w(e){return ge(e).identifier}function P(e,t){var r=je(ge(e),t,!1);if(void 0!==r)try{return r.value}catch(e){return}}function O(e){return ge(e).observableIsAlive}function j(e){var t;return{name:(t=ve(e)?b(e):e).name,properties:l({},t.properties)}}"function"==typeof SuppressedError&&SuppressedError;var _=function(){function e(e,t,r,n){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"environment",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"_escapedSubpath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subpath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subpathUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pathUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storedValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"aliveAtom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:pe.INITIALIZING}),Object.defineProperty(this,"_hookSubscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pathAtom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.environment=n,this.baseSetParent(t,r)}return Object.defineProperty(e.prototype,"subpath",{get:function(){return this._subpath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subpathUponDeath",{get:function(){return this._subpathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"pathUponDeath",{get:function(){return this._pathUponDeath},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"state",{get:function(){return this._state},set:function(e){var t=this.isAlive;this._state=e;var r=this.isAlive;this.aliveAtom&&t!==r&&this.aliveAtom.reportChanged()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"fireInternalHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._hookSubscribers&&this._hookSubscribers.emit(e,this,e)}}),Object.defineProperty(e.prototype,"registerHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._hookSubscribers||(this._hookSubscribers=new He),this._hookSubscribers.register(e,t)}}),Object.defineProperty(e.prototype,"parent",{get:function(){return this._parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"getReconciliationType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type}}),Object.defineProperty(e.prototype,"baseSetParent",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._parent=e,this._subpath=t,this._escapedSubpath=void 0,this.pathAtom&&this.pathAtom.reportChanged()}}),Object.defineProperty(e.prototype,"path",{get:function(){return this.getEscapedPath(!0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"getEscapedPath",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e&&(this.pathAtom||(this.pathAtom=t.createAtom("path")),this.pathAtom.reportObserved()),this.parent?(void 0===this._escapedSubpath&&(this._escapedSubpath=this._subpath?Je(this._subpath):""),this.parent.getEscapedPath(e)+"/"+this._escapedSubpath):""}}),Object.defineProperty(e.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isAlive",{get:function(){return this.state!==pe.DEAD},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isDetaching",{get:function(){return this.state===pe.DETACHING},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"observableIsAlive",{get:function(){return this.aliveAtom||(this.aliveAtom=t.createAtom("alive")),this.aliveAtom.reportObserved(),this.isAlive},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"baseFinalizeCreation",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.state===pe.CREATED){if(this.parent){if(this.parent.state!==pe.FINALIZED)return;this.fireHook(r.afterAttach)}this.state=pe.FINALIZED,e&&e()}}}),Object.defineProperty(e.prototype,"baseFinalizeDeath",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._hookSubscribers&&this._hookSubscribers.clearAll(),this._subpathUponDeath=this._subpath,this._pathUponDeath=this.getEscapedPath(!1),this.baseSetParent(null,""),this.state=pe.DEAD}}),Object.defineProperty(e.prototype,"baseAboutToDie",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.fireHook(r.beforeDestroy)}}),e}(),S=function(e){function t(t,r,n,i,a){var o=e.call(this,t,r,n,i)||this;try{o.storedValue=t.createNewInstance(a)}catch(e){throw o.state=pe.DEAD,e}return o.state=pe.CREATED,o.finalizeCreation(),o}return u(t,e),Object.defineProperty(t.prototype,"root",{get:function(){if(!this.parent)throw new Ee("This scalar node is not part of a tree");return this.parent.root},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"setParent",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.parent!==e,n=this.subpath!==t;(r||n)&&(this.environment=void 0,this.baseSetParent(this.parent,t))}}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return this.getSnapshot()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(t.prototype,"toString",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||"<root>";return"".concat(this.type.name,"@").concat(e).concat(this.isAlive?"":" [dead]")}}),Object.defineProperty(t.prototype,"die",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isAlive&&this.state!==pe.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(t.prototype,"finalizeCreation",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeCreation()}}),Object.defineProperty(t.prototype,"aboutToDie",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseAboutToDie()}}),Object.defineProperty(t.prototype,"finalizeDeath",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.baseFinalizeDeath()}}),Object.defineProperty(t.prototype,"fireHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.fireInternalHook(e)}}),t}(_);S.prototype.die=t.action(S.prototype.die);var A,I,T=1;!function(e){e[e.UNINITIALIZED=0]="UNINITIALIZED",e[e.CREATING=1]="CREATING",e[e.CREATED=2]="CREATED"}(A||(A={})),function(e){e.Dispose="dispose",e.Patch="patch",e.Snapshot="snapshot"}(I||(I={}));var C,E,N={onError:function(e){throw e}},V=function(e){function n(r,n,i,a,o){var u=e.call(this,r,n,i,a)||this;if(Object.defineProperty(u,"nodeId",{enumerable:!0,configurable:!0,writable:!0,value:++T}),Object.defineProperty(u,"identifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"unnormalizedIdentifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"identifierCache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"isProtectionEnabled",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(u,"middlewares",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"hasSnapshotPostProcessor",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_applyPatches",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_applySnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_autoUnbox",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(u,"_isRunningAction",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_hasSnapshotReaction",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_endOfActionCallbacks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_observableInstanceState",{enumerable:!0,configurable:!0,writable:!0,value:A.UNINITIALIZED}),Object.defineProperty(u,"_childNodes",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_initialSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_cachedInitialSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_cachedInitialSnapshotCreated",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(u,"_snapshotComputed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_snapshotUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(u,"_internalEvents",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),u._snapshotComputed=t.computed((function(){return u.getSnapshot()})),u.unbox=u.unbox.bind(u),u._initialSnapshot=o,u.identifierAttribute=r.identifierAttribute,n||(u.identifierCache=new de),u._childNodes=r.initializeChildNodes(u,u._initialSnapshot),u.identifier=null,u.unnormalizedIdentifier=null,u.identifierAttribute&&u._initialSnapshot){var l=u._initialSnapshot[u.identifierAttribute];if(void 0===l){var c=u._childNodes[u.identifierAttribute];c&&(l=c.value)}if("string"!=typeof l&&"number"!=typeof l&&"bigint"!=typeof l)throw new Ee("Instance identifier '".concat(u.identifierAttribute,"' for type '").concat(u.type.name,"' must be a string, a number or a bigint"));u.identifier=rr(l),u.unnormalizedIdentifier=l}return n?n.root.identifierCache.addNodeToCache(u):u.identifierCache.addNodeToCache(u),u}return u(n,e),Object.defineProperty(n.prototype,"applyPatches",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applyPatches(e)}}),Object.defineProperty(n.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.createObservableInstanceIfNeeded(),this._applySnapshot(e)}}),Object.defineProperty(n.prototype,"createObservableInstanceIfNeeded",{enumerable:!1,configurable:!0,writable:!0,value:function(e){void 0===e&&(e=!0),this._observableInstanceState===A.UNINITIALIZED&&this.createObservableInstance(e)}}),Object.defineProperty(n.prototype,"createObservableInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,n,i,a;void 0===e&&(e=!0),this._observableInstanceState=A.CREATING;for(var o=[],u=this.parent;u&&u._observableInstanceState===A.UNINITIALIZED;)o.unshift(u),u=u.parent;try{for(var l=s(o),c=l.next();!c.done;c=l.next()){(d=c.value).createObservableInstanceIfNeeded(!1)}}catch(e){t={error:e}}finally{try{c&&!c.done&&(n=l.return)&&n.call(l)}finally{if(t)throw t.error}}var f=this.type;try{this.storedValue=f.createNewInstance(this._childNodes),this.preboot(),this._isRunningAction=!0,f.finalizeNewInstance(this,this.storedValue)}catch(e){throw this.state=pe.DEAD,e}finally{this._isRunningAction=!1}if(this._observableInstanceState=A.CREATED,this._snapshotComputed.trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this._childNodes=Te,this.state=pe.CREATED,e){this.fireHook(r.afterCreate),this.finalizeCreation();try{for(var p=s(o.reverse()),b=p.next();!b.done;b=p.next()){var d;(d=b.value).fireHook(r.afterCreate),d.finalizeCreation()}}catch(e){i={error:e}}finally{try{b&&!b.done&&(a=p.return)&&a.call(p)}finally{if(i)throw i.error}}}}}),Object.defineProperty(n.prototype,"root",{get:function(){var e=this.parent;return e?e.root:this},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"enqueueEndOfAction",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.root;t._endOfActionCallbacks||(t._endOfActionCallbacks=[]),t._endOfActionCallbacks.push(e)}}),Object.defineProperty(n.prototype,"flushEndOfActionCallbacks",{enumerable:!1,configurable:!0,writable:!0,value:function(){for(var e=this.root;e._endOfActionCallbacks&&e._endOfActionCallbacks.length>0;){var t=e._endOfActionCallbacks;e._endOfActionCallbacks=void 0,t.forEach((function(e){e()}))}}}),Object.defineProperty(n.prototype,"clearParent",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.parent){this.fireHook(r.beforeDetach);var e=this.state;this.state=pe.DETACHING;var t=this.root,n=t.environment,i=t.identifierCache.splitCache(this);try{this.parent.removeChild(this.subpath),this.baseSetParent(null,""),this.environment=n,this.identifierCache=i}finally{this.state=e}}}}),Object.defineProperty(n.prototype,"setParent",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=e!==this.parent,i=t!==this.subpath;(n||i)&&(n?(this.environment=void 0,e.root.identifierCache.mergeCache(this),this.baseSetParent(e,t),this.fireHook(r.afterAttach)):i&&this.baseSetParent(this.parent,t))}}),Object.defineProperty(n.prototype,"fireHook",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this;this.fireInternalHook(e);var n=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[e];"function"==typeof n&&(t._allowStateChangesInsideComputed?t._allowStateChangesInsideComputed((function(){n.apply(r.storedValue)})):n.apply(this.storedValue))}}),Object.defineProperty(n.prototype,"snapshot",{get:function(){return this.hasSnapshotPostProcessor&&this.createObservableInstanceIfNeeded(),this._snapshotComputed.get()},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.isAlive?this._observableInstanceState===A.CREATED?this._getActualSnapshot():this._getCachedInitialSnapshot():this._snapshotUponDeath}}),Object.defineProperty(n.prototype,"_getActualSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.type.getSnapshot(this)}}),Object.defineProperty(n.prototype,"_getCachedInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this._cachedInitialSnapshotCreated){var e=this.type,t=this._childNodes,r=this._initialSnapshot;this._cachedInitialSnapshot=e.processInitialSnapshot(t,r),this._cachedInitialSnapshotCreated=!0}return this._cachedInitialSnapshot}}),Object.defineProperty(n.prototype,"isRunningAction",{enumerable:!1,configurable:!0,writable:!0,value:function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()}}),Object.defineProperty(n.prototype,"assertAlive",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,r=a();if(!this.isAlive&&"ignore"!==r){var n=this._getAssertAliveError(e);switch(r){case"error":throw new Ee(n);case"warn":t=n,console.warn(new Error("[mobx-state-tree] ".concat(t)))}}}}),Object.defineProperty(n.prototype,"_getAssertAliveError",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getEscapedPath(!1)||this.pathUponDeath||"",r=e.subpath&&Je(e.subpath)||"",n=e.actionContext||W();n&&"action"!==n.type&&n.parentActionEvent&&(n=n.parentActionEvent);var i="";if(n&&null!=n.name){var a=n&&n.context&&m(n.context)||t;i="".concat(a,".").concat(n.name,"()")}return"You are trying to read or write to an object that is no longer part of a state tree. (Object type: '".concat(this.type.name,"', Path upon death: '").concat(t,"', Subpath: '").concat(r,"', Action: '").concat(i,"'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.")}}),Object.defineProperty(n.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.assertAlive({subpath:e}),this._autoUnbox=!1;try{return this._observableInstanceState===A.CREATED?this.type.getChildNode(this,e):this._childNodes[e]}finally{this._autoUnbox=!0}}}),Object.defineProperty(n.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.assertAlive(Te),this._autoUnbox=!1;try{return this._observableInstanceState===A.CREATED?this.type.getChildren(this):Se(this._childNodes)}finally{this._autoUnbox=!0}}}),Object.defineProperty(n.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.type.getChildType(e)}}),Object.defineProperty(n.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"assertWritable",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.assertAlive(e),!this.isRunningAction()&&this.isProtected)throw new Ee("Cannot modify '".concat(this,"', the object is protected and can only be modified by using an action."))}}),Object.defineProperty(n.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.type.removeChild(this,e)}}),Object.defineProperty(n.prototype,"unbox",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e?(this.assertAlive({subpath:e.subpath||e.subpathUponDeath}),this._autoUnbox?e.value:e):e}}),Object.defineProperty(n.prototype,"toString",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=(this.isAlive?this.path:this.pathUponDeath)||"<root>",t=this.identifier?"(id: ".concat(this.identifier,")"):"";return"".concat(this.type.name,"@").concat(e).concat(t).concat(this.isAlive?"":" [dead]")}}),Object.defineProperty(n.prototype,"finalizeCreation",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this.baseFinalizeCreation((function(){var t,n;try{for(var i=s(e.getChildren()),a=i.next();!a.done;a=i.next()){a.value.finalizeCreation()}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}e.fireInternalHook(r.afterCreationFinalization)}))}}),Object.defineProperty(n.prototype,"detach",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(!this.isAlive)throw new Ee("Error while detaching, node is not alive.");this.clearParent()}}),Object.defineProperty(n.prototype,"preboot",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;this._applyPatches=q(this.storedValue,"@APPLY_PATCHES",(function(t){t.forEach((function(t){if(t.path){var r=Qe(t.path);_e(e,r.slice(0,-1)).applyPatchLocally(r[r.length-1],t)}else e.type.applySnapshot(e,t.value)}))})),this._applySnapshot=q(this.storedValue,"@APPLY_SNAPSHOT",(function(t){if(t!==e.snapshot)return e.type.applySnapshot(e,t)})),Me(this.storedValue,"$treenode",this),Me(this.storedValue,"toJSON",we)}}),Object.defineProperty(n.prototype,"die",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isAlive&&this.state!==pe.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}}),Object.defineProperty(n.prototype,"aboutToDie",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._observableInstanceState!==A.UNINITIALIZED&&(this.getChildren().forEach((function(e){e.aboutToDie()})),this.baseAboutToDie(),this._internalEventsEmit(I.Dispose),this._internalEventsClear(I.Dispose))}}),Object.defineProperty(n.prototype,"finalizeDeath",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.getChildren().forEach((function(e){e.finalizeDeath()})),this.root.identifierCache.notifyDied(this);var e=this.snapshot;this._snapshotUponDeath=e,this._internalEventsClearAll(),this.baseFinalizeDeath()}}),Object.defineProperty(n.prototype,"onSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._addSnapshotReaction(),this._internalEventsRegister(I.Snapshot,e)}}),Object.defineProperty(n.prototype,"emitSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEventsEmit(I.Snapshot,e)}}),Object.defineProperty(n.prototype,"onPatch",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsRegister(I.Patch,e)}}),Object.defineProperty(n.prototype,"hasPatchSubscribers",{enumerable:!1,configurable:!0,writable:!0,value:function(){return!!this._internalEventsHasSubscribers(I.Patch)||!!this.parent&&this.parent.hasPatchSubscribers()}}),Object.defineProperty(n.prototype,"emitPatch",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._internalEventsHasSubscribers(I.Patch)){var r=f(function(e){if(!("oldValue"in e))throw new Ee("Patches without `oldValue` field cannot be inversed");return[Ze(e),Ye(e)]}(function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];for(var n=0;n<t.length;n++){var i=t[n];for(var a in i)e[a]=i[a]}return e}({},e,{path:t.path.substr(this.path.length)+(e.path?"/"+e.path:"")})),2),n=r[0],i=r[1];this._internalEventsEmit(I.Patch,n,i)}this.parent&&this.parent.emitPatch(e,t)}}),Object.defineProperty(n.prototype,"hasDisposer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._internalEventsHas(I.Dispose,e)}}),Object.defineProperty(n.prototype,"addDisposer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.hasDisposer(e))throw new Ee("cannot add a disposer when it is already registered for execution");this._internalEventsRegister(I.Dispose,e,!0)}}),Object.defineProperty(n.prototype,"removeDisposer",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._internalEventsHas(I.Dispose,e))throw new Ee("cannot remove a disposer which was never registered for execution");this._internalEventsUnregister(I.Dispose,e)}}),Object.defineProperty(n.prototype,"removeMiddleware",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.middlewares){var t=this.middlewares.indexOf(e);t>=0&&this.middlewares.splice(t,1)}}}),Object.defineProperty(n.prototype,"addMiddleWare",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;void 0===t&&(t=!0);var n={handler:e,includeHooks:t};return this.middlewares?this.middlewares.push(n):this.middlewares=[n],function(){r.removeMiddleware(n)}}}),Object.defineProperty(n.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this.assertWritable({subpath:e}),this.createObservableInstanceIfNeeded(),this.type.applyPatchLocally(this,e,t)}}),Object.defineProperty(n.prototype,"_addSnapshotReaction",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;if(!this._hasSnapshotReaction){var r=t.reaction((function(){return e.snapshot}),(function(t){return e.emitSnapshot(t)}),N);this.addDisposer(r),this._hasSnapshotReaction=!0}}}),Object.defineProperty(n.prototype,"_internalEventsHasSubscribers",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return!!this._internalEvents&&this._internalEvents.hasSubscribers(e)}}),Object.defineProperty(n.prototype,"_internalEventsRegister",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){return void 0===r&&(r=!1),this._internalEvents||(this._internalEvents=new He),this._internalEvents.register(e,t,r)}}),Object.defineProperty(n.prototype,"_internalEventsHas",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!!this._internalEvents&&this._internalEvents.has(e,t)}}),Object.defineProperty(n.prototype,"_internalEventsUnregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){this._internalEvents&&this._internalEvents.unregister(e,t)}}),Object.defineProperty(n.prototype,"_internalEventsEmit",{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];this._internalEvents&&(t=this._internalEvents).emit.apply(t,p([e],f(r),!1))}}),Object.defineProperty(n.prototype,"_internalEventsClear",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this._internalEvents&&this._internalEvents.clear(e)}}),Object.defineProperty(n.prototype,"_internalEventsClearAll",{enumerable:!1,configurable:!0,writable:!0,value:function(){this._internalEvents&&this._internalEvents.clearAll()}}),n}(_);V.prototype.createObservableInstance=t.action(V.prototype.createObservableInstance),V.prototype.detach=t.action(V.prototype.detach),V.prototype.die=t.action(V.prototype.die),function(e){e[e.String=1]="String",e[e.Number=2]="Number",e[e.Boolean=4]="Boolean",e[e.Date=8]="Date",e[e.Literal=16]="Literal",e[e.Array=32]="Array",e[e.Map=64]="Map",e[e.Object=128]="Object",e[e.Frozen=256]="Frozen",e[e.Optional=512]="Optional",e[e.Reference=1024]="Reference",e[e.Identifier=2048]="Identifier",e[e.Late=4096]="Late",e[e.Refinement=8192]="Refinement",e[e.Union=16384]="Union",e[e.Null=32768]="Null",e[e.Undefined=65536]="Undefined",e[e.Integer=131072]="Integer",e[e.Custom=262144]="Custom",e[e.SnapshotProcessor=524288]="SnapshotProcessor",e[e.Lazy=1048576]="Lazy",e[e.Finite=2097152]="Finite",e[e.Float=4194304]="Float",e[e.BigInt=8388608]="BigInt"}(E||(E={}));var D=Symbol("$type"),x=function(){function e(e){Object.defineProperty(this,C,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"C",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"S",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"T",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isType",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=e}return Object.defineProperty(e.prototype,"create",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return se(this,e),this.instantiate(null,"",t,e).value}}),Object.defineProperty(e.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){throw new Ee("unimplemented method")}}),Object.defineProperty(e.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e===this}}),Object.defineProperty(e.prototype,"validate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(me(e)){var r=b(e);return this.isAssignableFrom(r)?ue():le(t,e)}return this.isValidSnapshot(e,t)}}),Object.defineProperty(e.prototype,"is",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return 0===this.validate(e,[{path:"",type:this}]).length}}),Object.defineProperty(e.prototype,"Type",{get:function(){throw new Ee("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"TypeWithoutSTN",{get:function(){throw new Ee("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"SnapshotType",{get:function(){throw new Ee("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"CreationType",{get:function(){throw new Ee("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!1,configurable:!0}),e}();C=D,x.prototype.create=t.action(x.prototype.create);var k=function(e){function t(t){var r=e.call(this,t)||this;return Object.defineProperty(r,"identifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),r}return u(t,e),Object.defineProperty(t.prototype,"create",{enumerable:!1,configurable:!0,writable:!0,value:function(t,r){return void 0===t&&(t=this.getDefaultSnapshot()),e.prototype.create.call(this,t,r)}}),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.createObservableInstanceIfNeeded(),e.storedValue}}),Object.defineProperty(t.prototype,"isMatchingSnapshotId",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!e.identifierAttribute||e.identifier===rr(t[e.identifierAttribute])}}),Object.defineProperty(t.prototype,"tryToReconcileNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return!e.isDetaching&&(e.snapshot===t||(!(!ve(t)||ge(t)!==e)||!(e.type!==this||!Re(t)||ve(t)||!this.isMatchingSnapshotId(e,t))&&(e.applySnapshot(t),!0)))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(this.tryToReconcileNode(e,t))return e.setParent(r,n),e;if(e.die(),ve(t)&&this.isAssignableFrom(b(t))){var i=ge(t);return i.setParent(r,n),i}return this.instantiate(r,n,void 0,t)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(x);k.prototype.create=t.action(k.prototype.create);var R=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return u(t,e),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e}}),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!e.isDetaching&&e.type===this&&e.storedValue===t)return e;var i=this.instantiate(r,n,void 0,t);return e.die(),i}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return null}}),t}(x);function z(e,t,r){var n=t.getReconciliationType(),i=function e(t){var r=t.getSubTypes();if(!r||Array.isArray(r)||"cannotDetermine"===r||!function(e){var t=E.Optional|E.Late,r=E.Refinement|E.SnapshotProcessor|E.Union;return(e.flags&t)>0&&0==(e.flags&r)}(t))return t;return e(r)}(e);return t instanceof V&&n===i&&n instanceof k&&Re(r)&&!ve(r)&&n.isMatchingSnapshotId(t,r)}function F(e){return"object"==typeof e&&e&&!0===e.isType}var M=new Map;var L=function(){function e(e,t){Object.defineProperty(this,"hooks",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"call",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"flowsPending",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"running",{enumerable:!0,configurable:!0,writable:!0,value:!0}),e&&e.onStart(t)}return Object.defineProperty(e.prototype,"finish",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.running&&(this.running=!1,this.hooks&&this.hooks.onFinish(this.call,e))}}),Object.defineProperty(e.prototype,"incFlowsPending",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending++}}),Object.defineProperty(e.prototype,"decFlowsPending",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.flowsPending--}}),Object.defineProperty(e.prototype,"hasFlowsPending",{get:function(){return this.flowsPending>0},enumerable:!1,configurable:!0}),e}();function H(e){return{$MST_UNSERIALIZABLE:!0,type:e}}function U(e,r){t.runInAction((function(){xe(r).forEach((function(t){return function(e,t){var r=P(e,t.path||"");if(!r)throw new Ee("Invalid action path: ".concat(t.path||""));var n=ge(r);if("@APPLY_PATCHES"===t.name)return h.call(null,r,t.args[0]);if("@APPLY_SNAPSHOT"===t.name)return y.call(null,r,t.args[0]);if("function"!=typeof r[t.name])throw new Ee("Action '".concat(t.name,"' does not exist in '").concat(n.path,"'"));return r[t.name].apply(r,t.args?t.args.map((function(e){return(t=e)&&"object"==typeof t&&"$MST_DATE"in t?new Date(t.$MST_DATE):t;var t})):[])}(e,t)}))}))}function $(e,t,r){return void 0===r&&(r=!1),K(e,(function(n,i){if("action"===n.type&&n.id===n.rootId){var a=ge(n.context),o={name:n.name,path:Oe(ge(e),a),args:n.args.map((function(e,t){return function(e,t,r,n){if(n instanceof Date)return{$MST_DATE:n.getTime()};if(ze(n))return n;if(ve(n))return H("[MSTNode: ".concat(b(n).name,"]"));if("function"==typeof n)return H("[function]");if("object"==typeof n&&!ke(n)&&!De(n))return H("[object ".concat(n&&n.constructor&&n.constructor.name||"Complex Object","]"));try{return JSON.stringify(n),n}catch(e){return H(""+e)}}(0,n.name,0,e)}))};if(r){var u=i(n);return t(o),u}return t(o),i(n)}return i(n)}))}var B,G=1;function W(){return B}function Z(){return G++}function Y(e,n){var i=ge(e.context);"action"===e.type&&i.assertAlive({actionContext:e});var a=i._isRunningAction;i._isRunningAction=!0;var o=B,u=!o;B=e;try{return function(e,n,i,a){function o(r,n){var i=function(){var t,i;try{t=n.apply(null,r.args)}catch(e){i=e}if(a||!r.parentActionEvent)try{e.root.flushEndOfActionCallbacks()}catch(e){i||(i=e)}if(i)throw i;return t};return r.name?t.action(r.name,i)():t.action(i)()}var u=new Q(e,i);if(u.isEmpty)return o(n,i);var l=null;return function e(t){var n=u.getNextMiddleware(),c=n&&n.handler;if(!c)return o(t,i);if(!n.includeHooks&&r[t.name])return e(t);var s=!1;return c(t,(function(t,r){l=e(t),r&&(l=r(l))}),(function(e){s=!0,l=e})),!s||!a&&t.parentActionEvent?l:o(t,(function(){return l}))}(n)}(i,e,n,u)}finally{B=o,i._isRunningAction=a}}function J(e){if(e)return"action"===e.type?e:e.parentActionEvent}function q(e,t,r){var n=function(){var n=Z(),i=B,a=J(i);return Y({type:"action",name:t,id:n,args:Ue(arguments),context:e,tree:g(e),rootId:i?i.rootId:n,parentId:i?i.id:0,allParentIds:i?p(p([],f(i.allParentIds),!1),[i.id],!1):[],parentEvent:i,parentActionEvent:a},r)};return n._isMSTAction=!0,n._isFlowAction=r._isFlowAction,n}function K(e,t,r){return void 0===r&&(r=!0),ge(e).addMiddleWare(t,r)}var Q=function(){function e(e,t){Object.defineProperty(this,"arrayIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"inArrayIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"middlewares",{enumerable:!0,configurable:!0,writable:!0,value:[]}),t.$mst_middleware&&this.middlewares.push(t.$mst_middleware);for(var r=e;r;)r.middlewares&&this.middlewares.push(r.middlewares),r=r.parent}return Object.defineProperty(e.prototype,"isEmpty",{get:function(){return this.middlewares.length<=0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"getNextMiddleware",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.middlewares[this.arrayIndex];if(e){var t=e[this.inArrayIndex++];return t||(this.arrayIndex++,this.inArrayIndex=0,this.getNextMiddleware())}}}),e}();function X(){for(var e=W();e&&"action"!==e.type;)e=e.parentActionEvent;return e}function ee(e,t,r){for(var n="number"==typeof t?t:t.id,i=r?e:e.parentActionEvent;i;){if(i.id===n)return!0;i=i.parentActionEvent}return!1}var te=l({},{enabled:!1,indent:2,maxStringLength:100,maxArrayLength:10,maxPropertyCount:30,maxDepth:5});function re(){return l({},te)}function ne(e,t){try{return JSON.stringify(e,null,t)}catch(e){return"<Unserializable: ".concat(e,">")}}function ie(e){if("function"==typeof e)return"<function".concat(e.name?" "+e.name:"",">");if(ve(e))return"<".concat(e,">");var t=re();if(!t.enabled)return"`".concat(ne(e),"`");var r=function e(t,r,n){if("string"==typeof t)return t.length>n.maxStringLength?"".concat(t.slice(0,n.maxStringLength),"… (").concat(t.length-n.maxStringLength," more characters)"):t;if(Array.isArray(t)){if(r>=n.maxDepth)return"[…]";var i=t.slice(0,n.maxArrayLength).map((function(t){return e(t,r+1,n)}));return t.length>n.maxArrayLength&&i.push("… ".concat(t.length-n.maxArrayLength," more items")),i}if(ke(t)){if(r>=n.maxDepth)return"{…}";var a={},o=Object.keys(t);return o.slice(0,n.maxPropertyCount).forEach((function(i){a[i]=e(t[i],r+1,n)})),o.length>n.maxPropertyCount&&(a["…"]="".concat(o.length-n.maxPropertyCount," more keys")),a}return t}(e,0,t);return"`".concat(ne(r,t.indent||void 0),"`")}function ae(e){var t,r=e.value,n=e.context[e.context.length-1].type,i=e.context.map((function(e){return e.path})).filter((function(e){return e.length>0})).join("/"),a=i.length>0?'at path "/'.concat(i,'" '):"",o=ve(r)?"value of type ".concat(ge(r).type.name,":"):ze(r)?"value":"snapshot",u=n&&ve(r)&&n.is(ge(r).snapshot),l=re();return"".concat(a).concat(o," ").concat(ie(r)," is not assignable ").concat(n?"to type: `".concat(n.name,"`"):"")+(e.message?" (".concat(e.message,")"):"")+(n?It(n)||ze(r)?".":", expected an instance of `".concat(n.name,"` or a snapshot like `").concat((t=n,l.enabled?function(e,t){if(t<=0)return e;try{for(var r=" ".repeat(t),n="",i=0,a=null,o=!1,u=function(){n=n.replace(/[ \t]+$/,""),n+="\n"+r.repeat(Math.max(0,i))},l=0;l<e.length;l++){var c=e[l];if(a)n+=c,o?o=!1:"\\"===c?o=!0:c===a&&(a=null);else switch(c){case'"':case"'":a=c,n+=c;break;case"{":for(i++,n+="{",u();" "===e[l+1];)l++;break;case"}":i--,u(),n+="}";break;case";":for(n+=";",u();" "===e[l+1];)l++;break;default:n+=c}}return n}catch(t){return e}}(t.describe(),l.indent):t.describe()),"` instead.")+(u?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function oe(e,t,r){return e.concat([{path:t,type:r}])}function ue(){return Ie}function le(e,t,r){return[{context:e,value:t,message:r}]}function ce(e){return e.reduce((function(e,t){return e.concat(t)}),[])}function se(e,t){"undefined"!=typeof process&&process.env&&"true"===process.env.ENABLE_TYPE_CHECK&&fe(e,t)}function fe(e,t){var r=e.validate(t,[{path:"",type:e}]);if(r.length>0)throw new Ee(function(e,t,r){if(0===r.length)return;var n=ie(t),i=re().enabled?n:(a=n,a.length<280?a:"".concat(a.substring(0,272),"......").concat(a.substring(a.length-8)));var a;return"Error while converting ".concat(i," to `").concat(e.name,"`:\n\n ")+r.map(ae).join("\n ")}(e,t,r))}var pe,be=0,de=function(){function e(){Object.defineProperty(this,"cacheId",{enumerable:!0,configurable:!0,writable:!0,value:be++}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:t.observable.map()}),Object.defineProperty(this,"lastCacheModificationPerId",{enumerable:!0,configurable:!0,writable:!0,value:t.observable.map()})}return Object.defineProperty(e.prototype,"updateLastCacheModificationPerId",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e);this.lastCacheModificationPerId.set(e,void 0===t?1:t+1)}}),Object.defineProperty(e.prototype,"getLastCacheModificationPerId",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.lastCacheModificationPerId.get(e)||0;return"".concat(this.cacheId,"-").concat(t)}}),Object.defineProperty(e.prototype,"addNodeToCache",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){if(void 0===r&&(r=!0),e.identifierAttribute){var n=e.identifier;this.cache.has(n)||this.cache.set(n,t.observable.array([],Ce));var i=this.cache.get(n);if(-1!==i.indexOf(e))throw new Ee("Already registered");i.push(e),r&&this.updateLastCacheModificationPerId(n)}}}),Object.defineProperty(e.prototype,"mergeCache",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=this;t.values(e.identifierCache.cache).forEach((function(e){return e.forEach((function(e){r.addNodeToCache(e)}))}))}}),Object.defineProperty(e.prototype,"notifyDied",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.identifierAttribute){var t=e.identifier,r=this.cache.get(t);r&&(r.remove(e),r.length||this.cache.delete(t),this.updateLastCacheModificationPerId(e.identifier))}}}),Object.defineProperty(e.prototype,"splitCache",{enumerable:!1,configurable:!0,writable:!0,value:function(r){var n=this,i=new e,a=r.path+"/";return t.entries(this.cache).forEach((function(e){for(var t=f(e,2),o=t[0],u=t[1],l=!1,c=u.length-1;c>=0;c--){var s=u[c];s!==r&&0!==s.path.indexOf(a)||(i.addNodeToCache(s,!1),u.splice(c,1),u.length||n.cache.delete(o),l=!0)}l&&n.updateLastCacheModificationPerId(o)})),i}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.cache.get(t);return!!r&&r.some((function(t){return e.isAssignableFrom(t.type)}))}}),Object.defineProperty(e.prototype,"resolve",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.cache.get(t);if(!r)return null;var n=r.filter((function(t){return e.isAssignableFrom(t.type)}));switch(n.length){case 0:return null;case 1:return n[0];default:throw new Ee("Cannot resolve a reference to type '".concat(e.name,"' with id: '").concat(t,"' unambigously, there are multiple candidates: ").concat(n.map((function(e){return e.path})).join(", ")))}}}),e}();function he(e,t,r,n,i){var a=me(i);if(a){if(a.parent)throw new Ee("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '".concat(t?t.path:"","/").concat(r,"', but it lives already at '").concat(a.path,"'"));return t&&a.setParent(t,r),a}return new V(e,t,r,n,i)}function ye(e,t,r,n,i){return new S(e,t,r,n,i)}function ve(e){return!(!e||!e.$treenode)}function ge(e){if(!ve(e))throw new Ee("Value ".concat(e," is no MST Node"));return e.$treenode}function me(e){return e&&e.$treenode||null}function we(){return ge(this).snapshot}!function(e){e[e.INITIALIZING=0]="INITIALIZING",e[e.CREATED=1]="CREATED",e[e.FINALIZED=2]="FINALIZED",e[e.DETACHING=3]="DETACHING",e[e.DEAD=4]="DEAD"}(pe||(pe={}));var Pe=function(e){return".."};function Oe(e,t){if(e.root!==t.root)throw new Ee("Cannot calculate relative path: objects '".concat(e,"' and '").concat(t,"' are not part of the same object tree"));for(var r=Qe(e.path),n=Qe(t.path),i=0;i<r.length&&r[i]===n[i];i++);return r.slice(i).map(Pe).join("/")+Ke(n.slice(i))}function je(e,t,r){return void 0===r&&(r=!0),_e(e,Qe(t),r)}function _e(e,t,r){void 0===r&&(r=!0);var n=e;try{for(var i=0;i<t.length;i++){var a=t[i];if(".."===a){if(n=n.parent)continue}else{if("."===a)continue;if(n){if(n instanceof S){var o=n.value;ve(o)&&(n=ge(o))}if(n instanceof V)if(n.getChildType(a)&&(n=n.getChildNode(a)))continue}}throw new Ee("Could not resolve '".concat(a,"' in path '").concat(Ke(t.slice(0,i))||"/","' while resolving '").concat(Ke(t),"'"))}}catch(e){if(!r)return;throw e}return n}function Se(e){if(!e)return Ie;var t=Object.keys(e);if(!t.length)return Ie;var r=new Array(t.length);return t.forEach((function(t,n){r[n]=e[t]})),r}var Ae=Object.toString(),Ie=Object.freeze([]),Te=Object.freeze({}),Ce=t._getGlobalState().useProxies?{deep:!1}:{deep:!1,proxy:!1};Object.freeze(Ce);var Ee=function(e){function t(t){return void 0===t&&(t="Illegal state"),e.call(this,"[mobx-state-tree] ".concat(t))||this}return u(t,e),t}(Error);function Ne(e){return e}var Ve=Number.isInteger;function De(e){return Array.isArray(e)||t.isObservableArray(e)}function xe(e){return e?De(e)?e:[e]:Ie}function ke(e){var t;if(null===e||"object"!=typeof e)return!1;var r=Object.getPrototypeOf(e);return null==r||(null===(t=r.constructor)||void 0===t?void 0:t.toString())===Ae}function Re(e){return!(null===e||"object"!=typeof e||e instanceof Date||e instanceof RegExp)}function ze(e,t){return void 0===t&&(t=!0),null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||t&&e instanceof Date}function Fe(e){return"function"!=typeof e}function Me(e,r,n){!function(e,r,n){t.isObservableObject(e)?t.defineProperty(e,r,n):Object.defineProperty(e,r,n)}(e,r,{enumerable:!1,writable:!1,configurable:!0,value:n})}var Le=function(){function e(){Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:[]})}return Object.defineProperty(e.prototype,"hasSubscribers",{get:function(){return this.handlers.length>0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;return void 0===t&&(t=!1),t?this.handlers.unshift(e):this.handlers.push(e),function(){r.unregister(e)}}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.handlers.indexOf(e)>=0}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.handlers.indexOf(e);t>=0&&this.handlers.splice(t,1)}}),Object.defineProperty(e.prototype,"clear",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.handlers.length=0}}),Object.defineProperty(e.prototype,"emit",{enumerable:!1,configurable:!0,writable:!0,value:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=this.handlers.slice();r.forEach((function(t){return t.apply(void 0,p([],f(e),!1))}))}}),e}(),He=function(){function e(){Object.defineProperty(this,"eventHandlers",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}return Object.defineProperty(e.prototype,"hasSubscribers",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.eventHandlers&&this.eventHandlers[e];return!!t&&t.hasSubscribers}}),Object.defineProperty(e.prototype,"register",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){void 0===r&&(r=!1),this.eventHandlers||(this.eventHandlers={});var n=this.eventHandlers[e];return n||(n=this.eventHandlers[e]=new Le),n.register(t,r)}}),Object.defineProperty(e.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.eventHandlers&&this.eventHandlers[e];return!!r&&r.has(t)}}),Object.defineProperty(e.prototype,"unregister",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.eventHandlers&&this.eventHandlers[e];r&&r.unregister(t)}}),Object.defineProperty(e.prototype,"clear",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.eventHandlers&&delete this.eventHandlers[e]}}),Object.defineProperty(e.prototype,"clearAll",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.eventHandlers=void 0}}),Object.defineProperty(e.prototype,"emit",{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,r=[],n=1;n<arguments.length;n++)r[n-1]=arguments[n];var i=this.eventHandlers&&this.eventHandlers[e];i&&(t=i).emit.apply(t,p([],f(r),!1))}}),e}();function Ue(e){for(var t=new Array(e.length),r=0;r<e.length;r++)t[r]=e[r];return t}function $e(e,t){return 0===e.indexOf(t)}var Be=function(e,t){};function Ge(e){"function"==typeof queueMicrotask?queueMicrotask(e):"function"==typeof setImmediate?setImmediate(e):setTimeout(e,1)}function We(e){return function(e,t){var r=function(){var n=Z(),i=W();if(!i)throw new Ee("a mst flow must always have a parent context");var a=J(i);if(!a)throw new Ee("a mst flow must always have a parent action context");var o={name:e,id:n,tree:i.tree,context:i.context,parentId:i.id,allParentIds:p(p([],f(i.allParentIds),!1),[i.id],!1),rootId:i.rootId,parentEvent:i,parentActionEvent:a},u=arguments;function c(e,t,n){return e.$mst_middleware=r.$mst_middleware,Y(l(l({},o),{type:t,args:[n]}),e)}return new Promise((function(e,n){var i,a=function(){i=t.apply(null,arguments),s(void 0)};function s(e){var t;try{var r=c((function(e){t=i.next(e)}),"flow_resume",e);r instanceof Error&&(t=i.throw(r))}catch(e){return void Ge((function(){c((function(t){n(e)}),"flow_throw",e)}))}p(t)}function f(e){var t;try{c((function(e){t=i.throw(e)}),"flow_resume_error",e)}catch(e){return void Ge((function(){c((function(t){n(e)}),"flow_throw",e)}))}p(t)}function p(t){if(!t.done){if(!t.value||"function"!=typeof t.value.then)throw new Ee("Only promises can be yielded to `async`, got: "+t);return t.value.then(s,f)}Ge((function(){c((function(t){e(t)}),"flow_return",t.value)}))}a.$mst_middleware=r.$mst_middleware,Y(l(l({},o),{type:"flow_spawn",args:Ue(u)}),a)}))};return r._isFlowAction=!0,r}(e.name,e)}function Ze(e){switch(e.op){case"add":return{op:"add",path:e.path,value:e.value};case"remove":return{op:"remove",path:e.path};case"replace":return{op:"replace",path:e.path,value:e.value}}}function Ye(e){switch(e.op){case"add":return{op:"remove",path:e.path};case"remove":return{op:"add",path:e.path,value:e.oldValue};case"replace":return{op:"replace",path:e.path,value:e.oldValue}}}function Je(e){return!0==("number"==typeof e)?""+e:-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function qe(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Ke(e){if(0===e.length)return"";var t=function(e){return e.map(Je).join("/")};return"."===e[0]||".."===e[0]?t(e):"/"+t(e)}function Qe(e){var t=e.split("/").map(qe);if(!(""===e||"."===e||".."===e||$e(e,"/")||$e(e,"./")||$e(e,"../")))throw new Ee("a json path must be either rooted, empty or relative, but got '".concat(e,"'"));return""===t[0]&&t.shift(),t}Be.ids={};var Xe=Symbol("$preProcessorFailed"),et=function(e){function t(t,r,n){var i=e.call(this,n||t.name)||this;return Object.defineProperty(i,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,"_processors",{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return u(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|E.SnapshotProcessor},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"snapshotProcessor(".concat(this._subtype.describe(),")")}}),Object.defineProperty(t.prototype,"preProcessSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._processors.preProcessor?this._processors.preProcessor.call(null,e):e}}),Object.defineProperty(t.prototype,"preProcessSnapshotSafe",{enumerable:!1,configurable:!0,writable:!0,value:function(e){try{return this.preProcessSnapshot(e)}catch(e){return Xe}}}),Object.defineProperty(t.prototype,"postProcessSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._processors.postProcessor?this._processors.postProcessor.call(null,e,t.storedValue):e}}),Object.defineProperty(t.prototype,"_fixNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;!function(e,t){for(var r,n,i=[],a=2;a<arguments.length;a++)i[a-2]=arguments[a];try{for(var o=s(i),u=o.next();!u.done;u=o.next()){var l=u.value;e[l]=t[l].bind(t)}}catch(e){r={error:e}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}(e.type,this,"create"),e instanceof V&&(e.hasSnapshotPostProcessor=!!this._processors.postProcessor);var r=e.getSnapshot;e.getSnapshot=function(){return t.postProcessSnapshot(r.call(e),e)},Dt(this._subtype)||(e.getReconciliationType=function(){return t})}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=ve(n)?n:this.preProcessSnapshot(n),a=this._subtype.instantiate(e,t,r,i);return this._fixNode(a),a}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=this._subtype.reconcile(e,ve(t)?t:this.preProcessSnapshot(t),r,n);return i!==e&&this._fixNode(i),i}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t=!0);var r=this._subtype.getSnapshot(e);return t?this.postProcessSnapshot(r,e):r}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.preProcessSnapshotSafe(e);return r===Xe?le(t,e,"Failed to preprocess value"):this._subtype.validate(r,t)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),Object.defineProperty(t.prototype,"is",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=F(e)?this._subtype:ve(e)?e:this.preProcessSnapshotSafe(e);return t!==Xe&&0===this._subtype.validate(t,[{path:"",type:this._subtype}]).length}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"isMatchingSnapshotId",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(!(this._subtype instanceof k))return!1;var r=this.preProcessSnapshot(t);return this._subtype.isMatchingSnapshotId(e,r)}}),t}(x);var tt,rt="Map.put can only be used to store complex values that have an identifier type attribute";!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.YES=1]="YES",e[e.NO=2]="NO"}(tt||(tt={}));var nt=function(e){function t(t,r){return e.call(this,t,(function(e){return e}),r)||this}return u(t,e),Object.defineProperty(t.prototype,"get",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.get.call(this,""+t)}}),Object.defineProperty(t.prototype,"has",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.has.call(this,""+t)}}),Object.defineProperty(t.prototype,"delete",{enumerable:!1,configurable:!0,writable:!0,value:function(t){return e.prototype.delete.call(this,""+t)}}),Object.defineProperty(t.prototype,"set",{enumerable:!1,configurable:!0,writable:!0,value:function(t,r){return e.prototype.set.call(this,""+t,r)}}),Object.defineProperty(t.prototype,"put",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!e)throw new Ee("Map.put cannot be used to set empty values");if(ve(e)){var t=ge(e);if(null===t.identifier)throw new Ee(rt);return this.set(t.identifier,e),e}if(Re(e)){var r=ge(this),n=r.type;if(n.identifierMode!==tt.YES)throw new Ee(rt);var i=e[n.mapIdentifierAttribute];if(!nr(i)){var a=this.put(n.getChildType().create(e,r.environment));return this.put(v(a))}var o=rr(i);return this.set(o,e),this.get(o)}throw new Ee("Map.put can only be used to store complex values")}}),t}(t.ObservableMap),it=function(e){function r(t,r,n){void 0===n&&(n=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"identifierMode",{enumerable:!0,configurable:!0,writable:!0,value:tt.UNKNOWN}),Object.defineProperty(i,"mapIdentifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Map}),Object.defineProperty(i,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),i._determineIdentifierMode(),i.hookInitializers=n,i}return u(r,e),Object.defineProperty(r.prototype,"hooks",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new r(this.name,this._subType,t)}}),Object.defineProperty(r.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._determineIdentifierMode(),he(this,e,t,r,n)}}),Object.defineProperty(r.prototype,"_determineIdentifierMode",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.identifierMode===tt.UNKNOWN){var e=[];if(function e(t,r){var n,i,a=t.getSubTypes();if("cannotDetermine"===a)return!1;if(a){var o=xe(a);try{for(var u=s(o),l=u.next();!l.done;l=u.next()){if(!e(l.value,r))return!1}}catch(e){n={error:e}}finally{try{l&&!l.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}}return t instanceof pt&&r.push(t),!0}(this._subType,e)){var t=e.reduce((function(e,t){if(!t.identifierAttribute)return e;if(e&&e!==t.identifierAttribute)throw new Ee("The objects in a map should all have the same identifier attribute, expected '".concat(e,"', but child of type '").concat(t.name,"' declared attribute '").concat(t.identifierAttribute,"' as identifier"));return t.identifierAttribute}),void 0);t?(this.identifierMode=tt.YES,this.mapIdentifierAttribute=t):this.identifierMode=tt.NO}}}}),Object.defineProperty(r.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t={});var r=e.type._subType,n={};return Object.keys(t).forEach((function(i){n[i]=r.instantiate(e,i,void 0,t[i])})),n}}),Object.defineProperty(r.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new nt(e,this.name)}}),Object.defineProperty(r.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){t._interceptReads(r,e.unbox),e.type.hookInitializers.forEach((function(e){var t=e(r);Object.keys(t).forEach((function(e){var n=t[e],i=q(r,e,n);Me(r,e,i)}))})),t.intercept(r,this.willChange),t.observe(r,this.didChange)}}),Object.defineProperty(r.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(r.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return t.values(e.storedValue)}}),Object.defineProperty(r.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=e.storedValue.get(""+t);if(!r)throw new Ee("Not a child "+t);return r}}),Object.defineProperty(r.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ge(e.object),r=e.name;t.assertWritable({subpath:r});var n=t.type,i=n._subType;switch(e.type){case"update":var a=e.newValue;if(a===e.object.get(r))return null;se(i,a),e.newValue=i.reconcile(t.getChildNode(r),e.newValue,t,r),n.processIdentifier(r,e.newValue);break;case"add":se(i,e.newValue),e.newValue=i.instantiate(t,r,void 0,e.newValue),n.processIdentifier(r,e.newValue)}return e}}),Object.defineProperty(r.prototype,"processIdentifier",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.identifierMode===tt.YES&&t instanceof V){var r=t.identifier;if(r!==e)throw new Ee("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '".concat(r,"', but expected: '").concat(e,"'"))}}}),Object.defineProperty(r.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return e.getChildren().forEach((function(e){t[e.subpath]=e.snapshot})),t}}),Object.defineProperty(r.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach((function(r){t[r]=e[r].getSnapshot()})),t}}),Object.defineProperty(r.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ge(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:Je(e.name),value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"add":return void t.emitPatch({op:"add",path:Je(e.name),value:e.newValue.snapshot,oldValue:void 0},t);case"delete":var r=e.oldValue.snapshot;return e.oldValue.die(),void t.emitPatch({op:"remove",path:Je(e.name),oldValue:r},t)}}}),Object.defineProperty(r.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){var n=e.storedValue;switch(r.op){case"add":case"replace":n.set(t,r.value);break;case"remove":n.delete(t)}}}),Object.defineProperty(r.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(ke(t)){var r=e.storedValue,n=this.getChildType();for(var i in Array.from(r.keys()).forEach((function(i){if(Object.prototype.hasOwnProperty.call(t,i)){var a=e.getChildNode(i),o=t[i];a.snapshot!==o&&(z(n,a,o)?a.applySnapshot(o):r.set(i,o))}else r.delete(i)})),t)Object.prototype.hasOwnProperty.call(t,i)&&!r.has(i)&&r.set(i,t[i])}else se(this,t)}}),Object.defineProperty(r.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(r.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;return ke(e)?ce(Object.keys(e).map((function(n){return r._subType.validate(e[n],oe(t,n,r._subType))}))):le(t,e,"Value is not a plain object")}}),Object.defineProperty(r.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return Te}}),Object.defineProperty(r.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.delete(t)}}),r}(k);it.prototype.applySnapshot=t.action(it.prototype.applySnapshot);var at=function(e){function r(t,r,n){void 0===n&&(n=[]);var i=e.call(this,t)||this;return Object.defineProperty(i,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Array}),Object.defineProperty(i,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),i.hookInitializers=n,i}return u(r,e),Object.defineProperty(r.prototype,"hooks",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new r(this.name,this._subType,t)}}),Object.defineProperty(r.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return he(this,e,t,r,n)}}),Object.defineProperty(r.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t=[]);var r=e.type._subType,n={};return t.forEach((function(t,i){var a=""+i;n[a]=r.instantiate(e,a,void 0,t)})),n}}),Object.defineProperty(r.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=l(l({},Ce),{name:this.name});return t.observable.array(Se(e),r)}}),Object.defineProperty(r.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){t._getAdministration(r).dehancer=e.unbox,e.type.hookInitializers.forEach((function(e){var t=e(r);Object.keys(t).forEach((function(e){var n=t[e],i=q(r,e,n);Me(r,e,i)}))})),t.intercept(r,this.willChange),t.observe(r,this.didChange)}}),Object.defineProperty(r.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(r.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.slice()}}),Object.defineProperty(r.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=Number(t);if(r<e.storedValue.length)return e.storedValue[r];throw new Ee("Not a child: "+t)}}),Object.defineProperty(r.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ge(e.object);t.assertWritable({subpath:""+e.index});var r=t.type._subType,n=t.getChildren();switch(e.type){case"update":if(e.newValue===e.object[e.index])return null;var i=ot(t,r,[n[e.index]],[e.newValue],[e.index]);if(!i)return null;e.newValue=i[0];break;case"splice":var a=e.index,o=e.removedCount,u=e.added,l=ot(t,r,n.slice(a,a+o),u,u.map((function(e,t){return a+t})));if(!l)return null;e.added=l;for(var c=a+o;c<n.length;c++)n[c].setParent(t,""+(c+u.length-o))}return e}}),Object.defineProperty(r.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.getChildren().map((function(e){return e.snapshot}))}}),Object.defineProperty(r.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=[];return Object.keys(e).forEach((function(r){t.push(e[r].getSnapshot())})),t}}),Object.defineProperty(r.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=ge(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:""+e.index,value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"splice":if(e.removedCount&&e.addedCount===e.object.length)return void t.emitPatch({op:"replace",path:"",value:t.snapshot,oldValue:e.removed.map((function(e){return e.snapshot}))},t);for(var r=e.removedCount-1;r>=0;r--)t.emitPatch({op:"remove",path:""+(e.index+r),oldValue:e.removed[r].snapshot},t);for(r=0;r<e.addedCount;r++)t.emitPatch({op:"add",path:""+(e.index+r),value:e.added[r].snapshot,oldValue:void 0},t);return}}}),Object.defineProperty(r.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){var n=e.storedValue,i="-"===t?n.length:Number(t);switch(r.op){case"replace":n[i]=r.value;break;case"add":n.splice(i,0,r.value);break;case"remove":n.splice(i,1)}}}),Object.defineProperty(r.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r,n;if(De(t)){var i=e.storedValue,a=e.getChildren(),o=a.length,u=t.length,l=this.getChildType(),c=function(e,t,r){var n=0;for(;n<r&&e[n].snapshot===t[n];)n++;return n}(a,t,Math.min(o,u));if(c!==o||c!==u)if(o!==u||e.hasPatchSubscribers())i.replace(t);else if(function(e,t,r,n){for(var i=n;i<t.length;i++){var a=t[i];if(a.snapshot!==r[i]){if(!z(e,a,r[i]))return!1;if(!a.identifierAttribute||null===a.identifier)return!1}}return!0}(l,a,t,c))!function(e,t,r){for(var n=r;n<e.length;n++){var i=e[n];i.snapshot!==t[n]&&i.applySnapshot(t[n])}}(a,t,c);else{for(var f=[],p=c;p<o;p++)a[p].snapshot!==t[p]&&f.push(p);try{for(var b=s(f),d=b.next();!d.done;d=b.next()){var h=d.value;i[h]=t[h]}}catch(e){r={error:e}}finally{try{d&&!d.done&&(n=b.return)&&n.call(b)}finally{if(r)throw r.error}}}}else se(this,t)}}),Object.defineProperty(r.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subType}}),Object.defineProperty(r.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this;return De(e)?ce(e.map((function(e,n){return r._subType.validate(e,oe(t,""+n,r._subType))}))):le(t,e,"Value is not an array")}}),Object.defineProperty(r.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return Ie}}),Object.defineProperty(r.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue.splice(Number(t),1)}}),r}(k);function ot(e,t,r,n,i){for(var a,o=!0,u=0;;u++){var l=u<=n.length-1,c=r[u],s=l?n[u]:void 0,f=""+i[u];if(((a=s)instanceof S||a instanceof V)&&(s=s.storedValue),!c&&!l)break;if(l)if(c)if(lt(c,s))r[u]=ut(t,e,f,s,c);else{for(var p=void 0,b=u;b<r.length;b++)if(lt(r[b],s)){p=r.splice(b,1)[0];break}o=!1;d=ut(t,e,f,s,p);r.splice(u,0,d)}else{if(ve(s)&&ge(s).parent===e)throw new Ee("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '".concat(e.path,"/").concat(f,"', but it lives already at '").concat(ge(s).path,"'"));o=!1;var d=ut(t,e,f,s);r.splice(u,0,d)}else o=!1,r.splice(u,1),c instanceof V&&c.createObservableInstanceIfNeeded(),c.die(),u--}return o?null:r}function ut(e,t,r,n,i){se(e,n);var a=function(){if(ve(n)){var a=ge(n);if(a.assertAlive(Te),null!==a.parent&&a.parent===t)return a.setParent(t,r),a}return i?e.reconcile(i,n,t,r):e.instantiate(t,r,void 0,n)}();return i&&i!==a&&(i instanceof V&&i.createObservableInstanceIfNeeded(),i.die()),a}function lt(e,t){if(!e.isAlive)return!1;if(ve(t)){var r=ge(t);return r.isAlive&&r===e}if(e.snapshot===t)return!0;if(!(e instanceof V))return!1;var n=e.getReconciliationType();return null!==e.identifier&&e.identifierAttribute&&ke(t)&&n.is(t)&&n.isMatchingSnapshotId(e,t)}at.prototype.applySnapshot=t.action(at.prototype.applySnapshot);function ct(){return ge(this).toString()}var st={name:"AnonymousModel",properties:{},initializers:Ie};function ft(e){var t=Object.keys(e),n=new Set;return t.forEach((function(e){if(n.has(e))throw new Ee("".concat(e," is declared twice in the model. Model should not contain the same keys"));n.add(e)})),t.reduce((function(t,n){if(n in r)throw new Ee("Hook '".concat(n,"' was defined as property. Hooks should be defined as part of the actions"));var i=Object.getOwnPropertyDescriptor(e,n);if("get"in i)throw new Ee("Getters are not supported as properties. Please use views instead");var a=i.value;if(null==a)throw new Ee("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(ze(a))t[n]=kt(function(e){switch(typeof e){case"string":return ht;case"number":return yt;case"boolean":return Ot;case"bigint":return Pt;case"object":if(e instanceof Date)return At}throw new Ee("Cannot determine primitive type from value "+e)}(a),a);else if(a instanceof it)t[n]=kt(a,{});else if(a instanceof at)t[n]=kt(a,[]);else if(!F(a))throw new Ee("Invalid type definition for property '".concat(n,"', cannot infer a type from a value like '").concat(a,"' (").concat(typeof a,")"));return t}),l({},e))}var pt=function(e){function n(t){var r=e.call(this,t.name||st.name)||this;return Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Object}),Object.defineProperty(r,"initializers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"properties",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"preProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"postProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"propertyNames",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"named",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return r.cloneAndEnhance({name:e})}}),Object.defineProperty(r,"props",{enumerable:!0,configurable:!0,writable:!0,value:function(e){return r.cloneAndEnhance({properties:e})}}),Object.defineProperty(r,"preProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=r.preProcessor;return t?r.cloneAndEnhance({preProcessor:function(r){return t(e(r))}}):r.cloneAndEnhance({preProcessor:e})}}),Object.defineProperty(r,"postProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=r.postProcessor;return t?r.cloneAndEnhance({postProcessor:function(r){return e(t(r))}}):r.cloneAndEnhance({postProcessor:e})}}),Object.assign(r,st,t),r.properties=ft(r.properties),r.properties,r.propertyNames=Object.keys(r.properties),r.identifierAttribute=r._getIdentifierAttribute(),r}return u(n,e),Object.defineProperty(n.prototype,"_getIdentifierAttribute",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=void 0;return this.forAllProps((function(t,r){if(r.flags&E.Identifier){if(e)throw new Ee("Cannot define property '".concat(t,"' as object identifier, property '").concat(e,"' is already defined as identifier property"));e=t}})),e}}),Object.defineProperty(n.prototype,"cloneAndEnhance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return new n({name:e.name||this.name,properties:Object.assign({},this.properties,e.properties),initializers:this.initializers.concat(e.initializers||[]),preProcessor:e.preProcessor||this.preProcessor,postProcessor:e.postProcessor||this.postProcessor})}}),Object.defineProperty(n.prototype,"actions",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(r){return t.instantiateActions(r,e(r)),r}]})}}),Object.defineProperty(n.prototype,"instantiateActions",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this;if(!ke(t))throw new Ee("actions initializer should return a plain object containing actions");Object.getOwnPropertyNames(t).forEach((function(i){if(i in n.properties)throw new Ee("'".concat(i,"' is a property and cannot be declared as an action"));if("preProcessSnapshot"===i)throw new Ee("Cannot define action '".concat("preProcessSnapshot","', it should be defined using 'type.preProcessSnapshot(fn)' instead"));if("postProcessSnapshot"===i)throw new Ee("Cannot define action '".concat("postProcessSnapshot","', it should be defined using 'type.postProcessSnapshot(fn)' instead"));var a=t[i],o=e[i];if(i in r&&o){var u=a;a=function(){o.apply(null,arguments),u.apply(null,arguments)}}var l=a.$mst_middleware,c=a.bind(t);c._isFlowAction=a._isFlowAction||!1,c.$mst_middleware=l;var s=q(e,i,c);t[i]=s,Me(e,i,s)}))}}),Object.defineProperty(n.prototype,"volatile",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;if("function"!=typeof e)throw new Ee("You passed an ".concat(typeof e," to volatile state as an argument, when function is expected"));return this.cloneAndEnhance({initializers:[function(r){return t.instantiateVolatileState(r,e(r)),r}]})}}),Object.defineProperty(n.prototype,"instantiateVolatileState",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){var n=this;if(!ke(r))throw new Ee("volatile state initializer should return a plain object containing state");Object.getOwnPropertyNames(r).forEach((function(i){if(i in n.properties)throw new Ee("'".concat(i,"' is a property and cannot be declared as volatile state"));t.set(e,i,r[i])}))}}),Object.defineProperty(n.prototype,"extend",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(r){var n=e(r),i=n.actions,a=n.views,o=n.state,u=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}(n,["actions","views","state"]);for(var l in u)throw new Ee("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '".concat(l,"'"));return o&&t.instantiateVolatileState(r,o),a&&t.instantiateViews(r,a),i&&t.instantiateActions(r,i),r}]})}}),Object.defineProperty(n.prototype,"views",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;return this.cloneAndEnhance({initializers:[function(r){return t.instantiateViews(r,e(r)),r}]})}}),Object.defineProperty(n.prototype,"instantiateViews",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){var n=this;if(!ke(r))throw new Ee("views initializer should return a plain object containing views");Object.getOwnPropertyNames(r).forEach((function(i){var a;if(i in n.properties)throw new Ee("'".concat(i,"' is a property and cannot be declared as a view"));var o=Object.getOwnPropertyDescriptor(r,i);if("get"in o)t.defineProperty(e,i,o),t.makeObservable(e,((a={})[i]=t.computed,a));else{if("function"!=typeof o.value)throw new Ee("A view member should either be a function or getter based property");Me(e,i,o.value)}}))}}),Object.defineProperty(n.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return he(this,e,t,r,ve(n)?n:this.applySnapshotPreProcessor(n))}}),Object.defineProperty(n.prototype,"initializeChildNodes",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){void 0===t&&(t={});var r=e.type,n={};return r.forAllProps((function(r,i){n[r]=i.instantiate(e,r,void 0,t[r])})),n}}),Object.defineProperty(n.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var r=l(l({},Ce),{name:this.name});return t.observable.object(e,Te,r)}}),Object.defineProperty(n.prototype,"finalizeNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){Me(r,"toString",ct),this.forAllProps((function(n){t._interceptReads(r,n,e.unbox)})),this.initializers.reduce((function(e,t){return t(e)}),r),t.intercept(r,this.willChange),t.observe(r,this.didChange)}}),Object.defineProperty(n.prototype,"willChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,r=ge(t.object),n=t.name;r.assertWritable({subpath:n});var i=r.type.properties[n];return i&&(se(i,t.newValue),t.newValue=i.reconcile(r.getChildNode(n),t.newValue,r,n)),t}}),Object.defineProperty(n.prototype,"didChange",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=e,r=ge(t.object);if(r.type.properties[t.name]){var n=t.oldValue?t.oldValue.snapshot:void 0;r.emitPatch({op:"replace",path:Je(t.name),value:t.newValue.snapshot,oldValue:n},r)}}}),Object.defineProperty(n.prototype,"getChildren",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this,r=[];return this.forAllProps((function(n){r.push(t.getChildNode(e,n))})),r}}),Object.defineProperty(n.prototype,"getChildNode",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){var n;if(!(r in this.properties))throw new Ee("Not a value property: "+r);var i=t._getAdministration(e.storedValue,r),a=null===(n=i.raw)||void 0===n?void 0:n.call(i);if(!a)throw new Ee("Node not available for property "+r);return a}}),Object.defineProperty(n.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r){var n=this;void 0===r&&(r=!0);var i={};return this.forAllProps((function(r,a){t.getAtom(e.storedValue,r).reportObserved(),i[r]=n.getChildNode(e,r).snapshot})),r?this.applySnapshotPostProcessor(i):i}}),Object.defineProperty(n.prototype,"processInitialSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t={};return Object.keys(e).forEach((function(r){t[r]=e[r].getSnapshot()})),this.applySnapshotPostProcessor(t)}}),Object.defineProperty(n.prototype,"applyPatchLocally",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r){if("replace"!==r.op&&"add"!==r.op)throw new Ee("object does not support operation ".concat(r.op));e.storedValue[t]=r.value}}),Object.defineProperty(n.prototype,"applySnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.applySnapshotPreProcessor(t),n=!ke(r);(ke(t)&&!n||(se(this,t),!n))&&this.forAllProps((function(t,n){var i=e.getChildNode(t),a=r[t];i.snapshot!==a&&(z(n,i,a)?i.applySnapshot(a):e.storedValue[t]=a)}))}}),Object.defineProperty(n.prototype,"applySnapshotPreProcessor",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.preProcessor;return t?t.call(null,e):e}}),Object.defineProperty(n.prototype,"applySnapshotPostProcessor",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.postProcessor;return t?t.call(null,e):e}}),Object.defineProperty(n.prototype,"getChildType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.properties[e]}}),Object.defineProperty(n.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this,n=this.applySnapshotPreProcessor(e);return ke(n)?ce(this.propertyNames.map((function(e){return r.properties[e].validate(n[e],oe(t,e,r.properties[e]))}))):le(t,n,"Value is not a plain object")}}),Object.defineProperty(n.prototype,"forAllProps",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;this.propertyNames.forEach((function(r){return e(r,t.properties[r])}))}}),Object.defineProperty(n.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this;return"{ "+this.propertyNames.map((function(t){return t+": "+e.properties[t].describe()})).join("; ")+" }"}}),Object.defineProperty(n.prototype,"getDefaultSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){return Te}}),Object.defineProperty(n.prototype,"removeChild",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){e.storedValue[t]=void 0}}),n}(k);function bt(e){return F(e)&&(e.flags&E.Object)>0}pt.prototype.applySnapshot=t.action(pt.prototype.applySnapshot);var dt=function(e){function t(t,r,n,i){void 0===i&&(i=Ne);var a=e.call(this,t)||this;return Object.defineProperty(a,"flags",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,"checker",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,"initializer",{enumerable:!0,configurable:!0,writable:!0,value:i}),a.flags=r,a}return u(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return ye(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.initializer(e)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(ze(e)&&this.checker(e))return ue();var r="Date"===this.name?"Date or a unix milliseconds timestamp":this.name;return le(t,e,"Value is not a ".concat(r))}}),t}(R),ht=new dt("string",E.String,(function(e){return"string"==typeof e})),yt=new dt("number",E.Number,(function(e){return"number"==typeof e})),vt=new dt("integer",E.Integer,(function(e){return Ve(e)})),gt=new dt("float",E.Float,(function(e){return t=e,Number(t)===t&&t%1!=0;var t})),mt=new dt("finite",E.Finite,(function(e){return t=e,Number.isFinite(t);var t})),wt=new dt("bigint",E.BigInt,(function(e){if("bigint"==typeof e)return!0;if("string"==typeof e||"number"==typeof e)try{return BigInt(e),!0}catch(e){}return!1}),(function(e){return"bigint"==typeof e?e:BigInt(e)}));wt.getSnapshot=function(e){return String(e.storedValue)};var Pt=wt,Ot=new dt("boolean",E.Boolean,(function(e){return"boolean"==typeof e})),jt=new dt("null",E.Null,(function(e){return null===e})),_t=new dt("undefined",E.Undefined,(function(e){return void 0===e})),St=new dt("Date",E.Date,(function(e){return"number"==typeof e||e instanceof Date}),(function(e){return e instanceof Date?e:new Date(e)}));St.getSnapshot=function(e){return e.storedValue.getTime()};var At=St;function It(e){return F(e)&&(e.flags&(E.String|E.Number|E.Integer|E.Boolean|E.Date|E.BigInt))>0}var Tt=function(e){function t(t){var r=e.call(this,JSON.stringify(t))||this;return Object.defineProperty(r,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Literal}),r.value=t,r}return u(t,e),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return ye(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return JSON.stringify(this.value)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return ze(e)&&e===this.value?ue():le(t,e,"Value is not a literal ".concat(JSON.stringify(this.value)))}}),t}(R);function Ct(e){return new Tt(e)}var Et=function(e){function t(t,r,n,i){var a=e.call(this,t)||this;return Object.defineProperty(a,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(a,"_predicate",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(a,"_message",{enumerable:!0,configurable:!0,writable:!0,value:i}),a}return u(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|E.Refinement},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._subtype.instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this._subtype.validate(e,t);if(r.length>0)return r;var n=ve(e)?ge(e).snapshot:e;return this._predicate(n)?ue():le(t,e,this._message(e))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._subtype.reconcile(e,t,r,n)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(x);var Nt=function(e){function t(t,r,n){var i=e.call(this,t)||this;return Object.defineProperty(i,"_types",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"_dispatcher",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(i,"_eager",{enumerable:!0,configurable:!0,writable:!0,value:!0}),n=l({eager:!0,dispatcher:void 0},n),i._dispatcher=n.dispatcher,n.eager||(i._eager=!1),i}return u(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){var e=E.Union;return this._types.forEach((function(t){e|=t.flags})),e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._types.some((function(t){return t.isAssignableFrom(e)}))}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"("+this._types.map((function(e){return e.describe()})).join(" | ")+")"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=this.determineType(n,void 0);if(!i)throw new Ee("No matching type for union "+this.describe());return i.instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=this.determineType(t,e.getReconciliationType());if(!i)throw new Ee("No matching type for union "+this.describe());return i.reconcile(e,t,r,n)}}),Object.defineProperty(t.prototype,"determineType",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this._dispatcher?this._dispatcher(e):t?t.is(e)?t:this._types.filter((function(e){return e!==t})).find((function(t){return t.is(e)})):this._types.find((function(t){return t.is(e)}))}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this._dispatcher)return this._dispatcher(e).validate(e,t);for(var r=[],n=0,i=0;i<this._types.length;i++){var a=this._types[i].validate(e,t);if(0===a.length){if(this._eager)return ue();n++}else r.push(a)}return 1===n?ue():le(t,e,"No type is applicable for the union").concat(ce(r))}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._types}}),t}(x);function Vt(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];var n=F(e)?void 0:e,i=F(e)?p([e],f(t),!1):t,a="("+i.map((function(e){return e.name})).join(" | ")+")";return new Nt(a,i,n)}function Dt(e){return F(e)&&(e.flags&E.Union)>0}var xt=function(e){function t(t,r,n){var i=e.call(this,t.name)||this;return Object.defineProperty(i,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(i,"_defaultValue",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(i,"optionalValues",{enumerable:!0,configurable:!0,writable:!0,value:n}),i}return u(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return this._subtype.flags|E.Optional},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype.describe()+"?"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(this.optionalValues.indexOf(n)>=0){var i=this.getDefaultInstanceOrSnapshot();return this._subtype.instantiate(e,t,r,i)}return this._subtype.instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this._subtype.reconcile(e,this.optionalValues.indexOf(t)<0&&this._subtype.is(t)?t:this.getDefaultInstanceOrSnapshot(),r,n)}}),Object.defineProperty(t.prototype,"getDefaultInstanceOrSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e="function"==typeof this._defaultValue?this._defaultValue():this._defaultValue;return"function"==typeof this._defaultValue&&se(this,e),e}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.optionalValues.indexOf(e)>=0?ue():this._subtype.validate(e,t)}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this._subtype.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this._subtype}}),t}(x);function kt(e,t,r){return function(e,t){if("function"!=typeof t&&ve(t))throw new Ee("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead")}(0,t),new xt(e,t,r||Rt)}var Rt=[void 0];var zt=kt(_t,void 0),Ft=kt(jt,null);function Mt(e){return Vt(e,zt)}var Lt=function(e){function t(t,r){var n=e.call(this,t)||this;return Object.defineProperty(n,"_definition",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),n}return u(t,e),Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|E.Late},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"getSubType",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(!this._subType){var t=void 0;try{t=this._definition()}catch(e){if(!(e instanceof ReferenceError))throw e;t=void 0}if(e&&void 0===t)throw new Ee("Late type seems to be used too early, the definition (still) returns undefined");t&&(this._subType=t)}return this._subType}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this.getSubType(!0).instantiate(e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return this.getSubType(!0).reconcile(e,t,r,n)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.getSubType(!1);return e?e.name:"<uknown late type>"}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var r=this.getSubType(!1);return r?r.validate(e,t):ue()}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this.getSubType(!1);return!!t&&t.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"getSubTypes",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.getSubType(!1);return e||"cannotDetermine"}}),t}(x);var Ht=function(e){function r(r,n){var i=e.call(this,r)||this;return Object.defineProperty(i,"options",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(i,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Lazy}),Object.defineProperty(i,"loadedType",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(i,"pendingNodeList",{enumerable:!0,configurable:!0,writable:!0,value:t.observable.array()}),t.when((function(){return i.pendingNodeList.length>0&&i.pendingNodeList.some((function(e){return e.isAlive&&i.options.shouldLoadPredicate(e.parent?e.parent.value:null)}))}),(function(){i.options.loadType().then(t.action((function(e){i.loadedType=e,i.pendingNodeList.forEach((function(e){e.parent&&i.loadedType&&e.parent.applyPatches([{op:"replace",path:"/".concat(e.subpath),value:e.snapshot}])}))})))})),i}return u(r,e),Object.defineProperty(r.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"<lazy ".concat(this.name,">")}}),Object.defineProperty(r.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,r,n,i){var a=this;if(this.loadedType)return this.loadedType.instantiate(e,r,n,i);var o=ye(this,e,r,n,i);return this.pendingNodeList.push(o),t.when((function(){return!o.isAlive}),(function(){return a.pendingNodeList.splice(a.pendingNodeList.indexOf(o),1)})),o}}),Object.defineProperty(r.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return this.loadedType?this.loadedType.validate(e,t):Fe(e)?ue():le(t,e,"Value is not serializable and cannot be lazy")}}),Object.defineProperty(r.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(t,r,n,i){return this.loadedType?(t.die(),this.loadedType.instantiate(n,i,n.environment,r)):e.prototype.reconcile.call(this,t,r,n,i)}}),r}(R),Ut=function(e){function t(t){var r=e.call(this,t?"frozen(".concat(t.name,")"):"frozen")||this;return Object.defineProperty(r,"subType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Frozen}),r}return u(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"<any immutable value>"}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return ye(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return Fe(e)?this.subType?this.subType.validate(e,t):ue():le(t,e,"Value is not serializable and cannot be frozen")}}),t}(R),$t=new Ut;var Bt=function(){function e(e,t){if(Object.defineProperty(this,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"node",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"resolvedReference",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),nr(e))this.identifier=e;else{if(!ve(e))throw new Ee("Can only store references to tree nodes or identifiers, got: '".concat(e,"'"));var r=ge(e);if(!r.identifierAttribute)throw new Ee("Can only store references with a defined identifier attribute.");var n=r.unnormalizedIdentifier;if(null==n)throw new Ee("Can only store references to tree nodes with a defined identifier.");this.identifier=n}}return Object.defineProperty(e.prototype,"updateResolvedReference",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=rr(this.identifier),r=e.root,n=r.identifierCache.getLastCacheModificationPerId(t);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==n){var i=this.targetType,a=r.identifierCache.resolve(i,t);if(!a)throw new Gt("[mobx-state-tree] Failed to resolve reference '".concat(this.identifier,"' to type '").concat(this.targetType.name,"' (from node: ").concat(e.path,")"));this.resolvedReference={node:a,lastCacheModification:n}}}}),Object.defineProperty(e.prototype,"resolvedValue",{get:function(){return this.updateResolvedReference(this.node),this.resolvedReference.node.value},enumerable:!1,configurable:!0}),e}(),Gt=function(e){function t(r){var n=e.call(this,r)||this;return Object.setPrototypeOf(n,t.prototype),n}return u(t,e),t}(Error),Wt=function(e){function t(t,r){var n=e.call(this,"reference(".concat(t.name,")"))||this;return Object.defineProperty(n,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(n,"onInvalidated",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Reference}),n}return u(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"isAssignableFrom",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.targetType.isAssignableFrom(e)}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return nr(e)?ue():le(t,e,"Value is not a valid identifier, which is a string, number or a bigint")}}),Object.defineProperty(t.prototype,"fireInvalidated",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=t.parent;if(i&&i.isAlive){var a=i.storedValue;a&&this.onInvalidated({cause:e,parent:a,invalidTarget:n?n.storedValue:void 0,invalidId:r,replaceRef:function(e){h(t.root.storedValue,{op:"replace",value:e,path:t.path})},removeRef:function(){bt(i.type)?this.replaceRef(void 0):h(t.root.storedValue,{op:"remove",path:t.path})}})}}}),Object.defineProperty(t.prototype,"addTargetNodeWatcher",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var n=this,i=this.getValue(e);if(i){var a=ge(i),o=function(i,o){var u=function(e){switch(e){case r.beforeDestroy:return"destroy";case r.beforeDetach:return"detach";default:return}}(o);u&&n.fireInvalidated(u,e,t,a)},u=a.registerHook(r.beforeDetach,o),l=a.registerHook(r.beforeDestroy,o);return function(){u(),l()}}}}),Object.defineProperty(t.prototype,"watchTargetNodeForInvalidations",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,n){var i=this;if(this.onInvalidated){var a;e.registerHook(r.beforeDestroy,(function(){a&&a()}));var o=function(r){a&&a();var u,l=e.parent,c=l&&l.storedValue;if(l&&l.isAlive&&c){(n?!!n.get(t,c):e.root.identifierCache.has(i.targetType,rr(t)))?a=i.addTargetNodeWatcher(e,t):r?(u=function(){e.isAlive&&i.getSnapshot(e)===t&&o(!1)},W()?e.root.enqueueEndOfAction(u):Ge(u)):i.fireInvalidated("invalidSnapshotReference",e,t,null)}};e.state===pe.FINALIZED?o(!0):(e.isRoot||e.root.registerHook(r.afterCreationFinalization,(function(){e.parent&&e.parent.createObservableInstanceIfNeeded()})),e.registerHook(r.afterAttach,(function(){o(!1)})))}}}),t}(R),Zt=function(e){function t(t,r){return e.call(this,t,r)||this}return u(t,e),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return e.storedValue.resolvedValue}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue.identifier}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=ve(n)?w(n):n,a=new Bt(n,this.targetType),o=ye(this,e,t,r,a);return a.node=o,this.watchTargetNodeForInvalidations(o,i,void 0),o}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!e.isDetaching&&e.type===this){var i=ve(t),a=e.storedValue;if(!i&&a.identifier===t||i&&a.resolvedValue===t)return e.setParent(r,n),e}var o=this.instantiate(r,n,void 0,t);return e.die(),o}}),t}(Wt),Yt=function(e){function t(t,r,n){var i=e.call(this,t,n)||this;return Object.defineProperty(i,"options",{enumerable:!0,configurable:!0,writable:!0,value:r}),i}return u(t,e),Object.defineProperty(t.prototype,"getValue",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(e.isAlive)return this.options.get(e.storedValue,e.parent?e.parent.storedValue:null)}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=ve(n)?this.options.set(n,e?e.storedValue:null):n,a=ye(this,e,t,r,i);return this.watchTargetNodeForInvalidations(a,i,this.options),a}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=ve(t)?this.options.set(t,e?e.storedValue:null):t;if(!e.isDetaching&&e.type===this&&e.storedValue===i)return e.setParent(r,n),e;var a=this.instantiate(r,n,void 0,i);return e.die(),a}}),t}(Wt);function Jt(e,t){var r=t||void 0,n=t?t.onInvalidated:void 0;return r&&(r.get||r.set)?new Yt(e,{get:r.get,set:r.set},n):new Zt(e,n)}var qt=function(e){function t(t,r){var n=e.call(this,t)||this;return Object.defineProperty(n,"validType",{enumerable:!0,configurable:!0,writable:!0,value:r}),Object.defineProperty(n,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Identifier}),n}return u(t,e),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!(e&&e.type instanceof pt))throw new Ee("Identifier types can only be instantiated as direct child of a model type");return ye(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(e.storedValue!==t)throw new Ee("Tried to change identifier from '".concat(e.storedValue,"' to '").concat(t,"'. Changing identifiers is not allowed."));return e.setParent(r,n),e}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){return typeof e!==this.validType?le(t,e,"Value is not a valid ".concat(this.describe(),", expected a ").concat(this.validType)):ue()}}),t}(R),Kt=function(e){function t(){var t=e.call(this,"identifier","string")||this;return Object.defineProperty(t,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Identifier}),t}return u(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifier"}}),t}(qt),Qt=function(e){function t(){return e.call(this,"identifierNumber","number")||this}return u(t,e),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return e.storedValue}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifierNumber"}}),t}(qt),Xt=new Kt,er=new Qt,tr=new(function(e){function t(){var t=e.call(this,"identifierBigint")||this;return Object.defineProperty(t,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Identifier}),t}return u(t,e),Object.defineProperty(t.prototype,"createNewInstance",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return"bigint"==typeof e?e:BigInt(e)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){if(!(e&&e.type instanceof pt))throw new Ee("Identifier types can only be instantiated as direct child of a model type");return ye(this,e,t,r,n)}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=e.storedValue,a="bigint"==typeof t?t:BigInt(t);if(i!==a)throw new Ee("Tried to change identifier from '".concat(i,"' to '").concat(a,"'. Changing identifiers is not allowed."));return e.setParent(r,n),e}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if("bigint"==typeof e)return ue();if("string"==typeof e||"number"==typeof e)try{return BigInt(e),ue()}catch(n){var r=n instanceof Error?n.message:String(n);return le(t,e,"Value is not a valid ".concat(this.describe(),": ").concat(r))}return le(t,e,"Value is not a valid ".concat(this.describe(),", expected a bigint, a string or a number"))}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return String(e.storedValue)}}),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return"identifierBigint"}}),t}(R));function rr(e){return""+e}function nr(e){return"string"==typeof e||"number"==typeof e||"bigint"==typeof e}var ir=function(e){function t(t){var r=e.call(this,t.name)||this;return Object.defineProperty(r,"options",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(r,"flags",{enumerable:!0,configurable:!0,writable:!0,value:E.Custom}),r}return u(t,e),Object.defineProperty(t.prototype,"describe",{enumerable:!1,configurable:!0,writable:!0,value:function(){return this.name}}),Object.defineProperty(t.prototype,"isValidSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){if(this.options.isTargetType(e))return ue();var r=this.options.getValidationMessage(e);return r?le(t,e,"Invalid value for type '".concat(this.name,"': ").concat(r)):ue()}}),Object.defineProperty(t.prototype,"getSnapshot",{enumerable:!1,configurable:!0,writable:!0,value:function(e){return this.options.toSnapshot(e.storedValue)}}),Object.defineProperty(t.prototype,"instantiate",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){return ye(this,e,t,r,this.options.isTargetType(n)?n:this.options.fromSnapshot(n,e&&e.root.environment))}}),Object.defineProperty(t.prototype,"reconcile",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t,r,n){var i=!this.options.isTargetType(t);if(!e.isDetaching&&(e.type===this&&(i?t===e.snapshot:t===e.storedValue)))return e.setParent(r,n),e;var a=i?this.options.fromSnapshot(t,r.root.environment):t,o=this.instantiate(r,n,void 0,a);return e.die(),o}}),t}(R),ar={enumeration:function(e,t){var r="string"==typeof e?t:e,n=Vt.apply(void 0,p([],f(r.map((function(e){return Ct(""+e)}))),!1));return"string"==typeof e&&(n.name=e),n},model:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r="string"==typeof e[0]?e.shift():"AnonymousModel",n=e.shift()||{};return new pt({name:r,properties:n})},compose:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r="string"==typeof e[0],n=r?e[0]:"AnonymousModel";return r&&e.shift(),e.reduce((function(e,t){return e.cloneAndEnhance({name:e.name+"_"+t.name,properties:t.properties,initializers:t.initializers,preProcessor:function(r){return t.applySnapshotPreProcessor(e.applySnapshotPreProcessor(r))},postProcessor:function(r){return t.applySnapshotPostProcessor(e.applySnapshotPostProcessor(r))}})})).named(n)},custom:function(e){return new ir(e)},reference:Jt,safeReference:function(e,t){var r=Jt(e,l(l({},t),{onInvalidated:function(e){t&&t.onInvalidated&&t.onInvalidated(e),e.removeRef()}}));return t&&!1===t.acceptsUndefined?r:Mt(r)},union:Vt,optional:kt,literal:Ct,maybe:Mt,maybeNull:function(e){return Vt(e,Ft)},refinement:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r="string"==typeof e[0]?e.shift():F(e[0])?e[0].name:null,n=e[0],i=e[1],a=e[2]?e[2]:function(e){return"Value does not respect the refinement predicate"};return new Et(r,n,i,a)},string:ht,boolean:Ot,number:yt,integer:vt,float:gt,finite:mt,bigint:Pt,Date:At,map:function(e){return new it("Map<string, ".concat(e.name,">"),e)},array:function(e){return new at("".concat(e.name,"[]"),e)},frozen:function(e){return 0===arguments.length?$t:F(e)?new Ut(e):kt($t,e)},identifier:Xt,identifierNumber:er,identifierBigint:tr,late:function(e,t){var r="string"==typeof e?e:"late(".concat(e.toString(),")");return new Lt(r,"string"==typeof e?t:e)},lazy:function(e,t){return new Ht(e,t)},undefined:_t,null:jt,snapshotProcessor:function(e,t,r){return new et(e,t,r)}};e.addDisposer=function(e,t){return ge(e).addDisposer(t),t},e.addMiddleware=K,e.applyAction=U,e.applyPatch=h,e.applySnapshot=y,e.cast=function(e){return e},e.castFlowReturn=function(e){return e},e.castToReferenceSnapshot=function(e){return e},e.castToSnapshot=function(e){return e},e.clone=function(e,t){void 0===t&&(t=!0);var r=ge(e);return r.type.create(r.snapshot,!0===t?r.root.environment:!1===t?void 0:t)},e.createActionTrackingMiddleware=function(e){return function(t,r,n){switch(t.type){case"action":if(e.filter&&!0!==e.filter(t))return r(t);var i=e.onStart(t);e.onResume(t,i),M.set(t.id,{call:t,context:i,async:!1});try{var a=r(t);return e.onSuspend(t,i),!1===M.get(t.id).async&&(M.delete(t.id),e.onSuccess(t,i,a)),a}catch(r){throw M.delete(t.id),e.onFail(t,i,r),r}case"flow_spawn":return(o=M.get(t.rootId)).async=!0,r(t);case"flow_resume":case"flow_resume_error":var o=M.get(t.rootId);e.onResume(t,o.context);try{return r(t)}finally{e.onSuspend(t,o.context)}case"flow_throw":o=M.get(t.rootId);return M.delete(t.rootId),e.onFail(t,o.context,t.args[0]),r(t);case"flow_return":o=M.get(t.rootId);return M.delete(t.rootId),e.onSuccess(t,o.context,t.args[0]),r(t)}}},e.createActionTrackingMiddleware2=function(e){var t=new Map;return function(r,n){var i=r.parentActionEvent?t.get(r.parentActionEvent.id):void 0;if("action"===r.type){var a=l(l({},r),{env:i&&i.call.env,parentCall:i&&i.call}),o=!e.filter||e.filter(a),u=new L(o?e:void 0,a);t.set(r.id,u);var c=void 0;try{c=n(r)}catch(e){throw t.delete(r.id),u.finish(e),e}return u.hasFlowsPending||(t.delete(r.id),u.finish()),c}if(!i)return n(r);switch(r.type){case"flow_spawn":return i.incFlowsPending(),n(r);case"flow_resume":case"flow_resume_error":return n(r);case"flow_throw":var s=r.args[0];try{return n(r)}finally{i.decFlowsPending(),i.hasFlowsPending||(t.delete(r.parentActionEvent.id),i.finish(s))}case"flow_return":try{return n(r)}finally{i.decFlowsPending(),i.hasFlowsPending||(t.delete(r.parentActionEvent.id),i.finish())}}}},e.decorate=function(e,t,r){void 0===r&&(r=!0);var n={handler:e,includeHooks:r};return t.$mst_middleware=t.$mst_middleware||[],t.$mst_middleware.push(n),t},e.destroy=function(e){var t=ge(e);t.isRoot?t.die():t.parent.removeChild(t.subpath)},e.detach=function(e){return ge(e).detach(),e},e.escapeJsonPath=Je,e.flow=We,e.getChildType=function(e,t){return ge(e).getChildType(t)},e.getEnv=function(e){var t=ge(e),r=t.root.environment;if(!r)throw new Ee("Failed to find the environment of ".concat(t," ").concat(t.path));return r},e.getErrorFormatting=re,e.getIdentifier=w,e.getLivelinessChecking=a,e.getMembers=function(e){var r=ge(e).type,n=l(l({},j(r)),{actions:[],volatile:[],views:[],flowActions:[]});return Object.getOwnPropertyNames(e).forEach((function(r){if(!(r in n.properties)){var i=Object.getOwnPropertyDescriptor(e,r);i.get?t.isComputedProp(e,r)?n.views.push(r):n.volatile.push(r):(!0===i.value._isFlowAction&&n.flowActions.push(r),!0===i.value._isMSTAction?n.actions.push(r):t.isObservableProp(e,r)?n.volatile.push(r):n.views.push(r))}})),n},e.getNodeId=function(e){return ge(e).nodeId},e.getParent=function(e,t){void 0===t&&(t=1);for(var r=t,n=ge(e).parent;n;){if(0==--r)return n.storedValue;n=n.parent}throw new Ee("Failed to find the parent of ".concat(ge(e)," at depth ").concat(t))},e.getParentOfType=function(e,t){for(var r=ge(e).parent;r;){if(t.is(r.storedValue))return r.storedValue;r=r.parent}throw new Ee("Failed to find the parent of ".concat(ge(e)," of a given type"))},e.getPath=m,e.getPathParts=function(e){return Qe(ge(e).path)},e.getPropertyMembers=j,e.getRelativePath=function(e,t){return Oe(ge(e),ge(t))},e.getRoot=g,e.getRunningActionContext=X,e.getSnapshot=v,e.getType=b,e.hasEnv=function(e){return!!ge(e).root.environment},e.hasParent=function(e,t){void 0===t&&(t=1);for(var r=ge(e).parent;r;){if(0==--t)return!0;r=r.parent}return!1},e.hasParentOfType=function(e,t){for(var r=ge(e).parent;r;){if(t.is(r.storedValue))return!0;r=r.parent}return!1},e.isActionContextChildOf=function(e,t){return ee(e,t,!1)},e.isActionContextThisOrChildOf=function(e,t){return ee(e,t,!0)},e.isAlive=O,e.isArrayType=function(e){return F(e)&&(e.flags&E.Array)>0},e.isFrozenType=function(e){return F(e)&&(e.flags&E.Frozen)>0},e.isIdentifierType=function(e){return F(e)&&(e.flags&E.Identifier)>0},e.isLateType=function(e){return F(e)&&(e.flags&E.Late)>0},e.isLiteralType=function(e){return F(e)&&(e.flags&E.Literal)>0},e.isMapType=function(e){return F(e)&&(e.flags&E.Map)>0},e.isModelType=bt,e.isOptionalType=function(e){return F(e)&&(e.flags&E.Optional)>0},e.isPrimitiveType=It,e.isProtected=function(e){return ge(e).isProtected},e.isReferenceType=function(e){return F(e)&&(e.flags&E.Reference)>0},e.isRefinementType=function(e){return F(e)&&(e.flags&E.Refinement)>0},e.isRoot=function(e){return ge(e).isRoot},e.isStateTreeNode=ve,e.isType=F,e.isUnionType=Dt,e.isValidReference=function(e,t){void 0===t&&(t=!0);try{var r=e();if(null==r)return!1;if(ve(r))return!t||O(r);throw new Ee("The reference to be checked is not one of node, null or undefined")}catch(e){if(e instanceof Gt)return!1;throw e}},e.joinJsonPath=Ke,e.onAction=$,e.onPatch=d,e.onSnapshot=function(e,t){return ge(e).onSnapshot(t)},e.process=function(e){return Be(),We(e)},e.protect=function(e){var t=ge(e);if(!t.isRoot)throw new Ee("`protect` can only be invoked on root nodes");t.isProtectionEnabled=!0},e.recordActions=function(e,t){var r,n=[],i=function(e){(!t||t(e,X()))&&n.push(e)},a={actions:n,get recording(){return!!r},stop:function(){r&&(r(),r=void 0)},resume:function(){r||(r=$(e,i))},replay:function(e){U(e,n)}};return a.resume(),a},e.recordPatches=function(e,t){var r,n={patches:[],inversePatches:[]},i={},a={get recording(){return!!r},get patches(){return i.patches||(i.patches=n.patches.slice()),i.patches},get reversedInversePatches(){return i.reversedInversePatches||(i.reversedInversePatches=n.inversePatches.slice().reverse()),i.reversedInversePatches},get inversePatches(){return i.inversePatches||(i.inversePatches=n.inversePatches.slice()),i.inversePatches},stop:function(){r&&(r(),r=void 0)},resume:function(){r||(r=d(e,(function(e,r){t&&!t(e,r,X())||(n.patches.push(e),n.inversePatches.push(r),i.patches=void 0,i.inversePatches=void 0,i.reversedInversePatches=void 0)})))},replay:function(t){h(t||e,n.patches)},undo:function(t){h(t||e,n.inversePatches.slice().reverse())}};return a.resume(),a},e.resolveIdentifier=function(e,t,r){var n=ge(t).root.identifierCache.resolve(e,rr(r));return null==n?void 0:n.value},e.resolvePath=function(e,t){var r=je(ge(e),t);return r?r.value:void 0},e.setErrorFormatting=function(e){te=l(l({},te),e)},e.setLivelinessChecking=i,e.setLivelynessChecking=function(e){i(e)},e.splitJsonPath=Qe,e.t=ar,e.toGenerator=function(e){return c(this,(function(t){switch(t.label){case 0:return[4,e];case 1:return[2,t.sent()]}}))},e.toGeneratorFunction=function(e){return function(){var t,r=[];for(t=0;t<arguments.length;t++)r[t]=arguments[t];return c(this,(function(t){switch(t.label){case 0:return[4,e.apply(void 0,p([],f(r),!1))];case 1:return[2,t.sent()]}}))}},e.tryReference=function(e,t){void 0===t&&(t=!0);try{var r=e();if(null==r)return;if(ve(r))return t?O(r)?r:void 0:r;throw new Ee("The reference to be checked is not one of node, null or undefined")}catch(e){if(e instanceof Gt)return;throw e}},e.tryResolve=P,e.typecheck=fe,e.types=ar,e.unescapeJsonPath=qe,e.unprotect=function(e){var t=ge(e);if(!t.isRoot)throw new Ee("`unprotect` can only be invoked on root nodes");t.isProtectionEnabled=!1},e.walk=function e(t,r){var n=ge(t);n.getChildren().forEach((function(t){ve(t.storedValue)&&e(t.storedValue,r)})),r(n.storedValue)},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).mobxStateTree={},e.mobx)}(this,(function(e,t){"use strict";let n="warn";function i(e){n=e}function r(){return n}var s;function a(e){return he(e).type}function o(e,t){return he(e).onPatch(t)}function l(e,t){he(e).applyPatches(je(t))}function c(e,t){return he(e).applySnapshot(t)}function u(e,t=!0){const n=he(e);return t?n.snapshot:n.type.getSnapshot(n,!1)}function h(e){return he(e).root.storedValue}function p(e){return he(e).path}function d(e){return he(e).identifier}function f(e,t){const n=ye(he(e),t,!1);if(void 0!==n)try{return n.value}catch(e){return}}function b(e){return he(e).observableIsAlive}function y(e){let t;return t=ue(e)?a(e):e,{name:t.name,properties:Object.assign({},t.properties)}}!function(e){e.afterCreate="afterCreate",e.afterAttach="afterAttach",e.afterCreationFinalization="afterCreationFinalization",e.beforeDetach="beforeDetach",e.beforeDestroy="beforeDestroy"}(s||(s={}));class g{get subpath(){return this._subpath}get subpathUponDeath(){return this._subpathUponDeath}get pathUponDeath(){return this._pathUponDeath}get value(){return this.type.getValue(this)}get state(){return this._state}set state(e){const t=this.isAlive;this._state=e;const n=this.isAlive;this.aliveAtom&&t!==n&&this.aliveAtom.reportChanged()}fireInternalHook(e){this._hookSubscribers&&this._hookSubscribers.emit(e,this,e)}registerHook(e,t){return this._hookSubscribers||(this._hookSubscribers=new xe),this._hookSubscribers.register(e,t)}get parent(){return this._parent}constructor(e,t,n,i){Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"environment",{enumerable:!0,configurable:!0,writable:!0,value:i}),Object.defineProperty(this,"_escapedSubpath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subpath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_subpathUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_pathUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"storedValue",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"aliveAtom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_state",{enumerable:!0,configurable:!0,writable:!0,value:ce.INITIALIZING}),Object.defineProperty(this,"_hookSubscribers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pathAtom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.environment=i,this.baseSetParent(t,n)}getReconciliationType(){return this.type}baseSetParent(e,t){this._parent=e,this._subpath=t,this._escapedSubpath=void 0,this.pathAtom&&this.pathAtom.reportChanged()}get path(){return this.getEscapedPath(!0)}getEscapedPath(e){return e&&(this.pathAtom||(this.pathAtom=t.createAtom("path")),this.pathAtom.reportObserved()),this.parent?(void 0===this._escapedSubpath&&(this._escapedSubpath=this._subpath?He(this._subpath):""),this.parent.getEscapedPath(e)+"/"+this._escapedSubpath):""}get isRoot(){return null===this.parent}get isAlive(){return this.state!==ce.DEAD}get isDetaching(){return this.state===ce.DETACHING}get observableIsAlive(){return this.aliveAtom||(this.aliveAtom=t.createAtom("alive")),this.aliveAtom.reportObserved(),this.isAlive}baseFinalizeCreation(e){if(this.state===ce.CREATED){if(this.parent){if(this.parent.state!==ce.FINALIZED)return;this.fireHook(s.afterAttach)}this.state=ce.FINALIZED,e&&e()}}baseFinalizeDeath(){this._hookSubscribers&&this._hookSubscribers.clearAll(),this._subpathUponDeath=this._subpath,this._pathUponDeath=this.getEscapedPath(!1),this.baseSetParent(null,""),this.state=ce.DEAD}baseAboutToDie(){this.fireHook(s.beforeDestroy)}}class v extends g{constructor(e,t,n,i,r){super(e,t,n,i);try{this.storedValue=e.createNewInstance(r)}catch(e){throw this.state=ce.DEAD,e}this.state=ce.CREATED,this.finalizeCreation()}get root(){if(!this.parent)throw new Se("This scalar node is not part of a tree");return this.parent.root}setParent(e,t){const n=this.parent!==e,i=this.subpath!==t;(n||i)&&(this.environment=void 0,this.baseSetParent(this.parent,t))}get snapshot(){return this.getSnapshot()}getSnapshot(){return this.type.getSnapshot(this)}toString(){const e=(this.isAlive?this.path:this.pathUponDeath)||"<root>";return`${this.type.name}@${e}${this.isAlive?"":" [dead]"}`}die(){this.isAlive&&this.state!==ce.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}finalizeCreation(){this.baseFinalizeCreation()}aboutToDie(){this.baseAboutToDie()}finalizeDeath(){this.baseFinalizeDeath()}fireHook(e){this.fireInternalHook(e)}}v.prototype.die=t.action(v.prototype.die);let m=1;var w,P;!function(e){e[e.UNINITIALIZED=0]="UNINITIALIZED",e[e.CREATING=1]="CREATING",e[e.CREATED=2]="CREATED"}(w||(w={})),function(e){e.Dispose="dispose",e.Patch="patch",e.Snapshot="snapshot"}(P||(P={}));const _={onError(e){throw e}};class S extends g{applyPatches(e){this.createObservableInstanceIfNeeded(),this._applyPatches(e)}applySnapshot(e){this.createObservableInstanceIfNeeded(),this._applySnapshot(e)}constructor(e,n,i,r,s){if(super(e,n,i,r),Object.defineProperty(this,"nodeId",{enumerable:!0,configurable:!0,writable:!0,value:++m}),Object.defineProperty(this,"identifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"unnormalizedIdentifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"identifierCache",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isProtectionEnabled",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"middlewares",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"hasSnapshotPostProcessor",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_applyPatches",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_applySnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_autoUnbox",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"_isRunningAction",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_hasSnapshotReaction",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_endOfActionCallbacks",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_observableInstanceState",{enumerable:!0,configurable:!0,writable:!0,value:w.UNINITIALIZED}),Object.defineProperty(this,"_childNodes",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_initialSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_cachedInitialSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_cachedInitialSnapshotCreated",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"_snapshotComputed",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_snapshotUponDeath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_internalEvents",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this._snapshotComputed=t.computed(()=>this.getSnapshot()),this.unbox=this.unbox.bind(this),this._initialSnapshot=s,this.identifierAttribute=e.identifierAttribute,n||(this.identifierCache=new ae),this._childNodes=e.initializeChildNodes(this,this._initialSnapshot),this.identifier=null,this.unnormalizedIdentifier=null,this.identifierAttribute&&this._initialSnapshot){let e=this._initialSnapshot[this.identifierAttribute];if(void 0===e){const t=this._childNodes[this.identifierAttribute];t&&(e=t.value)}if("string"!=typeof e&&"number"!=typeof e&&"bigint"!=typeof e)throw new Se(`Instance identifier '${this.identifierAttribute}' for type '${this.type.name}' must be a string, a number or a bigint`);this.identifier=Zt(e),this.unnormalizedIdentifier=e}n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this)}createObservableInstanceIfNeeded(e=!0){this._observableInstanceState===w.UNINITIALIZED&&this.createObservableInstance(e)}createObservableInstance(e=!0){this._observableInstanceState=w.CREATING;const t=[];let n=this.parent;for(;n&&n._observableInstanceState===w.UNINITIALIZED;)t.unshift(n),n=n.parent;for(const e of t)e.createObservableInstanceIfNeeded(!1);const i=this.type;try{this.storedValue=i.createNewInstance(this._childNodes),this.preboot(),this._isRunningAction=!0,i.finalizeNewInstance(this,this.storedValue)}catch(e){throw this.state=ce.DEAD,e}finally{this._isRunningAction=!1}if(this._observableInstanceState=w.CREATED,this._snapshotComputed.trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this._childNodes=Pe,this.state=ce.CREATED,e){this.fireHook(s.afterCreate),this.finalizeCreation();for(const e of t.reverse())e.fireHook(s.afterCreate),e.finalizeCreation()}}get root(){const e=this.parent;return e?e.root:this}enqueueEndOfAction(e){const t=this.root;t._endOfActionCallbacks||(t._endOfActionCallbacks=[]),t._endOfActionCallbacks.push(e)}flushEndOfActionCallbacks(){const e=this.root;for(;e._endOfActionCallbacks&&e._endOfActionCallbacks.length>0;){const t=e._endOfActionCallbacks;e._endOfActionCallbacks=void 0,t.forEach(e=>{e()})}}clearParent(){if(!this.parent)return;this.fireHook(s.beforeDetach);const e=this.state;this.state=ce.DETACHING;const t=this.root,n=t.environment,i=t.identifierCache.splitCache(this);try{this.parent.removeChild(this.subpath),this.baseSetParent(null,""),this.environment=n,this.identifierCache=i}finally{this.state=e}}setParent(e,t){const n=e!==this.parent,i=t!==this.subpath;(n||i)&&(n?(this.environment=void 0,e.root.identifierCache.mergeCache(this),this.baseSetParent(e,t),this.fireHook(s.afterAttach)):i&&this.baseSetParent(this.parent,t))}fireHook(e){this.fireInternalHook(e);const n=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[e];"function"==typeof n&&(t._allowStateChangesInsideComputed?t._allowStateChangesInsideComputed(()=>{n.apply(this.storedValue)}):n.apply(this.storedValue))}get snapshot(){return this.hasSnapshotPostProcessor&&this.createObservableInstanceIfNeeded(),this._snapshotComputed.get()}getSnapshot(){return this.isAlive?this._observableInstanceState===w.CREATED?this._getActualSnapshot():this._getCachedInitialSnapshot():this._snapshotUponDeath}_getActualSnapshot(){return this.type.getSnapshot(this)}_getCachedInitialSnapshot(){if(!this._cachedInitialSnapshotCreated){const e=this.type,t=this._childNodes,n=this._initialSnapshot;this._cachedInitialSnapshot=e.processInitialSnapshot(t,n),this._cachedInitialSnapshotCreated=!0}return this._cachedInitialSnapshot}isRunningAction(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()}assertAlive(e){const t=r();if(!this.isAlive&&"ignore"!==t){const i=this._getAssertAliveError(e);switch(t){case"error":throw new Se(i);case"warn":n=i,console.warn(new Error("[mobx-state-tree] "+n))}}var n}_getAssertAliveError(e){const t=this.getEscapedPath(!1)||this.pathUponDeath||"",n=e.subpath&&He(e.subpath)||"";let i=e.actionContext||F();i&&"action"!==i.type&&i.parentActionEvent&&(i=i.parentActionEvent);let r="";if(i&&null!=i.name){r=`${i&&i.context&&p(i.context)||t}.${i.name}()`}return`You are trying to read or write to an object that is no longer part of a state tree. (Object type: '${this.type.name}', Path upon death: '${t}', Subpath: '${n}', Action: '${r}'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.`}getChildNode(e){this.assertAlive({subpath:e}),this._autoUnbox=!1;try{return this._observableInstanceState===w.CREATED?this.type.getChildNode(this,e):this._childNodes[e]}finally{this._autoUnbox=!0}}getChildren(){this.assertAlive(Pe),this._autoUnbox=!1;try{return this._observableInstanceState===w.CREATED?this.type.getChildren(this):ve(this._childNodes)}finally{this._autoUnbox=!0}}getChildType(e){return this.type.getChildType(e)}get isProtected(){return this.root.isProtectionEnabled}assertWritable(e){if(this.assertAlive(e),!this.isRunningAction()&&this.isProtected)throw new Se(`Cannot modify '${this}', the object is protected and can only be modified by using an action.`)}removeChild(e){this.type.removeChild(this,e)}unbox(e){return e?(this.assertAlive({subpath:e.subpath||e.subpathUponDeath}),this._autoUnbox?e.value:e):e}toString(){const e=(this.isAlive?this.path:this.pathUponDeath)||"<root>",t=this.identifier?`(id: ${this.identifier})`:"";return`${this.type.name}@${e}${t}${this.isAlive?"":" [dead]"}`}finalizeCreation(){this.baseFinalizeCreation(()=>{for(let e of this.getChildren())e.finalizeCreation();this.fireInternalHook(s.afterCreationFinalization)})}detach(){if(!this.isAlive)throw new Se("Error while detaching, node is not alive.");this.clearParent()}preboot(){const e=this;this._applyPatches=U(this.storedValue,"@APPLY_PATCHES",t=>{t.forEach(t=>{if(!t.path)return void e.type.applySnapshot(e,t.value);const n=We(t.path);ge(e,n.slice(0,-1)).applyPatchLocally(n[n.length-1],t)})}),this._applySnapshot=U(this.storedValue,"@APPLY_SNAPSHOT",t=>{if(t!==e.snapshot)return e.type.applySnapshot(e,t)}),Ve(this.storedValue,"$treenode",this),Ve(this.storedValue,"toJSON",de)}die(){this.isAlive&&this.state!==ce.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}aboutToDie(){this._observableInstanceState!==w.UNINITIALIZED&&(this.getChildren().forEach(e=>{e.aboutToDie()}),this.baseAboutToDie(),this._internalEventsEmit(P.Dispose),this._internalEventsClear(P.Dispose))}finalizeDeath(){this.getChildren().forEach(e=>{e.finalizeDeath()}),this.root.identifierCache.notifyDied(this);const e=this.snapshot;this._snapshotUponDeath=e,this._internalEventsClearAll(),this.baseFinalizeDeath()}onSnapshot(e){return this._addSnapshotReaction(),this._internalEventsRegister(P.Snapshot,e)}emitSnapshot(e){this._internalEventsEmit(P.Snapshot,e)}onPatch(e){return this._internalEventsRegister(P.Patch,e)}hasPatchSubscribers(){return!!this._internalEventsHasSubscribers(P.Patch)||!!this.parent&&this.parent.hasPatchSubscribers()}emitPatch(e,t){if(this._internalEventsHasSubscribers(P.Patch)){const n=function(e,...t){for(let n=0;n<t.length;n++){const i=t[n];for(let t in i)e[t]=i[t]}return e}({},e,{path:t.path.substr(this.path.length)+(e.path?"/"+e.path:"")}),[i,r]=function(e){if(!("oldValue"in e))throw new Se("Patches without `oldValue` field cannot be inversed");return[Me(e),Le(e)]}(n);this._internalEventsEmit(P.Patch,i,r)}this.parent&&this.parent.emitPatch(e,t)}hasDisposer(e){return this._internalEventsHas(P.Dispose,e)}addDisposer(e){if(this.hasDisposer(e))throw new Se("cannot add a disposer when it is already registered for execution");this._internalEventsRegister(P.Dispose,e,!0)}removeDisposer(e){if(!this._internalEventsHas(P.Dispose,e))throw new Se("cannot remove a disposer which was never registered for execution");this._internalEventsUnregister(P.Dispose,e)}removeMiddleware(e){if(this.middlewares){const t=this.middlewares.indexOf(e);t>=0&&this.middlewares.splice(t,1)}}addMiddleWare(e,t=!0){const n={handler:e,includeHooks:t};return this.middlewares?this.middlewares.push(n):this.middlewares=[n],()=>{this.removeMiddleware(n)}}applyPatchLocally(e,t){this.assertWritable({subpath:e}),this.createObservableInstanceIfNeeded(),this.type.applyPatchLocally(this,e,t)}_addSnapshotReaction(){if(!this._hasSnapshotReaction){const e=t.reaction(()=>this.snapshot,e=>this.emitSnapshot(e),_);this.addDisposer(e),this._hasSnapshotReaction=!0}}_internalEventsHasSubscribers(e){return!!this._internalEvents&&this._internalEvents.hasSubscribers(e)}_internalEventsRegister(e,t,n=!1){return this._internalEvents||(this._internalEvents=new xe),this._internalEvents.register(e,t,n)}_internalEventsHas(e,t){return!!this._internalEvents&&this._internalEvents.has(e,t)}_internalEventsUnregister(e,t){this._internalEvents&&this._internalEvents.unregister(e,t)}_internalEventsEmit(e,...t){this._internalEvents&&this._internalEvents.emit(e,...t)}_internalEventsClear(e){this._internalEvents&&this._internalEvents.clear(e)}_internalEventsClearAll(){this._internalEvents&&this._internalEvents.clearAll()}}var A,O;S.prototype.createObservableInstance=t.action(S.prototype.createObservableInstance),S.prototype.detach=t.action(S.prototype.detach),S.prototype.die=t.action(S.prototype.die),function(e){e[e.String=1]="String",e[e.Number=2]="Number",e[e.Boolean=4]="Boolean",e[e.Date=8]="Date",e[e.Literal=16]="Literal",e[e.Array=32]="Array",e[e.Map=64]="Map",e[e.Object=128]="Object",e[e.Frozen=256]="Frozen",e[e.Optional=512]="Optional",e[e.Reference=1024]="Reference",e[e.Identifier=2048]="Identifier",e[e.Late=4096]="Late",e[e.Refinement=8192]="Refinement",e[e.Union=16384]="Union",e[e.Null=32768]="Null",e[e.Undefined=65536]="Undefined",e[e.Integer=131072]="Integer",e[e.Custom=262144]="Custom",e[e.SnapshotProcessor=524288]="SnapshotProcessor",e[e.Lazy=1048576]="Lazy",e[e.Finite=2097152]="Finite",e[e.Float=4194304]="Float",e[e.BigInt=8388608]="BigInt"}(O||(O={}));const I=Symbol("$type");class j{constructor(e){Object.defineProperty(this,A,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"C",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"S",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"T",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"N",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isType",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.name=e}create(e,t){return ie(this,e),this.instantiate(null,"",t,e).value}getSnapshot(e,t){throw new Se("unimplemented method")}isAssignableFrom(e){return e===this}validate(e,t){if(pe(e)){const n=a(e);return this.isAssignableFrom(n)?ee():te(t,e)}return this.isValidSnapshot(e,t)}is(e){return 0===this.validate(e,[{path:"",type:this}]).length}get Type(){throw new Se("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")}get TypeWithoutSTN(){throw new Se("Factory.TypeWithoutSTN should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.TypeWithoutSTN`")}get SnapshotType(){throw new Se("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")}get CreationType(){throw new Se("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")}}A=I,j.prototype.create=t.action(j.prototype.create);class T extends j{constructor(e){super(e),Object.defineProperty(this,"identifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}create(e=this.getDefaultSnapshot(),t){return super.create(e,t)}getValue(e){return e.createObservableInstanceIfNeeded(),e.storedValue}isMatchingSnapshotId(e,t){return!e.identifierAttribute||e.identifier===Zt(t[e.identifierAttribute])}tryToReconcileNode(e,t){return!e.isDetaching&&(e.snapshot===t||(!(!ue(t)||he(t)!==e)||!(e.type!==this||!Ce(t)||ue(t)||!this.isMatchingSnapshotId(e,t))&&(e.applySnapshot(t),!0)))}reconcile(e,t,n,i){if(this.tryToReconcileNode(e,t))return e.setParent(n,i),e;if(e.die(),ue(t)&&this.isAssignableFrom(a(t))){const e=he(t);return e.setParent(n,i),e}return this.instantiate(n,i,void 0,t)}getSubTypes(){return null}}T.prototype.create=t.action(T.prototype.create);class C extends j{createNewInstance(e){return e}getValue(e){return e.storedValue}getSnapshot(e){return e.storedValue}reconcile(e,t,n,i){if(!e.isDetaching&&e.type===this&&e.storedValue===t)return e;const r=this.instantiate(n,i,void 0,t);return e.die(),r}getSubTypes(){return null}}function E(e,t,n){const i=t.getReconciliationType(),r=function e(t){const n=t.getSubTypes();if(!n||Array.isArray(n)||"cannotDetermine"===n||!function(e){const t=O.Optional|O.Late,n=O.Refinement|O.SnapshotProcessor|O.Union;return(e.flags&t)>0&&0==(e.flags&n)}(t))return t;return e(n)}(e);return t instanceof S&&i===r&&i instanceof T&&Ce(n)&&!ue(n)&&i.isMatchingSnapshotId(t,n)}function N(e){return"object"==typeof e&&e&&!0===e.isType}const V=new Map;class D{constructor(e,t){Object.defineProperty(this,"hooks",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"call",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"flowsPending",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"running",{enumerable:!0,configurable:!0,writable:!0,value:!0}),e&&e.onStart(t)}finish(e){this.running&&(this.running=!1,this.hooks&&this.hooks.onFinish(this.call,e))}incFlowsPending(){this.flowsPending++}decFlowsPending(){this.flowsPending--}get hasFlowsPending(){return this.flowsPending>0}}function x(e){return{$MST_UNSERIALIZABLE:!0,type:e}}function $(e,n){t.runInAction(()=>{je(n).forEach(t=>function(e,t){const n=f(e,t.path||"");if(!n)throw new Se("Invalid action path: "+(t.path||""));const i=he(n);if("@APPLY_PATCHES"===t.name)return l.call(null,n,t.args[0]);if("@APPLY_SNAPSHOT"===t.name)return c.call(null,n,t.args[0]);if("function"!=typeof n[t.name])throw new Se(`Action '${t.name}' does not exist in '${i.path}'`);return n[t.name].apply(n,t.args?t.args.map(e=>{return(t=e)&&"object"==typeof t&&"$MST_DATE"in t?new Date(t.$MST_DATE):t;var t}):[])}(e,t))})}function k(e,t,n=!1){return B(e,(function(i,r){if("action"===i.type&&i.id===i.rootId){const s=he(i.context),o={name:i.name,path:be(he(e),s),args:i.args.map((e,t)=>function(e,t,n,i){if(i instanceof Date)return{$MST_DATE:i.getTime()};if(Ee(i))return i;if(ue(i))return x(`[MSTNode: ${a(i).name}]`);if("function"==typeof i)return x("[function]");if("object"==typeof i&&!Te(i)&&!Ie(i))return x(`[object ${i&&i.constructor&&i.constructor.name||"Complex Object"}]`);try{return JSON.stringify(i),i}catch(e){return x(""+e)}}(0,i.name,0,e))};if(n){const e=r(i);return t(o),e}return t(o),r(i)}return r(i)}))}let R,z=1;function F(){return R}function M(){return z++}function L(e,n){const i=he(e.context);"action"===e.type&&i.assertAlive({actionContext:e});const r=i._isRunningAction;i._isRunningAction=!0;const a=R,o=!a;R=e;try{return function(e,n,i,r){function a(n,i){const s=()=>{let t,s;try{t=i.apply(null,n.args)}catch(e){s=e}if(r||!n.parentActionEvent)try{e.root.flushEndOfActionCallbacks()}catch(e){s||(s=e)}if(s)throw s;return t};return n.name?t.action(n.name,s)():t.action(s)()}const o=new W(e,i);if(o.isEmpty)return a(n,i);let l=null;return function e(t){const n=o.getNextMiddleware(),c=n&&n.handler;if(!c)return a(t,i);if(!n.includeHooks&&s[t.name])return e(t);let u=!1;return c(t,(function(t,n){l=e(t),n&&(l=n(l))}),(function(e){u=!0,l=e})),!u||!r&&t.parentActionEvent?l:a(t,()=>l)}(n)}(i,e,n,o)}finally{R=a,i._isRunningAction=r}}function H(e){if(e)return"action"===e.type?e:e.parentActionEvent}function U(e,t,n){const i=function(){const i=M(),r=R,s=H(r);return L({type:"action",name:t,id:i,args:$e(arguments),context:e,tree:h(e),rootId:r?r.rootId:i,parentId:r?r.id:0,allParentIds:r?[...r.allParentIds,r.id]:[],parentEvent:r,parentActionEvent:s},n)};return i._isMSTAction=!0,i._isFlowAction=n._isFlowAction,i}function B(e,t,n=!0){return he(e).addMiddleWare(t,n)}class W{constructor(e,t){Object.defineProperty(this,"arrayIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"inArrayIndex",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"middlewares",{enumerable:!0,configurable:!0,writable:!0,value:[]}),t.$mst_middleware&&this.middlewares.push(t.$mst_middleware);let n=e;for(;n;)n.middlewares&&this.middlewares.push(n.middlewares),n=n.parent}get isEmpty(){return this.middlewares.length<=0}getNextMiddleware(){const e=this.middlewares[this.arrayIndex];if(!e)return;const t=e[this.inArrayIndex++];return t||(this.arrayIndex++,this.inArrayIndex=0,this.getNextMiddleware())}}function G(){let e=F();for(;e&&"action"!==e.type;)e=e.parentActionEvent;return e}function Z(e,t,n){const i="number"==typeof t?t:t.id;let r=n?e:e.parentActionEvent;for(;r;){if(r.id===i)return!0;r=r.parentActionEvent}return!1}let Y=Object.assign({},{enabled:!1,indent:2,maxStringLength:100,maxArrayLength:10,maxPropertyCount:30,maxDepth:5});function J(){return Object.assign({},Y)}function q(e,t){try{return JSON.stringify(e,null,t)}catch(e){return`<Unserializable: ${e}>`}}function K(e){if("function"==typeof e)return`<function${e.name?" "+e.name:""}>`;if(ue(e))return`<${e}>`;const t=J();if(!t.enabled)return`\`${q(e)}\``;return`\`${q(function e(t,n,i){if("string"==typeof t)return t.length>i.maxStringLength?`${t.slice(0,i.maxStringLength)}… (${t.length-i.maxStringLength} more characters)`:t;if(Array.isArray(t)){if(n>=i.maxDepth)return"[…]";const r=t.slice(0,i.maxArrayLength).map(t=>e(t,n+1,i));return t.length>i.maxArrayLength&&r.push(`… ${t.length-i.maxArrayLength} more items`),r}if(Te(t)){if(n>=i.maxDepth)return"{…}";const r={},s=Object.keys(t);return s.slice(0,i.maxPropertyCount).forEach(s=>{r[s]=e(t[s],n+1,i)}),s.length>i.maxPropertyCount&&(r["…"]=s.length-i.maxPropertyCount+" more keys"),r}return t}(e,0,t),t.indent||void 0)}\``}function Q(e){const{value:t}=e,n=e.context[e.context.length-1].type,i=e.context.map(({path:e})=>e).filter(e=>e.length>0).join("/"),r=i.length>0?`at path "/${i}" `:"",s=ue(t)?`value of type ${he(t).type.name}:`:Ee(t)?"value":"snapshot",a=n&&ue(t)&&n.is(he(t).snapshot),o=J();return`${r}${s} ${K(t)} is not assignable ${n?`to type: \`${n.name}\``:""}`+(e.message?` (${e.message})`:"")+(n?wt(n)||Ee(t)?".":`, expected an instance of \`${n.name}\` or a snapshot like \`${l=n,o.enabled?function(e,t){if(t<=0)return e;try{const n=" ".repeat(t);let i="",r=0,s=null,a=!1;const o=()=>{i=i.replace(/[ \t]+$/,""),i+="\n"+n.repeat(Math.max(0,r))};for(let t=0;t<e.length;t++){const n=e[t];if(s)i+=n,a?a=!1:"\\"===n?a=!0:n===s&&(s=null);else switch(n){case'"':case"'":s=n,i+=n;break;case"{":for(r++,i+="{",o();" "===e[t+1];)t++;break;case"}":r--,o(),i+="}";break;case";":for(i+=";",o();" "===e[t+1];)t++;break;default:i+=n}}return i}catch(t){return e}}(l.describe(),o.indent):l.describe()}\` instead.`+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".");var l}function X(e,t,n){return e.concat([{path:t,type:n}])}function ee(){return we}function te(e,t,n){return[{context:e,value:t,message:n}]}function ne(e){return e.reduce((e,t)=>e.concat(t),[])}function ie(e,t){"undefined"!=typeof process&&process.env&&"true"===process.env.ENABLE_TYPE_CHECK&&re(e,t)}function re(e,t){const n=e.validate(t,[{path:"",type:e}]);if(n.length>0)throw new Se(function(e,t,n){if(0===n.length)return;const i=K(t);return`Error while converting ${J().enabled?i:(r=i,r.length<280?r:`${r.substring(0,272)}......${r.substring(r.length-8)}`)} to \`${e.name}\`:\n\n `+n.map(Q).join("\n ");var r}(e,t,n))}let se=0;class ae{constructor(){Object.defineProperty(this,"cacheId",{enumerable:!0,configurable:!0,writable:!0,value:se++}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:t.observable.map()}),Object.defineProperty(this,"lastCacheModificationPerId",{enumerable:!0,configurable:!0,writable:!0,value:t.observable.map()})}updateLastCacheModificationPerId(e){const t=this.lastCacheModificationPerId.get(e);this.lastCacheModificationPerId.set(e,void 0===t?1:t+1)}getLastCacheModificationPerId(e){const t=this.lastCacheModificationPerId.get(e)||0;return`${this.cacheId}-${t}`}addNodeToCache(e,n=!0){if(e.identifierAttribute){const i=e.identifier;this.cache.has(i)||this.cache.set(i,t.observable.array([],_e));const r=this.cache.get(i);if(-1!==r.indexOf(e))throw new Se("Already registered");r.push(e),n&&this.updateLastCacheModificationPerId(i)}}mergeCache(e){t.values(e.identifierCache.cache).forEach(e=>e.forEach(e=>{this.addNodeToCache(e)}))}notifyDied(e){if(e.identifierAttribute){const t=e.identifier,n=this.cache.get(t);n&&(n.remove(e),n.length||this.cache.delete(t),this.updateLastCacheModificationPerId(e.identifier))}}splitCache(e){const n=new ae,i=e.path+"/";return t.entries(this.cache).forEach(([t,r])=>{let s=!1;for(let a=r.length-1;a>=0;a--){const o=r[a];o!==e&&0!==o.path.indexOf(i)||(n.addNodeToCache(o,!1),r.splice(a,1),r.length||this.cache.delete(t),s=!0)}s&&this.updateLastCacheModificationPerId(t)}),n}has(e,t){const n=this.cache.get(t);return!!n&&n.some(t=>e.isAssignableFrom(t.type))}resolve(e,t){const n=this.cache.get(t);if(!n)return null;const i=n.filter(t=>e.isAssignableFrom(t.type));switch(i.length){case 0:return null;case 1:return i[0];default:throw new Se(`Cannot resolve a reference to type '${e.name}' with id: '${t}' unambigously, there are multiple candidates: ${i.map(e=>e.path).join(", ")}`)}}}function oe(e,t,n,i,r){const s=pe(r);if(s){if(s.parent)throw new Se(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${t?t.path:""}/${n}', but it lives already at '${s.path}'`);return t&&s.setParent(t,n),s}return new S(e,t,n,i,r)}function le(e,t,n,i,r){return new v(e,t,n,i,r)}var ce;function ue(e){return!(!e||!e.$treenode)}function he(e){if(!ue(e))throw new Se(`Value ${e} is no MST Node`);return e.$treenode}function pe(e){return e&&e.$treenode||null}function de(){return he(this).snapshot}!function(e){e[e.INITIALIZING=0]="INITIALIZING",e[e.CREATED=1]="CREATED",e[e.FINALIZED=2]="FINALIZED",e[e.DETACHING=3]="DETACHING",e[e.DEAD=4]="DEAD"}(ce||(ce={}));const fe=e=>"..";function be(e,t){if(e.root!==t.root)throw new Se(`Cannot calculate relative path: objects '${e}' and '${t}' are not part of the same object tree`);const n=We(e.path),i=We(t.path);let r=0;for(;r<n.length&&n[r]===i[r];r++);return n.slice(r).map(fe).join("/")+Be(i.slice(r))}function ye(e,t,n=!0){return ge(e,We(t),n)}function ge(e,t,n=!0){let i=e;try{for(let e=0;e<t.length;e++){const n=t[e];if(".."===n){if(i=i.parent,i)continue}else{if("."===n)continue;if(i){if(i instanceof v){const e=i.value;ue(e)&&(i=he(e))}if(i instanceof S){if(i.getChildType(n)&&(i=i.getChildNode(n),i))continue}}}throw new Se(`Could not resolve '${n}' in path '${Be(t.slice(0,e))||"/"}' while resolving '${Be(t)}'`)}}catch(e){if(!n)return;throw e}return i}function ve(e){if(!e)return we;const t=Object.keys(e);if(!t.length)return we;const n=new Array(t.length);return t.forEach((t,i)=>{n[i]=e[t]}),n}const me=Object.toString(),we=Object.freeze([]),Pe=Object.freeze({}),_e={deep:!1};Object.freeze(_e);class Se extends Error{constructor(e="Illegal state"){super("[mobx-state-tree] "+e)}}function Ae(e){return e}const Oe=Number.isInteger;function Ie(e){return Array.isArray(e)||t.isObservableArray(e)}function je(e){return e?Ie(e)?e:[e]:we}function Te(e){var t;if(null===e||"object"!=typeof e)return!1;const n=Object.getPrototypeOf(e);return null==n||(null===(t=n.constructor)||void 0===t?void 0:t.toString())===me}function Ce(e){return!(null===e||"object"!=typeof e||e instanceof Date||e instanceof RegExp)}function Ee(e,t=!0){return null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||t&&e instanceof Date}function Ne(e){return"function"!=typeof e}function Ve(e,n,i){!function(e,n,i){t.isObservableObject(e)?t.defineProperty(e,n,i):Object.defineProperty(e,n,i)}(e,n,{enumerable:!1,writable:!1,configurable:!0,value:i})}class De{constructor(){Object.defineProperty(this,"handlers",{enumerable:!0,configurable:!0,writable:!0,value:[]})}get hasSubscribers(){return this.handlers.length>0}register(e,t=!1){return t?this.handlers.unshift(e):this.handlers.push(e),()=>{this.unregister(e)}}has(e){return this.handlers.indexOf(e)>=0}unregister(e){const t=this.handlers.indexOf(e);t>=0&&this.handlers.splice(t,1)}clear(){this.handlers.length=0}emit(...e){this.handlers.slice().forEach(t=>t(...e))}}class xe{constructor(){Object.defineProperty(this,"eventHandlers",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}hasSubscribers(e){const t=this.eventHandlers&&this.eventHandlers[e];return!!t&&t.hasSubscribers}register(e,t,n=!1){this.eventHandlers||(this.eventHandlers={});let i=this.eventHandlers[e];return i||(i=this.eventHandlers[e]=new De),i.register(t,n)}has(e,t){const n=this.eventHandlers&&this.eventHandlers[e];return!!n&&n.has(t)}unregister(e,t){const n=this.eventHandlers&&this.eventHandlers[e];n&&n.unregister(t)}clear(e){this.eventHandlers&&delete this.eventHandlers[e]}clearAll(){this.eventHandlers=void 0}emit(e,...t){const n=this.eventHandlers&&this.eventHandlers[e];n&&n.emit(...t)}}function $e(e){const t=new Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n];return t}function ke(e,t){return 0===e.indexOf(t)}const Re=function(e,t){};function ze(e){"function"==typeof queueMicrotask?queueMicrotask(e):"function"==typeof setImmediate?setImmediate(e):setTimeout(e,1)}function Fe(e){return function(e,t){const n=function(){const i=M(),r=F();if(!r)throw new Se("a mst flow must always have a parent context");const s=H(r);if(!s)throw new Se("a mst flow must always have a parent action context");const a={name:e,id:i,tree:r.tree,context:r.context,parentId:r.id,allParentIds:[...r.allParentIds,r.id],rootId:r.rootId,parentEvent:r,parentActionEvent:s},o=arguments;function l(e,t,i){return e.$mst_middleware=n.$mst_middleware,L(Object.assign(Object.assign({},a),{type:t,args:[i]}),e)}return new Promise((function(e,i){let r;const s=function(){r=t.apply(null,arguments),c(void 0)};function c(e){let t;try{const n=l(e=>{t=r.next(e)},"flow_resume",e);n instanceof Error&&(t=r.throw(n))}catch(e){return void ze(()=>{l(t=>{i(e)},"flow_throw",e)})}h(t)}function u(e){let t;try{l(e=>{t=r.throw(e)},"flow_resume_error",e)}catch(e){return void ze(()=>{l(t=>{i(e)},"flow_throw",e)})}h(t)}function h(t){if(!t.done){if(!t.value||"function"!=typeof t.value.then)throw new Se("Only promises can be yielded to `async`, got: "+t);return t.value.then(c,u)}ze(()=>{l(t=>{e(t)},"flow_return",t.value)})}s.$mst_middleware=n.$mst_middleware,L(Object.assign(Object.assign({},a),{type:"flow_spawn",args:$e(o)}),s)}))};return n._isFlowAction=!0,n}(e.name,e)}function Me(e){switch(e.op){case"add":return{op:"add",path:e.path,value:e.value};case"remove":return{op:"remove",path:e.path};case"replace":return{op:"replace",path:e.path,value:e.value}}}function Le(e){switch(e.op){case"add":return{op:"remove",path:e.path};case"remove":return{op:"add",path:e.path,value:e.oldValue};case"replace":return{op:"replace",path:e.path,value:e.oldValue}}}function He(e){return!0==("number"==typeof e)?""+e:-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function Ue(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Be(e){if(0===e.length)return"";const t=e=>e.map(He).join("/");return"."===e[0]||".."===e[0]?t(e):"/"+t(e)}function We(e){const t=e.split("/").map(Ue);if(!(""===e||"."===e||".."===e||ke(e,"/")||ke(e,"./")||ke(e,"../")))throw new Se(`a json path must be either rooted, empty or relative, but got '${e}'`);return""===t[0]&&t.shift(),t}Re.ids={};const Ge=Symbol("$preProcessorFailed");class Ze extends j{get flags(){return this._subtype.flags|O.SnapshotProcessor}constructor(e,t,n){super(n||e.name),Object.defineProperty(this,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_processors",{enumerable:!0,configurable:!0,writable:!0,value:t})}describe(){return`snapshotProcessor(${this._subtype.describe()})`}preProcessSnapshot(e){return this._processors.preProcessor?this._processors.preProcessor.call(null,e):e}preProcessSnapshotSafe(e){try{return this.preProcessSnapshot(e)}catch(e){return Ge}}postProcessSnapshot(e,t){return this._processors.postProcessor?this._processors.postProcessor.call(null,e,t.storedValue):e}_fixNode(e){!function(e,t,...n){for(const i of n)e[i]=t[i].bind(t)}(e.type,this,"create"),e instanceof S&&(e.hasSnapshotPostProcessor=!!this._processors.postProcessor);const t=e.getSnapshot;e.getSnapshot=()=>this.postProcessSnapshot(t.call(e),e),It(this._subtype)||(e.getReconciliationType=()=>this)}instantiate(e,t,n,i){const r=ue(i)?i:this.preProcessSnapshot(i),s=this._subtype.instantiate(e,t,n,r);return this._fixNode(s),s}reconcile(e,t,n,i){const r=this._subtype.reconcile(e,ue(t)?t:this.preProcessSnapshot(t),n,i);return r!==e&&this._fixNode(r),r}getSnapshot(e,t=!0){const n=this._subtype.getSnapshot(e);return t?this.postProcessSnapshot(n,e):n}isValidSnapshot(e,t){const n=this.preProcessSnapshotSafe(e);return n===Ge?te(t,e,"Failed to preprocess value"):this._subtype.validate(n,t)}getSubTypes(){return this._subtype}is(e){const t=N(e)?this._subtype:ue(e)?e:this.preProcessSnapshotSafe(e);return t!==Ge&&0===this._subtype.validate(t,[{path:"",type:this._subtype}]).length}isAssignableFrom(e){return this._subtype.isAssignableFrom(e)}isMatchingSnapshotId(e,t){if(!(this._subtype instanceof T))return!1;const n=this.preProcessSnapshot(t);return this._subtype.isMatchingSnapshotId(e,n)}}const Ye="Map.put can only be used to store complex values that have an identifier type attribute";var Je;!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.YES=1]="YES",e[e.NO=2]="NO"}(Je||(Je={}));class qe extends t.ObservableMap{constructor(e,t){super(e,e=>e,t)}get(e){return super.get(""+e)}has(e){return super.has(""+e)}delete(e){return super.delete(""+e)}set(e,t){return super.set(""+e,t)}put(e){if(!e)throw new Se("Map.put cannot be used to set empty values");if(ue(e)){const t=he(e);if(null===t.identifier)throw new Se(Ye);return this.set(t.identifier,e),e}if(Ce(e)){const t=he(this),n=t.type;if(n.identifierMode!==Je.YES)throw new Se(Ye);const i=e[n.mapIdentifierAttribute];if(!Yt(i)){const i=this.put(n.getChildType().create(e,t.environment));return this.put(u(i))}const r=Zt(i);return this.set(r,e),this.get(r)}throw new Se("Map.put can only be used to store complex values")}}class Ke extends T{constructor(e,t,n=[]){super(e),Object.defineProperty(this,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"identifierMode",{enumerable:!0,configurable:!0,writable:!0,value:Je.UNKNOWN}),Object.defineProperty(this,"mapIdentifierAttribute",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Map}),Object.defineProperty(this,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this._determineIdentifierMode(),this.hookInitializers=n}hooks(e){const t=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new Ke(this.name,this._subType,t)}instantiate(e,t,n,i){return this._determineIdentifierMode(),oe(this,e,t,n,i)}_determineIdentifierMode(){if(this.identifierMode!==Je.UNKNOWN)return;const e=[];if(function e(t,n){const i=t.getSubTypes();if("cannotDetermine"===i)return!1;if(i){const t=je(i);for(const i of t)if(!e(i,n))return!1}return t instanceof st&&n.push(t),!0}(this._subType,e)){const t=e.reduce((e,t)=>{if(!t.identifierAttribute)return e;if(e&&e!==t.identifierAttribute)throw new Se(`The objects in a map should all have the same identifier attribute, expected '${e}', but child of type '${t.name}' declared attribute '${t.identifierAttribute}' as identifier`);return t.identifierAttribute},void 0);t?(this.identifierMode=Je.YES,this.mapIdentifierAttribute=t):this.identifierMode=Je.NO}}initializeChildNodes(e,t={}){const n=e.type._subType,i={};return Object.keys(t).forEach(r=>{i[r]=n.instantiate(e,r,void 0,t[r])}),i}createNewInstance(e){return new qe(e,this.name)}finalizeNewInstance(e,n){t._interceptReads(n,e.unbox);e.type.hookInitializers.forEach(e=>{const t=e(n);Object.keys(t).forEach(e=>{const i=t[e],r=U(n,e,i);Ve(n,e,r)})}),t.intercept(n,this.willChange),t.observe(n,this.didChange)}describe(){return this.name}getChildren(e){return t.values(e.storedValue)}getChildNode(e,t){const n=e.storedValue.get(""+t);if(!n)throw new Se("Not a child "+t);return n}willChange(e){const t=he(e.object),n=e.name;t.assertWritable({subpath:n});const i=t.type,r=i._subType;switch(e.type){case"update":{const{newValue:s}=e;if(s===e.object.get(n))return null;ie(r,s),e.newValue=r.reconcile(t.getChildNode(n),e.newValue,t,n),i.processIdentifier(n,e.newValue)}break;case"add":ie(r,e.newValue),e.newValue=r.instantiate(t,n,void 0,e.newValue),i.processIdentifier(n,e.newValue)}return e}processIdentifier(e,t){if(this.identifierMode===Je.YES&&t instanceof S){const n=t.identifier;if(n!==e)throw new Se(`A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '${n}', but expected: '${e}'`)}}getSnapshot(e){const t={};return e.getChildren().forEach(e=>{t[e.subpath]=e.snapshot}),t}processInitialSnapshot(e){const t={};return Object.keys(e).forEach(n=>{t[n]=e[n].getSnapshot()}),t}didChange(e){const t=he(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:He(e.name),value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"add":return void t.emitPatch({op:"add",path:He(e.name),value:e.newValue.snapshot,oldValue:void 0},t);case"delete":const n=e.oldValue.snapshot;return e.oldValue.die(),void t.emitPatch({op:"remove",path:He(e.name),oldValue:n},t)}}applyPatchLocally(e,t,n){const i=e.storedValue;switch(n.op){case"add":case"replace":i.set(t,n.value);break;case"remove":i.delete(t)}}applySnapshot(e,t){if(!Te(t))return void ie(this,t);const n=e.storedValue,i=this.getChildType();Array.from(n.keys()).forEach(r=>{if(!Object.prototype.hasOwnProperty.call(t,r))return void n.delete(r);const s=e.getChildNode(r),a=t[r];s.snapshot!==a&&(E(i,s,a)?s.applySnapshot(a):n.set(r,a))});for(let e in t)Object.prototype.hasOwnProperty.call(t,e)&&!n.has(e)&&n.set(e,t[e])}getChildType(){return this._subType}isValidSnapshot(e,t){return Te(e)?ne(Object.keys(e).map(n=>this._subType.validate(e[n],X(t,n,this._subType)))):te(t,e,"Value is not a plain object")}getDefaultSnapshot(){return Pe}removeChild(e,t){e.storedValue.delete(t)}}Ke.prototype.applySnapshot=t.action(Ke.prototype.applySnapshot);class Qe extends T{constructor(e,t,n=[]){super(e),Object.defineProperty(this,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Array}),Object.defineProperty(this,"hookInitializers",{enumerable:!0,configurable:!0,writable:!0,value:[]}),this.hookInitializers=n}hooks(e){const t=this.hookInitializers.length>0?this.hookInitializers.concat(e):[e];return new Qe(this.name,this._subType,t)}instantiate(e,t,n,i){return oe(this,e,t,n,i)}initializeChildNodes(e,t=[]){const n=e.type._subType,i={};return t.forEach((t,r)=>{const s=""+r;i[s]=n.instantiate(e,s,void 0,t)}),i}createNewInstance(e){const n=Object.assign(Object.assign({},_e),{name:this.name});return t.observable.array(ve(e),n)}finalizeNewInstance(e,n){t._getAdministration(n).dehancer=e.unbox;e.type.hookInitializers.forEach(e=>{const t=e(n);Object.keys(t).forEach(e=>{const i=t[e],r=U(n,e,i);Ve(n,e,r)})}),t.intercept(n,this.willChange),t.observe(n,this.didChange)}describe(){return this.name}getChildren(e){return e.storedValue.slice()}getChildNode(e,t){const n=Number(t);if(n<e.storedValue.length)return e.storedValue[n];throw new Se("Not a child: "+t)}willChange(e){const t=he(e.object);t.assertWritable({subpath:""+e.index});const n=t.type._subType,i=t.getChildren();switch(e.type){case"update":{if(e.newValue===e.object[e.index])return null;const r=Xe(t,n,[i[e.index]],[e.newValue],[e.index]);if(!r)return null;e.newValue=r[0]}break;case"splice":{const{index:r,removedCount:s,added:a}=e,o=Xe(t,n,i.slice(r,r+s),a,a.map((e,t)=>r+t));if(!o)return null;e.added=o;for(let e=r+s;e<i.length;e++)i[e].setParent(t,""+(e+a.length-s))}}return e}getSnapshot(e){return e.getChildren().map(e=>e.snapshot)}processInitialSnapshot(e){const t=[];return Object.keys(e).forEach(n=>{t.push(e[n].getSnapshot())}),t}didChange(e){const t=he(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:""+e.index,value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"splice":if(e.removedCount&&e.addedCount===e.object.length)return void t.emitPatch({op:"replace",path:"",value:t.snapshot,oldValue:e.removed.map(e=>e.snapshot)},t);for(let n=e.removedCount-1;n>=0;n--)t.emitPatch({op:"remove",path:""+(e.index+n),oldValue:e.removed[n].snapshot},t);for(let n=0;n<e.addedCount;n++)t.emitPatch({op:"add",path:""+(e.index+n),value:e.added[n].snapshot,oldValue:void 0},t);return}}applyPatchLocally(e,t,n){const i=e.storedValue,r="-"===t?i.length:Number(t);switch(n.op){case"replace":i[r]=n.value;break;case"add":i.splice(r,0,n.value);break;case"remove":i.splice(r,1)}}applySnapshot(e,t){if(!Ie(t))return void ie(this,t);const n=e.storedValue,i=e.getChildren(),r=i.length,s=t.length,a=this.getChildType(),o=function(e,t,n){let i=0;for(;i<n&&e[i].snapshot===t[i];)i++;return i}(i,t,Math.min(r,s));if(o===r&&o===s)return;if(r!==s||e.hasPatchSubscribers())return void n.replace(t);if(function(e,t,n,i){for(let r=i;r<t.length;r++){const i=t[r];if(i.snapshot!==n[r]){if(!E(e,i,n[r]))return!1;if(!i.identifierAttribute||null===i.identifier)return!1}}return!0}(a,i,t,o))return void function(e,t,n){for(let i=n;i<e.length;i++){const n=e[i];n.snapshot!==t[i]&&n.applySnapshot(t[i])}}(i,t,o);const l=[];for(let e=o;e<r;e++)i[e].snapshot!==t[e]&&l.push(e);for(const e of l)n[e]=t[e]}getChildType(){return this._subType}isValidSnapshot(e,t){return Ie(e)?ne(e.map((e,n)=>this._subType.validate(e,X(t,""+n,this._subType)))):te(t,e,"Value is not an array")}getDefaultSnapshot(){return we}removeChild(e,t){e.storedValue.splice(Number(t),1)}}function Xe(e,t,n,i,r){let s=!0;for(let o=0;;o++){const l=o<=i.length-1,c=n[o];let u=l?i[o]:void 0;const h=""+r[o];if(((a=u)instanceof v||a instanceof S)&&(u=u.storedValue),!c&&!l)break;if(l)if(c)if(tt(c,u))n[o]=et(t,e,h,u,c);else{let i=void 0;for(let e=o;e<n.length;e++)if(tt(n[e],u)){i=n.splice(e,1)[0];break}s=!1;const r=et(t,e,h,u,i);n.splice(o,0,r)}else{if(ue(u)&&he(u).parent===e)throw new Se(`Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '${e.path}/${h}', but it lives already at '${he(u).path}'`);s=!1;const i=et(t,e,h,u);n.splice(o,0,i)}else s=!1,n.splice(o,1),c instanceof S&&c.createObservableInstanceIfNeeded(),c.die(),o--}var a;return s?null:n}function et(e,t,n,i,r){ie(e,i);const s=function(){if(ue(i)){const e=he(i);if(e.assertAlive(Pe),null!==e.parent&&e.parent===t)return e.setParent(t,n),e}return r?e.reconcile(r,i,t,n):e.instantiate(t,n,void 0,i)}();return r&&r!==s&&(r instanceof S&&r.createObservableInstanceIfNeeded(),r.die()),s}function tt(e,t){if(!e.isAlive)return!1;if(ue(t)){const n=he(t);return n.isAlive&&n===e}if(e.snapshot===t)return!0;if(!(e instanceof S))return!1;const n=e.getReconciliationType();return null!==e.identifier&&e.identifierAttribute&&Te(t)&&n.is(t)&&n.isMatchingSnapshotId(e,t)}Qe.prototype.applySnapshot=t.action(Qe.prototype.applySnapshot),"function"==typeof SuppressedError&&SuppressedError;function nt(){return he(this).toString()}const it={name:"AnonymousModel",properties:{},initializers:we};function rt(e){const t=Object.keys(e),n=new Set;return t.forEach(e=>{if(n.has(e))throw new Se(e+" is declared twice in the model. Model should not contain the same keys");n.add(e)}),t.reduce((t,n)=>{if(n in s)throw new Se(`Hook '${n}' was defined as property. Hooks should be defined as part of the actions`);const i=Object.getOwnPropertyDescriptor(e,n);if("get"in i)throw new Se("Getters are not supported as properties. Please use views instead");const r=i.value;if(null==r)throw new Se("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(Ee(r))t[n]=Tt(function(e){switch(typeof e){case"string":return lt;case"number":return ct;case"boolean":return bt;case"bigint":return ft;case"object":if(e instanceof Date)return mt}throw new Se("Cannot determine primitive type from value "+e)}(r),r);else if(r instanceof Ke)t[n]=Tt(r,{});else if(r instanceof Qe)t[n]=Tt(r,[]);else if(!N(r))throw new Se(`Invalid type definition for property '${n}', cannot infer a type from a value like '${r}' (${typeof r})`);return t},Object.assign({},e))}class st extends T{constructor(e){super(e.name||it.name),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Object}),Object.defineProperty(this,"initializers",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"properties",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"preProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"postProcessor",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"propertyNames",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"named",{enumerable:!0,configurable:!0,writable:!0,value:e=>this.cloneAndEnhance({name:e})}),Object.defineProperty(this,"props",{enumerable:!0,configurable:!0,writable:!0,value:e=>this.cloneAndEnhance({properties:e})}),Object.defineProperty(this,"preProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=this.preProcessor;return t?this.cloneAndEnhance({preProcessor:n=>t(e(n))}):this.cloneAndEnhance({preProcessor:e})}}),Object.defineProperty(this,"postProcessSnapshot",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=this.postProcessor;return t?this.cloneAndEnhance({postProcessor:n=>e(t(n))}):this.cloneAndEnhance({postProcessor:e})}}),Object.assign(this,it,e),this.properties=rt(this.properties),this.properties,this.propertyNames=Object.keys(this.properties),this.identifierAttribute=this._getIdentifierAttribute()}_getIdentifierAttribute(){let e=void 0;return this.forAllProps((t,n)=>{if(n.flags&O.Identifier){if(e)throw new Se(`Cannot define property '${t}' as object identifier, property '${e}' is already defined as identifier property`);e=t}}),e}cloneAndEnhance(e){return new st({name:e.name||this.name,properties:Object.assign({},this.properties,e.properties),initializers:this.initializers.concat(e.initializers||[]),preProcessor:e.preProcessor||this.preProcessor,postProcessor:e.postProcessor||this.postProcessor})}actions(e){return this.cloneAndEnhance({initializers:[t=>(this.instantiateActions(t,e(t)),t)]})}instantiateActions(e,t){if(!Te(t))throw new Se("actions initializer should return a plain object containing actions");Object.getOwnPropertyNames(t).forEach(n=>{if(n in this.properties)throw new Se(`'${n}' is a property and cannot be declared as an action`);if("preProcessSnapshot"===n)throw new Se("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");if("postProcessSnapshot"===n)throw new Se("Cannot define action 'postProcessSnapshot', it should be defined using 'type.postProcessSnapshot(fn)' instead");let i=t[n],r=e[n];if(n in s&&r){let e=i;i=function(){r.apply(null,arguments),e.apply(null,arguments)}}const a=i.$mst_middleware;let o=i.bind(t);o._isFlowAction=i._isFlowAction||!1,o.$mst_middleware=a;const l=U(e,n,o);t[n]=l,Ve(e,n,l)})}volatile(e){if("function"!=typeof e)throw new Se(`You passed an ${typeof e} to volatile state as an argument, when function is expected`);return this.cloneAndEnhance({initializers:[t=>(this.instantiateVolatileState(t,e(t)),t)]})}instantiateVolatileState(e,n){if(!Te(n))throw new Se("volatile state initializer should return a plain object containing state");Object.getOwnPropertyNames(n).forEach(i=>{if(i in this.properties)throw new Se(`'${i}' is a property and cannot be declared as volatile state`);t.set(e,i,n[i])})}extend(e){return this.cloneAndEnhance({initializers:[t=>{const n=e(t),{actions:i,views:r,state:s}=n,a=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(n[i[r]]=e[i[r]])}return n}(n,["actions","views","state"]);for(let e in a)throw new Se(`The \`extend\` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '${e}'`);return s&&this.instantiateVolatileState(t,s),r&&this.instantiateViews(t,r),i&&this.instantiateActions(t,i),t}]})}views(e){return this.cloneAndEnhance({initializers:[t=>(this.instantiateViews(t,e(t)),t)]})}instantiateViews(e,n){if(!Te(n))throw new Se("views initializer should return a plain object containing views");Object.getOwnPropertyNames(n).forEach(i=>{if(i in this.properties)throw new Se(`'${i}' is a property and cannot be declared as a view`);const r=Object.getOwnPropertyDescriptor(n,i);if("get"in r)t.defineProperty(e,i,r),t.makeObservable(e,{[i]:t.computed});else{if("function"!=typeof r.value)throw new Se("A view member should either be a function or getter based property");Ve(e,i,r.value)}})}instantiate(e,t,n,i){return oe(this,e,t,n,ue(i)?i:this.applySnapshotPreProcessor(i))}initializeChildNodes(e,t={}){const n=e.type,i={};return n.forAllProps((n,r)=>{i[n]=r.instantiate(e,n,void 0,t[n])}),i}createNewInstance(e){const n=Object.assign(Object.assign({},_e),{name:this.name});return t.observable.object(e,Pe,n)}finalizeNewInstance(e,n){Ve(n,"toString",nt),this.forAllProps(i=>{t._interceptReads(n,i,e.unbox)}),this.initializers.reduce((e,t)=>t(e),n),t.intercept(n,this.willChange),t.observe(n,this.didChange)}willChange(e){const t=e,n=he(t.object),i=t.name;n.assertWritable({subpath:i});const r=n.type.properties[i];return r&&(ie(r,t.newValue),t.newValue=r.reconcile(n.getChildNode(i),t.newValue,n,i)),t}didChange(e){const t=e,n=he(t.object);if(!n.type.properties[t.name])return;const i=t.oldValue?t.oldValue.snapshot:void 0;n.emitPatch({op:"replace",path:He(t.name),value:t.newValue.snapshot,oldValue:i},n)}getChildren(e){const t=[];return this.forAllProps(n=>{t.push(this.getChildNode(e,n))}),t}getChildNode(e,n){var i;if(!(n in this.properties))throw new Se("Not a value property: "+n);const r=t._getAdministration(e.storedValue,n),s=null===(i=r.raw)||void 0===i?void 0:i.call(r);if(!s)throw new Se("Node not available for property "+n);return s}getSnapshot(e,n=!0){const i={};return this.forAllProps((n,r)=>{t.getAtom(e.storedValue,n).reportObserved(),i[n]=this.getChildNode(e,n).snapshot}),n?this.applySnapshotPostProcessor(i):i}processInitialSnapshot(e){const t={};return Object.keys(e).forEach(n=>{t[n]=e[n].getSnapshot()}),this.applySnapshotPostProcessor(t)}applyPatchLocally(e,t,n){if("replace"!==n.op&&"add"!==n.op)throw new Se("object does not support operation "+n.op);e.storedValue[t]=n.value}applySnapshot(e,t){const n=this.applySnapshotPreProcessor(t),i=!Te(n);(Te(t)&&!i||(ie(this,t),!i))&&this.forAllProps((t,i)=>{const r=e.getChildNode(t),s=n[t];r.snapshot!==s&&(E(i,r,s)?r.applySnapshot(s):e.storedValue[t]=s)})}applySnapshotPreProcessor(e){const t=this.preProcessor;return t?t.call(null,e):e}applySnapshotPostProcessor(e){const t=this.postProcessor;return t?t.call(null,e):e}getChildType(e){return this.properties[e]}isValidSnapshot(e,t){let n=this.applySnapshotPreProcessor(e);return Te(n)?ne(this.propertyNames.map(e=>this.properties[e].validate(n[e],X(t,e,this.properties[e])))):te(t,n,"Value is not a plain object")}forAllProps(e){this.propertyNames.forEach(t=>e(t,this.properties[t]))}describe(){return"{ "+this.propertyNames.map(e=>e+": "+this.properties[e].describe()).join("; ")+" }"}getDefaultSnapshot(){return Pe}removeChild(e,t){e.storedValue[t]=void 0}}function at(e){return N(e)&&(e.flags&O.Object)>0}st.prototype.applySnapshot=t.action(st.prototype.applySnapshot);class ot extends C{constructor(e,t,n,i=Ae){super(e),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"checker",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"initializer",{enumerable:!0,configurable:!0,writable:!0,value:i}),this.flags=t}describe(){return this.name}instantiate(e,t,n,i){return le(this,e,t,n,i)}createNewInstance(e){return this.initializer(e)}isValidSnapshot(e,t){if(Ee(e)&&this.checker(e))return ee();return te(t,e,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))}}const lt=new ot("string",O.String,e=>"string"==typeof e),ct=new ot("number",O.Number,e=>"number"==typeof e),ut=new ot("integer",O.Integer,e=>Oe(e)),ht=new ot("float",O.Float,e=>{return t=e,Number(t)===t&&t%1!=0;var t}),pt=new ot("finite",O.Finite,e=>{return t=e,Number.isFinite(t);var t}),dt=new ot("bigint",O.BigInt,e=>{if("bigint"==typeof e)return!0;if("string"==typeof e||"number"==typeof e)try{return BigInt(e),!0}catch(e){}return!1},e=>"bigint"==typeof e?e:BigInt(e));dt.getSnapshot=function(e){return String(e.storedValue)};const ft=dt,bt=new ot("boolean",O.Boolean,e=>"boolean"==typeof e),yt=new ot("null",O.Null,e=>null===e),gt=new ot("undefined",O.Undefined,e=>void 0===e),vt=new ot("Date",O.Date,e=>"number"==typeof e||e instanceof Date,e=>e instanceof Date?e:new Date(e));vt.getSnapshot=function(e){return e.storedValue.getTime()};const mt=vt;function wt(e){return N(e)&&(e.flags&(O.String|O.Number|O.Integer|O.Boolean|O.Date|O.BigInt))>0}class Pt extends C{constructor(e){super(JSON.stringify(e)),Object.defineProperty(this,"value",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Literal}),this.value=e}instantiate(e,t,n,i){return le(this,e,t,n,i)}describe(){return JSON.stringify(this.value)}isValidSnapshot(e,t){return Ee(e)&&e===this.value?ee():te(t,e,"Value is not a literal "+JSON.stringify(this.value))}}function _t(e){return new Pt(e)}class St extends j{get flags(){return this._subtype.flags|O.Refinement}constructor(e,t,n,i){super(e),Object.defineProperty(this,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_predicate",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"_message",{enumerable:!0,configurable:!0,writable:!0,value:i})}describe(){return this.name}instantiate(e,t,n,i){return this._subtype.instantiate(e,t,n,i)}isAssignableFrom(e){return this._subtype.isAssignableFrom(e)}isValidSnapshot(e,t){const n=this._subtype.validate(e,t);if(n.length>0)return n;const i=ue(e)?he(e).snapshot:e;return this._predicate(i)?ee():te(t,e,this._message(e))}reconcile(e,t,n,i){return this._subtype.reconcile(e,t,n,i)}getSubTypes(){return this._subtype}}class At extends j{get flags(){let e=O.Union;return this._types.forEach(t=>{e|=t.flags}),e}constructor(e,t,n){super(e),Object.defineProperty(this,"_types",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_dispatcher",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"_eager",{enumerable:!0,configurable:!0,writable:!0,value:!0}),n=Object.assign({eager:!0,dispatcher:void 0},n),this._dispatcher=n.dispatcher,n.eager||(this._eager=!1)}isAssignableFrom(e){return this._types.some(t=>t.isAssignableFrom(e))}describe(){return"("+this._types.map(e=>e.describe()).join(" | ")+")"}instantiate(e,t,n,i){const r=this.determineType(i,void 0);if(!r)throw new Se("No matching type for union "+this.describe());return r.instantiate(e,t,n,i)}reconcile(e,t,n,i){const r=this.determineType(t,e.getReconciliationType());if(!r)throw new Se("No matching type for union "+this.describe());return r.reconcile(e,t,n,i)}determineType(e,t){return this._dispatcher?this._dispatcher(e):t?t.is(e)?t:this._types.filter(e=>e!==t).find(t=>t.is(e)):this._types.find(t=>t.is(e))}isValidSnapshot(e,t){if(this._dispatcher)return this._dispatcher(e).validate(e,t);const n=[];let i=0;for(let r=0;r<this._types.length;r++){const s=this._types[r].validate(e,t);if(0===s.length){if(this._eager)return ee();i++}else n.push(s)}return 1===i?ee():te(t,e,"No type is applicable for the union").concat(ne(n))}getSubTypes(){return this._types}}function Ot(e,...t){const n=N(e)?void 0:e,i=N(e)?[e,...t]:t,r="("+i.map(e=>e.name).join(" | ")+")";return new At(r,i,n)}function It(e){return N(e)&&(e.flags&O.Union)>0}class jt extends j{get flags(){return this._subtype.flags|O.Optional}constructor(e,t,n){super(e.name),Object.defineProperty(this,"_subtype",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"_defaultValue",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"optionalValues",{enumerable:!0,configurable:!0,writable:!0,value:n})}describe(){return this._subtype.describe()+"?"}instantiate(e,t,n,i){if(this.optionalValues.indexOf(i)>=0){const i=this.getDefaultInstanceOrSnapshot();return this._subtype.instantiate(e,t,n,i)}return this._subtype.instantiate(e,t,n,i)}reconcile(e,t,n,i){return this._subtype.reconcile(e,this.optionalValues.indexOf(t)<0&&this._subtype.is(t)?t:this.getDefaultInstanceOrSnapshot(),n,i)}getDefaultInstanceOrSnapshot(){const e="function"==typeof this._defaultValue?this._defaultValue():this._defaultValue;return"function"==typeof this._defaultValue&&ie(this,e),e}isValidSnapshot(e,t){return this.optionalValues.indexOf(e)>=0?ee():this._subtype.validate(e,t)}isAssignableFrom(e){return this._subtype.isAssignableFrom(e)}getSubTypes(){return this._subtype}}function Tt(e,t,n){return function(e,t){if("function"!=typeof t&&ue(t))throw new Se("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead")}(0,t),new jt(e,t,n||Ct)}const Ct=[void 0];const Et=Tt(gt,void 0),Nt=Tt(yt,null);function Vt(e){return Ot(e,Et)}class Dt extends j{get flags(){return(this._subType?this._subType.flags:0)|O.Late}getSubType(e){if(!this._subType){let t=void 0;try{t=this._definition()}catch(e){if(!(e instanceof ReferenceError))throw e;t=void 0}if(e&&void 0===t)throw new Se("Late type seems to be used too early, the definition (still) returns undefined");t&&(this._subType=t)}return this._subType}constructor(e,t){super(e),Object.defineProperty(this,"_definition",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"_subType",{enumerable:!0,configurable:!0,writable:!0,value:void 0})}instantiate(e,t,n,i){return this.getSubType(!0).instantiate(e,t,n,i)}reconcile(e,t,n,i){return this.getSubType(!0).reconcile(e,t,n,i)}describe(){const e=this.getSubType(!1);return e?e.name:"<uknown late type>"}isValidSnapshot(e,t){const n=this.getSubType(!1);return n?n.validate(e,t):ee()}isAssignableFrom(e){const t=this.getSubType(!1);return!!t&&t.isAssignableFrom(e)}getSubTypes(){const e=this.getSubType(!1);return e||"cannotDetermine"}}class xt extends C{constructor(e,n){super(e),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Lazy}),Object.defineProperty(this,"loadedType",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"pendingNodeList",{enumerable:!0,configurable:!0,writable:!0,value:t.observable.array()}),t.when(()=>this.pendingNodeList.length>0&&this.pendingNodeList.some(e=>e.isAlive&&this.options.shouldLoadPredicate(e.parent?e.parent.value:null)),()=>{this.options.loadType().then(t.action(e=>{this.loadedType=e,this.pendingNodeList.forEach(e=>{e.parent&&this.loadedType&&e.parent.applyPatches([{op:"replace",path:"/"+e.subpath,value:e.snapshot}])})}))})}describe(){return`<lazy ${this.name}>`}instantiate(e,n,i,r){if(this.loadedType)return this.loadedType.instantiate(e,n,i,r);const s=le(this,e,n,i,r);return this.pendingNodeList.push(s),t.when(()=>!s.isAlive,()=>this.pendingNodeList.splice(this.pendingNodeList.indexOf(s),1)),s}isValidSnapshot(e,t){return this.loadedType?this.loadedType.validate(e,t):Ne(e)?ee():te(t,e,"Value is not serializable and cannot be lazy")}reconcile(e,t,n,i){return this.loadedType?(e.die(),this.loadedType.instantiate(n,i,n.environment,t)):super.reconcile(e,t,n,i)}}class $t extends C{constructor(e){super(e?`frozen(${e.name})`:"frozen"),Object.defineProperty(this,"subType",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Frozen})}describe(){return"<any immutable value>"}instantiate(e,t,n,i){return le(this,e,t,n,i)}isValidSnapshot(e,t){return Ne(e)?this.subType?this.subType.validate(e,t):ee():te(t,e,"Value is not serializable and cannot be frozen")}}const kt=new $t;class Rt{constructor(e,t){if(Object.defineProperty(this,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"identifier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"node",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"resolvedReference",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Yt(e))this.identifier=e;else{if(!ue(e))throw new Se(`Can only store references to tree nodes or identifiers, got: '${e}'`);{const t=he(e);if(!t.identifierAttribute)throw new Se("Can only store references with a defined identifier attribute.");const n=t.unnormalizedIdentifier;if(null==n)throw new Se("Can only store references to tree nodes with a defined identifier.");this.identifier=n}}}updateResolvedReference(e){const t=Zt(this.identifier),n=e.root,i=n.identifierCache.getLastCacheModificationPerId(t);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==i){const{targetType:r}=this,s=n.identifierCache.resolve(r,t);if(!s)throw new zt(`[mobx-state-tree] Failed to resolve reference '${this.identifier}' to type '${this.targetType.name}' (from node: ${e.path})`);this.resolvedReference={node:s,lastCacheModification:i}}}get resolvedValue(){return this.updateResolvedReference(this.node),this.resolvedReference.node.value}}class zt extends Error{constructor(e){super(e),Object.setPrototypeOf(this,zt.prototype)}}class Ft extends C{constructor(e,t){super(`reference(${e.name})`),Object.defineProperty(this,"targetType",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"onInvalidated",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Reference})}describe(){return this.name}isAssignableFrom(e){return this.targetType.isAssignableFrom(e)}isValidSnapshot(e,t){return Yt(e)?ee():te(t,e,"Value is not a valid identifier, which is a string, number or a bigint")}fireInvalidated(e,t,n,i){const r=t.parent;if(!r||!r.isAlive)return;const s=r.storedValue;s&&this.onInvalidated({cause:e,parent:s,invalidTarget:i?i.storedValue:void 0,invalidId:n,replaceRef(e){l(t.root.storedValue,{op:"replace",value:e,path:t.path})},removeRef(){at(r.type)?this.replaceRef(void 0):l(t.root.storedValue,{op:"remove",path:t.path})}})}addTargetNodeWatcher(e,t){const n=this.getValue(e);if(!n)return;const i=he(n),r=(n,r)=>{const a=function(e){switch(e){case s.beforeDestroy:return"destroy";case s.beforeDetach:return"detach";default:return}}(r);a&&this.fireInvalidated(a,e,t,i)},a=i.registerHook(s.beforeDetach,r),o=i.registerHook(s.beforeDestroy,r);return()=>{a(),o()}}watchTargetNodeForInvalidations(e,t,n){if(!this.onInvalidated)return;let i;e.registerHook(s.beforeDestroy,()=>{i&&i()});const r=()=>{const n=()=>{e.isAlive&&this.getSnapshot(e)===t&&a(!1)};F()?e.root.enqueueEndOfAction(n):ze(n)},a=s=>{i&&i();const a=e.parent,o=a&&a.storedValue;if(a&&a.isAlive&&o){let a;a=n?!!n.get(t,o):e.root.identifierCache.has(this.targetType,Zt(t)),a?i=this.addTargetNodeWatcher(e,t):s?r():this.fireInvalidated("invalidSnapshotReference",e,t,null)}};e.state===ce.FINALIZED?a(!0):(e.isRoot||e.root.registerHook(s.afterCreationFinalization,()=>{e.parent&&e.parent.createObservableInstanceIfNeeded()}),e.registerHook(s.afterAttach,()=>{a(!1)}))}}class Mt extends Ft{constructor(e,t){super(e,t)}getValue(e){if(!e.isAlive)return;return e.storedValue.resolvedValue}getSnapshot(e){return e.storedValue.identifier}instantiate(e,t,n,i){const r=ue(i)?d(i):i,s=new Rt(i,this.targetType),a=le(this,e,t,n,s);return s.node=a,this.watchTargetNodeForInvalidations(a,r,void 0),a}reconcile(e,t,n,i){if(!e.isDetaching&&e.type===this){const r=ue(t),s=e.storedValue;if(!r&&s.identifier===t||r&&s.resolvedValue===t)return e.setParent(n,i),e}const r=this.instantiate(n,i,void 0,t);return e.die(),r}}class Lt extends Ft{constructor(e,t,n){super(e,n),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:t})}getValue(e){if(!e.isAlive)return;return this.options.get(e.storedValue,e.parent?e.parent.storedValue:null)}getSnapshot(e){return e.storedValue}instantiate(e,t,n,i){const r=ue(i)?this.options.set(i,e?e.storedValue:null):i,s=le(this,e,t,n,r);return this.watchTargetNodeForInvalidations(s,r,this.options),s}reconcile(e,t,n,i){const r=ue(t)?this.options.set(t,e?e.storedValue:null):t;if(!e.isDetaching&&e.type===this&&e.storedValue===r)return e.setParent(n,i),e;const s=this.instantiate(n,i,void 0,r);return e.die(),s}}function Ht(e,t){const n=t||void 0,i=t?t.onInvalidated:void 0;return n&&(n.get||n.set)?new Lt(e,{get:n.get,set:n.set},i):new Mt(e,i)}class Ut extends C{constructor(e,t){super(e),Object.defineProperty(this,"validType",{enumerable:!0,configurable:!0,writable:!0,value:t}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Identifier})}instantiate(e,t,n,i){if(!(e&&e.type instanceof st))throw new Se("Identifier types can only be instantiated as direct child of a model type");return le(this,e,t,n,i)}reconcile(e,t,n,i){if(e.storedValue!==t)throw new Se(`Tried to change identifier from '${e.storedValue}' to '${t}'. Changing identifiers is not allowed.`);return e.setParent(n,i),e}isValidSnapshot(e,t){return typeof e!==this.validType?te(t,e,`Value is not a valid ${this.describe()}, expected a ${this.validType}`):ee()}}const Bt=new class extends Ut{constructor(){super("identifier","string"),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Identifier})}describe(){return"identifier"}},Wt=new class extends Ut{constructor(){super("identifierNumber","number")}getSnapshot(e){return e.storedValue}describe(){return"identifierNumber"}};const Gt=new class extends C{constructor(){super("identifierBigint"),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Identifier})}createNewInstance(e){return"bigint"==typeof e?e:BigInt(e)}instantiate(e,t,n,i){if(!(e&&e.type instanceof st))throw new Se("Identifier types can only be instantiated as direct child of a model type");return le(this,e,t,n,i)}reconcile(e,t,n,i){const r=e.storedValue,s="bigint"==typeof t?t:BigInt(t);if(r!==s)throw new Se(`Tried to change identifier from '${r}' to '${s}'. Changing identifiers is not allowed.`);return e.setParent(n,i),e}isValidSnapshot(e,t){if("bigint"==typeof e)return ee();if("string"==typeof e||"number"==typeof e)try{return BigInt(e),ee()}catch(n){const i=n instanceof Error?n.message:String(n);return te(t,e,`Value is not a valid ${this.describe()}: ${i}`)}return te(t,e,`Value is not a valid ${this.describe()}, expected a bigint, a string or a number`)}getSnapshot(e){return String(e.storedValue)}describe(){return"identifierBigint"}};function Zt(e){return""+e}function Yt(e){return"string"==typeof e||"number"==typeof e||"bigint"==typeof e}class Jt extends C{constructor(e){super(e.name),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:e}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:O.Custom})}describe(){return this.name}isValidSnapshot(e,t){if(this.options.isTargetType(e))return ee();const n=this.options.getValidationMessage(e);return n?te(t,e,`Invalid value for type '${this.name}': ${n}`):ee()}getSnapshot(e){return this.options.toSnapshot(e.storedValue)}instantiate(e,t,n,i){return le(this,e,t,n,this.options.isTargetType(i)?i:this.options.fromSnapshot(i,e&&e.root.environment))}reconcile(e,t,n,i){const r=!this.options.isTargetType(t);if(!e.isDetaching){if(e.type===this&&(r?t===e.snapshot:t===e.storedValue))return e.setParent(n,i),e}const s=r?this.options.fromSnapshot(t,n.root.environment):t,a=this.instantiate(n,i,void 0,s);return e.die(),a}}const qt={enumeration:function(e,t){const n=Ot(...("string"==typeof e?t:e).map(e=>_t(e)));return"string"==typeof e&&(n.name=e),n},model:function(...e){const t="string"==typeof e[0]?e.shift():"AnonymousModel",n=e.shift()||{};return new st({name:t,properties:n})},compose:function(...e){const t="string"==typeof e[0],n=t?e[0]:"AnonymousModel";return t&&e.shift(),e.reduce((e,t)=>e.cloneAndEnhance({name:e.name+"_"+t.name,properties:t.properties,initializers:t.initializers,preProcessor:n=>t.applySnapshotPreProcessor(e.applySnapshotPreProcessor(n)),postProcessor:n=>t.applySnapshotPostProcessor(e.applySnapshotPostProcessor(n))})).named(n)},custom:function(e){return new Jt(e)},reference:Ht,safeReference:function(e,t){const n=Ht(e,Object.assign(Object.assign({},t),{onInvalidated(e){t&&t.onInvalidated&&t.onInvalidated(e),e.removeRef()}}));return t&&!1===t.acceptsUndefined?n:Vt(n)},union:Ot,optional:Tt,literal:_t,maybe:Vt,maybeNull:function(e){return Ot(e,Nt)},refinement:function(...e){const t="string"==typeof e[0]?e.shift():N(e[0])?e[0].name:null,n=e[0],i=e[1],r=e[2]?e[2]:e=>"Value does not respect the refinement predicate";return new St(t,n,i,r)},string:lt,boolean:bt,number:ct,integer:ut,float:ht,finite:pt,bigint:ft,Date:mt,map:function(e){return new Ke(`Map<string, ${e.name}>`,e)},array:function(e){return new Qe(e.name+"[]",e)},frozen:function(e){return 0===arguments.length?kt:N(e)?new $t(e):Tt(kt,e)},identifier:Bt,identifierNumber:Wt,identifierBigint:Gt,late:function(e,t){const n="string"==typeof e?e:`late(${e.toString()})`;return new Dt(n,"string"==typeof e?t:e)},lazy:function(e,t){return new xt(e,t)},undefined:gt,null:yt,snapshotProcessor:function(e,t,n){return new Ze(e,t,n)}};e.addDisposer=function(e,t){return he(e).addDisposer(t),t},e.addMiddleware=B,e.applyAction=$,e.applyPatch=l,e.applySnapshot=c,e.cast=function(e){return e},e.castFlowReturn=function(e){return e},e.castToReferenceSnapshot=function(e){return e},e.castToSnapshot=function(e){return e},e.clone=function(e,t=!0){const n=he(e);return n.type.create(n.snapshot,!0===t?n.root.environment:!1===t?void 0:t)},e.createActionTrackingMiddleware=function(e){return function(t,n,i){switch(t.type){case"action":if(e.filter&&!0!==e.filter(t))return n(t);{const i=e.onStart(t);e.onResume(t,i),V.set(t.id,{call:t,context:i,async:!1});try{const r=n(t);return e.onSuspend(t,i),!1===V.get(t.id).async&&(V.delete(t.id),e.onSuccess(t,i,r)),r}catch(n){throw V.delete(t.id),e.onFail(t,i,n),n}}case"flow_spawn":return V.get(t.rootId).async=!0,n(t);case"flow_resume":case"flow_resume_error":{const i=V.get(t.rootId);e.onResume(t,i.context);try{return n(t)}finally{e.onSuspend(t,i.context)}}case"flow_throw":{const i=V.get(t.rootId);return V.delete(t.rootId),e.onFail(t,i.context,t.args[0]),n(t)}case"flow_return":{const i=V.get(t.rootId);return V.delete(t.rootId),e.onSuccess(t,i.context,t.args[0]),n(t)}}}},e.createActionTrackingMiddleware2=function(e){const t=new Map;return function(n,i){const r=n.parentActionEvent?t.get(n.parentActionEvent.id):void 0;if("action"===n.type){const s=Object.assign(Object.assign({},n),{env:r&&r.call.env,parentCall:r&&r.call}),a=!e.filter||e.filter(s),o=new D(a?e:void 0,s);let l;t.set(n.id,o);try{l=i(n)}catch(e){throw t.delete(n.id),o.finish(e),e}return o.hasFlowsPending||(t.delete(n.id),o.finish()),l}if(!r)return i(n);switch(n.type){case"flow_spawn":return r.incFlowsPending(),i(n);case"flow_resume":case"flow_resume_error":return i(n);case"flow_throw":{const e=n.args[0];try{return i(n)}finally{r.decFlowsPending(),r.hasFlowsPending||(t.delete(n.parentActionEvent.id),r.finish(e))}}case"flow_return":try{return i(n)}finally{r.decFlowsPending(),r.hasFlowsPending||(t.delete(n.parentActionEvent.id),r.finish())}}}},e.decorate=function(e,t,n=!0){const i={handler:e,includeHooks:n};return t.$mst_middleware=t.$mst_middleware||[],t.$mst_middleware.push(i),t},e.destroy=function(e){const t=he(e);t.isRoot?t.die():t.parent.removeChild(t.subpath)},e.detach=function(e){return he(e).detach(),e},e.escapeJsonPath=He,e.flow=Fe,e.getChildType=function(e,t){return he(e).getChildType(t)},e.getEnv=function(e){const t=he(e),n=t.root.environment;if(!n)throw new Se(`Failed to find the environment of ${t} ${t.path}`);return n},e.getErrorFormatting=J,e.getIdentifier=d,e.getLivelinessChecking=r,e.getMembers=function(e){const n=he(e).type,i=Object.assign(Object.assign({},y(n)),{actions:[],volatile:[],views:[],flowActions:[]});return Object.getOwnPropertyNames(e).forEach(n=>{if(n in i.properties)return;const r=Object.getOwnPropertyDescriptor(e,n);r.get?t.isComputedProp(e,n)?i.views.push(n):i.volatile.push(n):(!0===r.value._isFlowAction&&i.flowActions.push(n),!0===r.value._isMSTAction?i.actions.push(n):t.isObservableProp(e,n)?i.volatile.push(n):i.views.push(n))}),i},e.getNodeId=function(e){return he(e).nodeId},e.getParent=function(e,t=1){let n=t,i=he(e).parent;for(;i;){if(0==--n)return i.storedValue;i=i.parent}throw new Se(`Failed to find the parent of ${he(e)} at depth ${t}`)},e.getParentOfType=function(e,t){let n=he(e).parent;for(;n;){if(t.is(n.storedValue))return n.storedValue;n=n.parent}throw new Se(`Failed to find the parent of ${he(e)} of a given type`)},e.getPath=p,e.getPathParts=function(e){return We(he(e).path)},e.getPropertyMembers=y,e.getRelativePath=function(e,t){return be(he(e),he(t))},e.getRoot=h,e.getRunningActionContext=G,e.getSnapshot=u,e.getType=a,e.hasEnv=function(e){return!!he(e).root.environment},e.hasParent=function(e,t=1){let n=he(e).parent;for(;n;){if(0==--t)return!0;n=n.parent}return!1},e.hasParentOfType=function(e,t){let n=he(e).parent;for(;n;){if(t.is(n.storedValue))return!0;n=n.parent}return!1},e.isActionContextChildOf=function(e,t){return Z(e,t,!1)},e.isActionContextThisOrChildOf=function(e,t){return Z(e,t,!0)},e.isAlive=b,e.isArrayType=function(e){return N(e)&&(e.flags&O.Array)>0},e.isFrozenType=function(e){return N(e)&&(e.flags&O.Frozen)>0},e.isIdentifierType=function(e){return N(e)&&(e.flags&O.Identifier)>0},e.isLateType=function(e){return N(e)&&(e.flags&O.Late)>0},e.isLiteralType=function(e){return N(e)&&(e.flags&O.Literal)>0},e.isMapType=function(e){return N(e)&&(e.flags&O.Map)>0},e.isModelType=at,e.isOptionalType=function(e){return N(e)&&(e.flags&O.Optional)>0},e.isPrimitiveType=wt,e.isProtected=function(e){return he(e).isProtected},e.isReferenceType=function(e){return N(e)&&(e.flags&O.Reference)>0},e.isRefinementType=function(e){return N(e)&&(e.flags&O.Refinement)>0},e.isRoot=function(e){return he(e).isRoot},e.isStateTreeNode=ue,e.isType=N,e.isUnionType=It,e.isValidReference=function(e,t=!0){try{const n=e();if(null==n)return!1;if(ue(n))return!t||b(n);throw new Se("The reference to be checked is not one of node, null or undefined")}catch(e){if(e instanceof zt)return!1;throw e}},e.joinJsonPath=Be,e.onAction=k,e.onPatch=o,e.onSnapshot=function(e,t){return he(e).onSnapshot(t)},e.process=function(e){return Re(),Fe(e)},e.protect=function(e){const t=he(e);if(!t.isRoot)throw new Se("`protect` can only be invoked on root nodes");t.isProtectionEnabled=!0},e.recordActions=function(e,t){const n=[],i=e=>{(!t||t(e,G()))&&n.push(e)};let r;const s={actions:n,get recording(){return!!r},stop(){r&&(r(),r=void 0)},resume(){r||(r=k(e,i))},replay(e){$(e,n)}};return s.resume(),s},e.recordPatches=function(e,t){const n={patches:[],inversePatches:[]},i={};let r;const s={get recording(){return!!r},get patches(){return i.patches||(i.patches=n.patches.slice()),i.patches},get reversedInversePatches(){return i.reversedInversePatches||(i.reversedInversePatches=n.inversePatches.slice().reverse()),i.reversedInversePatches},get inversePatches(){return i.inversePatches||(i.inversePatches=n.inversePatches.slice()),i.inversePatches},stop(){r&&(r(),r=void 0)},resume(){r||(r=o(e,(e,r)=>{t&&!t(e,r,G())||(n.patches.push(e),n.inversePatches.push(r),i.patches=void 0,i.inversePatches=void 0,i.reversedInversePatches=void 0)}))},replay(t){l(t||e,n.patches)},undo(t){l(t||e,n.inversePatches.slice().reverse())}};return s.resume(),s},e.resolveIdentifier=function(e,t,n){const i=he(t).root.identifierCache.resolve(e,Zt(n));return null==i?void 0:i.value},e.resolvePath=function(e,t){const n=ye(he(e),t);return n?n.value:void 0},e.setErrorFormatting=function(e){Y=Object.assign(Object.assign({},Y),e)},e.setLivelinessChecking=i,e.setLivelynessChecking=function(e){i(e)},e.splitJsonPath=We,e.t=qt,e.toGenerator=function*(e){return yield e},e.toGeneratorFunction=function(e){return function*(...t){return yield e(...t)}},e.tryReference=function(e,t=!0){try{const n=e();if(null==n)return;if(ue(n))return t?b(n)?n:void 0:n;throw new Se("The reference to be checked is not one of node, null or undefined")}catch(e){if(e instanceof zt)return;throw e}},e.tryResolve=f,e.typecheck=re,e.types=qt,e.unescapeJsonPath=Ue,e.unprotect=function(e){const t=he(e);if(!t.isRoot)throw new Se("`unprotect` can only be invoked on root nodes");t.isProtectionEnabled=!1},e.walk=function e(t,n){const i=he(t);i.getChildren().forEach(t=>{ue(t.storedValue)&&e(t.storedValue,n)}),n(i.storedValue)},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ISimpleType } from "../../internal";
|
|
2
2
|
/** @hidden */
|
|
3
|
-
export type UnionStringArray<T extends readonly string[]> = T[number];
|
|
4
|
-
export declare function enumeration<T extends string>(options: readonly T[]): ISimpleType<UnionStringArray<T[]>>;
|
|
5
|
-
export declare function enumeration<T extends string>(name: string, options: readonly T[]): ISimpleType<UnionStringArray<T[]>>;
|
|
3
|
+
export type UnionStringArray<T extends readonly (string | number)[]> = T[number];
|
|
4
|
+
export declare function enumeration<T extends string | number>(options: readonly T[]): ISimpleType<UnionStringArray<T[]>>;
|
|
5
|
+
export declare function enumeration<T extends string | number>(name: string, options: readonly T[]): ISimpleType<UnionStringArray<T[]>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-state-tree",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "Opinionated, transactional, MobX powered state container",
|
|
5
5
|
"main": "dist/mobx-state-tree.js",
|
|
6
6
|
"umd:main": "dist/mobx-state-tree.umd.js",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"cpr": "^3.0.1",
|
|
65
65
|
"husky": "^7.0.0",
|
|
66
66
|
"lint-staged": "^11.1.2",
|
|
67
|
-
"mobx": "^
|
|
67
|
+
"mobx": "^7.0.3",
|
|
68
68
|
"prettier": "3.4.1",
|
|
69
69
|
"rollup": "^2.18.1",
|
|
70
70
|
"rollup-plugin-commonjs": "^10.0.0",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"yarn-deduplicate": "^3.1.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
|
-
"mobx": "^
|
|
87
|
+
"mobx": "^7.0.0"
|
|
88
88
|
},
|
|
89
89
|
"keywords": [
|
|
90
90
|
"mobx",
|