Socket
Socket
Sign inDemoInstall

immer

Package Overview
Dependencies
Maintainers
2
Versions
173
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

immer - npm Package Compare versions

Comparing version 9.0.21 to 10.0.0-beta.1

dist/core/mapset.d.ts

13

dist/core/immerClass.d.ts

@@ -7,7 +7,7 @@ import { IProduceWithPatches, IProduce, ImmerState, Drafted, Patch, Objectish, Draft, PatchListener } from "../internal";

export declare class Immer implements ProducersFns {
useProxies_: boolean;
autoFreeze_: boolean;
useStrictShallowCopy_: boolean;
constructor(config?: {
useProxies?: boolean;
autoFreeze?: boolean;
useStrictShallowCopy?: boolean;
});

@@ -44,12 +44,11 @@ /**

/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
setUseProxies(value: boolean): void;
setUseStrictShallowCopy(value: boolean): void;
applyPatches<T extends Objectish>(base: T, patches: Patch[]): T;
}
export declare function createProxy<T extends Objectish>(immer: Immer, value: T, parent?: ImmerState): Drafted<T, ImmerState>;
export declare function createProxy<T extends Objectish>(value: T, parent?: ImmerState): Drafted<T, ImmerState>;
export {};
//# sourceMappingURL=immerClass.d.ts.map

@@ -1,2 +0,2 @@

import { ImmerBaseState, ImmerState, Drafted, AnyObject, AnyArray, Objectish, ProxyType } from "../internal";
import { ImmerBaseState, ImmerState, Drafted, AnyObject, AnyArray, Objectish, ArchType, ImmerScope } from "../internal";
interface ProxyBaseState extends ImmerBaseState {

@@ -10,3 +10,3 @@ assigned_: {

export interface ProxyObjectState extends ProxyBaseState {
type_: ProxyType.ProxyObject;
type_: ArchType.Object;
base_: any;

@@ -17,3 +17,3 @@ copy_: any;

export interface ProxyArrayState extends ProxyBaseState {
type_: ProxyType.ProxyArray;
type_: ArchType.Array;
base_: AnyArray;

@@ -38,4 +38,5 @@ copy_: AnyArray | null;

copy_: any;
scope_: ImmerScope;
}): void;
export {};
//# sourceMappingURL=proxy.d.ts.map

@@ -5,20 +5,7 @@ 'use strict';

var _ref;
// Should be no imports here!
// Some things that should be evaluated before all else...
// We only want to know if non-polyfilled symbols are available
var hasSymbol = typeof Symbol !== "undefined" && typeof
/*#__PURE__*/
Symbol("x") === "symbol";
var hasMap = typeof Map !== "undefined";
var hasSet = typeof Set !== "undefined";
var hasProxies = typeof Proxy !== "undefined" && typeof Proxy.revocable !== "undefined" && typeof Reflect !== "undefined";
/**
* The sentinel value returned by producers to replace the draft with undefined.
*/
var NOTHING = hasSymbol ?
/*#__PURE__*/
Symbol.for("immer-nothing") : (_ref = {}, _ref["immer-nothing"] = true, _ref);
var NOTHING = /*#__PURE__*/Symbol["for"]("immer-nothing");
/**

@@ -32,60 +19,28 @@ * To let Immer treat your class instances as plain immutable objects

*/
var DRAFTABLE = /*#__PURE__*/Symbol["for"]("immer-draftable");
var DRAFT_STATE = /*#__PURE__*/Symbol["for"]("immer-state");
var DRAFTABLE = hasSymbol ?
/*#__PURE__*/
Symbol.for("immer-draftable") : "__$immer_draftable";
var DRAFT_STATE = hasSymbol ?
/*#__PURE__*/
Symbol.for("immer-state") : "__$immer_state"; // Even a polyfilled Symbol might provide Symbol.iterator
var iteratorSymbol = typeof Symbol != "undefined" && Symbol.iterator || "@@iterator";
var errors = {
0: "Illegal state",
1: "Immer drafts cannot have computed properties",
2: "This object has been frozen and should not be mutated",
3: function _(data) {
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
},
4: "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
5: "Immer forbids circular references",
6: "The first or second argument to `produce` must be a function",
7: "The third argument to `produce` must be a function or undefined",
8: "First argument to `createDraft` must be a plain object, an array, or an immerable object",
9: "First argument to `finishDraft` must be a draft returned by `createDraft`",
10: "The given draft is already finalized",
11: "Object.defineProperty() cannot be used on an Immer draft",
12: "Object.setPrototypeOf() cannot be used on an Immer draft",
13: "Immer only supports deleting array indices",
14: "Immer only supports setting array indices and the 'length' property",
15: function _(path) {
return "Cannot apply patch, path doesn't resolve: " + path;
},
16: 'Sets cannot have "replace" patches.',
17: function _(op) {
return "Unsupported patch operation: " + op;
},
18: function _(plugin) {
return "The plugin for '" + plugin + "' has not been loaded into Immer. To enable the plugin, import and call `enable" + plugin + "()` when initializing your application.";
},
20: "Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",
21: function _(thing) {
return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '" + thing + "'";
},
22: function _(thing) {
return "'current' expects a draft, got: " + thing;
},
23: function _(thing) {
return "'original' expects a draft, got: " + thing;
},
24: "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
};
var errors = [
// All error codes, starting by 0:
function (plugin) {
return "The plugin for '" + plugin + "' has not been loaded into Immer. To enable the plugin, import and call `enable" + plugin + "()` when initializing your application.";
}, function (thing) {
return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '" + thing + "'";
}, "This object has been frozen and should not be mutated", function (data) {
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
}, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.", "Immer forbids circular references", "The first or second argument to `produce` must be a function", "The third argument to `produce` must be a function or undefined", "First argument to `createDraft` must be a plain object, an array, or an immerable object", "First argument to `finishDraft` must be a draft returned by `createDraft`", function (thing) {
return "'current' expects a draft, got: " + thing;
}, "Object.defineProperty() cannot be used on an Immer draft", "Object.setPrototypeOf() cannot be used on an Immer draft", "Immer only supports deleting array indices", "Immer only supports setting array indices and the 'length' property", function (thing) {
return "'original' expects a draft, got: " + thing;
}
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
// See Patches.ts for additional errors
] ;
function die(error) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
{
var e = errors[error];
var msg = !e ? "unknown error nr: " + error : typeof e === "function" ? e.apply(null, args) : e;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var msg = typeof e === "function" ? e.apply(null, args) : e;
throw new Error("[Immer] " + msg);

@@ -95,6 +50,129 @@ }

function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct.bind();
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
/** Returns true if the given value is an Immer draft */
/*#__PURE__*/
function isDraft(value) {

@@ -104,24 +182,16 @@ return !!value && !!value[DRAFT_STATE];

/** Returns true if the given value can be drafted by Immer */
/*#__PURE__*/
function isDraftable(value) {
var _value$constructor;
if (!value) return false;
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor[DRAFTABLE]) || isMap(value) || isSet(value);
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_value$constructor = value.constructor) != null && _value$constructor[DRAFTABLE]) || isMap(value) || isSet(value);
}
var objectCtorString =
var objectCtorString = /*#__PURE__*/Object.prototype.constructor.toString();
/*#__PURE__*/
Object.prototype.constructor.toString();
/*#__PURE__*/
function isPlainObject(value) {
if (!value || typeof value !== "object") return false;
var proto = Object.getPrototypeOf(value);
if (proto === null) {
return true;
}
var Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;

@@ -132,32 +202,13 @@ if (Ctor === Object) return true;

function original(value) {
if (!isDraft(value)) die(23, value);
if (!isDraft(value)) die(15, value);
return value[DRAFT_STATE].base_;
}
/*#__PURE__*/
var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
} :
/* istanbul ignore next */
Object.getOwnPropertyNames;
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors(target) {
// Polyfill needed for Hermes and IE, see https://github.com/facebook/hermes/issues/274
var res = {};
ownKeys(target).forEach(function (key) {
res[key] = Object.getOwnPropertyDescriptor(target, key);
});
return res;
};
function each(obj, iter, enumerableOnly) {
if (enumerableOnly === void 0) {
enumerableOnly = false;
}
if (getArchtype(obj) === 0
/* Object */
) {
(enumerableOnly ? Object.keys : ownKeys)(obj).forEach(function (key) {
if (!enumerableOnly || typeof key !== "symbol") iter(key, obj[key], obj);
});
} else {
function each(obj, iter) {
if (getArchtype(obj) === 0 /* Object */) {
Object.entries(obj).forEach(function (_ref) {
var key = _ref[0],
value = _ref[1];
iter(key, value, obj);
});
} else {
obj.forEach(function (entry, index) {

@@ -169,47 +220,23 @@ return iter(index, entry, obj);

/*#__PURE__*/
function getArchtype(thing) {
/* istanbul ignore next */
var state = thing[DRAFT_STATE];
return state ? state.type_ > 3 ? state.type_ - 4 // cause Object and Array map back from 4 and 5
: state.type_ // others are the same
: Array.isArray(thing) ? 1
/* Array */
: isMap(thing) ? 2
/* Map */
: isSet(thing) ? 3
/* Set */
: 0
/* Object */
;
return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
}
/*#__PURE__*/
function has(thing, prop) {
return getArchtype(thing) === 2
/* Map */
? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
}
/*#__PURE__*/
function get(thing, prop) {
// @ts-ignore
return getArchtype(thing) === 2
/* Map */
? thing.get(prop) : thing[prop];
return getArchtype(thing) === 2 /* Map */ ? thing.get(prop) : thing[prop];
}
/*#__PURE__*/
function set(thing, propOrOldValue, value) {
var t = getArchtype(thing);
if (t === 2
/* Map */
) thing.set(propOrOldValue, value);else if (t === 3
/* Set */
) {
thing.add(value);
} else thing[propOrOldValue] = value;
if (t === 2 /* Map */) thing.set(propOrOldValue, value);else if (t === 3 /* Set */) {
thing.add(value);
} else thing[propOrOldValue] = value;
}
/*#__PURE__*/
function is(x, y) {

@@ -224,13 +251,10 @@ // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js

/*#__PURE__*/
function isMap(target) {
return hasMap && target instanceof Map;
return target instanceof Map;
}
/*#__PURE__*/
function isSet(target) {
return hasSet && target instanceof Set;
return target instanceof Set;
}
/*#__PURE__*/
function latest(state) {

@@ -240,21 +264,30 @@ return state.copy_ || state.base_;

/*#__PURE__*/
function shallowCopy(base) {
function shallowCopy(base, strict) {
if (isMap(base)) {
return new Map(base);
}
if (isSet(base)) {
return new Set(base);
}
if (Array.isArray(base)) return Array.prototype.slice.call(base);
var descriptors = getOwnPropertyDescriptors(base);
if (!strict && isPlainObject(base)) {
if (!Object.getPrototypeOf(base)) {
var obj = Object.create(null);
return Object.assign(obj, base);
}
return _extends({}, base);
}
var descriptors = Object.getOwnPropertyDescriptors(base);
delete descriptors[DRAFT_STATE];
var keys = ownKeys(descriptors);
var keys = Reflect.ownKeys(descriptors);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var desc = descriptors[key];
if (desc.writable === false) {
desc.writable = true;
desc.configurable = true;
} // like object.assign, we will read any _own_, get/set accessors. This helps in dealing
}
// like object.assign, we will read any _own_, get/set accessors. This helps in dealing
// with libraries that trap values, like mobx or vue
// unlike object.assign, non-enumerables will be copied as well
if (desc.get || desc.set) descriptors[key] = {

@@ -267,3 +300,2 @@ configurable: true,

}
return Object.create(Object.getPrototypeOf(base), descriptors);

@@ -275,25 +307,16 @@ }

}
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
if (getArchtype(obj) > 1
/* Map or Set */
) {
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
}
if (getArchtype(obj) > 1 /* Map or Set */) {
obj.set = obj.add = obj.clear = obj["delete"] = dontMutateFrozenCollections;
}
Object.freeze(obj);
if (deep) each(obj, function (key, value) {
if (deep) each(obj, function (_key, value) {
return freeze(value, true);
}, true);
});
return obj;
}
function dontMutateFrozenCollections() {
die(2);
}
function isFrozen(obj) {
if (obj == null || typeof obj !== "object") return true; // See #600, IE dies on non-objects in Object.isFrozen
return Object.isFrozen(obj);

@@ -303,12 +326,9 @@ }

/** Plugin utilities */
var plugins = {};
function getPlugin(pluginKey) {
var plugin = plugins[pluginKey];
if (!plugin) {
die(18, pluginKey);
} // @ts-ignore
die(0, pluginKey);
}
// @ts-ignore
return plugin;

@@ -322,6 +342,4 @@ }

function getCurrentScope() {
if ( !currentScope) die(0);
return currentScope;
}
function createScope(parent_, immer_) {

@@ -338,7 +356,5 @@ return {

}
function usePatchesInScope(scope, patchListener) {
if (patchListener) {
getPlugin("Patches"); // assert we have the plugin
scope.patches_ = [];

@@ -351,4 +367,4 @@ scope.inversePatches_ = [];

leaveScope(scope);
scope.drafts_.forEach(revokeDraft); // @ts-ignore
scope.drafts_.forEach(revokeDraft);
// @ts-ignore
scope.drafts_ = null;

@@ -364,10 +380,5 @@ }

}
function revokeDraft(draft) {
var state = draft[DRAFT_STATE];
if (state.type_ === 0
/* ProxyObject */
|| state.type_ === 1
/* ProxyArray */
) state.revoke_();else state.revoked_ = true;
if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) state.revoke_();else state.revoked_ = true;
}

@@ -379,4 +390,2 @@

var isReplaced = result !== undefined && result !== baseDraft;
if (!scope.immer_.useProxies_) getPlugin("ES5").willFinalizeES5_(scope, result, isReplaced);
if (isReplaced) {

@@ -387,3 +396,2 @@ if (baseDraft[DRAFT_STATE].modified_) {

}
if (isDraftable(result)) {

@@ -394,3 +402,2 @@ // Finalize the result in case it contains (or is) a subset of the draft.

}
if (scope.patches_) {

@@ -403,64 +410,49 @@ getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);

}
revokeScope(scope);
if (scope.patches_) {
scope.patchListener_(scope.patches_, scope.inversePatches_);
}
return result !== NOTHING ? result : undefined;
}
function finalize(rootScope, value, path) {
// Don't recurse in tho recursive data structures
if (isFrozen(value)) return value;
var state = value[DRAFT_STATE]; // A plain object, might need freezing, might contain drafts
var state = value[DRAFT_STATE];
// A plain object, might need freezing, might contain drafts
if (!state) {
each(value, function (key, childValue) {
return finalizeProperty(rootScope, state, value, key, childValue, path);
}, true // See #590, don't recurse into non-enumerable of non drafted objects
);
});
return value;
} // Never finalize drafts owned by another scope.
if (state.scope_ !== rootScope) return value; // Unmodified draft, return the (frozen) original
}
// Never finalize drafts owned by another scope.
if (state.scope_ !== rootScope) return value;
// Unmodified draft, return the (frozen) original
if (!state.modified_) {
maybeFreeze(rootScope, state.base_, true);
return state.base_;
} // Not finalized yet, let's do that now
}
// Not finalized yet, let's do that now
if (!state.finalized_) {
state.finalized_ = true;
state.scope_.unfinalizedDrafts_--;
var result = // For ES5, create a good copy from the draft first, with added keys and without deleted keys.
state.type_ === 4
/* ES5Object */
|| state.type_ === 5
/* ES5Array */
? state.copy_ = shallowCopy(state.draft_) : state.copy_; // Finalize all children of the copy
var result = state.copy_;
// Finalize all children of the copy
// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628
// To preserve insertion order in all cases we then clear the set
// And we let finalizeProperty know it needs to re-add non-draft children back to the target
var resultEach = result;
var isSet = false;
if (state.type_ === 3
/* Set */
) {
resultEach = new Set(result);
result.clear();
isSet = true;
}
if (state.type_ === 3 /* Set */) {
resultEach = new Set(result);
result.clear();
isSet = true;
}
each(resultEach, function (key, childValue) {
return finalizeProperty(rootScope, state, result, key, childValue, path, isSet);
}); // everything inside is frozen, we can freeze here
maybeFreeze(rootScope, result, false); // first time finalizing, let's create those patches
});
// everything inside is frozen, we can freeze here
maybeFreeze(rootScope, result, false);
// first time finalizing, let's create those patches
if (path && rootScope.patches_) {

@@ -470,20 +462,16 @@ getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);

}
return state.copy_;
}
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
if ( childValue === targetObject) die(5);
if (isDraft(childValue)) {
var path = rootPath && parentState && parentState.type_ !== 3
/* Set */
&& // Set objects are atomic since they have no keys.
var path = rootPath && parentState && parentState.type_ !== 3 /* Set */ &&
// Set objects are atomic since they have no keys.
!has(parentState.assigned_, prop) // Skip deep patches for assigned keys.
? rootPath.concat(prop) : undefined; // Drafts owned by `scope` are finalized here.
? rootPath.concat(prop) : undefined;
// Drafts owned by `scope` are finalized here.
var res = finalize(rootScope, childValue, path);
set(targetObject, prop, res); // Drafts from another scope must prevented to be frozen
set(targetObject, prop, res);
// Drafts from another scope must prevented to be frozen
// if we got a draft back from finalize, we're in a nested produce and shouldn't freeze
if (isDraft(res)) {

@@ -494,5 +482,4 @@ rootScope.canAutoFreeze_ = false;

targetObject.add(childValue);
} // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
}
// Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
if (isDraftable(childValue) && !isFrozen(childValue)) {

@@ -507,9 +494,7 @@ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {

}
finalize(rootScope, childValue); // immer deep freezes plain objects, so if there is no parent state, we freeze as well
finalize(rootScope, childValue);
// immer deep freezes plain objects, so if there is no parent state, we freeze as well
if (!parentState || !parentState.scope_.parent_) maybeFreeze(rootScope, childValue);
}
}
function maybeFreeze(scope, value, deep) {

@@ -519,3 +504,2 @@ if (deep === void 0) {

}
// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects

@@ -532,11 +516,7 @@ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {

*/
function createProxyProxy(base, parent) {
var isArray = Array.isArray(base);
var state = {
type_: isArray ? 1
/* ProxyArray */
: 0
/* ProxyObject */
,
type_: isArray ? 1 /* Array */ : 0 /* Object */,
// Track which produce call this is associated with.

@@ -561,3 +541,4 @@ scope_: parent ? parent.scope_ : getCurrentScope(),

isManual_: false
}; // the traps must target something, a bit like the 'real' base.
};
// the traps must target something, a bit like the 'real' base.
// but also, we need to be able to determine from the target what the relevant state is

@@ -568,6 +549,4 @@ // (to avoid creating traps per instance to capture the state in closure,

// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
var target = state;
var traps = objectTraps;
if (isArray) {

@@ -577,7 +556,5 @@ target = [state];

}
var _Proxy$revocable = Proxy.revocable(target, traps),
revoke = _Proxy$revocable.revoke,
proxy = _Proxy$revocable.proxy;
revoke = _Proxy$revocable.revoke,
proxy = _Proxy$revocable.proxy;
state.draft_ = proxy;

@@ -590,3 +567,2 @@ state.revoke_ = revoke;

*/
var objectTraps = {

@@ -596,3 +572,2 @@ get: function get(state, prop) {

var source = latest(state);
if (!has(source, prop)) {

@@ -602,16 +577,12 @@ // non-existing or non-own property...

}
var value = source[prop];
if (state.finalized_ || !isDraftable(value)) {
return value;
} // Check for existing draft in modified state.
}
// Check for existing draft in modified state.
// Assigned values are never drafted. This catches any drafts we created, too.
if (value === peek(state.base_, prop)) {
prepareCopy(state);
return state.copy_[prop] = createProxy(state.scope_.immer_, value, state);
return state.copy_[prop] = createProxy(value, state);
}
return value;

@@ -625,8 +596,5 @@ },

},
set: function set(state, prop
/* strictly not, but helps TS */
, value) {
set: function set(state, prop /* strictly not, but helps TS */, value) {
var desc = getDescriptorFromProto(latest(state), prop);
if (desc === null || desc === void 0 ? void 0 : desc.set) {
if (desc != null && desc.set) {
// special case: if this write is captured by a setter, we have

@@ -637,10 +605,8 @@ // to trigger it with the correct context

}
if (!state.modified_) {
// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)
// from setting an existing property with value undefined to undefined (which is not a change)
var current = peek(latest(state), prop); // special case, if we assigning the original value to a draft, we can ignore the assignment
var currentState = current === null || current === void 0 ? void 0 : current[DRAFT_STATE];
var current = peek(latest(state), prop);
// special case, if we assigning the original value to a draft, we can ignore the assignment
var currentState = current == null ? void 0 : current[DRAFT_STATE];
if (currentState && currentState.base_ === value) {

@@ -651,3 +617,2 @@ state.copy_[prop] = value;

}
if (is(value, current) && (value !== undefined || has(state.base_, prop))) return true;

@@ -657,7 +622,8 @@ prepareCopy(state);

}
if (state.copy_[prop] === value && ( // special case: handle new props with value 'undefined'
value !== undefined || prop in state.copy_) || // special case: NaN
Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true; // @ts-ignore
if (state.copy_[prop] === value && (
// special case: handle new props with value 'undefined'
value !== undefined || prop in state.copy_) ||
// special case: NaN
Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
// @ts-ignore
state.copy_[prop] = value;

@@ -676,6 +642,4 @@ state.assigned_[prop] = true;

delete state.assigned_[prop];
} // @ts-ignore
if (state.copy_) delete state.copy_[prop];
}
delete state.copy_[prop];
return true;

@@ -691,5 +655,3 @@ },

writable: true,
configurable: state.type_ !== 1
/* ProxyArray */
|| prop !== "length",
configurable: state.type_ !== 1 /* Array */ || prop !== "length",
enumerable: desc.enumerable,

@@ -712,3 +674,2 @@ value: owner[prop]

*/
var arrayTraps = {};

@@ -722,15 +683,12 @@ each(objectTraps, function (key, fn) {

});
arrayTraps.deleteProperty = function (state, prop) {
if ( isNaN(parseInt(prop))) die(13); // @ts-ignore
if ( isNaN(parseInt(prop))) die(13);
// @ts-ignore
return arrayTraps.set.call(this, state, prop, undefined);
};
arrayTraps.set = function (state, prop, value) {
if ( prop !== "length" && isNaN(parseInt(prop))) die(14);
return objectTraps.set.call(this, state[0], prop, value, state[0]);
}; // Access a property without creating an Immer draft.
};
// Access a property without creating an Immer draft.
function peek(draft, prop) {

@@ -741,12 +699,9 @@ var state = draft[DRAFT_STATE];

}
function readPropFromProto(state, source, prop) {
var _desc$get;
var desc = getDescriptorFromProto(source, prop);
return desc ? "value" in desc ? desc.value : // This is a very special case, if the prop is a getter defined by the
// prototype, we should invoke it with the draft as context!
(_desc$get = desc.get) === null || _desc$get === void 0 ? void 0 : _desc$get.call(state.draft_) : undefined;
(_desc$get = desc.get) == null ? void 0 : _desc$get.call(state.draft_) : undefined;
}
function getDescriptorFromProto(source, prop) {

@@ -756,3 +711,2 @@ // 'in' checks proto!

var proto = Object.getPrototypeOf(source);
while (proto) {

@@ -763,10 +717,7 @@ var desc = Object.getOwnPropertyDescriptor(proto, prop);

}
return undefined;
}
function markChanged(state) {
if (!state.modified_) {
state.modified_ = true;
if (state.parent_) {

@@ -779,14 +730,11 @@ markChanged(state.parent_);

if (!state.copy_) {
state.copy_ = shallowCopy(state.base_);
state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
}
}
var Immer =
/*#__PURE__*/
function () {
var Immer = /*#__PURE__*/function () {
function Immer(config) {
var _this = this;
this.useProxies_ = hasProxies;
this.autoFreeze_ = true;
this.useStrictShallowCopy_ = false;
/**

@@ -811,3 +759,2 @@ * The `produce` function takes a value and a "recipe function" (whose

*/
this.produce = function (base, recipe, patchListener) {

@@ -821,14 +768,10 @@ // curried invocation

var _this2 = this;
if (base === void 0) {
base = defaultBase;
}
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return self.produce(base, function (draft) {
var _recipe;
return (_recipe = recipe).call.apply(_recipe, [_this2, draft].concat(args));

@@ -841,9 +784,8 @@ }); // prettier-ignore

if (patchListener !== undefined && typeof patchListener !== "function") die(7);
var result; // Only plain objects, arrays, and "immerable classes" are drafted.
var result;
// Only plain objects, arrays, and "immerable classes" are drafted.
if (isDraftable(base)) {
var scope = enterScope(_this);
var proxy = createProxy(_this, base, undefined);
var proxy = createProxy(base, undefined);
var hasError = true;
try {

@@ -856,13 +798,2 @@ result = recipe(proxy);

}
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(function (result) {
usePatchesInScope(scope, patchListener);
return processResult(result, scope);
}, function (error) {
revokeScope(scope);
throw error;
});
}
usePatchesInScope(scope, patchListener);

@@ -875,3 +806,2 @@ return processResult(result, scope);

if (_this.autoFreeze_) freeze(result, true);
if (patchListener) {

@@ -883,7 +813,5 @@ var p = [];

}
return result;
} else die(21, base);
} else die(1, base);
};
this.produceWithPatches = function (base, recipe) {

@@ -896,3 +824,2 @@ // curried invocation

}
return _this.produceWithPatches(state, function (draft) {

@@ -903,5 +830,3 @@ return base.apply(void 0, [draft].concat(args));

}
var patches, inversePatches;
var result = _this.produce(base, recipe, function (p, ip) {

@@ -911,18 +836,8 @@ patches = p;

});
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(function (nextState) {
return [nextState, patches, inversePatches];
});
}
return [result, patches, inversePatches];
};
if (typeof (config === null || config === void 0 ? void 0 : config.useProxies) === "boolean") this.setUseProxies(config.useProxies);
if (typeof (config === null || config === void 0 ? void 0 : config.autoFreeze) === "boolean") this.setAutoFreeze(config.autoFreeze);
if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean") this.setAutoFreeze(config.autoFreeze);
if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean") this.setUseStrictShallowCopy(config.useStrictShallowCopy);
}
var _proto = Immer.prototype;
_proto.createDraft = function createDraft(base) {

@@ -932,3 +847,3 @@ if (!isDraftable(base)) die(8);

var scope = enterScope(this);
var proxy = createProxy(this, base, undefined);
var proxy = createProxy(base, undefined);
proxy[DRAFT_STATE].isManual_ = true;

@@ -938,11 +853,5 @@ leaveScope(scope);

};
_proto.finishDraft = function finishDraft(draft, patchListener) {
var state = draft && draft[DRAFT_STATE];
{
if (!state || !state.isManual_) die(9);
if (state.finalized_) die(10);
}
if (!state || !state.isManual_) die(9);
var scope = state.scope_;

@@ -956,5 +865,3 @@ usePatchesInScope(scope, patchListener);

* By default, auto-freezing is enabled.
*/
;
*/;
_proto.setAutoFreeze = function setAutoFreeze(value) {

@@ -964,17 +871,9 @@ this.autoFreeze_ = value;

/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
*/
;
_proto.setUseProxies = function setUseProxies(value) {
if (value && !hasProxies) {
die(20);
}
this.useProxies_ = value;
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/;
_proto.setUseStrictShallowCopy = function setUseStrictShallowCopy(value) {
this.useStrictShallowCopy_ = value;
};
_proto.applyPatches = function applyPatches(base, patches) {

@@ -984,6 +883,4 @@ // If a patch replaces the entire state, take that replacement as base

var i;
for (i = patches.length - 1; i >= 0; i--) {
var patch = patches[i];
if (patch.path.length === 0 && patch.op === "replace") {

@@ -993,18 +890,14 @@ base = patch.value;

}
} // If there was a patch that replaced the entire state, start from the
}
// If there was a patch that replaced the entire state, start from the
// patch after that.
if (i > -1) {
patches = patches.slice(i + 1);
}
var applyPatchesImpl = getPlugin("Patches").applyPatches_;
if (isDraft(base)) {
// N.B: never hits if some patch a replacement, patches are never drafts
return applyPatchesImpl(base, patches);
} // Otherwise, produce a copy of the base state.
}
// Otherwise, produce a copy of the base state.
return this.produce(base, function (draft) {

@@ -1014,8 +907,7 @@ return applyPatchesImpl(draft, patches);

};
return Immer;
}();
function createProxy(immer, value, parent) {
function createProxy(value, parent) {
// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
var draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : immer.useProxies_ ? createProxyProxy(value, parent) : getPlugin("ES5").createES5Proxy_(value, parent);
var draft = isMap(value) ? proxyMap(value, parent) : isSet(value) ? proxySet(value, parent) : createProxyProxy(value, parent);
var scope = parent ? parent.scope_ : getCurrentScope();

@@ -1027,358 +919,319 @@ scope.drafts_.push(draft);

function current(value) {
if (!isDraft(value)) die(22, value);
if (!isDraft(value)) die(10, value);
return currentImpl(value);
}
function currentImpl(value) {
if (!isDraftable(value)) return value;
if (!isDraftable(value) || isFrozen(value)) return value;
var state = value[DRAFT_STATE];
var copy;
var archType = getArchtype(value);
if (state) {
if (!state.modified_ && (state.type_ < 4 || !getPlugin("ES5").hasChanges_(state))) return state.base_; // Optimization: avoid generating new drafts during copying
if (!state.modified_) return state.base_;
// Optimization: avoid generating new drafts during copying
state.finalized_ = true;
copy = copyHelper(value, archType);
state.finalized_ = false;
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
} else {
copy = copyHelper(value, archType);
copy = shallowCopy(value, true);
}
// recurse
each(copy, function (key, childValue) {
if (state && get(state.base_, key) === childValue) return; // no need to copy or search in something that didn't change
set(copy, key, currentImpl(childValue));
}); // In the future, we might consider freezing here, based on the current settings
return archType === 3
/* Set */
? new Set(copy) : copy;
}
function copyHelper(value, archType) {
// creates a shallow copy, even if it is a map or set
switch (archType) {
case 2
/* Map */
:
return new Map(value);
case 3
/* Set */
:
// Set will be cloned as array temporarily, so that we can replace individual items
return Array.from(value);
});
if (state) {
state.finalized_ = false;
}
return shallowCopy(value);
return copy;
}
function enableES5() {
function willFinalizeES5_(scope, result, isReplaced) {
if (!isReplaced) {
if (scope.patches_) {
markChangesRecursively(scope.drafts_[0]);
} // This is faster when we don't care about which attributes changed.
markChangesSweep(scope.drafts_);
} // When a child draft is returned, look for changes.
else if (isDraft(result) && result[DRAFT_STATE].scope_ === scope) {
markChangesSweep(scope.drafts_);
}
var DraftMap = /*#__PURE__*/function (_Map, _Symbol$iterator) {
_inheritsLoose(DraftMap, _Map);
function DraftMap(target, parent) {
var _this;
_this = _Map.call(this) || this;
_this[DRAFT_STATE] = {
type_: 2 /* Map */,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
assigned_: undefined,
base_: target,
draft_: _assertThisInitialized(_this),
isManual_: false,
revoked_: false
};
return _this;
}
function createES5Draft(isArray, base) {
if (isArray) {
var draft = new Array(base.length);
for (var i = 0; i < base.length; i++) {
Object.defineProperty(draft, "" + i, proxyProperty(i, true));
}
return draft;
var _proto = DraftMap.prototype;
_proto.has = function has(key) {
return latest(this[DRAFT_STATE]).has(key);
};
_proto.set = function set(key, value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!latest(state).has(key) || latest(state).get(key) !== value) {
prepareMapCopy(state);
markChanged(state);
state.assigned_.set(key, true);
state.copy_.set(key, value);
state.assigned_.set(key, true);
}
return this;
};
_proto["delete"] = function _delete(key) {
if (!this.has(key)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareMapCopy(state);
markChanged(state);
if (state.base_.has(key)) {
state.assigned_.set(key, false);
} else {
var _descriptors = getOwnPropertyDescriptors(base);
delete _descriptors[DRAFT_STATE];
var keys = ownKeys(_descriptors);
for (var _i = 0; _i < keys.length; _i++) {
var key = keys[_i];
_descriptors[key] = proxyProperty(key, isArray || !!_descriptors[key].enumerable);
}
return Object.create(Object.getPrototypeOf(base), _descriptors);
state.assigned_["delete"](key);
}
state.copy_["delete"](key);
return true;
};
_proto.clear = function clear() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareMapCopy(state);
markChanged(state);
state.assigned_ = new Map();
each(state.base_, function (key) {
state.assigned_.set(key, false);
});
state.copy_.clear();
}
};
_proto.forEach = function forEach(cb, thisArg) {
var _this2 = this;
var state = this[DRAFT_STATE];
latest(state).forEach(function (_value, key, _map) {
cb.call(thisArg, _this2.get(key), key, _this2);
});
};
_proto.get = function get(key) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
var value = latest(state).get(key);
if (state.finalized_ || !isDraftable(value)) {
return value;
}
if (value !== state.base_.get(key)) {
return value; // either already drafted or reassigned
}
// despite what it looks, this creates a draft only once, see above condition
var draft = createProxy(value, state);
prepareMapCopy(state);
state.copy_.set(key, draft);
return draft;
};
_proto.keys = function keys() {
return latest(this[DRAFT_STATE]).keys();
};
_proto.values = function values() {
var _this3 = this,
_ref;
var iterator = this.keys();
return _ref = {}, _ref[Symbol.iterator] = function () {
return _this3.values();
}, _ref.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this3.get(r.value);
return {
done: false,
value: value
};
}, _ref;
};
_proto.entries = function entries() {
var _this4 = this,
_ref2;
var iterator = this.keys();
return _ref2 = {}, _ref2[Symbol.iterator] = function () {
return _this4.entries();
}, _ref2.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this4.get(r.value);
return {
done: false,
value: [r.value, value]
};
}, _ref2;
};
_proto[_Symbol$iterator] = function () {
return this.entries();
};
_createClass(DraftMap, [{
key: "size",
get: function get() {
return latest(this[DRAFT_STATE]).size;
}
}]);
return DraftMap;
}( /*#__PURE__*/_wrapNativeSuper(Map), Symbol.iterator);
function proxyMap(target, parent) {
// @ts-ignore
return new DraftMap(target, parent);
}
function prepareMapCopy(state) {
if (!state.copy_) {
state.assigned_ = new Map();
state.copy_ = new Map(state.base_);
}
function createES5Proxy_(base, parent) {
var isArray = Array.isArray(base);
var draft = createES5Draft(isArray, base);
var state = {
type_: isArray ? 5
/* ES5Array */
: 4
/* ES5Object */
,
}
var DraftSet = /*#__PURE__*/function (_Set, _Symbol$iterator2) {
_inheritsLoose(DraftSet, _Set);
function DraftSet(target, parent) {
var _this5;
_this5 = _Set.call(this) || this;
_this5[DRAFT_STATE] = {
type_: 3 /* Set */,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
assigned_: {},
parent_: parent,
// base is the object we are drafting
base_: base,
// draft is the draft object itself, that traps all reads and reads from either the base (if unmodified) or copy (if modified)
draft_: draft,
copy_: null,
copy_: undefined,
base_: target,
draft_: _assertThisInitialized(_this5),
drafts_: new Map(),
revoked_: false,
isManual_: false
};
Object.defineProperty(draft, DRAFT_STATE, {
value: state,
// enumerable: false <- the default
writable: true
});
return draft;
} // property descriptors are recycled to make sure we don't create a get and set closure per property,
// but share them all instead
var descriptors = {};
function proxyProperty(prop, enumerable) {
var desc = descriptors[prop];
if (desc) {
desc.enumerable = enumerable;
} else {
descriptors[prop] = desc = {
configurable: true,
enumerable: enumerable,
get: function get() {
var state = this[DRAFT_STATE];
assertUnrevoked(state); // @ts-ignore
return objectTraps.get(state, prop);
},
set: function set(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state); // @ts-ignore
objectTraps.set(state, prop, value);
}
};
return _this5;
}
var _proto2 = DraftSet.prototype;
_proto2.has = function has(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
// bit of trickery here, to be able to recognize both the value, and the draft of its value
if (!state.copy_) {
return state.base_.has(value);
}
return desc;
} // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
function markChangesSweep(drafts) {
// The natural order of drafts in the `scope` array is based on when they
// were accessed. By processing drafts in reverse natural order, we have a
// better chance of processing leaf nodes first. When a leaf node is known to
// have changed, we can avoid any traversal of its ancestor nodes.
for (var i = drafts.length - 1; i >= 0; i--) {
var state = drafts[i][DRAFT_STATE];
if (!state.modified_) {
switch (state.type_) {
case 5
/* ES5Array */
:
if (hasArrayChanges(state)) markChanged(state);
break;
case 4
/* ES5Object */
:
if (hasObjectChanges(state)) markChanged(state);
break;
}
}
if (state.copy_.has(value)) return true;
if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true;
return false;
};
_proto2.add = function add(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!this.has(value)) {
prepareSetCopy(state);
markChanged(state);
state.copy_.add(value);
}
}
function markChangesRecursively(object) {
if (!object || typeof object !== "object") return;
var state = object[DRAFT_STATE];
if (!state) return;
var base_ = state.base_,
draft_ = state.draft_,
assigned_ = state.assigned_,
type_ = state.type_;
if (type_ === 4
/* ES5Object */
) {
// Look for added keys.
// probably there is a faster way to detect changes, as sweep + recurse seems to do some
// unnecessary work.
// also: probably we can store the information we detect here, to speed up tree finalization!
each(draft_, function (key) {
if (key === DRAFT_STATE) return; // The `undefined` check is a fast path for pre-existing keys.
if (base_[key] === undefined && !has(base_, key)) {
assigned_[key] = true;
markChanged(state);
} else if (!assigned_[key]) {
// Only untouched properties trigger recursion.
markChangesRecursively(draft_[key]);
}
}); // Look for removed keys.
each(base_, function (key) {
// The `undefined` check is a fast path for pre-existing keys.
if (draft_[key] === undefined && !has(draft_, key)) {
assigned_[key] = false;
markChanged(state);
}
});
} else if (type_ === 5
/* ES5Array */
) {
if (hasArrayChanges(state)) {
markChanged(state);
assigned_.length = true;
}
if (draft_.length < base_.length) {
for (var i = draft_.length; i < base_.length; i++) {
assigned_[i] = false;
}
} else {
for (var _i2 = base_.length; _i2 < draft_.length; _i2++) {
assigned_[_i2] = true;
}
} // Minimum count is enough, the other parts has been processed.
var min = Math.min(draft_.length, base_.length);
for (var _i3 = 0; _i3 < min; _i3++) {
// Only untouched indices trigger recursion.
if (!draft_.hasOwnProperty(_i3)) {
assigned_[_i3] = true;
}
if (assigned_[_i3] === undefined) markChangesRecursively(draft_[_i3]);
}
return this;
};
_proto2["delete"] = function _delete(value) {
if (!this.has(value)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
markChanged(state);
return state.copy_["delete"](value) || (state.drafts_.has(value) ? state.copy_["delete"](state.drafts_.get(value)) : /* istanbul ignore next */false);
};
_proto2.clear = function clear() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareSetCopy(state);
markChanged(state);
state.copy_.clear();
}
};
_proto2.values = function values() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.values();
};
_proto2.entries = function entries() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.entries();
};
_proto2.keys = function keys() {
return this.values();
};
_proto2[_Symbol$iterator2] = function () {
return this.values();
};
_proto2.forEach = function forEach(cb, thisArg) {
var iterator = this.values();
var result = iterator.next();
while (!result.done) {
cb.call(thisArg, result.value, result.value, this);
result = iterator.next();
}
};
_createClass(DraftSet, [{
key: "size",
get: function get() {
return latest(this[DRAFT_STATE]).size;
}
}]);
return DraftSet;
}( /*#__PURE__*/_wrapNativeSuper(Set), Symbol.iterator);
function proxySet(target, parent) {
// @ts-ignore
return new DraftSet(target, parent);
}
function prepareSetCopy(state) {
if (!state.copy_) {
// create drafts for all entries to preserve insertion order
state.copy_ = new Set();
state.base_.forEach(function (value) {
if (isDraftable(value)) {
var draft = createProxy(value, state);
state.drafts_.set(value, draft);
state.copy_.add(draft);
} else {
state.copy_.add(value);
}
});
}
function hasObjectChanges(state) {
var base_ = state.base_,
draft_ = state.draft_; // Search for added keys and changed keys. Start at the back, because
// non-numeric keys are ordered by time of definition on the object.
var keys = ownKeys(draft_);
for (var i = keys.length - 1; i >= 0; i--) {
var key = keys[i];
if (key === DRAFT_STATE) continue;
var baseValue = base_[key]; // The `undefined` check is a fast path for pre-existing keys.
if (baseValue === undefined && !has(base_, key)) {
return true;
} // Once a base key is deleted, future changes go undetected, because its
// descriptor is erased. This branch detects any missed changes.
else {
var value = draft_[key];
var _state = value && value[DRAFT_STATE];
if (_state ? _state.base_ !== baseValue : !is(value, baseValue)) {
return true;
}
}
} // At this point, no keys were added or changed.
// Compare key count to determine if keys were deleted.
var baseIsDraft = !!base_[DRAFT_STATE];
return keys.length !== ownKeys(base_).length + (baseIsDraft ? 0 : 1); // + 1 to correct for DRAFT_STATE
}
function hasArrayChanges(state) {
var draft_ = state.draft_;
if (draft_.length !== state.base_.length) return true; // See #116
// If we first shorten the length, our array interceptors will be removed.
// If after that new items are added, result in the same original length,
// those last items will have no intercepting property.
// So if there is no own descriptor on the last position, we know that items were removed and added
// N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
// the last one
// last descriptor can be not a trap, if the array was extended
var descriptor = Object.getOwnPropertyDescriptor(draft_, draft_.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
if (descriptor && !descriptor.get) return true; // if we miss a property, it has been deleted, so array probobaly changed
for (var i = 0; i < draft_.length; i++) {
if (!draft_.hasOwnProperty(i)) return true;
} // For all other cases, we don't have to compare, as they would have been picked up by the index setters
return false;
}
function hasChanges_(state) {
return state.type_ === 4
/* ES5Object */
? hasObjectChanges(state) : hasArrayChanges(state);
}
function assertUnrevoked(state
/*ES5State | MapState | SetState*/
) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
loadPlugin("ES5", {
createES5Proxy_: createES5Proxy_,
willFinalizeES5_: willFinalizeES5_,
hasChanges_: hasChanges_
});
}
function assertUnrevoked(state /*ES5State | MapState | SetState*/) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
function enablePatches() {
var errorOffset = 16;
{
errors.push('Sets cannot have "replace" patches.', function (op) {
return "Unsupported patch operation: " + op;
}, function (path) {
return "Cannot apply patch, path doesn't resolve: " + path;
}, "Patching reserved attributes like __proto__, prototype and constructor is not allowed");
}
var REPLACE = "replace";
var ADD = "add";
var REMOVE = "remove";
function generatePatches_(state, basePath, patches, inversePatches) {
switch (state.type_) {
case 0
/* ProxyObject */
:
case 4
/* ES5Object */
:
case 2
/* Map */
:
case 0 /* Object */:
case 2 /* Map */:
return generatePatchesFromAssigned(state, basePath, patches, inversePatches);
case 5
/* ES5Array */
:
case 1
/* ProxyArray */
:
case 1 /* Array */:
return generateArrayPatches(state, basePath, patches, inversePatches);
case 3
/* Set */
:
case 3 /* Set */:
return generateSetPatches(state, basePath, patches, inversePatches);
}
}
function generateArrayPatches(state, basePath, patches, inversePatches) {
var base_ = state.base_,
assigned_ = state.assigned_;
var copy_ = state.copy_; // Reduce complexity by ensuring `base` is never longer.
assigned_ = state.assigned_;
var copy_ = state.copy_;
// Reduce complexity by ensuring `base` is never longer.
if (copy_.length < base_.length) {

@@ -1391,5 +1244,4 @@ var _ref = [copy_, base_];

inversePatches = _ref2[1];
} // Process replaced indices.
}
// Process replaced indices.
for (var i = 0; i < base_.length; i++) {

@@ -1411,8 +1263,6 @@ if (assigned_[i] && copy_[i] !== base_[i]) {

}
} // Process added indices.
}
// Process added indices.
for (var _i = base_.length; _i < copy_.length; _i++) {
var _path = basePath.concat([_i]);
patches.push({

@@ -1426,16 +1276,14 @@ op: ADD,

}
if (base_.length < copy_.length) {
for (var _i2 = copy_.length - 1; base_.length <= _i2; --_i2) {
var _path2 = basePath.concat([_i2]);
inversePatches.push({
op: REPLACE,
path: basePath.concat(["length"]),
value: base_.length
op: REMOVE,
path: _path2
});
}
} // This is used for both Map objects and normal objects.
}
// This is used for both Map objects and normal objects.
function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
var base_ = state.base_,
copy_ = state.copy_;
copy_ = state.copy_;
each(state.assigned_, function (key, assignedValue) {

@@ -1469,6 +1317,5 @@ var origValue = get(base_, key);

}
function generateSetPatches(state, basePath, patches, inversePatches) {
var base_ = state.base_,
copy_ = state.copy_;
copy_ = state.copy_;
var i = 0;

@@ -1489,3 +1336,2 @@ base_.forEach(function (value) {

}
i++;

@@ -1508,7 +1354,5 @@ });

}
i++;
});
}
function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {

@@ -1526,48 +1370,30 @@ patches.push({

}
function applyPatches_(draft, patches) {
patches.forEach(function (patch) {
var path = patch.path,
op = patch.op;
op = patch.op;
var base = draft;
for (var i = 0; i < path.length - 1; i++) {
var parentType = getArchtype(base);
var p = path[i];
if (typeof p !== "string" && typeof p !== "number") {
p = "" + p;
} // See #738, avoid prototype pollution
if ((parentType === 0
/* Object */
|| parentType === 1
/* Array */
) && (p === "__proto__" || p === "constructor")) die(24);
if (typeof base === "function" && p === "prototype") die(24);
}
// See #738, avoid prototype pollution
if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === "__proto__" || p === "constructor")) die(errorOffset + 3);
if (typeof base === "function" && p === "prototype") die(errorOffset + 3);
base = get(base, p);
if (typeof base !== "object") die(15, path.join("/"));
if (typeof base !== "object") die(errorOffset + 2, path.join("/"));
}
var type = getArchtype(base);
var value = deepClonePatchValue(patch.value); // used to clone patch to ensure original patch is not modified, see #411
var key = path[path.length - 1];
switch (op) {
case REPLACE:
switch (type) {
case 2
/* Map */
:
case 2 /* Map */:
return base.set(key, value);
/* istanbul ignore next */
case 3
/* Set */
:
die(16);
case 3 /* Set */:
die(errorOffset);
default:

@@ -1580,47 +1406,26 @@ // if value is an object, then it's assigned by reference

}
case ADD:
switch (type) {
case 1
/* Array */
:
case 1 /* Array */:
return key === "-" ? base.push(value) : base.splice(key, 0, value);
case 2
/* Map */
:
case 2 /* Map */:
return base.set(key, value);
case 3
/* Set */
:
case 3 /* Set */:
return base.add(value);
default:
return base[key] = value;
}
case REMOVE:
switch (type) {
case 1
/* Array */
:
case 1 /* Array */:
return base.splice(key, 1);
case 2
/* Map */
:
return base.delete(key);
case 3
/* Set */
:
return base.delete(patch.value);
case 2 /* Map */:
return base["delete"](key);
case 3 /* Set */:
return base["delete"](patch.value);
default:
return delete base[key];
}
default:
die(17, op);
die(errorOffset + 1, op);
}

@@ -1630,3 +1435,2 @@ });

}
function deepClonePatchValue(obj) {

@@ -1637,3 +1441,3 @@ if (!isDraftable(obj)) return obj;

var k = _ref3[0],
v = _ref3[1];
v = _ref3[1];
return [k, deepClonePatchValue(v)];

@@ -1643,11 +1447,6 @@ }));

var cloned = Object.create(Object.getPrototypeOf(obj));
for (var key in obj) {
cloned[key] = deepClonePatchValue(obj[key]);
}
for (var key in obj) cloned[key] = deepClonePatchValue(obj[key]);
if (has(obj, DRAFTABLE)) cloned[DRAFTABLE] = obj[DRAFTABLE];
return cloned;
}
function clonePatchValueIfNeeded(obj) {

@@ -1658,3 +1457,2 @@ if (isDraft(obj)) {

}
loadPlugin("Patches", {

@@ -1667,372 +1465,3 @@ applyPatches_: applyPatches_,

// types only!
function enableMapSet() {
/* istanbul ignore next */
var _extendStatics = function extendStatics(d, b) {
_extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) d[p] = b[p];
}
};
return _extendStatics(d, b);
}; // Ugly hack to resolve #502 and inherit built in Map / Set
function __extends(d, b) {
_extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = ( // @ts-ignore
__.prototype = b.prototype, new __());
}
var DraftMap = function (_super) {
__extends(DraftMap, _super); // Create class manually, cause #502
function DraftMap(target, parent) {
this[DRAFT_STATE] = {
type_: 2
/* Map */
,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
assigned_: undefined,
base_: target,
draft_: this,
isManual_: false,
revoked_: false
};
return this;
}
var p = DraftMap.prototype;
Object.defineProperty(p, "size", {
get: function get() {
return latest(this[DRAFT_STATE]).size;
} // enumerable: false,
// configurable: true
});
p.has = function (key) {
return latest(this[DRAFT_STATE]).has(key);
};
p.set = function (key, value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!latest(state).has(key) || latest(state).get(key) !== value) {
prepareMapCopy(state);
markChanged(state);
state.assigned_.set(key, true);
state.copy_.set(key, value);
state.assigned_.set(key, true);
}
return this;
};
p.delete = function (key) {
if (!this.has(key)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareMapCopy(state);
markChanged(state);
if (state.base_.has(key)) {
state.assigned_.set(key, false);
} else {
state.assigned_.delete(key);
}
state.copy_.delete(key);
return true;
};
p.clear = function () {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareMapCopy(state);
markChanged(state);
state.assigned_ = new Map();
each(state.base_, function (key) {
state.assigned_.set(key, false);
});
state.copy_.clear();
}
};
p.forEach = function (cb, thisArg) {
var _this = this;
var state = this[DRAFT_STATE];
latest(state).forEach(function (_value, key, _map) {
cb.call(thisArg, _this.get(key), key, _this);
});
};
p.get = function (key) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
var value = latest(state).get(key);
if (state.finalized_ || !isDraftable(value)) {
return value;
}
if (value !== state.base_.get(key)) {
return value; // either already drafted or reassigned
} // despite what it looks, this creates a draft only once, see above condition
var draft = createProxy(state.scope_.immer_, value, state);
prepareMapCopy(state);
state.copy_.set(key, draft);
return draft;
};
p.keys = function () {
return latest(this[DRAFT_STATE]).keys();
};
p.values = function () {
var _this2 = this,
_ref;
var iterator = this.keys();
return _ref = {}, _ref[iteratorSymbol] = function () {
return _this2.values();
}, _ref.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this2.get(r.value);
return {
done: false,
value: value
};
}, _ref;
};
p.entries = function () {
var _this3 = this,
_ref2;
var iterator = this.keys();
return _ref2 = {}, _ref2[iteratorSymbol] = function () {
return _this3.entries();
}, _ref2.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this3.get(r.value);
return {
done: false,
value: [r.value, value]
};
}, _ref2;
};
p[iteratorSymbol] = function () {
return this.entries();
};
return DraftMap;
}(Map);
function proxyMap_(target, parent) {
// @ts-ignore
return new DraftMap(target, parent);
}
function prepareMapCopy(state) {
if (!state.copy_) {
state.assigned_ = new Map();
state.copy_ = new Map(state.base_);
}
}
var DraftSet = function (_super) {
__extends(DraftSet, _super); // Create class manually, cause #502
function DraftSet(target, parent) {
this[DRAFT_STATE] = {
type_: 3
/* Set */
,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
base_: target,
draft_: this,
drafts_: new Map(),
revoked_: false,
isManual_: false
};
return this;
}
var p = DraftSet.prototype;
Object.defineProperty(p, "size", {
get: function get() {
return latest(this[DRAFT_STATE]).size;
} // enumerable: true,
});
p.has = function (value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state); // bit of trickery here, to be able to recognize both the value, and the draft of its value
if (!state.copy_) {
return state.base_.has(value);
}
if (state.copy_.has(value)) return true;
if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true;
return false;
};
p.add = function (value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!this.has(value)) {
prepareSetCopy(state);
markChanged(state);
state.copy_.add(value);
}
return this;
};
p.delete = function (value) {
if (!this.has(value)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
markChanged(state);
return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) :
/* istanbul ignore next */
false);
};
p.clear = function () {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareSetCopy(state);
markChanged(state);
state.copy_.clear();
}
};
p.values = function () {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.values();
};
p.entries = function entries() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.entries();
};
p.keys = function () {
return this.values();
};
p[iteratorSymbol] = function () {
return this.values();
};
p.forEach = function forEach(cb, thisArg) {
var iterator = this.values();
var result = iterator.next();
while (!result.done) {
cb.call(thisArg, result.value, result.value, this);
result = iterator.next();
}
};
return DraftSet;
}(Set);
function proxySet_(target, parent) {
// @ts-ignore
return new DraftSet(target, parent);
}
function prepareSetCopy(state) {
if (!state.copy_) {
// create drafts for all entries to preserve insertion order
state.copy_ = new Set();
state.base_.forEach(function (value) {
if (isDraftable(value)) {
var draft = createProxy(state.scope_.immer_, value, state);
state.drafts_.set(value, draft);
state.copy_.add(draft);
} else {
state.copy_.add(value);
}
});
}
}
function assertUnrevoked(state
/*ES5State | MapState | SetState*/
) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
loadPlugin("MapSet", {
proxyMap_: proxyMap_,
proxySet_: proxySet_
});
}
function enableAllPlugins() {
enableES5();
enableMapSet();
enablePatches();
}
var immer =
/*#__PURE__*/
new Immer();
var immer = /*#__PURE__*/new Immer();
/**

@@ -2057,3 +1486,2 @@ * The `produce` function takes a value and a "recipe function" (whose

*/
var produce = immer.produce;

@@ -2064,6 +1492,3 @@ /**

*/
var produceWithPatches =
/*#__PURE__*/
immer.produceWithPatches.bind(immer);
var produceWithPatches = /*#__PURE__*/immer.produceWithPatches.bind(immer);
/**

@@ -2074,16 +1499,9 @@ * Pass true to automatically freeze all copies created by Immer.

*/
var setAutoFreeze =
/*#__PURE__*/
immer.setAutoFreeze.bind(immer);
var setAutoFreeze = /*#__PURE__*/immer.setAutoFreeze.bind(immer);
/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
var setUseProxies =
/*#__PURE__*/
immer.setUseProxies.bind(immer);
var setUseStrictShallowCopy = /*#__PURE__*/immer.setUseStrictShallowCopy.bind(immer);
/**

@@ -2094,6 +1512,3 @@ * Apply an array of Immer patches to the first argument.

*/
var applyPatches =
/*#__PURE__*/
immer.applyPatches.bind(immer);
var applyPatches = /*#__PURE__*/immer.applyPatches.bind(immer);
/**

@@ -2103,6 +1518,3 @@ * Create an Immer draft from the given base state, which may be a draft itself.

*/
var createDraft =
/*#__PURE__*/
immer.createDraft.bind(immer);
var createDraft = /*#__PURE__*/immer.createDraft.bind(immer);
/**

@@ -2116,6 +1528,3 @@ * Finalize an Immer draft from a `createDraft` call, returning the base state

*/
var finishDraft =
/*#__PURE__*/
immer.finishDraft.bind(immer);
var finishDraft = /*#__PURE__*/immer.finishDraft.bind(immer);
/**

@@ -2127,3 +1536,2 @@ * This function is actually a no-op, but can be used to cast an immutable type

*/
function castDraft(value) {

@@ -2137,3 +1545,2 @@ return value;

*/
function castImmutable(value) {

@@ -2149,6 +1556,2 @@ return value;

exports.current = current;
exports.default = produce;
exports.enableAllPlugins = enableAllPlugins;
exports.enableES5 = enableES5;
exports.enableMapSet = enableMapSet;
exports.enablePatches = enablePatches;

@@ -2165,3 +1568,3 @@ exports.finishDraft = finishDraft;

exports.setAutoFreeze = setAutoFreeze;
exports.setUseProxies = setUseProxies;
exports.setUseStrictShallowCopy = setUseStrictShallowCopy;
//# sourceMappingURL=immer.cjs.development.js.map

@@ -1,2 +0,2 @@

function n(n){for(var r=arguments.length,t=Array(r>1?r-1:0),e=1;e<r;e++)t[e-1]=arguments[e];throw Error("[Immer] minified error nr: "+n+(t.length?" "+t.map((function(n){return"'"+n+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function r(n){return!!n&&!!n[H]}function t(n){var r;return!!n&&(function(n){if(!n||"object"!=typeof n)return!1;var r=Object.getPrototypeOf(n);if(null===r)return!0;var t=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return t===Object||"function"==typeof t&&Function.toString.call(t)===Q}(n)||Array.isArray(n)||!!n[G]||!!(null===(r=n.constructor)||void 0===r?void 0:r[G])||c(n)||v(n))}function e(n,r,t){void 0===t&&(t=!1),0===i(n)?(t?Object.keys:T)(n).forEach((function(e){t&&"symbol"==typeof e||r(e,n[e],n)})):n.forEach((function(t,e){return r(e,t,n)}))}function i(n){var r=n[H];return r?r.t>3?r.t-4:r.t:Array.isArray(n)?1:c(n)?2:v(n)?3:0}function u(n,r){return 2===i(n)?n.has(r):Object.prototype.hasOwnProperty.call(n,r)}function o(n,r){return 2===i(n)?n.get(r):n[r]}function f(n,r,t){var e=i(n);2===e?n.set(r,t):3===e?n.add(t):n[r]=t}function a(n,r){return n===r?0!==n||1/n==1/r:n!=n&&r!=r}function c(n){return W&&n instanceof Map}function v(n){return X&&n instanceof Set}function s(n){return n.i||n.u}function p(n){if(Array.isArray(n))return Array.prototype.slice.call(n);var r=U(n);delete r[H];for(var t=T(r),e=0;e<t.length;e++){var i=t[e],u=r[i];!1===u.writable&&(u.writable=!0,u.configurable=!0),(u.get||u.set)&&(r[i]={configurable:!0,writable:!0,enumerable:u.enumerable,value:n[i]})}return Object.create(Object.getPrototypeOf(n),r)}function l(n,u){return void 0===u&&(u=!1),h(n)||r(n)||!t(n)||(i(n)>1&&(n.set=n.add=n.clear=n.delete=d),Object.freeze(n),u&&e(n,(function(n,r){return l(r,!0)}),!0)),n}function d(){n(2)}function h(n){return null==n||"object"!=typeof n||Object.isFrozen(n)}function y(r){var t=V[r];return t||n(18,r),t}function _(n,r){V[n]||(V[n]=r)}function b(){return I}function m(n,r){r&&(y("Patches"),n.o=[],n.v=[],n.s=r)}function j(n){O(n),n.p.forEach(w),n.p=null}function O(n){n===I&&(I=n.l)}function x(n){return I={p:[],l:I,h:n,_:!0,m:0}}function w(n){var r=n[H];0===r.t||1===r.t?r.j():r.O=!0}function S(r,e){e.m=e.p.length;var i=e.p[0],u=void 0!==r&&r!==i;return e.h.S||y("ES5").P(e,r,u),u?(i[H].g&&(j(e),n(4)),t(r)&&(r=P(e,r),e.l||M(e,r)),e.o&&y("Patches").M(i[H].u,r,e.o,e.v)):r=P(e,i,[]),j(e),e.o&&e.s(e.o,e.v),r!==B?r:void 0}function P(n,r,t){if(h(r))return r;var i=r[H];if(!i)return e(r,(function(e,u){return g(n,i,r,e,u,t)}),!0),r;if(i.A!==n)return r;if(!i.g)return M(n,i.u,!0),i.u;if(!i.R){i.R=!0,i.A.m--;var u=4===i.t||5===i.t?i.i=p(i.k):i.i,o=u,f=!1;3===i.t&&(o=new Set(u),u.clear(),f=!0),e(o,(function(r,e){return g(n,i,u,r,e,t,f)})),M(n,u,!1),t&&n.o&&y("Patches").F(i,t,n.o,n.v)}return i.i}function g(n,e,i,o,a,c,v){if(r(a)){var s=P(n,a,c&&e&&3!==e.t&&!u(e.N,o)?c.concat(o):void 0);if(f(i,o,s),!r(s))return;n._=!1}else v&&i.add(a);if(t(a)&&!h(a)){if(!n.h.D&&n.m<1)return;P(n,a),e&&e.A.l||M(n,a)}}function M(n,r,t){void 0===t&&(t=!1),!n.l&&n.h.D&&n._&&l(r,t)}function A(n,r){var t=n[H];return(t?s(t):n)[r]}function z(n,r){if(r in n)for(var t=Object.getPrototypeOf(n);t;){var e=Object.getOwnPropertyDescriptor(t,r);if(e)return e;t=Object.getPrototypeOf(t)}}function E(n){n.g||(n.g=!0,n.l&&E(n.l))}function R(n){n.i||(n.i=p(n.u))}function k(n,r,t){var e=c(r)?y("MapSet").K(r,t):v(r)?y("MapSet").$(r,t):n.S?function(n,r){var t=Array.isArray(n),e={t:t?1:0,A:r?r.A:b(),g:!1,R:!1,N:{},l:r,u:n,k:null,i:null,j:null,C:!1},i=e,u=Y;t&&(i=[e],u=Z);var o=Proxy.revocable(i,u),f=o.revoke,a=o.proxy;return e.k=a,e.j=f,a}(r,t):y("ES5").I(r,t);return(t?t.A:b()).p.push(e),e}function F(u){return r(u)||n(22,u),function n(r){if(!t(r))return r;var u,a=r[H],c=i(r);if(a){if(!a.g&&(a.t<4||!y("ES5").J(a)))return a.u;a.R=!0,u=N(r,c),a.R=!1}else u=N(r,c);return e(u,(function(r,t){a&&o(a.u,r)===t||f(u,r,n(t))})),3===c?new Set(u):u}(u)}function N(n,r){switch(r){case 2:return new Map(n);case 3:return Array.from(n)}return p(n)}function D(){function n(n,r){var t=f[n];return t?t.enumerable=r:f[n]=t={configurable:!0,enumerable:r,get:function(){return Y.get(this[H],n)},set:function(r){Y.set(this[H],n,r)}},t}function t(n){for(var r=n.length-1;r>=0;r--){var t=n[r][H];if(!t.g)switch(t.t){case 5:o(t)&&E(t);break;case 4:i(t)&&E(t)}}}function i(n){for(var r=n.u,t=n.k,e=T(t),i=e.length-1;i>=0;i--){var o=e[i];if(o!==H){var f=r[o];if(void 0===f&&!u(r,o))return!0;var c=t[o],v=c&&c[H];if(v?v.u!==f:!a(c,f))return!0}}var s=!!r[H];return e.length!==T(r).length+(s?0:1)}function o(n){var r=n.k;if(r.length!==n.u.length)return!0;var t=Object.getOwnPropertyDescriptor(r,r.length-1);if(t&&!t.get)return!0;for(var e=0;e<r.length;e++)if(!r.hasOwnProperty(e))return!0;return!1}var f={};_("ES5",{I:function(r,t){var e=Array.isArray(r),i=function(r,t){if(r){for(var e=Array(t.length),i=0;i<t.length;i++)Object.defineProperty(e,""+i,n(i,!0));return e}var u=U(t);delete u[H];for(var o=T(u),f=0;f<o.length;f++){var a=o[f];u[a]=n(a,r||!!u[a].enumerable)}return Object.create(Object.getPrototypeOf(t),u)}(e,r),u={t:e?5:4,A:t?t.A:b(),g:!1,R:!1,N:{},l:t,u:r,k:i,i:null,O:!1,C:!1};return Object.defineProperty(i,H,{value:u,writable:!0}),i},P:function(n,i,f){f?r(i)&&i[H].A===n&&t(n.p):(n.o&&function n(r){if(r&&"object"==typeof r){var t=r[H];if(t){var i=t.u,f=t.k,a=t.N,c=t.t;if(4===c)e(f,(function(r){r!==H&&(void 0!==i[r]||u(i,r)?a[r]||n(f[r]):(a[r]=!0,E(t)))})),e(i,(function(n){void 0!==f[n]||u(f,n)||(a[n]=!1,E(t))}));else if(5===c){if(o(t)&&(E(t),a.length=!0),f.length<i.length)for(var v=f.length;v<i.length;v++)a[v]=!1;else for(var s=i.length;s<f.length;s++)a[s]=!0;for(var p=Math.min(f.length,i.length),l=0;l<p;l++)f.hasOwnProperty(l)||(a[l]=!0),void 0===a[l]&&n(f[l])}}}}(n.p[0]),t(n.p))},J:function(n){return 4===n.t?i(n):o(n)}})}function K(){function f(n){if(!t(n))return n;if(Array.isArray(n))return n.map(f);if(c(n))return new Map(Array.from(n.entries()).map((function(n){return[n[0],f(n[1])]})));if(v(n))return new Set(Array.from(n).map(f));var r=Object.create(Object.getPrototypeOf(n));for(var e in n)r[e]=f(n[e]);return u(n,G)&&(r[G]=n[G]),r}function a(n){return r(n)?f(n):n}var s="add";_("Patches",{W:function(r,t){return t.forEach((function(t){for(var e=t.path,u=t.op,a=r,c=0;c<e.length-1;c++){var v=i(a),p=e[c];"string"!=typeof p&&"number"!=typeof p&&(p=""+p),0!==v&&1!==v||"__proto__"!==p&&"constructor"!==p||n(24),"function"==typeof a&&"prototype"===p&&n(24),"object"!=typeof(a=o(a,p))&&n(15,e.join("/"))}var l=i(a),d=f(t.value),h=e[e.length-1];switch(u){case"replace":switch(l){case 2:return a.set(h,d);case 3:n(16);default:return a[h]=d}case s:switch(l){case 1:return"-"===h?a.push(d):a.splice(h,0,d);case 2:return a.set(h,d);case 3:return a.add(d);default:return a[h]=d}case"remove":switch(l){case 1:return a.splice(h,1);case 2:return a.delete(h);case 3:return a.delete(t.value);default:return delete a[h]}default:n(17,u)}})),r},F:function(n,r,t,i){switch(n.t){case 0:case 4:case 2:return function(n,r,t,i){var f=n.u,c=n.i;e(n.N,(function(n,e){var v=o(f,n),p=o(c,n),l=e?u(f,n)?"replace":s:"remove";if(v!==p||"replace"!==l){var d=r.concat(n);t.push("remove"===l?{op:l,path:d}:{op:l,path:d,value:p}),i.push(l===s?{op:"remove",path:d}:"remove"===l?{op:s,path:d,value:a(v)}:{op:"replace",path:d,value:a(v)})}}))}(n,r,t,i);case 5:case 1:return function(n,r,t,e){var i=n.u,u=n.N,o=n.i;if(o.length<i.length){var f=[o,i];i=f[0],o=f[1];var c=[e,t];t=c[0],e=c[1]}for(var v=0;v<i.length;v++)if(u[v]&&o[v]!==i[v]){var p=r.concat([v]);t.push({op:"replace",path:p,value:a(o[v])}),e.push({op:"replace",path:p,value:a(i[v])})}for(var l=i.length;l<o.length;l++){var d=r.concat([l]);t.push({op:s,path:d,value:a(o[l])})}i.length<o.length&&e.push({op:"replace",path:r.concat(["length"]),value:i.length})}(n,r,t,i);case 3:return function(n,r,t,e){var i=n.u,u=n.i,o=0;i.forEach((function(n){if(!u.has(n)){var i=r.concat([o]);t.push({op:"remove",path:i,value:n}),e.unshift({op:s,path:i,value:n})}o++})),o=0,u.forEach((function(n){if(!i.has(n)){var u=r.concat([o]);t.push({op:s,path:u,value:n}),e.unshift({op:"remove",path:u,value:n})}o++}))}(n,r,t,i)}},M:function(n,r,t,e){t.push({op:"replace",path:[],value:r===B?void 0:r}),e.push({op:"replace",path:[],value:n})}})}function $(){function r(n,r){function t(){this.constructor=n}f(n,r),n.prototype=(t.prototype=r.prototype,new t)}function i(n){n.i||(n.N=new Map,n.i=new Map(n.u))}function u(n){n.i||(n.i=new Set,n.u.forEach((function(r){if(t(r)){var e=k(n.A.h,r,n);n.p.set(r,e),n.i.add(e)}else n.i.add(r)})))}function o(r){r.O&&n(3,JSON.stringify(s(r)))}var f=function(n,r){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])})(n,r)},a=function(){function n(n,r){return this[H]={t:2,l:r,A:r?r.A:b(),g:!1,R:!1,i:void 0,N:void 0,u:n,k:this,C:!1,O:!1},this}r(n,Map);var u=n.prototype;return Object.defineProperty(u,"size",{get:function(){return s(this[H]).size}}),u.has=function(n){return s(this[H]).has(n)},u.set=function(n,r){var t=this[H];return o(t),s(t).has(n)&&s(t).get(n)===r||(i(t),E(t),t.N.set(n,!0),t.i.set(n,r),t.N.set(n,!0)),this},u.delete=function(n){if(!this.has(n))return!1;var r=this[H];return o(r),i(r),E(r),r.u.has(n)?r.N.set(n,!1):r.N.delete(n),r.i.delete(n),!0},u.clear=function(){var n=this[H];o(n),s(n).size&&(i(n),E(n),n.N=new Map,e(n.u,(function(r){n.N.set(r,!1)})),n.i.clear())},u.forEach=function(n,r){var t=this;s(this[H]).forEach((function(e,i){n.call(r,t.get(i),i,t)}))},u.get=function(n){var r=this[H];o(r);var e=s(r).get(n);if(r.R||!t(e))return e;if(e!==r.u.get(n))return e;var u=k(r.A.h,e,r);return i(r),r.i.set(n,u),u},u.keys=function(){return s(this[H]).keys()},u.values=function(){var n,r=this,t=this.keys();return(n={})[L]=function(){return r.values()},n.next=function(){var n=t.next();return n.done?n:{done:!1,value:r.get(n.value)}},n},u.entries=function(){var n,r=this,t=this.keys();return(n={})[L]=function(){return r.entries()},n.next=function(){var n=t.next();if(n.done)return n;var e=r.get(n.value);return{done:!1,value:[n.value,e]}},n},u[L]=function(){return this.entries()},n}(),c=function(){function n(n,r){return this[H]={t:3,l:r,A:r?r.A:b(),g:!1,R:!1,i:void 0,u:n,k:this,p:new Map,O:!1,C:!1},this}r(n,Set);var t=n.prototype;return Object.defineProperty(t,"size",{get:function(){return s(this[H]).size}}),t.has=function(n){var r=this[H];return o(r),r.i?!!r.i.has(n)||!(!r.p.has(n)||!r.i.has(r.p.get(n))):r.u.has(n)},t.add=function(n){var r=this[H];return o(r),this.has(n)||(u(r),E(r),r.i.add(n)),this},t.delete=function(n){if(!this.has(n))return!1;var r=this[H];return o(r),u(r),E(r),r.i.delete(n)||!!r.p.has(n)&&r.i.delete(r.p.get(n))},t.clear=function(){var n=this[H];o(n),s(n).size&&(u(n),E(n),n.i.clear())},t.values=function(){var n=this[H];return o(n),u(n),n.i.values()},t.entries=function(){var n=this[H];return o(n),u(n),n.i.entries()},t.keys=function(){return this.values()},t[L]=function(){return this.values()},t.forEach=function(n,r){for(var t=this.values(),e=t.next();!e.done;)n.call(r,e.value,e.value,this),e=t.next()},n}();_("MapSet",{K:function(n,r){return new a(n,r)},$:function(n,r){return new c(n,r)}})}var C;Object.defineProperty(exports,"__esModule",{value:!0});var I,J="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),W="undefined"!=typeof Map,X="undefined"!=typeof Set,q="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,B=J?Symbol.for("immer-nothing"):((C={})["immer-nothing"]=!0,C),G=J?Symbol.for("immer-draftable"):"__$immer_draftable",H=J?Symbol.for("immer-state"):"__$immer_state",L="undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator",Q=""+Object.prototype.constructor,T="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:Object.getOwnPropertyNames,U=Object.getOwnPropertyDescriptors||function(n){var r={};return T(n).forEach((function(t){r[t]=Object.getOwnPropertyDescriptor(n,t)})),r},V={},Y={get:function(n,r){if(r===H)return n;var e=s(n);if(!u(e,r))return function(n,r,t){var e,i=z(r,t);return i?"value"in i?i.value:null===(e=i.get)||void 0===e?void 0:e.call(n.k):void 0}(n,e,r);var i=e[r];return n.R||!t(i)?i:i===A(n.u,r)?(R(n),n.i[r]=k(n.A.h,i,n)):i},has:function(n,r){return r in s(n)},ownKeys:function(n){return Reflect.ownKeys(s(n))},set:function(n,r,t){var e=z(s(n),r);if(null==e?void 0:e.set)return e.set.call(n.k,t),!0;if(!n.g){var i=A(s(n),r),o=null==i?void 0:i[H];if(o&&o.u===t)return n.i[r]=t,n.N[r]=!1,!0;if(a(t,i)&&(void 0!==t||u(n.u,r)))return!0;R(n),E(n)}return n.i[r]===t&&(void 0!==t||r in n.i)||Number.isNaN(t)&&Number.isNaN(n.i[r])||(n.i[r]=t,n.N[r]=!0),!0},deleteProperty:function(n,r){return void 0!==A(n.u,r)||r in n.u?(n.N[r]=!1,R(n),E(n)):delete n.N[r],n.i&&delete n.i[r],!0},getOwnPropertyDescriptor:function(n,r){var t=s(n),e=Reflect.getOwnPropertyDescriptor(t,r);return e?{writable:!0,configurable:1!==n.t||"length"!==r,enumerable:e.enumerable,value:t[r]}:e},defineProperty:function(){n(11)},getPrototypeOf:function(n){return Object.getPrototypeOf(n.u)},setPrototypeOf:function(){n(12)}},Z={};e(Y,(function(n,r){Z[n]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}})),Z.deleteProperty=function(n,r){return Z.set.call(this,n,r,void 0)},Z.set=function(n,r,t){return Y.set.call(this,n[0],r,t,n[0])};var nn=function(){function e(r){var e=this;this.S=q,this.D=!0,this.produce=function(r,i,u){if("function"==typeof r&&"function"!=typeof i){var o=i;i=r;var f=e;return function(n){var r=this;void 0===n&&(n=o);for(var t=arguments.length,e=Array(t>1?t-1:0),u=1;u<t;u++)e[u-1]=arguments[u];return f.produce(n,(function(n){var t;return(t=i).call.apply(t,[r,n].concat(e))}))}}var a;if("function"!=typeof i&&n(6),void 0!==u&&"function"!=typeof u&&n(7),t(r)){var c=x(e),v=k(e,r,void 0),s=!0;try{a=i(v),s=!1}finally{s?j(c):O(c)}return"undefined"!=typeof Promise&&a instanceof Promise?a.then((function(n){return m(c,u),S(n,c)}),(function(n){throw j(c),n})):(m(c,u),S(a,c))}if(!r||"object"!=typeof r){if(void 0===(a=i(r))&&(a=r),a===B&&(a=void 0),e.D&&l(a,!0),u){var p=[],d=[];y("Patches").M(r,a,p,d),u(p,d)}return a}n(21,r)},this.produceWithPatches=function(n,r){if("function"==typeof n)return function(r){for(var t=arguments.length,i=Array(t>1?t-1:0),u=1;u<t;u++)i[u-1]=arguments[u];return e.produceWithPatches(r,(function(r){return n.apply(void 0,[r].concat(i))}))};var t,i,u=e.produce(n,r,(function(n,r){t=n,i=r}));return"undefined"!=typeof Promise&&u instanceof Promise?u.then((function(n){return[n,t,i]})):[u,t,i]},"boolean"==typeof(null==r?void 0:r.useProxies)&&this.setUseProxies(r.useProxies),"boolean"==typeof(null==r?void 0:r.autoFreeze)&&this.setAutoFreeze(r.autoFreeze)}var i=e.prototype;return i.createDraft=function(e){t(e)||n(8),r(e)&&(e=F(e));var i=x(this),u=k(this,e,void 0);return u[H].C=!0,O(i),u},i.finishDraft=function(n,r){var t=(n&&n[H]).A;return m(t,r),S(void 0,t)},i.setAutoFreeze=function(n){this.D=n},i.setUseProxies=function(r){r&&!q&&n(20),this.S=r},i.applyPatches=function(n,t){var e;for(e=t.length-1;e>=0;e--){var i=t[e];if(0===i.path.length&&"replace"===i.op){n=i.value;break}}e>-1&&(t=t.slice(e+1));var u=y("Patches").W;return r(n)?u(n,t):this.produce(n,(function(n){return u(n,t)}))},e}(),rn=new nn,tn=rn.produce,en=rn.produceWithPatches.bind(rn),un=rn.setAutoFreeze.bind(rn),on=rn.setUseProxies.bind(rn),fn=rn.applyPatches.bind(rn),an=rn.createDraft.bind(rn),cn=rn.finishDraft.bind(rn);exports.Immer=nn,exports.applyPatches=fn,exports.castDraft=function(n){return n},exports.castImmutable=function(n){return n},exports.createDraft=an,exports.current=F,exports.default=tn,exports.enableAllPlugins=function(){D(),$(),K()},exports.enableES5=D,exports.enableMapSet=$,exports.enablePatches=K,exports.finishDraft=cn,exports.freeze=l,exports.immerable=G,exports.isDraft=r,exports.isDraftable=t,exports.nothing=B,exports.original=function(t){return r(t)||n(23,t),t[H].u},exports.produce=tn,exports.produceWithPatches=en,exports.setAutoFreeze=un,exports.setUseProxies=on;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=Symbol.for("immer-nothing"),t=Symbol.for("immer-draftable"),r=Symbol.for("immer-state");function n(e){throw new Error("[Immer] minified error nr: "+e+". Full error at: https://bit.ly/3cXEKWf")}function o(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o),n)}var o}function a(e,t,r){return t&&o(e.prototype,t),r&&o(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function i(){return(i=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,s(e,t)}function c(e){return(c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function f(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function p(e,t,r){return(p=f()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&s(o,r.prototype),o}).apply(null,arguments)}function l(e){var t="function"==typeof Map?new Map:void 0;return(l=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return p(e,arguments,c(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)})(e)}function _(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e){return!!e&&!!e[r]}function h(e){var r;return!!e&&(d(e)||Array.isArray(e)||!!e[t]||!(null==(r=e.constructor)||!r[t])||P(e)||S(e))}var y=Object.prototype.constructor.toString();function d(e){if(!e||"object"!=typeof e)return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;var r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===y}function b(e,t){0===g(e)?Object.entries(e).forEach((function(r){t(r[0],r[1],e)})):e.forEach((function(r,n){return t(n,r,e)}))}function g(e){var t=e[r];return t?t.type_:Array.isArray(e)?1:P(e)?2:S(e)?3:0}function m(e,t){return 2===g(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function w(e,t){return 2===g(e)?e.get(t):e[t]}function O(e,t,r){var n=g(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function P(e){return e instanceof Map}function S(e){return e instanceof Set}function j(e){return e.copy_||e.base_}function z(e,t){if(P(e))return new Map(e);if(S(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);if(!t&&d(e)){if(!Object.getPrototypeOf(e)){var n=Object.create(null);return Object.assign(n,e)}return i({},e)}var o=Object.getOwnPropertyDescriptors(e);delete o[r];for(var a=Reflect.ownKeys(o),u=0;u<a.length;u++){var c=a[u],s=o[c];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(o[c]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[c]})}return Object.create(Object.getPrototypeOf(e),o)}function x(e,t){return void 0===t&&(t=!1),F(e)||v(e)||!h(e)||(g(e)>1&&(e.set=e.add=e.clear=e.delete=A),Object.freeze(e),t&&b(e,(function(e,t){return x(t,!0)}))),e}function A(){n(2)}function F(e){return Object.isFrozen(e)}var k,D={};function M(e){var t=D[e];return t||n(0),t}function E(){return k}function R(e,t){t&&(M("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function C(e){N(e),e.drafts_.forEach(K),e.drafts_=null}function N(e){e===k&&(k=e.parent_)}function W(e){return k={drafts_:[],parent_:k,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function K(e){var t=e[r];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function U(t,o){o.unfinalizedDrafts_=o.drafts_.length;var a=o.drafts_[0];return void 0!==t&&t!==a?(a[r].modified_&&(C(o),n(4)),h(t)&&(t=I(o,t),o.parent_||L(o,t)),o.patches_&&M("Patches").generateReplacementPatches_(a[r].base_,t,o.patches_,o.inversePatches_)):t=I(o,a,[]),C(o),o.patches_&&o.patchListener_(o.patches_,o.inversePatches_),t!==e?t:void 0}function I(e,t,n){if(F(t))return t;var o=t[r];if(!o)return b(t,(function(r,a){return B(e,o,t,r,a,n)})),t;if(o.scope_!==e)return t;if(!o.modified_)return L(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;var a=o.copy_,i=a,u=!1;3===o.type_&&(i=new Set(a),a.clear(),u=!0),b(i,(function(t,r){return B(e,o,a,t,r,n,u)})),L(e,a,!1),n&&e.patches_&&M("Patches").generatePatches_(o,n,e.patches_,e.inversePatches_)}return o.copy_}function B(e,t,r,n,o,a,i){if(v(o)){var u=I(e,o,a&&t&&3!==t.type_&&!m(t.assigned_,n)?a.concat(n):void 0);if(O(r,n,u),!v(u))return;e.canAutoFreeze_=!1}else i&&r.add(o);if(h(o)&&!F(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;I(e,o),t&&t.scope_.parent_||L(e,o)}}function L(e,t,r){void 0===r&&(r=!1),!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&x(t,r)}var T={get:function(e,t){if(t===r)return e;var n=j(e);if(!m(n,t))return function(e,t,r){var n,o=q(t,r);return o?"value"in o?o.value:null==(n=o.get)?void 0:n.call(e.draft_):void 0}(e,n,t);var o=n[t];return e.finalized_||!h(o)?o:o===X(e.base_,t)?(H(e),e.copy_[t]=V(o,e)):o},has:function(e,t){return t in j(e)},ownKeys:function(e){return Reflect.ownKeys(j(e))},set:function(e,t,n){var o,a,i=q(j(e),t);if(null!=i&&i.set)return i.set.call(e.draft_,n),!0;if(!e.modified_){var u=X(j(e),t),c=null==u?void 0:u[r];if(c&&c.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(((o=n)===(a=u)?0!==o||1/o==1/a:o!=o&&a!=a)&&(void 0!==n||m(e.base_,t)))return!0;H(e),G(e)}return e.copy_[t]===n&&(void 0!==n||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty:function(e,t){return void 0!==X(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,H(e),G(e)):delete e.assigned_[t],delete e.copy_[t],!0},getOwnPropertyDescriptor:function(e,t){var r=j(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n?{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}:n},defineProperty:function(){n(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.base_)},setPrototypeOf:function(){n(12)}},J={};function X(e,t){var n=e[r];return(n?j(n):e)[t]}function q(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=Object.getPrototypeOf(r)}}function G(e){e.modified_||(e.modified_=!0,e.parent_&&G(e.parent_))}function H(e){e.copy_||(e.copy_=z(e.base_,e.scope_.immer_.useStrictShallowCopy_))}b(T,(function(e,t){J[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),J.deleteProperty=function(e,t){return J.set.call(this,e,t,void 0)},J.set=function(e,t,r){return T.set.call(this,e[0],t,r,e[0])};var Q=function(){function t(t){var r=this;this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=function(t,o,a){if("function"==typeof t&&"function"!=typeof o){var i=o;o=t;var u=r;return function(e){var t=this;void 0===e&&(e=i);for(var r=arguments.length,n=new Array(r>1?r-1:0),a=1;a<r;a++)n[a-1]=arguments[a];return u.produce(e,(function(e){var r;return(r=o).call.apply(r,[t,e].concat(n))}))}}var c;if("function"!=typeof o&&n(6),void 0!==a&&"function"!=typeof a&&n(7),h(t)){var s=W(r),f=V(t,void 0),p=!0;try{c=o(f),p=!1}finally{p?C(s):N(s)}return R(s,a),U(c,s)}if(!t||"object"!=typeof t){if(void 0===(c=o(t))&&(c=t),c===e&&(c=void 0),r.autoFreeze_&&x(c,!0),a){var l=[],_=[];M("Patches").generateReplacementPatches_(t,c,l,_),a(l,_)}return c}n(1)},this.produceWithPatches=function(e,t){return"function"==typeof e?function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),a=1;a<n;a++)o[a-1]=arguments[a];return r.produceWithPatches(t,(function(t){return e.apply(void 0,[t].concat(o))}))}:[r.produce(e,t,(function(e,t){n=e,o=t})),n,o];var n,o},"boolean"==typeof(null==t?void 0:t.autoFreeze)&&this.setAutoFreeze(t.autoFreeze),"boolean"==typeof(null==t?void 0:t.useStrictShallowCopy)&&this.setUseStrictShallowCopy(t.useStrictShallowCopy)}var o=t.prototype;return o.createDraft=function(e){h(e)||n(8),v(e)&&(e=Y(e));var t=W(this),o=V(e,void 0);return o[r].isManual_=!0,N(t),o},o.finishDraft=function(e,t){var o=e&&e[r];o&&o.isManual_||n(9);var a=o.scope_;return R(a,t),U(void 0,a)},o.setAutoFreeze=function(e){this.autoFreeze_=e},o.setUseStrictShallowCopy=function(e){this.useStrictShallowCopy_=e},o.applyPatches=function(e,t){var r;for(r=t.length-1;r>=0;r--){var n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));var o=M("Patches").applyPatches_;return v(e)?o(e,t):this.produce(e,(function(e){return o(e,t)}))},t}();function V(e,t){var r=P(e)?function(e,t){return new Z(e,t)}(e,t):S(e)?function(e,t){return new ee(e,t)}(e,t):function(e,t){var r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:E(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=n,a=T;r&&(o=[n],a=J);var i=Proxy.revocable(o,a),u=i.revoke,c=i.proxy;return n.draft_=c,n.revoke_=u,c}(e,t);return(t?t.scope_:E()).drafts_.push(r),r}function Y(e){return v(e)||n(10),function e(t){if(!h(t)||F(t))return t;var n,o=t[r];if(o){if(!o.modified_)return o.base_;o.finalized_=!0,n=z(t,o.scope_.immer_.useStrictShallowCopy_)}else n=z(t,!0);return b(n,(function(t,r){O(n,t,e(r))})),o&&(o.finalized_=!1),n}(e)}var Z=function(e,t){function n(t,n){var o;return(o=e.call(this)||this)[r]={type_:2,parent_:n,scope_:n?n.scope_:E(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:t,draft_:_(o),isManual_:!1,revoked_:!1},o}u(n,e);var o=n.prototype;return o.has=function(e){return j(this[r]).has(e)},o.set=function(e,t){var n=this[r];return re(n),j(n).has(e)&&j(n).get(e)===t||($(n),G(n),n.assigned_.set(e,!0),n.copy_.set(e,t),n.assigned_.set(e,!0)),this},o.delete=function(e){if(!this.has(e))return!1;var t=this[r];return re(t),$(t),G(t),t.base_.has(e)?t.assigned_.set(e,!1):t.assigned_.delete(e),t.copy_.delete(e),!0},o.clear=function(){var e=this[r];re(e),j(e).size&&($(e),G(e),e.assigned_=new Map,b(e.base_,(function(t){e.assigned_.set(t,!1)})),e.copy_.clear())},o.forEach=function(e,t){var n=this;j(this[r]).forEach((function(r,o,a){e.call(t,n.get(o),o,n)}))},o.get=function(e){var t=this[r];re(t);var n=j(t).get(e);if(t.finalized_||!h(n))return n;if(n!==t.base_.get(e))return n;var o=V(n,t);return $(t),t.copy_.set(e,o),o},o.keys=function(){return j(this[r]).keys()},o.values=function(){var e,t=this,r=this.keys();return(e={})[Symbol.iterator]=function(){return t.values()},e.next=function(){var e=r.next();return e.done?e:{done:!1,value:t.get(e.value)}},e},o.entries=function(){var e,t=this,r=this.keys();return(e={})[Symbol.iterator]=function(){return t.entries()},e.next=function(){var e=r.next();if(e.done)return e;var n=t.get(e.value);return{done:!1,value:[e.value,n]}},e},o[t]=function(){return this.entries()},a(n,[{key:"size",get:function(){return j(this[r]).size}}]),n}(l(Map),Symbol.iterator);function $(e){e.copy_||(e.assigned_=new Map,e.copy_=new Map(e.base_))}var ee=function(e,t){function n(t,n){var o;return(o=e.call(this)||this)[r]={type_:3,parent_:n,scope_:n?n.scope_:E(),modified_:!1,finalized_:!1,copy_:void 0,base_:t,draft_:_(o),drafts_:new Map,revoked_:!1,isManual_:!1},o}u(n,e);var o=n.prototype;return o.has=function(e){var t=this[r];return re(t),t.copy_?!!t.copy_.has(e)||!(!t.drafts_.has(e)||!t.copy_.has(t.drafts_.get(e))):t.base_.has(e)},o.add=function(e){var t=this[r];return re(t),this.has(e)||(te(t),G(t),t.copy_.add(e)),this},o.delete=function(e){if(!this.has(e))return!1;var t=this[r];return re(t),te(t),G(t),t.copy_.delete(e)||!!t.drafts_.has(e)&&t.copy_.delete(t.drafts_.get(e))},o.clear=function(){var e=this[r];re(e),j(e).size&&(te(e),G(e),e.copy_.clear())},o.values=function(){var e=this[r];return re(e),te(e),e.copy_.values()},o.entries=function(){var e=this[r];return re(e),te(e),e.copy_.entries()},o.keys=function(){return this.values()},o[t]=function(){return this.values()},o.forEach=function(e,t){for(var r=this.values(),n=r.next();!n.done;)e.call(t,n.value,n.value,this),n=r.next()},a(n,[{key:"size",get:function(){return j(this[r]).size}}]),n}(l(Set),Symbol.iterator);function te(e){e.copy_||(e.copy_=new Set,e.base_.forEach((function(t){if(h(t)){var r=V(t,e);e.drafts_.set(t,r),e.copy_.add(r)}else e.copy_.add(t)})))}function re(e){e.revoked_&&n(3,JSON.stringify(j(e)))}var ne=new Q,oe=ne.produce,ae=ne.produceWithPatches.bind(ne),ie=ne.setAutoFreeze.bind(ne),ue=ne.setUseStrictShallowCopy.bind(ne),ce=ne.applyPatches.bind(ne),se=ne.createDraft.bind(ne),fe=ne.finishDraft.bind(ne);exports.Immer=Q,exports.applyPatches=ce,exports.castDraft=function(e){return e},exports.castImmutable=function(e){return e},exports.createDraft=se,exports.current=Y,exports.enablePatches=function(){var r="add";function o(e){if(!h(e))return e;if(Array.isArray(e))return e.map(o);if(P(e))return new Map(Array.from(e.entries()).map((function(e){return[e[0],o(e[1])]})));if(S(e))return new Set(Array.from(e).map(o));var r=Object.create(Object.getPrototypeOf(e));for(var n in e)r[n]=o(e[n]);return m(e,t)&&(r[t]=e[t]),r}function a(e){return v(e)?o(e):e}D.Patches||(D.Patches={applyPatches_:function(e,t){return t.forEach((function(t){for(var a=t.path,i=t.op,u=e,c=0;c<a.length-1;c++){var s=g(u),f=a[c];"string"!=typeof f&&"number"!=typeof f&&(f=""+f),0!==s&&1!==s||"__proto__"!==f&&"constructor"!==f||n(19),"function"==typeof u&&"prototype"===f&&n(19),"object"!=typeof(u=w(u,f))&&n(18,a.join("/"))}var p=g(u),l=o(t.value),_=a[a.length-1];switch(i){case"replace":switch(p){case 2:return u.set(_,l);case 3:n(16);default:return u[_]=l}case r:switch(p){case 1:return"-"===_?u.push(l):u.splice(_,0,l);case 2:return u.set(_,l);case 3:return u.add(l);default:return u[_]=l}case"remove":switch(p){case 1:return u.splice(_,1);case 2:return u.delete(_);case 3:return u.delete(t.value);default:return delete u[_]}default:n(17)}})),e},generatePatches_:function(e,t,n,o){switch(e.type_){case 0:case 2:return function(e,t,n,o){var i=e.base_,u=e.copy_;b(e.assigned_,(function(e,c){var s=w(i,e),f=w(u,e),p=c?m(i,e)?"replace":r:"remove";if(s!==f||"replace"!==p){var l=t.concat(e);n.push("remove"===p?{op:p,path:l}:{op:p,path:l,value:f}),o.push(p===r?{op:"remove",path:l}:"remove"===p?{op:r,path:l,value:a(s)}:{op:"replace",path:l,value:a(s)})}}))}(e,t,n,o);case 1:return function(e,t,n,o){var i=e.base_,u=e.assigned_,c=e.copy_;if(c.length<i.length){var s=[c,i];i=s[0],c=s[1];var f=[o,n];n=f[0],o=f[1]}for(var p=0;p<i.length;p++)if(u[p]&&c[p]!==i[p]){var l=t.concat([p]);n.push({op:"replace",path:l,value:a(c[p])}),o.push({op:"replace",path:l,value:a(i[p])})}for(var _=i.length;_<c.length;_++){var v=t.concat([_]);n.push({op:r,path:v,value:a(c[_])})}for(var h=c.length-1;i.length<=h;--h){var y=t.concat([h]);o.push({op:"remove",path:y})}}(e,t,n,o);case 3:return function(e,t,n,o){var a=e.base_,i=e.copy_,u=0;a.forEach((function(e){if(!i.has(e)){var a=t.concat([u]);n.push({op:"remove",path:a,value:e}),o.unshift({op:r,path:a,value:e})}u++})),u=0,i.forEach((function(e){if(!a.has(e)){var i=t.concat([u]);n.push({op:r,path:i,value:e}),o.unshift({op:"remove",path:i,value:e})}u++}))}(e,t,n,o)}},generateReplacementPatches_:function(t,r,n,o){n.push({op:"replace",path:[],value:r===e?void 0:r}),o.push({op:"replace",path:[],value:t})}})},exports.finishDraft=fe,exports.freeze=x,exports.immerable=t,exports.isDraft=v,exports.isDraftable=h,exports.nothing=e,exports.original=function(e){return v(e)||n(15),e[r].base_},exports.produce=oe,exports.produceWithPatches=ae,exports.setAutoFreeze=ie,exports.setUseStrictShallowCopy=ue;
//# sourceMappingURL=immer.cjs.production.min.js.map

@@ -23,3 +23,2 @@ import { IProduce, IProduceWithPatches, Immer, Draft, Immutable } from "./internal";

export declare const produce: IProduce;
export default produce;
/**

@@ -37,8 +36,7 @@ * Like `produce`, but `produceWithPatches` always returns a tuple

/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
export declare const setUseProxies: (value: boolean) => void;
export declare const setUseStrictShallowCopy: (value: boolean) => void;
/**

@@ -78,6 +76,3 @@ * Apply an array of Immer patches to the first argument.

export { Immer };
export { enableES5 } from "./plugins/es5";
export { enablePatches } from "./plugins/patches";
export { enableMapSet } from "./plugins/mapset";
export { enableAllPlugins } from "./plugins/all";
//# sourceMappingURL=immer.d.ts.map

@@ -1,2 +0,1468 @@

function n(n){for(var r=arguments.length,t=Array(r>1?r-1:0),e=1;e<r;e++)t[e-1]=arguments[e];if("production"!==process.env.NODE_ENV){var i=Y[n],o=i?"function"==typeof i?i.apply(null,t):i:"unknown error nr: "+n;throw Error("[Immer] "+o)}throw Error("[Immer] minified error nr: "+n+(t.length?" "+t.map((function(n){return"'"+n+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function r(n){return!!n&&!!n[Q]}function t(n){var r;return!!n&&(function(n){if(!n||"object"!=typeof n)return!1;var r=Object.getPrototypeOf(n);if(null===r)return!0;var t=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return t===Object||"function"==typeof t&&Function.toString.call(t)===Z}(n)||Array.isArray(n)||!!n[L]||!!(null===(r=n.constructor)||void 0===r?void 0:r[L])||s(n)||v(n))}function e(t){return r(t)||n(23,t),t[Q].t}function i(n,r,t){void 0===t&&(t=!1),0===o(n)?(t?Object.keys:nn)(n).forEach((function(e){t&&"symbol"==typeof e||r(e,n[e],n)})):n.forEach((function(t,e){return r(e,t,n)}))}function o(n){var r=n[Q];return r?r.i>3?r.i-4:r.i:Array.isArray(n)?1:s(n)?2:v(n)?3:0}function u(n,r){return 2===o(n)?n.has(r):Object.prototype.hasOwnProperty.call(n,r)}function a(n,r){return 2===o(n)?n.get(r):n[r]}function f(n,r,t){var e=o(n);2===e?n.set(r,t):3===e?n.add(t):n[r]=t}function c(n,r){return n===r?0!==n||1/n==1/r:n!=n&&r!=r}function s(n){return X&&n instanceof Map}function v(n){return q&&n instanceof Set}function p(n){return n.o||n.t}function l(n){if(Array.isArray(n))return Array.prototype.slice.call(n);var r=rn(n);delete r[Q];for(var t=nn(r),e=0;e<t.length;e++){var i=t[e],o=r[i];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(r[i]={configurable:!0,writable:!0,enumerable:o.enumerable,value:n[i]})}return Object.create(Object.getPrototypeOf(n),r)}function d(n,e){return void 0===e&&(e=!1),y(n)||r(n)||!t(n)||(o(n)>1&&(n.set=n.add=n.clear=n.delete=h),Object.freeze(n),e&&i(n,(function(n,r){return d(r,!0)}),!0)),n}function h(){n(2)}function y(n){return null==n||"object"!=typeof n||Object.isFrozen(n)}function b(r){var t=tn[r];return t||n(18,r),t}function m(n,r){tn[n]||(tn[n]=r)}function _(){return"production"===process.env.NODE_ENV||U||n(0),U}function j(n,r){r&&(b("Patches"),n.u=[],n.s=[],n.v=r)}function g(n){O(n),n.p.forEach(S),n.p=null}function O(n){n===U&&(U=n.l)}function w(n){return U={p:[],l:U,h:n,m:!0,_:0}}function S(n){var r=n[Q];0===r.i||1===r.i?r.j():r.g=!0}function P(r,e){e._=e.p.length;var i=e.p[0],o=void 0!==r&&r!==i;return e.h.O||b("ES5").S(e,r,o),o?(i[Q].P&&(g(e),n(4)),t(r)&&(r=M(e,r),e.l||x(e,r)),e.u&&b("Patches").M(i[Q].t,r,e.u,e.s)):r=M(e,i,[]),g(e),e.u&&e.v(e.u,e.s),r!==H?r:void 0}function M(n,r,t){if(y(r))return r;var e=r[Q];if(!e)return i(r,(function(i,o){return A(n,e,r,i,o,t)}),!0),r;if(e.A!==n)return r;if(!e.P)return x(n,e.t,!0),e.t;if(!e.I){e.I=!0,e.A._--;var o=4===e.i||5===e.i?e.o=l(e.k):e.o,u=o,a=!1;3===e.i&&(u=new Set(o),o.clear(),a=!0),i(u,(function(r,i){return A(n,e,o,r,i,t,a)})),x(n,o,!1),t&&n.u&&b("Patches").N(e,t,n.u,n.s)}return e.o}function A(e,i,o,a,c,s,v){if("production"!==process.env.NODE_ENV&&c===o&&n(5),r(c)){var p=M(e,c,s&&i&&3!==i.i&&!u(i.R,a)?s.concat(a):void 0);if(f(o,a,p),!r(p))return;e.m=!1}else v&&o.add(c);if(t(c)&&!y(c)){if(!e.h.D&&e._<1)return;M(e,c),i&&i.A.l||x(e,c)}}function x(n,r,t){void 0===t&&(t=!1),!n.l&&n.h.D&&n.m&&d(r,t)}function z(n,r){var t=n[Q];return(t?p(t):n)[r]}function I(n,r){if(r in n)for(var t=Object.getPrototypeOf(n);t;){var e=Object.getOwnPropertyDescriptor(t,r);if(e)return e;t=Object.getPrototypeOf(t)}}function k(n){n.P||(n.P=!0,n.l&&k(n.l))}function E(n){n.o||(n.o=l(n.t))}function N(n,r,t){var e=s(r)?b("MapSet").F(r,t):v(r)?b("MapSet").T(r,t):n.O?function(n,r){var t=Array.isArray(n),e={i:t?1:0,A:r?r.A:_(),P:!1,I:!1,R:{},l:r,t:n,k:null,o:null,j:null,C:!1},i=e,o=en;t&&(i=[e],o=on);var u=Proxy.revocable(i,o),a=u.revoke,f=u.proxy;return e.k=f,e.j=a,f}(r,t):b("ES5").J(r,t);return(t?t.A:_()).p.push(e),e}function R(e){return r(e)||n(22,e),function n(r){if(!t(r))return r;var e,u=r[Q],c=o(r);if(u){if(!u.P&&(u.i<4||!b("ES5").K(u)))return u.t;u.I=!0,e=D(r,c),u.I=!1}else e=D(r,c);return i(e,(function(r,t){u&&a(u.t,r)===t||f(e,r,n(t))})),3===c?new Set(e):e}(e)}function D(n,r){switch(r){case 2:return new Map(n);case 3:return Array.from(n)}return l(n)}function F(){function t(n,r){var t=s[n];return t?t.enumerable=r:s[n]=t={configurable:!0,enumerable:r,get:function(){var r=this[Q];return"production"!==process.env.NODE_ENV&&f(r),en.get(r,n)},set:function(r){var t=this[Q];"production"!==process.env.NODE_ENV&&f(t),en.set(t,n,r)}},t}function e(n){for(var r=n.length-1;r>=0;r--){var t=n[r][Q];if(!t.P)switch(t.i){case 5:a(t)&&k(t);break;case 4:o(t)&&k(t)}}}function o(n){for(var r=n.t,t=n.k,e=nn(t),i=e.length-1;i>=0;i--){var o=e[i];if(o!==Q){var a=r[o];if(void 0===a&&!u(r,o))return!0;var f=t[o],s=f&&f[Q];if(s?s.t!==a:!c(f,a))return!0}}var v=!!r[Q];return e.length!==nn(r).length+(v?0:1)}function a(n){var r=n.k;if(r.length!==n.t.length)return!0;var t=Object.getOwnPropertyDescriptor(r,r.length-1);if(t&&!t.get)return!0;for(var e=0;e<r.length;e++)if(!r.hasOwnProperty(e))return!0;return!1}function f(r){r.g&&n(3,JSON.stringify(p(r)))}var s={};m("ES5",{J:function(n,r){var e=Array.isArray(n),i=function(n,r){if(n){for(var e=Array(r.length),i=0;i<r.length;i++)Object.defineProperty(e,""+i,t(i,!0));return e}var o=rn(r);delete o[Q];for(var u=nn(o),a=0;a<u.length;a++){var f=u[a];o[f]=t(f,n||!!o[f].enumerable)}return Object.create(Object.getPrototypeOf(r),o)}(e,n),o={i:e?5:4,A:r?r.A:_(),P:!1,I:!1,R:{},l:r,t:n,k:i,o:null,g:!1,C:!1};return Object.defineProperty(i,Q,{value:o,writable:!0}),i},S:function(n,t,o){o?r(t)&&t[Q].A===n&&e(n.p):(n.u&&function n(r){if(r&&"object"==typeof r){var t=r[Q];if(t){var e=t.t,o=t.k,f=t.R,c=t.i;if(4===c)i(o,(function(r){r!==Q&&(void 0!==e[r]||u(e,r)?f[r]||n(o[r]):(f[r]=!0,k(t)))})),i(e,(function(n){void 0!==o[n]||u(o,n)||(f[n]=!1,k(t))}));else if(5===c){if(a(t)&&(k(t),f.length=!0),o.length<e.length)for(var s=o.length;s<e.length;s++)f[s]=!1;else for(var v=e.length;v<o.length;v++)f[v]=!0;for(var p=Math.min(o.length,e.length),l=0;l<p;l++)o.hasOwnProperty(l)||(f[l]=!0),void 0===f[l]&&n(o[l])}}}}(n.p[0]),e(n.p))},K:function(n){return 4===n.i?o(n):a(n)}})}function T(){function e(n){if(!t(n))return n;if(Array.isArray(n))return n.map(e);if(s(n))return new Map(Array.from(n.entries()).map((function(n){return[n[0],e(n[1])]})));if(v(n))return new Set(Array.from(n).map(e));var r=Object.create(Object.getPrototypeOf(n));for(var i in n)r[i]=e(n[i]);return u(n,L)&&(r[L]=n[L]),r}function f(n){return r(n)?e(n):n}var c="add";m("Patches",{$:function(r,t){return t.forEach((function(t){for(var i=t.path,u=t.op,f=r,s=0;s<i.length-1;s++){var v=o(f),p=i[s];"string"!=typeof p&&"number"!=typeof p&&(p=""+p),0!==v&&1!==v||"__proto__"!==p&&"constructor"!==p||n(24),"function"==typeof f&&"prototype"===p&&n(24),"object"!=typeof(f=a(f,p))&&n(15,i.join("/"))}var l=o(f),d=e(t.value),h=i[i.length-1];switch(u){case"replace":switch(l){case 2:return f.set(h,d);case 3:n(16);default:return f[h]=d}case c:switch(l){case 1:return"-"===h?f.push(d):f.splice(h,0,d);case 2:return f.set(h,d);case 3:return f.add(d);default:return f[h]=d}case"remove":switch(l){case 1:return f.splice(h,1);case 2:return f.delete(h);case 3:return f.delete(t.value);default:return delete f[h]}default:n(17,u)}})),r},N:function(n,r,t,e){switch(n.i){case 0:case 4:case 2:return function(n,r,t,e){var o=n.t,s=n.o;i(n.R,(function(n,i){var v=a(o,n),p=a(s,n),l=i?u(o,n)?"replace":c:"remove";if(v!==p||"replace"!==l){var d=r.concat(n);t.push("remove"===l?{op:l,path:d}:{op:l,path:d,value:p}),e.push(l===c?{op:"remove",path:d}:"remove"===l?{op:c,path:d,value:f(v)}:{op:"replace",path:d,value:f(v)})}}))}(n,r,t,e);case 5:case 1:return function(n,r,t,e){var i=n.t,o=n.R,u=n.o;if(u.length<i.length){var a=[u,i];i=a[0],u=a[1];var s=[e,t];t=s[0],e=s[1]}for(var v=0;v<i.length;v++)if(o[v]&&u[v]!==i[v]){var p=r.concat([v]);t.push({op:"replace",path:p,value:f(u[v])}),e.push({op:"replace",path:p,value:f(i[v])})}for(var l=i.length;l<u.length;l++){var d=r.concat([l]);t.push({op:c,path:d,value:f(u[l])})}i.length<u.length&&e.push({op:"replace",path:r.concat(["length"]),value:i.length})}(n,r,t,e);case 3:return function(n,r,t,e){var i=n.t,o=n.o,u=0;i.forEach((function(n){if(!o.has(n)){var i=r.concat([u]);t.push({op:"remove",path:i,value:n}),e.unshift({op:c,path:i,value:n})}u++})),u=0,o.forEach((function(n){if(!i.has(n)){var o=r.concat([u]);t.push({op:c,path:o,value:n}),e.unshift({op:"remove",path:o,value:n})}u++}))}(n,r,t,e)}},M:function(n,r,t,e){t.push({op:"replace",path:[],value:r===H?void 0:r}),e.push({op:"replace",path:[],value:n})}})}function C(){function r(n,r){function t(){this.constructor=n}a(n,r),n.prototype=(t.prototype=r.prototype,new t)}function e(n){n.o||(n.R=new Map,n.o=new Map(n.t))}function o(n){n.o||(n.o=new Set,n.t.forEach((function(r){if(t(r)){var e=N(n.A.h,r,n);n.p.set(r,e),n.o.add(e)}else n.o.add(r)})))}function u(r){r.g&&n(3,JSON.stringify(p(r)))}var a=function(n,r){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var t in r)r.hasOwnProperty(t)&&(n[t]=r[t])})(n,r)},f=function(){function n(n,r){return this[Q]={i:2,l:r,A:r?r.A:_(),P:!1,I:!1,o:void 0,R:void 0,t:n,k:this,C:!1,g:!1},this}r(n,Map);var o=n.prototype;return Object.defineProperty(o,"size",{get:function(){return p(this[Q]).size}}),o.has=function(n){return p(this[Q]).has(n)},o.set=function(n,r){var t=this[Q];return u(t),p(t).has(n)&&p(t).get(n)===r||(e(t),k(t),t.R.set(n,!0),t.o.set(n,r),t.R.set(n,!0)),this},o.delete=function(n){if(!this.has(n))return!1;var r=this[Q];return u(r),e(r),k(r),r.t.has(n)?r.R.set(n,!1):r.R.delete(n),r.o.delete(n),!0},o.clear=function(){var n=this[Q];u(n),p(n).size&&(e(n),k(n),n.R=new Map,i(n.t,(function(r){n.R.set(r,!1)})),n.o.clear())},o.forEach=function(n,r){var t=this;p(this[Q]).forEach((function(e,i){n.call(r,t.get(i),i,t)}))},o.get=function(n){var r=this[Q];u(r);var i=p(r).get(n);if(r.I||!t(i))return i;if(i!==r.t.get(n))return i;var o=N(r.A.h,i,r);return e(r),r.o.set(n,o),o},o.keys=function(){return p(this[Q]).keys()},o.values=function(){var n,r=this,t=this.keys();return(n={})[V]=function(){return r.values()},n.next=function(){var n=t.next();return n.done?n:{done:!1,value:r.get(n.value)}},n},o.entries=function(){var n,r=this,t=this.keys();return(n={})[V]=function(){return r.entries()},n.next=function(){var n=t.next();if(n.done)return n;var e=r.get(n.value);return{done:!1,value:[n.value,e]}},n},o[V]=function(){return this.entries()},n}(),c=function(){function n(n,r){return this[Q]={i:3,l:r,A:r?r.A:_(),P:!1,I:!1,o:void 0,t:n,k:this,p:new Map,g:!1,C:!1},this}r(n,Set);var t=n.prototype;return Object.defineProperty(t,"size",{get:function(){return p(this[Q]).size}}),t.has=function(n){var r=this[Q];return u(r),r.o?!!r.o.has(n)||!(!r.p.has(n)||!r.o.has(r.p.get(n))):r.t.has(n)},t.add=function(n){var r=this[Q];return u(r),this.has(n)||(o(r),k(r),r.o.add(n)),this},t.delete=function(n){if(!this.has(n))return!1;var r=this[Q];return u(r),o(r),k(r),r.o.delete(n)||!!r.p.has(n)&&r.o.delete(r.p.get(n))},t.clear=function(){var n=this[Q];u(n),p(n).size&&(o(n),k(n),n.o.clear())},t.values=function(){var n=this[Q];return u(n),o(n),n.o.values()},t.entries=function(){var n=this[Q];return u(n),o(n),n.o.entries()},t.keys=function(){return this.values()},t[V]=function(){return this.values()},t.forEach=function(n,r){for(var t=this.values(),e=t.next();!e.done;)n.call(r,e.value,e.value,this),e=t.next()},n}();m("MapSet",{F:function(n,r){return new f(n,r)},T:function(n,r){return new c(n,r)}})}function J(){F(),C(),T()}function K(n){return n}function $(n){return n}var G,U,W="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),X="undefined"!=typeof Map,q="undefined"!=typeof Set,B="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,H=W?Symbol.for("immer-nothing"):((G={})["immer-nothing"]=!0,G),L=W?Symbol.for("immer-draftable"):"__$immer_draftable",Q=W?Symbol.for("immer-state"):"__$immer_state",V="undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator",Y={0:"Illegal state",1:"Immer drafts cannot have computed properties",2:"This object has been frozen and should not be mutated",3:function(n){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+n},4:"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",5:"Immer forbids circular references",6:"The first or second argument to `produce` must be a function",7:"The third argument to `produce` must be a function or undefined",8:"First argument to `createDraft` must be a plain object, an array, or an immerable object",9:"First argument to `finishDraft` must be a draft returned by `createDraft`",10:"The given draft is already finalized",11:"Object.defineProperty() cannot be used on an Immer draft",12:"Object.setPrototypeOf() cannot be used on an Immer draft",13:"Immer only supports deleting array indices",14:"Immer only supports setting array indices and the 'length' property",15:function(n){return"Cannot apply patch, path doesn't resolve: "+n},16:'Sets cannot have "replace" patches.',17:function(n){return"Unsupported patch operation: "+n},18:function(n){return"The plugin for '"+n+"' has not been loaded into Immer. To enable the plugin, import and call `enable"+n+"()` when initializing your application."},20:"Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",21:function(n){return"produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '"+n+"'"},22:function(n){return"'current' expects a draft, got: "+n},23:function(n){return"'original' expects a draft, got: "+n},24:"Patching reserved attributes like __proto__, prototype and constructor is not allowed"},Z=""+Object.prototype.constructor,nn="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:Object.getOwnPropertyNames,rn=Object.getOwnPropertyDescriptors||function(n){var r={};return nn(n).forEach((function(t){r[t]=Object.getOwnPropertyDescriptor(n,t)})),r},tn={},en={get:function(n,r){if(r===Q)return n;var e=p(n);if(!u(e,r))return function(n,r,t){var e,i=I(r,t);return i?"value"in i?i.value:null===(e=i.get)||void 0===e?void 0:e.call(n.k):void 0}(n,e,r);var i=e[r];return n.I||!t(i)?i:i===z(n.t,r)?(E(n),n.o[r]=N(n.A.h,i,n)):i},has:function(n,r){return r in p(n)},ownKeys:function(n){return Reflect.ownKeys(p(n))},set:function(n,r,t){var e=I(p(n),r);if(null==e?void 0:e.set)return e.set.call(n.k,t),!0;if(!n.P){var i=z(p(n),r),o=null==i?void 0:i[Q];if(o&&o.t===t)return n.o[r]=t,n.R[r]=!1,!0;if(c(t,i)&&(void 0!==t||u(n.t,r)))return!0;E(n),k(n)}return n.o[r]===t&&(void 0!==t||r in n.o)||Number.isNaN(t)&&Number.isNaN(n.o[r])||(n.o[r]=t,n.R[r]=!0),!0},deleteProperty:function(n,r){return void 0!==z(n.t,r)||r in n.t?(n.R[r]=!1,E(n),k(n)):delete n.R[r],n.o&&delete n.o[r],!0},getOwnPropertyDescriptor:function(n,r){var t=p(n),e=Reflect.getOwnPropertyDescriptor(t,r);return e?{writable:!0,configurable:1!==n.i||"length"!==r,enumerable:e.enumerable,value:t[r]}:e},defineProperty:function(){n(11)},getPrototypeOf:function(n){return Object.getPrototypeOf(n.t)},setPrototypeOf:function(){n(12)}},on={};i(en,(function(n,r){on[n]=function(){return arguments[0]=arguments[0][0],r.apply(this,arguments)}})),on.deleteProperty=function(r,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&n(13),on.set.call(this,r,t,void 0)},on.set=function(r,t,e){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&n(14),en.set.call(this,r[0],t,e,r[0])};var un=function(){function e(r){var e=this;this.O=B,this.D=!0,this.produce=function(r,i,o){if("function"==typeof r&&"function"!=typeof i){var u=i;i=r;var a=e;return function(n){var r=this;void 0===n&&(n=u);for(var t=arguments.length,e=Array(t>1?t-1:0),o=1;o<t;o++)e[o-1]=arguments[o];return a.produce(n,(function(n){var t;return(t=i).call.apply(t,[r,n].concat(e))}))}}var f;if("function"!=typeof i&&n(6),void 0!==o&&"function"!=typeof o&&n(7),t(r)){var c=w(e),s=N(e,r,void 0),v=!0;try{f=i(s),v=!1}finally{v?g(c):O(c)}return"undefined"!=typeof Promise&&f instanceof Promise?f.then((function(n){return j(c,o),P(n,c)}),(function(n){throw g(c),n})):(j(c,o),P(f,c))}if(!r||"object"!=typeof r){if(void 0===(f=i(r))&&(f=r),f===H&&(f=void 0),e.D&&d(f,!0),o){var p=[],l=[];b("Patches").M(r,f,p,l),o(p,l)}return f}n(21,r)},this.produceWithPatches=function(n,r){if("function"==typeof n)return function(r){for(var t=arguments.length,i=Array(t>1?t-1:0),o=1;o<t;o++)i[o-1]=arguments[o];return e.produceWithPatches(r,(function(r){return n.apply(void 0,[r].concat(i))}))};var t,i,o=e.produce(n,r,(function(n,r){t=n,i=r}));return"undefined"!=typeof Promise&&o instanceof Promise?o.then((function(n){return[n,t,i]})):[o,t,i]},"boolean"==typeof(null==r?void 0:r.useProxies)&&this.setUseProxies(r.useProxies),"boolean"==typeof(null==r?void 0:r.autoFreeze)&&this.setAutoFreeze(r.autoFreeze)}var i=e.prototype;return i.createDraft=function(e){t(e)||n(8),r(e)&&(e=R(e));var i=w(this),o=N(this,e,void 0);return o[Q].C=!0,O(i),o},i.finishDraft=function(r,t){var e=r&&r[Q];"production"!==process.env.NODE_ENV&&(e&&e.C||n(9),e.I&&n(10));var i=e.A;return j(i,t),P(void 0,i)},i.setAutoFreeze=function(n){this.D=n},i.setUseProxies=function(r){r&&!B&&n(20),this.O=r},i.applyPatches=function(n,t){var e;for(e=t.length-1;e>=0;e--){var i=t[e];if(0===i.path.length&&"replace"===i.op){n=i.value;break}}e>-1&&(t=t.slice(e+1));var o=b("Patches").$;return r(n)?o(n,t):this.produce(n,(function(n){return o(n,t)}))},e}(),an=new un,fn=an.produce,cn=an.produceWithPatches.bind(an),sn=an.setAutoFreeze.bind(an),vn=an.setUseProxies.bind(an),pn=an.applyPatches.bind(an),ln=an.createDraft.bind(an),dn=an.finishDraft.bind(an);export default fn;export{un as Immer,pn as applyPatches,K as castDraft,$ as castImmutable,ln as createDraft,R as current,J as enableAllPlugins,F as enableES5,C as enableMapSet,T as enablePatches,dn as finishDraft,d as freeze,L as immerable,r as isDraft,t as isDraftable,H as nothing,e as original,fn as produce,cn as produceWithPatches,sn as setAutoFreeze,vn as setUseProxies};
// Should be no imports here!
/**
* The sentinel value returned by producers to replace the draft with undefined.
*/
var NOTHING = /*#__PURE__*/Symbol["for"]("immer-nothing");
/**
* To let Immer treat your class instances as plain immutable objects
* (albeit with a custom prototype), you must define either an instance property
* or a static property on each of your custom classes.
*
* Otherwise, your class instance will never be drafted, which means it won't be
* safe to mutate in a produce callback.
*/
var DRAFTABLE = /*#__PURE__*/Symbol["for"]("immer-draftable");
var DRAFT_STATE = /*#__PURE__*/Symbol["for"]("immer-state");
var errors = process.env.NODE_ENV !== "production" ? [
// All error codes, starting by 0:
function (plugin) {
return "The plugin for '" + plugin + "' has not been loaded into Immer. To enable the plugin, import and call `enable" + plugin + "()` when initializing your application.";
}, function (thing) {
return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '" + thing + "'";
}, "This object has been frozen and should not be mutated", function (data) {
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
}, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.", "Immer forbids circular references", "The first or second argument to `produce` must be a function", "The third argument to `produce` must be a function or undefined", "First argument to `createDraft` must be a plain object, an array, or an immerable object", "First argument to `finishDraft` must be a draft returned by `createDraft`", function (thing) {
return "'current' expects a draft, got: " + thing;
}, "Object.defineProperty() cannot be used on an Immer draft", "Object.setPrototypeOf() cannot be used on an Immer draft", "Immer only supports deleting array indices", "Immer only supports setting array indices and the 'length' property", function (thing) {
return "'original' expects a draft, got: " + thing;
}
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
// See Patches.ts for additional errors
] : [];
function die(error) {
if (process.env.NODE_ENV !== "production") {
var e = errors[error];
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var msg = typeof e === "function" ? e.apply(null, args) : e;
throw new Error("[Immer] " + msg);
}
throw new Error("[Immer] minified error nr: " + error + ". Full error at: https://bit.ly/3cXEKWf");
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct.bind();
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
/** Returns true if the given value is an Immer draft */
/*#__PURE__*/
function isDraft(value) {
return !!value && !!value[DRAFT_STATE];
}
/** Returns true if the given value can be drafted by Immer */
/*#__PURE__*/
function isDraftable(value) {
var _value$constructor;
if (!value) return false;
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_value$constructor = value.constructor) != null && _value$constructor[DRAFTABLE]) || isMap(value) || isSet(value);
}
var objectCtorString = /*#__PURE__*/Object.prototype.constructor.toString();
/*#__PURE__*/
function isPlainObject(value) {
if (!value || typeof value !== "object") return false;
var proto = Object.getPrototypeOf(value);
if (proto === null) {
return true;
}
var Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
if (Ctor === Object) return true;
return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString;
}
function original(value) {
if (!isDraft(value)) die(15, value);
return value[DRAFT_STATE].base_;
}
function each(obj, iter) {
if (getArchtype(obj) === 0 /* Object */) {
Object.entries(obj).forEach(function (_ref) {
var key = _ref[0],
value = _ref[1];
iter(key, value, obj);
});
} else {
obj.forEach(function (entry, index) {
return iter(index, entry, obj);
});
}
}
/*#__PURE__*/
function getArchtype(thing) {
var state = thing[DRAFT_STATE];
return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
}
/*#__PURE__*/
function has(thing, prop) {
return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
}
/*#__PURE__*/
function get(thing, prop) {
// @ts-ignore
return getArchtype(thing) === 2 /* Map */ ? thing.get(prop) : thing[prop];
}
/*#__PURE__*/
function set(thing, propOrOldValue, value) {
var t = getArchtype(thing);
if (t === 2 /* Map */) thing.set(propOrOldValue, value);else if (t === 3 /* Set */) {
thing.add(value);
} else thing[propOrOldValue] = value;
}
/*#__PURE__*/
function is(x, y) {
// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js
if (x === y) {
return x !== 0 || 1 / x === 1 / y;
} else {
return x !== x && y !== y;
}
}
/*#__PURE__*/
function isMap(target) {
return target instanceof Map;
}
/*#__PURE__*/
function isSet(target) {
return target instanceof Set;
}
/*#__PURE__*/
function latest(state) {
return state.copy_ || state.base_;
}
/*#__PURE__*/
function shallowCopy(base, strict) {
if (isMap(base)) {
return new Map(base);
}
if (isSet(base)) {
return new Set(base);
}
if (Array.isArray(base)) return Array.prototype.slice.call(base);
if (!strict && isPlainObject(base)) {
if (!Object.getPrototypeOf(base)) {
var obj = Object.create(null);
return Object.assign(obj, base);
}
return _extends({}, base);
}
var descriptors = Object.getOwnPropertyDescriptors(base);
delete descriptors[DRAFT_STATE];
var keys = Reflect.ownKeys(descriptors);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var desc = descriptors[key];
if (desc.writable === false) {
desc.writable = true;
desc.configurable = true;
}
// like object.assign, we will read any _own_, get/set accessors. This helps in dealing
// with libraries that trap values, like mobx or vue
// unlike object.assign, non-enumerables will be copied as well
if (desc.get || desc.set) descriptors[key] = {
configurable: true,
writable: true,
enumerable: desc.enumerable,
value: base[key]
};
}
return Object.create(Object.getPrototypeOf(base), descriptors);
}
function freeze(obj, deep) {
if (deep === void 0) {
deep = false;
}
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
if (getArchtype(obj) > 1 /* Map or Set */) {
obj.set = obj.add = obj.clear = obj["delete"] = dontMutateFrozenCollections;
}
Object.freeze(obj);
if (deep) each(obj, function (_key, value) {
return freeze(value, true);
});
return obj;
}
function dontMutateFrozenCollections() {
die(2);
}
function isFrozen(obj) {
return Object.isFrozen(obj);
}
/** Plugin utilities */
var plugins = {};
function getPlugin(pluginKey) {
var plugin = plugins[pluginKey];
if (!plugin) {
die(0, pluginKey);
}
// @ts-ignore
return plugin;
}
function loadPlugin(pluginKey, implementation) {
if (!plugins[pluginKey]) plugins[pluginKey] = implementation;
}
var currentScope;
function getCurrentScope() {
return currentScope;
}
function createScope(parent_, immer_) {
return {
drafts_: [],
parent_: parent_,
immer_: immer_,
// Whenever the modified draft contains a draft from another scope, we
// need to prevent auto-freezing so the unowned draft can be finalized.
canAutoFreeze_: true,
unfinalizedDrafts_: 0
};
}
function usePatchesInScope(scope, patchListener) {
if (patchListener) {
getPlugin("Patches"); // assert we have the plugin
scope.patches_ = [];
scope.inversePatches_ = [];
scope.patchListener_ = patchListener;
}
}
function revokeScope(scope) {
leaveScope(scope);
scope.drafts_.forEach(revokeDraft);
// @ts-ignore
scope.drafts_ = null;
}
function leaveScope(scope) {
if (scope === currentScope) {
currentScope = scope.parent_;
}
}
function enterScope(immer) {
return currentScope = createScope(currentScope, immer);
}
function revokeDraft(draft) {
var state = draft[DRAFT_STATE];
if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) state.revoke_();else state.revoked_ = true;
}
function processResult(result, scope) {
scope.unfinalizedDrafts_ = scope.drafts_.length;
var baseDraft = scope.drafts_[0];
var isReplaced = result !== undefined && result !== baseDraft;
if (isReplaced) {
if (baseDraft[DRAFT_STATE].modified_) {
revokeScope(scope);
die(4);
}
if (isDraftable(result)) {
// Finalize the result in case it contains (or is) a subset of the draft.
result = finalize(scope, result);
if (!scope.parent_) maybeFreeze(scope, result);
}
if (scope.patches_) {
getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);
}
} else {
// Finalize the base draft.
result = finalize(scope, baseDraft, []);
}
revokeScope(scope);
if (scope.patches_) {
scope.patchListener_(scope.patches_, scope.inversePatches_);
}
return result !== NOTHING ? result : undefined;
}
function finalize(rootScope, value, path) {
// Don't recurse in tho recursive data structures
if (isFrozen(value)) return value;
var state = value[DRAFT_STATE];
// A plain object, might need freezing, might contain drafts
if (!state) {
each(value, function (key, childValue) {
return finalizeProperty(rootScope, state, value, key, childValue, path);
});
return value;
}
// Never finalize drafts owned by another scope.
if (state.scope_ !== rootScope) return value;
// Unmodified draft, return the (frozen) original
if (!state.modified_) {
maybeFreeze(rootScope, state.base_, true);
return state.base_;
}
// Not finalized yet, let's do that now
if (!state.finalized_) {
state.finalized_ = true;
state.scope_.unfinalizedDrafts_--;
var result = state.copy_;
// Finalize all children of the copy
// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628
// To preserve insertion order in all cases we then clear the set
// And we let finalizeProperty know it needs to re-add non-draft children back to the target
var resultEach = result;
var isSet = false;
if (state.type_ === 3 /* Set */) {
resultEach = new Set(result);
result.clear();
isSet = true;
}
each(resultEach, function (key, childValue) {
return finalizeProperty(rootScope, state, result, key, childValue, path, isSet);
});
// everything inside is frozen, we can freeze here
maybeFreeze(rootScope, result, false);
// first time finalizing, let's create those patches
if (path && rootScope.patches_) {
getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);
}
}
return state.copy_;
}
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
if (process.env.NODE_ENV !== "production" && childValue === targetObject) die(5);
if (isDraft(childValue)) {
var path = rootPath && parentState && parentState.type_ !== 3 /* Set */ &&
// Set objects are atomic since they have no keys.
!has(parentState.assigned_, prop) // Skip deep patches for assigned keys.
? rootPath.concat(prop) : undefined;
// Drafts owned by `scope` are finalized here.
var res = finalize(rootScope, childValue, path);
set(targetObject, prop, res);
// Drafts from another scope must prevented to be frozen
// if we got a draft back from finalize, we're in a nested produce and shouldn't freeze
if (isDraft(res)) {
rootScope.canAutoFreeze_ = false;
} else return;
} else if (targetIsSet) {
targetObject.add(childValue);
}
// Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
if (isDraftable(childValue) && !isFrozen(childValue)) {
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
// optimization: if an object is not a draft, and we don't have to
// deepfreeze everything, and we are sure that no drafts are left in the remaining object
// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.
// This benefits especially adding large data tree's without further processing.
// See add-data.js perf test
return;
}
finalize(rootScope, childValue);
// immer deep freezes plain objects, so if there is no parent state, we freeze as well
if (!parentState || !parentState.scope_.parent_) maybeFreeze(rootScope, childValue);
}
}
function maybeFreeze(scope, value, deep) {
if (deep === void 0) {
deep = false;
}
// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
freeze(value, deep);
}
}
/**
* Returns a new draft of the `base` object.
*
* The second argument is the parent draft-state (used internally).
*/
function createProxyProxy(base, parent) {
var isArray = Array.isArray(base);
var state = {
type_: isArray ? 1 /* Array */ : 0 /* Object */,
// Track which produce call this is associated with.
scope_: parent ? parent.scope_ : getCurrentScope(),
// True for both shallow and deep changes.
modified_: false,
// Used during finalization.
finalized_: false,
// Track which properties have been assigned (true) or deleted (false).
assigned_: {},
// The parent draft state.
parent_: parent,
// The base state.
base_: base,
// The base proxy.
draft_: null,
// The base copy with any updated values.
copy_: null,
// Called by the `produce` function.
revoke_: null,
isManual_: false
};
// the traps must target something, a bit like the 'real' base.
// but also, we need to be able to determine from the target what the relevant state is
// (to avoid creating traps per instance to capture the state in closure,
// and to avoid creating weird hidden properties as well)
// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)
// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
var target = state;
var traps = objectTraps;
if (isArray) {
target = [state];
traps = arrayTraps;
}
var _Proxy$revocable = Proxy.revocable(target, traps),
revoke = _Proxy$revocable.revoke,
proxy = _Proxy$revocable.proxy;
state.draft_ = proxy;
state.revoke_ = revoke;
return proxy;
}
/**
* Object drafts
*/
var objectTraps = {
get: function get(state, prop) {
if (prop === DRAFT_STATE) return state;
var source = latest(state);
if (!has(source, prop)) {
// non-existing or non-own property...
return readPropFromProto(state, source, prop);
}
var value = source[prop];
if (state.finalized_ || !isDraftable(value)) {
return value;
}
// Check for existing draft in modified state.
// Assigned values are never drafted. This catches any drafts we created, too.
if (value === peek(state.base_, prop)) {
prepareCopy(state);
return state.copy_[prop] = createProxy(value, state);
}
return value;
},
has: function has(state, prop) {
return prop in latest(state);
},
ownKeys: function ownKeys(state) {
return Reflect.ownKeys(latest(state));
},
set: function set(state, prop /* strictly not, but helps TS */, value) {
var desc = getDescriptorFromProto(latest(state), prop);
if (desc != null && desc.set) {
// special case: if this write is captured by a setter, we have
// to trigger it with the correct context
desc.set.call(state.draft_, value);
return true;
}
if (!state.modified_) {
// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)
// from setting an existing property with value undefined to undefined (which is not a change)
var current = peek(latest(state), prop);
// special case, if we assigning the original value to a draft, we can ignore the assignment
var currentState = current == null ? void 0 : current[DRAFT_STATE];
if (currentState && currentState.base_ === value) {
state.copy_[prop] = value;
state.assigned_[prop] = false;
return true;
}
if (is(value, current) && (value !== undefined || has(state.base_, prop))) return true;
prepareCopy(state);
markChanged(state);
}
if (state.copy_[prop] === value && (
// special case: handle new props with value 'undefined'
value !== undefined || prop in state.copy_) ||
// special case: NaN
Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
// @ts-ignore
state.copy_[prop] = value;
state.assigned_[prop] = true;
return true;
},
deleteProperty: function deleteProperty(state, prop) {
// The `undefined` check is a fast path for pre-existing keys.
if (peek(state.base_, prop) !== undefined || prop in state.base_) {
state.assigned_[prop] = false;
prepareCopy(state);
markChanged(state);
} else {
// if an originally not assigned property was deleted
delete state.assigned_[prop];
}
delete state.copy_[prop];
return true;
},
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
// the same guarantee in ES5 mode.
getOwnPropertyDescriptor: function getOwnPropertyDescriptor(state, prop) {
var owner = latest(state);
var desc = Reflect.getOwnPropertyDescriptor(owner, prop);
if (!desc) return desc;
return {
writable: true,
configurable: state.type_ !== 1 /* Array */ || prop !== "length",
enumerable: desc.enumerable,
value: owner[prop]
};
},
defineProperty: function defineProperty() {
die(11);
},
getPrototypeOf: function getPrototypeOf(state) {
return Object.getPrototypeOf(state.base_);
},
setPrototypeOf: function setPrototypeOf() {
die(12);
}
};
/**
* Array drafts
*/
var arrayTraps = {};
each(objectTraps, function (key, fn) {
// @ts-ignore
arrayTraps[key] = function () {
arguments[0] = arguments[0][0];
return fn.apply(this, arguments);
};
});
arrayTraps.deleteProperty = function (state, prop) {
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13);
// @ts-ignore
return arrayTraps.set.call(this, state, prop, undefined);
};
arrayTraps.set = function (state, prop, value) {
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop))) die(14);
return objectTraps.set.call(this, state[0], prop, value, state[0]);
};
// Access a property without creating an Immer draft.
function peek(draft, prop) {
var state = draft[DRAFT_STATE];
var source = state ? latest(state) : draft;
return source[prop];
}
function readPropFromProto(state, source, prop) {
var _desc$get;
var desc = getDescriptorFromProto(source, prop);
return desc ? "value" in desc ? desc.value : // This is a very special case, if the prop is a getter defined by the
// prototype, we should invoke it with the draft as context!
(_desc$get = desc.get) == null ? void 0 : _desc$get.call(state.draft_) : undefined;
}
function getDescriptorFromProto(source, prop) {
// 'in' checks proto!
if (!(prop in source)) return undefined;
var proto = Object.getPrototypeOf(source);
while (proto) {
var desc = Object.getOwnPropertyDescriptor(proto, prop);
if (desc) return desc;
proto = Object.getPrototypeOf(proto);
}
return undefined;
}
function markChanged(state) {
if (!state.modified_) {
state.modified_ = true;
if (state.parent_) {
markChanged(state.parent_);
}
}
}
function prepareCopy(state) {
if (!state.copy_) {
state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
}
}
var Immer = /*#__PURE__*/function () {
function Immer(config) {
var _this = this;
this.autoFreeze_ = true;
this.useStrictShallowCopy_ = false;
/**
* The `produce` function takes a value and a "recipe function" (whose
* return value often depends on the base state). The recipe function is
* free to mutate its first argument however it wants. All mutations are
* only ever applied to a __copy__ of the base state.
*
* Pass only a function to create a "curried producer" which relieves you
* from passing the recipe function every time.
*
* Only plain objects and arrays are made mutable. All other objects are
* considered uncopyable.
*
* Note: This function is __bound__ to its `Immer` instance.
*
* @param {any} base - the initial state
* @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified
* @param {Function} patchListener - optional function that will be called with all the patches produced here
* @returns {any} a new state, or the initial state if nothing was modified
*/
this.produce = function (base, recipe, patchListener) {
// curried invocation
if (typeof base === "function" && typeof recipe !== "function") {
var defaultBase = recipe;
recipe = base;
var self = _this;
return function curriedProduce(base) {
var _this2 = this;
if (base === void 0) {
base = defaultBase;
}
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return self.produce(base, function (draft) {
var _recipe;
return (_recipe = recipe).call.apply(_recipe, [_this2, draft].concat(args));
}); // prettier-ignore
};
}
if (typeof recipe !== "function") die(6);
if (patchListener !== undefined && typeof patchListener !== "function") die(7);
var result;
// Only plain objects, arrays, and "immerable classes" are drafted.
if (isDraftable(base)) {
var scope = enterScope(_this);
var proxy = createProxy(base, undefined);
var hasError = true;
try {
result = recipe(proxy);
hasError = false;
} finally {
// finally instead of catch + rethrow better preserves original stack
if (hasError) revokeScope(scope);else leaveScope(scope);
}
usePatchesInScope(scope, patchListener);
return processResult(result, scope);
} else if (!base || typeof base !== "object") {
result = recipe(base);
if (result === undefined) result = base;
if (result === NOTHING) result = undefined;
if (_this.autoFreeze_) freeze(result, true);
if (patchListener) {
var p = [];
var ip = [];
getPlugin("Patches").generateReplacementPatches_(base, result, p, ip);
patchListener(p, ip);
}
return result;
} else die(1, base);
};
this.produceWithPatches = function (base, recipe) {
// curried invocation
if (typeof base === "function") {
return function (state) {
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
return _this.produceWithPatches(state, function (draft) {
return base.apply(void 0, [draft].concat(args));
});
};
}
var patches, inversePatches;
var result = _this.produce(base, recipe, function (p, ip) {
patches = p;
inversePatches = ip;
});
return [result, patches, inversePatches];
};
if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean") this.setAutoFreeze(config.autoFreeze);
if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean") this.setUseStrictShallowCopy(config.useStrictShallowCopy);
}
var _proto = Immer.prototype;
_proto.createDraft = function createDraft(base) {
if (!isDraftable(base)) die(8);
if (isDraft(base)) base = current(base);
var scope = enterScope(this);
var proxy = createProxy(base, undefined);
proxy[DRAFT_STATE].isManual_ = true;
leaveScope(scope);
return proxy;
};
_proto.finishDraft = function finishDraft(draft, patchListener) {
var state = draft && draft[DRAFT_STATE];
if (!state || !state.isManual_) die(9);
var scope = state.scope_;
usePatchesInScope(scope, patchListener);
return processResult(undefined, scope);
}
/**
* Pass true to automatically freeze all copies created by Immer.
*
* By default, auto-freezing is enabled.
*/;
_proto.setAutoFreeze = function setAutoFreeze(value) {
this.autoFreeze_ = value;
}
/**
* Pass true to enable strict shallow copy.
*
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/;
_proto.setUseStrictShallowCopy = function setUseStrictShallowCopy(value) {
this.useStrictShallowCopy_ = value;
};
_proto.applyPatches = function applyPatches(base, patches) {
// If a patch replaces the entire state, take that replacement as base
// before applying patches
var i;
for (i = patches.length - 1; i >= 0; i--) {
var patch = patches[i];
if (patch.path.length === 0 && patch.op === "replace") {
base = patch.value;
break;
}
}
// If there was a patch that replaced the entire state, start from the
// patch after that.
if (i > -1) {
patches = patches.slice(i + 1);
}
var applyPatchesImpl = getPlugin("Patches").applyPatches_;
if (isDraft(base)) {
// N.B: never hits if some patch a replacement, patches are never drafts
return applyPatchesImpl(base, patches);
}
// Otherwise, produce a copy of the base state.
return this.produce(base, function (draft) {
return applyPatchesImpl(draft, patches);
});
};
return Immer;
}();
function createProxy(value, parent) {
// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
var draft = isMap(value) ? proxyMap(value, parent) : isSet(value) ? proxySet(value, parent) : createProxyProxy(value, parent);
var scope = parent ? parent.scope_ : getCurrentScope();
scope.drafts_.push(draft);
return draft;
}
function current(value) {
if (!isDraft(value)) die(10, value);
return currentImpl(value);
}
function currentImpl(value) {
if (!isDraftable(value) || isFrozen(value)) return value;
var state = value[DRAFT_STATE];
var copy;
if (state) {
if (!state.modified_) return state.base_;
// Optimization: avoid generating new drafts during copying
state.finalized_ = true;
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
} else {
copy = shallowCopy(value, true);
}
// recurse
each(copy, function (key, childValue) {
set(copy, key, currentImpl(childValue));
});
if (state) {
state.finalized_ = false;
}
return copy;
}
var DraftMap = /*#__PURE__*/function (_Map, _Symbol$iterator) {
_inheritsLoose(DraftMap, _Map);
function DraftMap(target, parent) {
var _this;
_this = _Map.call(this) || this;
_this[DRAFT_STATE] = {
type_: 2 /* Map */,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
assigned_: undefined,
base_: target,
draft_: _assertThisInitialized(_this),
isManual_: false,
revoked_: false
};
return _this;
}
var _proto = DraftMap.prototype;
_proto.has = function has(key) {
return latest(this[DRAFT_STATE]).has(key);
};
_proto.set = function set(key, value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!latest(state).has(key) || latest(state).get(key) !== value) {
prepareMapCopy(state);
markChanged(state);
state.assigned_.set(key, true);
state.copy_.set(key, value);
state.assigned_.set(key, true);
}
return this;
};
_proto["delete"] = function _delete(key) {
if (!this.has(key)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareMapCopy(state);
markChanged(state);
if (state.base_.has(key)) {
state.assigned_.set(key, false);
} else {
state.assigned_["delete"](key);
}
state.copy_["delete"](key);
return true;
};
_proto.clear = function clear() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareMapCopy(state);
markChanged(state);
state.assigned_ = new Map();
each(state.base_, function (key) {
state.assigned_.set(key, false);
});
state.copy_.clear();
}
};
_proto.forEach = function forEach(cb, thisArg) {
var _this2 = this;
var state = this[DRAFT_STATE];
latest(state).forEach(function (_value, key, _map) {
cb.call(thisArg, _this2.get(key), key, _this2);
});
};
_proto.get = function get(key) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
var value = latest(state).get(key);
if (state.finalized_ || !isDraftable(value)) {
return value;
}
if (value !== state.base_.get(key)) {
return value; // either already drafted or reassigned
}
// despite what it looks, this creates a draft only once, see above condition
var draft = createProxy(value, state);
prepareMapCopy(state);
state.copy_.set(key, draft);
return draft;
};
_proto.keys = function keys() {
return latest(this[DRAFT_STATE]).keys();
};
_proto.values = function values() {
var _this3 = this,
_ref;
var iterator = this.keys();
return _ref = {}, _ref[Symbol.iterator] = function () {
return _this3.values();
}, _ref.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this3.get(r.value);
return {
done: false,
value: value
};
}, _ref;
};
_proto.entries = function entries() {
var _this4 = this,
_ref2;
var iterator = this.keys();
return _ref2 = {}, _ref2[Symbol.iterator] = function () {
return _this4.entries();
}, _ref2.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this4.get(r.value);
return {
done: false,
value: [r.value, value]
};
}, _ref2;
};
_proto[_Symbol$iterator] = function () {
return this.entries();
};
_createClass(DraftMap, [{
key: "size",
get: function get() {
return latest(this[DRAFT_STATE]).size;
}
}]);
return DraftMap;
}( /*#__PURE__*/_wrapNativeSuper(Map), Symbol.iterator);
function proxyMap(target, parent) {
// @ts-ignore
return new DraftMap(target, parent);
}
function prepareMapCopy(state) {
if (!state.copy_) {
state.assigned_ = new Map();
state.copy_ = new Map(state.base_);
}
}
var DraftSet = /*#__PURE__*/function (_Set, _Symbol$iterator2) {
_inheritsLoose(DraftSet, _Set);
function DraftSet(target, parent) {
var _this5;
_this5 = _Set.call(this) || this;
_this5[DRAFT_STATE] = {
type_: 3 /* Set */,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
base_: target,
draft_: _assertThisInitialized(_this5),
drafts_: new Map(),
revoked_: false,
isManual_: false
};
return _this5;
}
var _proto2 = DraftSet.prototype;
_proto2.has = function has(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
// bit of trickery here, to be able to recognize both the value, and the draft of its value
if (!state.copy_) {
return state.base_.has(value);
}
if (state.copy_.has(value)) return true;
if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true;
return false;
};
_proto2.add = function add(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!this.has(value)) {
prepareSetCopy(state);
markChanged(state);
state.copy_.add(value);
}
return this;
};
_proto2["delete"] = function _delete(value) {
if (!this.has(value)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
markChanged(state);
return state.copy_["delete"](value) || (state.drafts_.has(value) ? state.copy_["delete"](state.drafts_.get(value)) : /* istanbul ignore next */false);
};
_proto2.clear = function clear() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareSetCopy(state);
markChanged(state);
state.copy_.clear();
}
};
_proto2.values = function values() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.values();
};
_proto2.entries = function entries() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.entries();
};
_proto2.keys = function keys() {
return this.values();
};
_proto2[_Symbol$iterator2] = function () {
return this.values();
};
_proto2.forEach = function forEach(cb, thisArg) {
var iterator = this.values();
var result = iterator.next();
while (!result.done) {
cb.call(thisArg, result.value, result.value, this);
result = iterator.next();
}
};
_createClass(DraftSet, [{
key: "size",
get: function get() {
return latest(this[DRAFT_STATE]).size;
}
}]);
return DraftSet;
}( /*#__PURE__*/_wrapNativeSuper(Set), Symbol.iterator);
function proxySet(target, parent) {
// @ts-ignore
return new DraftSet(target, parent);
}
function prepareSetCopy(state) {
if (!state.copy_) {
// create drafts for all entries to preserve insertion order
state.copy_ = new Set();
state.base_.forEach(function (value) {
if (isDraftable(value)) {
var draft = createProxy(value, state);
state.drafts_.set(value, draft);
state.copy_.add(draft);
} else {
state.copy_.add(value);
}
});
}
}
function assertUnrevoked(state /*ES5State | MapState | SetState*/) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
function enablePatches() {
var errorOffset = 16;
if (process.env.NODE_ENV !== "production") {
errors.push('Sets cannot have "replace" patches.', function (op) {
return "Unsupported patch operation: " + op;
}, function (path) {
return "Cannot apply patch, path doesn't resolve: " + path;
}, "Patching reserved attributes like __proto__, prototype and constructor is not allowed");
}
var REPLACE = "replace";
var ADD = "add";
var REMOVE = "remove";
function generatePatches_(state, basePath, patches, inversePatches) {
switch (state.type_) {
case 0 /* Object */:
case 2 /* Map */:
return generatePatchesFromAssigned(state, basePath, patches, inversePatches);
case 1 /* Array */:
return generateArrayPatches(state, basePath, patches, inversePatches);
case 3 /* Set */:
return generateSetPatches(state, basePath, patches, inversePatches);
}
}
function generateArrayPatches(state, basePath, patches, inversePatches) {
var base_ = state.base_,
assigned_ = state.assigned_;
var copy_ = state.copy_;
// Reduce complexity by ensuring `base` is never longer.
if (copy_.length < base_.length) {
var _ref = [copy_, base_];
base_ = _ref[0];
copy_ = _ref[1];
var _ref2 = [inversePatches, patches];
patches = _ref2[0];
inversePatches = _ref2[1];
}
// Process replaced indices.
for (var i = 0; i < base_.length; i++) {
if (assigned_[i] && copy_[i] !== base_[i]) {
var path = basePath.concat([i]);
patches.push({
op: REPLACE,
path: path,
// Need to maybe clone it, as it can in fact be the original value
// due to the base/copy inversion at the start of this function
value: clonePatchValueIfNeeded(copy_[i])
});
inversePatches.push({
op: REPLACE,
path: path,
value: clonePatchValueIfNeeded(base_[i])
});
}
}
// Process added indices.
for (var _i = base_.length; _i < copy_.length; _i++) {
var _path = basePath.concat([_i]);
patches.push({
op: ADD,
path: _path,
// Need to maybe clone it, as it can in fact be the original value
// due to the base/copy inversion at the start of this function
value: clonePatchValueIfNeeded(copy_[_i])
});
}
for (var _i2 = copy_.length - 1; base_.length <= _i2; --_i2) {
var _path2 = basePath.concat([_i2]);
inversePatches.push({
op: REMOVE,
path: _path2
});
}
}
// This is used for both Map objects and normal objects.
function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
var base_ = state.base_,
copy_ = state.copy_;
each(state.assigned_, function (key, assignedValue) {
var origValue = get(base_, key);
var value = get(copy_, key);
var op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD;
if (origValue === value && op === REPLACE) return;
var path = basePath.concat(key);
patches.push(op === REMOVE ? {
op: op,
path: path
} : {
op: op,
path: path,
value: value
});
inversePatches.push(op === ADD ? {
op: REMOVE,
path: path
} : op === REMOVE ? {
op: ADD,
path: path,
value: clonePatchValueIfNeeded(origValue)
} : {
op: REPLACE,
path: path,
value: clonePatchValueIfNeeded(origValue)
});
});
}
function generateSetPatches(state, basePath, patches, inversePatches) {
var base_ = state.base_,
copy_ = state.copy_;
var i = 0;
base_.forEach(function (value) {
if (!copy_.has(value)) {
var path = basePath.concat([i]);
patches.push({
op: REMOVE,
path: path,
value: value
});
inversePatches.unshift({
op: ADD,
path: path,
value: value
});
}
i++;
});
i = 0;
copy_.forEach(function (value) {
if (!base_.has(value)) {
var path = basePath.concat([i]);
patches.push({
op: ADD,
path: path,
value: value
});
inversePatches.unshift({
op: REMOVE,
path: path,
value: value
});
}
i++;
});
}
function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {
patches.push({
op: REPLACE,
path: [],
value: replacement === NOTHING ? undefined : replacement
});
inversePatches.push({
op: REPLACE,
path: [],
value: baseValue
});
}
function applyPatches_(draft, patches) {
patches.forEach(function (patch) {
var path = patch.path,
op = patch.op;
var base = draft;
for (var i = 0; i < path.length - 1; i++) {
var parentType = getArchtype(base);
var p = path[i];
if (typeof p !== "string" && typeof p !== "number") {
p = "" + p;
}
// See #738, avoid prototype pollution
if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === "__proto__" || p === "constructor")) die(errorOffset + 3);
if (typeof base === "function" && p === "prototype") die(errorOffset + 3);
base = get(base, p);
if (typeof base !== "object") die(errorOffset + 2, path.join("/"));
}
var type = getArchtype(base);
var value = deepClonePatchValue(patch.value); // used to clone patch to ensure original patch is not modified, see #411
var key = path[path.length - 1];
switch (op) {
case REPLACE:
switch (type) {
case 2 /* Map */:
return base.set(key, value);
/* istanbul ignore next */
case 3 /* Set */:
die(errorOffset);
default:
// if value is an object, then it's assigned by reference
// in the following add or remove ops, the value field inside the patch will also be modifyed
// so we use value from the cloned patch
// @ts-ignore
return base[key] = value;
}
case ADD:
switch (type) {
case 1 /* Array */:
return key === "-" ? base.push(value) : base.splice(key, 0, value);
case 2 /* Map */:
return base.set(key, value);
case 3 /* Set */:
return base.add(value);
default:
return base[key] = value;
}
case REMOVE:
switch (type) {
case 1 /* Array */:
return base.splice(key, 1);
case 2 /* Map */:
return base["delete"](key);
case 3 /* Set */:
return base["delete"](patch.value);
default:
return delete base[key];
}
default:
die(errorOffset + 1, op);
}
});
return draft;
}
function deepClonePatchValue(obj) {
if (!isDraftable(obj)) return obj;
if (Array.isArray(obj)) return obj.map(deepClonePatchValue);
if (isMap(obj)) return new Map(Array.from(obj.entries()).map(function (_ref3) {
var k = _ref3[0],
v = _ref3[1];
return [k, deepClonePatchValue(v)];
}));
if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue));
var cloned = Object.create(Object.getPrototypeOf(obj));
for (var key in obj) cloned[key] = deepClonePatchValue(obj[key]);
if (has(obj, DRAFTABLE)) cloned[DRAFTABLE] = obj[DRAFTABLE];
return cloned;
}
function clonePatchValueIfNeeded(obj) {
if (isDraft(obj)) {
return deepClonePatchValue(obj);
} else return obj;
}
loadPlugin("Patches", {
applyPatches_: applyPatches_,
generatePatches_: generatePatches_,
generateReplacementPatches_: generateReplacementPatches_
});
}
var immer = /*#__PURE__*/new Immer();
/**
* The `produce` function takes a value and a "recipe function" (whose
* return value often depends on the base state). The recipe function is
* free to mutate its first argument however it wants. All mutations are
* only ever applied to a __copy__ of the base state.
*
* Pass only a function to create a "curried producer" which relieves you
* from passing the recipe function every time.
*
* Only plain objects and arrays are made mutable. All other objects are
* considered uncopyable.
*
* Note: This function is __bound__ to its `Immer` instance.
*
* @param {any} base - the initial state
* @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified
* @param {Function} patchListener - optional function that will be called with all the patches produced here
* @returns {any} a new state, or the initial state if nothing was modified
*/
var produce = immer.produce;
/**
* Like `produce`, but `produceWithPatches` always returns a tuple
* [nextState, patches, inversePatches] (instead of just the next state)
*/
var produceWithPatches = /*#__PURE__*/immer.produceWithPatches.bind(immer);
/**
* Pass true to automatically freeze all copies created by Immer.
*
* Always freeze by default, even in production mode
*/
var setAutoFreeze = /*#__PURE__*/immer.setAutoFreeze.bind(immer);
/**
* Pass true to enable strict shallow copy.
*
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
var setUseStrictShallowCopy = /*#__PURE__*/immer.setUseStrictShallowCopy.bind(immer);
/**
* Apply an array of Immer patches to the first argument.
*
* This function is a producer, which means copy-on-write is in effect.
*/
var applyPatches = /*#__PURE__*/immer.applyPatches.bind(immer);
/**
* Create an Immer draft from the given base state, which may be a draft itself.
* The draft can be modified until you finalize it with the `finishDraft` function.
*/
var createDraft = /*#__PURE__*/immer.createDraft.bind(immer);
/**
* Finalize an Immer draft from a `createDraft` call, returning the base state
* (if no changes were made) or a modified copy. The draft must *not* be
* mutated afterwards.
*
* Pass a function as the 2nd argument to generate Immer patches based on the
* changes that were made.
*/
var finishDraft = /*#__PURE__*/immer.finishDraft.bind(immer);
/**
* This function is actually a no-op, but can be used to cast an immutable type
* to an draft type and make TypeScript happy
*
* @param value
*/
function castDraft(value) {
return value;
}
/**
* This function is actually a no-op, but can be used to cast a mutable type
* to an immutable type and make TypeScript happy
* @param value
*/
function castImmutable(value) {
return value;
}
export { Immer, applyPatches, castDraft, castImmutable, createDraft, current, enablePatches, finishDraft, freeze, DRAFTABLE as immerable, isDraft, isDraftable, NOTHING as nothing, original, produce, produceWithPatches, setAutoFreeze, setUseStrictShallowCopy };
//# sourceMappingURL=immer.esm.js.map

@@ -7,20 +7,7 @@ (function (global, factory) {

var _ref;
// Should be no imports here!
// Some things that should be evaluated before all else...
// We only want to know if non-polyfilled symbols are available
var hasSymbol = typeof Symbol !== "undefined" && typeof
/*#__PURE__*/
Symbol("x") === "symbol";
var hasMap = typeof Map !== "undefined";
var hasSet = typeof Set !== "undefined";
var hasProxies = typeof Proxy !== "undefined" && typeof Proxy.revocable !== "undefined" && typeof Reflect !== "undefined";
/**
* The sentinel value returned by producers to replace the draft with undefined.
*/
var NOTHING = hasSymbol ?
/*#__PURE__*/
Symbol.for("immer-nothing") : (_ref = {}, _ref["immer-nothing"] = true, _ref);
var NOTHING = /*#__PURE__*/Symbol["for"]("immer-nothing");
/**

@@ -34,60 +21,28 @@ * To let Immer treat your class instances as plain immutable objects

*/
var DRAFTABLE = /*#__PURE__*/Symbol["for"]("immer-draftable");
var DRAFT_STATE = /*#__PURE__*/Symbol["for"]("immer-state");
var DRAFTABLE = hasSymbol ?
/*#__PURE__*/
Symbol.for("immer-draftable") : "__$immer_draftable";
var DRAFT_STATE = hasSymbol ?
/*#__PURE__*/
Symbol.for("immer-state") : "__$immer_state"; // Even a polyfilled Symbol might provide Symbol.iterator
var iteratorSymbol = typeof Symbol != "undefined" && Symbol.iterator || "@@iterator";
var errors = {
0: "Illegal state",
1: "Immer drafts cannot have computed properties",
2: "This object has been frozen and should not be mutated",
3: function _(data) {
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
},
4: "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
5: "Immer forbids circular references",
6: "The first or second argument to `produce` must be a function",
7: "The third argument to `produce` must be a function or undefined",
8: "First argument to `createDraft` must be a plain object, an array, or an immerable object",
9: "First argument to `finishDraft` must be a draft returned by `createDraft`",
10: "The given draft is already finalized",
11: "Object.defineProperty() cannot be used on an Immer draft",
12: "Object.setPrototypeOf() cannot be used on an Immer draft",
13: "Immer only supports deleting array indices",
14: "Immer only supports setting array indices and the 'length' property",
15: function _(path) {
return "Cannot apply patch, path doesn't resolve: " + path;
},
16: 'Sets cannot have "replace" patches.',
17: function _(op) {
return "Unsupported patch operation: " + op;
},
18: function _(plugin) {
return "The plugin for '" + plugin + "' has not been loaded into Immer. To enable the plugin, import and call `enable" + plugin + "()` when initializing your application.";
},
20: "Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",
21: function _(thing) {
return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '" + thing + "'";
},
22: function _(thing) {
return "'current' expects a draft, got: " + thing;
},
23: function _(thing) {
return "'original' expects a draft, got: " + thing;
},
24: "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
};
var errors = [
// All error codes, starting by 0:
function (plugin) {
return "The plugin for '" + plugin + "' has not been loaded into Immer. To enable the plugin, import and call `enable" + plugin + "()` when initializing your application.";
}, function (thing) {
return "produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '" + thing + "'";
}, "This object has been frozen and should not be mutated", function (data) {
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
}, "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.", "Immer forbids circular references", "The first or second argument to `produce` must be a function", "The third argument to `produce` must be a function or undefined", "First argument to `createDraft` must be a plain object, an array, or an immerable object", "First argument to `finishDraft` must be a draft returned by `createDraft`", function (thing) {
return "'current' expects a draft, got: " + thing;
}, "Object.defineProperty() cannot be used on an Immer draft", "Object.setPrototypeOf() cannot be used on an Immer draft", "Immer only supports deleting array indices", "Immer only supports setting array indices and the 'length' property", function (thing) {
return "'original' expects a draft, got: " + thing;
}
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
// See Patches.ts for additional errors
] ;
function die(error) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
{
var e = errors[error];
var msg = !e ? "unknown error nr: " + error : typeof e === "function" ? e.apply(null, args) : e;
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var msg = typeof e === "function" ? e.apply(null, args) : e;
throw new Error("[Immer] " + msg);

@@ -97,6 +52,129 @@ }

function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _extends() {
_extends = Object.assign ? Object.assign.bind() : function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
return true;
} catch (e) {
return false;
}
}
function _construct(Parent, args, Class) {
if (_isNativeReflectConstruct()) {
_construct = Reflect.construct.bind();
} else {
_construct = function _construct(Parent, args, Class) {
var a = [null];
a.push.apply(a, args);
var Constructor = Function.bind.apply(Parent, a);
var instance = new Constructor();
if (Class) _setPrototypeOf(instance, Class.prototype);
return instance;
};
}
return _construct.apply(null, arguments);
}
function _isNativeFunction(fn) {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
/** Returns true if the given value is an Immer draft */
/*#__PURE__*/
function isDraft(value) {

@@ -106,24 +184,16 @@ return !!value && !!value[DRAFT_STATE];

/** Returns true if the given value can be drafted by Immer */
/*#__PURE__*/
function isDraftable(value) {
var _value$constructor;
if (!value) return false;
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_value$constructor = value.constructor) === null || _value$constructor === void 0 ? void 0 : _value$constructor[DRAFTABLE]) || isMap(value) || isSet(value);
return isPlainObject(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_value$constructor = value.constructor) != null && _value$constructor[DRAFTABLE]) || isMap(value) || isSet(value);
}
var objectCtorString =
var objectCtorString = /*#__PURE__*/Object.prototype.constructor.toString();
/*#__PURE__*/
Object.prototype.constructor.toString();
/*#__PURE__*/
function isPlainObject(value) {
if (!value || typeof value !== "object") return false;
var proto = Object.getPrototypeOf(value);
if (proto === null) {
return true;
}
var Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;

@@ -134,32 +204,13 @@ if (Ctor === Object) return true;

function original(value) {
if (!isDraft(value)) die(23, value);
if (!isDraft(value)) die(15, value);
return value[DRAFT_STATE].base_;
}
/*#__PURE__*/
var ownKeys = typeof Reflect !== "undefined" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols !== "undefined" ? function (obj) {
return Object.getOwnPropertyNames(obj).concat(Object.getOwnPropertySymbols(obj));
} :
/* istanbul ignore next */
Object.getOwnPropertyNames;
var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors || function getOwnPropertyDescriptors(target) {
// Polyfill needed for Hermes and IE, see https://github.com/facebook/hermes/issues/274
var res = {};
ownKeys(target).forEach(function (key) {
res[key] = Object.getOwnPropertyDescriptor(target, key);
});
return res;
};
function each(obj, iter, enumerableOnly) {
if (enumerableOnly === void 0) {
enumerableOnly = false;
}
if (getArchtype(obj) === 0
/* Object */
) {
(enumerableOnly ? Object.keys : ownKeys)(obj).forEach(function (key) {
if (!enumerableOnly || typeof key !== "symbol") iter(key, obj[key], obj);
});
} else {
function each(obj, iter) {
if (getArchtype(obj) === 0 /* Object */) {
Object.entries(obj).forEach(function (_ref) {
var key = _ref[0],
value = _ref[1];
iter(key, value, obj);
});
} else {
obj.forEach(function (entry, index) {

@@ -171,47 +222,23 @@ return iter(index, entry, obj);

/*#__PURE__*/
function getArchtype(thing) {
/* istanbul ignore next */
var state = thing[DRAFT_STATE];
return state ? state.type_ > 3 ? state.type_ - 4 // cause Object and Array map back from 4 and 5
: state.type_ // others are the same
: Array.isArray(thing) ? 1
/* Array */
: isMap(thing) ? 2
/* Map */
: isSet(thing) ? 3
/* Set */
: 0
/* Object */
;
return state ? state.type_ : Array.isArray(thing) ? 1 /* Array */ : isMap(thing) ? 2 /* Map */ : isSet(thing) ? 3 /* Set */ : 0 /* Object */;
}
/*#__PURE__*/
function has(thing, prop) {
return getArchtype(thing) === 2
/* Map */
? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
return getArchtype(thing) === 2 /* Map */ ? thing.has(prop) : Object.prototype.hasOwnProperty.call(thing, prop);
}
/*#__PURE__*/
function get(thing, prop) {
// @ts-ignore
return getArchtype(thing) === 2
/* Map */
? thing.get(prop) : thing[prop];
return getArchtype(thing) === 2 /* Map */ ? thing.get(prop) : thing[prop];
}
/*#__PURE__*/
function set(thing, propOrOldValue, value) {
var t = getArchtype(thing);
if (t === 2
/* Map */
) thing.set(propOrOldValue, value);else if (t === 3
/* Set */
) {
thing.add(value);
} else thing[propOrOldValue] = value;
if (t === 2 /* Map */) thing.set(propOrOldValue, value);else if (t === 3 /* Set */) {
thing.add(value);
} else thing[propOrOldValue] = value;
}
/*#__PURE__*/
function is(x, y) {

@@ -226,13 +253,10 @@ // From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js

/*#__PURE__*/
function isMap(target) {
return hasMap && target instanceof Map;
return target instanceof Map;
}
/*#__PURE__*/
function isSet(target) {
return hasSet && target instanceof Set;
return target instanceof Set;
}
/*#__PURE__*/
function latest(state) {

@@ -242,21 +266,30 @@ return state.copy_ || state.base_;

/*#__PURE__*/
function shallowCopy(base) {
function shallowCopy(base, strict) {
if (isMap(base)) {
return new Map(base);
}
if (isSet(base)) {
return new Set(base);
}
if (Array.isArray(base)) return Array.prototype.slice.call(base);
var descriptors = getOwnPropertyDescriptors(base);
if (!strict && isPlainObject(base)) {
if (!Object.getPrototypeOf(base)) {
var obj = Object.create(null);
return Object.assign(obj, base);
}
return _extends({}, base);
}
var descriptors = Object.getOwnPropertyDescriptors(base);
delete descriptors[DRAFT_STATE];
var keys = ownKeys(descriptors);
var keys = Reflect.ownKeys(descriptors);
for (var i = 0; i < keys.length; i++) {
var key = keys[i];
var desc = descriptors[key];
if (desc.writable === false) {
desc.writable = true;
desc.configurable = true;
} // like object.assign, we will read any _own_, get/set accessors. This helps in dealing
}
// like object.assign, we will read any _own_, get/set accessors. This helps in dealing
// with libraries that trap values, like mobx or vue
// unlike object.assign, non-enumerables will be copied as well
if (desc.get || desc.set) descriptors[key] = {

@@ -269,3 +302,2 @@ configurable: true,

}
return Object.create(Object.getPrototypeOf(base), descriptors);

@@ -277,25 +309,16 @@ }

}
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj;
if (getArchtype(obj) > 1
/* Map or Set */
) {
obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
}
if (getArchtype(obj) > 1 /* Map or Set */) {
obj.set = obj.add = obj.clear = obj["delete"] = dontMutateFrozenCollections;
}
Object.freeze(obj);
if (deep) each(obj, function (key, value) {
if (deep) each(obj, function (_key, value) {
return freeze(value, true);
}, true);
});
return obj;
}
function dontMutateFrozenCollections() {
die(2);
}
function isFrozen(obj) {
if (obj == null || typeof obj !== "object") return true; // See #600, IE dies on non-objects in Object.isFrozen
return Object.isFrozen(obj);

@@ -305,12 +328,9 @@ }

/** Plugin utilities */
var plugins = {};
function getPlugin(pluginKey) {
var plugin = plugins[pluginKey];
if (!plugin) {
die(18, pluginKey);
} // @ts-ignore
die(0, pluginKey);
}
// @ts-ignore
return plugin;

@@ -324,6 +344,4 @@ }

function getCurrentScope() {
if ( !currentScope) die(0);
return currentScope;
}
function createScope(parent_, immer_) {

@@ -340,7 +358,5 @@ return {

}
function usePatchesInScope(scope, patchListener) {
if (patchListener) {
getPlugin("Patches"); // assert we have the plugin
scope.patches_ = [];

@@ -353,4 +369,4 @@ scope.inversePatches_ = [];

leaveScope(scope);
scope.drafts_.forEach(revokeDraft); // @ts-ignore
scope.drafts_.forEach(revokeDraft);
// @ts-ignore
scope.drafts_ = null;

@@ -366,10 +382,5 @@ }

}
function revokeDraft(draft) {
var state = draft[DRAFT_STATE];
if (state.type_ === 0
/* ProxyObject */
|| state.type_ === 1
/* ProxyArray */
) state.revoke_();else state.revoked_ = true;
if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) state.revoke_();else state.revoked_ = true;
}

@@ -381,4 +392,2 @@

var isReplaced = result !== undefined && result !== baseDraft;
if (!scope.immer_.useProxies_) getPlugin("ES5").willFinalizeES5_(scope, result, isReplaced);
if (isReplaced) {

@@ -389,3 +398,2 @@ if (baseDraft[DRAFT_STATE].modified_) {

}
if (isDraftable(result)) {

@@ -396,3 +404,2 @@ // Finalize the result in case it contains (or is) a subset of the draft.

}
if (scope.patches_) {

@@ -405,64 +412,49 @@ getPlugin("Patches").generateReplacementPatches_(baseDraft[DRAFT_STATE].base_, result, scope.patches_, scope.inversePatches_);

}
revokeScope(scope);
if (scope.patches_) {
scope.patchListener_(scope.patches_, scope.inversePatches_);
}
return result !== NOTHING ? result : undefined;
}
function finalize(rootScope, value, path) {
// Don't recurse in tho recursive data structures
if (isFrozen(value)) return value;
var state = value[DRAFT_STATE]; // A plain object, might need freezing, might contain drafts
var state = value[DRAFT_STATE];
// A plain object, might need freezing, might contain drafts
if (!state) {
each(value, function (key, childValue) {
return finalizeProperty(rootScope, state, value, key, childValue, path);
}, true // See #590, don't recurse into non-enumerable of non drafted objects
);
});
return value;
} // Never finalize drafts owned by another scope.
if (state.scope_ !== rootScope) return value; // Unmodified draft, return the (frozen) original
}
// Never finalize drafts owned by another scope.
if (state.scope_ !== rootScope) return value;
// Unmodified draft, return the (frozen) original
if (!state.modified_) {
maybeFreeze(rootScope, state.base_, true);
return state.base_;
} // Not finalized yet, let's do that now
}
// Not finalized yet, let's do that now
if (!state.finalized_) {
state.finalized_ = true;
state.scope_.unfinalizedDrafts_--;
var result = // For ES5, create a good copy from the draft first, with added keys and without deleted keys.
state.type_ === 4
/* ES5Object */
|| state.type_ === 5
/* ES5Array */
? state.copy_ = shallowCopy(state.draft_) : state.copy_; // Finalize all children of the copy
var result = state.copy_;
// Finalize all children of the copy
// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628
// To preserve insertion order in all cases we then clear the set
// And we let finalizeProperty know it needs to re-add non-draft children back to the target
var resultEach = result;
var isSet = false;
if (state.type_ === 3
/* Set */
) {
resultEach = new Set(result);
result.clear();
isSet = true;
}
if (state.type_ === 3 /* Set */) {
resultEach = new Set(result);
result.clear();
isSet = true;
}
each(resultEach, function (key, childValue) {
return finalizeProperty(rootScope, state, result, key, childValue, path, isSet);
}); // everything inside is frozen, we can freeze here
maybeFreeze(rootScope, result, false); // first time finalizing, let's create those patches
});
// everything inside is frozen, we can freeze here
maybeFreeze(rootScope, result, false);
// first time finalizing, let's create those patches
if (path && rootScope.patches_) {

@@ -472,20 +464,16 @@ getPlugin("Patches").generatePatches_(state, path, rootScope.patches_, rootScope.inversePatches_);

}
return state.copy_;
}
function finalizeProperty(rootScope, parentState, targetObject, prop, childValue, rootPath, targetIsSet) {
if ( childValue === targetObject) die(5);
if (isDraft(childValue)) {
var path = rootPath && parentState && parentState.type_ !== 3
/* Set */
&& // Set objects are atomic since they have no keys.
var path = rootPath && parentState && parentState.type_ !== 3 /* Set */ &&
// Set objects are atomic since they have no keys.
!has(parentState.assigned_, prop) // Skip deep patches for assigned keys.
? rootPath.concat(prop) : undefined; // Drafts owned by `scope` are finalized here.
? rootPath.concat(prop) : undefined;
// Drafts owned by `scope` are finalized here.
var res = finalize(rootScope, childValue, path);
set(targetObject, prop, res); // Drafts from another scope must prevented to be frozen
set(targetObject, prop, res);
// Drafts from another scope must prevented to be frozen
// if we got a draft back from finalize, we're in a nested produce and shouldn't freeze
if (isDraft(res)) {

@@ -496,5 +484,4 @@ rootScope.canAutoFreeze_ = false;

targetObject.add(childValue);
} // Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
}
// Search new objects for unfinalized drafts. Frozen objects should never contain drafts.
if (isDraftable(childValue) && !isFrozen(childValue)) {

@@ -509,9 +496,7 @@ if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {

}
finalize(rootScope, childValue); // immer deep freezes plain objects, so if there is no parent state, we freeze as well
finalize(rootScope, childValue);
// immer deep freezes plain objects, so if there is no parent state, we freeze as well
if (!parentState || !parentState.scope_.parent_) maybeFreeze(rootScope, childValue);
}
}
function maybeFreeze(scope, value, deep) {

@@ -521,3 +506,2 @@ if (deep === void 0) {

}
// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects

@@ -534,11 +518,7 @@ if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {

*/
function createProxyProxy(base, parent) {
var isArray = Array.isArray(base);
var state = {
type_: isArray ? 1
/* ProxyArray */
: 0
/* ProxyObject */
,
type_: isArray ? 1 /* Array */ : 0 /* Object */,
// Track which produce call this is associated with.

@@ -563,3 +543,4 @@ scope_: parent ? parent.scope_ : getCurrentScope(),

isManual_: false
}; // the traps must target something, a bit like the 'real' base.
};
// the traps must target something, a bit like the 'real' base.
// but also, we need to be able to determine from the target what the relevant state is

@@ -570,6 +551,4 @@ // (to avoid creating traps per instance to capture the state in closure,

// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb
var target = state;
var traps = objectTraps;
if (isArray) {

@@ -579,7 +558,5 @@ target = [state];

}
var _Proxy$revocable = Proxy.revocable(target, traps),
revoke = _Proxy$revocable.revoke,
proxy = _Proxy$revocable.proxy;
revoke = _Proxy$revocable.revoke,
proxy = _Proxy$revocable.proxy;
state.draft_ = proxy;

@@ -592,3 +569,2 @@ state.revoke_ = revoke;

*/
var objectTraps = {

@@ -598,3 +574,2 @@ get: function get(state, prop) {

var source = latest(state);
if (!has(source, prop)) {

@@ -604,16 +579,12 @@ // non-existing or non-own property...

}
var value = source[prop];
if (state.finalized_ || !isDraftable(value)) {
return value;
} // Check for existing draft in modified state.
}
// Check for existing draft in modified state.
// Assigned values are never drafted. This catches any drafts we created, too.
if (value === peek(state.base_, prop)) {
prepareCopy(state);
return state.copy_[prop] = createProxy(state.scope_.immer_, value, state);
return state.copy_[prop] = createProxy(value, state);
}
return value;

@@ -627,8 +598,5 @@ },

},
set: function set(state, prop
/* strictly not, but helps TS */
, value) {
set: function set(state, prop /* strictly not, but helps TS */, value) {
var desc = getDescriptorFromProto(latest(state), prop);
if (desc === null || desc === void 0 ? void 0 : desc.set) {
if (desc != null && desc.set) {
// special case: if this write is captured by a setter, we have

@@ -639,10 +607,8 @@ // to trigger it with the correct context

}
if (!state.modified_) {
// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)
// from setting an existing property with value undefined to undefined (which is not a change)
var current = peek(latest(state), prop); // special case, if we assigning the original value to a draft, we can ignore the assignment
var currentState = current === null || current === void 0 ? void 0 : current[DRAFT_STATE];
var current = peek(latest(state), prop);
// special case, if we assigning the original value to a draft, we can ignore the assignment
var currentState = current == null ? void 0 : current[DRAFT_STATE];
if (currentState && currentState.base_ === value) {

@@ -653,3 +619,2 @@ state.copy_[prop] = value;

}
if (is(value, current) && (value !== undefined || has(state.base_, prop))) return true;

@@ -659,7 +624,8 @@ prepareCopy(state);

}
if (state.copy_[prop] === value && ( // special case: handle new props with value 'undefined'
value !== undefined || prop in state.copy_) || // special case: NaN
Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true; // @ts-ignore
if (state.copy_[prop] === value && (
// special case: handle new props with value 'undefined'
value !== undefined || prop in state.copy_) ||
// special case: NaN
Number.isNaN(value) && Number.isNaN(state.copy_[prop])) return true;
// @ts-ignore
state.copy_[prop] = value;

@@ -678,6 +644,4 @@ state.assigned_[prop] = true;

delete state.assigned_[prop];
} // @ts-ignore
if (state.copy_) delete state.copy_[prop];
}
delete state.copy_[prop];
return true;

@@ -693,5 +657,3 @@ },

writable: true,
configurable: state.type_ !== 1
/* ProxyArray */
|| prop !== "length",
configurable: state.type_ !== 1 /* Array */ || prop !== "length",
enumerable: desc.enumerable,

@@ -714,3 +676,2 @@ value: owner[prop]

*/
var arrayTraps = {};

@@ -724,15 +685,12 @@ each(objectTraps, function (key, fn) {

});
arrayTraps.deleteProperty = function (state, prop) {
if ( isNaN(parseInt(prop))) die(13); // @ts-ignore
if ( isNaN(parseInt(prop))) die(13);
// @ts-ignore
return arrayTraps.set.call(this, state, prop, undefined);
};
arrayTraps.set = function (state, prop, value) {
if ( prop !== "length" && isNaN(parseInt(prop))) die(14);
return objectTraps.set.call(this, state[0], prop, value, state[0]);
}; // Access a property without creating an Immer draft.
};
// Access a property without creating an Immer draft.
function peek(draft, prop) {

@@ -743,12 +701,9 @@ var state = draft[DRAFT_STATE];

}
function readPropFromProto(state, source, prop) {
var _desc$get;
var desc = getDescriptorFromProto(source, prop);
return desc ? "value" in desc ? desc.value : // This is a very special case, if the prop is a getter defined by the
// prototype, we should invoke it with the draft as context!
(_desc$get = desc.get) === null || _desc$get === void 0 ? void 0 : _desc$get.call(state.draft_) : undefined;
(_desc$get = desc.get) == null ? void 0 : _desc$get.call(state.draft_) : undefined;
}
function getDescriptorFromProto(source, prop) {

@@ -758,3 +713,2 @@ // 'in' checks proto!

var proto = Object.getPrototypeOf(source);
while (proto) {

@@ -765,10 +719,7 @@ var desc = Object.getOwnPropertyDescriptor(proto, prop);

}
return undefined;
}
function markChanged(state) {
if (!state.modified_) {
state.modified_ = true;
if (state.parent_) {

@@ -781,14 +732,11 @@ markChanged(state.parent_);

if (!state.copy_) {
state.copy_ = shallowCopy(state.base_);
state.copy_ = shallowCopy(state.base_, state.scope_.immer_.useStrictShallowCopy_);
}
}
var Immer =
/*#__PURE__*/
function () {
var Immer = /*#__PURE__*/function () {
function Immer(config) {
var _this = this;
this.useProxies_ = hasProxies;
this.autoFreeze_ = true;
this.useStrictShallowCopy_ = false;
/**

@@ -813,3 +761,2 @@ * The `produce` function takes a value and a "recipe function" (whose

*/
this.produce = function (base, recipe, patchListener) {

@@ -823,14 +770,10 @@ // curried invocation

var _this2 = this;
if (base === void 0) {
base = defaultBase;
}
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return self.produce(base, function (draft) {
var _recipe;
return (_recipe = recipe).call.apply(_recipe, [_this2, draft].concat(args));

@@ -843,9 +786,8 @@ }); // prettier-ignore

if (patchListener !== undefined && typeof patchListener !== "function") die(7);
var result; // Only plain objects, arrays, and "immerable classes" are drafted.
var result;
// Only plain objects, arrays, and "immerable classes" are drafted.
if (isDraftable(base)) {
var scope = enterScope(_this);
var proxy = createProxy(_this, base, undefined);
var proxy = createProxy(base, undefined);
var hasError = true;
try {

@@ -858,13 +800,2 @@ result = recipe(proxy);

}
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(function (result) {
usePatchesInScope(scope, patchListener);
return processResult(result, scope);
}, function (error) {
revokeScope(scope);
throw error;
});
}
usePatchesInScope(scope, patchListener);

@@ -877,3 +808,2 @@ return processResult(result, scope);

if (_this.autoFreeze_) freeze(result, true);
if (patchListener) {

@@ -885,7 +815,5 @@ var p = [];

}
return result;
} else die(21, base);
} else die(1, base);
};
this.produceWithPatches = function (base, recipe) {

@@ -898,3 +826,2 @@ // curried invocation

}
return _this.produceWithPatches(state, function (draft) {

@@ -905,5 +832,3 @@ return base.apply(void 0, [draft].concat(args));

}
var patches, inversePatches;
var result = _this.produce(base, recipe, function (p, ip) {

@@ -913,18 +838,8 @@ patches = p;

});
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(function (nextState) {
return [nextState, patches, inversePatches];
});
}
return [result, patches, inversePatches];
};
if (typeof (config === null || config === void 0 ? void 0 : config.useProxies) === "boolean") this.setUseProxies(config.useProxies);
if (typeof (config === null || config === void 0 ? void 0 : config.autoFreeze) === "boolean") this.setAutoFreeze(config.autoFreeze);
if (typeof (config == null ? void 0 : config.autoFreeze) === "boolean") this.setAutoFreeze(config.autoFreeze);
if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean") this.setUseStrictShallowCopy(config.useStrictShallowCopy);
}
var _proto = Immer.prototype;
_proto.createDraft = function createDraft(base) {

@@ -934,3 +849,3 @@ if (!isDraftable(base)) die(8);

var scope = enterScope(this);
var proxy = createProxy(this, base, undefined);
var proxy = createProxy(base, undefined);
proxy[DRAFT_STATE].isManual_ = true;

@@ -940,11 +855,5 @@ leaveScope(scope);

};
_proto.finishDraft = function finishDraft(draft, patchListener) {
var state = draft && draft[DRAFT_STATE];
{
if (!state || !state.isManual_) die(9);
if (state.finalized_) die(10);
}
if (!state || !state.isManual_) die(9);
var scope = state.scope_;

@@ -958,5 +867,3 @@ usePatchesInScope(scope, patchListener);

* By default, auto-freezing is enabled.
*/
;
*/;
_proto.setAutoFreeze = function setAutoFreeze(value) {

@@ -966,17 +873,9 @@ this.autoFreeze_ = value;

/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
*/
;
_proto.setUseProxies = function setUseProxies(value) {
if (value && !hasProxies) {
die(20);
}
this.useProxies_ = value;
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/;
_proto.setUseStrictShallowCopy = function setUseStrictShallowCopy(value) {
this.useStrictShallowCopy_ = value;
};
_proto.applyPatches = function applyPatches(base, patches) {

@@ -986,6 +885,4 @@ // If a patch replaces the entire state, take that replacement as base

var i;
for (i = patches.length - 1; i >= 0; i--) {
var patch = patches[i];
if (patch.path.length === 0 && patch.op === "replace") {

@@ -995,18 +892,14 @@ base = patch.value;

}
} // If there was a patch that replaced the entire state, start from the
}
// If there was a patch that replaced the entire state, start from the
// patch after that.
if (i > -1) {
patches = patches.slice(i + 1);
}
var applyPatchesImpl = getPlugin("Patches").applyPatches_;
if (isDraft(base)) {
// N.B: never hits if some patch a replacement, patches are never drafts
return applyPatchesImpl(base, patches);
} // Otherwise, produce a copy of the base state.
}
// Otherwise, produce a copy of the base state.
return this.produce(base, function (draft) {

@@ -1016,8 +909,7 @@ return applyPatchesImpl(draft, patches);

};
return Immer;
}();
function createProxy(immer, value, parent) {
function createProxy(value, parent) {
// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft
var draft = isMap(value) ? getPlugin("MapSet").proxyMap_(value, parent) : isSet(value) ? getPlugin("MapSet").proxySet_(value, parent) : immer.useProxies_ ? createProxyProxy(value, parent) : getPlugin("ES5").createES5Proxy_(value, parent);
var draft = isMap(value) ? proxyMap(value, parent) : isSet(value) ? proxySet(value, parent) : createProxyProxy(value, parent);
var scope = parent ? parent.scope_ : getCurrentScope();

@@ -1029,358 +921,319 @@ scope.drafts_.push(draft);

function current(value) {
if (!isDraft(value)) die(22, value);
if (!isDraft(value)) die(10, value);
return currentImpl(value);
}
function currentImpl(value) {
if (!isDraftable(value)) return value;
if (!isDraftable(value) || isFrozen(value)) return value;
var state = value[DRAFT_STATE];
var copy;
var archType = getArchtype(value);
if (state) {
if (!state.modified_ && (state.type_ < 4 || !getPlugin("ES5").hasChanges_(state))) return state.base_; // Optimization: avoid generating new drafts during copying
if (!state.modified_) return state.base_;
// Optimization: avoid generating new drafts during copying
state.finalized_ = true;
copy = copyHelper(value, archType);
state.finalized_ = false;
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
} else {
copy = copyHelper(value, archType);
copy = shallowCopy(value, true);
}
// recurse
each(copy, function (key, childValue) {
if (state && get(state.base_, key) === childValue) return; // no need to copy or search in something that didn't change
set(copy, key, currentImpl(childValue));
}); // In the future, we might consider freezing here, based on the current settings
return archType === 3
/* Set */
? new Set(copy) : copy;
}
function copyHelper(value, archType) {
// creates a shallow copy, even if it is a map or set
switch (archType) {
case 2
/* Map */
:
return new Map(value);
case 3
/* Set */
:
// Set will be cloned as array temporarily, so that we can replace individual items
return Array.from(value);
});
if (state) {
state.finalized_ = false;
}
return shallowCopy(value);
return copy;
}
function enableES5() {
function willFinalizeES5_(scope, result, isReplaced) {
if (!isReplaced) {
if (scope.patches_) {
markChangesRecursively(scope.drafts_[0]);
} // This is faster when we don't care about which attributes changed.
markChangesSweep(scope.drafts_);
} // When a child draft is returned, look for changes.
else if (isDraft(result) && result[DRAFT_STATE].scope_ === scope) {
markChangesSweep(scope.drafts_);
}
var DraftMap = /*#__PURE__*/function (_Map, _Symbol$iterator) {
_inheritsLoose(DraftMap, _Map);
function DraftMap(target, parent) {
var _this;
_this = _Map.call(this) || this;
_this[DRAFT_STATE] = {
type_: 2 /* Map */,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
assigned_: undefined,
base_: target,
draft_: _assertThisInitialized(_this),
isManual_: false,
revoked_: false
};
return _this;
}
function createES5Draft(isArray, base) {
if (isArray) {
var draft = new Array(base.length);
for (var i = 0; i < base.length; i++) {
Object.defineProperty(draft, "" + i, proxyProperty(i, true));
}
return draft;
var _proto = DraftMap.prototype;
_proto.has = function has(key) {
return latest(this[DRAFT_STATE]).has(key);
};
_proto.set = function set(key, value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!latest(state).has(key) || latest(state).get(key) !== value) {
prepareMapCopy(state);
markChanged(state);
state.assigned_.set(key, true);
state.copy_.set(key, value);
state.assigned_.set(key, true);
}
return this;
};
_proto["delete"] = function _delete(key) {
if (!this.has(key)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareMapCopy(state);
markChanged(state);
if (state.base_.has(key)) {
state.assigned_.set(key, false);
} else {
var _descriptors = getOwnPropertyDescriptors(base);
delete _descriptors[DRAFT_STATE];
var keys = ownKeys(_descriptors);
for (var _i = 0; _i < keys.length; _i++) {
var key = keys[_i];
_descriptors[key] = proxyProperty(key, isArray || !!_descriptors[key].enumerable);
}
return Object.create(Object.getPrototypeOf(base), _descriptors);
state.assigned_["delete"](key);
}
state.copy_["delete"](key);
return true;
};
_proto.clear = function clear() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareMapCopy(state);
markChanged(state);
state.assigned_ = new Map();
each(state.base_, function (key) {
state.assigned_.set(key, false);
});
state.copy_.clear();
}
};
_proto.forEach = function forEach(cb, thisArg) {
var _this2 = this;
var state = this[DRAFT_STATE];
latest(state).forEach(function (_value, key, _map) {
cb.call(thisArg, _this2.get(key), key, _this2);
});
};
_proto.get = function get(key) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
var value = latest(state).get(key);
if (state.finalized_ || !isDraftable(value)) {
return value;
}
if (value !== state.base_.get(key)) {
return value; // either already drafted or reassigned
}
// despite what it looks, this creates a draft only once, see above condition
var draft = createProxy(value, state);
prepareMapCopy(state);
state.copy_.set(key, draft);
return draft;
};
_proto.keys = function keys() {
return latest(this[DRAFT_STATE]).keys();
};
_proto.values = function values() {
var _this3 = this,
_ref;
var iterator = this.keys();
return _ref = {}, _ref[Symbol.iterator] = function () {
return _this3.values();
}, _ref.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this3.get(r.value);
return {
done: false,
value: value
};
}, _ref;
};
_proto.entries = function entries() {
var _this4 = this,
_ref2;
var iterator = this.keys();
return _ref2 = {}, _ref2[Symbol.iterator] = function () {
return _this4.entries();
}, _ref2.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this4.get(r.value);
return {
done: false,
value: [r.value, value]
};
}, _ref2;
};
_proto[_Symbol$iterator] = function () {
return this.entries();
};
_createClass(DraftMap, [{
key: "size",
get: function get() {
return latest(this[DRAFT_STATE]).size;
}
}]);
return DraftMap;
}( /*#__PURE__*/_wrapNativeSuper(Map), Symbol.iterator);
function proxyMap(target, parent) {
// @ts-ignore
return new DraftMap(target, parent);
}
function prepareMapCopy(state) {
if (!state.copy_) {
state.assigned_ = new Map();
state.copy_ = new Map(state.base_);
}
function createES5Proxy_(base, parent) {
var isArray = Array.isArray(base);
var draft = createES5Draft(isArray, base);
var state = {
type_: isArray ? 5
/* ES5Array */
: 4
/* ES5Object */
,
}
var DraftSet = /*#__PURE__*/function (_Set, _Symbol$iterator2) {
_inheritsLoose(DraftSet, _Set);
function DraftSet(target, parent) {
var _this5;
_this5 = _Set.call(this) || this;
_this5[DRAFT_STATE] = {
type_: 3 /* Set */,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
assigned_: {},
parent_: parent,
// base is the object we are drafting
base_: base,
// draft is the draft object itself, that traps all reads and reads from either the base (if unmodified) or copy (if modified)
draft_: draft,
copy_: null,
copy_: undefined,
base_: target,
draft_: _assertThisInitialized(_this5),
drafts_: new Map(),
revoked_: false,
isManual_: false
};
Object.defineProperty(draft, DRAFT_STATE, {
value: state,
// enumerable: false <- the default
writable: true
});
return draft;
} // property descriptors are recycled to make sure we don't create a get and set closure per property,
// but share them all instead
var descriptors = {};
function proxyProperty(prop, enumerable) {
var desc = descriptors[prop];
if (desc) {
desc.enumerable = enumerable;
} else {
descriptors[prop] = desc = {
configurable: true,
enumerable: enumerable,
get: function get() {
var state = this[DRAFT_STATE];
assertUnrevoked(state); // @ts-ignore
return objectTraps.get(state, prop);
},
set: function set(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state); // @ts-ignore
objectTraps.set(state, prop, value);
}
};
return _this5;
}
var _proto2 = DraftSet.prototype;
_proto2.has = function has(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
// bit of trickery here, to be able to recognize both the value, and the draft of its value
if (!state.copy_) {
return state.base_.has(value);
}
return desc;
} // This looks expensive, but only proxies are visited, and only objects without known changes are scanned.
function markChangesSweep(drafts) {
// The natural order of drafts in the `scope` array is based on when they
// were accessed. By processing drafts in reverse natural order, we have a
// better chance of processing leaf nodes first. When a leaf node is known to
// have changed, we can avoid any traversal of its ancestor nodes.
for (var i = drafts.length - 1; i >= 0; i--) {
var state = drafts[i][DRAFT_STATE];
if (!state.modified_) {
switch (state.type_) {
case 5
/* ES5Array */
:
if (hasArrayChanges(state)) markChanged(state);
break;
case 4
/* ES5Object */
:
if (hasObjectChanges(state)) markChanged(state);
break;
}
}
if (state.copy_.has(value)) return true;
if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true;
return false;
};
_proto2.add = function add(value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!this.has(value)) {
prepareSetCopy(state);
markChanged(state);
state.copy_.add(value);
}
}
function markChangesRecursively(object) {
if (!object || typeof object !== "object") return;
var state = object[DRAFT_STATE];
if (!state) return;
var base_ = state.base_,
draft_ = state.draft_,
assigned_ = state.assigned_,
type_ = state.type_;
if (type_ === 4
/* ES5Object */
) {
// Look for added keys.
// probably there is a faster way to detect changes, as sweep + recurse seems to do some
// unnecessary work.
// also: probably we can store the information we detect here, to speed up tree finalization!
each(draft_, function (key) {
if (key === DRAFT_STATE) return; // The `undefined` check is a fast path for pre-existing keys.
if (base_[key] === undefined && !has(base_, key)) {
assigned_[key] = true;
markChanged(state);
} else if (!assigned_[key]) {
// Only untouched properties trigger recursion.
markChangesRecursively(draft_[key]);
}
}); // Look for removed keys.
each(base_, function (key) {
// The `undefined` check is a fast path for pre-existing keys.
if (draft_[key] === undefined && !has(draft_, key)) {
assigned_[key] = false;
markChanged(state);
}
});
} else if (type_ === 5
/* ES5Array */
) {
if (hasArrayChanges(state)) {
markChanged(state);
assigned_.length = true;
}
if (draft_.length < base_.length) {
for (var i = draft_.length; i < base_.length; i++) {
assigned_[i] = false;
}
} else {
for (var _i2 = base_.length; _i2 < draft_.length; _i2++) {
assigned_[_i2] = true;
}
} // Minimum count is enough, the other parts has been processed.
var min = Math.min(draft_.length, base_.length);
for (var _i3 = 0; _i3 < min; _i3++) {
// Only untouched indices trigger recursion.
if (!draft_.hasOwnProperty(_i3)) {
assigned_[_i3] = true;
}
if (assigned_[_i3] === undefined) markChangesRecursively(draft_[_i3]);
}
return this;
};
_proto2["delete"] = function _delete(value) {
if (!this.has(value)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
markChanged(state);
return state.copy_["delete"](value) || (state.drafts_.has(value) ? state.copy_["delete"](state.drafts_.get(value)) : /* istanbul ignore next */false);
};
_proto2.clear = function clear() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareSetCopy(state);
markChanged(state);
state.copy_.clear();
}
};
_proto2.values = function values() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.values();
};
_proto2.entries = function entries() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.entries();
};
_proto2.keys = function keys() {
return this.values();
};
_proto2[_Symbol$iterator2] = function () {
return this.values();
};
_proto2.forEach = function forEach(cb, thisArg) {
var iterator = this.values();
var result = iterator.next();
while (!result.done) {
cb.call(thisArg, result.value, result.value, this);
result = iterator.next();
}
};
_createClass(DraftSet, [{
key: "size",
get: function get() {
return latest(this[DRAFT_STATE]).size;
}
}]);
return DraftSet;
}( /*#__PURE__*/_wrapNativeSuper(Set), Symbol.iterator);
function proxySet(target, parent) {
// @ts-ignore
return new DraftSet(target, parent);
}
function prepareSetCopy(state) {
if (!state.copy_) {
// create drafts for all entries to preserve insertion order
state.copy_ = new Set();
state.base_.forEach(function (value) {
if (isDraftable(value)) {
var draft = createProxy(value, state);
state.drafts_.set(value, draft);
state.copy_.add(draft);
} else {
state.copy_.add(value);
}
});
}
function hasObjectChanges(state) {
var base_ = state.base_,
draft_ = state.draft_; // Search for added keys and changed keys. Start at the back, because
// non-numeric keys are ordered by time of definition on the object.
var keys = ownKeys(draft_);
for (var i = keys.length - 1; i >= 0; i--) {
var key = keys[i];
if (key === DRAFT_STATE) continue;
var baseValue = base_[key]; // The `undefined` check is a fast path for pre-existing keys.
if (baseValue === undefined && !has(base_, key)) {
return true;
} // Once a base key is deleted, future changes go undetected, because its
// descriptor is erased. This branch detects any missed changes.
else {
var value = draft_[key];
var _state = value && value[DRAFT_STATE];
if (_state ? _state.base_ !== baseValue : !is(value, baseValue)) {
return true;
}
}
} // At this point, no keys were added or changed.
// Compare key count to determine if keys were deleted.
var baseIsDraft = !!base_[DRAFT_STATE];
return keys.length !== ownKeys(base_).length + (baseIsDraft ? 0 : 1); // + 1 to correct for DRAFT_STATE
}
function hasArrayChanges(state) {
var draft_ = state.draft_;
if (draft_.length !== state.base_.length) return true; // See #116
// If we first shorten the length, our array interceptors will be removed.
// If after that new items are added, result in the same original length,
// those last items will have no intercepting property.
// So if there is no own descriptor on the last position, we know that items were removed and added
// N.B.: splice, unshift, etc only shift values around, but not prop descriptors, so we only have to check
// the last one
// last descriptor can be not a trap, if the array was extended
var descriptor = Object.getOwnPropertyDescriptor(draft_, draft_.length - 1); // descriptor can be null, but only for newly created sparse arrays, eg. new Array(10)
if (descriptor && !descriptor.get) return true; // if we miss a property, it has been deleted, so array probobaly changed
for (var i = 0; i < draft_.length; i++) {
if (!draft_.hasOwnProperty(i)) return true;
} // For all other cases, we don't have to compare, as they would have been picked up by the index setters
return false;
}
function hasChanges_(state) {
return state.type_ === 4
/* ES5Object */
? hasObjectChanges(state) : hasArrayChanges(state);
}
function assertUnrevoked(state
/*ES5State | MapState | SetState*/
) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
loadPlugin("ES5", {
createES5Proxy_: createES5Proxy_,
willFinalizeES5_: willFinalizeES5_,
hasChanges_: hasChanges_
});
}
function assertUnrevoked(state /*ES5State | MapState | SetState*/) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
function enablePatches() {
var errorOffset = 16;
{
errors.push('Sets cannot have "replace" patches.', function (op) {
return "Unsupported patch operation: " + op;
}, function (path) {
return "Cannot apply patch, path doesn't resolve: " + path;
}, "Patching reserved attributes like __proto__, prototype and constructor is not allowed");
}
var REPLACE = "replace";
var ADD = "add";
var REMOVE = "remove";
function generatePatches_(state, basePath, patches, inversePatches) {
switch (state.type_) {
case 0
/* ProxyObject */
:
case 4
/* ES5Object */
:
case 2
/* Map */
:
case 0 /* Object */:
case 2 /* Map */:
return generatePatchesFromAssigned(state, basePath, patches, inversePatches);
case 5
/* ES5Array */
:
case 1
/* ProxyArray */
:
case 1 /* Array */:
return generateArrayPatches(state, basePath, patches, inversePatches);
case 3
/* Set */
:
case 3 /* Set */:
return generateSetPatches(state, basePath, patches, inversePatches);
}
}
function generateArrayPatches(state, basePath, patches, inversePatches) {
var base_ = state.base_,
assigned_ = state.assigned_;
var copy_ = state.copy_; // Reduce complexity by ensuring `base` is never longer.
assigned_ = state.assigned_;
var copy_ = state.copy_;
// Reduce complexity by ensuring `base` is never longer.
if (copy_.length < base_.length) {

@@ -1393,5 +1246,4 @@ var _ref = [copy_, base_];

inversePatches = _ref2[1];
} // Process replaced indices.
}
// Process replaced indices.
for (var i = 0; i < base_.length; i++) {

@@ -1413,8 +1265,6 @@ if (assigned_[i] && copy_[i] !== base_[i]) {

}
} // Process added indices.
}
// Process added indices.
for (var _i = base_.length; _i < copy_.length; _i++) {
var _path = basePath.concat([_i]);
patches.push({

@@ -1428,16 +1278,14 @@ op: ADD,

}
if (base_.length < copy_.length) {
for (var _i2 = copy_.length - 1; base_.length <= _i2; --_i2) {
var _path2 = basePath.concat([_i2]);
inversePatches.push({
op: REPLACE,
path: basePath.concat(["length"]),
value: base_.length
op: REMOVE,
path: _path2
});
}
} // This is used for both Map objects and normal objects.
}
// This is used for both Map objects and normal objects.
function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {
var base_ = state.base_,
copy_ = state.copy_;
copy_ = state.copy_;
each(state.assigned_, function (key, assignedValue) {

@@ -1471,6 +1319,5 @@ var origValue = get(base_, key);

}
function generateSetPatches(state, basePath, patches, inversePatches) {
var base_ = state.base_,
copy_ = state.copy_;
copy_ = state.copy_;
var i = 0;

@@ -1491,3 +1338,2 @@ base_.forEach(function (value) {

}
i++;

@@ -1510,7 +1356,5 @@ });

}
i++;
});
}
function generateReplacementPatches_(baseValue, replacement, patches, inversePatches) {

@@ -1528,48 +1372,30 @@ patches.push({

}
function applyPatches_(draft, patches) {
patches.forEach(function (patch) {
var path = patch.path,
op = patch.op;
op = patch.op;
var base = draft;
for (var i = 0; i < path.length - 1; i++) {
var parentType = getArchtype(base);
var p = path[i];
if (typeof p !== "string" && typeof p !== "number") {
p = "" + p;
} // See #738, avoid prototype pollution
if ((parentType === 0
/* Object */
|| parentType === 1
/* Array */
) && (p === "__proto__" || p === "constructor")) die(24);
if (typeof base === "function" && p === "prototype") die(24);
}
// See #738, avoid prototype pollution
if ((parentType === 0 /* Object */ || parentType === 1 /* Array */) && (p === "__proto__" || p === "constructor")) die(errorOffset + 3);
if (typeof base === "function" && p === "prototype") die(errorOffset + 3);
base = get(base, p);
if (typeof base !== "object") die(15, path.join("/"));
if (typeof base !== "object") die(errorOffset + 2, path.join("/"));
}
var type = getArchtype(base);
var value = deepClonePatchValue(patch.value); // used to clone patch to ensure original patch is not modified, see #411
var key = path[path.length - 1];
switch (op) {
case REPLACE:
switch (type) {
case 2
/* Map */
:
case 2 /* Map */:
return base.set(key, value);
/* istanbul ignore next */
case 3
/* Set */
:
die(16);
case 3 /* Set */:
die(errorOffset);
default:

@@ -1582,47 +1408,26 @@ // if value is an object, then it's assigned by reference

}
case ADD:
switch (type) {
case 1
/* Array */
:
case 1 /* Array */:
return key === "-" ? base.push(value) : base.splice(key, 0, value);
case 2
/* Map */
:
case 2 /* Map */:
return base.set(key, value);
case 3
/* Set */
:
case 3 /* Set */:
return base.add(value);
default:
return base[key] = value;
}
case REMOVE:
switch (type) {
case 1
/* Array */
:
case 1 /* Array */:
return base.splice(key, 1);
case 2
/* Map */
:
return base.delete(key);
case 3
/* Set */
:
return base.delete(patch.value);
case 2 /* Map */:
return base["delete"](key);
case 3 /* Set */:
return base["delete"](patch.value);
default:
return delete base[key];
}
default:
die(17, op);
die(errorOffset + 1, op);
}

@@ -1632,3 +1437,2 @@ });

}
function deepClonePatchValue(obj) {

@@ -1639,3 +1443,3 @@ if (!isDraftable(obj)) return obj;

var k = _ref3[0],
v = _ref3[1];
v = _ref3[1];
return [k, deepClonePatchValue(v)];

@@ -1645,11 +1449,6 @@ }));

var cloned = Object.create(Object.getPrototypeOf(obj));
for (var key in obj) {
cloned[key] = deepClonePatchValue(obj[key]);
}
for (var key in obj) cloned[key] = deepClonePatchValue(obj[key]);
if (has(obj, DRAFTABLE)) cloned[DRAFTABLE] = obj[DRAFTABLE];
return cloned;
}
function clonePatchValueIfNeeded(obj) {

@@ -1660,3 +1459,2 @@ if (isDraft(obj)) {

}
loadPlugin("Patches", {

@@ -1669,372 +1467,3 @@ applyPatches_: applyPatches_,

// types only!
function enableMapSet() {
/* istanbul ignore next */
var _extendStatics = function extendStatics(d, b) {
_extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(p)) d[p] = b[p];
}
};
return _extendStatics(d, b);
}; // Ugly hack to resolve #502 and inherit built in Map / Set
function __extends(d, b) {
_extendStatics(d, b);
function __() {
this.constructor = d;
}
d.prototype = ( // @ts-ignore
__.prototype = b.prototype, new __());
}
var DraftMap = function (_super) {
__extends(DraftMap, _super); // Create class manually, cause #502
function DraftMap(target, parent) {
this[DRAFT_STATE] = {
type_: 2
/* Map */
,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
assigned_: undefined,
base_: target,
draft_: this,
isManual_: false,
revoked_: false
};
return this;
}
var p = DraftMap.prototype;
Object.defineProperty(p, "size", {
get: function get() {
return latest(this[DRAFT_STATE]).size;
} // enumerable: false,
// configurable: true
});
p.has = function (key) {
return latest(this[DRAFT_STATE]).has(key);
};
p.set = function (key, value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!latest(state).has(key) || latest(state).get(key) !== value) {
prepareMapCopy(state);
markChanged(state);
state.assigned_.set(key, true);
state.copy_.set(key, value);
state.assigned_.set(key, true);
}
return this;
};
p.delete = function (key) {
if (!this.has(key)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareMapCopy(state);
markChanged(state);
if (state.base_.has(key)) {
state.assigned_.set(key, false);
} else {
state.assigned_.delete(key);
}
state.copy_.delete(key);
return true;
};
p.clear = function () {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareMapCopy(state);
markChanged(state);
state.assigned_ = new Map();
each(state.base_, function (key) {
state.assigned_.set(key, false);
});
state.copy_.clear();
}
};
p.forEach = function (cb, thisArg) {
var _this = this;
var state = this[DRAFT_STATE];
latest(state).forEach(function (_value, key, _map) {
cb.call(thisArg, _this.get(key), key, _this);
});
};
p.get = function (key) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
var value = latest(state).get(key);
if (state.finalized_ || !isDraftable(value)) {
return value;
}
if (value !== state.base_.get(key)) {
return value; // either already drafted or reassigned
} // despite what it looks, this creates a draft only once, see above condition
var draft = createProxy(state.scope_.immer_, value, state);
prepareMapCopy(state);
state.copy_.set(key, draft);
return draft;
};
p.keys = function () {
return latest(this[DRAFT_STATE]).keys();
};
p.values = function () {
var _this2 = this,
_ref;
var iterator = this.keys();
return _ref = {}, _ref[iteratorSymbol] = function () {
return _this2.values();
}, _ref.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this2.get(r.value);
return {
done: false,
value: value
};
}, _ref;
};
p.entries = function () {
var _this3 = this,
_ref2;
var iterator = this.keys();
return _ref2 = {}, _ref2[iteratorSymbol] = function () {
return _this3.entries();
}, _ref2.next = function next() {
var r = iterator.next();
/* istanbul ignore next */
if (r.done) return r;
var value = _this3.get(r.value);
return {
done: false,
value: [r.value, value]
};
}, _ref2;
};
p[iteratorSymbol] = function () {
return this.entries();
};
return DraftMap;
}(Map);
function proxyMap_(target, parent) {
// @ts-ignore
return new DraftMap(target, parent);
}
function prepareMapCopy(state) {
if (!state.copy_) {
state.assigned_ = new Map();
state.copy_ = new Map(state.base_);
}
}
var DraftSet = function (_super) {
__extends(DraftSet, _super); // Create class manually, cause #502
function DraftSet(target, parent) {
this[DRAFT_STATE] = {
type_: 3
/* Set */
,
parent_: parent,
scope_: parent ? parent.scope_ : getCurrentScope(),
modified_: false,
finalized_: false,
copy_: undefined,
base_: target,
draft_: this,
drafts_: new Map(),
revoked_: false,
isManual_: false
};
return this;
}
var p = DraftSet.prototype;
Object.defineProperty(p, "size", {
get: function get() {
return latest(this[DRAFT_STATE]).size;
} // enumerable: true,
});
p.has = function (value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state); // bit of trickery here, to be able to recognize both the value, and the draft of its value
if (!state.copy_) {
return state.base_.has(value);
}
if (state.copy_.has(value)) return true;
if (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value))) return true;
return false;
};
p.add = function (value) {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (!this.has(value)) {
prepareSetCopy(state);
markChanged(state);
state.copy_.add(value);
}
return this;
};
p.delete = function (value) {
if (!this.has(value)) {
return false;
}
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
markChanged(state);
return state.copy_.delete(value) || (state.drafts_.has(value) ? state.copy_.delete(state.drafts_.get(value)) :
/* istanbul ignore next */
false);
};
p.clear = function () {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
if (latest(state).size) {
prepareSetCopy(state);
markChanged(state);
state.copy_.clear();
}
};
p.values = function () {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.values();
};
p.entries = function entries() {
var state = this[DRAFT_STATE];
assertUnrevoked(state);
prepareSetCopy(state);
return state.copy_.entries();
};
p.keys = function () {
return this.values();
};
p[iteratorSymbol] = function () {
return this.values();
};
p.forEach = function forEach(cb, thisArg) {
var iterator = this.values();
var result = iterator.next();
while (!result.done) {
cb.call(thisArg, result.value, result.value, this);
result = iterator.next();
}
};
return DraftSet;
}(Set);
function proxySet_(target, parent) {
// @ts-ignore
return new DraftSet(target, parent);
}
function prepareSetCopy(state) {
if (!state.copy_) {
// create drafts for all entries to preserve insertion order
state.copy_ = new Set();
state.base_.forEach(function (value) {
if (isDraftable(value)) {
var draft = createProxy(state.scope_.immer_, value, state);
state.drafts_.set(value, draft);
state.copy_.add(draft);
} else {
state.copy_.add(value);
}
});
}
}
function assertUnrevoked(state
/*ES5State | MapState | SetState*/
) {
if (state.revoked_) die(3, JSON.stringify(latest(state)));
}
loadPlugin("MapSet", {
proxyMap_: proxyMap_,
proxySet_: proxySet_
});
}
function enableAllPlugins() {
enableES5();
enableMapSet();
enablePatches();
}
var immer =
/*#__PURE__*/
new Immer();
var immer = /*#__PURE__*/new Immer();
/**

@@ -2059,3 +1488,2 @@ * The `produce` function takes a value and a "recipe function" (whose

*/
var produce = immer.produce;

@@ -2066,6 +1494,3 @@ /**

*/
var produceWithPatches =
/*#__PURE__*/
immer.produceWithPatches.bind(immer);
var produceWithPatches = /*#__PURE__*/immer.produceWithPatches.bind(immer);
/**

@@ -2076,16 +1501,9 @@ * Pass true to automatically freeze all copies created by Immer.

*/
var setAutoFreeze =
/*#__PURE__*/
immer.setAutoFreeze.bind(immer);
var setAutoFreeze = /*#__PURE__*/immer.setAutoFreeze.bind(immer);
/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
var setUseProxies =
/*#__PURE__*/
immer.setUseProxies.bind(immer);
var setUseStrictShallowCopy = /*#__PURE__*/immer.setUseStrictShallowCopy.bind(immer);
/**

@@ -2096,6 +1514,3 @@ * Apply an array of Immer patches to the first argument.

*/
var applyPatches =
/*#__PURE__*/
immer.applyPatches.bind(immer);
var applyPatches = /*#__PURE__*/immer.applyPatches.bind(immer);
/**

@@ -2105,6 +1520,3 @@ * Create an Immer draft from the given base state, which may be a draft itself.

*/
var createDraft =
/*#__PURE__*/
immer.createDraft.bind(immer);
var createDraft = /*#__PURE__*/immer.createDraft.bind(immer);
/**

@@ -2118,6 +1530,3 @@ * Finalize an Immer draft from a `createDraft` call, returning the base state

*/
var finishDraft =
/*#__PURE__*/
immer.finishDraft.bind(immer);
var finishDraft = /*#__PURE__*/immer.finishDraft.bind(immer);
/**

@@ -2129,3 +1538,2 @@ * This function is actually a no-op, but can be used to cast an immutable type

*/
function castDraft(value) {

@@ -2139,3 +1547,2 @@ return value;

*/
function castImmutable(value) {

@@ -2151,6 +1558,2 @@ return value;

exports.current = current;
exports.default = produce;
exports.enableAllPlugins = enableAllPlugins;
exports.enableES5 = enableES5;
exports.enableMapSet = enableMapSet;
exports.enablePatches = enablePatches;

@@ -2167,3 +1570,3 @@ exports.finishDraft = finishDraft;

exports.setAutoFreeze = setAutoFreeze;
exports.setUseProxies = setUseProxies;
exports.setUseStrictShallowCopy = setUseStrictShallowCopy;

@@ -2170,0 +1573,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -1,2 +0,2 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n=n||self).immer={})}(this,(function(n){function t(n){for(var t=arguments.length,r=Array(t>1?t-1:0),e=1;e<t;e++)r[e-1]=arguments[e];throw Error("[Immer] minified error nr: "+n+(r.length?" "+r.map((function(n){return"'"+n+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function r(n){return!!n&&!!n[L]}function e(n){var t;return!!n&&(function(n){if(!n||"object"!=typeof n)return!1;var t=Object.getPrototypeOf(n);if(null===t)return!0;var r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===T}(n)||Array.isArray(n)||!!n[H]||!!(null===(t=n.constructor)||void 0===t?void 0:t[H])||v(n)||s(n))}function i(n,t,r){void 0===r&&(r=!1),0===u(n)?(r?Object.keys:U)(n).forEach((function(e){r&&"symbol"==typeof e||t(e,n[e],n)})):n.forEach((function(r,e){return t(e,r,n)}))}function u(n){var t=n[L];return t?t.t>3?t.t-4:t.t:Array.isArray(n)?1:v(n)?2:s(n)?3:0}function o(n,t){return 2===u(n)?n.has(t):Object.prototype.hasOwnProperty.call(n,t)}function f(n,t){return 2===u(n)?n.get(t):n[t]}function a(n,t,r){var e=u(n);2===e?n.set(t,r):3===e?n.add(r):n[t]=r}function c(n,t){return n===t?0!==n||1/n==1/t:n!=n&&t!=t}function v(n){return X&&n instanceof Map}function s(n){return q&&n instanceof Set}function l(n){return n.i||n.u}function p(n){if(Array.isArray(n))return Array.prototype.slice.call(n);var t=V(n);delete t[L];for(var r=U(t),e=0;e<r.length;e++){var i=r[e],u=t[i];!1===u.writable&&(u.writable=!0,u.configurable=!0),(u.get||u.set)&&(t[i]={configurable:!0,writable:!0,enumerable:u.enumerable,value:n[i]})}return Object.create(Object.getPrototypeOf(n),t)}function d(n,t){return void 0===t&&(t=!1),y(n)||r(n)||!e(n)||(u(n)>1&&(n.set=n.add=n.clear=n.delete=h),Object.freeze(n),t&&i(n,(function(n,t){return d(t,!0)}),!0)),n}function h(){t(2)}function y(n){return null==n||"object"!=typeof n||Object.isFrozen(n)}function _(n){var r=Y[n];return r||t(18,n),r}function b(n,t){Y[n]||(Y[n]=t)}function m(){return J}function j(n,t){t&&(_("Patches"),n.o=[],n.v=[],n.s=t)}function O(n){w(n),n.l.forEach(P),n.l=null}function w(n){n===J&&(J=n.p)}function S(n){return J={l:[],p:J,h:n,_:!0,m:0}}function P(n){var t=n[L];0===t.t||1===t.t?t.j():t.O=!0}function g(n,r){r.m=r.l.length;var i=r.l[0],u=void 0!==n&&n!==i;return r.h.S||_("ES5").P(r,n,u),u?(i[L].g&&(O(r),t(4)),e(n)&&(n=M(r,n),r.p||x(r,n)),r.o&&_("Patches").M(i[L].u,n,r.o,r.v)):n=M(r,i,[]),O(r),r.o&&r.s(r.o,r.v),n!==G?n:void 0}function M(n,t,r){if(y(t))return t;var e=t[L];if(!e)return i(t,(function(i,u){return A(n,e,t,i,u,r)}),!0),t;if(e.A!==n)return t;if(!e.g)return x(n,e.u,!0),e.u;if(!e.R){e.R=!0,e.A.m--;var u=4===e.t||5===e.t?e.i=p(e.k):e.i,o=u,f=!1;3===e.t&&(o=new Set(u),u.clear(),f=!0),i(o,(function(t,i){return A(n,e,u,t,i,r,f)})),x(n,u,!1),r&&n.o&&_("Patches").F(e,r,n.o,n.v)}return e.i}function A(n,t,i,u,f,c,v){if(r(f)){var s=M(n,f,c&&t&&3!==t.t&&!o(t.N,u)?c.concat(u):void 0);if(a(i,u,s),!r(s))return;n._=!1}else v&&i.add(f);if(e(f)&&!y(f)){if(!n.h.D&&n.m<1)return;M(n,f),t&&t.A.p||x(n,f)}}function x(n,t,r){void 0===r&&(r=!1),!n.p&&n.h.D&&n._&&d(t,r)}function z(n,t){var r=n[L];return(r?l(r):n)[t]}function E(n,t){if(t in n)for(var r=Object.getPrototypeOf(n);r;){var e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=Object.getPrototypeOf(r)}}function R(n){n.g||(n.g=!0,n.p&&R(n.p))}function k(n){n.i||(n.i=p(n.u))}function F(n,t,r){var e=v(t)?_("MapSet").K(t,r):s(t)?_("MapSet").$(t,r):n.S?function(n,t){var r=Array.isArray(n),e={t:r?1:0,A:t?t.A:m(),g:!1,R:!1,N:{},p:t,u:n,k:null,i:null,j:null,C:!1},i=e,u=Z;r&&(i=[e],u=nn);var o=Proxy.revocable(i,u),f=o.revoke,a=o.proxy;return e.k=a,e.j=f,a}(t,r):_("ES5").I(t,r);return(r?r.A:m()).l.push(e),e}function N(n){return r(n)||t(22,n),function n(t){if(!e(t))return t;var r,o=t[L],c=u(t);if(o){if(!o.g&&(o.t<4||!_("ES5").J(o)))return o.u;o.R=!0,r=D(t,c),o.R=!1}else r=D(t,c);return i(r,(function(t,e){o&&f(o.u,t)===e||a(r,t,n(e))})),3===c?new Set(r):r}(n)}function D(n,t){switch(t){case 2:return new Map(n);case 3:return Array.from(n)}return p(n)}function K(){function n(n,t){var r=f[n];return r?r.enumerable=t:f[n]=r={configurable:!0,enumerable:t,get:function(){return Z.get(this[L],n)},set:function(t){Z.set(this[L],n,t)}},r}function t(n){for(var t=n.length-1;t>=0;t--){var r=n[t][L];if(!r.g)switch(r.t){case 5:u(r)&&R(r);break;case 4:e(r)&&R(r)}}}function e(n){for(var t=n.u,r=n.k,e=U(r),i=e.length-1;i>=0;i--){var u=e[i];if(u!==L){var f=t[u];if(void 0===f&&!o(t,u))return!0;var a=r[u],v=a&&a[L];if(v?v.u!==f:!c(a,f))return!0}}var s=!!t[L];return e.length!==U(t).length+(s?0:1)}function u(n){var t=n.k;if(t.length!==n.u.length)return!0;var r=Object.getOwnPropertyDescriptor(t,t.length-1);if(r&&!r.get)return!0;for(var e=0;e<t.length;e++)if(!t.hasOwnProperty(e))return!0;return!1}var f={};b("ES5",{I:function(t,r){var e=Array.isArray(t),i=function(t,r){if(t){for(var e=Array(r.length),i=0;i<r.length;i++)Object.defineProperty(e,""+i,n(i,!0));return e}var u=V(r);delete u[L];for(var o=U(u),f=0;f<o.length;f++){var a=o[f];u[a]=n(a,t||!!u[a].enumerable)}return Object.create(Object.getPrototypeOf(r),u)}(e,t),u={t:e?5:4,A:r?r.A:m(),g:!1,R:!1,N:{},p:r,u:t,k:i,i:null,O:!1,C:!1};return Object.defineProperty(i,L,{value:u,writable:!0}),i},P:function(n,e,f){f?r(e)&&e[L].A===n&&t(n.l):(n.o&&function n(t){if(t&&"object"==typeof t){var r=t[L];if(r){var e=r.u,f=r.k,a=r.N,c=r.t;if(4===c)i(f,(function(t){t!==L&&(void 0!==e[t]||o(e,t)?a[t]||n(f[t]):(a[t]=!0,R(r)))})),i(e,(function(n){void 0!==f[n]||o(f,n)||(a[n]=!1,R(r))}));else if(5===c){if(u(r)&&(R(r),a.length=!0),f.length<e.length)for(var v=f.length;v<e.length;v++)a[v]=!1;else for(var s=e.length;s<f.length;s++)a[s]=!0;for(var l=Math.min(f.length,e.length),p=0;p<l;p++)f.hasOwnProperty(p)||(a[p]=!0),void 0===a[p]&&n(f[p])}}}}(n.l[0]),t(n.l))},J:function(n){return 4===n.t?e(n):u(n)}})}function $(){function n(t){if(!e(t))return t;if(Array.isArray(t))return t.map(n);if(v(t))return new Map(Array.from(t.entries()).map((function(t){return[t[0],n(t[1])]})));if(s(t))return new Set(Array.from(t).map(n));var r=Object.create(Object.getPrototypeOf(t));for(var i in t)r[i]=n(t[i]);return o(t,H)&&(r[H]=t[H]),r}function a(t){return r(t)?n(t):t}var c="add";b("Patches",{W:function(r,e){return e.forEach((function(e){for(var i=e.path,o=e.op,a=r,v=0;v<i.length-1;v++){var s=u(a),l=i[v];"string"!=typeof l&&"number"!=typeof l&&(l=""+l),0!==s&&1!==s||"__proto__"!==l&&"constructor"!==l||t(24),"function"==typeof a&&"prototype"===l&&t(24),"object"!=typeof(a=f(a,l))&&t(15,i.join("/"))}var p=u(a),d=n(e.value),h=i[i.length-1];switch(o){case"replace":switch(p){case 2:return a.set(h,d);case 3:t(16);default:return a[h]=d}case c:switch(p){case 1:return"-"===h?a.push(d):a.splice(h,0,d);case 2:return a.set(h,d);case 3:return a.add(d);default:return a[h]=d}case"remove":switch(p){case 1:return a.splice(h,1);case 2:return a.delete(h);case 3:return a.delete(e.value);default:return delete a[h]}default:t(17,o)}})),r},F:function(n,t,r,e){switch(n.t){case 0:case 4:case 2:return function(n,t,r,e){var u=n.u,v=n.i;i(n.N,(function(n,i){var s=f(u,n),l=f(v,n),p=i?o(u,n)?"replace":c:"remove";if(s!==l||"replace"!==p){var d=t.concat(n);r.push("remove"===p?{op:p,path:d}:{op:p,path:d,value:l}),e.push(p===c?{op:"remove",path:d}:"remove"===p?{op:c,path:d,value:a(s)}:{op:"replace",path:d,value:a(s)})}}))}(n,t,r,e);case 5:case 1:return function(n,t,r,e){var i=n.u,u=n.N,o=n.i;if(o.length<i.length){var f=[o,i];i=f[0],o=f[1];var v=[e,r];r=v[0],e=v[1]}for(var s=0;s<i.length;s++)if(u[s]&&o[s]!==i[s]){var l=t.concat([s]);r.push({op:"replace",path:l,value:a(o[s])}),e.push({op:"replace",path:l,value:a(i[s])})}for(var p=i.length;p<o.length;p++){var d=t.concat([p]);r.push({op:c,path:d,value:a(o[p])})}i.length<o.length&&e.push({op:"replace",path:t.concat(["length"]),value:i.length})}(n,t,r,e);case 3:return function(n,t,r,e){var i=n.u,u=n.i,o=0;i.forEach((function(n){if(!u.has(n)){var i=t.concat([o]);r.push({op:"remove",path:i,value:n}),e.unshift({op:c,path:i,value:n})}o++})),o=0,u.forEach((function(n){if(!i.has(n)){var u=t.concat([o]);r.push({op:c,path:u,value:n}),e.unshift({op:"remove",path:u,value:n})}o++}))}(n,t,r,e)}},M:function(n,t,r,e){r.push({op:"replace",path:[],value:t===G?void 0:t}),e.push({op:"replace",path:[],value:n})}})}function C(){function n(n,t){function r(){this.constructor=n}f(n,t),n.prototype=(r.prototype=t.prototype,new r)}function r(n){n.i||(n.N=new Map,n.i=new Map(n.u))}function u(n){n.i||(n.i=new Set,n.u.forEach((function(t){if(e(t)){var r=F(n.A.h,t,n);n.l.set(t,r),n.i.add(r)}else n.i.add(t)})))}function o(n){n.O&&t(3,JSON.stringify(l(n)))}var f=function(n,t){return(f=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,t){n.__proto__=t}||function(n,t){for(var r in t)t.hasOwnProperty(r)&&(n[r]=t[r])})(n,t)},a=function(){function t(n,t){return this[L]={t:2,p:t,A:t?t.A:m(),g:!1,R:!1,i:void 0,N:void 0,u:n,k:this,C:!1,O:!1},this}n(t,Map);var u=t.prototype;return Object.defineProperty(u,"size",{get:function(){return l(this[L]).size}}),u.has=function(n){return l(this[L]).has(n)},u.set=function(n,t){var e=this[L];return o(e),l(e).has(n)&&l(e).get(n)===t||(r(e),R(e),e.N.set(n,!0),e.i.set(n,t),e.N.set(n,!0)),this},u.delete=function(n){if(!this.has(n))return!1;var t=this[L];return o(t),r(t),R(t),t.u.has(n)?t.N.set(n,!1):t.N.delete(n),t.i.delete(n),!0},u.clear=function(){var n=this[L];o(n),l(n).size&&(r(n),R(n),n.N=new Map,i(n.u,(function(t){n.N.set(t,!1)})),n.i.clear())},u.forEach=function(n,t){var r=this;l(this[L]).forEach((function(e,i){n.call(t,r.get(i),i,r)}))},u.get=function(n){var t=this[L];o(t);var i=l(t).get(n);if(t.R||!e(i))return i;if(i!==t.u.get(n))return i;var u=F(t.A.h,i,t);return r(t),t.i.set(n,u),u},u.keys=function(){return l(this[L]).keys()},u.values=function(){var n,t=this,r=this.keys();return(n={})[Q]=function(){return t.values()},n.next=function(){var n=r.next();return n.done?n:{done:!1,value:t.get(n.value)}},n},u.entries=function(){var n,t=this,r=this.keys();return(n={})[Q]=function(){return t.entries()},n.next=function(){var n=r.next();if(n.done)return n;var e=t.get(n.value);return{done:!1,value:[n.value,e]}},n},u[Q]=function(){return this.entries()},t}(),c=function(){function t(n,t){return this[L]={t:3,p:t,A:t?t.A:m(),g:!1,R:!1,i:void 0,u:n,k:this,l:new Map,O:!1,C:!1},this}n(t,Set);var r=t.prototype;return Object.defineProperty(r,"size",{get:function(){return l(this[L]).size}}),r.has=function(n){var t=this[L];return o(t),t.i?!!t.i.has(n)||!(!t.l.has(n)||!t.i.has(t.l.get(n))):t.u.has(n)},r.add=function(n){var t=this[L];return o(t),this.has(n)||(u(t),R(t),t.i.add(n)),this},r.delete=function(n){if(!this.has(n))return!1;var t=this[L];return o(t),u(t),R(t),t.i.delete(n)||!!t.l.has(n)&&t.i.delete(t.l.get(n))},r.clear=function(){var n=this[L];o(n),l(n).size&&(u(n),R(n),n.i.clear())},r.values=function(){var n=this[L];return o(n),u(n),n.i.values()},r.entries=function(){var n=this[L];return o(n),u(n),n.i.entries()},r.keys=function(){return this.values()},r[Q]=function(){return this.values()},r.forEach=function(n,t){for(var r=this.values(),e=r.next();!e.done;)n.call(t,e.value,e.value,this),e=r.next()},t}();b("MapSet",{K:function(n,t){return new a(n,t)},$:function(n,t){return new c(n,t)}})}var I,J,W="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),X="undefined"!=typeof Map,q="undefined"!=typeof Set,B="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,G=W?Symbol.for("immer-nothing"):((I={})["immer-nothing"]=!0,I),H=W?Symbol.for("immer-draftable"):"__$immer_draftable",L=W?Symbol.for("immer-state"):"__$immer_state",Q="undefined"!=typeof Symbol&&Symbol.iterator||"@@iterator",T=""+Object.prototype.constructor,U="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(n){return Object.getOwnPropertyNames(n).concat(Object.getOwnPropertySymbols(n))}:Object.getOwnPropertyNames,V=Object.getOwnPropertyDescriptors||function(n){var t={};return U(n).forEach((function(r){t[r]=Object.getOwnPropertyDescriptor(n,r)})),t},Y={},Z={get:function(n,t){if(t===L)return n;var r=l(n);if(!o(r,t))return function(n,t,r){var e,i=E(t,r);return i?"value"in i?i.value:null===(e=i.get)||void 0===e?void 0:e.call(n.k):void 0}(n,r,t);var i=r[t];return n.R||!e(i)?i:i===z(n.u,t)?(k(n),n.i[t]=F(n.A.h,i,n)):i},has:function(n,t){return t in l(n)},ownKeys:function(n){return Reflect.ownKeys(l(n))},set:function(n,t,r){var e=E(l(n),t);if(null==e?void 0:e.set)return e.set.call(n.k,r),!0;if(!n.g){var i=z(l(n),t),u=null==i?void 0:i[L];if(u&&u.u===r)return n.i[t]=r,n.N[t]=!1,!0;if(c(r,i)&&(void 0!==r||o(n.u,t)))return!0;k(n),R(n)}return n.i[t]===r&&(void 0!==r||t in n.i)||Number.isNaN(r)&&Number.isNaN(n.i[t])||(n.i[t]=r,n.N[t]=!0),!0},deleteProperty:function(n,t){return void 0!==z(n.u,t)||t in n.u?(n.N[t]=!1,k(n),R(n)):delete n.N[t],n.i&&delete n.i[t],!0},getOwnPropertyDescriptor:function(n,t){var r=l(n),e=Reflect.getOwnPropertyDescriptor(r,t);return e?{writable:!0,configurable:1!==n.t||"length"!==t,enumerable:e.enumerable,value:r[t]}:e},defineProperty:function(){t(11)},getPrototypeOf:function(n){return Object.getPrototypeOf(n.u)},setPrototypeOf:function(){t(12)}},nn={};i(Z,(function(n,t){nn[n]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),nn.deleteProperty=function(n,t){return nn.set.call(this,n,t,void 0)},nn.set=function(n,t,r){return Z.set.call(this,n[0],t,r,n[0])};var tn=function(){function n(n){var r=this;this.S=B,this.D=!0,this.produce=function(n,i,u){if("function"==typeof n&&"function"!=typeof i){var o=i;i=n;var f=r;return function(n){var t=this;void 0===n&&(n=o);for(var r=arguments.length,e=Array(r>1?r-1:0),u=1;u<r;u++)e[u-1]=arguments[u];return f.produce(n,(function(n){var r;return(r=i).call.apply(r,[t,n].concat(e))}))}}var a;if("function"!=typeof i&&t(6),void 0!==u&&"function"!=typeof u&&t(7),e(n)){var c=S(r),v=F(r,n,void 0),s=!0;try{a=i(v),s=!1}finally{s?O(c):w(c)}return"undefined"!=typeof Promise&&a instanceof Promise?a.then((function(n){return j(c,u),g(n,c)}),(function(n){throw O(c),n})):(j(c,u),g(a,c))}if(!n||"object"!=typeof n){if(void 0===(a=i(n))&&(a=n),a===G&&(a=void 0),r.D&&d(a,!0),u){var l=[],p=[];_("Patches").M(n,a,l,p),u(l,p)}return a}t(21,n)},this.produceWithPatches=function(n,t){if("function"==typeof n)return function(t){for(var e=arguments.length,i=Array(e>1?e-1:0),u=1;u<e;u++)i[u-1]=arguments[u];return r.produceWithPatches(t,(function(t){return n.apply(void 0,[t].concat(i))}))};var e,i,u=r.produce(n,t,(function(n,t){e=n,i=t}));return"undefined"!=typeof Promise&&u instanceof Promise?u.then((function(n){return[n,e,i]})):[u,e,i]},"boolean"==typeof(null==n?void 0:n.useProxies)&&this.setUseProxies(n.useProxies),"boolean"==typeof(null==n?void 0:n.autoFreeze)&&this.setAutoFreeze(n.autoFreeze)}var i=n.prototype;return i.createDraft=function(n){e(n)||t(8),r(n)&&(n=N(n));var i=S(this),u=F(this,n,void 0);return u[L].C=!0,w(i),u},i.finishDraft=function(n,t){var r=(n&&n[L]).A;return j(r,t),g(void 0,r)},i.setAutoFreeze=function(n){this.D=n},i.setUseProxies=function(n){n&&!B&&t(20),this.S=n},i.applyPatches=function(n,t){var e;for(e=t.length-1;e>=0;e--){var i=t[e];if(0===i.path.length&&"replace"===i.op){n=i.value;break}}e>-1&&(t=t.slice(e+1));var u=_("Patches").W;return r(n)?u(n,t):this.produce(n,(function(n){return u(n,t)}))},n}(),rn=new tn,en=rn.produce,un=rn.produceWithPatches.bind(rn),on=rn.setAutoFreeze.bind(rn),fn=rn.setUseProxies.bind(rn),an=rn.applyPatches.bind(rn),cn=rn.createDraft.bind(rn),vn=rn.finishDraft.bind(rn);n.Immer=tn,n.applyPatches=an,n.castDraft=function(n){return n},n.castImmutable=function(n){return n},n.createDraft=cn,n.current=N,n.default=en,n.enableAllPlugins=function(){K(),C(),$()},n.enableES5=K,n.enableMapSet=C,n.enablePatches=$,n.finishDraft=vn,n.freeze=d,n.immerable=H,n.isDraft=r,n.isDraftable=e,n.nothing=G,n.original=function(n){return r(n)||t(23,n),n[L].u},n.produce=en,n.produceWithPatches=un,n.setAutoFreeze=on,n.setUseProxies=fn,Object.defineProperty(n,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).immer={})}(this,(function(e){"use strict";var t=Symbol.for("immer-nothing"),r=Symbol.for("immer-draftable"),n=Symbol.for("immer-state");function o(e){throw new Error("[Immer] minified error nr: "+e+". Full error at: https://bit.ly/3cXEKWf")}function a(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,"symbol"==typeof(o=function(e,t){if("object"!=typeof e||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(n.key))?o:String(o),n)}var o}function i(e,t,r){return t&&a(e.prototype,t),r&&a(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function u(){return(u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function c(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,s(e,t)}function f(e){return(f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function s(e,t){return(s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function p(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function l(e,t,r){return(l=p()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&s(o,r.prototype),o}).apply(null,arguments)}function _(e){var t="function"==typeof Map?new Map:void 0;return(_=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return l(e,arguments,f(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),s(r,e)})(e)}function h(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e){return!!e&&!!e[n]}function d(e){var t;return!!e&&(b(e)||Array.isArray(e)||!!e[r]||!(null==(t=e.constructor)||!t[r])||S(e)||j(e))}var y=Object.prototype.constructor.toString();function b(e){if(!e||"object"!=typeof e)return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;var r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===y}function g(e,t){0===m(e)?Object.entries(e).forEach((function(r){t(r[0],r[1],e)})):e.forEach((function(r,n){return t(n,r,e)}))}function m(e){var t=e[n];return t?t.type_:Array.isArray(e)?1:S(e)?2:j(e)?3:0}function w(e,t){return 2===m(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function O(e,t){return 2===m(e)?e.get(t):e[t]}function P(e,t,r){var n=m(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function S(e){return e instanceof Map}function j(e){return e instanceof Set}function z(e){return e.copy_||e.base_}function A(e,t){if(S(e))return new Map(e);if(j(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);if(!t&&b(e)){if(!Object.getPrototypeOf(e)){var r=Object.create(null);return Object.assign(r,e)}return u({},e)}var o=Object.getOwnPropertyDescriptors(e);delete o[n];for(var a=Reflect.ownKeys(o),i=0;i<a.length;i++){var c=a[i],f=o[c];!1===f.writable&&(f.writable=!0,f.configurable=!0),(f.get||f.set)&&(o[c]={configurable:!0,writable:!0,enumerable:f.enumerable,value:e[c]})}return Object.create(Object.getPrototypeOf(e),o)}function F(e,t){return void 0===t&&(t=!1),D(e)||v(e)||!d(e)||(m(e)>1&&(e.set=e.add=e.clear=e.delete=k),Object.freeze(e),t&&g(e,(function(e,t){return F(t,!0)}))),e}function k(){o(2)}function D(e){return Object.isFrozen(e)}var M,E={};function x(e){var t=E[e];return t||o(0),t}function R(){return M}function C(e,t){t&&(x("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function N(e){W(e),e.drafts_.forEach(U),e.drafts_=null}function W(e){e===M&&(M=e.parent_)}function K(e){return M={drafts_:[],parent_:M,immer_:e,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function U(e){var t=e[n];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function I(e,r){r.unfinalizedDrafts_=r.drafts_.length;var a=r.drafts_[0];return void 0!==e&&e!==a?(a[n].modified_&&(N(r),o(4)),d(e)&&(e=B(r,e),r.parent_||T(r,e)),r.patches_&&x("Patches").generateReplacementPatches_(a[n].base_,e,r.patches_,r.inversePatches_)):e=B(r,a,[]),N(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==t?e:void 0}function B(e,t,r){if(D(t))return t;var o=t[n];if(!o)return g(t,(function(n,a){return L(e,o,t,n,a,r)})),t;if(o.scope_!==e)return t;if(!o.modified_)return T(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;var a=o.copy_,i=a,u=!1;3===o.type_&&(i=new Set(a),a.clear(),u=!0),g(i,(function(t,n){return L(e,o,a,t,n,r,u)})),T(e,a,!1),r&&e.patches_&&x("Patches").generatePatches_(o,r,e.patches_,e.inversePatches_)}return o.copy_}function L(e,t,r,n,o,a,i){if(v(o)){var u=B(e,o,a&&t&&3!==t.type_&&!w(t.assigned_,n)?a.concat(n):void 0);if(P(r,n,u),!v(u))return;e.canAutoFreeze_=!1}else i&&r.add(o);if(d(o)&&!D(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;B(e,o),t&&t.scope_.parent_||T(e,o)}}function T(e,t,r){void 0===r&&(r=!1),!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&F(t,r)}var J={get:function(e,t){if(t===n)return e;var r=z(e);if(!w(r,t))return function(e,t,r){var n,o=G(t,r);return o?"value"in o?o.value:null==(n=o.get)?void 0:n.call(e.draft_):void 0}(e,r,t);var o=r[t];return e.finalized_||!d(o)?o:o===q(e.base_,t)?(Q(e),e.copy_[t]=Y(o,e)):o},has:function(e,t){return t in z(e)},ownKeys:function(e){return Reflect.ownKeys(z(e))},set:function(e,t,r){var o,a,i=G(z(e),t);if(null!=i&&i.set)return i.set.call(e.draft_,r),!0;if(!e.modified_){var u=q(z(e),t),c=null==u?void 0:u[n];if(c&&c.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(((o=r)===(a=u)?0!==o||1/o==1/a:o!=o&&a!=a)&&(void 0!==r||w(e.base_,t)))return!0;Q(e),H(e)}return e.copy_[t]===r&&(void 0!==r||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty:function(e,t){return void 0!==q(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,Q(e),H(e)):delete e.assigned_[t],delete e.copy_[t],!0},getOwnPropertyDescriptor:function(e,t){var r=z(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n?{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}:n},defineProperty:function(){o(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.base_)},setPrototypeOf:function(){o(12)}},X={};function q(e,t){var r=e[n];return(r?z(r):e)[t]}function G(e,t){if(t in e)for(var r=Object.getPrototypeOf(e);r;){var n=Object.getOwnPropertyDescriptor(r,t);if(n)return n;r=Object.getPrototypeOf(r)}}function H(e){e.modified_||(e.modified_=!0,e.parent_&&H(e.parent_))}function Q(e){e.copy_||(e.copy_=A(e.base_,e.scope_.immer_.useStrictShallowCopy_))}g(J,(function(e,t){X[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),X.deleteProperty=function(e,t){return X.set.call(this,e,t,void 0)},X.set=function(e,t,r){return J.set.call(this,e[0],t,r,e[0])};var V=function(){function e(e){var r=this;this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=function(e,n,a){if("function"==typeof e&&"function"!=typeof n){var i=n;n=e;var u=r;return function(e){var t=this;void 0===e&&(e=i);for(var r=arguments.length,o=new Array(r>1?r-1:0),a=1;a<r;a++)o[a-1]=arguments[a];return u.produce(e,(function(e){var r;return(r=n).call.apply(r,[t,e].concat(o))}))}}var c;if("function"!=typeof n&&o(6),void 0!==a&&"function"!=typeof a&&o(7),d(e)){var f=K(r),s=Y(e,void 0),p=!0;try{c=n(s),p=!1}finally{p?N(f):W(f)}return C(f,a),I(c,f)}if(!e||"object"!=typeof e){if(void 0===(c=n(e))&&(c=e),c===t&&(c=void 0),r.autoFreeze_&&F(c,!0),a){var l=[],_=[];x("Patches").generateReplacementPatches_(e,c,l,_),a(l,_)}return c}o(1)},this.produceWithPatches=function(e,t){return"function"==typeof e?function(t){for(var n=arguments.length,o=new Array(n>1?n-1:0),a=1;a<n;a++)o[a-1]=arguments[a];return r.produceWithPatches(t,(function(t){return e.apply(void 0,[t].concat(o))}))}:[r.produce(e,t,(function(e,t){n=e,o=t})),n,o];var n,o},"boolean"==typeof(null==e?void 0:e.autoFreeze)&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof(null==e?void 0:e.useStrictShallowCopy)&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}var r=e.prototype;return r.createDraft=function(e){d(e)||o(8),v(e)&&(e=Z(e));var t=K(this),r=Y(e,void 0);return r[n].isManual_=!0,W(t),r},r.finishDraft=function(e,t){var r=e&&e[n];r&&r.isManual_||o(9);var a=r.scope_;return C(a,t),I(void 0,a)},r.setAutoFreeze=function(e){this.autoFreeze_=e},r.setUseStrictShallowCopy=function(e){this.useStrictShallowCopy_=e},r.applyPatches=function(e,t){var r;for(r=t.length-1;r>=0;r--){var n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));var o=x("Patches").applyPatches_;return v(e)?o(e,t):this.produce(e,(function(e){return o(e,t)}))},e}();function Y(e,t){var r=S(e)?function(e,t){return new $(e,t)}(e,t):j(e)?function(e,t){return new te(e,t)}(e,t):function(e,t){var r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:R(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1},o=n,a=J;r&&(o=[n],a=X);var i=Proxy.revocable(o,a),u=i.revoke,c=i.proxy;return n.draft_=c,n.revoke_=u,c}(e,t);return(t?t.scope_:R()).drafts_.push(r),r}function Z(e){return v(e)||o(10),function e(t){if(!d(t)||D(t))return t;var r,o=t[n];if(o){if(!o.modified_)return o.base_;o.finalized_=!0,r=A(t,o.scope_.immer_.useStrictShallowCopy_)}else r=A(t,!0);return g(r,(function(t,n){P(r,t,e(n))})),o&&(o.finalized_=!1),r}(e)}var $=function(e,t){function r(t,r){var o;return(o=e.call(this)||this)[n]={type_:2,parent_:r,scope_:r?r.scope_:R(),modified_:!1,finalized_:!1,copy_:void 0,assigned_:void 0,base_:t,draft_:h(o),isManual_:!1,revoked_:!1},o}c(r,e);var o=r.prototype;return o.has=function(e){return z(this[n]).has(e)},o.set=function(e,t){var r=this[n];return ne(r),z(r).has(e)&&z(r).get(e)===t||(ee(r),H(r),r.assigned_.set(e,!0),r.copy_.set(e,t),r.assigned_.set(e,!0)),this},o.delete=function(e){if(!this.has(e))return!1;var t=this[n];return ne(t),ee(t),H(t),t.base_.has(e)?t.assigned_.set(e,!1):t.assigned_.delete(e),t.copy_.delete(e),!0},o.clear=function(){var e=this[n];ne(e),z(e).size&&(ee(e),H(e),e.assigned_=new Map,g(e.base_,(function(t){e.assigned_.set(t,!1)})),e.copy_.clear())},o.forEach=function(e,t){var r=this;z(this[n]).forEach((function(n,o,a){e.call(t,r.get(o),o,r)}))},o.get=function(e){var t=this[n];ne(t);var r=z(t).get(e);if(t.finalized_||!d(r))return r;if(r!==t.base_.get(e))return r;var o=Y(r,t);return ee(t),t.copy_.set(e,o),o},o.keys=function(){return z(this[n]).keys()},o.values=function(){var e,t=this,r=this.keys();return(e={})[Symbol.iterator]=function(){return t.values()},e.next=function(){var e=r.next();return e.done?e:{done:!1,value:t.get(e.value)}},e},o.entries=function(){var e,t=this,r=this.keys();return(e={})[Symbol.iterator]=function(){return t.entries()},e.next=function(){var e=r.next();if(e.done)return e;var n=t.get(e.value);return{done:!1,value:[e.value,n]}},e},o[t]=function(){return this.entries()},i(r,[{key:"size",get:function(){return z(this[n]).size}}]),r}(_(Map),Symbol.iterator);function ee(e){e.copy_||(e.assigned_=new Map,e.copy_=new Map(e.base_))}var te=function(e,t){function r(t,r){var o;return(o=e.call(this)||this)[n]={type_:3,parent_:r,scope_:r?r.scope_:R(),modified_:!1,finalized_:!1,copy_:void 0,base_:t,draft_:h(o),drafts_:new Map,revoked_:!1,isManual_:!1},o}c(r,e);var o=r.prototype;return o.has=function(e){var t=this[n];return ne(t),t.copy_?!!t.copy_.has(e)||!(!t.drafts_.has(e)||!t.copy_.has(t.drafts_.get(e))):t.base_.has(e)},o.add=function(e){var t=this[n];return ne(t),this.has(e)||(re(t),H(t),t.copy_.add(e)),this},o.delete=function(e){if(!this.has(e))return!1;var t=this[n];return ne(t),re(t),H(t),t.copy_.delete(e)||!!t.drafts_.has(e)&&t.copy_.delete(t.drafts_.get(e))},o.clear=function(){var e=this[n];ne(e),z(e).size&&(re(e),H(e),e.copy_.clear())},o.values=function(){var e=this[n];return ne(e),re(e),e.copy_.values()},o.entries=function(){var e=this[n];return ne(e),re(e),e.copy_.entries()},o.keys=function(){return this.values()},o[t]=function(){return this.values()},o.forEach=function(e,t){for(var r=this.values(),n=r.next();!n.done;)e.call(t,n.value,n.value,this),n=r.next()},i(r,[{key:"size",get:function(){return z(this[n]).size}}]),r}(_(Set),Symbol.iterator);function re(e){e.copy_||(e.copy_=new Set,e.base_.forEach((function(t){if(d(t)){var r=Y(t,e);e.drafts_.set(t,r),e.copy_.add(r)}else e.copy_.add(t)})))}function ne(e){e.revoked_&&o(3,JSON.stringify(z(e)))}var oe=new V,ae=oe.produce,ie=oe.produceWithPatches.bind(oe),ue=oe.setAutoFreeze.bind(oe),ce=oe.setUseStrictShallowCopy.bind(oe),fe=oe.applyPatches.bind(oe),se=oe.createDraft.bind(oe),pe=oe.finishDraft.bind(oe);e.Immer=V,e.applyPatches=fe,e.castDraft=function(e){return e},e.castImmutable=function(e){return e},e.createDraft=se,e.current=Z,e.enablePatches=function(){var e="add";function n(e){if(!d(e))return e;if(Array.isArray(e))return e.map(n);if(S(e))return new Map(Array.from(e.entries()).map((function(e){return[e[0],n(e[1])]})));if(j(e))return new Set(Array.from(e).map(n));var t=Object.create(Object.getPrototypeOf(e));for(var o in e)t[o]=n(e[o]);return w(e,r)&&(t[r]=e[r]),t}function a(e){return v(e)?n(e):e}E.Patches||(E.Patches={applyPatches_:function(t,r){return r.forEach((function(r){for(var a=r.path,i=r.op,u=t,c=0;c<a.length-1;c++){var f=m(u),s=a[c];"string"!=typeof s&&"number"!=typeof s&&(s=""+s),0!==f&&1!==f||"__proto__"!==s&&"constructor"!==s||o(19),"function"==typeof u&&"prototype"===s&&o(19),"object"!=typeof(u=O(u,s))&&o(18,a.join("/"))}var p=m(u),l=n(r.value),_=a[a.length-1];switch(i){case"replace":switch(p){case 2:return u.set(_,l);case 3:o(16);default:return u[_]=l}case e:switch(p){case 1:return"-"===_?u.push(l):u.splice(_,0,l);case 2:return u.set(_,l);case 3:return u.add(l);default:return u[_]=l}case"remove":switch(p){case 1:return u.splice(_,1);case 2:return u.delete(_);case 3:return u.delete(r.value);default:return delete u[_]}default:o(17)}})),t},generatePatches_:function(t,r,n,o){switch(t.type_){case 0:case 2:return function(t,r,n,o){var i=t.base_,u=t.copy_;g(t.assigned_,(function(t,c){var f=O(i,t),s=O(u,t),p=c?w(i,t)?"replace":e:"remove";if(f!==s||"replace"!==p){var l=r.concat(t);n.push("remove"===p?{op:p,path:l}:{op:p,path:l,value:s}),o.push(p===e?{op:"remove",path:l}:"remove"===p?{op:e,path:l,value:a(f)}:{op:"replace",path:l,value:a(f)})}}))}(t,r,n,o);case 1:return function(t,r,n,o){var i=t.base_,u=t.assigned_,c=t.copy_;if(c.length<i.length){var f=[c,i];i=f[0],c=f[1];var s=[o,n];n=s[0],o=s[1]}for(var p=0;p<i.length;p++)if(u[p]&&c[p]!==i[p]){var l=r.concat([p]);n.push({op:"replace",path:l,value:a(c[p])}),o.push({op:"replace",path:l,value:a(i[p])})}for(var _=i.length;_<c.length;_++){var h=r.concat([_]);n.push({op:e,path:h,value:a(c[_])})}for(var v=c.length-1;i.length<=v;--v){var d=r.concat([v]);o.push({op:"remove",path:d})}}(t,r,n,o);case 3:return function(t,r,n,o){var a=t.base_,i=t.copy_,u=0;a.forEach((function(t){if(!i.has(t)){var a=r.concat([u]);n.push({op:"remove",path:a,value:t}),o.unshift({op:e,path:a,value:t})}u++})),u=0,i.forEach((function(t){if(!a.has(t)){var i=r.concat([u]);n.push({op:e,path:i,value:t}),o.unshift({op:"remove",path:i,value:t})}u++}))}(t,r,n,o)}},generateReplacementPatches_:function(e,r,n,o){n.push({op:"replace",path:[],value:r===t?void 0:r}),o.push({op:"replace",path:[],value:e})}})},e.finishDraft=pe,e.freeze=F,e.immerable=r,e.isDraft=v,e.isDraftable=d,e.nothing=t,e.original=function(e){return v(e)||o(15),e[n].base_},e.produce=ae,e.produceWithPatches=ie,e.setAutoFreeze=ue,e.setUseStrictShallowCopy=ce,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=immer.umd.production.min.js.map

@@ -12,2 +12,3 @@ export * from "./utils/env";

export * from "./core/current";
export * from "./core/mapset";
//# sourceMappingURL=internal.d.ts.map

@@ -1,2 +0,2 @@

import { Nothing } from "../internal";
import { NOTHING } from "../internal";
declare type AnyFunc = (...args: any[]) => any;

@@ -23,5 +23,5 @@ declare type PrimitiveType = number | string | boolean;

/** Convert a readonly type into a mutable type, if possible */
export declare type Draft<T> = T extends PrimitiveType ? T : T extends AtomicObject ? T : T extends IfAvailable<ReadonlyMap<infer K, infer V>> ? Map<Draft<K>, Draft<V>> : T extends IfAvailable<ReadonlySet<infer V>> ? Set<Draft<V>> : T extends WeakReferences ? T : T extends object ? WritableDraft<T> : T;
export declare type Draft<T> = T extends PrimitiveType ? T : T extends AtomicObject ? T : T extends ReadonlyMap<infer K, infer V> ? Map<Draft<K>, Draft<V>> : T extends ReadonlySet<infer V> ? Set<Draft<V>> : T extends WeakReferences ? T : T extends object ? WritableDraft<T> : T;
/** Convert a mutable type into a readonly type */
export declare type Immutable<T> = T extends PrimitiveType ? T : T extends AtomicObject ? T : T extends IfAvailable<ReadonlyMap<infer K, infer V>> ? ReadonlyMap<Immutable<K>, Immutable<V>> : T extends IfAvailable<ReadonlySet<infer V>> ? ReadonlySet<Immutable<V>> : T extends WeakReferences ? T : T extends object ? {
export declare type Immutable<T> = T extends PrimitiveType ? T : T extends AtomicObject ? T : T extends ReadonlyMap<infer K, infer V> ? ReadonlyMap<Immutable<K>, Immutable<V>> : T extends ReadonlySet<infer V> ? ReadonlySet<Immutable<V>> : T extends WeakReferences ? T : T extends object ? {
readonly [K in keyof T]: Immutable<T[K]>;

@@ -36,5 +36,5 @@ } : T;

/** Converts `nothing` into `undefined` */
declare type FromNothing<T> = T extends Nothing ? undefined : T;
declare type FromNothing<T> = T extends typeof NOTHING ? undefined : T;
/** The inferred return type of `produce` */
export declare type Produced<Base, Return> = Return extends void ? Base : Return extends Promise<infer Result> ? Promise<Result extends void ? Base : FromNothing<Result>> : FromNothing<Return>;
export declare type Produced<Base, Return> = Return extends void ? Base : FromNothing<Return>;
/**

@@ -44,5 +44,4 @@ * Utility types

declare type PatchesTuple<T> = readonly [T, Patch[], Patch[]];
declare type ValidRecipeReturnType<State> = State | void | undefined | (State extends undefined ? Nothing : never);
declare type ValidRecipeReturnTypePossiblyPromise<State> = ValidRecipeReturnType<State> | Promise<ValidRecipeReturnType<State>>;
declare type PromisifyReturnIfNeeded<State, Recipe extends AnyFunc, UsePatches extends boolean> = ReturnType<Recipe> extends Promise<any> ? Promise<UsePatches extends true ? PatchesTuple<State> : State> : UsePatches extends true ? PatchesTuple<State> : State;
declare type ValidRecipeReturnType<State> = State | void | undefined | (State extends undefined ? typeof NOTHING : never);
declare type ReturnTypeWithPatchesIfNeeded<State, UsePatches extends boolean> = UsePatches extends true ? PatchesTuple<State> : State;
/**

@@ -53,4 +52,4 @@ * Core Producer inference

declare type InferInitialStateFromCurried<Curried> = Curried extends (base: infer State, ...rest: any[]) => any ? State : never;
declare type InferCurriedFromRecipe<Recipe, UsePatches extends boolean> = Recipe extends (draft: infer DraftState, ...args: infer RestArgs) => any ? ReturnType<Recipe> extends ValidRecipeReturnTypePossiblyPromise<DraftState> ? (base: Immutable<DraftState>, ...args: RestArgs) => PromisifyReturnIfNeeded<DraftState, Recipe, UsePatches> : never : never;
declare type InferCurriedFromInitialStateAndRecipe<State, Recipe, UsePatches extends boolean> = Recipe extends (draft: Draft<State>, ...rest: infer RestArgs) => ValidRecipeReturnTypePossiblyPromise<State> ? (base?: State | undefined, ...args: RestArgs) => PromisifyReturnIfNeeded<State, Recipe, UsePatches> : never;
declare type InferCurriedFromRecipe<Recipe, UsePatches extends boolean> = Recipe extends (draft: infer DraftState, ...args: infer RestArgs) => any ? ReturnType<Recipe> extends ValidRecipeReturnType<DraftState> ? (base: Immutable<DraftState>, ...args: RestArgs) => ReturnTypeWithPatchesIfNeeded<DraftState, UsePatches> : never : never;
declare type InferCurriedFromInitialStateAndRecipe<State, Recipe, UsePatches extends boolean> = Recipe extends (draft: Draft<State>, ...rest: infer RestArgs) => ValidRecipeReturnType<State> ? (base?: State | undefined, ...args: RestArgs) => ReturnTypeWithPatchesIfNeeded<State, UsePatches> : never;
/**

@@ -90,4 +89,2 @@ * The `produce` function takes a value and a "recipe function" (whose

base: Base, recipe: (draft: D) => ValidRecipeReturnType<D>, listener?: PatchListener): Base;
/** Promisified normal producer */
<Base, D = Draft<Base>>(base: Base, recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>, listener?: PatchListener): Promise<Base>;
}

@@ -104,3 +101,2 @@ /**

<Base, D = Draft<Base>>(base: Base, recipe: (draft: D) => ValidRecipeReturnType<D>, listener?: PatchListener): PatchesTuple<Base>;
<Base, D = Draft<Base>>(base: Base, recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>, listener?: PatchListener): Promise<PatchesTuple<Base>>;
}

@@ -110,5 +106,5 @@ /**

*/
export declare type Producer<T> = (draft: Draft<T>) => ValidRecipeReturnType<Draft<T>> | Promise<ValidRecipeReturnType<Draft<T>>>;
export declare type Producer<T> = (draft: Draft<T>) => ValidRecipeReturnType<Draft<T>>;
export declare function never_used(): void;
export {};
//# sourceMappingURL=types-external.d.ts.map

@@ -1,2 +0,2 @@

import { SetState, ImmerScope, ProxyObjectState, ProxyArrayState, ES5ObjectState, ES5ArrayState, MapState, DRAFT_STATE } from "../internal";
import { SetState, ImmerScope, ProxyObjectState, ProxyArrayState, MapState, DRAFT_STATE } from "../internal";
export declare type Objectish = AnyObject | AnyArray | AnyMap | AnySet;

@@ -10,3 +10,3 @@ export declare type ObjectishNoSet = AnyObject | AnyArray | AnyMap;

export declare type AnyMap = Map<any, any>;
export declare const enum Archtype {
export declare const enum ArchType {
Object = 0,

@@ -17,10 +17,2 @@ Array = 1,

}
export declare const enum ProxyType {
ProxyObject = 0,
ProxyArray = 1,
Map = 2,
Set = 3,
ES5Object = 4,
ES5Array = 5
}
export interface ImmerBaseState {

@@ -33,3 +25,3 @@ parent_?: ImmerState;

}
export declare type ImmerState = ProxyObjectState | ProxyArrayState | ES5ObjectState | ES5ArrayState | MapState | SetState;
export declare type ImmerState = ProxyObjectState | ProxyArrayState | MapState | SetState;
export declare type Drafted<Base = any, T extends ImmerState = ImmerState> = {

@@ -36,0 +28,0 @@ [DRAFT_STATE]: T;

@@ -1,2 +0,2 @@

import { Objectish, AnyObject, AnyMap, AnySet, ImmerState, Archtype } from "../internal";
import { Objectish, AnyObject, AnyMap, AnySet, ImmerState, ArchType } from "../internal";
/** Returns true if the given value is an Immer draft */

@@ -9,8 +9,4 @@ export declare function isDraft(value: any): boolean;

export declare function original<T>(value: T): T | undefined;
export declare const ownKeys: (target: AnyObject) => PropertyKey[];
export declare const getOwnPropertyDescriptors: <T>(o: T) => { [P in keyof T]: TypedPropertyDescriptor<T[P]>; } & {
[x: string]: PropertyDescriptor;
};
export declare function each<T extends Objectish>(obj: T, iter: (key: string | number, value: any, source: T) => void, enumerableOnly?: boolean): void;
export declare function getArchtype(thing: any): Archtype;
export declare function getArchtype(thing: any): ArchType;
export declare function has(thing: any, prop: PropertyKey): boolean;

@@ -23,3 +19,3 @@ export declare function get(thing: AnyMap | AnyObject, prop: PropertyKey): any;

export declare function latest(state: ImmerState): any;
export declare function shallowCopy(base: any): any;
export declare function shallowCopy(base: any, strict: boolean): any;
/**

@@ -26,0 +22,0 @@ * Freezes draftable objects. Returns the original object.

@@ -1,8 +0,5 @@

export declare const hasMap: boolean;
export declare const hasSet: boolean;
export declare const hasProxies: boolean;
/**
* The sentinel value returned by producers to replace the draft with undefined.
*/
export declare const NOTHING: Nothing;
export declare const NOTHING: unique symbol;
/**

@@ -18,7 +15,2 @@ * To let Immer treat your class instances as plain immutable objects

export declare const DRAFT_STATE: unique symbol;
export declare const iteratorSymbol: typeof Symbol.iterator;
/** Use a class type for `nothing` so its type is unique */
export declare class Nothing {
private _;
}
//# sourceMappingURL=env.d.ts.map

@@ -1,29 +0,3 @@

declare const errors: {
readonly 0: "Illegal state";
readonly 1: "Immer drafts cannot have computed properties";
readonly 2: "This object has been frozen and should not be mutated";
readonly 3: (data: any) => string;
readonly 4: "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.";
readonly 5: "Immer forbids circular references";
readonly 6: "The first or second argument to `produce` must be a function";
readonly 7: "The third argument to `produce` must be a function or undefined";
readonly 8: "First argument to `createDraft` must be a plain object, an array, or an immerable object";
readonly 9: "First argument to `finishDraft` must be a draft returned by `createDraft`";
readonly 10: "The given draft is already finalized";
readonly 11: "Object.defineProperty() cannot be used on an Immer draft";
readonly 12: "Object.setPrototypeOf() cannot be used on an Immer draft";
readonly 13: "Immer only supports deleting array indices";
readonly 14: "Immer only supports setting array indices and the 'length' property";
readonly 15: (path: string) => string;
readonly 16: "Sets cannot have \"replace\" patches.";
readonly 17: (op: string) => string;
readonly 18: (plugin: string) => string;
readonly 20: "Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available";
readonly 21: (thing: string) => string;
readonly 22: (thing: string) => string;
readonly 23: (thing: string) => string;
readonly 24: "Patching reserved attributes like __proto__, prototype and constructor is not allowed";
};
export declare function die(error: keyof typeof errors, ...args: any[]): never;
export {};
export declare const errors: (string | ((plugin: string) => string))[];
export declare function die(error: number, ...args: any[]): never;
//# sourceMappingURL=errors.d.ts.map

@@ -1,2 +0,2 @@

import { ImmerState, Patch, ImmerScope, Drafted, AnyObject, ImmerBaseState, AnyMap, AnySet, ProxyType } from "../internal";
import { ImmerState, Patch } from "../internal";
/** Plugin utilities */

@@ -9,11 +9,2 @@ declare const plugins: {

};
ES5?: {
willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void;
createES5Proxy_<T>(base: T, parent?: ImmerState): Drafted<T, ES5ObjectState | ES5ArrayState>;
hasChanges_(state: ES5ArrayState | ES5ObjectState): boolean;
};
MapSet?: {
proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T;
proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T;
};
};

@@ -23,39 +14,2 @@ declare type Plugins = typeof plugins;

export declare function loadPlugin<K extends keyof Plugins>(pluginKey: K, implementation: Plugins[K]): void;
/** ES5 Plugin */
interface ES5BaseState extends ImmerBaseState {
assigned_: {
[key: string]: any;
};
parent_?: ImmerState;
revoked_: boolean;
}
export interface ES5ObjectState extends ES5BaseState {
type_: ProxyType.ES5Object;
draft_: Drafted<AnyObject, ES5ObjectState>;
base_: AnyObject;
copy_: AnyObject | null;
}
export interface ES5ArrayState extends ES5BaseState {
type_: ProxyType.ES5Array;
draft_: Drafted<AnyObject, ES5ArrayState>;
base_: any;
copy_: any;
}
/** Map / Set plugin */
export interface MapState extends ImmerBaseState {
type_: ProxyType.Map;
copy_: AnyMap | undefined;
assigned_: Map<any, boolean> | undefined;
base_: AnyMap;
revoked_: boolean;
draft_: Drafted<AnyMap, MapState>;
}
export interface SetState extends ImmerBaseState {
type_: ProxyType.Set;
copy_: AnySet | undefined;
base_: AnySet;
drafts_: Map<any, Drafted>;
revoked_: boolean;
draft_: Drafted<AnySet, SetState>;
}
/** Patches plugin */

@@ -62,0 +16,0 @@ export declare type PatchPath = (string | number)[];

{
"name": "immer",
"version": "9.0.21",
"version": "10.0.0-beta.1",
"description": "Create your next immutable state by mutating the current one",
"type": "module",
"main": "dist/index.js",

@@ -10,6 +11,5 @@ "module": "dist/immer.esm.js",

"types": "./dist/immer.d.ts",
"import": "./dist/immer.esm.mjs",
"import": "./dist/immer.esm.js",
"require": "./dist/index.js"
},
"./*": "./*"
}
},

@@ -23,28 +23,16 @@ "umd:main": "dist/immer.umd.production.min.js",

"types": "./dist/immer.d.ts",
"typesVersions": {
">=3.7": {
"*": [
"./*"
]
},
">=3.1": {
"*": [
"compat/pre-3.7/*"
]
}
},
"sideEffects": false,
"scripts": {
"test": "jest && yarn test:build && yarn test:flow",
"test:perf": "cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js",
"test:perf": "cd __performance_tests__ && babel-node add-data.js && babel-node todo.js && babel-node incremental.js && babel-node large-obj.js",
"test:flow": "yarn flow check __tests__/flow",
"test:build": "yarn build && NODE_ENV='production' yarn jest --config jest.config.build.js",
"test:build": "yarn build && NODE_ENV='production' yarn jest --config jest.config.build.mjs",
"watch": "jest --watch",
"coverage": "jest --coverage",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",
"build": "rimraf dist/ && tsdx build --name immer --format esm,cjs,umd && cp dist/immer.esm.js dist/immer.esm.mjs && yarn build:flow",
"build": "rimraf dist/ && tsdx build --name immer --format esm,cjs,umd && yarn build:flow",
"build:flow": "cpx 'src/types/index.js.flow' dist -v",
"publish-docs": "cd website && GIT_USER=mweststrate USE_SSH=true yarn docusaurus deploy",
"start": "cd website && yarn start",
"test:size": "yarn build && yarn import-size --report . produce enableES5 enableMapSet enablePatches enableAllPlugins",
"test:size": "yarn build && yarn import-size --report . produce enablePatches",
"test:sizequick": "tsdx build --name immer --format esm && yarn import-size . produce"

@@ -66,3 +54,3 @@ },

],
"author": "Michel Weststrate",
"author": "Michel Weststrate <info@michel.codes>",
"license": "MIT",

@@ -83,4 +71,4 @@ "funding": {

"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/node": "^7.8.4",
"@babel/core": "^7.21.3",
"@babel/node": "^7.20.7",
"@types/jest": "^25.1.2",

@@ -94,3 +82,3 @@ "coveralls": "^3.0.0",

"import-size": "^1.0.2",
"jest": "^25.1.0",
"jest": "^29.5.0",
"lodash": "^4.17.4",

@@ -105,6 +93,6 @@ "lodash.clonedeep": "^4.5.0",

"spec.ts": "^1.1.0",
"ts-jest": "^25.2.0",
"tsdx": "^0.12.3",
"typescript": "^4.2.3"
"ts-jest": "^29.0.0",
"tsdx": "^0.14.1",
"typescript": "^5.0.2"
}
}

@@ -7,9 +7,6 @@ import {

DRAFT_STATE,
get,
set,
ImmerState,
isDraftable,
Archtype,
getArchtype,
getPlugin
isFrozen
} from "../internal"

@@ -20,3 +17,3 @@

export function current(value: any): any {
if (!isDraft(value)) die(22, value)
if (!isDraft(value)) die(10, value)
return currentImpl(value)

@@ -26,38 +23,21 @@ }

function currentImpl(value: any): any {
if (!isDraftable(value)) return value
if (!isDraftable(value) || isFrozen(value)) return value
const state: ImmerState | undefined = value[DRAFT_STATE]
let copy: any
const archType = getArchtype(value)
if (state) {
if (
!state.modified_ &&
(state.type_ < 4 || !getPlugin("ES5").hasChanges_(state as any))
)
return state.base_
if (!state.modified_) return state.base_
// Optimization: avoid generating new drafts during copying
state.finalized_ = true
copy = copyHelper(value, archType)
state.finalized_ = false
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)
} else {
copy = copyHelper(value, archType)
copy = shallowCopy(value, true)
}
// recurse
each(copy, (key, childValue) => {
if (state && get(state.base_, key) === childValue) return // no need to copy or search in something that didn't change
set(copy, key, currentImpl(childValue))
})
// In the future, we might consider freezing here, based on the current settings
return archType === Archtype.Set ? new Set(copy) : copy
}
function copyHelper(value: any, archType: number): any {
// creates a shallow copy, even if it is a map or set
switch (archType) {
case Archtype.Map:
return new Map(value)
case Archtype.Set:
// Set will be cloned as array temporarily, so that we can replace individual items
return Array.from(value)
if (state) {
state.finalized_ = false
}
return shallowCopy(value)
return copy
}

@@ -14,8 +14,7 @@ import {

set,
ProxyType,
ArchType,
getPlugin,
die,
revokeScope,
isFrozen,
shallowCopy
isFrozen
} from "../internal"

@@ -27,4 +26,2 @@

const isReplaced = result !== undefined && result !== baseDraft
if (!scope.immer_.useProxies_)
getPlugin("ES5").willFinalizeES5_(scope, result, isReplaced)
if (isReplaced) {

@@ -85,7 +82,3 @@ if (baseDraft[DRAFT_STATE].modified_) {

state.scope_.unfinalizedDrafts_--
const result =
// For ES5, create a good copy from the draft first, with added keys and without deleted keys.
state.type_ === ProxyType.ES5Object || state.type_ === ProxyType.ES5Array
? (state.copy_ = shallowCopy(state.draft_))
: state.copy_
const result = state.copy_
// Finalize all children of the copy

@@ -97,3 +90,3 @@ // For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628

let isSet = false
if (state.type_ === ProxyType.Set) {
if (state.type_ === ArchType.Set) {
resultEach = new Set(result)

@@ -135,3 +128,3 @@ result.clear()

parentState &&
parentState!.type_ !== ProxyType.Set && // Set objects are atomic since they have no keys.
parentState!.type_ !== ArchType.Set && // Set objects are atomic since they have no keys.
!has((parentState as Exclude<ImmerState, SetState>).assigned_!, prop) // Skip deep patches for assigned keys.

@@ -138,0 +131,0 @@ ? rootPath!.concat(prop)

@@ -19,3 +19,2 @@ import {

die,
hasProxies,
enterScope,

@@ -28,3 +27,5 @@ revokeScope,

freeze,
current
current,
proxyMap,
proxySet
} from "../internal"

@@ -38,11 +39,10 @@

export class Immer implements ProducersFns {
useProxies_: boolean = hasProxies
autoFreeze_: boolean = true
useStrictShallowCopy_: boolean = false
constructor(config?: {useProxies?: boolean; autoFreeze?: boolean}) {
if (typeof config?.useProxies === "boolean")
this.setUseProxies(config!.useProxies)
constructor(config?: {autoFreeze?: boolean; useStrictShallowCopy?: boolean}) {
if (typeof config?.autoFreeze === "boolean")
this.setAutoFreeze(config!.autoFreeze)
if (typeof config?.useStrictShallowCopy === "boolean")
this.setUseStrictShallowCopy(config!.useStrictShallowCopy)
}

@@ -94,3 +94,3 @@

const scope = enterScope(this)
const proxy = createProxy(this, base, undefined)
const proxy = createProxy(base, undefined)
let hasError = true

@@ -105,14 +105,2 @@ try {

}
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(
result => {
usePatchesInScope(scope, patchListener)
return processResult(result, scope)
},
error => {
revokeScope(scope)
throw error
}
)
}
usePatchesInScope(scope, patchListener)

@@ -132,3 +120,3 @@ return processResult(result, scope)

return result
} else die(21, base)
} else die(1, base)
}

@@ -148,6 +136,2 @@

})
if (typeof Promise !== "undefined" && result instanceof Promise) {
return result.then(nextState => [nextState, patches!, inversePatches!])
}
return [result, patches!, inversePatches!]

@@ -160,3 +144,3 @@ }

const scope = enterScope(this)
const proxy = createProxy(this, base, undefined)
const proxy = createProxy(base, undefined)
proxy[DRAFT_STATE].isManual_ = true

@@ -172,6 +156,3 @@ leaveScope(scope)

const state: ImmerState = draft && (draft as any)[DRAFT_STATE]
if (__DEV__) {
if (!state || !state.isManual_) die(9)
if (state.finalized_) die(10)
}
if (!state || !state.isManual_) die(9)
const {scope_: scope} = state

@@ -192,12 +173,8 @@ usePatchesInScope(scope, patchListener)

/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
setUseProxies(value: boolean) {
if (value && !hasProxies) {
die(20)
}
this.useProxies_ = value
setUseStrictShallowCopy(value: boolean) {
this.useStrictShallowCopy_ = value
}

@@ -235,3 +212,2 @@

export function createProxy<T extends Objectish>(
immer: Immer,
value: T,

@@ -242,8 +218,6 @@ parent?: ImmerState

const draft: Drafted = isMap(value)
? getPlugin("MapSet").proxyMap_(value, parent)
? proxyMap(value, parent)
: isSet(value)
? getPlugin("MapSet").proxySet_(value, parent)
: immer.useProxies_
? createProxyProxy(value, parent)
: getPlugin("ES5").createES5Proxy_(value, parent)
? proxySet(value, parent)
: createProxyProxy(value, parent)

@@ -250,0 +224,0 @@ const scope = parent ? parent.scope_ : getCurrentScope()

@@ -18,3 +18,4 @@ import {

createProxy,
ProxyType
ArchType,
ImmerScope
} from "../internal"

@@ -31,3 +32,3 @@

export interface ProxyObjectState extends ProxyBaseState {
type_: ProxyType.ProxyObject
type_: ArchType.Object
base_: any

@@ -39,3 +40,3 @@ copy_: any

export interface ProxyArrayState extends ProxyBaseState {
type_: ProxyType.ProxyArray
type_: ArchType.Array
base_: AnyArray

@@ -59,3 +60,3 @@ copy_: AnyArray | null

const state: ProxyState = {
type_: isArray ? ProxyType.ProxyArray : (ProxyType.ProxyObject as any),
type_: isArray ? ArchType.Array : (ArchType.Object as any),
// Track which produce call this is associated with.

@@ -121,7 +122,3 @@ scope_: parent ? parent.scope_ : getCurrentScope()!,

prepareCopy(state)
return (state.copy_![prop as any] = createProxy(
state.scope_.immer_,
value,
state
))
return (state.copy_![prop as any] = createProxy(value, state))
}

@@ -189,4 +186,3 @@ return value

}
// @ts-ignore
if (state.copy_) delete state.copy_[prop]
delete state.copy_[prop]
return true

@@ -202,3 +198,3 @@ },

writable: true,
configurable: state.type_ !== ProxyType.ProxyArray || prop !== "length",
configurable: state.type_ !== ArchType.Array || prop !== "length",
enumerable: desc.enumerable,

@@ -283,6 +279,13 @@ value: owner[prop]

export function prepareCopy(state: {base_: any; copy_: any}) {
export function prepareCopy(state: {
base_: any
copy_: any
scope_: ImmerScope
}) {
if (!state.copy_) {
state.copy_ = shallowCopy(state.base_)
state.copy_ = shallowCopy(
state.base_,
state.scope_.immer_.useStrictShallowCopy_
)
}
}

@@ -8,6 +8,5 @@ import {

ImmerState,
ProxyType,
ArchType,
getPlugin
} from "../internal"
import {die} from "../utils/errors"

@@ -30,3 +29,2 @@ /** Each scope represents a `produce` call. */

export function getCurrentScope() {
if (__DEV__ && !currentScope) die(0)
return currentScope!

@@ -81,8 +79,5 @@ }

const state: ImmerState = draft[DRAFT_STATE]
if (
state.type_ === ProxyType.ProxyObject ||
state.type_ === ProxyType.ProxyArray
)
if (state.type_ === ArchType.Object || state.type_ === ArchType.Array)
state.revoke_()
else state.revoked_ = true
}

@@ -45,3 +45,2 @@ import {

export const produce: IProduce = immer.produce
export default produce

@@ -64,8 +63,7 @@ /**

/**
* Pass true to use the ES2015 `Proxy` class when creating drafts, which is
* always faster than using ES5 proxies.
* Pass true to enable strict shallow copy.
*
* By default, feature detection is used, so calling this is rarely necessary.
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
*/
export const setUseProxies = immer.setUseProxies.bind(immer)
export const setUseStrictShallowCopy = immer.setUseStrictShallowCopy.bind(immer)

@@ -116,5 +114,2 @@ /**

export {enableES5} from "./plugins/es5"
export {enablePatches} from "./plugins/patches"
export {enableMapSet} from "./plugins/mapset"
export {enableAllPlugins} from "./plugins/all"

@@ -12,1 +12,2 @@ export * from "./utils/env"

export * from "./core/current"
export * from "./core/mapset"

@@ -6,6 +6,4 @@ import {immerable} from "../immer"

SetState,
ES5ArrayState,
ProxyArrayState,
MapState,
ES5ObjectState,
ProxyObjectState,

@@ -20,11 +18,25 @@ PatchPath,

loadPlugin,
ProxyType,
Archtype,
ArchType,
die,
isDraft,
isDraftable,
NOTHING
NOTHING,
errors
} from "../internal"
export function enablePatches() {
const errorOffset = 16
if (__DEV__) {
errors.push(
'Sets cannot have "replace" patches.',
function(op: string) {
return "Unsupported patch operation: " + op
},
function(path: string) {
return "Cannot apply patch, path doesn't resolve: " + path
},
"Patching reserved attributes like __proto__, prototype and constructor is not allowed"
)
}
const REPLACE = "replace"

@@ -41,5 +53,4 @@ const ADD = "add"

switch (state.type_) {
case ProxyType.ProxyObject:
case ProxyType.ES5Object:
case ProxyType.Map:
case ArchType.Object:
case ArchType.Map:
return generatePatchesFromAssigned(

@@ -51,6 +62,5 @@ state,

)
case ProxyType.ES5Array:
case ProxyType.ProxyArray:
case ArchType.Array:
return generateArrayPatches(state, basePath, patches, inversePatches)
case ProxyType.Set:
case ArchType.Set:
return generateSetPatches(

@@ -66,3 +76,3 @@ (state as any) as SetState,

function generateArrayPatches(
state: ES5ArrayState | ProxyArrayState,
state: ProxyArrayState,
basePath: PatchPath,

@@ -112,7 +122,7 @@ patches: Patch[],

}
if (base_.length < copy_.length) {
for (let i = copy_.length - 1; base_.length <= i; --i) {
const path = basePath.concat([i])
inversePatches.push({
op: REPLACE,
path: basePath.concat(["length"]),
value: base_.length
op: REMOVE,
path
})

@@ -124,3 +134,3 @@ }

function generatePatchesFromAssigned(
state: MapState | ES5ObjectState | ProxyObjectState,
state: MapState | ProxyObjectState,
basePath: PatchPath,

@@ -224,9 +234,10 @@ patches: Patch[],

if (
(parentType === Archtype.Object || parentType === Archtype.Array) &&
(parentType === ArchType.Object || parentType === ArchType.Array) &&
(p === "__proto__" || p === "constructor")
)
die(24)
if (typeof base === "function" && p === "prototype") die(24)
die(errorOffset + 3)
if (typeof base === "function" && p === "prototype")
die(errorOffset + 3)
base = get(base, p)
if (typeof base !== "object") die(15, path.join("/"))
if (typeof base !== "object") die(errorOffset + 2, path.join("/"))
}

@@ -240,7 +251,7 @@

switch (type) {
case Archtype.Map:
case ArchType.Map:
return base.set(key, value)
/* istanbul ignore next */
case Archtype.Set:
die(16)
case ArchType.Set:
die(errorOffset)
default:

@@ -255,9 +266,9 @@ // if value is an object, then it's assigned by reference

switch (type) {
case Archtype.Array:
case ArchType.Array:
return key === "-"
? base.push(value)
: base.splice(key as any, 0, value)
case Archtype.Map:
case ArchType.Map:
return base.set(key, value)
case Archtype.Set:
case ArchType.Set:
return base.add(value)

@@ -269,7 +280,7 @@ default:

switch (type) {
case Archtype.Array:
case ArchType.Array:
return base.splice(key as any, 1)
case Archtype.Map:
case ArchType.Map:
return base.delete(key)
case Archtype.Set:
case ArchType.Set:
return base.delete(patch.value)

@@ -280,3 +291,3 @@ default:

default:
die(17, op)
die(errorOffset + 1, op)
}

@@ -283,0 +294,0 @@ })

@@ -1,2 +0,2 @@

import {Nothing} from "../internal"
import {NOTHING} from "../internal"

@@ -40,5 +40,5 @@ type AnyFunc = (...args: any[]) => any

? T
: T extends IfAvailable<ReadonlyMap<infer K, infer V>> // Map extends ReadonlyMap
: T extends ReadonlyMap<infer K, infer V> // Map extends ReadonlyMap
? Map<Draft<K>, Draft<V>>
: T extends IfAvailable<ReadonlySet<infer V>> // Set extends ReadonlySet
: T extends ReadonlySet<infer V> // Set extends ReadonlySet
? Set<Draft<V>>

@@ -56,5 +56,5 @@ : T extends WeakReferences

? T
: T extends IfAvailable<ReadonlyMap<infer K, infer V>> // Map extends ReadonlyMap
: T extends ReadonlyMap<infer K, infer V> // Map extends ReadonlyMap
? ReadonlyMap<Immutable<K>, Immutable<V>>
: T extends IfAvailable<ReadonlySet<infer V>> // Set extends ReadonlySet
: T extends ReadonlySet<infer V> // Set extends ReadonlySet
? ReadonlySet<Immutable<V>>

@@ -76,3 +76,3 @@ : T extends WeakReferences

/** Converts `nothing` into `undefined` */
type FromNothing<T> = T extends Nothing ? undefined : T
type FromNothing<T> = T extends typeof NOTHING ? undefined : T

@@ -82,4 +82,2 @@ /** The inferred return type of `produce` */

? Base
: Return extends Promise<infer Result>
? Promise<Result extends void ? Base : FromNothing<Result>>
: FromNothing<Return>

@@ -96,17 +94,8 @@

| undefined
| (State extends undefined ? Nothing : never)
| (State extends undefined ? typeof NOTHING : never)
type ValidRecipeReturnTypePossiblyPromise<State> =
| ValidRecipeReturnType<State>
| Promise<ValidRecipeReturnType<State>>
type PromisifyReturnIfNeeded<
type ReturnTypeWithPatchesIfNeeded<
State,
Recipe extends AnyFunc,
UsePatches extends boolean
> = ReturnType<Recipe> extends Promise<any>
? Promise<UsePatches extends true ? PatchesTuple<State> : State>
: UsePatches extends true
? PatchesTuple<State>
: State
> = UsePatches extends true ? PatchesTuple<State> : State

@@ -139,7 +128,7 @@ /**

> = Recipe extends (draft: infer DraftState, ...args: infer RestArgs) => any // verify return type
? ReturnType<Recipe> extends ValidRecipeReturnTypePossiblyPromise<DraftState>
? ReturnType<Recipe> extends ValidRecipeReturnType<DraftState>
? (
base: Immutable<DraftState>,
...args: RestArgs
) => PromisifyReturnIfNeeded<DraftState, Recipe, UsePatches> // N.b. we return mutable draftstate, in case the recipe's first arg isn't read only, and that isn't expected as output either
) => ReturnTypeWithPatchesIfNeeded<DraftState, UsePatches> // N.b. we return mutable draftstate, in case the recipe's first arg isn't read only, and that isn't expected as output either
: never // incorrect return type

@@ -155,7 +144,7 @@ : never // not a function

...rest: infer RestArgs
) => ValidRecipeReturnTypePossiblyPromise<State>
) => ValidRecipeReturnType<State>
? (
base?: State | undefined,
...args: RestArgs
) => PromisifyReturnIfNeeded<State, Recipe, UsePatches>
) => ReturnTypeWithPatchesIfNeeded<State, UsePatches>
: never // recipe doesn't match initial state

@@ -228,9 +217,2 @@

): Base
/** Promisified normal producer */
<Base, D = Draft<Base>>(
base: Base,
recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,
listener?: PatchListener
): Promise<Base>
}

@@ -256,7 +238,2 @@

): PatchesTuple<Base>
<Base, D = Draft<Base>>(
base: Base,
recipe: (draft: D) => Promise<ValidRecipeReturnType<D>>,
listener?: PatchListener
): Promise<PatchesTuple<Base>>
}

@@ -267,3 +244,3 @@

*/
export type Producer<T> = (draft: Draft<T>) => ValidRecipeReturnType<Draft<T>> | Promise<ValidRecipeReturnType<Draft<T>>>
export type Producer<T> = (draft: Draft<T>) => ValidRecipeReturnType<Draft<T>>

@@ -270,0 +247,0 @@ // Fixes #507: bili doesn't export the types of this file if there is no actual source in it..

@@ -6,4 +6,2 @@ import {

ProxyArrayState,
ES5ObjectState,
ES5ArrayState,
MapState,

@@ -21,3 +19,3 @@ DRAFT_STATE

export const enum Archtype {
export const enum ArchType {
Object,

@@ -29,11 +27,2 @@ Array,

export const enum ProxyType {
ProxyObject,
ProxyArray,
Map,
Set,
ES5Object,
ES5Array
}
export interface ImmerBaseState {

@@ -50,4 +39,2 @@ parent_?: ImmerState

| ProxyArrayState
| ES5ObjectState
| ES5ArrayState
| MapState

@@ -54,0 +41,0 @@ | SetState

import {
DRAFT_STATE,
DRAFTABLE,
hasSet,
Objectish,

@@ -11,4 +10,3 @@ Drafted,

ImmerState,
hasMap,
Archtype,
ArchType,
die

@@ -60,28 +58,6 @@ } from "../internal"

export function original(value: Drafted<any>): any {
if (!isDraft(value)) die(23, value)
if (!isDraft(value)) die(15, value)
return value[DRAFT_STATE].base_
}
/*#__PURE__*/
export const ownKeys: (target: AnyObject) => PropertyKey[] =
typeof Reflect !== "undefined" && Reflect.ownKeys
? Reflect.ownKeys
: typeof Object.getOwnPropertySymbols !== "undefined"
? obj =>
Object.getOwnPropertyNames(obj).concat(
Object.getOwnPropertySymbols(obj) as any
)
: /* istanbul ignore next */ Object.getOwnPropertyNames
export const getOwnPropertyDescriptors =
Object.getOwnPropertyDescriptors ||
function getOwnPropertyDescriptors(target: any) {
// Polyfill needed for Hermes and IE, see https://github.com/facebook/hermes/issues/274
const res: any = {}
ownKeys(target).forEach(key => {
res[key] = Object.getOwnPropertyDescriptor(target, key)
})
return res
}
export function each<T extends Objectish>(

@@ -92,6 +68,6 @@ obj: T,

): void
export function each(obj: any, iter: any, enumerableOnly = false) {
if (getArchtype(obj) === Archtype.Object) {
;(enumerableOnly ? Object.keys : ownKeys)(obj).forEach(key => {
if (!enumerableOnly || typeof key !== "symbol") iter(key, obj[key], obj)
export function each(obj: any, iter: any) {
if (getArchtype(obj) === ArchType.Object) {
Object.entries(obj).forEach(([key, value]) => {
iter(key, value, obj)
})

@@ -104,16 +80,13 @@ } else {

/*#__PURE__*/
export function getArchtype(thing: any): Archtype {
/* istanbul ignore next */
export function getArchtype(thing: any): ArchType {
const state: undefined | ImmerState = thing[DRAFT_STATE]
return state
? state.type_ > 3
? state.type_ - 4 // cause Object and Array map back from 4 and 5
: (state.type_ as any) // others are the same
? state.type_
: Array.isArray(thing)
? Archtype.Array
? ArchType.Array
: isMap(thing)
? Archtype.Map
? ArchType.Map
: isSet(thing)
? Archtype.Set
: Archtype.Object
? ArchType.Set
: ArchType.Object
}

@@ -123,3 +96,3 @@

export function has(thing: any, prop: PropertyKey): boolean {
return getArchtype(thing) === Archtype.Map
return getArchtype(thing) === ArchType.Map
? thing.has(prop)

@@ -132,3 +105,3 @@ : Object.prototype.hasOwnProperty.call(thing, prop)

// @ts-ignore
return getArchtype(thing) === Archtype.Map ? thing.get(prop) : thing[prop]
return getArchtype(thing) === ArchType.Map ? thing.get(prop) : thing[prop]
}

@@ -139,4 +112,4 @@

const t = getArchtype(thing)
if (t === Archtype.Map) thing.set(propOrOldValue, value)
else if (t === Archtype.Set) {
if (t === ArchType.Map) thing.set(propOrOldValue, value)
else if (t === ArchType.Set) {
thing.add(value)

@@ -158,3 +131,3 @@ } else thing[propOrOldValue] = value

export function isMap(target: any): target is AnyMap {
return hasMap && target instanceof Map
return target instanceof Map
}

@@ -164,3 +137,3 @@

export function isSet(target: any): target is AnySet {
return hasSet && target instanceof Set
return target instanceof Set
}

@@ -173,7 +146,22 @@ /*#__PURE__*/

/*#__PURE__*/
export function shallowCopy(base: any) {
export function shallowCopy(base: any, strict: boolean) {
if (isMap(base)) {
return new Map(base)
}
if (isSet(base)) {
return new Set(base)
}
if (Array.isArray(base)) return Array.prototype.slice.call(base)
const descriptors = getOwnPropertyDescriptors(base)
if (!strict && isPlainObject(base)) {
if (!Object.getPrototypeOf(base)) {
const obj = Object.create(null)
return Object.assign(obj, base)
}
return {...base}
}
const descriptors = Object.getOwnPropertyDescriptors(base)
delete descriptors[DRAFT_STATE as any]
let keys = ownKeys(descriptors)
let keys = Reflect.ownKeys(descriptors)
for (let i = 0; i < keys.length; i++) {

@@ -214,3 +202,3 @@ const key: any = keys[i]

Object.freeze(obj)
if (deep) each(obj, (key, value) => freeze(value, true), true)
if (deep) each(obj, (_key, value) => freeze(value, true), true)
return obj

@@ -224,5 +212,3 @@ }

export function isFrozen(obj: any): boolean {
if (obj == null || typeof obj !== "object") return true
// See #600, IE dies on non-objects in Object.isFrozen
return Object.isFrozen(obj)
}
// Should be no imports here!
// Some things that should be evaluated before all else...
// We only want to know if non-polyfilled symbols are available
const hasSymbol =
typeof Symbol !== "undefined" && typeof Symbol("x") === "symbol"
export const hasMap = typeof Map !== "undefined"
export const hasSet = typeof Set !== "undefined"
export const hasProxies =
typeof Proxy !== "undefined" &&
typeof Proxy.revocable !== "undefined" &&
typeof Reflect !== "undefined"
/**
* The sentinel value returned by producers to replace the draft with undefined.
*/
export const NOTHING: Nothing = hasSymbol
? Symbol.for("immer-nothing")
: ({["immer-nothing"]: true} as any)
export const NOTHING: unique symbol = Symbol.for("immer-nothing")

@@ -30,19 +16,4 @@ /**

*/
export const DRAFTABLE: unique symbol = hasSymbol
? Symbol.for("immer-draftable")
: ("__$immer_draftable" as any)
export const DRAFTABLE: unique symbol = Symbol.for("immer-draftable")
export const DRAFT_STATE: unique symbol = hasSymbol
? Symbol.for("immer-state")
: ("__$immer_state" as any)
// Even a polyfilled Symbol might provide Symbol.iterator
export const iteratorSymbol: typeof Symbol.iterator =
(typeof Symbol != "undefined" && Symbol.iterator) || ("@@iterator" as any)
/** Use a class type for `nothing` so its type is unique */
export class Nothing {
// This lets us do `Exclude<T, Nothing>`
// @ts-ignore
private _!: unique symbol
}
export const DRAFT_STATE: unique symbol = Symbol.for("immer-state")

@@ -1,60 +0,47 @@

const errors = {
0: "Illegal state",
1: "Immer drafts cannot have computed properties",
2: "This object has been frozen and should not be mutated",
3(data: any) {
return (
"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " +
data
)
},
4: "An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
5: "Immer forbids circular references",
6: "The first or second argument to `produce` must be a function",
7: "The third argument to `produce` must be a function or undefined",
8: "First argument to `createDraft` must be a plain object, an array, or an immerable object",
9: "First argument to `finishDraft` must be a draft returned by `createDraft`",
10: "The given draft is already finalized",
11: "Object.defineProperty() cannot be used on an Immer draft",
12: "Object.setPrototypeOf() cannot be used on an Immer draft",
13: "Immer only supports deleting array indices",
14: "Immer only supports setting array indices and the 'length' property",
15(path: string) {
return "Cannot apply patch, path doesn't resolve: " + path
},
16: 'Sets cannot have "replace" patches.',
17(op: string) {
return "Unsupported patch operation: " + op
},
18(plugin: string) {
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`
},
20: "Cannot use proxies if Proxy, Proxy.revocable or Reflect are not available",
21(thing: string) {
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`
},
22(thing: string) {
return `'current' expects a draft, got: ${thing}`
},
23(thing: string) {
return `'original' expects a draft, got: ${thing}`
},
24: "Patching reserved attributes like __proto__, prototype and constructor is not allowed"
} as const
export const errors = __DEV__
? [
// All error codes, starting by 0:
function(plugin: string) {
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`
},
function(thing: string) {
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`
},
"This object has been frozen and should not be mutated",
function(data: any) {
return (
"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " +
data
)
},
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
"Immer forbids circular references",
"The first or second argument to `produce` must be a function",
"The third argument to `produce` must be a function or undefined",
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
"First argument to `finishDraft` must be a draft returned by `createDraft`",
function(thing: string) {
return `'current' expects a draft, got: ${thing}`
},
"Object.defineProperty() cannot be used on an Immer draft",
"Object.setPrototypeOf() cannot be used on an Immer draft",
"Immer only supports deleting array indices",
"Immer only supports setting array indices and the 'length' property",
function(thing: string) {
return `'original' expects a draft, got: ${thing}`
}
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
// See Patches.ts for additional errors
]
: []
export function die(error: keyof typeof errors, ...args: any[]): never {
export function die(error: number, ...args: any[]): never {
if (__DEV__) {
const e = errors[error]
const msg = !e
? "unknown error nr: " + error
: typeof e === "function"
? e.apply(null, args as any)
: e
const msg = typeof e === "function" ? e.apply(null, args as any) : e
throw new Error(`[Immer] ${msg}`)
}
throw new Error(
`[Immer] minified error nr: ${error}${
args.length ? " " + args.map(s => `'${s}'`).join(",") : ""
}. Find the full error at: https://bit.ly/3cXEKWf`
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
)
}

@@ -1,13 +0,2 @@

import {
ImmerState,
Patch,
ImmerScope,
Drafted,
AnyObject,
ImmerBaseState,
AnyMap,
AnySet,
ProxyType,
die
} from "../internal"
import {ImmerState, Patch, die} from "../internal"

@@ -31,14 +20,2 @@ /** Plugin utilities */

}
ES5?: {
willFinalizeES5_(scope: ImmerScope, result: any, isReplaced: boolean): void
createES5Proxy_<T>(
base: T,
parent?: ImmerState
): Drafted<T, ES5ObjectState | ES5ArrayState>
hasChanges_(state: ES5ArrayState | ES5ObjectState): boolean
}
MapSet?: {
proxyMap_<T extends AnyMap>(target: T, parent?: ImmerState): T
proxySet_<T extends AnySet>(target: T, parent?: ImmerState): T
}
} = {}

@@ -53,3 +30,3 @@

if (!plugin) {
die(18, pluginKey)
die(0, pluginKey)
}

@@ -67,46 +44,4 @@ // @ts-ignore

/** ES5 Plugin */
interface ES5BaseState extends ImmerBaseState {
assigned_: {[key: string]: any}
parent_?: ImmerState
revoked_: boolean
}
export interface ES5ObjectState extends ES5BaseState {
type_: ProxyType.ES5Object
draft_: Drafted<AnyObject, ES5ObjectState>
base_: AnyObject
copy_: AnyObject | null
}
export interface ES5ArrayState extends ES5BaseState {
type_: ProxyType.ES5Array
draft_: Drafted<AnyObject, ES5ArrayState>
base_: any
copy_: any
}
/** Map / Set plugin */
export interface MapState extends ImmerBaseState {
type_: ProxyType.Map
copy_: AnyMap | undefined
assigned_: Map<any, boolean> | undefined
base_: AnyMap
revoked_: boolean
draft_: Drafted<AnyMap, MapState>
}
export interface SetState extends ImmerBaseState {
type_: ProxyType.Set
copy_: AnySet | undefined
base_: AnySet
drafts_: Map<any, Drafted> // maps the original value to the draft value in the new set
revoked_: boolean
draft_: Drafted<AnySet, SetState>
}
/** Patches plugin */
export type PatchPath = (string | number)[]

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc