UNPKG

mobx-state-tree

Version:

Opinionated, transactional, MobX powered state container

2 lines 82.4 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("mobx");let t="warn";function n(e){t=e}function i(){return t}var r;function s(e){return ue(e).type}function a(e,t){return ue(e).onPatch(t)}function o(e,t){ue(e).applyPatches(Ie(t))}function l(e,t){return ue(e).applySnapshot(t)}function c(e,t=!0){const n=ue(e);return t?n.snapshot:n.type.getSnapshot(n,!1)}function u(e){return ue(e).root.storedValue}function h(e){return ue(e).path}function p(e){return ue(e).identifier}function d(e,t){const n=be(ue(e),t,!1);if(void 0!==n)try{return n.value}catch(e){return}}function f(e){return ue(e).observableIsAlive}function b(e){let t;return t=ce(e)?s(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"}(r||(r={}));class y{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 Ve),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:le.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(t){return t&&(this.pathAtom||(this.pathAtom=e.createAtom("path")),this.pathAtom.reportObserved()),this.parent?(void 0===this._escapedSubpath&&(this._escapedSubpath=this._subpath?Le(this._subpath):""),this.parent.getEscapedPath(t)+"/"+this._escapedSubpath):""}get isRoot(){return null===this.parent}get isAlive(){return this.state!==le.DEAD}get isDetaching(){return this.state===le.DETACHING}get observableIsAlive(){return this.aliveAtom||(this.aliveAtom=e.createAtom("alive")),this.aliveAtom.reportObserved(),this.isAlive}baseFinalizeCreation(e){if(this.state===le.CREATED){if(this.parent){if(this.parent.state!==le.FINALIZED)return;this.fireHook(r.afterAttach)}this.state=le.FINALIZED,e&&e()}}baseFinalizeDeath(){this._hookSubscribers&&this._hookSubscribers.clearAll(),this._subpathUponDeath=this._subpath,this._pathUponDeath=this.getEscapedPath(!1),this.baseSetParent(null,""),this.state=le.DEAD}baseAboutToDie(){this.fireHook(r.beforeDestroy)}}class g extends y{constructor(e,t,n,i,r){super(e,t,n,i);try{this.storedValue=e.createNewInstance(r)}catch(e){throw this.state=le.DEAD,e}this.state=le.CREATED,this.finalizeCreation()}get root(){if(!this.parent)throw new _e("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!==le.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}finalizeCreation(){this.baseFinalizeCreation()}aboutToDie(){this.baseAboutToDie()}finalizeDeath(){this.baseFinalizeDeath()}fireHook(e){this.fireInternalHook(e)}}g.prototype.die=e.action(g.prototype.die);let v=1;var m,w;!function(e){e[e.UNINITIALIZED=0]="UNINITIALIZED",e[e.CREATING=1]="CREATING",e[e.CREATED=2]="CREATED"}(m||(m={})),function(e){e.Dispose="dispose",e.Patch="patch",e.Snapshot="snapshot"}(w||(w={}));const P={onError(e){throw e}};class _ extends y{applyPatches(e){this.createObservableInstanceIfNeeded(),this._applyPatches(e)}applySnapshot(e){this.createObservableInstanceIfNeeded(),this._applySnapshot(e)}constructor(t,n,i,r,s){if(super(t,n,i,r),Object.defineProperty(this,"nodeId",{enumerable:!0,configurable:!0,writable:!0,value:++v}),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:m.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=e.computed(()=>this.getSnapshot()),this.unbox=this.unbox.bind(this),this._initialSnapshot=s,this.identifierAttribute=t.identifierAttribute,n||(this.identifierCache=new se),this._childNodes=t.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 _e(`Instance identifier '${this.identifierAttribute}' for type '${this.type.name}' must be a string, a number or a bigint`);this.identifier=Gt(e),this.unnormalizedIdentifier=e}n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this)}createObservableInstanceIfNeeded(e=!0){this._observableInstanceState===m.UNINITIALIZED&&this.createObservableInstance(e)}createObservableInstance(e=!0){this._observableInstanceState=m.CREATING;const t=[];let n=this.parent;for(;n&&n._observableInstanceState===m.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=le.DEAD,e}finally{this._isRunningAction=!1}if(this._observableInstanceState=m.CREATED,this._snapshotComputed.trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this._childNodes=we,this.state=le.CREATED,e){this.fireHook(r.afterCreate),this.finalizeCreation();for(const e of t.reverse())e.fireHook(r.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(r.beforeDetach);const e=this.state;this.state=le.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(r.afterAttach)):i&&this.baseSetParent(this.parent,t))}fireHook(t){this.fireInternalHook(t);const n=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof n&&(e._allowStateChangesInsideComputed?e._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===m.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=i();if(!this.isAlive&&"ignore"!==t){const i=this._getAssertAliveError(e);switch(t){case"error":throw new _e(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&&Le(e.subpath)||"";let i=e.actionContext||z();i&&"action"!==i.type&&i.parentActionEvent&&(i=i.parentActionEvent);let r="";if(i&&null!=i.name){r=`${i&&i.context&&h(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===m.CREATED?this.type.getChildNode(this,e):this._childNodes[e]}finally{this._autoUnbox=!0}}getChildren(){this.assertAlive(we),this._autoUnbox=!1;try{return this._observableInstanceState===m.CREATED?this.type.getChildren(this):ge(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 _e(`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(r.afterCreationFinalization)})}detach(){if(!this.isAlive)throw new _e("Error while detaching, node is not alive.");this.clearParent()}preboot(){const e=this;this._applyPatches=H(this.storedValue,"@APPLY_PATCHES",t=>{t.forEach(t=>{if(!t.path)return void e.type.applySnapshot(e,t.value);const n=Be(t.path);ye(e,n.slice(0,-1)).applyPatchLocally(n[n.length-1],t)})}),this._applySnapshot=H(this.storedValue,"@APPLY_SNAPSHOT",t=>{if(t!==e.snapshot)return e.type.applySnapshot(e,t)}),Ee(this.storedValue,"$treenode",this),Ee(this.storedValue,"toJSON",pe)}die(){this.isAlive&&this.state!==le.DETACHING&&(this.aboutToDie(),this.finalizeDeath())}aboutToDie(){this._observableInstanceState!==m.UNINITIALIZED&&(this.getChildren().forEach(e=>{e.aboutToDie()}),this.baseAboutToDie(),this._internalEventsEmit(w.Dispose),this._internalEventsClear(w.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(w.Snapshot,e)}emitSnapshot(e){this._internalEventsEmit(w.Snapshot,e)}onPatch(e){return this._internalEventsRegister(w.Patch,e)}hasPatchSubscribers(){return!!this._internalEventsHasSubscribers(w.Patch)||!!this.parent&&this.parent.hasPatchSubscribers()}emitPatch(e,t){if(this._internalEventsHasSubscribers(w.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 _e("Patches without `oldValue` field cannot be inversed");return[Fe(e),Me(e)]}(n);this._internalEventsEmit(w.Patch,i,r)}this.parent&&this.parent.emitPatch(e,t)}hasDisposer(e){return this._internalEventsHas(w.Dispose,e)}addDisposer(e){if(this.hasDisposer(e))throw new _e("cannot add a disposer when it is already registered for execution");this._internalEventsRegister(w.Dispose,e,!0)}removeDisposer(e){if(!this._internalEventsHas(w.Dispose,e))throw new _e("cannot remove a disposer which was never registered for execution");this._internalEventsUnregister(w.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 t=e.reaction(()=>this.snapshot,e=>this.emitSnapshot(e),P);this.addDisposer(t),this._hasSnapshotReaction=!0}}_internalEventsHasSubscribers(e){return!!this._internalEvents&&this._internalEvents.hasSubscribers(e)}_internalEventsRegister(e,t,n=!1){return this._internalEvents||(this._internalEvents=new Ve),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 S,A;_.prototype.createObservableInstance=e.action(_.prototype.createObservableInstance),_.prototype.detach=e.action(_.prototype.detach),_.prototype.die=e.action(_.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"}(A||(A={}));const O=Symbol("$type");class I{constructor(e){Object.defineProperty(this,S,{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 ne(this,e),this.instantiate(null,"",t,e).value}getSnapshot(e,t){throw new _e("unimplemented method")}isAssignableFrom(e){return e===this}validate(e,t){if(he(e)){const n=s(e);return this.isAssignableFrom(n)?X():ee(t,e)}return this.isValidSnapshot(e,t)}is(e){return 0===this.validate(e,[{path:"",type:this}]).length}get Type(){throw new _e("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 _e("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 _e("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 _e("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`")}}S=O,I.prototype.create=e.action(I.prototype.create);class j extends I{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===Gt(t[e.identifierAttribute])}tryToReconcileNode(e,t){return!e.isDetaching&&(e.snapshot===t||(!(!ce(t)||ue(t)!==e)||!(e.type!==this||!xe(t)||ce(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(),ce(t)&&this.isAssignableFrom(s(t))){const e=ue(t);return e.setParent(n,i),e}return this.instantiate(n,i,void 0,t)}getSubTypes(){return null}}j.prototype.create=e.action(j.prototype.create);class x extends I{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 T(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=A.Optional|A.Late,n=A.Refinement|A.SnapshotProcessor|A.Union;return(e.flags&t)>0&&0==(e.flags&n)}(t))return t;return e(n)}(e);return t instanceof _&&i===r&&i instanceof j&&xe(n)&&!ce(n)&&i.isMatchingSnapshotId(t,n)}function C(e){return"object"==typeof e&&e&&!0===e.isType}const E=new Map;class N{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 V(e){return{$MST_UNSERIALIZABLE:!0,type:e}}function D(t,n){e.runInAction(()=>{Ie(n).forEach(e=>function(e,t){const n=d(e,t.path||"");if(!n)throw new _e("Invalid action path: "+(t.path||""));const i=ue(n);if("@APPLY_PATCHES"===t.name)return o.call(null,n,t.args[0]);if("@APPLY_SNAPSHOT"===t.name)return l.call(null,n,t.args[0]);if("function"!=typeof n[t.name])throw new _e(`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}):[])}(t,e))})}function $(e,t,n=!1){return U(e,(function(i,r){if("action"===i.type&&i.id===i.rootId){const a=ue(i.context),o={name:i.name,path:fe(ue(e),a),args:i.args.map((e,t)=>function(e,t,n,i){if(i instanceof Date)return{$MST_DATE:i.getTime()};if(Te(i))return i;if(ce(i))return V(`[MSTNode: ${s(i).name}]`);if("function"==typeof i)return V("[function]");if("object"==typeof i&&!je(i)&&!Oe(i))return V(`[object ${i&&i.constructor&&i.constructor.name||"Complex Object"}]`);try{return JSON.stringify(i),i}catch(e){return V(""+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 k,R=1;function z(){return k}function F(){return R++}function M(t,n){const i=ue(t.context);"action"===t.type&&i.assertAlive({actionContext:t});const s=i._isRunningAction;i._isRunningAction=!0;const a=k,o=!a;k=t;try{return function(t,n,i,s){function a(n,i){const r=()=>{let e,r;try{e=i.apply(null,n.args)}catch(e){r=e}if(s||!n.parentActionEvent)try{t.root.flushEndOfActionCallbacks()}catch(e){r||(r=e)}if(r)throw r;return e};return n.name?e.action(n.name,r)():e.action(r)()}const o=new B(t,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&&r[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||!s&&t.parentActionEvent?l:a(t,()=>l)}(n)}(i,t,n,o)}finally{k=a,i._isRunningAction=s}}function L(e){if(e)return"action"===e.type?e:e.parentActionEvent}function H(e,t,n){const i=function(){const i=F(),r=k,s=L(r);return M({type:"action",name:t,id:i,args:De(arguments),context:e,tree:u(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 U(e,t,n=!0){return ue(e).addMiddleWare(t,n)}class B{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 W(){let e=z();for(;e&&"action"!==e.type;)e=e.parentActionEvent;return e}function G(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 Z=Object.assign({},{enabled:!1,indent:2,maxStringLength:100,maxArrayLength:10,maxPropertyCount:30,maxDepth:5});function Y(){return Object.assign({},Z)}function J(e,t){try{return JSON.stringify(e,null,t)}catch(e){return`<Unserializable: ${e}>`}}function q(e){if("function"==typeof e)return`<function${e.name?" "+e.name:""}>`;if(ce(e))return`<${e}>`;const t=Y();if(!t.enabled)return`\`${J(e)}\``;return`\`${J(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(je(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 K(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=ce(t)?`value of type ${ue(t).type.name}:`:Te(t)?"value":"snapshot",a=n&&ce(t)&&n.is(ue(t).snapshot),o=Y();return`${r}${s} ${q(t)} is not assignable ${n?`to type: \`${n.name}\``:""}`+(e.message?` (${e.message})`:"")+(n?mt(n)||Te(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 Q(e,t,n){return e.concat([{path:t,type:n}])}function X(){return me}function ee(e,t,n){return[{context:e,value:t,message:n}]}function te(e){return e.reduce((e,t)=>e.concat(t),[])}function ne(e,t){"undefined"!=typeof process&&process.env&&"true"===process.env.ENABLE_TYPE_CHECK&&ie(e,t)}function ie(e,t){const n=e.validate(t,[{path:"",type:e}]);if(n.length>0)throw new _e(function(e,t,n){if(0===n.length)return;const i=q(t);return`Error while converting ${Y().enabled?i:(r=i,r.length<280?r:`${r.substring(0,272)}......${r.substring(r.length-8)}`)} to \`${e.name}\`:\n\n    `+n.map(K).join("\n    ");var r}(e,t,n))}let re=0;class se{constructor(){Object.defineProperty(this,"cacheId",{enumerable:!0,configurable:!0,writable:!0,value:re++}),Object.defineProperty(this,"cache",{enumerable:!0,configurable:!0,writable:!0,value:e.observable.map()}),Object.defineProperty(this,"lastCacheModificationPerId",{enumerable:!0,configurable:!0,writable:!0,value:e.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(t,n=!0){if(t.identifierAttribute){const i=t.identifier;this.cache.has(i)||this.cache.set(i,e.observable.array([],Pe));const r=this.cache.get(i);if(-1!==r.indexOf(t))throw new _e("Already registered");r.push(t),n&&this.updateLastCacheModificationPerId(i)}}mergeCache(t){e.values(t.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(t){const n=new se,i=t.path+"/";return e.entries(this.cache).forEach(([e,r])=>{let s=!1;for(let a=r.length-1;a>=0;a--){const o=r[a];o!==t&&0!==o.path.indexOf(i)||(n.addNodeToCache(o,!1),r.splice(a,1),r.length||this.cache.delete(e),s=!0)}s&&this.updateLastCacheModificationPerId(e)}),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 _e(`Cannot resolve a reference to type '${e.name}' with id: '${t}' unambigously, there are multiple candidates: ${i.map(e=>e.path).join(", ")}`)}}}function ae(e,t,n,i,r){const s=he(r);if(s){if(s.parent)throw new _e(`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 _(e,t,n,i,r)}function oe(e,t,n,i,r){return new g(e,t,n,i,r)}var le;function ce(e){return!(!e||!e.$treenode)}function ue(e){if(!ce(e))throw new _e(`Value ${e} is no MST Node`);return e.$treenode}function he(e){return e&&e.$treenode||null}function pe(){return ue(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"}(le||(le={}));const de=e=>"..";function fe(e,t){if(e.root!==t.root)throw new _e(`Cannot calculate relative path: objects '${e}' and '${t}' are not part of the same object tree`);const n=Be(e.path),i=Be(t.path);let r=0;for(;r<n.length&&n[r]===i[r];r++);return n.slice(r).map(de).join("/")+Ue(i.slice(r))}function be(e,t,n=!0){return ye(e,Be(t),n)}function ye(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 g){const e=i.value;ce(e)&&(i=ue(e))}if(i instanceof _){if(i.getChildType(n)&&(i=i.getChildNode(n),i))continue}}}throw new _e(`Could not resolve '${n}' in path '${Ue(t.slice(0,e))||"/"}' while resolving '${Ue(t)}'`)}}catch(e){if(!n)return;throw e}return i}function ge(e){if(!e)return me;const t=Object.keys(e);if(!t.length)return me;const n=new Array(t.length);return t.forEach((t,i)=>{n[i]=e[t]}),n}const ve=Object.toString(),me=Object.freeze([]),we=Object.freeze({}),Pe={deep:!1};Object.freeze(Pe);class _e extends Error{constructor(e="Illegal state"){super("[mobx-state-tree] "+e)}}function Se(e){return e}const Ae=Number.isInteger;function Oe(t){return Array.isArray(t)||e.isObservableArray(t)}function Ie(e){return e?Oe(e)?e:[e]:me}function je(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())===ve}function xe(e){return!(null===e||"object"!=typeof e||e instanceof Date||e instanceof RegExp)}function Te(e,t=!0){return null==e||"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"bigint"==typeof e||t&&e instanceof Date}function Ce(e){return"function"!=typeof e}function Ee(t,n,i){!function(t,n,i){e.isObservableObject(t)?e.defineProperty(t,n,i):Object.defineProperty(t,n,i)}(t,n,{enumerable:!1,writable:!1,configurable:!0,value:i})}class Ne{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 Ve{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 Ne),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 De(e){const t=new Array(e.length);for(let n=0;n<e.length;n++)t[n]=e[n];return t}function $e(e,t){return 0===e.indexOf(t)}const ke=function(e,t){};function Re(e){"function"==typeof queueMicrotask?queueMicrotask(e):"function"==typeof setImmediate?setImmediate(e):setTimeout(e,1)}function ze(e){return function(e,t){const n=function(){const i=F(),r=z();if(!r)throw new _e("a mst flow must always have a parent context");const s=L(r);if(!s)throw new _e("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,M(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 Re(()=>{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 Re(()=>{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 _e("Only promises can be yielded to `async`, got: "+t);return t.value.then(c,u)}Re(()=>{l(t=>{e(t)},"flow_return",t.value)})}s.$mst_middleware=n.$mst_middleware,M(Object.assign(Object.assign({},a),{type:"flow_spawn",args:De(o)}),s)}))};return n._isFlowAction=!0,n}(e.name,e)}function Fe(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 Me(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 Le(e){return!0==("number"==typeof e)?""+e:-1===e.indexOf("/")&&-1===e.indexOf("~")?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function He(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Ue(e){if(0===e.length)return"";const t=e=>e.map(Le).join("/");return"."===e[0]||".."===e[0]?t(e):"/"+t(e)}function Be(e){const t=e.split("/").map(He);if(!(""===e||"."===e||".."===e||$e(e,"/")||$e(e,"./")||$e(e,"../")))throw new _e(`a json path must be either rooted, empty or relative, but got '${e}'`);return""===t[0]&&t.shift(),t}ke.ids={};const We=Symbol("$preProcessorFailed");class Ge extends I{get flags(){return this._subtype.flags|A.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 We}}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 _&&(e.hasSnapshotPostProcessor=!!this._processors.postProcessor);const t=e.getSnapshot;e.getSnapshot=()=>this.postProcessSnapshot(t.call(e),e),Ot(this._subtype)||(e.getReconciliationType=()=>this)}instantiate(e,t,n,i){const r=ce(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,ce(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===We?ee(t,e,"Failed to preprocess value"):this._subtype.validate(n,t)}getSubTypes(){return this._subtype}is(e){const t=C(e)?this._subtype:ce(e)?e:this.preProcessSnapshotSafe(e);return t!==We&&0===this._subtype.validate(t,[{path:"",type:this._subtype}]).length}isAssignableFrom(e){return this._subtype.isAssignableFrom(e)}isMatchingSnapshotId(e,t){if(!(this._subtype instanceof j))return!1;const n=this.preProcessSnapshot(t);return this._subtype.isMatchingSnapshotId(e,n)}}const Ze="Map.put can only be used to store complex values that have an identifier type attribute";var Ye;!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.YES=1]="YES",e[e.NO=2]="NO"}(Ye||(Ye={}));class Je extends e.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 _e("Map.put cannot be used to set empty values");if(ce(e)){const t=ue(e);if(null===t.identifier)throw new _e(Ze);return this.set(t.identifier,e),e}if(xe(e)){const t=ue(this),n=t.type;if(n.identifierMode!==Ye.YES)throw new _e(Ze);const i=e[n.mapIdentifierAttribute];if(!Zt(i)){const i=this.put(n.getChildType().create(e,t.environment));return this.put(c(i))}const r=Gt(i);return this.set(r,e),this.get(r)}throw new _e("Map.put can only be used to store complex values")}}class qe extends j{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:Ye.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:A.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 qe(this.name,this._subType,t)}instantiate(e,t,n,i){return this._determineIdentifierMode(),ae(this,e,t,n,i)}_determineIdentifierMode(){if(this.identifierMode!==Ye.UNKNOWN)return;const e=[];if(function e(t,n){const i=t.getSubTypes();if("cannotDetermine"===i)return!1;if(i){const t=Ie(i);for(const i of t)if(!e(i,n))return!1}return t instanceof rt&&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 _e(`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=Ye.YES,this.mapIdentifierAttribute=t):this.identifierMode=Ye.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 Je(e,this.name)}finalizeNewInstance(t,n){e._interceptReads(n,t.unbox);t.type.hookInitializers.forEach(e=>{const t=e(n);Object.keys(t).forEach(e=>{const i=t[e],r=H(n,e,i);Ee(n,e,r)})}),e.intercept(n,this.willChange),e.observe(n,this.didChange)}describe(){return this.name}getChildren(t){return e.values(t.storedValue)}getChildNode(e,t){const n=e.storedValue.get(""+t);if(!n)throw new _e("Not a child "+t);return n}willChange(e){const t=ue(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;ne(r,s),e.newValue=r.reconcile(t.getChildNode(n),e.newValue,t,n),i.processIdentifier(n,e.newValue)}break;case"add":ne(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===Ye.YES&&t instanceof _){const n=t.identifier;if(n!==e)throw new _e(`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=ue(e.object);switch(e.type){case"update":return void t.emitPatch({op:"replace",path:Le(e.name),value:e.newValue.snapshot,oldValue:e.oldValue?e.oldValue.snapshot:void 0},t);case"add":return void t.emitPatch({op:"add",path:Le(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:Le(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(!je(t))return void ne(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&&(T(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 je(e)?te(Object.keys(e).map(n=>this._subType.validate(e[n],Q(t,n,this._subType)))):ee(t,e,"Value is not a plain object")}getDefaultSnapshot(){return we}removeChild(e,t){e.storedValue.delete(t)}}qe.prototype.applySnapshot=e.action(qe.prototype.applySnapshot);class Ke extends j{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:A.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 Ke(this.name,this._subType,t)}instantiate(e,t,n,i){return ae(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(t){const n=Object.assign(Object.assign({},Pe),{name:this.name});return e.observable.array(ge(t),n)}finalizeNewInstance(t,n){e._getAdministration(n).dehancer=t.unbox;t.type.hookInitializers.forEach(e=>{const t=e(n);Object.keys(t).forEach(e=>{const i=t[e],r=H(n,e,i);Ee(n,e,r)})}),e.intercept(n,this.willChange),e.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 _e("Not a child: "+t)}willChange(e){const t=ue(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=Qe(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=Qe(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=ue(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(!Oe(t))return void ne(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(!T(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 Oe(e)?te(e.map((e,n)=>this._subType.validate(e,Q(t,""+n,this._subType)))):ee(t,e,"Value is not an array")}getDefaultSnapshot(){return me}removeChild(e,t){e.storedValue.splice(Number(t),1)}}function Qe(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 g||a instanceof _)&&(u=u.storedValue),!c&&!l)break;if(l)if(c)if(et(c,u))n[o]=Xe(t,e,h,u,c);else{let i=void 0;for(let e=o;e<n.length;e++)if(et(n[e],u)){i=n.splice(e,1)[0];break}s=!1;const r=Xe(t,e,h,u,i);n.splice(o,0,r)}else{if(ce(u)&&ue(u).parent===e)throw new _e(`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 '${ue(u).path}'`);s=!1;const i=Xe(t,e,h,u);n.splice(o,0,i)}else s=!1,n.splice(o,1),c instanceof _&&c.createObservableInstanceIfNeeded(),c.die(),o--}var a;return s?null:n}function Xe(e,t,n,i,r){ne(e,i);const s=function(){if(ce(i)){const e=ue(i);if(e.assertAlive(we),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 _&&r.createObservableInstanceIfNeeded(),r.die()),s}function et(e,t){if(!e.isAlive)return!1;if(ce(t)){const n=ue(t);return n.isAlive&&n===e}if(e.snapshot===t)return!0;if(!(e instanceof _))return!1;const n=e.getReconciliationType();return null!==e.identifier&&e.identifierAttribute&&je(t)&&n.is(t)&&n.isMatchingSnapshotId(e,t)}Ke.prototype.applySnapshot=e.action(Ke.prototype.applySnapshot),"function"==typeof SuppressedError&&SuppressedError;function tt(){return ue(this).toString()}const nt={name:"AnonymousModel",properties:{},initializers:me};function it(e){const t=Object.keys(e),n=new Set;return t.forEach(e=>{if(n.has(e))throw new _e(e+" is declared twice in the model. Model should not contain the same keys");n.add(e)}),t.reduce((t,n)=>{if(n in r)throw new _e(`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 _e("Getters are not supported as properties. Please use views instead");const s=i.value;if(null==s)throw new _e("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");if(Te(s))t[n]=jt(function(e){switch(typeof e){case"string":return ot;case"number":return lt;case"boolean":return ft;case"bigint":return dt;case"object":if(e instanceof Date)return vt}throw new _e("Cannot determine primitive type from value "+e)}(s),s);else if(s instanceof qe)t[n]=jt(s,{});else if(s instanceof Ke)t[n]=jt(s,[]);else if(!C(s))throw new _e(`Invalid type definition for property '${n}', cannot infer a type from a value like '${s}' (${typeof s})`);return t},Object.assign({},e))}class rt extends j{constructor(e){super(e.name||nt.name),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:A.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,nt,e),this.properties=it(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&A.Identifier){if(e)throw new _e(`Cannot define property '${t}' as object identifier, property '${e}' is already defined as identifier property`);e=t}}),e}cloneAndEnhance(e){return new rt({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(!je(t))throw new _e("actions initializer should return a plain object containing actions");Object.getOwnPropertyNames(t).forEach(n=>{if(n in this.properties)throw new _e(`'${n}' is a property and cannot be declared as an action`);if("preProcessSnapshot"===n)throw new _e("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");if("postProcessSnapshot"===n)throw new _e("Cannot define action 'postProcessSnapshot', it should be defined using 'type.postProcessSnapshot(fn)' instead");let i=t[n],s=e[n];if(n in r&&s){let e=i;i=function(){s.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=H(e,n,o);t[n]=l,Ee(e,n,l)})}volatile(e){if("function"!=typeof e)throw new _e(`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(t,n){if(!je(n))throw new _e("volatile state initializer should return a plain object containing state");Object.getOwnPropertyNames(n).forEach(i=>{if(i in this.properties)throw new _e(`'${i}' is a property and cannot be declared as volatile state`);e.set(t,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 _e(`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(t,n){if(!je(n))throw new _e("views initializer should return a plain object containing views");Object.getOwnPropertyNames(n).forEach(i=>{if(i in this.properties)throw new _e(`'${i}' is a property and cannot be declared as a view`);const r=Object.getOwnPropertyDescriptor(n,i);if("get"in r)e.defineProperty(t,i,r),e.makeObservable(t,{[i]:e.computed});else{if("function"!=typeof r.value)throw new _e("A view member should either be a function or getter based property");Ee(t,i,r.value)}})}instantiate(e,t,n,i){return ae(this,e,t,n,ce(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(t){const n=Object.assign(Object.assign({},Pe),{name:this.name});return e.observable.object(t,we,n)}finalizeNewInstance(t,n){Ee(n,"toString",tt),this.forAllProps(i=>{e._interceptReads(n,i,t.unbox)}),this.initializers.reduce((e,t)=>t(e),n),e.intercept(n,this.willChange),e.observe(n,this.didChange)}willChange(e){const t=e,n=ue(t.object),i=t.name;n.assertWritable({subpath:i});const r=n.type.properties[i];return r&&(ne(r,t.newValue),t.newValue=r.reconcile(n.getChildNode(i),t.newValue,n,i)),t}didChange(e){const t=e,n=ue(t.object);if(!n.type.properties[t.name])return;const i=t.oldValue?t.oldValue.snapshot:void 0;n.emitPatch({op:"replace",path:Le(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(t,n){var i;if(!(n in this.properties))throw new _e("Not a value property: "+n);const r=e._getAdministration(t.storedValue,n),s=null===(i=r.raw)||void 0===i?void 0:i.call(r);if(!s)throw new _e("Node not available for property "+n);return s}getSnapshot(t,n=!0){const i={};return this.forAllProps((n,r)=>{e.getAtom(t.storedValue,n).reportObserved(),i[n]=this.getChildNode(t,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 _e("object does not support operation "+n.op);e.storedValue[t]=n.value}applySnapshot(e,t){const n=this.applySnapshotPreProcessor(t),i=!je(n);(je(t)&&!i||(ne(this,t),!i))&&this.forAllProps((t,i)=>{const r=e.getChildNode(t),s=n[t];r.snapshot!==s&&(T(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 je(n)?te(this.propertyNames.map(e=>this.properties[e].validate(n[e],Q(t,e,this.properties[e])))):ee(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 we}removeChild(e,t){e.storedValue[t]=void 0}}function st(e){return C(e)&&(e.flags&A.Object)>0}rt.prototype.applySnapshot=e.action(rt.prototype.applySnapshot);class at extends x{constructor(e,t,n,i=Se){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 oe(this,e,t,n,i)}createNewInstance(e){return this.initializer(e)}isValidSnapshot(e,t){if(Te(e)&&this.checker(e))return X();return ee(t,e,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))}}const ot=new at("string",A.String,e=>"string"==typeof e),lt=new at("number",A.Number,e=>"number"==typeof e),ct=new at("integer",A.Integer,e=>Ae(e)),ut=new at("float",A.Float,e=>{return t=e,Number(t)===t&&t%1!=0;var t}),ht=new at("finite",A.Finite,e=>{return t=e,Number.isFinite(t);var t}),pt=new at("bigint",A.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));pt.getSnapshot=function(e){return String(e.storedValue)};const dt=pt,ft=new at("boolean",A.Boolean,e=>"boolean"==typeof e),bt=new at("null",A.Null,e=>null===e),yt=new at("undefined",A.Undefined,e=>void 0===e),gt=new at("Date",A.Date,e=>"number"==typeof e||e instanceof Date,e=>e instanceof Date?e:new Date(e));gt.getSnapshot=function(e){return e.storedValue.getTime()};const vt=gt;function mt(e){return C(e)&&(e.flags&(A.String|A.Number|A.Integer|A.Boolean|A.Date|A.BigInt))>0}class wt extends x{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:A.Literal}),this.value=e}instantiate(e,t,n,i){return oe(this,e,t,n,i)}describe(){return JSON.stringify(this.value)}isValidSnapshot(e,t){return Te(e)&&e===this.value?X():ee(t,e,"Value is not a literal "+JSON.stringify(this.value))}}function Pt(e){return new wt(e)}class _t extends I{get flags(){return this._subtype.flags|A.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=ce(e)?ue(e).snapshot:e;return this._predicate(i)?X():ee(t,e,this._message(e))}reconcile(e,t,n,i){return this._subtype.reconcile(e,t,n,i)}getSubTypes(){return this._subtype}}class St extends I{get flags(){let e=A.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 _e("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 _e("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 X();i++}else n.push(s)}return 1===i?X():ee(t,e,"No type is applicable for the union").concat(te(n))}getSubTypes(){return this._types}}function At(e,...t){const n=C(e)?void 0:e,i=C(e)?[e,...t]:t,r="("+i.map(e=>e.name).join(" | ")+")";return new St(r,i,n)}function Ot(e){return C(e)&&(e.flags&A.Union)>0}class It extends I{get flags(){return this._subtype.flags|A.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&&ne(this,e),e}isValidSnapshot(e,t){return this.optionalValues.indexOf(e)>=0?X():this._subtype.validate(e,t)}isAssignableFrom(e){return this._subtype.isAssignableFrom(e)}getSubTypes(){return this._subtype}}function jt(e,t,n){return function(e,t){if("function"!=typeof t&&ce(t))throw new _e("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead")}(0,t),new It(e,t,n||xt)}const xt=[void 0];const Tt=jt(yt,void 0),Ct=jt(bt,null);function Et(e){return At(e,Tt)}class Nt extends I{get flags(){return(this._subType?this._subType.flags:0)|A.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 _e("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):X()}isAssignableFrom(e){const t=this.getSubType(!1);return!!t&&t.isAssignableFrom(e)}getSubTypes(){const e=this.getSubType(!1);return e||"cannotDetermine"}}class Vt extends x{constructor(t,n){super(t),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:n}),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:A.Lazy}),Object.defineProperty(this,"loadedType",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"pendingNodeList",{enumerable:!0,configurable:!0,writable:!0,value:e.observable.array()}),e.when(()=>this.pendingNodeList.length>0&&this.pendingNodeList.some(e=>e.isAlive&&this.options.shouldLoadPredicate(e.parent?e.parent.value:null)),()=>{this.options.loadType().then(e.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(t,n,i,r){if(this.loadedType)return this.loadedType.instantiate(t,n,i,r);const s=oe(this,t,n,i,r);return this.pendingNodeList.push(s),e.when(()=>!s.isAlive,()=>this.pendingNodeList.splice(this.pendingNodeList.indexOf(s),1)),s}isValidSnapshot(e,t){return this.loadedType?this.loadedType.validate(e,t):Ce(e)?X():ee(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 Dt extends x{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:A.Frozen})}describe(){return"<any immutable value>"}instantiate(e,t,n,i){return oe(this,e,t,n,i)}isValidSnapshot(e,t){return Ce(e)?this.subType?this.subType.validate(e,t):X():ee(t,e,"Value is not serializable and cannot be frozen")}}const $t=new Dt;class kt{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}),Zt(e))this.identifier=e;else{if(!ce(e))throw new _e(`Can only store references to tree nodes or identifiers, got: '${e}'`);{const t=ue(e);if(!t.identifierAttribute)throw new _e("Can only store references with a defined identifier attribute.");const n=t.unnormalizedIdentifier;if(null==n)throw new _e("Can only store references to tree nodes with a defined identifier.");this.identifier=n}}}updateResolvedReference(e){const t=Gt(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 Rt(`[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 Rt extends Error{constructor(e){super(e),Object.setPrototypeOf(this,Rt.prototype)}}class zt extends x{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:A.Reference})}describe(){return this.name}isAssignableFrom(e){return this.targetType.isAssignableFrom(e)}isValidSnapshot(e,t){return Zt(e)?X():ee(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){o(t.root.storedValue,{op:"replace",value:e,path:t.path})},removeRef(){st(r.type)?this.replaceRef(void 0):o(t.root.storedValue,{op:"remove",path:t.path})}})}addTargetNodeWatcher(e,t){const n=this.getValue(e);if(!n)return;const i=ue(n),s=(n,s)=>{const a=function(e){switch(e){case r.beforeDestroy:return"destroy";case r.beforeDetach:return"detach";default:return}}(s);a&&this.fireInvalidated(a,e,t,i)},a=i.registerHook(r.beforeDetach,s),o=i.registerHook(r.beforeDestroy,s);return()=>{a(),o()}}watchTargetNodeForInvalidations(e,t,n){if(!this.onInvalidated)return;let i;e.registerHook(r.beforeDestroy,()=>{i&&i()});const s=()=>{const n=()=>{e.isAlive&&this.getSnapshot(e)===t&&a(!1)};z()?e.root.enqueueEndOfAction(n):Re(n)},a=r=>{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,Gt(t)),a?i=this.addTargetNodeWatcher(e,t):r?s():this.fireInvalidated("invalidSnapshotReference",e,t,null)}};e.state===le.FINALIZED?a(!0):(e.isRoot||e.root.registerHook(r.afterCreationFinalization,()=>{e.parent&&e.parent.createObservableInstanceIfNeeded()}),e.registerHook(r.afterAttach,()=>{a(!1)}))}}class Ft extends zt{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=ce(i)?p(i):i,s=new kt(i,this.targetType),a=oe(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=ce(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 Mt extends zt{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=ce(i)?this.options.set(i,e?e.storedValue:null):i,s=oe(this,e,t,n,r);return this.watchTargetNodeForInvalidations(s,r,this.options),s}reconcile(e,t,n,i){const r=ce(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 Lt(e,t){const n=t||void 0,i=t?t.onInvalidated:void 0;return n&&(n.get||n.set)?new Mt(e,{get:n.get,set:n.set},i):new Ft(e,i)}class Ht extends x{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:A.Identifier})}instantiate(e,t,n,i){if(!(e&&e.type instanceof rt))throw new _e("Identifier types can only be instantiated as direct child of a model type");return oe(this,e,t,n,i)}reconcile(e,t,n,i){if(e.storedValue!==t)throw new _e(`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?ee(t,e,`Value is not a valid ${this.describe()}, expected a ${this.validType}`):X()}}const Ut=new class extends Ht{constructor(){super("identifier","string"),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:A.Identifier})}describe(){return"identifier"}},Bt=new class extends Ht{constructor(){super("identifierNumber","number")}getSnapshot(e){return e.storedValue}describe(){return"identifierNumber"}};const Wt=new class extends x{constructor(){super("identifierBigint"),Object.defineProperty(this,"flags",{enumerable:!0,configurable:!0,writable:!0,value:A.Identifier})}createNewInstance(e){return"bigint"==typeof e?e:BigInt(e)}instantiate(e,t,n,i){if(!(e&&e.type instanceof rt))throw new _e("Identifier types can only be instantiated as direct child of a model type");return oe(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 _e(`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 X();if("string"==typeof e||"number"==typeof e)try{return BigInt(e),X()}catch(n){const i=n instanceof Error?n.message:String(n);return ee(t,e,`Value is not a valid ${this.describe()}: ${i}`)}return ee(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 Gt(e){return""+e}function Zt(e){return"string"==typeof e||"number"==typeof e||"bigint"==typeof e}class Yt extends x{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:A.Custom})}describe(){return this.name}isValidSnapshot(e,t){if(this.options.isTargetType(e))return X();const n=this.options.getValidationMessage(e);return n?ee(t,e,`Invalid value for type '${this.name}': ${n}`):X()}getSnapshot(e){return this.options.toSnapshot(e.storedValue)}instantiate(e,t,n,i){return oe(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 Jt={enumeration:function(e,t){const n=At(...("string"==typeof e?t:e).map(e=>Pt(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 rt({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 Yt(e)},reference:Lt,safeReference:function(e,t){const n=Lt(e,Object.assign(Object.assign({},t),{onInvalidated(e){t&&t.onInvalidated&&t.onInvalidated(e),e.removeRef()}}));return t&&!1===t.acceptsUndefined?n:Et(n)},union:At,optional:jt,literal:Pt,maybe:Et,maybeNull:function(e){return At(e,Ct)},refinement:function(...e){const t="string"==typeof e[0]?e.shift():C(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 _t(t,n,i,r)},string:ot,boolean:ft,number:lt,integer:ct,float:ut,finite:ht,bigint:dt,Date:vt,map:function(e){return new qe(`Map<string, ${e.name}>`,e)},array:function(e){return new Ke(e.name+"[]",e)},frozen:function(e){return 0===arguments.length?$t:C(e)?new Dt(e):jt($t,e)},identifier:Ut,identifierNumber:Bt,identifierBigint:Wt,late:function(e,t){const n="string"==typeof e?e:`late(${e.toString()})`;return new Nt(n,"string"==typeof e?t:e)},lazy:function(e,t){return new Vt(e,t)},undefined:yt,null:bt,snapshotProcessor:function(e,t,n){return new Ge(e,t,n)}};exports.addDisposer=function(e,t){return ue(e).addDisposer(t),t},exports.addMiddleware=U,exports.applyAction=D,exports.applyPatch=o,exports.applySnapshot=l,exports.cast=function(e){return e},exports.castFlowReturn=function(e){return e},exports.castToReferenceSnapshot=function(e){return e},exports.castToSnapshot=function(e){return e},exports.clone=function(e,t=!0){const n=ue(e);return n.type.create(n.snapshot,!0===t?n.root.environment:!1===t?void 0:t)},exports.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),E.set(t.id,{call:t,context:i,async:!1});try{const r=n(t);return e.onSuspend(t,i),!1===E.get(t.id).async&&(E.delete(t.id),e.onSuccess(t,i,r)),r}catch(n){throw E.delete(t.id),e.onFail(t,i,n),n}}case"flow_spawn":return E.get(t.rootId).async=!0,n(t);case"flow_resume":case"flow_resume_error":{const i=E.get(t.rootId);e.onResume(t,i.context);try{return n(t)}finally{e.onSuspend(t,i.context)}}case"flow_throw":{const i=E.get(t.rootId);return E.delete(t.rootId),e.onFail(t,i.context,t.args[0]),n(t)}case"flow_return":{const i=E.get(t.rootId);return E.delete(t.rootId),e.onSuccess(t,i.context,t.args[0]),n(t)}}}},exports.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 N(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())}}}},exports.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},exports.destroy=function(e){const t=ue(e);t.isRoot?t.die():t.parent.removeChild(t.subpath)},exports.detach=function(e){return ue(e).detach(),e},exports.escapeJsonPath=Le,exports.flow=ze,exports.getChildType=function(e,t){return ue(e).getChildType(t)},exports.getEnv=function(e){const t=ue(e),n=t.root.environment;if(!n)throw new _e(`Failed to find the environment of ${t} ${t.path}`);return n},exports.getErrorFormatting=Y,exports.getIdentifier=p,exports.getLivelinessChecking=i,exports.getMembers=function(t){const n=ue(t).type,i=Object.assign(Object.assign({},b(n)),{actions:[],volatile:[],views:[],flowActions:[]});return Object.getOwnPropertyNames(t).forEach(n=>{if(n in i.properties)return;const r=Object.getOwnPropertyDescriptor(t,n);r.get?e.isComputedProp(t,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):e.isObservableProp(t,n)?i.volatile.push(n):i.views.push(n))}),i},exports.getNodeId=function(e){return ue(e).nodeId},exports.getParent=function(e,t=1){let n=t,i=ue(e).parent;for(;i;){if(0==--n)return i.storedValue;i=i.parent}throw new _e(`Failed to find the parent of ${ue(e)} at depth ${t}`)},exports.getParentOfType=function(e,t){let n=ue(e).parent;for(;n;){if(t.is(n.storedValue))return n.storedValue;n=n.parent}throw new _e(`Failed to find the parent of ${ue(e)} of a given type`)},exports.getPath=h,exports.getPathParts=function(e){return Be(ue(e).path)},exports.getPropertyMembers=b,exports.getRelativePath=function(e,t){return fe(ue(e),ue(t))},exports.getRoot=u,exports.getRunningActionContext=W,exports.getSnapshot=c,exports.getType=s,exports.hasEnv=function(e){return!!ue(e).root.environment},exports.hasParent=function(e,t=1){let n=ue(e).parent;for(;n;){if(0==--t)return!0;n=n.parent}return!1},exports.hasParentOfType=function(e,t){let n=ue(e).parent;for(;n;){if(t.is(n.storedValue))return!0;n=n.parent}return!1},exports.isActionContextChildOf=function(e,t){return G(e,t,!1)},exports.isActionContextThisOrChildOf=function(e,t){return G(e,t,!0)},exports.isAlive=f,exports.isArrayType=function(e){return C(e)&&(e.flags&A.Array)>0},exports.isFrozenType=function(e){return C(e)&&(e.flags&A.Frozen)>0},exports.isIdentifierType=function(e){return C(e)&&(e.flags&A.Identifier)>0},exports.isLateType=function(e){return C(e)&&(e.flags&A.Late)>0},exports.isLiteralType=function(e){return C(e)&&(e.flags&A.Literal)>0},exports.isMapType=function(e){return C(e)&&(e.flags&A.Map)>0},exports.isModelType=st,exports.isOptionalType=function(e){return C(e)&&(e.flags&A.Optional)>0},exports.isPrimitiveType=mt,exports.isProtected=function(e){return ue(e).isProtected},exports.isReferenceType=function(e){return C(e)&&(e.flags&A.Reference)>0},exports.isRefinementType=function(e){return C(e)&&(e.flags&A.Refinement)>0},exports.isRoot=function(e){return ue(e).isRoot},exports.isStateTreeNode=ce,exports.isType=C,exports.isUnionType=Ot,exports.isValidReference=function(e,t=!0){try{const n=e();if(null==n)return!1;if(ce(n))return!t||f(n);throw new _e("The reference to be checked is not one of node, null or undefined")}catch(e){if(e instanceof Rt)return!1;throw e}},exports.joinJsonPath=Ue,exports.onAction=$,exports.onPatch=a,exports.onSnapshot=function(e,t){return ue(e).onSnapshot(t)},exports.process=function(e){return ke(),ze(e)},exports.protect=function(e){const t=ue(e);if(!t.isRoot)throw new _e("`protect` can only be invoked on root nodes");t.isProtectionEnabled=!0},exports.recordActions=function(e,t){const n=[],i=e=>{(!t||t(e,W()))&&n.push(e)};let r;const s={actions:n,get recording(){return!!r},stop(){r&&(r(),r=void 0)},resume(){r||(r=$(e,i))},replay(e){D(e,n)}};return s.resume(),s},exports.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=a(e,(e,r)=>{t&&!t(e,r,W())||(n.patches.push(e),n.inversePatches.push(r),i.patches=void 0,i.inversePatches=void 0,i.reversedInversePatches=void 0)}))},replay(t){o(t||e,n.patches)},undo(t){o(t||e,n.inversePatches.slice().reverse())}};return s.resume(),s},exports.resolveIdentifier=function(e,t,n){const i=ue(t).root.identifierCache.resolve(e,Gt(n));return null==i?void 0:i.value},exports.resolvePath=function(e,t){const n=be(ue(e),t);return n?n.value:void 0},exports.setErrorFormatting=function(e){Z=Object.assign(Object.assign({},Z),e)},exports.setLivelinessChecking=n,exports.setLivelynessChecking=function(e){n(e)},exports.splitJsonPath=Be,exports.t=Jt,exports.toGenerator=function*(e){return yield e},exports.toGeneratorFunction=function(e){return function*(...t){return yield e(...t)}},exports.tryReference=function(e,t=!0){try{const n=e();if(null==n)return;if(ce(n))return t?f(n)?n:void 0:n;throw new _e("The reference to be checked is not one of node, null or undefined")}catch(e){if(e instanceof Rt)return;throw e}},exports.tryResolve=d,exports.typecheck=ie,exports.types=Jt,exports.unescapeJsonPath=He,exports.unprotect=function(e){const t=ue(e);if(!t.isRoot)throw new _e("`unprotect` can only be invoked on root nodes");t.isProtectionEnabled=!1},exports.walk=function e(t,n){const i=ue(t);i.getChildren().forEach(t=>{ce(t.storedValue)&&e(t.storedValue,n)}),n(i.storedValue)};