diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 645f0281..74f64116 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,7 +24,7 @@ jobs: run: yarn build - name: publish # avoid release on fork - if: github.repository == 'immerjs/immer' + # if: github.repository == 'immerjs/immer' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.gitignore b/.gitignore index f154dce5..d51c7aa9 100644 --- a/.gitignore +++ b/.gitignore @@ -58,7 +58,7 @@ typings/ .env .idea -/dist* +# /dist* website/build website/.docusaurus .rts2* diff --git a/dist/cjs/immer.cjs.development.js b/dist/cjs/immer.cjs.development.js new file mode 100644 index 00000000..a0642852 --- /dev/null +++ b/dist/cjs/immer.cjs.development.js @@ -0,0 +1,1708 @@ +"use strict" +var __defProp = Object.defineProperty +var __getOwnPropDesc = Object.getOwnPropertyDescriptor +var __getOwnPropNames = Object.getOwnPropertyNames +var __hasOwnProp = Object.prototype.hasOwnProperty +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, {get: all[name], enumerable: true}) +} +var __copyProps = (to, from, except, desc) => { + if ((from && typeof from === "object") || typeof from === "function") { + for (let key of __getOwnPropNames(from)) + if (!__hasOwnProp.call(to, key) && key !== except) + __defProp(to, key, { + get: () => from[key], + enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable + }) + } + return to +} +var __toCommonJS = mod => + __copyProps(__defProp({}, "__esModule", {value: true}), mod) + +// src/immer.ts +var immer_exports = {} +__export(immer_exports, { + Immer: () => Immer2, + applyPatches: () => applyPatches, + castDraft: () => castDraft, + castImmutable: () => castImmutable, + createDraft: () => createDraft, + current: () => current, + enableArrayMethods: () => enableArrayMethods, + enableMapSet: () => enableMapSet, + enablePatches: () => enablePatches, + finishDraft: () => finishDraft, + freeze: () => freeze, + immerable: () => DRAFTABLE, + isDraft: () => isDraft, + isDraftable: () => isDraftable, + isNothing: () => isNothing, + nothing: () => NOTHING, + original: () => original, + produce: () => produce, + produceWithPatches: () => produceWithPatches, + setAutoFreeze: () => setAutoFreeze, + setUseStrictIteration: () => setUseStrictIteration, + setUseStrictShallowCopy: () => setUseStrictShallowCopy +}) +module.exports = __toCommonJS(immer_exports) + +// src/utils/env.ts +var NOTHING = Symbol.for("immer-nothing") +var DRAFTABLE = Symbol.for("immer-draftable") +var DRAFT_STATE = Symbol.for("immer-state") + +// src/utils/errors.ts +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, ...args) { + if (process.env.NODE_ENV !== "production") { + const e = errors[error] + const msg = isFunction(e) ? 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` + ) +} + +// src/utils/common.ts +var O = Object +var getPrototypeOf = O.getPrototypeOf +var CONSTRUCTOR = "constructor" +var PROTOTYPE = "prototype" +var CONFIGURABLE = "configurable" +var ENUMERABLE = "enumerable" +var WRITABLE = "writable" +var VALUE = "value" +var isDraft = value => !!value && !!value[DRAFT_STATE] +function isDraftable(value) { + if (!value) return false + return ( + isPlainObject(value) || + isArray(value) || + !!value[DRAFTABLE] || + !!value[CONSTRUCTOR]?.[DRAFTABLE] || + isMap(value) || + isSet(value) + ) +} +var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString() +var cachedCtorStrings = /* @__PURE__ */ new WeakMap() +function isPlainObject(value) { + if (!value || !isObjectish(value)) return false + const proto = getPrototypeOf(value) + if (proto === null || proto === O[PROTOTYPE]) return true + const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR] + if (Ctor === Object) return true + if (!isFunction(Ctor)) return false + let ctorString = cachedCtorStrings.get(Ctor) + if (ctorString === void 0) { + ctorString = Function.toString.call(Ctor) + cachedCtorStrings.set(Ctor, ctorString) + } + return ctorString === objectCtorString +} +function original(value) { + if (!isDraft(value)) die(15, value) + return value[DRAFT_STATE].base_ +} +function each(obj, iter, strict = true) { + if (getArchtype(obj) === 0 /* Object */) { + const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj) + keys.forEach(key => { + iter(key, obj[key], obj) + }) + } else { + obj.forEach((entry, index) => iter(index, entry, obj)) + } +} +function getArchtype(thing) { + const state = thing[DRAFT_STATE] + return state + ? state.type_ + : isArray(thing) + ? 1 /* Array */ + : isMap(thing) + ? 2 /* Map */ + : isSet(thing) + ? 3 /* Set */ + : 0 /* Object */ +} +var has = (thing, prop, type = getArchtype(thing)) => + type === 2 /* Map */ + ? thing.has(prop) + : O[PROTOTYPE].hasOwnProperty.call(thing, prop) +var get = (thing, prop, type = getArchtype(thing)) => + // @ts-ignore + type === 2 /* Map */ ? thing.get(prop) : thing[prop] +var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => { + if (type === 2 /* Map */) thing.set(propOrOldValue, value) + else if (type === 3 /* Set */) { + thing.add(value) + } else thing[propOrOldValue] = value +} +function is(x, y) { + if (x === y) { + return x !== 0 || 1 / x === 1 / y + } else { + return x !== x && y !== y + } +} +var isArray = Array.isArray +var isMap = target => target instanceof Map +var isSet = target => target instanceof Set +var isObjectish = target => typeof target === "object" +var isFunction = target => typeof target === "function" +var isBoolean = target => typeof target === "boolean" +function isArrayIndex(value) { + const n = +value + return Number.isInteger(n) && String(n) === value +} +var getProxyDraft = value => { + if (!isObjectish(value)) return null + return value?.[DRAFT_STATE] +} +var latest = state => state.copy_ || state.base_ +var getValue = value => { + const proxyDraft = getProxyDraft(value) + return proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value +} +var getFinalValue = state => (state.modified_ ? state.copy_ : state.base_) +function shallowCopy(base, strict) { + if (isMap(base)) { + return new Map(base) + } + if (isSet(base)) { + return new Set(base) + } + if (isArray(base)) return Array[PROTOTYPE].slice.call(base) + const isPlain = isPlainObject(base) + if (strict === true || (strict === "class_only" && !isPlain)) { + const descriptors = O.getOwnPropertyDescriptors(base) + delete descriptors[DRAFT_STATE] + let keys = Reflect.ownKeys(descriptors) + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + const desc = descriptors[key] + if (desc[WRITABLE] === false) { + desc[WRITABLE] = true + desc[CONFIGURABLE] = true + } + if (desc.get || desc.set) + descriptors[key] = { + [CONFIGURABLE]: true, + [WRITABLE]: true, + // could live with !!desc.set as well here... + [ENUMERABLE]: desc[ENUMERABLE], + [VALUE]: base[key] + } + } + return O.create(getPrototypeOf(base), descriptors) + } else { + const proto = getPrototypeOf(base) + if (proto !== null && isPlain) { + return {...base} + } + const obj = O.create(proto) + return O.assign(obj, base) + } +} +function freeze(obj, deep = false) { + if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj + if (getArchtype(obj) > 1) { + O.defineProperties(obj, { + set: dontMutateMethodOverride, + add: dontMutateMethodOverride, + clear: dontMutateMethodOverride, + delete: dontMutateMethodOverride + }) + } + O.freeze(obj) + if (deep) + each( + obj, + (_key, value) => { + freeze(value, true) + }, + false + ) + return obj +} +function dontMutateFrozenCollections() { + die(2) +} +var dontMutateMethodOverride = { + [VALUE]: dontMutateFrozenCollections +} +function isFrozen(obj) { + if (obj === null || !isObjectish(obj)) return true + return O.isFrozen(obj) +} + +// src/utils/plugins.ts +var PluginMapSet = "MapSet" +var PluginPatches = "Patches" +var PluginArrayMethods = "ArrayMethods" +var plugins = {} +function getPlugin(pluginKey) { + const plugin = plugins[pluginKey] + if (!plugin) { + die(0, pluginKey) + } + return plugin +} +var isPluginLoaded = pluginKey => !!plugins[pluginKey] +function loadPlugin(pluginKey, implementation) { + if (!plugins[pluginKey]) plugins[pluginKey] = implementation +} + +// src/core/scope.ts +var currentScope +var getCurrentScope = () => currentScope +var createScope = (parent_, immer_) => ({ + drafts_: [], + parent_, + 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, + handledSet_: /* @__PURE__ */ new Set(), + processedForPatches_: /* @__PURE__ */ new Set(), + mapSetPlugin_: isPluginLoaded(PluginMapSet) + ? getPlugin(PluginMapSet) + : void 0, + arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) + ? getPlugin(PluginArrayMethods) + : void 0 +}) +function usePatchesInScope(scope, patchListener) { + if (patchListener) { + scope.patchPlugin_ = getPlugin(PluginPatches) + scope.patches_ = [] + scope.inversePatches_ = [] + scope.patchListener_ = patchListener + } +} +function revokeScope(scope) { + leaveScope(scope) + scope.drafts_.forEach(revokeDraft) + scope.drafts_ = null +} +function leaveScope(scope) { + if (scope === currentScope) { + currentScope = scope.parent_ + } +} +var enterScope = immer2 => (currentScope = createScope(currentScope, immer2)) +function revokeDraft(draft) { + const state = draft[DRAFT_STATE] + if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) + state.revoke_() + else state.revoked_ = true +} + +// src/core/finalize.ts +function processResult(result, scope) { + scope.unfinalizedDrafts_ = scope.drafts_.length + const baseDraft = scope.drafts_[0] + const isReplaced = result !== void 0 && result !== baseDraft + if (isReplaced) { + if (baseDraft[DRAFT_STATE].modified_) { + revokeScope(scope) + die(4) + } + if (isDraftable(result)) { + result = finalize(scope, result) + } + const {patchPlugin_} = scope + if (patchPlugin_) { + patchPlugin_.generateReplacementPatches_( + baseDraft[DRAFT_STATE].base_, + result, + scope + ) + } + } else { + result = finalize(scope, baseDraft) + } + maybeFreeze(scope, result, true) + revokeScope(scope) + if (scope.patches_) { + scope.patchListener_(scope.patches_, scope.inversePatches_) + } + return result !== NOTHING ? result : void 0 +} +function finalize(rootScope, value) { + if (isFrozen(value)) return value + const state = value[DRAFT_STATE] + if (!state) { + const finalValue = handleValue(value, rootScope.handledSet_, rootScope) + return finalValue + } + if (!isSameScope(state, rootScope)) { + return value + } + if (!state.modified_) { + return state.base_ + } + if (!state.finalized_) { + const {callbacks_} = state + if (callbacks_) { + while (callbacks_.length > 0) { + const callback = callbacks_.pop() + callback(rootScope) + } + } + generatePatchesAndFinalize(state, rootScope) + } + return state.copy_ +} +function maybeFreeze(scope, value, deep = false) { + if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) { + freeze(value, deep) + } +} +function markStateFinalized(state) { + state.finalized_ = true + state.scope_.unfinalizedDrafts_-- +} +var isSameScope = (state, rootScope) => state.scope_ === rootScope +var EMPTY_LOCATIONS_RESULT = [] +function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) { + const parentCopy = latest(parent) + const parentType = parent.type_ + if (originalKey !== void 0) { + const currentValue = get(parentCopy, originalKey, parentType) + if (currentValue === draftValue) { + set(parentCopy, originalKey, finalizedValue, parentType) + return + } + } + if (!parent.draftLocations_) { + const draftLocations = (parent.draftLocations_ = /* @__PURE__ */ new Map()) + each(parentCopy, (key, value) => { + if (isDraft(value)) { + const keys = draftLocations.get(value) || [] + keys.push(key) + draftLocations.set(value, keys) + } + }) + } + const locations = + parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT + for (const location of locations) { + set(parentCopy, location, finalizedValue, parentType) + } +} +function registerChildFinalizationCallback(parent, child, key) { + parent.callbacks_.push(function childCleanup(rootScope) { + const state = child + if (!state || !isSameScope(state, rootScope)) { + return + } + rootScope.mapSetPlugin_?.fixSetContents(state) + const finalizedValue = getFinalValue(state) + updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key) + generatePatchesAndFinalize(state, rootScope) + }) +} +function generatePatchesAndFinalize(state, rootScope) { + const shouldFinalize = + state.modified_ && + !state.finalized_ && + (state.type_ === 3 /* Set */ || + (state.type_ === 1 /* Array */ && state.allIndicesReassigned_) || + (state.assigned_?.size ?? 0) > 0) + if (shouldFinalize) { + const {patchPlugin_} = rootScope + if (patchPlugin_) { + const basePath = patchPlugin_.getPath(state) + if (basePath) { + patchPlugin_.generatePatches_(state, basePath, rootScope) + } + } + markStateFinalized(state) + } +} +function handleCrossReference(target, key, value) { + const {scope_} = target + if (isDraft(value)) { + const state = value[DRAFT_STATE] + if (isSameScope(state, scope_)) { + state.callbacks_.push(function crossReferenceCleanup() { + prepareCopy(target) + const finalizedValue = getFinalValue(state) + updateDraftInParent(target, value, finalizedValue, key) + }) + } + } else if (isDraftable(value)) { + target.callbacks_.push(function nestedDraftCleanup() { + const targetCopy = latest(target) + if (get(targetCopy, key, target.type_) === value) { + if ( + scope_.drafts_.length > 1 && + (target.assigned_.get(key) ?? false) === true && + target.copy_ + ) { + handleValue( + get(target.copy_, key, target.type_), + scope_.handledSet_, + scope_ + ) + } + } + }) + } +} +function handleValue(target, handledSet, rootScope) { + if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) { + return target + } + if ( + isDraft(target) || + handledSet.has(target) || + !isDraftable(target) || + isFrozen(target) + ) { + return target + } + handledSet.add(target) + each(target, (key, value) => { + if (isDraft(value)) { + const state = value[DRAFT_STATE] + if (isSameScope(state, rootScope)) { + const updatedValue = getFinalValue(state) + set(target, key, updatedValue, target.type_) + markStateFinalized(state) + } + } else if (isDraftable(value)) { + handleValue(value, handledSet, rootScope) + } + }) + return target +} + +// src/core/proxy.ts +function createProxyProxy(base, parent) { + const baseIsArray = isArray(base) + const state = { + type_: baseIsArray ? 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). + // actually instantiated in `prepareCopy()` + assigned_: void 0, + // The parent draft state. + parent_: parent, + // The base state. + base_: base, + // The base proxy. + draft_: null, + // set below + // The base copy with any updated values. + copy_: null, + // Called by the `produce` function. + revoke_: null, + isManual_: false, + // `callbacks` actually gets assigned in `createProxy` + callbacks_: void 0 + } + let target = state + let traps = objectTraps + if (baseIsArray) { + target = [state] + traps = arrayTraps + } + const {revoke, proxy} = Proxy.revocable(target, traps) + state.draft_ = proxy + state.revoke_ = revoke + return [proxy, state] +} +var objectTraps = { + get(state, prop) { + if (prop === DRAFT_STATE) return state + let arrayPlugin = state.scope_.arrayMethodsPlugin_ + const isArrayWithStringProp = + state.type_ === 1 /* Array */ && typeof prop === "string" + if (isArrayWithStringProp) { + if (arrayPlugin?.isArrayOperationMethod(prop)) { + return arrayPlugin.createMethodInterceptor(state, prop) + } + } + const source = latest(state) + if (!has(source, prop, state.type_)) { + return readPropFromProto(state, source, prop) + } + const value = source[prop] + if (state.finalized_ || !isDraftable(value)) { + return value + } + if ( + isArrayWithStringProp && + state.operationMethod && + arrayPlugin?.isMutatingArrayMethod(state.operationMethod) && + isArrayIndex(prop) + ) { + return value + } + if (value === peek(state.base_, prop)) { + prepareCopy(state) + const childKey = state.type_ === 1 /* Array */ ? +prop : prop + const childDraft = createProxy(state.scope_, value, state, childKey) + return (state.copy_[childKey] = childDraft) + } + return value + }, + has(state, prop) { + return prop in latest(state) + }, + ownKeys(state) { + return Reflect.ownKeys(latest(state)) + }, + set(state, prop, value) { + const desc = getDescriptorFromProto(latest(state), prop) + if (desc?.set) { + desc.set.call(state.draft_, value) + return true + } + if (!state.modified_) { + const current2 = peek(latest(state), prop) + const currentState = current2?.[DRAFT_STATE] + if (currentState && currentState.base_ === value) { + state.copy_[prop] = value + state.assigned_.set(prop, false) + return true + } + if ( + is(value, current2) && + (value !== void 0 || has(state.base_, prop, state.type_)) + ) + return true + prepareCopy(state) + markChanged(state) + } + if ( + (state.copy_[prop] === value && // special case: handle new props with value 'undefined' + (value !== void 0 || prop in state.copy_)) || // special case: NaN + (Number.isNaN(value) && Number.isNaN(state.copy_[prop])) + ) + return true + state.copy_[prop] = value + state.assigned_.set(prop, true) + handleCrossReference(state, prop, value) + return true + }, + deleteProperty(state, prop) { + prepareCopy(state) + if (peek(state.base_, prop) !== void 0 || prop in state.base_) { + state.assigned_.set(prop, false) + markChanged(state) + } else { + state.assigned_.delete(prop) + } + if (state.copy_) { + 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(state, prop) { + const owner = latest(state) + const 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() { + die(11) + }, + getPrototypeOf(state) { + return getPrototypeOf(state.base_) + }, + setPrototypeOf() { + die(12) + } +} +var arrayTraps = {} +each(objectTraps, (key, fn) => { + arrayTraps[key] = function() { + const args = arguments + args[0] = args[0][0] + return fn.apply(this, args) + } +}) +arrayTraps.deleteProperty = function(state, prop) { + if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13) + return arrayTraps.set.call(this, state, prop, void 0) +} +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]) +} +function peek(draft, prop) { + const state = draft[DRAFT_STATE] + const source = state ? latest(state) : draft + return source[prop] +} +function readPropFromProto(state, source, prop) { + const 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?.call(state.draft_) + : void 0 +} +function getDescriptorFromProto(source, prop) { + if (!(prop in source)) return void 0 + let proto = getPrototypeOf(source) + while (proto) { + const desc = Object.getOwnPropertyDescriptor(proto, prop) + if (desc) return desc + proto = getPrototypeOf(proto) + } + return void 0 +} +function markChanged(state) { + if (!state.modified_) { + state.modified_ = true + if (state.parent_) { + markChanged(state.parent_) + } + } +} +function prepareCopy(state) { + if (!state.copy_) { + state.assigned_ = /* @__PURE__ */ new Map() + state.copy_ = shallowCopy( + state.base_, + state.scope_.immer_.useStrictShallowCopy_ + ) + } +} + +// src/core/immerClass.ts +var Immer2 = class { + constructor(config) { + this.autoFreeze_ = true + this.useStrictShallowCopy_ = false + this.useStrictIteration_ = 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 = (base, recipe, patchListener) => { + if (isFunction(base) && !isFunction(recipe)) { + const defaultBase = recipe + recipe = base + const self = this + return function curriedProduce(base2 = defaultBase, ...args) { + return self.produce(base2, draft => recipe.call(this, draft, ...args)) + } + } + if (!isFunction(recipe)) die(6) + if (patchListener !== void 0 && !isFunction(patchListener)) die(7) + let result + if (isDraftable(base)) { + const scope = enterScope(this) + const proxy = createProxy(scope, base, void 0) + let hasError = true + try { + result = recipe(proxy) + hasError = false + } finally { + if (hasError) revokeScope(scope) + else leaveScope(scope) + } + usePatchesInScope(scope, patchListener) + return processResult(result, scope) + } else if (!base || !isObjectish(base)) { + result = recipe(base) + if (result === void 0) result = base + if (result === NOTHING) result = void 0 + if (this.autoFreeze_) freeze(result, true) + if (patchListener) { + const p = [] + const ip = [] + getPlugin(PluginPatches).generateReplacementPatches_(base, result, { + patches_: p, + inversePatches_: ip + }) + patchListener(p, ip) + } + return result + } else die(1, base) + } + this.produceWithPatches = (base, recipe) => { + if (isFunction(base)) { + return (state, ...args) => + this.produceWithPatches(state, draft => base(draft, ...args)) + } + let patches, inversePatches + const result = this.produce(base, recipe, (p, ip) => { + patches = p + inversePatches = ip + }) + return [result, patches, inversePatches] + } + if (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config.autoFreeze) + if (isBoolean(config?.useStrictShallowCopy)) + this.setUseStrictShallowCopy(config.useStrictShallowCopy) + if (isBoolean(config?.useStrictIteration)) + this.setUseStrictIteration(config.useStrictIteration) + } + createDraft(base) { + if (!isDraftable(base)) die(8) + if (isDraft(base)) base = current(base) + const scope = enterScope(this) + const proxy = createProxy(scope, base, void 0) + proxy[DRAFT_STATE].isManual_ = true + leaveScope(scope) + return proxy + } + finishDraft(draft, patchListener) { + const state = draft && draft[DRAFT_STATE] + if (!state || !state.isManual_) die(9) + const {scope_: scope} = state + usePatchesInScope(scope, patchListener) + return processResult(void 0, scope) + } + /** + * Pass true to automatically freeze all copies created by Immer. + * + * By default, auto-freezing is enabled. + */ + 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. + */ + setUseStrictShallowCopy(value) { + this.useStrictShallowCopy_ = value + } + /** + * Pass false to use faster iteration that skips non-enumerable properties + * but still handles symbols for compatibility. + * + * By default, strict iteration is enabled (includes all own properties). + */ + setUseStrictIteration(value) { + this.useStrictIteration_ = value + } + shouldUseStrictIteration() { + return this.useStrictIteration_ + } + applyPatches(base, patches) { + let i + for (i = patches.length - 1; i >= 0; i--) { + const patch = patches[i] + if (patch.path.length === 0 && patch.op === "replace") { + base = patch.value + break + } + } + if (i > -1) { + patches = patches.slice(i + 1) + } + const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_ + if (isDraft(base)) { + return applyPatchesImpl(base, patches) + } + return this.produce(base, draft => applyPatchesImpl(draft, patches)) + } +} +function createProxy(rootScope, value, parent, key) { + const [draft, state] = isMap(value) + ? getPlugin(PluginMapSet).proxyMap_(value, parent) + : isSet(value) + ? getPlugin(PluginMapSet).proxySet_(value, parent) + : createProxyProxy(value, parent) + const scope = parent?.scope_ ?? getCurrentScope() + scope.drafts_.push(draft) + state.callbacks_ = parent?.callbacks_ ?? [] + state.key_ = key + if (parent && key !== void 0) { + registerChildFinalizationCallback(parent, state, key) + } else { + state.callbacks_.push(function rootDraftCleanup(rootScope2) { + rootScope2.mapSetPlugin_?.fixSetContents(state) + const {patchPlugin_} = rootScope2 + if (state.modified_ && patchPlugin_) { + patchPlugin_.generatePatches_(state, [], rootScope2) + } + }) + } + return draft +} + +// src/core/current.ts +function current(value) { + if (!isDraft(value)) die(10, value) + return currentImpl(value) +} +function currentImpl(value) { + if (!isDraftable(value) || isFrozen(value)) return value + const state = value[DRAFT_STATE] + let copy + let strict = true + if (state) { + if (!state.modified_) return state.base_ + state.finalized_ = true + copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_) + strict = state.scope_.immer_.shouldUseStrictIteration() + } else { + copy = shallowCopy(value, true) + } + each( + copy, + (key, childValue) => { + set(copy, key, currentImpl(childValue)) + }, + strict + ) + if (state) { + state.finalized_ = false + } + return copy +} + +// src/plugins/patches.ts +function enablePatches() { + const 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" + ) + } + function getPath(state, path = []) { + if ("key_" in state && state.key_ !== void 0) { + const parentCopy = state.parent_.copy_ ?? state.parent_.base_ + const proxyDraft = getProxyDraft(get(parentCopy, state.key_)) + const valueAtKey = get(parentCopy, state.key_) + if (valueAtKey === void 0) { + return null + } + if ( + valueAtKey !== state.draft_ && + valueAtKey !== state.base_ && + valueAtKey !== state.copy_ + ) { + return null + } + if (proxyDraft != null && proxyDraft.base_ !== state.base_) { + return null + } + const isSet2 = state.parent_.type_ === 3 /* Set */ + let key + if (isSet2) { + const setParent = state.parent_ + key = Array.from(setParent.drafts_.keys()).indexOf(state.key_) + } else { + key = state.key_ + } + if (!((isSet2 && parentCopy.size > key) || has(parentCopy, key))) { + return null + } + path.push(key) + } + if (state.parent_) { + return getPath(state.parent_, path) + } + path.reverse() + try { + resolvePath(state.copy_, path) + } catch (e) { + return null + } + return path + } + function resolvePath(base, path) { + let current2 = base + for (let i = 0; i < path.length - 1; i++) { + const key = path[i] + current2 = get(current2, key) + if (!isObjectish(current2) || current2 === null) { + throw new Error(`Cannot resolve path at '${path.join("/")}'`) + } + } + return current2 + } + const REPLACE = "replace" + const ADD = "add" + const REMOVE = "remove" + function generatePatches_(state, basePath, scope) { + if (state.scope_.processedForPatches_.has(state)) { + return + } + state.scope_.processedForPatches_.add(state) + const {patches_, inversePatches_} = scope + 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) { + let {base_, assigned_} = state + let copy_ = state.copy_ + if (copy_.length < base_.length) { + ;[base_, copy_] = [copy_, base_] + ;[patches, inversePatches] = [inversePatches, patches] + } + const allReassigned = state.allIndicesReassigned_ === true + for (let i = 0; i < base_.length; i++) { + const copiedItem = copy_[i] + const baseItem = base_[i] + const isAssigned = allReassigned || assigned_?.get(i.toString()) + if (isAssigned && copiedItem !== baseItem) { + const childState = copiedItem?.[DRAFT_STATE] + if (childState && childState.modified_) { + continue + } + const path = basePath.concat([i]) + patches.push({ + op: REPLACE, + 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(copiedItem) + }) + inversePatches.push({ + op: REPLACE, + path, + value: clonePatchValueIfNeeded(baseItem) + }) + } + } + for (let i = base_.length; i < copy_.length; i++) { + const path = basePath.concat([i]) + patches.push({ + op: ADD, + 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 (let i = copy_.length - 1; base_.length <= i; --i) { + const path = basePath.concat([i]) + inversePatches.push({ + op: REMOVE, + path + }) + } + } + function generatePatchesFromAssigned( + state, + basePath, + patches, + inversePatches + ) { + const {base_, copy_, type_} = state + each(state.assigned_, (key, assignedValue) => { + const origValue = get(base_, key, type_) + const value = get(copy_, key, type_) + const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD + if (origValue === value && op === REPLACE) return + const path = basePath.concat(key) + patches.push( + op === REMOVE + ? {op, path} + : {op, path, value: clonePatchValueIfNeeded(value)} + ) + inversePatches.push( + op === ADD + ? {op: REMOVE, path} + : op === REMOVE + ? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)} + : {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)} + ) + }) + } + function generateSetPatches(state, basePath, patches, inversePatches) { + let {base_, copy_} = state + let i = 0 + base_.forEach(value => { + if (!copy_.has(value)) { + const path = basePath.concat([i]) + patches.push({ + op: REMOVE, + path, + value + }) + inversePatches.unshift({ + op: ADD, + path, + value + }) + } + i++ + }) + i = 0 + copy_.forEach(value => { + if (!base_.has(value)) { + const path = basePath.concat([i]) + patches.push({ + op: ADD, + path, + value + }) + inversePatches.unshift({ + op: REMOVE, + path, + value + }) + } + i++ + }) + } + function generateReplacementPatches_(baseValue, replacement, scope) { + const {patches_, inversePatches_} = scope + patches_.push({ + op: REPLACE, + path: [], + value: replacement === NOTHING ? void 0 : replacement + }) + inversePatches_.push({ + op: REPLACE, + path: [], + value: baseValue + }) + } + function applyPatches_(draft, patches) { + patches.forEach(patch => { + const {path, op} = patch + let base = draft + for (let i = 0; i < path.length - 1; i++) { + const parentType = getArchtype(base) + let p = path[i] + if (typeof p !== "string" && typeof p !== "number") { + p = "" + p + } + if ( + (parentType === 0 /* Object */ || parentType === 1) /* Array */ && + (p === "__proto__" || p === CONSTRUCTOR) + ) + die(errorOffset + 3) + if (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3) + base = get(base, p) + if (!isObjectish(base)) die(errorOffset + 2, path.join("/")) + } + const type = getArchtype(base) + const value = deepClonePatchValue(patch.value) + const key = path[path.length - 1] + switch (op) { + case REPLACE: + switch (type) { + case 2 /* Map */: + return base.set(key, value) + case 3 /* Set */: + die(errorOffset) + default: + 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 (isArray(obj)) return obj.map(deepClonePatchValue) + if (isMap(obj)) + return new Map( + Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)]) + ) + if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue)) + const cloned = Object.create(getPrototypeOf(obj)) + for (const 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(PluginPatches, { + applyPatches_, + generatePatches_, + generateReplacementPatches_, + getPath + }) +} + +// src/plugins/mapset.ts +function enableMapSet() { + class DraftMap extends Map { + constructor(target, parent) { + super() + this[DRAFT_STATE] = { + type_: 2 /* Map */, + parent_: parent, + scope_: parent ? parent.scope_ : getCurrentScope(), + modified_: false, + finalized_: false, + copy_: void 0, + assigned_: void 0, + base_: target, + draft_: this, + isManual_: false, + revoked_: false, + callbacks_: [] + } + } + get size() { + return latest(this[DRAFT_STATE]).size + } + has(key) { + return latest(this[DRAFT_STATE]).has(key) + } + set(key, value) { + const 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 + } + delete(key) { + if (!this.has(key)) { + return false + } + const 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 + } + clear() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareMapCopy(state) + markChanged(state) + state.assigned_ = /* @__PURE__ */ new Map() + each(state.base_, key => { + state.assigned_.set(key, false) + }) + state.copy_.clear() + } + } + forEach(cb, thisArg) { + const state = this[DRAFT_STATE] + latest(state).forEach((_value, key, _map) => { + cb.call(thisArg, this.get(key), key, this) + }) + } + get(key) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + const value = latest(state).get(key) + if (state.finalized_ || !isDraftable(value)) { + return value + } + if (value !== state.base_.get(key)) { + return value + } + const draft = createProxy(state.scope_, value, state, key) + prepareMapCopy(state) + state.copy_.set(key, draft) + return draft + } + keys() { + return latest(this[DRAFT_STATE]).keys() + } + values() { + const iterator = this.keys() + return { + [Symbol.iterator]: () => this.values(), + next: () => { + const r = iterator.next() + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value + } + } + } + } + entries() { + const iterator = this.keys() + return { + [Symbol.iterator]: () => this.entries(), + next: () => { + const r = iterator.next() + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value: [r.value, value] + } + } + } + } + [(DRAFT_STATE, Symbol.iterator)]() { + return this.entries() + } + } + function proxyMap_(target, parent) { + const map = new DraftMap(target, parent) + return [map, map[DRAFT_STATE]] + } + function prepareMapCopy(state) { + if (!state.copy_) { + state.assigned_ = /* @__PURE__ */ new Map() + state.copy_ = new Map(state.base_) + } + } + class DraftSet extends Set { + constructor(target, parent) { + super() + this[DRAFT_STATE] = { + type_: 3 /* Set */, + parent_: parent, + scope_: parent ? parent.scope_ : getCurrentScope(), + modified_: false, + finalized_: false, + copy_: void 0, + base_: target, + draft_: this, + drafts_: /* @__PURE__ */ new Map(), + revoked_: false, + isManual_: false, + assigned_: void 0, + callbacks_: [] + } + } + get size() { + return latest(this[DRAFT_STATE]).size + } + has(value) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + 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 + } + add(value) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (!this.has(value)) { + prepareSetCopy(state) + markChanged(state) + state.copy_.add(value) + } + return this + } + delete(value) { + if (!this.has(value)) { + return false + } + const 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) + ) + } + clear() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareSetCopy(state) + markChanged(state) + state.copy_.clear() + } + } + values() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_.values() + } + entries() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_.entries() + } + keys() { + return this.values() + } + [(DRAFT_STATE, Symbol.iterator)]() { + return this.values() + } + forEach(cb, thisArg) { + const iterator = this.values() + let result = iterator.next() + while (!result.done) { + cb.call(thisArg, result.value, result.value, this) + result = iterator.next() + } + } + } + function proxySet_(target, parent) { + const set2 = new DraftSet(target, parent) + return [set2, set2[DRAFT_STATE]] + } + function prepareSetCopy(state) { + if (!state.copy_) { + state.copy_ = /* @__PURE__ */ new Set() + state.base_.forEach(value => { + if (isDraftable(value)) { + const draft = createProxy(state.scope_, value, state, value) + state.drafts_.set(value, draft) + state.copy_.add(draft) + } else { + state.copy_.add(value) + } + }) + } + } + function assertUnrevoked(state) { + if (state.revoked_) die(3, JSON.stringify(latest(state))) + } + function fixSetContents(target) { + if (target.type_ === 3 /* Set */ && target.copy_) { + const copy = new Set(target.copy_) + target.copy_.clear() + copy.forEach(value => { + target.copy_.add(getValue(value)) + }) + } + } + loadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents}) +} + +// src/plugins/arrayMethods.ts +function enableArrayMethods() { + const SHIFTING_METHODS = /* @__PURE__ */ new Set(["shift", "unshift"]) + const QUEUE_METHODS = /* @__PURE__ */ new Set(["push", "pop"]) + const RESULT_RETURNING_METHODS = /* @__PURE__ */ new Set([ + ...QUEUE_METHODS, + ...SHIFTING_METHODS + ]) + const REORDERING_METHODS = /* @__PURE__ */ new Set(["reverse", "sort"]) + const MUTATING_METHODS = /* @__PURE__ */ new Set([ + ...RESULT_RETURNING_METHODS, + ...REORDERING_METHODS, + "splice" + ]) + const FIND_METHODS = /* @__PURE__ */ new Set(["find", "findLast"]) + const NON_MUTATING_METHODS = /* @__PURE__ */ new Set([ + "filter", + "slice", + "concat", + "flat", + ...FIND_METHODS, + "findIndex", + "findLastIndex", + "some", + "every", + "indexOf", + "lastIndexOf", + "includes", + "join", + "toString", + "toLocaleString" + ]) + function isMutatingArrayMethod(method) { + return MUTATING_METHODS.has(method) + } + function isNonMutatingArrayMethod(method) { + return NON_MUTATING_METHODS.has(method) + } + function isArrayOperationMethod(method) { + return isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method) + } + function enterOperation(state, method) { + state.operationMethod = method + } + function exitOperation(state) { + state.operationMethod = void 0 + } + function executeArrayMethod(state, operation, markLength = true) { + prepareCopy(state) + const result = operation() + markChanged(state) + if (markLength) state.assigned_.set("length", true) + return result + } + function markAllIndicesReassigned(state) { + state.allIndicesReassigned_ = true + } + function normalizeSliceIndex(index, length) { + if (index < 0) { + return Math.max(length + index, 0) + } + return Math.min(index, length) + } + function handleSimpleOperation(state, method, args) { + return executeArrayMethod(state, () => { + const result = state.copy_[method](...args) + if (SHIFTING_METHODS.has(method)) { + markAllIndicesReassigned(state) + } + return RESULT_RETURNING_METHODS.has(method) ? result : state.draft_ + }) + } + function handleReorderingOperation(state, method, args) { + return executeArrayMethod( + state, + () => { + state.copy_[method](...args) + markAllIndicesReassigned(state) + return state.draft_ + }, + false + ) + } + function createMethodInterceptor(state, originalMethod) { + return function interceptedMethod(...args) { + const method = originalMethod + enterOperation(state, method) + try { + if (isMutatingArrayMethod(method)) { + if (RESULT_RETURNING_METHODS.has(method)) { + return handleSimpleOperation(state, method, args) + } + if (REORDERING_METHODS.has(method)) { + return handleReorderingOperation(state, method, args) + } + if (method === "splice") { + const res = executeArrayMethod(state, () => + state.copy_.splice(...args) + ) + markAllIndicesReassigned(state) + return res + } + } else { + return handleNonMutatingOperation(state, method, args) + } + } finally { + exitOperation(state) + } + } + } + function handleNonMutatingOperation(state, method, args) { + const source = latest(state) + if (method === "filter") { + const predicate = args[0] + const result = [] + for (let i = 0; i < source.length; i++) { + if (predicate(source[i], i, source)) { + result.push(state.draft_[i]) + } + } + return result + } + if (FIND_METHODS.has(method)) { + const predicate = args[0] + const isForward = method === "find" + const step = isForward ? 1 : -1 + const start = isForward ? 0 : source.length - 1 + for (let i = start; i >= 0 && i < source.length; i += step) { + if (predicate(source[i], i, source)) { + return state.draft_[i] + } + } + return void 0 + } + if (method === "slice") { + const rawStart = args[0] ?? 0 + const rawEnd = args[1] ?? source.length + const start = normalizeSliceIndex(rawStart, source.length) + const end = normalizeSliceIndex(rawEnd, source.length) + const result = [] + for (let i = start; i < end; i++) { + result.push(state.draft_[i]) + } + return result + } + return source[method](...args) + } + loadPlugin(PluginArrayMethods, { + createMethodInterceptor, + isArrayOperationMethod, + isMutatingArrayMethod + }) +} + +// src/immer.ts +var immer = new Immer2() +var produce = immer.produce +var produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(immer) +var setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer) +var setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind( + immer +) +var setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind( + immer +) +var applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer) +var createDraft = /* @__PURE__ */ immer.createDraft.bind(immer) +var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer) +var castDraft = value => value +var castImmutable = value => value +function isNothing(value) { + return value === NOTHING +} +// Annotate the CommonJS export names for ESM import in node: +0 && + (module.exports = { + Immer, + applyPatches, + castDraft, + castImmutable, + createDraft, + current, + enableArrayMethods, + enableMapSet, + enablePatches, + finishDraft, + freeze, + immerable, + isDraft, + isDraftable, + isNothing, + nothing, + original, + produce, + produceWithPatches, + setAutoFreeze, + setUseStrictIteration, + setUseStrictShallowCopy + }) +//# sourceMappingURL=immer.cjs.development.js.map diff --git a/dist/cjs/immer.cjs.development.js.map b/dist/cjs/immer.cjs.development.js.map new file mode 100644 index 00000000..4afe9814 --- /dev/null +++ b/dist/cjs/immer.cjs.development.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/immer.ts","../../src/utils/env.ts","../../src/utils/errors.ts","../../src/utils/common.ts","../../src/utils/plugins.ts","../../src/core/scope.ts","../../src/core/finalize.ts","../../src/core/proxy.ts","../../src/core/immerClass.ts","../../src/core/current.ts","../../src/plugins/patches.ts","../../src/plugins/mapset.ts","../../src/plugins/arrayMethods.ts"],"sourcesContent":["import {\n\tIProduce,\n\tIProduceWithPatches,\n\tImmer,\n\tDraft,\n\tImmutable,\n\tNOTHING as nothing\n} from \"./internal\"\n\nexport {\n\tDraft,\n\tWritableDraft,\n\tImmutable,\n\tPatch,\n\tPatchListener,\n\tProducer,\n\toriginal,\n\tcurrent,\n\tisDraft,\n\tisDraftable,\n\tDRAFTABLE as immerable,\n\tfreeze,\n\tObjectish,\n\tStrictMode\n} from \"./internal\"\n\nexport {nothing}\n\nconst immer = new Immer()\n\n/**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\nexport const produce: IProduce = /* @__PURE__ */ immer.produce\n\n/**\n * Like `produce`, but `produceWithPatches` always returns a tuple\n * [nextState, patches, inversePatches] (instead of just the next state)\n */\nexport const produceWithPatches: IProduceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(\n\timmer\n)\n\n/**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * Always freeze by default, even in production mode\n */\nexport const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)\n\n/**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\nexport const setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(\n\timmer\n)\n\n/**\n * Pass false to use loose iteration that only processes enumerable string properties.\n * This skips symbols and non-enumerable properties for maximum performance.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\nexport const setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(\n\timmer\n)\n\n/**\n * Apply an array of Immer patches to the first argument.\n *\n * This function is a producer, which means copy-on-write is in effect.\n */\nexport const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)\n\n/**\n * Create an Immer draft from the given base state, which may be a draft itself.\n * The draft can be modified until you finalize it with the `finishDraft` function.\n */\nexport const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)\n\n/**\n * Finalize an Immer draft from a `createDraft` call, returning the base state\n * (if no changes were made) or a modified copy. The draft must *not* be\n * mutated afterwards.\n *\n * Pass a function as the 2nd argument to generate Immer patches based on the\n * changes that were made.\n */\nexport const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)\n\n/**\n * This function is actually a no-op, but can be used to cast an immutable type\n * to an draft type and make TypeScript happy\n *\n * @param value\n */\nexport let castDraft = (value: T): Draft => value as any\n\n/**\n * This function is actually a no-op, but can be used to cast a mutable type\n * to an immutable type and make TypeScript happy\n * @param value\n */\nexport let castImmutable = (value: T): Immutable => value as any\n\nexport {Immer}\n\nexport {enablePatches} from \"./plugins/patches\"\nexport {enableMapSet} from \"./plugins/mapset\"\nexport {enableArrayMethods} from \"./plugins/arrayMethods\"\n\nexport function isNothing(value: unknown): value is typeof nothing {\n\treturn value === nothing\n}\n","// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","import {isFunction} from \"../internal\"\n\nexport const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `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}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = isFunction(e) ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nconst O = Object\n\nexport const getPrototypeOf = O.getPrototypeOf\n\nexport const CONSTRUCTOR = \"constructor\"\nexport const PROTOTYPE = \"prototype\"\n\nexport const CONFIGURABLE = \"configurable\"\nexport const ENUMERABLE = \"enumerable\"\nexport const WRITABLE = \"writable\"\nexport const VALUE = \"value\"\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport let isDraft = (value: any): boolean => !!value && !!value[DRAFT_STATE]\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tisArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value[CONSTRUCTOR]?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString()\nconst cachedCtorStrings = new WeakMap()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || !isObjectish(value)) return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null || proto === O[PROTOTYPE]) return true\n\n\tconst Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR]\n\tif (Ctor === Object) return true\n\n\tif (!isFunction(Ctor)) return false\n\n\tlet ctorString = cachedCtorStrings.get(Ctor)\n\tif (ctorString === undefined) {\n\t\tctorString = Function.toString.call(Ctor)\n\t\tcachedCtorStrings.set(Ctor, ctorString)\n\t}\n\n\treturn ctorString === objectCtorString\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n *\n * @param obj The object to iterate over\n * @param iter The iterator function\n * @param strict When true (default), includes symbols and non-enumerable properties.\n * When false, uses looseiteration over only enumerable string properties.\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void,\n\tstrict?: boolean\n): void\nexport function each(obj: any, iter: any, strict: boolean = true) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\t// If strict, we do a full iteration including symbols and non-enumerable properties\n\t\t// Otherwise, we only iterate enumerable string properties for performance\n\t\tconst keys = strict ? Reflect.ownKeys(obj) : O.keys(obj)\n\t\tkeys.forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport let has = (\n\tthing: any,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): boolean =>\n\ttype === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: O[PROTOTYPE].hasOwnProperty.call(thing, prop)\n\n/*#__PURE__*/\nexport let get = (\n\tthing: AnyMap | AnyObject,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): any =>\n\t// @ts-ignore\n\ttype === ArchType.Map ? thing.get(prop) : thing[prop]\n\n/*#__PURE__*/\nexport let set = (\n\tthing: any,\n\tpropOrOldValue: PropertyKey,\n\tvalue: any,\n\ttype = getArchtype(thing)\n) => {\n\tif (type === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (type === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\nexport let isArray = Array.isArray\n\n/*#__PURE__*/\nexport let isMap = (target: any): target is AnyMap => target instanceof Map\n\n/*#__PURE__*/\nexport let isSet = (target: any): target is AnySet => target instanceof Set\n\nexport let isObjectish = (target: any) => typeof target === \"object\"\n\nexport let isFunction = (target: any): target is Function =>\n\ttypeof target === \"function\"\n\nexport let isBoolean = (target: any): target is boolean =>\n\ttypeof target === \"boolean\"\n\nexport function isArrayIndex(value: string | number): value is number | string {\n\tconst n = +value\n\treturn Number.isInteger(n) && String(n) === value\n}\n\nexport let getProxyDraft = (value: T): ImmerState | null => {\n\tif (!isObjectish(value)) return null\n\treturn (value as {[DRAFT_STATE]: any})?.[DRAFT_STATE]\n}\n\n/*#__PURE__*/\nexport let latest = (state: ImmerState): any => state.copy_ || state.base_\n\nexport let getValue = (value: T): T => {\n\tconst proxyDraft = getProxyDraft(value)\n\treturn proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value\n}\n\nexport let getFinalValue = (state: ImmerState): any =>\n\tstate.modified_ ? state.copy_ : state.base_\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (isArray(base)) return Array[PROTOTYPE].slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = O.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc[WRITABLE] === false) {\n\t\t\t\tdesc[WRITABLE] = true\n\t\t\t\tdesc[CONFIGURABLE] = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\t[CONFIGURABLE]: true,\n\t\t\t\t\t[WRITABLE]: true, // could live with !!desc.set as well here...\n\t\t\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t\t\t[VALUE]: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn O.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = O.create(proto)\n\t\treturn O.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tO.defineProperties(obj, {\n\t\t\tset: dontMutateMethodOverride,\n\t\t\tadd: dontMutateMethodOverride,\n\t\t\tclear: dontMutateMethodOverride,\n\t\t\tdelete: dontMutateMethodOverride\n\t\t})\n\t}\n\tO.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.values (only string-like, enumerables) instead of each()\n\t\teach(\n\t\t\tobj,\n\t\t\t(_key, value) => {\n\t\t\t\tfreeze(value, true)\n\t\t\t},\n\t\t\tfalse\n\t\t)\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nconst dontMutateMethodOverride = {\n\t[VALUE]: dontMutateFrozenCollections\n}\n\nexport function isFrozen(obj: any): boolean {\n\t// Fast path: primitives and null/undefined are always \"frozen\"\n\tif (obj === null || !isObjectish(obj)) return true\n\treturn O.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie,\n\tImmerScope,\n\tProxyArrayState\n} from \"../internal\"\n\nexport const PluginMapSet = \"MapSet\"\nexport const PluginPatches = \"Patches\"\nexport const PluginArrayMethods = \"ArrayMethods\"\n\nexport type PatchesPlugin = {\n\tgeneratePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\trootScope: ImmerScope\n\t): void\n\tgenerateReplacementPatches_(\n\t\tbase: any,\n\t\treplacement: any,\n\t\trootScope: ImmerScope\n\t): void\n\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\tgetPath: (state: ImmerState) => PatchPath | null\n}\n\nexport type MapSetPlugin = {\n\tproxyMap_(target: T, parent?: ImmerState): [T, ImmerState]\n\tproxySet_(target: T, parent?: ImmerState): [T, ImmerState]\n\tfixSetContents: (state: ImmerState) => void\n}\n\nexport type ArrayMethodsPlugin = {\n\tcreateMethodInterceptor: (state: ProxyArrayState, method: string) => Function\n\tisArrayOperationMethod: (method: string) => boolean\n\tisMutatingArrayMethod: (method: string) => boolean\n}\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: PatchesPlugin\n\tMapSet?: MapSetPlugin\n\tArrayMethods?: ArrayMethodsPlugin\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport let isPluginLoaded = (pluginKey: K): boolean =>\n\t!!plugins[pluginKey]\n\nexport let clearPlugin = (pluginKey: K): void => {\n\tdelete plugins[pluginKey]\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin,\n\tPatchesPlugin,\n\tMapSetPlugin,\n\tisPluginLoaded,\n\tPluginMapSet,\n\tPluginPatches,\n\tArrayMethodsPlugin,\n\tPluginArrayMethods\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tpatchPlugin_?: PatchesPlugin\n\tmapSetPlugin_?: MapSetPlugin\n\tarrayMethodsPlugin_?: ArrayMethodsPlugin\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n\thandledSet_: Set\n\tprocessedForPatches_: Set\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport let getCurrentScope = () => currentScope!\n\nlet createScope = (\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope => ({\n\tdrafts_: [],\n\tparent_,\n\timmer_,\n\t// Whenever the modified draft contains a draft from another scope, we\n\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\tcanAutoFreeze_: true,\n\tunfinalizedDrafts_: 0,\n\thandledSet_: new Set(),\n\tprocessedForPatches_: new Set(),\n\tmapSetPlugin_: isPluginLoaded(PluginMapSet)\n\t\t? getPlugin(PluginMapSet)\n\t\t: undefined,\n\tarrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods)\n\t\t? getPlugin(PluginArrayMethods)\n\t\t: undefined\n})\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tscope.patchPlugin_ = getPlugin(PluginPatches) // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport let enterScope = (immer: Immer) =>\n\t(currentScope = createScope(currentScope, immer))\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen,\n\tget,\n\tPatch,\n\tlatest,\n\tprepareCopy,\n\tgetFinalValue,\n\tgetValue,\n\tProxyArrayState\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t}\n\t\tconst {patchPlugin_} = scope\n\t\tif (patchPlugin_) {\n\t\t\tpatchPlugin_.generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft)\n\t}\n\n\tmaybeFreeze(scope, result, true)\n\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\tif (!state) {\n\t\tconst finalValue = handleValue(value, rootScope.handledSet_, rootScope)\n\t\treturn finalValue\n\t}\n\n\t// Never finalize drafts owned by another scope\n\tif (!isSameScope(state, rootScope)) {\n\t\treturn value\n\t}\n\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\treturn state.base_\n\t}\n\n\tif (!state.finalized_) {\n\t\t// Execute all registered draft finalization callbacks\n\t\tconst {callbacks_} = state\n\t\tif (callbacks_) {\n\t\t\twhile (callbacks_.length > 0) {\n\t\t\t\tconst callback = callbacks_.pop()!\n\t\t\t\tcallback(rootScope)\n\t\t\t}\n\t\t}\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t}\n\n\t// By now the root copy has been fully updated throughout its tree\n\treturn state.copy_\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n\nfunction markStateFinalized(state: ImmerState) {\n\tstate.finalized_ = true\n\tstate.scope_.unfinalizedDrafts_--\n}\n\nlet isSameScope = (state: ImmerState, rootScope: ImmerScope) =>\n\tstate.scope_ === rootScope\n\n// A reusable empty array to avoid allocations\nconst EMPTY_LOCATIONS_RESULT: (string | symbol | number)[] = []\n\n// Updates all references to a draft in its parent to the finalized value.\n// This handles cases where the same draft appears multiple times in the parent, or has been moved around.\nexport function updateDraftInParent(\n\tparent: ImmerState,\n\tdraftValue: any,\n\tfinalizedValue: any,\n\toriginalKey?: string | number | symbol\n): void {\n\tconst parentCopy = latest(parent)\n\tconst parentType = parent.type_\n\n\t// Fast path: Check if draft is still at original key\n\tif (originalKey !== undefined) {\n\t\tconst currentValue = get(parentCopy, originalKey, parentType)\n\t\tif (currentValue === draftValue) {\n\t\t\t// Still at original location, just update it\n\t\t\tset(parentCopy, originalKey, finalizedValue, parentType)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Slow path: Build reverse mapping of all children\n\t// to their indices in the parent, so that we can\n\t// replace all locations where this draft appears.\n\t// We only have to build this once per parent.\n\tif (!parent.draftLocations_) {\n\t\tconst draftLocations = (parent.draftLocations_ = new Map())\n\n\t\t// Use `each` which works on Arrays, Maps, and Objects\n\t\teach(parentCopy, (key, value) => {\n\t\t\tif (isDraft(value)) {\n\t\t\t\tconst keys = draftLocations.get(value) || []\n\t\t\t\tkeys.push(key)\n\t\t\t\tdraftLocations.set(value, keys)\n\t\t\t}\n\t\t})\n\t}\n\n\t// Look up all locations where this draft appears\n\tconst locations =\n\t\tparent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT\n\n\t// Update all locations\n\tfor (const location of locations) {\n\t\tset(parentCopy, location, finalizedValue, parentType)\n\t}\n}\n\n// Register a callback to finalize a child draft when the parent draft is finalized.\n// This assumes there is a parent -> child relationship between the two drafts,\n// and we have a key to locate the child in the parent.\nexport function registerChildFinalizationCallback(\n\tparent: ImmerState,\n\tchild: ImmerState,\n\tkey: string | number | symbol\n) {\n\tparent.callbacks_.push(function childCleanup(rootScope) {\n\t\tconst state: ImmerState = child\n\n\t\t// Can only continue if this is a draft owned by this scope\n\t\tif (!state || !isSameScope(state, rootScope)) {\n\t\t\treturn\n\t\t}\n\n\t\t// Handle potential set value finalization first\n\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t// Update all locations in the parent that referenced this draft\n\t\tupdateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key)\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t})\n}\n\nfunction generatePatchesAndFinalize(state: ImmerState, rootScope: ImmerScope) {\n\tconst shouldFinalize =\n\t\tstate.modified_ &&\n\t\t!state.finalized_ &&\n\t\t(state.type_ === ArchType.Set ||\n\t\t\t(state.type_ === ArchType.Array &&\n\t\t\t\t(state as ProxyArrayState).allIndicesReassigned_) ||\n\t\t\t(state.assigned_?.size ?? 0) > 0)\n\n\tif (shouldFinalize) {\n\t\tconst {patchPlugin_} = rootScope\n\t\tif (patchPlugin_) {\n\t\t\tconst basePath = patchPlugin_!.getPath(state)\n\n\t\t\tif (basePath) {\n\t\t\t\tpatchPlugin_!.generatePatches_(state, basePath, rootScope)\n\t\t\t}\n\t\t}\n\n\t\tmarkStateFinalized(state)\n\t}\n}\n\nexport function handleCrossReference(\n\ttarget: ImmerState,\n\tkey: string | number | symbol,\n\tvalue: any\n) {\n\tconst {scope_} = target\n\t// Check if value is a draft from this scope\n\tif (isDraft(value)) {\n\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\tif (isSameScope(state, scope_)) {\n\t\t\t// Register callback to update this location when the draft finalizes\n\n\t\t\tstate.callbacks_.push(function crossReferenceCleanup() {\n\t\t\t\t// Update the target location with finalized value\n\t\t\t\tprepareCopy(target)\n\n\t\t\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t\t\tupdateDraftInParent(target, value, finalizedValue, key)\n\t\t\t})\n\t\t}\n\t} else if (isDraftable(value)) {\n\t\t// Handle non-draft objects that might contain drafts\n\t\ttarget.callbacks_.push(function nestedDraftCleanup() {\n\t\t\tconst targetCopy = latest(target)\n\n\t\t\tif (get(targetCopy, key, target.type_) === value) {\n\t\t\t\t// Process the value to replace any nested drafts\n\t\t\t\t// finalizeAssigned(target, key, target.scope_)\n\n\t\t\t\tif (\n\t\t\t\t\tscope_.drafts_.length > 1 &&\n\t\t\t\t\t((target as Exclude).assigned_!.get(key) ??\n\t\t\t\t\t\tfalse) === true &&\n\t\t\t\t\ttarget.copy_\n\t\t\t\t) {\n\t\t\t\t\t// This might be a non-draft value that has drafts\n\t\t\t\t\t// inside. We do need to recurse here to handle those.\n\t\t\t\t\thandleValue(\n\t\t\t\t\t\tget(target.copy_, key, target.type_),\n\t\t\t\t\t\tscope_.handledSet_,\n\t\t\t\t\t\tscope_\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport function handleValue(\n\ttarget: any,\n\thandledSet: Set,\n\trootScope: ImmerScope\n) {\n\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t// This benefits especially adding large data tree's without further processing.\n\t\t// See add-data.js perf test\n\t\treturn target\n\t}\n\n\t// Skip if already handled, frozen, or not draftable\n\tif (\n\t\tisDraft(target) ||\n\t\thandledSet.has(target) ||\n\t\t!isDraftable(target) ||\n\t\tisFrozen(target)\n\t) {\n\t\treturn target\n\t}\n\n\thandledSet.add(target)\n\n\t// Process ALL properties/entries\n\teach(target, (key, value) => {\n\t\tif (isDraft(value)) {\n\t\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\t\tif (isSameScope(state, rootScope)) {\n\t\t\t\t// Replace draft with finalized value\n\n\t\t\t\tconst updatedValue = getFinalValue(state)\n\n\t\t\t\tset(target, key, updatedValue, target.type_)\n\n\t\t\t\tmarkStateFinalized(state)\n\t\t\t}\n\t\t} else if (isDraftable(value)) {\n\t\t\t// Recursively handle nested values\n\t\t\thandleValue(value, handledSet, rootScope)\n\t\t}\n\t})\n\n\treturn target\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope,\n\thandleCrossReference,\n\tWRITABLE,\n\tCONFIGURABLE,\n\tENUMERABLE,\n\tVALUE,\n\tisArray,\n\tisArrayIndex\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted\n\toperationMethod?: string\n\tallIndicesReassigned_?: boolean\n}\n\ntype ProxyState = ProxyObjectState | ProxyArrayState\n\n/**\n * Returns a new draft of the `base` object.\n *\n * The second argument is the parent draft-state (used internally).\n */\nexport function createProxyProxy(\n\tbase: T,\n\tparent?: ImmerState\n): [Drafted, ProxyState] {\n\tconst baseIsArray = isArray(base)\n\tconst state: ProxyState = {\n\t\ttype_: baseIsArray ? ArchType.Array : (ArchType.Object as any),\n\t\t// Track which produce call this is associated with.\n\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t// True for both shallow and deep changes.\n\t\tmodified_: false,\n\t\t// Used during finalization.\n\t\tfinalized_: false,\n\t\t// Track which properties have been assigned (true) or deleted (false).\n\t\t// actually instantiated in `prepareCopy()`\n\t\tassigned_: undefined,\n\t\t// The parent draft state.\n\t\tparent_: parent,\n\t\t// The base state.\n\t\tbase_: base,\n\t\t// The base proxy.\n\t\tdraft_: null as any, // set below\n\t\t// The base copy with any updated values.\n\t\tcopy_: null,\n\t\t// Called by the `produce` function.\n\t\trevoke_: null as any,\n\t\tisManual_: false,\n\t\t// `callbacks` actually gets assigned in `createProxy`\n\t\tcallbacks_: undefined as any\n\t}\n\n\t// the traps must target something, a bit like the 'real' base.\n\t// but also, we need to be able to determine from the target what the relevant state is\n\t// (to avoid creating traps per instance to capture the state in closure,\n\t// and to avoid creating weird hidden properties as well)\n\t// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)\n\t// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb\n\tlet target: T = state as any\n\tlet traps: ProxyHandler> = objectTraps\n\tif (baseIsArray) {\n\t\ttarget = [state] as any\n\t\ttraps = arrayTraps\n\t}\n\n\tconst {revoke, proxy} = Proxy.revocable(target, traps)\n\tstate.draft_ = proxy as any\n\tstate.revoke_ = revoke\n\treturn [proxy as any, state]\n}\n\n/**\n * Object drafts\n */\nexport const objectTraps: ProxyHandler = {\n\tget(state, prop) {\n\t\tif (prop === DRAFT_STATE) return state\n\n\t\tlet arrayPlugin = state.scope_.arrayMethodsPlugin_\n\t\tconst isArrayWithStringProp =\n\t\t\tstate.type_ === ArchType.Array && typeof prop === \"string\"\n\t\t// Intercept array methods so that we can override\n\t\t// behavior and skip proxy creation for perf\n\t\tif (isArrayWithStringProp) {\n\t\t\tif (arrayPlugin?.isArrayOperationMethod(prop)) {\n\t\t\t\treturn arrayPlugin.createMethodInterceptor(state, prop)\n\t\t\t}\n\t\t}\n\n\t\tconst source = latest(state)\n\t\tif (!has(source, prop, state.type_)) {\n\t\t\t// non-existing or non-own property...\n\t\t\treturn readPropFromProto(state, source, prop)\n\t\t}\n\t\tconst value = source[prop]\n\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\treturn value\n\t\t}\n\n\t\t// During mutating array operations, defer proxy creation for array elements\n\t\t// This optimization avoids creating unnecessary proxies during sort/reverse\n\t\tif (\n\t\t\tisArrayWithStringProp &&\n\t\t\t(state as ProxyArrayState).operationMethod &&\n\t\t\tarrayPlugin?.isMutatingArrayMethod(\n\t\t\t\t(state as ProxyArrayState).operationMethod!\n\t\t\t) &&\n\t\t\tisArrayIndex(prop)\n\t\t) {\n\t\t\t// Return raw value during mutating operations, create proxy only if modified\n\t\t\treturn value\n\t\t}\n\t\t// Check for existing draft in modified state.\n\t\t// Assigned values are never drafted. This catches any drafts we created, too.\n\t\tif (value === peek(state.base_, prop)) {\n\t\t\tprepareCopy(state)\n\t\t\t// Ensure array keys are always numbers\n\t\t\tconst childKey = state.type_ === ArchType.Array ? +(prop as string) : prop\n\t\t\tconst childDraft = createProxy(state.scope_, value, state, childKey)\n\n\t\t\treturn (state.copy_![childKey] = childDraft)\n\t\t}\n\t\treturn value\n\t},\n\thas(state, prop) {\n\t\treturn prop in latest(state)\n\t},\n\townKeys(state) {\n\t\treturn Reflect.ownKeys(latest(state))\n\t},\n\tset(\n\t\tstate: ProxyObjectState,\n\t\tprop: string /* strictly not, but helps TS */,\n\t\tvalue\n\t) {\n\t\tconst desc = getDescriptorFromProto(latest(state), prop)\n\t\tif (desc?.set) {\n\t\t\t// special case: if this write is captured by a setter, we have\n\t\t\t// to trigger it with the correct context\n\t\t\tdesc.set.call(state.draft_, value)\n\t\t\treturn true\n\t\t}\n\t\tif (!state.modified_) {\n\t\t\t// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)\n\t\t\t// from setting an existing property with value undefined to undefined (which is not a change)\n\t\t\tconst current = peek(latest(state), prop)\n\t\t\t// special case, if we assigning the original value to a draft, we can ignore the assignment\n\t\t\tconst currentState: ProxyObjectState = current?.[DRAFT_STATE]\n\t\t\tif (currentState && currentState.base_ === value) {\n\t\t\t\tstate.copy_![prop] = value\n\t\t\t\tstate.assigned_!.set(prop, false)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (\n\t\t\t\tis(value, current) &&\n\t\t\t\t(value !== undefined || has(state.base_, prop, state.type_))\n\t\t\t)\n\t\t\t\treturn true\n\t\t\tprepareCopy(state)\n\t\t\tmarkChanged(state)\n\t\t}\n\n\t\tif (\n\t\t\t(state.copy_![prop] === value &&\n\t\t\t\t// special case: handle new props with value 'undefined'\n\t\t\t\t(value !== undefined || prop in state.copy_)) ||\n\t\t\t// special case: NaN\n\t\t\t(Number.isNaN(value) && Number.isNaN(state.copy_![prop]))\n\t\t)\n\t\t\treturn true\n\n\t\t// @ts-ignore\n\t\tstate.copy_![prop] = value\n\t\tstate.assigned_!.set(prop, true)\n\n\t\thandleCrossReference(state, prop, value)\n\t\treturn true\n\t},\n\tdeleteProperty(state, prop: string) {\n\t\tprepareCopy(state)\n\t\t// The `undefined` check is a fast path for pre-existing keys.\n\t\tif (peek(state.base_, prop) !== undefined || prop in state.base_) {\n\t\t\tstate.assigned_!.set(prop, false)\n\t\t\tmarkChanged(state)\n\t\t} else {\n\t\t\t// if an originally not assigned property was deleted\n\t\t\tstate.assigned_!.delete(prop)\n\t\t}\n\t\tif (state.copy_) {\n\t\t\tdelete state.copy_[prop]\n\t\t}\n\t\treturn true\n\t},\n\t// Note: We never coerce `desc.value` into an Immer draft, because we can't make\n\t// the same guarantee in ES5 mode.\n\tgetOwnPropertyDescriptor(state, prop) {\n\t\tconst owner = latest(state)\n\t\tconst desc = Reflect.getOwnPropertyDescriptor(owner, prop)\n\t\tif (!desc) return desc\n\t\treturn {\n\t\t\t[WRITABLE]: true,\n\t\t\t[CONFIGURABLE]: state.type_ !== ArchType.Array || prop !== \"length\",\n\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t[VALUE]: owner[prop]\n\t\t}\n\t},\n\tdefineProperty() {\n\t\tdie(11)\n\t},\n\tgetPrototypeOf(state) {\n\t\treturn getPrototypeOf(state.base_)\n\t},\n\tsetPrototypeOf() {\n\t\tdie(12)\n\t}\n}\n\n/**\n * Array drafts\n */\n\nconst arrayTraps: ProxyHandler<[ProxyArrayState]> = {}\neach(objectTraps, (key, fn) => {\n\t// @ts-ignore\n\tarrayTraps[key] = function() {\n\t\tconst args = arguments\n\t\targs[0] = args[0][0]\n\t\treturn fn.apply(this, args)\n\t}\n})\narrayTraps.deleteProperty = function(state, prop) {\n\tif (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop as any)))\n\t\tdie(13)\n\t// @ts-ignore\n\treturn arrayTraps.set!.call(this, state, prop, undefined)\n}\narrayTraps.set = function(state, prop, value) {\n\tif (\n\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\tprop !== \"length\" &&\n\t\tisNaN(parseInt(prop as any))\n\t)\n\t\tdie(14)\n\treturn objectTraps.set!.call(this, state[0], prop, value, state[0])\n}\n\n// Access a property without creating an Immer draft.\nfunction peek(draft: Drafted, prop: PropertyKey) {\n\tconst state = draft[DRAFT_STATE]\n\tconst source = state ? latest(state) : draft\n\treturn source[prop]\n}\n\nfunction readPropFromProto(state: ImmerState, source: any, prop: PropertyKey) {\n\tconst desc = getDescriptorFromProto(source, prop)\n\treturn desc\n\t\t? VALUE in desc\n\t\t\t? desc[VALUE]\n\t\t\t: // This is a very special case, if the prop is a getter defined by the\n\t\t\t // prototype, we should invoke it with the draft as context!\n\t\t\t desc.get?.call(state.draft_)\n\t\t: undefined\n}\n\nfunction getDescriptorFromProto(\n\tsource: any,\n\tprop: PropertyKey\n): PropertyDescriptor | undefined {\n\t// 'in' checks proto!\n\tif (!(prop in source)) return undefined\n\tlet proto = getPrototypeOf(source)\n\twhile (proto) {\n\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\tif (desc) return desc\n\t\tproto = getPrototypeOf(proto)\n\t}\n\treturn undefined\n}\n\nexport function markChanged(state: ImmerState) {\n\tif (!state.modified_) {\n\t\tstate.modified_ = true\n\t\tif (state.parent_) {\n\t\t\tmarkChanged(state.parent_)\n\t\t}\n\t}\n}\n\nexport function prepareCopy(state: ImmerState) {\n\tif (!state.copy_) {\n\t\t// Actually create the `assigned_` map now that we\n\t\t// know this is a modified draft.\n\t\tstate.assigned_ = new Map()\n\t\tstate.copy_ = shallowCopy(\n\t\t\tstate.base_,\n\t\t\tstate.scope_.immer_.useStrictShallowCopy_\n\t\t)\n\t}\n}\n","import {\n\tIProduceWithPatches,\n\tIProduce,\n\tImmerState,\n\tDrafted,\n\tisDraftable,\n\tprocessResult,\n\tPatch,\n\tObjectish,\n\tDRAFT_STATE,\n\tDraft,\n\tPatchListener,\n\tisDraft,\n\tisMap,\n\tisSet,\n\tcreateProxyProxy,\n\tgetPlugin,\n\tdie,\n\tenterScope,\n\trevokeScope,\n\tleaveScope,\n\tusePatchesInScope,\n\tgetCurrentScope,\n\tNOTHING,\n\tfreeze,\n\tcurrent,\n\tImmerScope,\n\tregisterChildFinalizationCallback,\n\tArchType,\n\tMapSetPlugin,\n\tAnyMap,\n\tAnySet,\n\tisObjectish,\n\tisFunction,\n\tisBoolean,\n\tPluginMapSet,\n\tPluginPatches\n} from \"../internal\"\n\ninterface ProducersFns {\n\tproduce: IProduce\n\tproduceWithPatches: IProduceWithPatches\n}\n\nexport type StrictMode = boolean | \"class_only\"\n\nexport class Immer implements ProducersFns {\n\tautoFreeze_: boolean = true\n\tuseStrictShallowCopy_: StrictMode = false\n\tuseStrictIteration_: boolean = false\n\n\tconstructor(config?: {\n\t\tautoFreeze?: boolean\n\t\tuseStrictShallowCopy?: StrictMode\n\t\tuseStrictIteration?: boolean\n\t}) {\n\t\tif (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config!.autoFreeze)\n\t\tif (isBoolean(config?.useStrictShallowCopy))\n\t\t\tthis.setUseStrictShallowCopy(config!.useStrictShallowCopy)\n\t\tif (isBoolean(config?.useStrictIteration))\n\t\t\tthis.setUseStrictIteration(config!.useStrictIteration)\n\t}\n\n\t/**\n\t * The `produce` function takes a value and a \"recipe function\" (whose\n\t * return value often depends on the base state). The recipe function is\n\t * free to mutate its first argument however it wants. All mutations are\n\t * only ever applied to a __copy__ of the base state.\n\t *\n\t * Pass only a function to create a \"curried producer\" which relieves you\n\t * from passing the recipe function every time.\n\t *\n\t * Only plain objects and arrays are made mutable. All other objects are\n\t * considered uncopyable.\n\t *\n\t * Note: This function is __bound__ to its `Immer` instance.\n\t *\n\t * @param {any} base - the initial state\n\t * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n\t * @param {Function} patchListener - optional function that will be called with all the patches produced here\n\t * @returns {any} a new state, or the initial state if nothing was modified\n\t */\n\tproduce: IProduce = (base: any, recipe?: any, patchListener?: any) => {\n\t\t// curried invocation\n\t\tif (isFunction(base) && !isFunction(recipe)) {\n\t\t\tconst defaultBase = recipe\n\t\t\trecipe = base\n\n\t\t\tconst self = this\n\t\t\treturn function curriedProduce(\n\t\t\t\tthis: any,\n\t\t\t\tbase = defaultBase,\n\t\t\t\t...args: any[]\n\t\t\t) {\n\t\t\t\treturn self.produce(base, (draft: Drafted) => recipe.call(this, draft, ...args)) // prettier-ignore\n\t\t\t}\n\t\t}\n\n\t\tif (!isFunction(recipe)) die(6)\n\t\tif (patchListener !== undefined && !isFunction(patchListener)) die(7)\n\n\t\tlet result\n\n\t\t// Only plain objects, arrays, and \"immerable classes\" are drafted.\n\t\tif (isDraftable(base)) {\n\t\t\tconst scope = enterScope(this)\n\t\t\tconst proxy = createProxy(scope, base, undefined)\n\t\t\tlet hasError = true\n\t\t\ttry {\n\t\t\t\tresult = recipe(proxy)\n\t\t\t\thasError = false\n\t\t\t} finally {\n\t\t\t\t// finally instead of catch + rethrow better preserves original stack\n\t\t\t\tif (hasError) revokeScope(scope)\n\t\t\t\telse leaveScope(scope)\n\t\t\t}\n\t\t\tusePatchesInScope(scope, patchListener)\n\t\t\treturn processResult(result, scope)\n\t\t} else if (!base || !isObjectish(base)) {\n\t\t\tresult = recipe(base)\n\t\t\tif (result === undefined) result = base\n\t\t\tif (result === NOTHING) result = undefined\n\t\t\tif (this.autoFreeze_) freeze(result, true)\n\t\t\tif (patchListener) {\n\t\t\t\tconst p: Patch[] = []\n\t\t\t\tconst ip: Patch[] = []\n\t\t\t\tgetPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n\t\t\t\t\tpatches_: p,\n\t\t\t\t\tinversePatches_: ip\n\t\t\t\t} as ImmerScope) // dummy scope\n\t\t\t\tpatchListener(p, ip)\n\t\t\t}\n\t\t\treturn result\n\t\t} else die(1, base)\n\t}\n\n\tproduceWithPatches: IProduceWithPatches = (base: any, recipe?: any): any => {\n\t\t// curried invocation\n\t\tif (isFunction(base)) {\n\t\t\treturn (state: any, ...args: any[]) =>\n\t\t\t\tthis.produceWithPatches(state, (draft: any) => base(draft, ...args))\n\t\t}\n\n\t\tlet patches: Patch[], inversePatches: Patch[]\n\t\tconst result = this.produce(base, recipe, (p: Patch[], ip: Patch[]) => {\n\t\t\tpatches = p\n\t\t\tinversePatches = ip\n\t\t})\n\t\treturn [result, patches!, inversePatches!]\n\t}\n\n\tcreateDraft(base: T): Draft {\n\t\tif (!isDraftable(base)) die(8)\n\t\tif (isDraft(base)) base = current(base)\n\t\tconst scope = enterScope(this)\n\t\tconst proxy = createProxy(scope, base, undefined)\n\t\tproxy[DRAFT_STATE].isManual_ = true\n\t\tleaveScope(scope)\n\t\treturn proxy as any\n\t}\n\n\tfinishDraft>(\n\t\tdraft: D,\n\t\tpatchListener?: PatchListener\n\t): D extends Draft ? T : never {\n\t\tconst state: ImmerState = draft && (draft as any)[DRAFT_STATE]\n\t\tif (!state || !state.isManual_) die(9)\n\t\tconst {scope_: scope} = state\n\t\tusePatchesInScope(scope, patchListener)\n\t\treturn processResult(undefined, scope)\n\t}\n\n\t/**\n\t * Pass true to automatically freeze all copies created by Immer.\n\t *\n\t * By default, auto-freezing is enabled.\n\t */\n\tsetAutoFreeze(value: boolean) {\n\t\tthis.autoFreeze_ = value\n\t}\n\n\t/**\n\t * Pass true to enable strict shallow copy.\n\t *\n\t * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n\t */\n\tsetUseStrictShallowCopy(value: StrictMode) {\n\t\tthis.useStrictShallowCopy_ = value\n\t}\n\n\t/**\n\t * Pass false to use faster iteration that skips non-enumerable properties\n\t * but still handles symbols for compatibility.\n\t *\n\t * By default, strict iteration is enabled (includes all own properties).\n\t */\n\tsetUseStrictIteration(value: boolean) {\n\t\tthis.useStrictIteration_ = value\n\t}\n\n\tshouldUseStrictIteration(): boolean {\n\t\treturn this.useStrictIteration_\n\t}\n\n\tapplyPatches(base: T, patches: readonly Patch[]): T {\n\t\t// If a patch replaces the entire state, take that replacement as base\n\t\t// before applying patches\n\t\tlet i: number\n\t\tfor (i = patches.length - 1; i >= 0; i--) {\n\t\t\tconst patch = patches[i]\n\t\t\tif (patch.path.length === 0 && patch.op === \"replace\") {\n\t\t\t\tbase = patch.value\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t// If there was a patch that replaced the entire state, start from the\n\t\t// patch after that.\n\t\tif (i > -1) {\n\t\t\tpatches = patches.slice(i + 1)\n\t\t}\n\n\t\tconst applyPatchesImpl = getPlugin(PluginPatches).applyPatches_\n\t\tif (isDraft(base)) {\n\t\t\t// N.B: never hits if some patch a replacement, patches are never drafts\n\t\t\treturn applyPatchesImpl(base, patches)\n\t\t}\n\t\t// Otherwise, produce a copy of the base state.\n\t\treturn this.produce(base, (draft: Drafted) =>\n\t\t\tapplyPatchesImpl(draft, patches)\n\t\t)\n\t}\n}\n\nexport function createProxy(\n\trootScope: ImmerScope,\n\tvalue: T,\n\tparent?: ImmerState,\n\tkey?: string | number | symbol\n): Drafted {\n\t// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft\n\t// returning a tuple here lets us skip a proxy access\n\t// to DRAFT_STATE later\n\tconst [draft, state] = isMap(value)\n\t\t? getPlugin(PluginMapSet).proxyMap_(value, parent)\n\t\t: isSet(value)\n\t\t? getPlugin(PluginMapSet).proxySet_(value, parent)\n\t\t: createProxyProxy(value, parent)\n\n\tconst scope = parent?.scope_ ?? getCurrentScope()\n\tscope.drafts_.push(draft)\n\n\t// Ensure the parent callbacks are passed down so we actually\n\t// track all callbacks added throughout the tree\n\tstate.callbacks_ = parent?.callbacks_ ?? []\n\tstate.key_ = key\n\n\tif (parent && key !== undefined) {\n\t\tregisterChildFinalizationCallback(parent, state, key)\n\t} else {\n\t\t// It's a root draft, register it with the scope\n\t\tstate.callbacks_.push(function rootDraftCleanup(rootScope) {\n\t\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\t\tconst {patchPlugin_} = rootScope\n\n\t\t\tif (state.modified_ && patchPlugin_) {\n\t\t\t\tpatchPlugin_.generatePatches_(state, [], rootScope)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn draft as any\n}\n","import {\n\tdie,\n\tisDraft,\n\tshallowCopy,\n\teach,\n\tDRAFT_STATE,\n\tset,\n\tImmerState,\n\tisDraftable,\n\tisFrozen\n} from \"../internal\"\n\n/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */\nexport function current(value: T): T\nexport function current(value: any): any {\n\tif (!isDraft(value)) die(10, value)\n\treturn currentImpl(value)\n}\n\nfunction currentImpl(value: any): any {\n\tif (!isDraftable(value) || isFrozen(value)) return value\n\tconst state: ImmerState | undefined = value[DRAFT_STATE]\n\tlet copy: any\n\tlet strict = true // Default to strict for compatibility\n\tif (state) {\n\t\tif (!state.modified_) return state.base_\n\t\t// Optimization: avoid generating new drafts during copying\n\t\tstate.finalized_ = true\n\t\tcopy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)\n\t\tstrict = state.scope_.immer_.shouldUseStrictIteration()\n\t} else {\n\t\tcopy = shallowCopy(value, true)\n\t}\n\t// recurse\n\teach(\n\t\tcopy,\n\t\t(key, childValue) => {\n\t\t\tset(copy, key, currentImpl(childValue))\n\t\t},\n\t\tstrict\n\t)\n\tif (state) {\n\t\tstate.finalized_ = false\n\t}\n\treturn copy\n}\n","import {immerable} from \"../immer\"\nimport {\n\tImmerState,\n\tPatch,\n\tSetState,\n\tProxyArrayState,\n\tMapState,\n\tProxyObjectState,\n\tPatchPath,\n\tget,\n\teach,\n\thas,\n\tgetArchtype,\n\tgetPrototypeOf,\n\tisSet,\n\tisMap,\n\tloadPlugin,\n\tArchType,\n\tdie,\n\tisDraft,\n\tisDraftable,\n\tNOTHING,\n\terrors,\n\tDRAFT_STATE,\n\tgetProxyDraft,\n\tImmerScope,\n\tisObjectish,\n\tisFunction,\n\tCONSTRUCTOR,\n\tPluginPatches,\n\tisArray,\n\tPROTOTYPE\n} from \"../internal\"\n\nexport function enablePatches() {\n\tconst errorOffset = 16\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\terrors.push(\n\t\t\t'Sets cannot have \"replace\" patches.',\n\t\t\tfunction(op: string) {\n\t\t\t\treturn \"Unsupported patch operation: \" + op\n\t\t\t},\n\t\t\tfunction(path: string) {\n\t\t\t\treturn \"Cannot apply patch, path doesn't resolve: \" + path\n\t\t\t},\n\t\t\t\"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n\t\t)\n\t}\n\n\tfunction getPath(state: ImmerState, path: PatchPath = []): PatchPath | null {\n\t\t// Step 1: Check if state has a stored key\n\t\tif (\"key_\" in state && state.key_ !== undefined) {\n\t\t\t// Step 2: Validate the key is still valid in parent\n\n\t\t\tconst parentCopy = state.parent_!.copy_ ?? state.parent_!.base_\n\t\t\tconst proxyDraft = getProxyDraft(get(parentCopy, state.key_!))\n\t\t\tconst valueAtKey = get(parentCopy, state.key_!)\n\n\t\t\tif (valueAtKey === undefined) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\t// Check if the value at the key is still related to this draft\n\t\t\t// It should be either the draft itself, the base, or the copy\n\t\t\tif (\n\t\t\t\tvalueAtKey !== state.draft_ &&\n\t\t\t\tvalueAtKey !== state.base_ &&\n\t\t\t\tvalueAtKey !== state.copy_\n\t\t\t) {\n\t\t\t\treturn null // Value was replaced with something else\n\t\t\t}\n\t\t\tif (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n\t\t\t\treturn null // Different draft\n\t\t\t}\n\n\t\t\t// Step 3: Handle Set case specially\n\t\t\tconst isSet = state.parent_!.type_ === ArchType.Set\n\t\t\tlet key: string | number\n\n\t\t\tif (isSet) {\n\t\t\t\t// For Sets, find the index in the drafts_ map\n\t\t\t\tconst setParent = state.parent_ as SetState\n\t\t\t\tkey = Array.from(setParent.drafts_.keys()).indexOf(state.key_)\n\t\t\t} else {\n\t\t\t\tkey = state.key_ as string | number\n\t\t\t}\n\n\t\t\t// Step 4: Validate key still exists in parent\n\t\t\tif (!((isSet && parentCopy.size > key) || has(parentCopy, key))) {\n\t\t\t\treturn null // Key deleted\n\t\t\t}\n\n\t\t\t// Step 5: Add key to path\n\t\t\tpath.push(key)\n\t\t}\n\n\t\t// Step 6: Recurse to parent if exists\n\t\tif (state.parent_) {\n\t\t\treturn getPath(state.parent_, path)\n\t\t}\n\n\t\t// Step 7: At root - reverse path and validate\n\t\tpath.reverse()\n\n\t\ttry {\n\t\t\t// Validate path can be resolved from ROOT\n\t\t\tresolvePath(state.copy_, path)\n\t\t} catch (e) {\n\t\t\treturn null // Path invalid\n\t\t}\n\n\t\treturn path\n\t}\n\n\t// NEW: Add resolvePath helper function\n\tfunction resolvePath(base: any, path: PatchPath): any {\n\t\tlet current = base\n\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\tconst key = path[i]\n\t\t\tcurrent = get(current, key)\n\t\t\tif (!isObjectish(current) || current === null) {\n\t\t\t\tthrow new Error(`Cannot resolve path at '${path.join(\"/\")}'`)\n\t\t\t}\n\t\t}\n\t\treturn current\n\t}\n\n\tconst REPLACE = \"replace\"\n\tconst ADD = \"add\"\n\tconst REMOVE = \"remove\"\n\n\tfunction generatePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\tscope: ImmerScope\n\t): void {\n\t\tif (state.scope_.processedForPatches_.has(state)) {\n\t\t\treturn\n\t\t}\n\n\t\tstate.scope_.processedForPatches_.add(state)\n\n\t\tconst {patches_, inversePatches_} = scope\n\n\t\tswitch (state.type_) {\n\t\t\tcase ArchType.Object:\n\t\t\tcase ArchType.Map:\n\t\t\t\treturn generatePatchesFromAssigned(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Array:\n\t\t\t\treturn generateArrayPatches(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Set:\n\t\t\t\treturn generateSetPatches(\n\t\t\t\t\t(state as any) as SetState,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t}\n\t}\n\n\tfunction generateArrayPatches(\n\t\tstate: ProxyArrayState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, assigned_} = state\n\t\tlet copy_ = state.copy_!\n\n\t\t// Reduce complexity by ensuring `base` is never longer.\n\t\tif (copy_.length < base_.length) {\n\t\t\t// @ts-ignore\n\t\t\t;[base_, copy_] = [copy_, base_]\n\t\t\t;[patches, inversePatches] = [inversePatches, patches]\n\t\t}\n\n\t\tconst allReassigned = state.allIndicesReassigned_ === true\n\n\t\t// Process replaced indices.\n\t\tfor (let i = 0; i < base_.length; i++) {\n\t\t\tconst copiedItem = copy_[i]\n\t\t\tconst baseItem = base_[i]\n\n\t\t\tconst isAssigned = allReassigned || assigned_?.get(i.toString())\n\t\t\tif (isAssigned && copiedItem !== baseItem) {\n\t\t\t\tconst childState = copiedItem?.[DRAFT_STATE]\n\t\t\t\tif (childState && childState.modified_) {\n\t\t\t\t\t// Skip - let the child generate its own patches\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(copiedItem)\n\t\t\t\t})\n\t\t\t\tinversePatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(baseItem)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Process added indices.\n\t\tfor (let i = base_.length; i < copy_.length; i++) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tpatches.push({\n\t\t\t\top: ADD,\n\t\t\t\tpath,\n\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\tvalue: clonePatchValueIfNeeded(copy_[i])\n\t\t\t})\n\t\t}\n\t\tfor (let i = copy_.length - 1; base_.length <= i; --i) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tinversePatches.push({\n\t\t\t\top: REMOVE,\n\t\t\t\tpath\n\t\t\t})\n\t\t}\n\t}\n\n\t// This is used for both Map objects and normal objects.\n\tfunction generatePatchesFromAssigned(\n\t\tstate: MapState | ProxyObjectState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tconst {base_, copy_, type_} = state\n\t\teach(state.assigned_!, (key, assignedValue) => {\n\t\t\tconst origValue = get(base_, key, type_)\n\t\t\tconst value = get(copy_!, key, type_)\n\t\t\tconst op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD\n\t\t\tif (origValue === value && op === REPLACE) return\n\t\t\tconst path = basePath.concat(key as any)\n\t\t\tpatches.push(\n\t\t\t\top === REMOVE\n\t\t\t\t\t? {op, path}\n\t\t\t\t\t: {op, path, value: clonePatchValueIfNeeded(value)}\n\t\t\t)\n\t\t\tinversePatches.push(\n\t\t\t\top === ADD\n\t\t\t\t\t? {op: REMOVE, path}\n\t\t\t\t\t: op === REMOVE\n\t\t\t\t\t? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t\t\t: {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t)\n\t\t})\n\t}\n\n\tfunction generateSetPatches(\n\t\tstate: SetState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, copy_} = state\n\n\t\tlet i = 0\n\t\tbase_.forEach((value: any) => {\n\t\t\tif (!copy_!.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t\ti = 0\n\t\tcopy_!.forEach((value: any) => {\n\t\t\tif (!base_.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t}\n\n\tfunction generateReplacementPatches_(\n\t\tbaseValue: any,\n\t\treplacement: any,\n\t\tscope: ImmerScope\n\t): void {\n\t\tconst {patches_, inversePatches_} = scope\n\t\tpatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: replacement === NOTHING ? undefined : replacement\n\t\t})\n\t\tinversePatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: baseValue\n\t\t})\n\t}\n\n\tfunction applyPatches_(draft: T, patches: readonly Patch[]): T {\n\t\tpatches.forEach(patch => {\n\t\t\tconst {path, op} = patch\n\n\t\t\tlet base: any = draft\n\t\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\t\tconst parentType = getArchtype(base)\n\t\t\t\tlet p = path[i]\n\t\t\t\tif (typeof p !== \"string\" && typeof p !== \"number\") {\n\t\t\t\t\tp = \"\" + p\n\t\t\t\t}\n\n\t\t\t\t// See #738, avoid prototype pollution\n\t\t\t\tif (\n\t\t\t\t\t(parentType === ArchType.Object || parentType === ArchType.Array) &&\n\t\t\t\t\t(p === \"__proto__\" || p === CONSTRUCTOR)\n\t\t\t\t)\n\t\t\t\t\tdie(errorOffset + 3)\n\t\t\t\tif (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3)\n\t\t\t\tbase = get(base, p)\n\t\t\t\tif (!isObjectish(base)) die(errorOffset + 2, path.join(\"/\"))\n\t\t\t}\n\n\t\t\tconst type = getArchtype(base)\n\t\t\tconst value = deepClonePatchValue(patch.value) // used to clone patch to ensure original patch is not modified, see #411\n\t\t\tconst key = path[path.length - 1]\n\t\t\tswitch (op) {\n\t\t\t\tcase REPLACE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\tdie(errorOffset)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t// if value is an object, then it's assigned by reference\n\t\t\t\t\t\t\t// in the following add or remove ops, the value field inside the patch will also be modifyed\n\t\t\t\t\t\t\t// so we use value from the cloned patch\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase ADD:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn key === \"-\"\n\t\t\t\t\t\t\t\t? base.push(value)\n\t\t\t\t\t\t\t\t: base.splice(key as any, 0, value)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.add(value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase REMOVE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn base.splice(key as any, 1)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.delete(key)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.delete(patch.value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn delete base[key]\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tdie(errorOffset + 1, op)\n\t\t\t}\n\t\t})\n\n\t\treturn draft\n\t}\n\n\t// optimize: this is quite a performance hit, can we detect intelligently when it is needed?\n\t// E.g. auto-draft when new objects from outside are assigned and modified?\n\t// (See failing test when deepClone just returns obj)\n\tfunction deepClonePatchValue(obj: T): T\n\tfunction deepClonePatchValue(obj: any) {\n\t\tif (!isDraftable(obj)) return obj\n\t\tif (isArray(obj)) return obj.map(deepClonePatchValue)\n\t\tif (isMap(obj))\n\t\t\treturn new Map(\n\t\t\t\tArray.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n\t\t\t)\n\t\tif (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue))\n\t\tconst cloned = Object.create(getPrototypeOf(obj))\n\t\tfor (const key in obj) cloned[key] = deepClonePatchValue(obj[key])\n\t\tif (has(obj, immerable)) cloned[immerable] = obj[immerable]\n\t\treturn cloned\n\t}\n\n\tfunction clonePatchValueIfNeeded(obj: T): T {\n\t\tif (isDraft(obj)) {\n\t\t\treturn deepClonePatchValue(obj)\n\t\t} else return obj\n\t}\n\n\tloadPlugin(PluginPatches, {\n\t\tapplyPatches_,\n\t\tgeneratePatches_,\n\t\tgenerateReplacementPatches_,\n\t\tgetPath\n\t})\n}\n","// types only!\nimport {\n\tImmerState,\n\tAnyMap,\n\tAnySet,\n\tMapState,\n\tSetState,\n\tDRAFT_STATE,\n\tgetCurrentScope,\n\tlatest,\n\tisDraftable,\n\tcreateProxy,\n\tloadPlugin,\n\tmarkChanged,\n\tdie,\n\tArchType,\n\teach,\n\tgetValue,\n\tPluginMapSet\n} from \"../internal\"\n\nexport function enableMapSet() {\n\tclass DraftMap extends Map {\n\t\t[DRAFT_STATE]: MapState\n\n\t\tconstructor(target: AnyMap, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Map,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this as any,\n\t\t\t\tisManual_: false,\n\t\t\t\trevoked_: false,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(key: any): boolean {\n\t\t\treturn latest(this[DRAFT_STATE]).has(key)\n\t\t}\n\n\t\tset(key: any, value: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!latest(state).has(key) || latest(state).get(key) !== value) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t\tstate.copy_!.set(key, value)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(key: any): boolean {\n\t\t\tif (!this.has(key)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareMapCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\tif (state.base_.has(key)) {\n\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t} else {\n\t\t\t\tstate.assigned_!.delete(key)\n\t\t\t}\n\t\t\tstate.copy_!.delete(key)\n\t\t\treturn true\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_ = new Map()\n\t\t\t\teach(state.base_, key => {\n\t\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t\t})\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tforEach(cb: (value: any, key: any, self: any) => void, thisArg?: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tlatest(state).forEach((_value: any, key: any, _map: any) => {\n\t\t\t\tcb.call(thisArg, this.get(key), key, this)\n\t\t\t})\n\t\t}\n\n\t\tget(key: any): any {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tconst value = latest(state).get(key)\n\t\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\t\treturn value\n\t\t\t}\n\t\t\tif (value !== state.base_.get(key)) {\n\t\t\t\treturn value // either already drafted or reassigned\n\t\t\t}\n\t\t\t// despite what it looks, this creates a draft only once, see above condition\n\t\t\tconst draft = createProxy(state.scope_, value, state, key)\n\t\t\tprepareMapCopy(state)\n\t\t\tstate.copy_!.set(key, draft)\n\t\t\treturn draft\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn latest(this[DRAFT_STATE]).keys()\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.values(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.entries(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue: [r.value, value]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.entries()\n\t\t}\n\t}\n\n\tfunction proxyMap_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, MapState] {\n\t\t// @ts-ignore\n\t\tconst map = new DraftMap(target, parent)\n\t\treturn [map as any, map[DRAFT_STATE]]\n\t}\n\n\tfunction prepareMapCopy(state: MapState) {\n\t\tif (!state.copy_) {\n\t\t\tstate.assigned_ = new Map()\n\t\t\tstate.copy_ = new Map(state.base_)\n\t\t}\n\t}\n\n\tclass DraftSet extends Set {\n\t\t[DRAFT_STATE]: SetState\n\t\tconstructor(target: AnySet, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Set,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this,\n\t\t\t\tdrafts_: new Map(),\n\t\t\t\trevoked_: false,\n\t\t\t\tisManual_: false,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(value: any): boolean {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\t// bit of trickery here, to be able to recognize both the value, and the draft of its value\n\t\t\tif (!state.copy_) {\n\t\t\t\treturn state.base_.has(value)\n\t\t\t}\n\t\t\tif (state.copy_.has(value)) return true\n\t\t\tif (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n\t\t\t\treturn true\n\t\t\treturn false\n\t\t}\n\n\t\tadd(value: any): any {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!this.has(value)) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.add(value)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(value: any): any {\n\t\t\tif (!this.has(value)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\treturn (\n\t\t\t\tstate.copy_!.delete(value) ||\n\t\t\t\t(state.drafts_.has(value)\n\t\t\t\t\t? state.copy_!.delete(state.drafts_.get(value))\n\t\t\t\t\t: /* istanbul ignore next */ false)\n\t\t\t)\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.values()\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.entries()\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn this.values()\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.values()\n\t\t}\n\n\t\tforEach(cb: any, thisArg?: any) {\n\t\t\tconst iterator = this.values()\n\t\t\tlet result = iterator.next()\n\t\t\twhile (!result.done) {\n\t\t\t\tcb.call(thisArg, result.value, result.value, this)\n\t\t\t\tresult = iterator.next()\n\t\t\t}\n\t\t}\n\t}\n\tfunction proxySet_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, SetState] {\n\t\t// @ts-ignore\n\t\tconst set = new DraftSet(target, parent)\n\t\treturn [set as any, set[DRAFT_STATE]]\n\t}\n\n\tfunction prepareSetCopy(state: SetState) {\n\t\tif (!state.copy_) {\n\t\t\t// create drafts for all entries to preserve insertion order\n\t\t\tstate.copy_ = new Set()\n\t\t\tstate.base_.forEach(value => {\n\t\t\t\tif (isDraftable(value)) {\n\t\t\t\t\tconst draft = createProxy(state.scope_, value, state, value)\n\t\t\t\t\tstate.drafts_.set(value, draft)\n\t\t\t\t\tstate.copy_!.add(draft)\n\t\t\t\t} else {\n\t\t\t\t\tstate.copy_!.add(value)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n\n\tfunction assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {\n\t\tif (state.revoked_) die(3, JSON.stringify(latest(state)))\n\t}\n\n\tfunction fixSetContents(target: ImmerState) {\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\tif (target.type_ === ArchType.Set && target.copy_) {\n\t\t\tconst copy = new Set(target.copy_)\n\t\t\ttarget.copy_.clear()\n\t\t\tcopy.forEach(value => {\n\t\t\t\ttarget.copy_!.add(getValue(value))\n\t\t\t})\n\t\t}\n\t}\n\n\tloadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents})\n}\n","import {\n\tPluginArrayMethods,\n\tlatest,\n\tloadPlugin,\n\tmarkChanged,\n\tprepareCopy,\n\tProxyArrayState\n} from \"../internal\"\n\n/**\n * Methods that directly modify the array in place.\n * These operate on the copy without creating per-element proxies:\n * - `push`, `pop`: Add/remove from end\n * - `shift`, `unshift`: Add/remove from start (marks all indices reassigned)\n * - `splice`: Add/remove at arbitrary position (marks all indices reassigned)\n * - `reverse`, `sort`: Reorder elements (marks all indices reassigned)\n */\ntype MutatingArrayMethod =\n\t| \"push\"\n\t| \"pop\"\n\t| \"shift\"\n\t| \"unshift\"\n\t| \"splice\"\n\t| \"reverse\"\n\t| \"sort\"\n\n/**\n * Methods that read from the array without modifying it.\n * These fall into distinct categories based on return semantics:\n *\n * **Subset operations** (return drafts - mutations propagate):\n * - `filter`, `slice`: Return array of draft proxies\n * - `find`, `findLast`: Return single draft proxy or undefined\n *\n * **Transform operations** (return base values - mutations don't track):\n * - `concat`, `flat`: Create new structures, not subsets of original\n *\n * **Primitive-returning** (no draft needed):\n * - `findIndex`, `findLastIndex`, `indexOf`, `lastIndexOf`: Return numbers\n * - `some`, `every`, `includes`: Return booleans\n * - `join`, `toString`, `toLocaleString`: Return strings\n */\ntype NonMutatingArrayMethod =\n\t| \"filter\"\n\t| \"slice\"\n\t| \"concat\"\n\t| \"flat\"\n\t| \"find\"\n\t| \"findIndex\"\n\t| \"findLast\"\n\t| \"findLastIndex\"\n\t| \"some\"\n\t| \"every\"\n\t| \"indexOf\"\n\t| \"lastIndexOf\"\n\t| \"includes\"\n\t| \"join\"\n\t| \"toString\"\n\t| \"toLocaleString\"\n\n/** Union of all array operation methods handled by the plugin. */\nexport type ArrayOperationMethod = MutatingArrayMethod | NonMutatingArrayMethod\n\n/**\n * Enables optimized array method handling for Immer drafts.\n *\n * This plugin overrides array methods to avoid unnecessary Proxy creation during iteration,\n * significantly improving performance for array-heavy operations.\n *\n * **Mutating methods** (push, pop, shift, unshift, splice, sort, reverse):\n * Operate directly on the copy without creating per-element proxies.\n *\n * **Non-mutating methods** fall into categories:\n * - **Subset operations** (filter, slice, find, findLast): Return draft proxies - mutations track\n * - **Transform operations** (concat, flat): Return base values - mutations don't track\n * - **Primitive-returning** (indexOf, includes, some, every, etc.): Return primitives\n *\n * **Important**: Callbacks for overridden methods receive base values, not drafts.\n * This is the core performance optimization.\n *\n * @example\n * ```ts\n * import { enableArrayMethods, produce } from \"immer\"\n *\n * enableArrayMethods()\n *\n * const next = produce(state, draft => {\n * // Optimized - no proxy creation per element\n * draft.items.sort((a, b) => a.value - b.value)\n *\n * // filter returns drafts - mutations propagate\n * const filtered = draft.items.filter(x => x.value > 5)\n * filtered[0].value = 999 // Affects draft.items[originalIndex]\n * })\n * ```\n *\n * @see https://immerjs.github.io/immer/array-methods\n */\nexport function enableArrayMethods() {\n\tconst SHIFTING_METHODS = new Set([\"shift\", \"unshift\"])\n\n\tconst QUEUE_METHODS = new Set([\"push\", \"pop\"])\n\n\tconst RESULT_RETURNING_METHODS = new Set([\n\t\t...QUEUE_METHODS,\n\t\t...SHIFTING_METHODS\n\t])\n\n\tconst REORDERING_METHODS = new Set([\"reverse\", \"sort\"])\n\n\t// Optimized method detection using array-based lookup\n\tconst MUTATING_METHODS = new Set([\n\t\t...RESULT_RETURNING_METHODS,\n\t\t...REORDERING_METHODS,\n\t\t\"splice\"\n\t])\n\n\tconst FIND_METHODS = new Set([\"find\", \"findLast\"])\n\n\tconst NON_MUTATING_METHODS = new Set([\n\t\t\"filter\",\n\t\t\"slice\",\n\t\t\"concat\",\n\t\t\"flat\",\n\t\t...FIND_METHODS,\n\t\t\"findIndex\",\n\t\t\"findLastIndex\",\n\t\t\"some\",\n\t\t\"every\",\n\t\t\"indexOf\",\n\t\t\"lastIndexOf\",\n\t\t\"includes\",\n\t\t\"join\",\n\t\t\"toString\",\n\t\t\"toLocaleString\"\n\t])\n\n\t// Type guard for method detection\n\tfunction isMutatingArrayMethod(\n\t\tmethod: string\n\t): method is MutatingArrayMethod {\n\t\treturn MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isNonMutatingArrayMethod(\n\t\tmethod: string\n\t): method is NonMutatingArrayMethod {\n\t\treturn NON_MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isArrayOperationMethod(\n\t\tmethod: string\n\t): method is ArrayOperationMethod {\n\t\treturn isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method)\n\t}\n\n\tfunction enterOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: ArrayOperationMethod\n\t) {\n\t\tstate.operationMethod = method\n\t}\n\n\tfunction exitOperation(state: ProxyArrayState) {\n\t\tstate.operationMethod = undefined\n\t}\n\n\t// Shared utility functions for array method handlers\n\tfunction executeArrayMethod(\n\t\tstate: ProxyArrayState,\n\t\toperation: () => T,\n\t\tmarkLength = true\n\t): T {\n\t\tprepareCopy(state)\n\t\tconst result = operation()\n\t\tmarkChanged(state)\n\t\tif (markLength) state.assigned_!.set(\"length\", true)\n\t\treturn result\n\t}\n\n\tfunction markAllIndicesReassigned(state: ProxyArrayState) {\n\t\tstate.allIndicesReassigned_ = true\n\t}\n\n\tfunction normalizeSliceIndex(index: number, length: number): number {\n\t\tif (index < 0) {\n\t\t\treturn Math.max(length + index, 0)\n\t\t}\n\t\treturn Math.min(index, length)\n\t}\n\n\t/**\n\t * Handles mutating operations that add/remove elements (push, pop, shift, unshift, splice).\n\t *\n\t * Operates directly on `state.copy_` without creating per-element proxies.\n\t * For shifting methods (shift, unshift), marks all indices as reassigned since\n\t * indices shift.\n\t *\n\t * @returns For push/pop/shift/unshift: the native method result. For others: the draft.\n\t */\n\tfunction handleSimpleOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(state, () => {\n\t\t\tconst result = (state.copy_! as any)[method](...args)\n\n\t\t\t// Handle index reassignment for shifting methods\n\t\t\tif (SHIFTING_METHODS.has(method as MutatingArrayMethod)) {\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t}\n\n\t\t\t// Return appropriate value based on method\n\t\t\treturn RESULT_RETURNING_METHODS.has(method as MutatingArrayMethod)\n\t\t\t\t? result\n\t\t\t\t: state.draft_\n\t\t})\n\t}\n\n\t/**\n\t * Handles reordering operations (reverse, sort) that change element order.\n\t *\n\t * Operates directly on `state.copy_` and marks all indices as reassigned\n\t * since element positions change. Does not mark length as changed since\n\t * these operations preserve array length.\n\t *\n\t * @returns The draft proxy for method chaining.\n\t */\n\tfunction handleReorderingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(\n\t\t\tstate,\n\t\t\t() => {\n\t\t\t\t;(state.copy_! as any)[method](...args)\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\treturn state.draft_\n\t\t\t},\n\t\t\tfalse\n\t\t) // Don't mark length as changed\n\t}\n\n\t/**\n\t * Creates an interceptor function for a specific array method.\n\t *\n\t * The interceptor wraps array method calls to:\n\t * 1. Set `state.operationMethod` flag during execution (allows proxy `get` trap\n\t * to detect we're inside an optimized method and skip proxy creation)\n\t * 2. Route to appropriate handler based on method type\n\t * 3. Clean up the operation flag in `finally` block\n\t *\n\t * The `operationMethod` flag is the key mechanism that enables the proxy's `get`\n\t * trap to return base values instead of creating nested proxies during iteration.\n\t *\n\t * @param state - The proxy array state\n\t * @param originalMethod - Name of the array method being intercepted\n\t * @returns Interceptor function that handles the method call\n\t */\n\tfunction createMethodInterceptor(\n\t\tstate: ProxyArrayState,\n\t\toriginalMethod: string\n\t) {\n\t\treturn function interceptedMethod(...args: any[]) {\n\t\t\t// Enter operation mode - this flag tells the proxy's get trap to return\n\t\t\t// base values instead of creating nested proxies during iteration\n\t\t\tconst method = originalMethod as ArrayOperationMethod\n\t\t\tenterOperation(state, method)\n\n\t\t\ttry {\n\t\t\t\t// Check if this is a mutating method\n\t\t\t\tif (isMutatingArrayMethod(method)) {\n\t\t\t\t\t// Direct method dispatch - no configuration lookup needed\n\t\t\t\t\tif (RESULT_RETURNING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleSimpleOperation(state, method, args)\n\t\t\t\t\t}\n\t\t\t\t\tif (REORDERING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleReorderingOperation(state, method, args)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"splice\") {\n\t\t\t\t\t\tconst res = executeArrayMethod(state, () =>\n\t\t\t\t\t\t\tstate.copy_!.splice(...(args as [number, number, ...any[]]))\n\t\t\t\t\t\t)\n\t\t\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\t\t\treturn res\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Handle non-mutating methods\n\t\t\t\t\treturn handleNonMutatingOperation(state, method, args)\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\t// Always exit operation mode - must be in finally to handle exceptions\n\t\t\t\texitOperation(state)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles non-mutating array methods with different return semantics.\n\t *\n\t * **Subset operations** return draft proxies for mutation tracking:\n\t * - `filter`, `slice`: Return `state.draft_[i]` for each selected element\n\t * - `find`, `findLast`: Return `state.draft_[i]` for the found element\n\t *\n\t * This allows mutations on returned elements to propagate back to the draft:\n\t * ```ts\n\t * const filtered = draft.items.filter(x => x.value > 5)\n\t * filtered[0].value = 999 // Mutates draft.items[originalIndex]\n\t * ```\n\t *\n\t * **Transform operations** return base values (no draft tracking):\n\t * - `concat`, `flat`: These create NEW arrays rather than selecting subsets.\n\t * Since the result structure differs from the original, tracking mutations\n\t * back to specific draft indices would be impractical/impossible.\n\t *\n\t * **Primitive operations** return the native result directly:\n\t * - `indexOf`, `includes`, `some`, `every`, `join`, etc.\n\t *\n\t * @param state - The proxy array state\n\t * @param method - The non-mutating method name\n\t * @param args - Arguments passed to the method\n\t * @returns Drafts for subset operations, base values for transforms, primitives otherwise\n\t */\n\tfunction handleNonMutatingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: NonMutatingArrayMethod,\n\t\targs: any[]\n\t) {\n\t\tconst source = latest(state)\n\n\t\t// Methods that return arrays with selected items - need to return drafts\n\t\tif (method === \"filter\") {\n\t\t\tconst predicate = args[0]\n\t\t\tconst result: any[] = []\n\n\t\t\t// First pass: call predicate on base values to determine which items pass\n\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\t// Only create draft for items that passed the predicate\n\t\t\t\t\tresult.push(state.draft_[i])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\tif (FIND_METHODS.has(method)) {\n\t\t\tconst predicate = args[0]\n\t\t\tconst isForward = method === \"find\"\n\t\t\tconst step = isForward ? 1 : -1\n\t\t\tconst start = isForward ? 0 : source.length - 1\n\n\t\t\tfor (let i = start; i >= 0 && i < source.length; i += step) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\treturn state.draft_[i]\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (method === \"slice\") {\n\t\t\tconst rawStart = args[0] ?? 0\n\t\t\tconst rawEnd = args[1] ?? source.length\n\n\t\t\t// Normalize negative indices\n\t\t\tconst start = normalizeSliceIndex(rawStart, source.length)\n\t\t\tconst end = normalizeSliceIndex(rawEnd, source.length)\n\n\t\t\tconst result: any[] = []\n\n\t\t\t// Return drafts for items in the slice range\n\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\tresult.push(state.draft_[i])\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\t// For other methods, call on base array directly:\n\t\t// - indexOf, includes, join, toString: Return primitives, no draft needed\n\t\t// - concat, flat: Return NEW arrays (not subsets). Elements are base values.\n\t\t// This is intentional - concat/flat create new data structures rather than\n\t\t// selecting subsets of the original, making draft tracking impractical.\n\t\treturn source[method as keyof typeof Array.prototype](...args)\n\t}\n\n\tloadPlugin(PluginArrayMethods, {\n\t\tcreateMethodInterceptor,\n\t\tisArrayOperationMethod,\n\t\tisMutatingArrayMethod\n\t})\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,eAAAA;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,UAAyB,OAAO,IAAI,eAAe;AAUzD,IAAM,YAA2B,OAAO,IAAI,iBAAiB;AAE7D,IAAM,cAA6B,OAAO,IAAI,aAAa;;;ACf3D,IAAM,SACZ,QAAQ,IAAI,aAAa,eACtB;AAAA;AAAA,EAEA,SAAS,QAAgB;AACxB,WAAO,mBAAmB,yFAAyF;AAAA,EACpH;AAAA,EACA,SAA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,sBAAM,sBAAsB;AAAA,EAChF;AACD;AAOO,IAAM,eAA+B,sBAAM,aAAa,KAAK,KAAK;AAMlE,IAAM,cAA8B,sBAAM,YAAY,KAAK,KAAK;AAUhE,IAAM,cAA8B,sBAAM,YAAY,KAAK,KAAK;AAQhE,IAAI,YAAY,CAAI,UAAuB;AAO3C,IAAI,gBAAgB,CAAI,UAA2B;AAQnD,SAAS,UAAU,OAAyC;AAClE,SAAO,UAAU;AAClB;","names":["Immer","immer","current","Immer","base","rootScope","isSet","current","set","Immer"]} \ No newline at end of file diff --git a/dist/cjs/immer.cjs.production.js b/dist/cjs/immer.cjs.production.js new file mode 100644 index 00000000..116f710d --- /dev/null +++ b/dist/cjs/immer.cjs.production.js @@ -0,0 +1,1150 @@ +"use strict" +var be = Object.defineProperty +var Xe = Object.getOwnPropertyDescriptor +var Ze = Object.getOwnPropertyNames +var et = Object.prototype.hasOwnProperty +var tt = (e, t) => { + for (var r in t) be(e, r, {get: t[r], enumerable: !0}) + }, + rt = (e, t, r, n) => { + if ((t && typeof t == "object") || typeof t == "function") + for (let a of Ze(t)) + !et.call(e, a) && + a !== r && + be(e, a, { + get: () => t[a], + enumerable: !(n = Xe(t, a)) || n.enumerable + }) + return e + } +var nt = e => rt(be({}, "__esModule", {value: !0}), e) +var It = {} +tt(It, { + Immer: () => he, + applyPatches: () => mt, + castDraft: () => gt, + castImmutable: () => xt, + createDraft: () => St, + current: () => Me, + enableArrayMethods: () => Qe, + enableMapSet: () => Je, + enablePatches: () => Ye, + finishDraft: () => Pt, + freeze: () => J, + immerable: () => j, + isDraft: () => w, + isDraftable: () => D, + isNothing: () => At, + nothing: () => L, + original: () => ke, + produce: () => lt, + produceWithPatches: () => yt, + setAutoFreeze: () => dt, + setUseStrictIteration: () => ht, + setUseStrictShallowCopy: () => pt +}) +module.exports = nt(It) +var L = Symbol.for("immer-nothing"), + j = Symbol.for("immer-draftable"), + y = Symbol.for("immer-state") +function b(e, ...t) { + throw new Error( + `[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf` + ) +} +var F = Object, + V = F.getPrototypeOf, + te = "constructor", + re = "prototype", + Se = "configurable", + ce = "enumerable", + se = "writable", + ne = "value", + w = e => !!e && !!e[y] +function D(e) { + return e ? ze(e) || $(e) || !!e[j] || !!e[te]?.[j] || q(e) || Y(e) : !1 +} +var at = F[re][te].toString(), + Re = new WeakMap() +function ze(e) { + if (!e || !H(e)) return !1 + let t = V(e) + if (t === null || t === F[re]) return !0 + let r = F.hasOwnProperty.call(t, te) && t[te] + if (r === Object) return !0 + if (!B(r)) return !1 + let n = Re.get(r) + return ( + n === void 0 && ((n = Function.toString.call(r)), Re.set(r, n)), n === at + ) +} +function ke(e) { + return w(e) || b(15, e), e[y].t +} +function z(e, t, r = !0) { + K(e) === 0 + ? (r ? Reflect.ownKeys(e) : F.keys(e)).forEach(a => { + t(a, e[a], e) + }) + : e.forEach((n, a) => t(a, n, e)) +} +function K(e) { + let t = e[y] + return t ? t.r : $(e) ? 1 : q(e) ? 2 : Y(e) ? 3 : 0 +} +var G = (e, t, r = K(e)) => + r === 2 ? e.has(t) : F[re].hasOwnProperty.call(e, t), + U = (e, t, r = K(e)) => (r === 2 ? e.get(t) : e[t]), + ae = (e, t, r, n = K(e)) => { + n === 2 ? e.set(t, r) : n === 3 ? e.add(r) : (e[t] = r) + } +function Ue(e, t) { + return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t +} +var $ = Array.isArray, + q = e => e instanceof Map, + Y = e => e instanceof Set, + H = e => typeof e == "object", + B = e => typeof e == "function", + Pe = e => typeof e == "boolean" +function Le(e) { + let t = +e + return Number.isInteger(t) && String(t) === e +} +var Oe = e => (H(e) ? e?.[y] : null), + O = e => e.e || e.t, + je = e => { + let t = Oe(e) + return t ? t.e ?? t.t : e + }, + ge = e => (e.s ? e.e : e.t) +function fe(e, t) { + if (q(e)) return new Map(e) + if (Y(e)) return new Set(e) + if ($(e)) return Array[re].slice.call(e) + let r = ze(e) + if (t === !0 || (t === "class_only" && !r)) { + let n = F.getOwnPropertyDescriptors(e) + delete n[y] + let a = Reflect.ownKeys(n) + for (let i = 0; i < a.length; i++) { + let d = a[i], + S = n[d] + S[se] === !1 && ((S[se] = !0), (S[Se] = !0)), + (S.get || S.set) && + (n[d] = {[Se]: !0, [se]: !0, [ce]: S[ce], [ne]: e[d]}) + } + return F.create(V(e), n) + } else { + let n = V(e) + if (n !== null && r) return {...e} + let a = F.create(n) + return F.assign(a, e) + } +} +function J(e, t = !1) { + return ( + oe(e) || + w(e) || + !D(e) || + (K(e) > 1 && + F.defineProperties(e, {set: me, add: me, clear: me, delete: me}), + F.freeze(e), + t && + z( + e, + (r, n) => { + J(n, !0) + }, + !1 + )), + e + ) +} +function ot() { + b(2) +} +var me = {[ne]: ot} +function oe(e) { + return e === null || !H(e) ? !0 : F.isFrozen(e) +} +var W = "MapSet", + Q = "Patches", + le = "ArrayMethods", + xe = {} +function v(e) { + let t = xe[e] + return t || b(0, e), t +} +var De = e => !!xe[e] +function ie(e, t) { + xe[e] || (xe[e] = t) +} +var ye, + X = () => ye, + it = (e, t) => ({ + o: [], + i: e, + l: t, + F: !0, + m: 0, + A: new Set(), + T: new Set(), + I: De(W) ? v(W) : void 0, + E: De(le) ? v(le) : void 0 + }) +function _e(e, t) { + t && ((e.P = v(Q)), (e.p = []), (e.d = []), (e.C = t)) +} +function de(e) { + Ae(e), e.o.forEach(st), (e.o = null) +} +function Ae(e) { + e === ye && (ye = e.i) +} +var Ee = e => (ye = it(ye, e)) +function st(e) { + let t = e[y] + t.r === 0 || t.r === 1 ? t.b() : (t.x = !0) +} +function we(e, t) { + t.m = t.o.length + let r = t.o[0] + if (e !== void 0 && e !== r) { + r[y].s && (de(t), b(4)), D(e) && (e = Ve(t, e)) + let {P: a} = t + a && a.M(r[y].t, e, t) + } else e = Ve(t, r) + return ct(t, e, !0), de(t), t.p && t.C(t.p, t.d), e !== L ? e : void 0 +} +function Ve(e, t) { + if (oe(t)) return t + let r = t[y] + if (!r) return Ne(t, e.A, e) + if (!Ie(r, e)) return t + if (!r.s) return r.t + if (!r.u) { + let {f: n} = r + if (n) for (; n.length > 0; ) n.pop()(e) + He(r, e) + } + return r.e +} +function ct(e, t, r = !1) { + !e.i && e.l.h && e.F && J(t, r) +} +function Be(e) { + ;(e.u = !0), e.n.m-- +} +var Ie = (e, t) => e.n === t, + ut = [] +function ve(e, t, r, n) { + let a = O(e), + i = e.r + if (n !== void 0 && U(a, n, i) === t) { + ae(a, n, r, i) + return + } + if (!e.D) { + let S = (e.D = new Map()) + z(a, (p, M) => { + if (w(M)) { + let o = S.get(M) || [] + o.push(p), S.set(M, o) + } + }) + } + let d = e.D.get(t) ?? ut + for (let S of d) ae(a, S, r, i) +} +function Ke(e, t, r) { + e.f.push(function(a) { + let i = t + if (!i || !Ie(i, a)) return + a.I?.fixSetContents(i) + let d = ge(i) + ve(e, i.c ?? i, d, r), He(i, a) + }) +} +function He(e, t) { + if ( + e.s && + !e.u && + (e.r === 3 || (e.r === 1 && e.R) || (e.a?.size ?? 0) > 0) + ) { + let {P: n} = t + if (n) { + let a = n.getPath(e) + a && n.O(e, a, t) + } + Be(e) + } +} +function We(e, t, r) { + let {n} = e + if (w(r)) { + let a = r[y] + Ie(a, n) && + a.f.push(function() { + Z(e) + let d = ge(a) + ve(e, r, d, t) + }) + } else + D(r) && + e.f.push(function() { + let i = O(e) + U(i, t, e.r) === r && + n.o.length > 1 && + (e.a.get(t) ?? !1) === !0 && + e.e && + Ne(U(e.e, t, e.r), n.A, n) + }) +} +function Ne(e, t, r) { + return ( + (!r.l.h && r.m < 1) || + w(e) || + t.has(e) || + !D(e) || + oe(e) || + (t.add(e), + z(e, (n, a) => { + if (w(a)) { + let i = a[y] + if (Ie(i, r)) { + let d = ge(i) + ae(e, n, d, e.r), Be(i) + } + } else D(a) && Ne(a, t, r) + })), + e + ) +} +function Ge(e, t) { + let r = $(e), + n = { + r: r ? 1 : 0, + n: t ? t.n : X(), + s: !1, + u: !1, + a: void 0, + i: t, + t: e, + c: null, + e: null, + b: null, + S: !1, + f: void 0 + }, + a = n, + i = Ce + r && ((a = [n]), (i = pe)) + let {revoke: d, proxy: S} = Proxy.revocable(a, i) + return (n.c = S), (n.b = d), [S, n] +} +var Ce = { + get(e, t) { + if (t === y) return e + let r = e.n.E, + n = e.r === 1 && typeof t == "string" + if (n && r?.isArrayOperationMethod(t)) + return r.createMethodInterceptor(e, t) + let a = O(e) + if (!G(a, t, e.r)) return ft(e, a, t) + let i = a[t] + if ( + e.u || + !D(i) || + (n && + e.operationMethod && + r?.isMutatingArrayMethod(e.operationMethod) && + Le(t)) + ) + return i + if (i === Fe(e.t, t)) { + Z(e) + let d = e.r === 1 ? +t : t, + S = ee(e.n, i, e, d) + return (e.e[d] = S) + } + return i + }, + has(e, t) { + return t in O(e) + }, + ownKeys(e) { + return Reflect.ownKeys(O(e)) + }, + set(e, t, r) { + let n = $e(O(e), t) + if (n?.set) return n.set.call(e.c, r), !0 + if (!e.s) { + let a = Fe(O(e), t), + i = a?.[y] + if (i && i.t === r) return (e.e[t] = r), e.a.set(t, !1), !0 + if (Ue(r, a) && (r !== void 0 || G(e.t, t, e.r))) return !0 + Z(e), k(e) + } + return ( + (e.e[t] === r && (r !== void 0 || t in e.e)) || + (Number.isNaN(r) && Number.isNaN(e.e[t])) || + ((e.e[t] = r), e.a.set(t, !0), We(e, t, r)), + !0 + ) + }, + deleteProperty(e, t) { + return ( + Z(e), + Fe(e.t, t) !== void 0 || t in e.t + ? (e.a.set(t, !1), k(e)) + : e.a.delete(t), + e.e && delete e.e[t], + !0 + ) + }, + getOwnPropertyDescriptor(e, t) { + let r = O(e), + n = Reflect.getOwnPropertyDescriptor(r, t) + return ( + n && { + [se]: !0, + [Se]: e.r !== 1 || t !== "length", + [ce]: n[ce], + [ne]: r[t] + } + ) + }, + defineProperty() { + b(11) + }, + getPrototypeOf(e) { + return V(e.t) + }, + setPrototypeOf() { + b(12) + } + }, + pe = {} +z(Ce, (e, t) => { + pe[e] = function() { + let r = arguments + return (r[0] = r[0][0]), t.apply(this, r) + } +}) +pe.deleteProperty = function(e, t) { + return pe.set.call(this, e, t, void 0) +} +pe.set = function(e, t, r) { + return Ce.set.call(this, e[0], t, r, e[0]) +} +function Fe(e, t) { + let r = e[y] + return (r ? O(r) : e)[t] +} +function ft(e, t, r) { + let n = $e(t, r) + return n ? (ne in n ? n[ne] : n.get?.call(e.c)) : void 0 +} +function $e(e, t) { + if (!(t in e)) return + let r = V(e) + for (; r; ) { + let n = Object.getOwnPropertyDescriptor(r, t) + if (n) return n + r = V(r) + } +} +function k(e) { + e.s || ((e.s = !0), e.i && k(e.i)) +} +function Z(e) { + e.e || ((e.a = new Map()), (e.e = fe(e.t, e.n.l.g))) +} +var he = class { + constructor(t) { + this.h = !0 + this.g = !1 + this._ = !1 + this.produce = (t, r, n) => { + if (B(t) && !B(r)) { + let i = r + r = t + let d = this + return function(p = i, ...M) { + return d.produce(p, o => r.call(this, o, ...M)) + } + } + B(r) || b(6), n !== void 0 && !B(n) && b(7) + let a + if (D(t)) { + let i = Ee(this), + d = ee(i, t, void 0), + S = !0 + try { + ;(a = r(d)), (S = !1) + } finally { + S ? de(i) : Ae(i) + } + return _e(i, n), we(a, i) + } else if (!t || !H(t)) { + if ( + ((a = r(t)), + a === void 0 && (a = t), + a === L && (a = void 0), + this.h && J(a, !0), + n) + ) { + let i = [], + d = [] + v(Q).M(t, a, {p: i, d}), n(i, d) + } + return a + } else b(1, t) + } + this.produceWithPatches = (t, r) => { + if (B(t)) return (d, ...S) => this.produceWithPatches(d, p => t(p, ...S)) + let n, a + return [ + this.produce(t, r, (d, S) => { + ;(n = d), (a = S) + }), + n, + a + ] + } + Pe(t?.autoFreeze) && this.setAutoFreeze(t.autoFreeze), + Pe(t?.useStrictShallowCopy) && + this.setUseStrictShallowCopy(t.useStrictShallowCopy), + Pe(t?.useStrictIteration) && + this.setUseStrictIteration(t.useStrictIteration) + } + createDraft(t) { + D(t) || b(8), w(t) && (t = Me(t)) + let r = Ee(this), + n = ee(r, t, void 0) + return (n[y].S = !0), Ae(r), n + } + finishDraft(t, r) { + let n = t && t[y] + ;(!n || !n.S) && b(9) + let {n: a} = n + return _e(a, r), we(void 0, a) + } + setAutoFreeze(t) { + this.h = t + } + setUseStrictShallowCopy(t) { + this.g = t + } + setUseStrictIteration(t) { + this._ = t + } + shouldUseStrictIteration() { + return this._ + } + applyPatches(t, r) { + let n + for (n = r.length - 1; n >= 0; n--) { + let i = r[n] + if (i.path.length === 0 && i.op === "replace") { + t = i.value + break + } + } + n > -1 && (r = r.slice(n + 1)) + let a = v(Q).N + return w(t) ? a(t, r) : this.produce(t, i => a(i, r)) + } +} +function ee(e, t, r, n) { + let [a, i] = q(t) ? v(W).w(t, r) : Y(t) ? v(W).v(t, r) : Ge(t, r) + return ( + (r?.n ?? X()).o.push(a), + (i.f = r?.f ?? []), + (i.y = n), + r && n !== void 0 + ? Ke(r, i, n) + : i.f.push(function(p) { + p.I?.fixSetContents(i) + let {P: M} = p + i.s && M && M.O(i, [], p) + }), + a + ) +} +function Me(e) { + return w(e) || b(10, e), qe(e) +} +function qe(e) { + if (!D(e) || oe(e)) return e + let t = e[y], + r, + n = !0 + if (t) { + if (!t.s) return t.t + ;(t.u = !0), (r = fe(e, t.n.l.g)), (n = t.n.l.shouldUseStrictIteration()) + } else r = fe(e, !0) + return ( + z( + r, + (a, i) => { + ae(r, a, qe(i)) + }, + n + ), + t && (t.u = !1), + r + ) +} +function Ye() { + function t(c, P = []) { + if ("key_" in c && c.y !== void 0) { + let m = c.i.e ?? c.i.t, + x = Oe(U(m, c.y)), + A = U(m, c.y) + if ( + A === void 0 || + (A !== c.c && A !== c.t && A !== c.e) || + (x != null && x.t !== c.t) + ) + return null + let s = c.i.r === 3, + l + if (s) { + let h = c.i + l = Array.from(h.o.keys()).indexOf(c.y) + } else l = c.y + if (!((s && m.size > l) || G(m, l))) return null + P.push(l) + } + if (c.i) return t(c.i, P) + P.reverse() + try { + r(c.e, P) + } catch { + return null + } + return P + } + function r(c, P) { + let m = c + for (let x = 0; x < P.length - 1; x++) { + let A = P[x] + if (((m = U(m, A)), !H(m) || m === null)) + throw new Error(`Cannot resolve path at '${P.join("/")}'`) + } + return m + } + let n = "replace", + a = "add", + i = "remove" + function d(c, P, m) { + if (c.n.T.has(c)) return + c.n.T.add(c) + let {p: x, d: A} = m + switch (c.r) { + case 0: + case 2: + return p(c, P, x, A) + case 1: + return S(c, P, x, A) + case 3: + return M(c, P, x, A) + } + } + function S(c, P, m, x) { + let {t: A, a: s} = c, + l = c.e + l.length < A.length && (([A, l] = [l, A]), ([m, x] = [x, m])) + let h = c.R === !0 + for (let f = 0; f < A.length; f++) { + let I = l[f], + E = A[f] + if ((h || s?.get(f.toString())) && I !== E) { + let C = I?.[y] + if (C && C.s) continue + let R = P.concat([f]) + m.push({op: n, path: R, value: _(I)}), + x.push({op: n, path: R, value: _(E)}) + } + } + for (let f = A.length; f < l.length; f++) { + let I = P.concat([f]) + m.push({op: a, path: I, value: _(l[f])}) + } + for (let f = l.length - 1; A.length <= f; --f) { + let I = P.concat([f]) + x.push({op: i, path: I}) + } + } + function p(c, P, m, x) { + let {t: A, e: s, r: l} = c + z(c.a, (h, f) => { + let I = U(A, h, l), + E = U(s, h, l), + T = f ? (G(A, h) ? n : a) : i + if (I === E && T === n) return + let C = P.concat(h) + m.push(T === i ? {op: T, path: C} : {op: T, path: C, value: _(E)}), + x.push( + T === a + ? {op: i, path: C} + : T === i + ? {op: a, path: C, value: _(I)} + : {op: n, path: C, value: _(I)} + ) + }) + } + function M(c, P, m, x) { + let {t: A, e: s} = c, + l = 0 + A.forEach(h => { + if (!s.has(h)) { + let f = P.concat([l]) + m.push({op: i, path: f, value: h}), + x.unshift({op: a, path: f, value: h}) + } + l++ + }), + (l = 0), + s.forEach(h => { + if (!A.has(h)) { + let f = P.concat([l]) + m.push({op: a, path: f, value: h}), + x.unshift({op: i, path: f, value: h}) + } + l++ + }) + } + function o(c, P, m) { + let {p: x, d: A} = m + x.push({op: n, path: [], value: P === L ? void 0 : P}), + A.push({op: n, path: [], value: c}) + } + function u(c, P) { + return ( + P.forEach(m => { + let {path: x, op: A} = m, + s = c + for (let I = 0; I < x.length - 1; I++) { + let E = K(s), + T = x[I] + typeof T != "string" && typeof T != "number" && (T = "" + T), + (E === 0 || E === 1) && + (T === "__proto__" || T === te) && + b(16 + 3), + B(s) && T === re && b(16 + 3), + (s = U(s, T)), + H(s) || b(16 + 2, x.join("/")) + } + let l = K(s), + h = g(m.value), + f = x[x.length - 1] + switch (A) { + case n: + switch (l) { + case 2: + return s.set(f, h) + case 3: + b(16) + default: + return (s[f] = h) + } + case a: + switch (l) { + case 1: + return f === "-" ? s.push(h) : s.splice(f, 0, h) + case 2: + return s.set(f, h) + case 3: + return s.add(h) + default: + return (s[f] = h) + } + case i: + switch (l) { + case 1: + return s.splice(f, 1) + case 2: + return s.delete(f) + case 3: + return s.delete(m.value) + default: + return delete s[f] + } + default: + b(16 + 1, A) + } + }), + c + ) + } + function g(c) { + if (!D(c)) return c + if ($(c)) return c.map(g) + if (q(c)) return new Map(Array.from(c.entries()).map(([m, x]) => [m, g(x)])) + if (Y(c)) return new Set(Array.from(c).map(g)) + let P = Object.create(V(c)) + for (let m in c) P[m] = g(c[m]) + return G(c, j) && (P[j] = c[j]), P + } + function _(c) { + return w(c) ? g(c) : c + } + ie(Q, {N: u, O: d, M: o, getPath: t}) +} +function Je() { + class e extends Map { + constructor(o, u) { + super() + this[y] = { + r: 2, + i: u, + n: u ? u.n : X(), + s: !1, + u: !1, + e: void 0, + a: void 0, + t: o, + c: this, + S: !1, + x: !1, + f: [] + } + } + get size() { + return O(this[y]).size + } + has(o) { + return O(this[y]).has(o) + } + set(o, u) { + let g = this[y] + return ( + d(g), + (!O(g).has(o) || O(g).get(o) !== u) && + (r(g), k(g), g.a.set(o, !0), g.e.set(o, u), g.a.set(o, !0)), + this + ) + } + delete(o) { + if (!this.has(o)) return !1 + let u = this[y] + return ( + d(u), + r(u), + k(u), + u.t.has(o) ? u.a.set(o, !1) : u.a.delete(o), + u.e.delete(o), + !0 + ) + } + clear() { + let o = this[y] + d(o), + O(o).size && + (r(o), + k(o), + (o.a = new Map()), + z(o.t, u => { + o.a.set(u, !1) + }), + o.e.clear()) + } + forEach(o, u) { + let g = this[y] + O(g).forEach((_, c, P) => { + o.call(u, this.get(c), c, this) + }) + } + get(o) { + let u = this[y] + d(u) + let g = O(u).get(o) + if (u.u || !D(g) || g !== u.t.get(o)) return g + let _ = ee(u.n, g, u, o) + return r(u), u.e.set(o, _), _ + } + keys() { + return O(this[y]).keys() + } + values() { + let o = this.keys() + return { + [Symbol.iterator]: () => this.values(), + next: () => { + let u = o.next() + return u.done ? u : {done: !1, value: this.get(u.value)} + } + } + } + entries() { + let o = this.keys() + return { + [Symbol.iterator]: () => this.entries(), + next: () => { + let u = o.next() + if (u.done) return u + let g = this.get(u.value) + return {done: !1, value: [u.value, g]} + } + } + } + [(y, Symbol.iterator)]() { + return this.entries() + } + } + function t(p, M) { + let o = new e(p, M) + return [o, o[y]] + } + function r(p) { + p.e || ((p.a = new Map()), (p.e = new Map(p.t))) + } + class n extends Set { + constructor(o, u) { + super() + this[y] = { + r: 3, + i: u, + n: u ? u.n : X(), + s: !1, + u: !1, + e: void 0, + t: o, + c: this, + o: new Map(), + x: !1, + S: !1, + a: void 0, + f: [] + } + } + get size() { + return O(this[y]).size + } + has(o) { + let u = this[y] + return ( + d(u), + u.e ? !!(u.e.has(o) || (u.o.has(o) && u.e.has(u.o.get(o)))) : u.t.has(o) + ) + } + add(o) { + let u = this[y] + return d(u), this.has(o) || (i(u), k(u), u.e.add(o)), this + } + delete(o) { + if (!this.has(o)) return !1 + let u = this[y] + return ( + d(u), + i(u), + k(u), + u.e.delete(o) || (u.o.has(o) ? u.e.delete(u.o.get(o)) : !1) + ) + } + clear() { + let o = this[y] + d(o), O(o).size && (i(o), k(o), o.e.clear()) + } + values() { + let o = this[y] + return d(o), i(o), o.e.values() + } + entries() { + let o = this[y] + return d(o), i(o), o.e.entries() + } + keys() { + return this.values() + } + [(y, Symbol.iterator)]() { + return this.values() + } + forEach(o, u) { + let g = this.values(), + _ = g.next() + for (; !_.done; ) o.call(u, _.value, _.value, this), (_ = g.next()) + } + } + function a(p, M) { + let o = new n(p, M) + return [o, o[y]] + } + function i(p) { + p.e || + ((p.e = new Set()), + p.t.forEach(M => { + if (D(M)) { + let o = ee(p.n, M, p, M) + p.o.set(M, o), p.e.add(o) + } else p.e.add(M) + })) + } + function d(p) { + p.x && b(3, JSON.stringify(O(p))) + } + function S(p) { + if (p.r === 3 && p.e) { + let M = new Set(p.e) + p.e.clear(), + M.forEach(o => { + p.e.add(je(o)) + }) + } + } + ie(W, {w: t, v: a, fixSetContents: S}) +} +function Qe() { + let e = new Set(["shift", "unshift"]), + t = new Set(["push", "pop"]), + r = new Set([...t, ...e]), + n = new Set(["reverse", "sort"]), + a = new Set([...r, ...n, "splice"]), + i = new Set(["find", "findLast"]), + d = new Set([ + "filter", + "slice", + "concat", + "flat", + ...i, + "findIndex", + "findLastIndex", + "some", + "every", + "indexOf", + "lastIndexOf", + "includes", + "join", + "toString", + "toLocaleString" + ]) + function S(s) { + return a.has(s) + } + function p(s) { + return d.has(s) + } + function M(s) { + return S(s) || p(s) + } + function o(s, l) { + s.operationMethod = l + } + function u(s) { + s.operationMethod = void 0 + } + function g(s, l, h = !0) { + Z(s) + let f = l() + return k(s), h && s.a.set("length", !0), f + } + function _(s) { + s.R = !0 + } + function c(s, l) { + return s < 0 ? Math.max(l + s, 0) : Math.min(s, l) + } + function P(s, l, h) { + return g(s, () => { + let f = s.e[l](...h) + return e.has(l) && _(s), r.has(l) ? f : s.c + }) + } + function m(s, l, h) { + return g(s, () => (s.e[l](...h), _(s), s.c), !1) + } + function x(s, l) { + return function(...f) { + let I = l + o(s, I) + try { + if (S(I)) { + if (r.has(I)) return P(s, I, f) + if (n.has(I)) return m(s, I, f) + if (I === "splice") { + let E = g(s, () => s.e.splice(...f)) + return _(s), E + } + } else return A(s, I, f) + } finally { + u(s) + } + } + } + function A(s, l, h) { + let f = O(s) + if (l === "filter") { + let I = h[0], + E = [] + for (let T = 0; T < f.length; T++) I(f[T], T, f) && E.push(s.c[T]) + return E + } + if (i.has(l)) { + let I = h[0], + E = l === "find", + T = E ? 1 : -1, + C = E ? 0 : f.length - 1 + for (let R = C; R >= 0 && R < f.length; R += T) + if (I(f[R], R, f)) return s.c[R] + return + } + if (l === "slice") { + let I = h[0] ?? 0, + E = h[1] ?? f.length, + T = c(I, f.length), + C = c(E, f.length), + R = [] + for (let Te = T; Te < C; Te++) R.push(s.c[Te]) + return R + } + return f[l](...h) + } + ie(le, { + createMethodInterceptor: x, + isArrayOperationMethod: M, + isMutatingArrayMethod: S + }) +} +var N = new he(), + lt = N.produce, + yt = N.produceWithPatches.bind(N), + dt = N.setAutoFreeze.bind(N), + pt = N.setUseStrictShallowCopy.bind(N), + ht = N.setUseStrictIteration.bind(N), + mt = N.applyPatches.bind(N), + St = N.createDraft.bind(N), + Pt = N.finishDraft.bind(N), + gt = e => e, + xt = e => e +function At(e) { + return e === L +} +0 && + (module.exports = { + Immer, + applyPatches, + castDraft, + castImmutable, + createDraft, + current, + enableArrayMethods, + enableMapSet, + enablePatches, + finishDraft, + freeze, + immerable, + isDraft, + isDraftable, + isNothing, + nothing, + original, + produce, + produceWithPatches, + setAutoFreeze, + setUseStrictIteration, + setUseStrictShallowCopy + }) +//# sourceMappingURL=immer.cjs.production.js.map diff --git a/dist/cjs/immer.cjs.production.js.map b/dist/cjs/immer.cjs.production.js.map new file mode 100644 index 00000000..a50a5623 --- /dev/null +++ b/dist/cjs/immer.cjs.production.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../src/immer.ts","../../src/utils/env.ts","../../src/utils/errors.ts","../../src/utils/common.ts","../../src/utils/plugins.ts","../../src/core/scope.ts","../../src/core/finalize.ts","../../src/core/proxy.ts","../../src/core/immerClass.ts","../../src/core/current.ts","../../src/plugins/patches.ts","../../src/plugins/mapset.ts","../../src/plugins/arrayMethods.ts"],"sourcesContent":["import {\n\tIProduce,\n\tIProduceWithPatches,\n\tImmer,\n\tDraft,\n\tImmutable,\n\tNOTHING as nothing\n} from \"./internal\"\n\nexport {\n\tDraft,\n\tWritableDraft,\n\tImmutable,\n\tPatch,\n\tPatchListener,\n\tProducer,\n\toriginal,\n\tcurrent,\n\tisDraft,\n\tisDraftable,\n\tDRAFTABLE as immerable,\n\tfreeze,\n\tObjectish,\n\tStrictMode\n} from \"./internal\"\n\nexport {nothing}\n\nconst immer = new Immer()\n\n/**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\nexport const produce: IProduce = /* @__PURE__ */ immer.produce\n\n/**\n * Like `produce`, but `produceWithPatches` always returns a tuple\n * [nextState, patches, inversePatches] (instead of just the next state)\n */\nexport const produceWithPatches: IProduceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(\n\timmer\n)\n\n/**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * Always freeze by default, even in production mode\n */\nexport const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)\n\n/**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\nexport const setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(\n\timmer\n)\n\n/**\n * Pass false to use loose iteration that only processes enumerable string properties.\n * This skips symbols and non-enumerable properties for maximum performance.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\nexport const setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(\n\timmer\n)\n\n/**\n * Apply an array of Immer patches to the first argument.\n *\n * This function is a producer, which means copy-on-write is in effect.\n */\nexport const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)\n\n/**\n * Create an Immer draft from the given base state, which may be a draft itself.\n * The draft can be modified until you finalize it with the `finishDraft` function.\n */\nexport const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)\n\n/**\n * Finalize an Immer draft from a `createDraft` call, returning the base state\n * (if no changes were made) or a modified copy. The draft must *not* be\n * mutated afterwards.\n *\n * Pass a function as the 2nd argument to generate Immer patches based on the\n * changes that were made.\n */\nexport const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)\n\n/**\n * This function is actually a no-op, but can be used to cast an immutable type\n * to an draft type and make TypeScript happy\n *\n * @param value\n */\nexport let castDraft = (value: T): Draft => value as any\n\n/**\n * This function is actually a no-op, but can be used to cast a mutable type\n * to an immutable type and make TypeScript happy\n * @param value\n */\nexport let castImmutable = (value: T): Immutable => value as any\n\nexport {Immer}\n\nexport {enablePatches} from \"./plugins/patches\"\nexport {enableMapSet} from \"./plugins/mapset\"\nexport {enableArrayMethods} from \"./plugins/arrayMethods\"\n\nexport function isNothing(value: unknown): value is typeof nothing {\n\treturn value === nothing\n}\n","// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","import {isFunction} from \"../internal\"\n\nexport const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `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}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = isFunction(e) ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nconst O = Object\n\nexport const getPrototypeOf = O.getPrototypeOf\n\nexport const CONSTRUCTOR = \"constructor\"\nexport const PROTOTYPE = \"prototype\"\n\nexport const CONFIGURABLE = \"configurable\"\nexport const ENUMERABLE = \"enumerable\"\nexport const WRITABLE = \"writable\"\nexport const VALUE = \"value\"\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport let isDraft = (value: any): boolean => !!value && !!value[DRAFT_STATE]\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tisArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value[CONSTRUCTOR]?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString()\nconst cachedCtorStrings = new WeakMap()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || !isObjectish(value)) return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null || proto === O[PROTOTYPE]) return true\n\n\tconst Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR]\n\tif (Ctor === Object) return true\n\n\tif (!isFunction(Ctor)) return false\n\n\tlet ctorString = cachedCtorStrings.get(Ctor)\n\tif (ctorString === undefined) {\n\t\tctorString = Function.toString.call(Ctor)\n\t\tcachedCtorStrings.set(Ctor, ctorString)\n\t}\n\n\treturn ctorString === objectCtorString\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n *\n * @param obj The object to iterate over\n * @param iter The iterator function\n * @param strict When true (default), includes symbols and non-enumerable properties.\n * When false, uses looseiteration over only enumerable string properties.\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void,\n\tstrict?: boolean\n): void\nexport function each(obj: any, iter: any, strict: boolean = true) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\t// If strict, we do a full iteration including symbols and non-enumerable properties\n\t\t// Otherwise, we only iterate enumerable string properties for performance\n\t\tconst keys = strict ? Reflect.ownKeys(obj) : O.keys(obj)\n\t\tkeys.forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport let has = (\n\tthing: any,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): boolean =>\n\ttype === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: O[PROTOTYPE].hasOwnProperty.call(thing, prop)\n\n/*#__PURE__*/\nexport let get = (\n\tthing: AnyMap | AnyObject,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): any =>\n\t// @ts-ignore\n\ttype === ArchType.Map ? thing.get(prop) : thing[prop]\n\n/*#__PURE__*/\nexport let set = (\n\tthing: any,\n\tpropOrOldValue: PropertyKey,\n\tvalue: any,\n\ttype = getArchtype(thing)\n) => {\n\tif (type === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (type === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\nexport let isArray = Array.isArray\n\n/*#__PURE__*/\nexport let isMap = (target: any): target is AnyMap => target instanceof Map\n\n/*#__PURE__*/\nexport let isSet = (target: any): target is AnySet => target instanceof Set\n\nexport let isObjectish = (target: any) => typeof target === \"object\"\n\nexport let isFunction = (target: any): target is Function =>\n\ttypeof target === \"function\"\n\nexport let isBoolean = (target: any): target is boolean =>\n\ttypeof target === \"boolean\"\n\nexport function isArrayIndex(value: string | number): value is number | string {\n\tconst n = +value\n\treturn Number.isInteger(n) && String(n) === value\n}\n\nexport let getProxyDraft = (value: T): ImmerState | null => {\n\tif (!isObjectish(value)) return null\n\treturn (value as {[DRAFT_STATE]: any})?.[DRAFT_STATE]\n}\n\n/*#__PURE__*/\nexport let latest = (state: ImmerState): any => state.copy_ || state.base_\n\nexport let getValue = (value: T): T => {\n\tconst proxyDraft = getProxyDraft(value)\n\treturn proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value\n}\n\nexport let getFinalValue = (state: ImmerState): any =>\n\tstate.modified_ ? state.copy_ : state.base_\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (isArray(base)) return Array[PROTOTYPE].slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = O.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc[WRITABLE] === false) {\n\t\t\t\tdesc[WRITABLE] = true\n\t\t\t\tdesc[CONFIGURABLE] = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\t[CONFIGURABLE]: true,\n\t\t\t\t\t[WRITABLE]: true, // could live with !!desc.set as well here...\n\t\t\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t\t\t[VALUE]: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn O.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = O.create(proto)\n\t\treturn O.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tO.defineProperties(obj, {\n\t\t\tset: dontMutateMethodOverride,\n\t\t\tadd: dontMutateMethodOverride,\n\t\t\tclear: dontMutateMethodOverride,\n\t\t\tdelete: dontMutateMethodOverride\n\t\t})\n\t}\n\tO.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.values (only string-like, enumerables) instead of each()\n\t\teach(\n\t\t\tobj,\n\t\t\t(_key, value) => {\n\t\t\t\tfreeze(value, true)\n\t\t\t},\n\t\t\tfalse\n\t\t)\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nconst dontMutateMethodOverride = {\n\t[VALUE]: dontMutateFrozenCollections\n}\n\nexport function isFrozen(obj: any): boolean {\n\t// Fast path: primitives and null/undefined are always \"frozen\"\n\tif (obj === null || !isObjectish(obj)) return true\n\treturn O.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie,\n\tImmerScope,\n\tProxyArrayState\n} from \"../internal\"\n\nexport const PluginMapSet = \"MapSet\"\nexport const PluginPatches = \"Patches\"\nexport const PluginArrayMethods = \"ArrayMethods\"\n\nexport type PatchesPlugin = {\n\tgeneratePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\trootScope: ImmerScope\n\t): void\n\tgenerateReplacementPatches_(\n\t\tbase: any,\n\t\treplacement: any,\n\t\trootScope: ImmerScope\n\t): void\n\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\tgetPath: (state: ImmerState) => PatchPath | null\n}\n\nexport type MapSetPlugin = {\n\tproxyMap_(target: T, parent?: ImmerState): [T, ImmerState]\n\tproxySet_(target: T, parent?: ImmerState): [T, ImmerState]\n\tfixSetContents: (state: ImmerState) => void\n}\n\nexport type ArrayMethodsPlugin = {\n\tcreateMethodInterceptor: (state: ProxyArrayState, method: string) => Function\n\tisArrayOperationMethod: (method: string) => boolean\n\tisMutatingArrayMethod: (method: string) => boolean\n}\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: PatchesPlugin\n\tMapSet?: MapSetPlugin\n\tArrayMethods?: ArrayMethodsPlugin\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport let isPluginLoaded = (pluginKey: K): boolean =>\n\t!!plugins[pluginKey]\n\nexport let clearPlugin = (pluginKey: K): void => {\n\tdelete plugins[pluginKey]\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin,\n\tPatchesPlugin,\n\tMapSetPlugin,\n\tisPluginLoaded,\n\tPluginMapSet,\n\tPluginPatches,\n\tArrayMethodsPlugin,\n\tPluginArrayMethods\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tpatchPlugin_?: PatchesPlugin\n\tmapSetPlugin_?: MapSetPlugin\n\tarrayMethodsPlugin_?: ArrayMethodsPlugin\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n\thandledSet_: Set\n\tprocessedForPatches_: Set\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport let getCurrentScope = () => currentScope!\n\nlet createScope = (\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope => ({\n\tdrafts_: [],\n\tparent_,\n\timmer_,\n\t// Whenever the modified draft contains a draft from another scope, we\n\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\tcanAutoFreeze_: true,\n\tunfinalizedDrafts_: 0,\n\thandledSet_: new Set(),\n\tprocessedForPatches_: new Set(),\n\tmapSetPlugin_: isPluginLoaded(PluginMapSet)\n\t\t? getPlugin(PluginMapSet)\n\t\t: undefined,\n\tarrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods)\n\t\t? getPlugin(PluginArrayMethods)\n\t\t: undefined\n})\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tscope.patchPlugin_ = getPlugin(PluginPatches) // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport let enterScope = (immer: Immer) =>\n\t(currentScope = createScope(currentScope, immer))\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen,\n\tget,\n\tPatch,\n\tlatest,\n\tprepareCopy,\n\tgetFinalValue,\n\tgetValue,\n\tProxyArrayState\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t}\n\t\tconst {patchPlugin_} = scope\n\t\tif (patchPlugin_) {\n\t\t\tpatchPlugin_.generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft)\n\t}\n\n\tmaybeFreeze(scope, result, true)\n\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\tif (!state) {\n\t\tconst finalValue = handleValue(value, rootScope.handledSet_, rootScope)\n\t\treturn finalValue\n\t}\n\n\t// Never finalize drafts owned by another scope\n\tif (!isSameScope(state, rootScope)) {\n\t\treturn value\n\t}\n\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\treturn state.base_\n\t}\n\n\tif (!state.finalized_) {\n\t\t// Execute all registered draft finalization callbacks\n\t\tconst {callbacks_} = state\n\t\tif (callbacks_) {\n\t\t\twhile (callbacks_.length > 0) {\n\t\t\t\tconst callback = callbacks_.pop()!\n\t\t\t\tcallback(rootScope)\n\t\t\t}\n\t\t}\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t}\n\n\t// By now the root copy has been fully updated throughout its tree\n\treturn state.copy_\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n\nfunction markStateFinalized(state: ImmerState) {\n\tstate.finalized_ = true\n\tstate.scope_.unfinalizedDrafts_--\n}\n\nlet isSameScope = (state: ImmerState, rootScope: ImmerScope) =>\n\tstate.scope_ === rootScope\n\n// A reusable empty array to avoid allocations\nconst EMPTY_LOCATIONS_RESULT: (string | symbol | number)[] = []\n\n// Updates all references to a draft in its parent to the finalized value.\n// This handles cases where the same draft appears multiple times in the parent, or has been moved around.\nexport function updateDraftInParent(\n\tparent: ImmerState,\n\tdraftValue: any,\n\tfinalizedValue: any,\n\toriginalKey?: string | number | symbol\n): void {\n\tconst parentCopy = latest(parent)\n\tconst parentType = parent.type_\n\n\t// Fast path: Check if draft is still at original key\n\tif (originalKey !== undefined) {\n\t\tconst currentValue = get(parentCopy, originalKey, parentType)\n\t\tif (currentValue === draftValue) {\n\t\t\t// Still at original location, just update it\n\t\t\tset(parentCopy, originalKey, finalizedValue, parentType)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Slow path: Build reverse mapping of all children\n\t// to their indices in the parent, so that we can\n\t// replace all locations where this draft appears.\n\t// We only have to build this once per parent.\n\tif (!parent.draftLocations_) {\n\t\tconst draftLocations = (parent.draftLocations_ = new Map())\n\n\t\t// Use `each` which works on Arrays, Maps, and Objects\n\t\teach(parentCopy, (key, value) => {\n\t\t\tif (isDraft(value)) {\n\t\t\t\tconst keys = draftLocations.get(value) || []\n\t\t\t\tkeys.push(key)\n\t\t\t\tdraftLocations.set(value, keys)\n\t\t\t}\n\t\t})\n\t}\n\n\t// Look up all locations where this draft appears\n\tconst locations =\n\t\tparent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT\n\n\t// Update all locations\n\tfor (const location of locations) {\n\t\tset(parentCopy, location, finalizedValue, parentType)\n\t}\n}\n\n// Register a callback to finalize a child draft when the parent draft is finalized.\n// This assumes there is a parent -> child relationship between the two drafts,\n// and we have a key to locate the child in the parent.\nexport function registerChildFinalizationCallback(\n\tparent: ImmerState,\n\tchild: ImmerState,\n\tkey: string | number | symbol\n) {\n\tparent.callbacks_.push(function childCleanup(rootScope) {\n\t\tconst state: ImmerState = child\n\n\t\t// Can only continue if this is a draft owned by this scope\n\t\tif (!state || !isSameScope(state, rootScope)) {\n\t\t\treturn\n\t\t}\n\n\t\t// Handle potential set value finalization first\n\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t// Update all locations in the parent that referenced this draft\n\t\tupdateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key)\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t})\n}\n\nfunction generatePatchesAndFinalize(state: ImmerState, rootScope: ImmerScope) {\n\tconst shouldFinalize =\n\t\tstate.modified_ &&\n\t\t!state.finalized_ &&\n\t\t(state.type_ === ArchType.Set ||\n\t\t\t(state.type_ === ArchType.Array &&\n\t\t\t\t(state as ProxyArrayState).allIndicesReassigned_) ||\n\t\t\t(state.assigned_?.size ?? 0) > 0)\n\n\tif (shouldFinalize) {\n\t\tconst {patchPlugin_} = rootScope\n\t\tif (patchPlugin_) {\n\t\t\tconst basePath = patchPlugin_!.getPath(state)\n\n\t\t\tif (basePath) {\n\t\t\t\tpatchPlugin_!.generatePatches_(state, basePath, rootScope)\n\t\t\t}\n\t\t}\n\n\t\tmarkStateFinalized(state)\n\t}\n}\n\nexport function handleCrossReference(\n\ttarget: ImmerState,\n\tkey: string | number | symbol,\n\tvalue: any\n) {\n\tconst {scope_} = target\n\t// Check if value is a draft from this scope\n\tif (isDraft(value)) {\n\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\tif (isSameScope(state, scope_)) {\n\t\t\t// Register callback to update this location when the draft finalizes\n\n\t\t\tstate.callbacks_.push(function crossReferenceCleanup() {\n\t\t\t\t// Update the target location with finalized value\n\t\t\t\tprepareCopy(target)\n\n\t\t\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t\t\tupdateDraftInParent(target, value, finalizedValue, key)\n\t\t\t})\n\t\t}\n\t} else if (isDraftable(value)) {\n\t\t// Handle non-draft objects that might contain drafts\n\t\ttarget.callbacks_.push(function nestedDraftCleanup() {\n\t\t\tconst targetCopy = latest(target)\n\n\t\t\tif (get(targetCopy, key, target.type_) === value) {\n\t\t\t\t// Process the value to replace any nested drafts\n\t\t\t\t// finalizeAssigned(target, key, target.scope_)\n\n\t\t\t\tif (\n\t\t\t\t\tscope_.drafts_.length > 1 &&\n\t\t\t\t\t((target as Exclude).assigned_!.get(key) ??\n\t\t\t\t\t\tfalse) === true &&\n\t\t\t\t\ttarget.copy_\n\t\t\t\t) {\n\t\t\t\t\t// This might be a non-draft value that has drafts\n\t\t\t\t\t// inside. We do need to recurse here to handle those.\n\t\t\t\t\thandleValue(\n\t\t\t\t\t\tget(target.copy_, key, target.type_),\n\t\t\t\t\t\tscope_.handledSet_,\n\t\t\t\t\t\tscope_\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport function handleValue(\n\ttarget: any,\n\thandledSet: Set,\n\trootScope: ImmerScope\n) {\n\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t// This benefits especially adding large data tree's without further processing.\n\t\t// See add-data.js perf test\n\t\treturn target\n\t}\n\n\t// Skip if already handled, frozen, or not draftable\n\tif (\n\t\tisDraft(target) ||\n\t\thandledSet.has(target) ||\n\t\t!isDraftable(target) ||\n\t\tisFrozen(target)\n\t) {\n\t\treturn target\n\t}\n\n\thandledSet.add(target)\n\n\t// Process ALL properties/entries\n\teach(target, (key, value) => {\n\t\tif (isDraft(value)) {\n\t\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\t\tif (isSameScope(state, rootScope)) {\n\t\t\t\t// Replace draft with finalized value\n\n\t\t\t\tconst updatedValue = getFinalValue(state)\n\n\t\t\t\tset(target, key, updatedValue, target.type_)\n\n\t\t\t\tmarkStateFinalized(state)\n\t\t\t}\n\t\t} else if (isDraftable(value)) {\n\t\t\t// Recursively handle nested values\n\t\t\thandleValue(value, handledSet, rootScope)\n\t\t}\n\t})\n\n\treturn target\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope,\n\thandleCrossReference,\n\tWRITABLE,\n\tCONFIGURABLE,\n\tENUMERABLE,\n\tVALUE,\n\tisArray,\n\tisArrayIndex\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted\n\toperationMethod?: string\n\tallIndicesReassigned_?: boolean\n}\n\ntype ProxyState = ProxyObjectState | ProxyArrayState\n\n/**\n * Returns a new draft of the `base` object.\n *\n * The second argument is the parent draft-state (used internally).\n */\nexport function createProxyProxy(\n\tbase: T,\n\tparent?: ImmerState\n): [Drafted, ProxyState] {\n\tconst baseIsArray = isArray(base)\n\tconst state: ProxyState = {\n\t\ttype_: baseIsArray ? ArchType.Array : (ArchType.Object as any),\n\t\t// Track which produce call this is associated with.\n\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t// True for both shallow and deep changes.\n\t\tmodified_: false,\n\t\t// Used during finalization.\n\t\tfinalized_: false,\n\t\t// Track which properties have been assigned (true) or deleted (false).\n\t\t// actually instantiated in `prepareCopy()`\n\t\tassigned_: undefined,\n\t\t// The parent draft state.\n\t\tparent_: parent,\n\t\t// The base state.\n\t\tbase_: base,\n\t\t// The base proxy.\n\t\tdraft_: null as any, // set below\n\t\t// The base copy with any updated values.\n\t\tcopy_: null,\n\t\t// Called by the `produce` function.\n\t\trevoke_: null as any,\n\t\tisManual_: false,\n\t\t// `callbacks` actually gets assigned in `createProxy`\n\t\tcallbacks_: undefined as any\n\t}\n\n\t// the traps must target something, a bit like the 'real' base.\n\t// but also, we need to be able to determine from the target what the relevant state is\n\t// (to avoid creating traps per instance to capture the state in closure,\n\t// and to avoid creating weird hidden properties as well)\n\t// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)\n\t// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb\n\tlet target: T = state as any\n\tlet traps: ProxyHandler> = objectTraps\n\tif (baseIsArray) {\n\t\ttarget = [state] as any\n\t\ttraps = arrayTraps\n\t}\n\n\tconst {revoke, proxy} = Proxy.revocable(target, traps)\n\tstate.draft_ = proxy as any\n\tstate.revoke_ = revoke\n\treturn [proxy as any, state]\n}\n\n/**\n * Object drafts\n */\nexport const objectTraps: ProxyHandler = {\n\tget(state, prop) {\n\t\tif (prop === DRAFT_STATE) return state\n\n\t\tlet arrayPlugin = state.scope_.arrayMethodsPlugin_\n\t\tconst isArrayWithStringProp =\n\t\t\tstate.type_ === ArchType.Array && typeof prop === \"string\"\n\t\t// Intercept array methods so that we can override\n\t\t// behavior and skip proxy creation for perf\n\t\tif (isArrayWithStringProp) {\n\t\t\tif (arrayPlugin?.isArrayOperationMethod(prop)) {\n\t\t\t\treturn arrayPlugin.createMethodInterceptor(state, prop)\n\t\t\t}\n\t\t}\n\n\t\tconst source = latest(state)\n\t\tif (!has(source, prop, state.type_)) {\n\t\t\t// non-existing or non-own property...\n\t\t\treturn readPropFromProto(state, source, prop)\n\t\t}\n\t\tconst value = source[prop]\n\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\treturn value\n\t\t}\n\n\t\t// During mutating array operations, defer proxy creation for array elements\n\t\t// This optimization avoids creating unnecessary proxies during sort/reverse\n\t\tif (\n\t\t\tisArrayWithStringProp &&\n\t\t\t(state as ProxyArrayState).operationMethod &&\n\t\t\tarrayPlugin?.isMutatingArrayMethod(\n\t\t\t\t(state as ProxyArrayState).operationMethod!\n\t\t\t) &&\n\t\t\tisArrayIndex(prop)\n\t\t) {\n\t\t\t// Return raw value during mutating operations, create proxy only if modified\n\t\t\treturn value\n\t\t}\n\t\t// Check for existing draft in modified state.\n\t\t// Assigned values are never drafted. This catches any drafts we created, too.\n\t\tif (value === peek(state.base_, prop)) {\n\t\t\tprepareCopy(state)\n\t\t\t// Ensure array keys are always numbers\n\t\t\tconst childKey = state.type_ === ArchType.Array ? +(prop as string) : prop\n\t\t\tconst childDraft = createProxy(state.scope_, value, state, childKey)\n\n\t\t\treturn (state.copy_![childKey] = childDraft)\n\t\t}\n\t\treturn value\n\t},\n\thas(state, prop) {\n\t\treturn prop in latest(state)\n\t},\n\townKeys(state) {\n\t\treturn Reflect.ownKeys(latest(state))\n\t},\n\tset(\n\t\tstate: ProxyObjectState,\n\t\tprop: string /* strictly not, but helps TS */,\n\t\tvalue\n\t) {\n\t\tconst desc = getDescriptorFromProto(latest(state), prop)\n\t\tif (desc?.set) {\n\t\t\t// special case: if this write is captured by a setter, we have\n\t\t\t// to trigger it with the correct context\n\t\t\tdesc.set.call(state.draft_, value)\n\t\t\treturn true\n\t\t}\n\t\tif (!state.modified_) {\n\t\t\t// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)\n\t\t\t// from setting an existing property with value undefined to undefined (which is not a change)\n\t\t\tconst current = peek(latest(state), prop)\n\t\t\t// special case, if we assigning the original value to a draft, we can ignore the assignment\n\t\t\tconst currentState: ProxyObjectState = current?.[DRAFT_STATE]\n\t\t\tif (currentState && currentState.base_ === value) {\n\t\t\t\tstate.copy_![prop] = value\n\t\t\t\tstate.assigned_!.set(prop, false)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (\n\t\t\t\tis(value, current) &&\n\t\t\t\t(value !== undefined || has(state.base_, prop, state.type_))\n\t\t\t)\n\t\t\t\treturn true\n\t\t\tprepareCopy(state)\n\t\t\tmarkChanged(state)\n\t\t}\n\n\t\tif (\n\t\t\t(state.copy_![prop] === value &&\n\t\t\t\t// special case: handle new props with value 'undefined'\n\t\t\t\t(value !== undefined || prop in state.copy_)) ||\n\t\t\t// special case: NaN\n\t\t\t(Number.isNaN(value) && Number.isNaN(state.copy_![prop]))\n\t\t)\n\t\t\treturn true\n\n\t\t// @ts-ignore\n\t\tstate.copy_![prop] = value\n\t\tstate.assigned_!.set(prop, true)\n\n\t\thandleCrossReference(state, prop, value)\n\t\treturn true\n\t},\n\tdeleteProperty(state, prop: string) {\n\t\tprepareCopy(state)\n\t\t// The `undefined` check is a fast path for pre-existing keys.\n\t\tif (peek(state.base_, prop) !== undefined || prop in state.base_) {\n\t\t\tstate.assigned_!.set(prop, false)\n\t\t\tmarkChanged(state)\n\t\t} else {\n\t\t\t// if an originally not assigned property was deleted\n\t\t\tstate.assigned_!.delete(prop)\n\t\t}\n\t\tif (state.copy_) {\n\t\t\tdelete state.copy_[prop]\n\t\t}\n\t\treturn true\n\t},\n\t// Note: We never coerce `desc.value` into an Immer draft, because we can't make\n\t// the same guarantee in ES5 mode.\n\tgetOwnPropertyDescriptor(state, prop) {\n\t\tconst owner = latest(state)\n\t\tconst desc = Reflect.getOwnPropertyDescriptor(owner, prop)\n\t\tif (!desc) return desc\n\t\treturn {\n\t\t\t[WRITABLE]: true,\n\t\t\t[CONFIGURABLE]: state.type_ !== ArchType.Array || prop !== \"length\",\n\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t[VALUE]: owner[prop]\n\t\t}\n\t},\n\tdefineProperty() {\n\t\tdie(11)\n\t},\n\tgetPrototypeOf(state) {\n\t\treturn getPrototypeOf(state.base_)\n\t},\n\tsetPrototypeOf() {\n\t\tdie(12)\n\t}\n}\n\n/**\n * Array drafts\n */\n\nconst arrayTraps: ProxyHandler<[ProxyArrayState]> = {}\neach(objectTraps, (key, fn) => {\n\t// @ts-ignore\n\tarrayTraps[key] = function() {\n\t\tconst args = arguments\n\t\targs[0] = args[0][0]\n\t\treturn fn.apply(this, args)\n\t}\n})\narrayTraps.deleteProperty = function(state, prop) {\n\tif (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop as any)))\n\t\tdie(13)\n\t// @ts-ignore\n\treturn arrayTraps.set!.call(this, state, prop, undefined)\n}\narrayTraps.set = function(state, prop, value) {\n\tif (\n\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\tprop !== \"length\" &&\n\t\tisNaN(parseInt(prop as any))\n\t)\n\t\tdie(14)\n\treturn objectTraps.set!.call(this, state[0], prop, value, state[0])\n}\n\n// Access a property without creating an Immer draft.\nfunction peek(draft: Drafted, prop: PropertyKey) {\n\tconst state = draft[DRAFT_STATE]\n\tconst source = state ? latest(state) : draft\n\treturn source[prop]\n}\n\nfunction readPropFromProto(state: ImmerState, source: any, prop: PropertyKey) {\n\tconst desc = getDescriptorFromProto(source, prop)\n\treturn desc\n\t\t? VALUE in desc\n\t\t\t? desc[VALUE]\n\t\t\t: // This is a very special case, if the prop is a getter defined by the\n\t\t\t // prototype, we should invoke it with the draft as context!\n\t\t\t desc.get?.call(state.draft_)\n\t\t: undefined\n}\n\nfunction getDescriptorFromProto(\n\tsource: any,\n\tprop: PropertyKey\n): PropertyDescriptor | undefined {\n\t// 'in' checks proto!\n\tif (!(prop in source)) return undefined\n\tlet proto = getPrototypeOf(source)\n\twhile (proto) {\n\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\tif (desc) return desc\n\t\tproto = getPrototypeOf(proto)\n\t}\n\treturn undefined\n}\n\nexport function markChanged(state: ImmerState) {\n\tif (!state.modified_) {\n\t\tstate.modified_ = true\n\t\tif (state.parent_) {\n\t\t\tmarkChanged(state.parent_)\n\t\t}\n\t}\n}\n\nexport function prepareCopy(state: ImmerState) {\n\tif (!state.copy_) {\n\t\t// Actually create the `assigned_` map now that we\n\t\t// know this is a modified draft.\n\t\tstate.assigned_ = new Map()\n\t\tstate.copy_ = shallowCopy(\n\t\t\tstate.base_,\n\t\t\tstate.scope_.immer_.useStrictShallowCopy_\n\t\t)\n\t}\n}\n","import {\n\tIProduceWithPatches,\n\tIProduce,\n\tImmerState,\n\tDrafted,\n\tisDraftable,\n\tprocessResult,\n\tPatch,\n\tObjectish,\n\tDRAFT_STATE,\n\tDraft,\n\tPatchListener,\n\tisDraft,\n\tisMap,\n\tisSet,\n\tcreateProxyProxy,\n\tgetPlugin,\n\tdie,\n\tenterScope,\n\trevokeScope,\n\tleaveScope,\n\tusePatchesInScope,\n\tgetCurrentScope,\n\tNOTHING,\n\tfreeze,\n\tcurrent,\n\tImmerScope,\n\tregisterChildFinalizationCallback,\n\tArchType,\n\tMapSetPlugin,\n\tAnyMap,\n\tAnySet,\n\tisObjectish,\n\tisFunction,\n\tisBoolean,\n\tPluginMapSet,\n\tPluginPatches\n} from \"../internal\"\n\ninterface ProducersFns {\n\tproduce: IProduce\n\tproduceWithPatches: IProduceWithPatches\n}\n\nexport type StrictMode = boolean | \"class_only\"\n\nexport class Immer implements ProducersFns {\n\tautoFreeze_: boolean = true\n\tuseStrictShallowCopy_: StrictMode = false\n\tuseStrictIteration_: boolean = false\n\n\tconstructor(config?: {\n\t\tautoFreeze?: boolean\n\t\tuseStrictShallowCopy?: StrictMode\n\t\tuseStrictIteration?: boolean\n\t}) {\n\t\tif (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config!.autoFreeze)\n\t\tif (isBoolean(config?.useStrictShallowCopy))\n\t\t\tthis.setUseStrictShallowCopy(config!.useStrictShallowCopy)\n\t\tif (isBoolean(config?.useStrictIteration))\n\t\t\tthis.setUseStrictIteration(config!.useStrictIteration)\n\t}\n\n\t/**\n\t * The `produce` function takes a value and a \"recipe function\" (whose\n\t * return value often depends on the base state). The recipe function is\n\t * free to mutate its first argument however it wants. All mutations are\n\t * only ever applied to a __copy__ of the base state.\n\t *\n\t * Pass only a function to create a \"curried producer\" which relieves you\n\t * from passing the recipe function every time.\n\t *\n\t * Only plain objects and arrays are made mutable. All other objects are\n\t * considered uncopyable.\n\t *\n\t * Note: This function is __bound__ to its `Immer` instance.\n\t *\n\t * @param {any} base - the initial state\n\t * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n\t * @param {Function} patchListener - optional function that will be called with all the patches produced here\n\t * @returns {any} a new state, or the initial state if nothing was modified\n\t */\n\tproduce: IProduce = (base: any, recipe?: any, patchListener?: any) => {\n\t\t// curried invocation\n\t\tif (isFunction(base) && !isFunction(recipe)) {\n\t\t\tconst defaultBase = recipe\n\t\t\trecipe = base\n\n\t\t\tconst self = this\n\t\t\treturn function curriedProduce(\n\t\t\t\tthis: any,\n\t\t\t\tbase = defaultBase,\n\t\t\t\t...args: any[]\n\t\t\t) {\n\t\t\t\treturn self.produce(base, (draft: Drafted) => recipe.call(this, draft, ...args)) // prettier-ignore\n\t\t\t}\n\t\t}\n\n\t\tif (!isFunction(recipe)) die(6)\n\t\tif (patchListener !== undefined && !isFunction(patchListener)) die(7)\n\n\t\tlet result\n\n\t\t// Only plain objects, arrays, and \"immerable classes\" are drafted.\n\t\tif (isDraftable(base)) {\n\t\t\tconst scope = enterScope(this)\n\t\t\tconst proxy = createProxy(scope, base, undefined)\n\t\t\tlet hasError = true\n\t\t\ttry {\n\t\t\t\tresult = recipe(proxy)\n\t\t\t\thasError = false\n\t\t\t} finally {\n\t\t\t\t// finally instead of catch + rethrow better preserves original stack\n\t\t\t\tif (hasError) revokeScope(scope)\n\t\t\t\telse leaveScope(scope)\n\t\t\t}\n\t\t\tusePatchesInScope(scope, patchListener)\n\t\t\treturn processResult(result, scope)\n\t\t} else if (!base || !isObjectish(base)) {\n\t\t\tresult = recipe(base)\n\t\t\tif (result === undefined) result = base\n\t\t\tif (result === NOTHING) result = undefined\n\t\t\tif (this.autoFreeze_) freeze(result, true)\n\t\t\tif (patchListener) {\n\t\t\t\tconst p: Patch[] = []\n\t\t\t\tconst ip: Patch[] = []\n\t\t\t\tgetPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n\t\t\t\t\tpatches_: p,\n\t\t\t\t\tinversePatches_: ip\n\t\t\t\t} as ImmerScope) // dummy scope\n\t\t\t\tpatchListener(p, ip)\n\t\t\t}\n\t\t\treturn result\n\t\t} else die(1, base)\n\t}\n\n\tproduceWithPatches: IProduceWithPatches = (base: any, recipe?: any): any => {\n\t\t// curried invocation\n\t\tif (isFunction(base)) {\n\t\t\treturn (state: any, ...args: any[]) =>\n\t\t\t\tthis.produceWithPatches(state, (draft: any) => base(draft, ...args))\n\t\t}\n\n\t\tlet patches: Patch[], inversePatches: Patch[]\n\t\tconst result = this.produce(base, recipe, (p: Patch[], ip: Patch[]) => {\n\t\t\tpatches = p\n\t\t\tinversePatches = ip\n\t\t})\n\t\treturn [result, patches!, inversePatches!]\n\t}\n\n\tcreateDraft(base: T): Draft {\n\t\tif (!isDraftable(base)) die(8)\n\t\tif (isDraft(base)) base = current(base)\n\t\tconst scope = enterScope(this)\n\t\tconst proxy = createProxy(scope, base, undefined)\n\t\tproxy[DRAFT_STATE].isManual_ = true\n\t\tleaveScope(scope)\n\t\treturn proxy as any\n\t}\n\n\tfinishDraft>(\n\t\tdraft: D,\n\t\tpatchListener?: PatchListener\n\t): D extends Draft ? T : never {\n\t\tconst state: ImmerState = draft && (draft as any)[DRAFT_STATE]\n\t\tif (!state || !state.isManual_) die(9)\n\t\tconst {scope_: scope} = state\n\t\tusePatchesInScope(scope, patchListener)\n\t\treturn processResult(undefined, scope)\n\t}\n\n\t/**\n\t * Pass true to automatically freeze all copies created by Immer.\n\t *\n\t * By default, auto-freezing is enabled.\n\t */\n\tsetAutoFreeze(value: boolean) {\n\t\tthis.autoFreeze_ = value\n\t}\n\n\t/**\n\t * Pass true to enable strict shallow copy.\n\t *\n\t * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n\t */\n\tsetUseStrictShallowCopy(value: StrictMode) {\n\t\tthis.useStrictShallowCopy_ = value\n\t}\n\n\t/**\n\t * Pass false to use faster iteration that skips non-enumerable properties\n\t * but still handles symbols for compatibility.\n\t *\n\t * By default, strict iteration is enabled (includes all own properties).\n\t */\n\tsetUseStrictIteration(value: boolean) {\n\t\tthis.useStrictIteration_ = value\n\t}\n\n\tshouldUseStrictIteration(): boolean {\n\t\treturn this.useStrictIteration_\n\t}\n\n\tapplyPatches(base: T, patches: readonly Patch[]): T {\n\t\t// If a patch replaces the entire state, take that replacement as base\n\t\t// before applying patches\n\t\tlet i: number\n\t\tfor (i = patches.length - 1; i >= 0; i--) {\n\t\t\tconst patch = patches[i]\n\t\t\tif (patch.path.length === 0 && patch.op === \"replace\") {\n\t\t\t\tbase = patch.value\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t// If there was a patch that replaced the entire state, start from the\n\t\t// patch after that.\n\t\tif (i > -1) {\n\t\t\tpatches = patches.slice(i + 1)\n\t\t}\n\n\t\tconst applyPatchesImpl = getPlugin(PluginPatches).applyPatches_\n\t\tif (isDraft(base)) {\n\t\t\t// N.B: never hits if some patch a replacement, patches are never drafts\n\t\t\treturn applyPatchesImpl(base, patches)\n\t\t}\n\t\t// Otherwise, produce a copy of the base state.\n\t\treturn this.produce(base, (draft: Drafted) =>\n\t\t\tapplyPatchesImpl(draft, patches)\n\t\t)\n\t}\n}\n\nexport function createProxy(\n\trootScope: ImmerScope,\n\tvalue: T,\n\tparent?: ImmerState,\n\tkey?: string | number | symbol\n): Drafted {\n\t// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft\n\t// returning a tuple here lets us skip a proxy access\n\t// to DRAFT_STATE later\n\tconst [draft, state] = isMap(value)\n\t\t? getPlugin(PluginMapSet).proxyMap_(value, parent)\n\t\t: isSet(value)\n\t\t? getPlugin(PluginMapSet).proxySet_(value, parent)\n\t\t: createProxyProxy(value, parent)\n\n\tconst scope = parent?.scope_ ?? getCurrentScope()\n\tscope.drafts_.push(draft)\n\n\t// Ensure the parent callbacks are passed down so we actually\n\t// track all callbacks added throughout the tree\n\tstate.callbacks_ = parent?.callbacks_ ?? []\n\tstate.key_ = key\n\n\tif (parent && key !== undefined) {\n\t\tregisterChildFinalizationCallback(parent, state, key)\n\t} else {\n\t\t// It's a root draft, register it with the scope\n\t\tstate.callbacks_.push(function rootDraftCleanup(rootScope) {\n\t\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\t\tconst {patchPlugin_} = rootScope\n\n\t\t\tif (state.modified_ && patchPlugin_) {\n\t\t\t\tpatchPlugin_.generatePatches_(state, [], rootScope)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn draft as any\n}\n","import {\n\tdie,\n\tisDraft,\n\tshallowCopy,\n\teach,\n\tDRAFT_STATE,\n\tset,\n\tImmerState,\n\tisDraftable,\n\tisFrozen\n} from \"../internal\"\n\n/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */\nexport function current(value: T): T\nexport function current(value: any): any {\n\tif (!isDraft(value)) die(10, value)\n\treturn currentImpl(value)\n}\n\nfunction currentImpl(value: any): any {\n\tif (!isDraftable(value) || isFrozen(value)) return value\n\tconst state: ImmerState | undefined = value[DRAFT_STATE]\n\tlet copy: any\n\tlet strict = true // Default to strict for compatibility\n\tif (state) {\n\t\tif (!state.modified_) return state.base_\n\t\t// Optimization: avoid generating new drafts during copying\n\t\tstate.finalized_ = true\n\t\tcopy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)\n\t\tstrict = state.scope_.immer_.shouldUseStrictIteration()\n\t} else {\n\t\tcopy = shallowCopy(value, true)\n\t}\n\t// recurse\n\teach(\n\t\tcopy,\n\t\t(key, childValue) => {\n\t\t\tset(copy, key, currentImpl(childValue))\n\t\t},\n\t\tstrict\n\t)\n\tif (state) {\n\t\tstate.finalized_ = false\n\t}\n\treturn copy\n}\n","import {immerable} from \"../immer\"\nimport {\n\tImmerState,\n\tPatch,\n\tSetState,\n\tProxyArrayState,\n\tMapState,\n\tProxyObjectState,\n\tPatchPath,\n\tget,\n\teach,\n\thas,\n\tgetArchtype,\n\tgetPrototypeOf,\n\tisSet,\n\tisMap,\n\tloadPlugin,\n\tArchType,\n\tdie,\n\tisDraft,\n\tisDraftable,\n\tNOTHING,\n\terrors,\n\tDRAFT_STATE,\n\tgetProxyDraft,\n\tImmerScope,\n\tisObjectish,\n\tisFunction,\n\tCONSTRUCTOR,\n\tPluginPatches,\n\tisArray,\n\tPROTOTYPE\n} from \"../internal\"\n\nexport function enablePatches() {\n\tconst errorOffset = 16\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\terrors.push(\n\t\t\t'Sets cannot have \"replace\" patches.',\n\t\t\tfunction(op: string) {\n\t\t\t\treturn \"Unsupported patch operation: \" + op\n\t\t\t},\n\t\t\tfunction(path: string) {\n\t\t\t\treturn \"Cannot apply patch, path doesn't resolve: \" + path\n\t\t\t},\n\t\t\t\"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n\t\t)\n\t}\n\n\tfunction getPath(state: ImmerState, path: PatchPath = []): PatchPath | null {\n\t\t// Step 1: Check if state has a stored key\n\t\tif (\"key_\" in state && state.key_ !== undefined) {\n\t\t\t// Step 2: Validate the key is still valid in parent\n\n\t\t\tconst parentCopy = state.parent_!.copy_ ?? state.parent_!.base_\n\t\t\tconst proxyDraft = getProxyDraft(get(parentCopy, state.key_!))\n\t\t\tconst valueAtKey = get(parentCopy, state.key_!)\n\n\t\t\tif (valueAtKey === undefined) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\t// Check if the value at the key is still related to this draft\n\t\t\t// It should be either the draft itself, the base, or the copy\n\t\t\tif (\n\t\t\t\tvalueAtKey !== state.draft_ &&\n\t\t\t\tvalueAtKey !== state.base_ &&\n\t\t\t\tvalueAtKey !== state.copy_\n\t\t\t) {\n\t\t\t\treturn null // Value was replaced with something else\n\t\t\t}\n\t\t\tif (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n\t\t\t\treturn null // Different draft\n\t\t\t}\n\n\t\t\t// Step 3: Handle Set case specially\n\t\t\tconst isSet = state.parent_!.type_ === ArchType.Set\n\t\t\tlet key: string | number\n\n\t\t\tif (isSet) {\n\t\t\t\t// For Sets, find the index in the drafts_ map\n\t\t\t\tconst setParent = state.parent_ as SetState\n\t\t\t\tkey = Array.from(setParent.drafts_.keys()).indexOf(state.key_)\n\t\t\t} else {\n\t\t\t\tkey = state.key_ as string | number\n\t\t\t}\n\n\t\t\t// Step 4: Validate key still exists in parent\n\t\t\tif (!((isSet && parentCopy.size > key) || has(parentCopy, key))) {\n\t\t\t\treturn null // Key deleted\n\t\t\t}\n\n\t\t\t// Step 5: Add key to path\n\t\t\tpath.push(key)\n\t\t}\n\n\t\t// Step 6: Recurse to parent if exists\n\t\tif (state.parent_) {\n\t\t\treturn getPath(state.parent_, path)\n\t\t}\n\n\t\t// Step 7: At root - reverse path and validate\n\t\tpath.reverse()\n\n\t\ttry {\n\t\t\t// Validate path can be resolved from ROOT\n\t\t\tresolvePath(state.copy_, path)\n\t\t} catch (e) {\n\t\t\treturn null // Path invalid\n\t\t}\n\n\t\treturn path\n\t}\n\n\t// NEW: Add resolvePath helper function\n\tfunction resolvePath(base: any, path: PatchPath): any {\n\t\tlet current = base\n\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\tconst key = path[i]\n\t\t\tcurrent = get(current, key)\n\t\t\tif (!isObjectish(current) || current === null) {\n\t\t\t\tthrow new Error(`Cannot resolve path at '${path.join(\"/\")}'`)\n\t\t\t}\n\t\t}\n\t\treturn current\n\t}\n\n\tconst REPLACE = \"replace\"\n\tconst ADD = \"add\"\n\tconst REMOVE = \"remove\"\n\n\tfunction generatePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\tscope: ImmerScope\n\t): void {\n\t\tif (state.scope_.processedForPatches_.has(state)) {\n\t\t\treturn\n\t\t}\n\n\t\tstate.scope_.processedForPatches_.add(state)\n\n\t\tconst {patches_, inversePatches_} = scope\n\n\t\tswitch (state.type_) {\n\t\t\tcase ArchType.Object:\n\t\t\tcase ArchType.Map:\n\t\t\t\treturn generatePatchesFromAssigned(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Array:\n\t\t\t\treturn generateArrayPatches(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Set:\n\t\t\t\treturn generateSetPatches(\n\t\t\t\t\t(state as any) as SetState,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t}\n\t}\n\n\tfunction generateArrayPatches(\n\t\tstate: ProxyArrayState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, assigned_} = state\n\t\tlet copy_ = state.copy_!\n\n\t\t// Reduce complexity by ensuring `base` is never longer.\n\t\tif (copy_.length < base_.length) {\n\t\t\t// @ts-ignore\n\t\t\t;[base_, copy_] = [copy_, base_]\n\t\t\t;[patches, inversePatches] = [inversePatches, patches]\n\t\t}\n\n\t\tconst allReassigned = state.allIndicesReassigned_ === true\n\n\t\t// Process replaced indices.\n\t\tfor (let i = 0; i < base_.length; i++) {\n\t\t\tconst copiedItem = copy_[i]\n\t\t\tconst baseItem = base_[i]\n\n\t\t\tconst isAssigned = allReassigned || assigned_?.get(i.toString())\n\t\t\tif (isAssigned && copiedItem !== baseItem) {\n\t\t\t\tconst childState = copiedItem?.[DRAFT_STATE]\n\t\t\t\tif (childState && childState.modified_) {\n\t\t\t\t\t// Skip - let the child generate its own patches\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(copiedItem)\n\t\t\t\t})\n\t\t\t\tinversePatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(baseItem)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Process added indices.\n\t\tfor (let i = base_.length; i < copy_.length; i++) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tpatches.push({\n\t\t\t\top: ADD,\n\t\t\t\tpath,\n\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\tvalue: clonePatchValueIfNeeded(copy_[i])\n\t\t\t})\n\t\t}\n\t\tfor (let i = copy_.length - 1; base_.length <= i; --i) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tinversePatches.push({\n\t\t\t\top: REMOVE,\n\t\t\t\tpath\n\t\t\t})\n\t\t}\n\t}\n\n\t// This is used for both Map objects and normal objects.\n\tfunction generatePatchesFromAssigned(\n\t\tstate: MapState | ProxyObjectState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tconst {base_, copy_, type_} = state\n\t\teach(state.assigned_!, (key, assignedValue) => {\n\t\t\tconst origValue = get(base_, key, type_)\n\t\t\tconst value = get(copy_!, key, type_)\n\t\t\tconst op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD\n\t\t\tif (origValue === value && op === REPLACE) return\n\t\t\tconst path = basePath.concat(key as any)\n\t\t\tpatches.push(\n\t\t\t\top === REMOVE\n\t\t\t\t\t? {op, path}\n\t\t\t\t\t: {op, path, value: clonePatchValueIfNeeded(value)}\n\t\t\t)\n\t\t\tinversePatches.push(\n\t\t\t\top === ADD\n\t\t\t\t\t? {op: REMOVE, path}\n\t\t\t\t\t: op === REMOVE\n\t\t\t\t\t? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t\t\t: {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t)\n\t\t})\n\t}\n\n\tfunction generateSetPatches(\n\t\tstate: SetState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, copy_} = state\n\n\t\tlet i = 0\n\t\tbase_.forEach((value: any) => {\n\t\t\tif (!copy_!.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t\ti = 0\n\t\tcopy_!.forEach((value: any) => {\n\t\t\tif (!base_.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t}\n\n\tfunction generateReplacementPatches_(\n\t\tbaseValue: any,\n\t\treplacement: any,\n\t\tscope: ImmerScope\n\t): void {\n\t\tconst {patches_, inversePatches_} = scope\n\t\tpatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: replacement === NOTHING ? undefined : replacement\n\t\t})\n\t\tinversePatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: baseValue\n\t\t})\n\t}\n\n\tfunction applyPatches_(draft: T, patches: readonly Patch[]): T {\n\t\tpatches.forEach(patch => {\n\t\t\tconst {path, op} = patch\n\n\t\t\tlet base: any = draft\n\t\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\t\tconst parentType = getArchtype(base)\n\t\t\t\tlet p = path[i]\n\t\t\t\tif (typeof p !== \"string\" && typeof p !== \"number\") {\n\t\t\t\t\tp = \"\" + p\n\t\t\t\t}\n\n\t\t\t\t// See #738, avoid prototype pollution\n\t\t\t\tif (\n\t\t\t\t\t(parentType === ArchType.Object || parentType === ArchType.Array) &&\n\t\t\t\t\t(p === \"__proto__\" || p === CONSTRUCTOR)\n\t\t\t\t)\n\t\t\t\t\tdie(errorOffset + 3)\n\t\t\t\tif (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3)\n\t\t\t\tbase = get(base, p)\n\t\t\t\tif (!isObjectish(base)) die(errorOffset + 2, path.join(\"/\"))\n\t\t\t}\n\n\t\t\tconst type = getArchtype(base)\n\t\t\tconst value = deepClonePatchValue(patch.value) // used to clone patch to ensure original patch is not modified, see #411\n\t\t\tconst key = path[path.length - 1]\n\t\t\tswitch (op) {\n\t\t\t\tcase REPLACE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\tdie(errorOffset)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t// if value is an object, then it's assigned by reference\n\t\t\t\t\t\t\t// in the following add or remove ops, the value field inside the patch will also be modifyed\n\t\t\t\t\t\t\t// so we use value from the cloned patch\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase ADD:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn key === \"-\"\n\t\t\t\t\t\t\t\t? base.push(value)\n\t\t\t\t\t\t\t\t: base.splice(key as any, 0, value)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.add(value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase REMOVE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn base.splice(key as any, 1)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.delete(key)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.delete(patch.value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn delete base[key]\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tdie(errorOffset + 1, op)\n\t\t\t}\n\t\t})\n\n\t\treturn draft\n\t}\n\n\t// optimize: this is quite a performance hit, can we detect intelligently when it is needed?\n\t// E.g. auto-draft when new objects from outside are assigned and modified?\n\t// (See failing test when deepClone just returns obj)\n\tfunction deepClonePatchValue(obj: T): T\n\tfunction deepClonePatchValue(obj: any) {\n\t\tif (!isDraftable(obj)) return obj\n\t\tif (isArray(obj)) return obj.map(deepClonePatchValue)\n\t\tif (isMap(obj))\n\t\t\treturn new Map(\n\t\t\t\tArray.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n\t\t\t)\n\t\tif (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue))\n\t\tconst cloned = Object.create(getPrototypeOf(obj))\n\t\tfor (const key in obj) cloned[key] = deepClonePatchValue(obj[key])\n\t\tif (has(obj, immerable)) cloned[immerable] = obj[immerable]\n\t\treturn cloned\n\t}\n\n\tfunction clonePatchValueIfNeeded(obj: T): T {\n\t\tif (isDraft(obj)) {\n\t\t\treturn deepClonePatchValue(obj)\n\t\t} else return obj\n\t}\n\n\tloadPlugin(PluginPatches, {\n\t\tapplyPatches_,\n\t\tgeneratePatches_,\n\t\tgenerateReplacementPatches_,\n\t\tgetPath\n\t})\n}\n","// types only!\nimport {\n\tImmerState,\n\tAnyMap,\n\tAnySet,\n\tMapState,\n\tSetState,\n\tDRAFT_STATE,\n\tgetCurrentScope,\n\tlatest,\n\tisDraftable,\n\tcreateProxy,\n\tloadPlugin,\n\tmarkChanged,\n\tdie,\n\tArchType,\n\teach,\n\tgetValue,\n\tPluginMapSet\n} from \"../internal\"\n\nexport function enableMapSet() {\n\tclass DraftMap extends Map {\n\t\t[DRAFT_STATE]: MapState\n\n\t\tconstructor(target: AnyMap, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Map,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this as any,\n\t\t\t\tisManual_: false,\n\t\t\t\trevoked_: false,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(key: any): boolean {\n\t\t\treturn latest(this[DRAFT_STATE]).has(key)\n\t\t}\n\n\t\tset(key: any, value: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!latest(state).has(key) || latest(state).get(key) !== value) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t\tstate.copy_!.set(key, value)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(key: any): boolean {\n\t\t\tif (!this.has(key)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareMapCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\tif (state.base_.has(key)) {\n\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t} else {\n\t\t\t\tstate.assigned_!.delete(key)\n\t\t\t}\n\t\t\tstate.copy_!.delete(key)\n\t\t\treturn true\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_ = new Map()\n\t\t\t\teach(state.base_, key => {\n\t\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t\t})\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tforEach(cb: (value: any, key: any, self: any) => void, thisArg?: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tlatest(state).forEach((_value: any, key: any, _map: any) => {\n\t\t\t\tcb.call(thisArg, this.get(key), key, this)\n\t\t\t})\n\t\t}\n\n\t\tget(key: any): any {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tconst value = latest(state).get(key)\n\t\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\t\treturn value\n\t\t\t}\n\t\t\tif (value !== state.base_.get(key)) {\n\t\t\t\treturn value // either already drafted or reassigned\n\t\t\t}\n\t\t\t// despite what it looks, this creates a draft only once, see above condition\n\t\t\tconst draft = createProxy(state.scope_, value, state, key)\n\t\t\tprepareMapCopy(state)\n\t\t\tstate.copy_!.set(key, draft)\n\t\t\treturn draft\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn latest(this[DRAFT_STATE]).keys()\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.values(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.entries(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue: [r.value, value]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.entries()\n\t\t}\n\t}\n\n\tfunction proxyMap_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, MapState] {\n\t\t// @ts-ignore\n\t\tconst map = new DraftMap(target, parent)\n\t\treturn [map as any, map[DRAFT_STATE]]\n\t}\n\n\tfunction prepareMapCopy(state: MapState) {\n\t\tif (!state.copy_) {\n\t\t\tstate.assigned_ = new Map()\n\t\t\tstate.copy_ = new Map(state.base_)\n\t\t}\n\t}\n\n\tclass DraftSet extends Set {\n\t\t[DRAFT_STATE]: SetState\n\t\tconstructor(target: AnySet, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Set,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this,\n\t\t\t\tdrafts_: new Map(),\n\t\t\t\trevoked_: false,\n\t\t\t\tisManual_: false,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(value: any): boolean {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\t// bit of trickery here, to be able to recognize both the value, and the draft of its value\n\t\t\tif (!state.copy_) {\n\t\t\t\treturn state.base_.has(value)\n\t\t\t}\n\t\t\tif (state.copy_.has(value)) return true\n\t\t\tif (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n\t\t\t\treturn true\n\t\t\treturn false\n\t\t}\n\n\t\tadd(value: any): any {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!this.has(value)) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.add(value)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(value: any): any {\n\t\t\tif (!this.has(value)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\treturn (\n\t\t\t\tstate.copy_!.delete(value) ||\n\t\t\t\t(state.drafts_.has(value)\n\t\t\t\t\t? state.copy_!.delete(state.drafts_.get(value))\n\t\t\t\t\t: /* istanbul ignore next */ false)\n\t\t\t)\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.values()\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.entries()\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn this.values()\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.values()\n\t\t}\n\n\t\tforEach(cb: any, thisArg?: any) {\n\t\t\tconst iterator = this.values()\n\t\t\tlet result = iterator.next()\n\t\t\twhile (!result.done) {\n\t\t\t\tcb.call(thisArg, result.value, result.value, this)\n\t\t\t\tresult = iterator.next()\n\t\t\t}\n\t\t}\n\t}\n\tfunction proxySet_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, SetState] {\n\t\t// @ts-ignore\n\t\tconst set = new DraftSet(target, parent)\n\t\treturn [set as any, set[DRAFT_STATE]]\n\t}\n\n\tfunction prepareSetCopy(state: SetState) {\n\t\tif (!state.copy_) {\n\t\t\t// create drafts for all entries to preserve insertion order\n\t\t\tstate.copy_ = new Set()\n\t\t\tstate.base_.forEach(value => {\n\t\t\t\tif (isDraftable(value)) {\n\t\t\t\t\tconst draft = createProxy(state.scope_, value, state, value)\n\t\t\t\t\tstate.drafts_.set(value, draft)\n\t\t\t\t\tstate.copy_!.add(draft)\n\t\t\t\t} else {\n\t\t\t\t\tstate.copy_!.add(value)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n\n\tfunction assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {\n\t\tif (state.revoked_) die(3, JSON.stringify(latest(state)))\n\t}\n\n\tfunction fixSetContents(target: ImmerState) {\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\tif (target.type_ === ArchType.Set && target.copy_) {\n\t\t\tconst copy = new Set(target.copy_)\n\t\t\ttarget.copy_.clear()\n\t\t\tcopy.forEach(value => {\n\t\t\t\ttarget.copy_!.add(getValue(value))\n\t\t\t})\n\t\t}\n\t}\n\n\tloadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents})\n}\n","import {\n\tPluginArrayMethods,\n\tlatest,\n\tloadPlugin,\n\tmarkChanged,\n\tprepareCopy,\n\tProxyArrayState\n} from \"../internal\"\n\n/**\n * Methods that directly modify the array in place.\n * These operate on the copy without creating per-element proxies:\n * - `push`, `pop`: Add/remove from end\n * - `shift`, `unshift`: Add/remove from start (marks all indices reassigned)\n * - `splice`: Add/remove at arbitrary position (marks all indices reassigned)\n * - `reverse`, `sort`: Reorder elements (marks all indices reassigned)\n */\ntype MutatingArrayMethod =\n\t| \"push\"\n\t| \"pop\"\n\t| \"shift\"\n\t| \"unshift\"\n\t| \"splice\"\n\t| \"reverse\"\n\t| \"sort\"\n\n/**\n * Methods that read from the array without modifying it.\n * These fall into distinct categories based on return semantics:\n *\n * **Subset operations** (return drafts - mutations propagate):\n * - `filter`, `slice`: Return array of draft proxies\n * - `find`, `findLast`: Return single draft proxy or undefined\n *\n * **Transform operations** (return base values - mutations don't track):\n * - `concat`, `flat`: Create new structures, not subsets of original\n *\n * **Primitive-returning** (no draft needed):\n * - `findIndex`, `findLastIndex`, `indexOf`, `lastIndexOf`: Return numbers\n * - `some`, `every`, `includes`: Return booleans\n * - `join`, `toString`, `toLocaleString`: Return strings\n */\ntype NonMutatingArrayMethod =\n\t| \"filter\"\n\t| \"slice\"\n\t| \"concat\"\n\t| \"flat\"\n\t| \"find\"\n\t| \"findIndex\"\n\t| \"findLast\"\n\t| \"findLastIndex\"\n\t| \"some\"\n\t| \"every\"\n\t| \"indexOf\"\n\t| \"lastIndexOf\"\n\t| \"includes\"\n\t| \"join\"\n\t| \"toString\"\n\t| \"toLocaleString\"\n\n/** Union of all array operation methods handled by the plugin. */\nexport type ArrayOperationMethod = MutatingArrayMethod | NonMutatingArrayMethod\n\n/**\n * Enables optimized array method handling for Immer drafts.\n *\n * This plugin overrides array methods to avoid unnecessary Proxy creation during iteration,\n * significantly improving performance for array-heavy operations.\n *\n * **Mutating methods** (push, pop, shift, unshift, splice, sort, reverse):\n * Operate directly on the copy without creating per-element proxies.\n *\n * **Non-mutating methods** fall into categories:\n * - **Subset operations** (filter, slice, find, findLast): Return draft proxies - mutations track\n * - **Transform operations** (concat, flat): Return base values - mutations don't track\n * - **Primitive-returning** (indexOf, includes, some, every, etc.): Return primitives\n *\n * **Important**: Callbacks for overridden methods receive base values, not drafts.\n * This is the core performance optimization.\n *\n * @example\n * ```ts\n * import { enableArrayMethods, produce } from \"immer\"\n *\n * enableArrayMethods()\n *\n * const next = produce(state, draft => {\n * // Optimized - no proxy creation per element\n * draft.items.sort((a, b) => a.value - b.value)\n *\n * // filter returns drafts - mutations propagate\n * const filtered = draft.items.filter(x => x.value > 5)\n * filtered[0].value = 999 // Affects draft.items[originalIndex]\n * })\n * ```\n *\n * @see https://immerjs.github.io/immer/array-methods\n */\nexport function enableArrayMethods() {\n\tconst SHIFTING_METHODS = new Set([\"shift\", \"unshift\"])\n\n\tconst QUEUE_METHODS = new Set([\"push\", \"pop\"])\n\n\tconst RESULT_RETURNING_METHODS = new Set([\n\t\t...QUEUE_METHODS,\n\t\t...SHIFTING_METHODS\n\t])\n\n\tconst REORDERING_METHODS = new Set([\"reverse\", \"sort\"])\n\n\t// Optimized method detection using array-based lookup\n\tconst MUTATING_METHODS = new Set([\n\t\t...RESULT_RETURNING_METHODS,\n\t\t...REORDERING_METHODS,\n\t\t\"splice\"\n\t])\n\n\tconst FIND_METHODS = new Set([\"find\", \"findLast\"])\n\n\tconst NON_MUTATING_METHODS = new Set([\n\t\t\"filter\",\n\t\t\"slice\",\n\t\t\"concat\",\n\t\t\"flat\",\n\t\t...FIND_METHODS,\n\t\t\"findIndex\",\n\t\t\"findLastIndex\",\n\t\t\"some\",\n\t\t\"every\",\n\t\t\"indexOf\",\n\t\t\"lastIndexOf\",\n\t\t\"includes\",\n\t\t\"join\",\n\t\t\"toString\",\n\t\t\"toLocaleString\"\n\t])\n\n\t// Type guard for method detection\n\tfunction isMutatingArrayMethod(\n\t\tmethod: string\n\t): method is MutatingArrayMethod {\n\t\treturn MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isNonMutatingArrayMethod(\n\t\tmethod: string\n\t): method is NonMutatingArrayMethod {\n\t\treturn NON_MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isArrayOperationMethod(\n\t\tmethod: string\n\t): method is ArrayOperationMethod {\n\t\treturn isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method)\n\t}\n\n\tfunction enterOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: ArrayOperationMethod\n\t) {\n\t\tstate.operationMethod = method\n\t}\n\n\tfunction exitOperation(state: ProxyArrayState) {\n\t\tstate.operationMethod = undefined\n\t}\n\n\t// Shared utility functions for array method handlers\n\tfunction executeArrayMethod(\n\t\tstate: ProxyArrayState,\n\t\toperation: () => T,\n\t\tmarkLength = true\n\t): T {\n\t\tprepareCopy(state)\n\t\tconst result = operation()\n\t\tmarkChanged(state)\n\t\tif (markLength) state.assigned_!.set(\"length\", true)\n\t\treturn result\n\t}\n\n\tfunction markAllIndicesReassigned(state: ProxyArrayState) {\n\t\tstate.allIndicesReassigned_ = true\n\t}\n\n\tfunction normalizeSliceIndex(index: number, length: number): number {\n\t\tif (index < 0) {\n\t\t\treturn Math.max(length + index, 0)\n\t\t}\n\t\treturn Math.min(index, length)\n\t}\n\n\t/**\n\t * Handles mutating operations that add/remove elements (push, pop, shift, unshift, splice).\n\t *\n\t * Operates directly on `state.copy_` without creating per-element proxies.\n\t * For shifting methods (shift, unshift), marks all indices as reassigned since\n\t * indices shift.\n\t *\n\t * @returns For push/pop/shift/unshift: the native method result. For others: the draft.\n\t */\n\tfunction handleSimpleOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(state, () => {\n\t\t\tconst result = (state.copy_! as any)[method](...args)\n\n\t\t\t// Handle index reassignment for shifting methods\n\t\t\tif (SHIFTING_METHODS.has(method as MutatingArrayMethod)) {\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t}\n\n\t\t\t// Return appropriate value based on method\n\t\t\treturn RESULT_RETURNING_METHODS.has(method as MutatingArrayMethod)\n\t\t\t\t? result\n\t\t\t\t: state.draft_\n\t\t})\n\t}\n\n\t/**\n\t * Handles reordering operations (reverse, sort) that change element order.\n\t *\n\t * Operates directly on `state.copy_` and marks all indices as reassigned\n\t * since element positions change. Does not mark length as changed since\n\t * these operations preserve array length.\n\t *\n\t * @returns The draft proxy for method chaining.\n\t */\n\tfunction handleReorderingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(\n\t\t\tstate,\n\t\t\t() => {\n\t\t\t\t;(state.copy_! as any)[method](...args)\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\treturn state.draft_\n\t\t\t},\n\t\t\tfalse\n\t\t) // Don't mark length as changed\n\t}\n\n\t/**\n\t * Creates an interceptor function for a specific array method.\n\t *\n\t * The interceptor wraps array method calls to:\n\t * 1. Set `state.operationMethod` flag during execution (allows proxy `get` trap\n\t * to detect we're inside an optimized method and skip proxy creation)\n\t * 2. Route to appropriate handler based on method type\n\t * 3. Clean up the operation flag in `finally` block\n\t *\n\t * The `operationMethod` flag is the key mechanism that enables the proxy's `get`\n\t * trap to return base values instead of creating nested proxies during iteration.\n\t *\n\t * @param state - The proxy array state\n\t * @param originalMethod - Name of the array method being intercepted\n\t * @returns Interceptor function that handles the method call\n\t */\n\tfunction createMethodInterceptor(\n\t\tstate: ProxyArrayState,\n\t\toriginalMethod: string\n\t) {\n\t\treturn function interceptedMethod(...args: any[]) {\n\t\t\t// Enter operation mode - this flag tells the proxy's get trap to return\n\t\t\t// base values instead of creating nested proxies during iteration\n\t\t\tconst method = originalMethod as ArrayOperationMethod\n\t\t\tenterOperation(state, method)\n\n\t\t\ttry {\n\t\t\t\t// Check if this is a mutating method\n\t\t\t\tif (isMutatingArrayMethod(method)) {\n\t\t\t\t\t// Direct method dispatch - no configuration lookup needed\n\t\t\t\t\tif (RESULT_RETURNING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleSimpleOperation(state, method, args)\n\t\t\t\t\t}\n\t\t\t\t\tif (REORDERING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleReorderingOperation(state, method, args)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"splice\") {\n\t\t\t\t\t\tconst res = executeArrayMethod(state, () =>\n\t\t\t\t\t\t\tstate.copy_!.splice(...(args as [number, number, ...any[]]))\n\t\t\t\t\t\t)\n\t\t\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\t\t\treturn res\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Handle non-mutating methods\n\t\t\t\t\treturn handleNonMutatingOperation(state, method, args)\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\t// Always exit operation mode - must be in finally to handle exceptions\n\t\t\t\texitOperation(state)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles non-mutating array methods with different return semantics.\n\t *\n\t * **Subset operations** return draft proxies for mutation tracking:\n\t * - `filter`, `slice`: Return `state.draft_[i]` for each selected element\n\t * - `find`, `findLast`: Return `state.draft_[i]` for the found element\n\t *\n\t * This allows mutations on returned elements to propagate back to the draft:\n\t * ```ts\n\t * const filtered = draft.items.filter(x => x.value > 5)\n\t * filtered[0].value = 999 // Mutates draft.items[originalIndex]\n\t * ```\n\t *\n\t * **Transform operations** return base values (no draft tracking):\n\t * - `concat`, `flat`: These create NEW arrays rather than selecting subsets.\n\t * Since the result structure differs from the original, tracking mutations\n\t * back to specific draft indices would be impractical/impossible.\n\t *\n\t * **Primitive operations** return the native result directly:\n\t * - `indexOf`, `includes`, `some`, `every`, `join`, etc.\n\t *\n\t * @param state - The proxy array state\n\t * @param method - The non-mutating method name\n\t * @param args - Arguments passed to the method\n\t * @returns Drafts for subset operations, base values for transforms, primitives otherwise\n\t */\n\tfunction handleNonMutatingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: NonMutatingArrayMethod,\n\t\targs: any[]\n\t) {\n\t\tconst source = latest(state)\n\n\t\t// Methods that return arrays with selected items - need to return drafts\n\t\tif (method === \"filter\") {\n\t\t\tconst predicate = args[0]\n\t\t\tconst result: any[] = []\n\n\t\t\t// First pass: call predicate on base values to determine which items pass\n\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\t// Only create draft for items that passed the predicate\n\t\t\t\t\tresult.push(state.draft_[i])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\tif (FIND_METHODS.has(method)) {\n\t\t\tconst predicate = args[0]\n\t\t\tconst isForward = method === \"find\"\n\t\t\tconst step = isForward ? 1 : -1\n\t\t\tconst start = isForward ? 0 : source.length - 1\n\n\t\t\tfor (let i = start; i >= 0 && i < source.length; i += step) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\treturn state.draft_[i]\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (method === \"slice\") {\n\t\t\tconst rawStart = args[0] ?? 0\n\t\t\tconst rawEnd = args[1] ?? source.length\n\n\t\t\t// Normalize negative indices\n\t\t\tconst start = normalizeSliceIndex(rawStart, source.length)\n\t\t\tconst end = normalizeSliceIndex(rawEnd, source.length)\n\n\t\t\tconst result: any[] = []\n\n\t\t\t// Return drafts for items in the slice range\n\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\tresult.push(state.draft_[i])\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\t// For other methods, call on base array directly:\n\t\t// - indexOf, includes, join, toString: Return primitives, no draft needed\n\t\t// - concat, flat: Return NEW arrays (not subsets). Elements are base values.\n\t\t// This is intentional - concat/flat create new data structures rather than\n\t\t// selecting subsets of the original, making draft tracking impractical.\n\t\treturn source[method as keyof typeof Array.prototype](...args)\n\t}\n\n\tloadPlugin(PluginArrayMethods, {\n\t\tcreateMethodInterceptor,\n\t\tisArrayOperationMethod,\n\t\tisMutatingArrayMethod\n\t})\n}\n"],"mappings":"ubAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,WAAAE,GAAA,iBAAAC,GAAA,cAAAC,GAAA,kBAAAC,GAAA,gBAAAC,GAAA,YAAAC,GAAA,uBAAAC,GAAA,iBAAAC,GAAA,kBAAAC,GAAA,gBAAAC,GAAA,WAAAC,EAAA,cAAAC,EAAA,YAAAC,EAAA,gBAAAC,EAAA,cAAAC,GAAA,YAAAC,EAAA,aAAAC,GAAA,YAAAC,GAAA,uBAAAC,GAAA,kBAAAC,GAAA,0BAAAC,GAAA,4BAAAC,KAAA,eAAAC,GAAAxB,ICKO,IAAMyB,EAAyB,OAAO,IAAI,eAAe,EAUnDC,EAA2B,OAAO,IAAI,iBAAiB,EAEvDC,EAA6B,OAAO,IAAI,aAAa,ECuB3D,SAASC,EAAIC,KAAkBC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exports","__export","Immer","applyPatches","castDraft","castImmutable","createDraft","current","enableArrayMethods","enableMapSet","enablePatches","finishDraft","freeze","DRAFTABLE","isDraft","isDraftable","isNothing","NOTHING","original","produce","produceWithPatches","setAutoFreeze","setUseStrictIteration","setUseStrictShallowCopy","__toCommonJS","NOTHING","DRAFTABLE","DRAFT_STATE","die","error","args","O","getPrototypeOf","CONSTRUCTOR","PROTOTYPE","CONFIGURABLE","ENUMERABLE","WRITABLE","VALUE","isDraft","value","DRAFT_STATE","isDraftable","isPlainObject","isArray","DRAFTABLE","isMap","isSet","objectCtorString","cachedCtorStrings","isObjectish","proto","Ctor","isFunction","ctorString","original","die","base_","each","obj","iter","strict","getArchtype","key","entry","index","thing","state","type_","has","prop","type","get","set","propOrOldValue","is","x","y","target","isBoolean","isArrayIndex","n","getProxyDraft","latest","copy_","getValue","proxyDraft","getFinalValue","modified_","shallowCopy","base","isPlain","descriptors","keys","desc","freeze","deep","isFrozen","dontMutateMethodOverride","_key","dontMutateFrozenCollections","PluginMapSet","PluginPatches","PluginArrayMethods","plugins","getPlugin","pluginKey","plugin","die","isPluginLoaded","loadPlugin","pluginKey","implementation","plugins","currentScope","getCurrentScope","createScope","parent_","immer_","drafts_","canAutoFreeze_","unfinalizedDrafts_","handledSet_","processedForPatches_","mapSetPlugin_","isPluginLoaded","PluginMapSet","getPlugin","arrayMethodsPlugin_","PluginArrayMethods","usePatchesInScope","scope","patchListener","patchPlugin_","PluginPatches","patches_","inversePatches_","patchListener_","revokeScope","leaveScope","revokeDraft","enterScope","immer","draft","state","DRAFT_STATE","type_","revoke_","revoked_","processResult","result","scope","unfinalizedDrafts_","drafts_","baseDraft","DRAFT_STATE","modified_","revokeScope","die","isDraftable","finalize","patchPlugin_","generateReplacementPatches_","base_","maybeFreeze","patches_","patchListener_","inversePatches_","NOTHING","rootScope","value","isFrozen","state","handleValue","handledSet_","isSameScope","finalized_","callbacks_","generatePatchesAndFinalize","copy_","deep","parent_","immer_","autoFreeze_","canAutoFreeze_","freeze","markStateFinalized","scope_","EMPTY_LOCATIONS_RESULT","updateDraftInParent","parent","draftValue","finalizedValue","originalKey","parentCopy","latest","parentType","type_","get","set","draftLocations_","draftLocations","each","key","isDraft","keys","locations","location","registerChildFinalizationCallback","child","mapSetPlugin_","getFinalValue","draft_","allIndicesReassigned_","assigned_","basePath","generatePatches_","handleCrossReference","target","prepareCopy","targetCopy","handledSet","updatedValue","createProxyProxy","base","parent","baseIsArray","isArray","state","type_","scope_","getCurrentScope","modified_","finalized_","assigned_","parent_","base_","draft_","copy_","revoke_","isManual_","callbacks_","target","traps","objectTraps","arrayTraps","revoke","proxy","prop","DRAFT_STATE","arrayPlugin","arrayMethodsPlugin_","isArrayWithStringProp","source","latest","has","readPropFromProto","value","isDraftable","isArrayIndex","peek","prepareCopy","childKey","childDraft","createProxy","desc","getDescriptorFromProto","current","currentState","is","markChanged","handleCrossReference","owner","WRITABLE","CONFIGURABLE","ENUMERABLE","VALUE","die","getPrototypeOf","each","key","fn","args","draft","proto","shallowCopy","immer_","useStrictShallowCopy_","Immer","config","autoFreeze_","useStrictShallowCopy_","useStrictIteration_","base","recipe","patchListener","isFunction","defaultBase","self","args","draft","die","result","isDraftable","scope","enterScope","proxy","createProxy","hasError","revokeScope","leaveScope","usePatchesInScope","processResult","isObjectish","NOTHING","freeze","p","ip","getPlugin","PluginPatches","generateReplacementPatches_","patches_","inversePatches_","state","patches","inversePatches","isBoolean","isDraft","current","DRAFT_STATE","isManual_","scope_","value","i","patch","applyPatchesImpl","applyPatches_","rootScope","parent","key","isMap","PluginMapSet","proxyMap_","isSet","proxySet_","createProxyProxy","getCurrentScope","drafts_","callbacks_","key_","registerChildFinalizationCallback","mapSetPlugin_","patchPlugin_","modified_","generatePatches_","current","value","isDraft","die","currentImpl","isDraftable","isFrozen","state","DRAFT_STATE","copy","strict","modified_","base_","finalized_","shallowCopy","scope_","immer_","useStrictShallowCopy_","each","key","childValue","set","enablePatches","getPath","state","path","key_","parentCopy","parent_","copy_","base_","proxyDraft","getProxyDraft","get","valueAtKey","draft_","isSet","type_","key","setParent","drafts_","has","resolvePath","base","current","i","isObjectish","REPLACE","ADD","REMOVE","generatePatches_","basePath","scope","scope_","processedForPatches_","patches_","inversePatches_","generatePatchesFromAssigned","generateArrayPatches","generateSetPatches","patches","inversePatches","assigned_","allReassigned","allIndicesReassigned_","copiedItem","baseItem","childState","DRAFT_STATE","modified_","clonePatchValueIfNeeded","each","assignedValue","origValue","value","op","generateReplacementPatches_","baseValue","replacement","NOTHING","applyPatches_","draft","patch","parentType","getArchtype","p","CONSTRUCTOR","die","isFunction","PROTOTYPE","type","deepClonePatchValue","obj","isDraftable","isArray","isMap","k","v","cloned","getPrototypeOf","DRAFTABLE","isDraft","loadPlugin","PluginPatches","enableMapSet","DraftMap","target","parent","DRAFT_STATE","type_","parent_","scope_","getCurrentScope","modified_","finalized_","copy_","assigned_","base_","draft_","isManual_","revoked_","callbacks_","latest","key","value","state","assertUnrevoked","prepareMapCopy","markChanged","each","cb","thisArg","_value","_map","isDraftable","draft","createProxy","iterator","r","proxyMap_","map","DraftSet","drafts_","prepareSetCopy","result","proxySet_","set","die","fixSetContents","copy","getValue","loadPlugin","PluginMapSet","enableArrayMethods","SHIFTING_METHODS","QUEUE_METHODS","RESULT_RETURNING_METHODS","REORDERING_METHODS","MUTATING_METHODS","FIND_METHODS","NON_MUTATING_METHODS","isMutatingArrayMethod","method","isNonMutatingArrayMethod","isArrayOperationMethod","enterOperation","state","exitOperation","executeArrayMethod","operation","markLength","prepareCopy","result","markChanged","assigned_","markAllIndicesReassigned","allIndicesReassigned_","normalizeSliceIndex","index","length","handleSimpleOperation","args","copy_","draft_","handleReorderingOperation","createMethodInterceptor","originalMethod","res","handleNonMutatingOperation","source","latest","predicate","i","isForward","step","start","rawStart","rawEnd","end","loadPlugin","PluginArrayMethods","immer","Immer","produce","produceWithPatches","setAutoFreeze","setUseStrictShallowCopy","setUseStrictIteration","applyPatches","createDraft","finishDraft","castDraft","value","castImmutable","isNothing","value","NOTHING"]} \ No newline at end of file diff --git a/dist/cjs/index.js b/dist/cjs/index.js new file mode 100644 index 00000000..4ef5ca94 --- /dev/null +++ b/dist/cjs/index.js @@ -0,0 +1,7 @@ +"use strict" + +if (process.env.NODE_ENV === "production") { + module.exports = require("./immer.cjs.production.js") +} else { + module.exports = require("./immer.cjs.development.js") +} diff --git a/dist/cjs/index.js.flow b/dist/cjs/index.js.flow new file mode 100644 index 00000000..5b3d94fa --- /dev/null +++ b/dist/cjs/index.js.flow @@ -0,0 +1,112 @@ +// @flow + +export interface Patch { + op: "replace" | "remove" | "add"; + path: (string | number)[]; + value?: any; +} + +export type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void + +type Base = {...} | Array +interface IProduce { + /** + * Immer takes a state, and runs a function against it. + * That function can freely mutate the state, as it will create copies-on-write. + * This means that the original state will stay unchanged, and once the function finishes, the modified state is returned. + * + * If the first argument is a function, this is interpreted as the recipe, and will create a curried function that will execute the recipe + * any time it is called with the current state. + * + * @param currentState - the state to start with + * @param recipe - function that receives a proxy of the current state as first argument and which can be freely modified + * @param initialState - if a curried function is created and this argument was given, it will be used as fallback if the curried function is called with a state of undefined + * @returns The next state: a new state, or the current state if nothing was modified + */ + ( + currentState: S, + recipe: (draftState: S) => S | void, + patchListener?: PatchListener + ): S; + // curried invocations with initial state + ( + recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void, + initialState: S + ): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => S; + // curried invocations without initial state + ( + recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void + ): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S; +} + +interface IProduceWithPatches { + /** + * Like `produce`, but instead of just returning the new state, + * a tuple is returned with [nextState, patches, inversePatches] + * + * Like produce, this function supports currying + */ + ( + currentState: S, + recipe: (draftState: S) => S | void + ): [S, Patch[], Patch[]]; + // curried invocations with initial state + ( + recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void, + initialState: S + ): (currentState: S | void, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]]; + // curried invocations without initial state + ( + recipe: (draftState: S, a: A, b: B, c: C, ...extraArgs: any[]) => S | void + ): (currentState: S, a: A, b: B, c: C, ...extraArgs: any[]) => [S, Patch[], Patch[]]; +} + +declare export var produce: IProduce + +declare export var produceWithPatches: IProduceWithPatches + +declare export var nothing: typeof undefined + +declare export var immerable: Symbol + +/** + * Automatically freezes any state trees generated by immer. + * This protects against accidental modifications of the state tree outside of an immer function. + * This comes with a performance impact, so it is recommended to disable this option in production. + * By default it is turned on during local development, and turned off in production. + */ +declare export function setAutoFreeze(autoFreeze: boolean): void + +/** + * Pass false to disable strict shallow copy. + * + * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties. + */ +declare export function setUseStrictShallowCopy(useStrictShallowCopy: boolean): void + +declare export function applyPatches(state: S, patches: Patch[]): S + +declare export function original(value: S): S + +declare export function current(value: S): S + +declare export function isDraft(value: any): boolean + +/** + * Creates a mutable draft from an (immutable) object / array. + * The draft can be modified until `finishDraft` is called + */ +declare export function createDraft(base: T): T + +/** + * Given a draft that was created using `createDraft`, + * finalizes the draft into a new immutable object. + * Optionally a patch-listener can be provided to gather the patches that are needed to construct the object. + */ +declare export function finishDraft(base: T, listener?: PatchListener): T + +declare export function enableMapSet(): void +declare export function enablePatches(): void +declare export function enableArrayMethods(): void + +declare export function freeze(obj: T, freeze?: boolean): T diff --git a/dist/immer.d.ts b/dist/immer.d.ts new file mode 100644 index 00000000..2c5aab24 --- /dev/null +++ b/dist/immer.d.ts @@ -0,0 +1,475 @@ +/** + * The sentinel value returned by producers to replace the draft with undefined. + */ +declare const NOTHING: unique symbol +/** + * 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. + */ +declare const DRAFTABLE: unique symbol + +type AnyFunc = (...args: any[]) => any +type PrimitiveType = number | string | boolean +/** Object types that should never be mapped */ +type AtomicObject = Function | Promise | Date | RegExp +/** + * If the lib "ES2015.Collection" is not included in tsconfig.json, + * types like ReadonlyArray, WeakMap etc. fall back to `any` (specified nowhere) + * or `{}` (from the node types), in both cases entering an infinite recursion in + * pattern matching type mappings + * This type can be used to cast these types to `void` in these cases. + */ +type IfAvailable = true | false extends (T extends never + ? true + : false) + ? Fallback + : keyof T extends never + ? Fallback + : T +/** + * These should also never be mapped but must be tested after regular Map and + * Set + */ +type WeakReferences = IfAvailable> | IfAvailable> +type WritableDraft = T extends any[] + ? number extends T["length"] + ? Draft[] + : WritableNonArrayDraft + : WritableNonArrayDraft +type WritableNonArrayDraft = { + -readonly [K in keyof T]: T[K] extends infer V + ? V extends object + ? Draft + : V + : never +} +/** Convert a readonly type into a mutable type, if possible */ +type Draft = T extends PrimitiveType + ? T + : T extends AtomicObject + ? T + : T extends ReadonlyMap + ? Map, Draft> + : T extends ReadonlySet + ? Set> + : T extends WeakReferences + ? T + : T extends object + ? WritableDraft + : T +/** Convert a mutable type into a readonly type */ +type Immutable = T extends PrimitiveType + ? T + : T extends AtomicObject + ? T + : T extends ReadonlyMap + ? ReadonlyMap, Immutable> + : T extends ReadonlySet + ? ReadonlySet> + : T extends WeakReferences + ? T + : T extends object + ? { + readonly [K in keyof T]: Immutable + } + : T +interface Patch { + op: "replace" | "remove" | "add" + path: (string | number)[] + value?: any +} +type PatchListener = (patches: Patch[], inversePatches: Patch[]) => void +/** + * Utility types + */ +type PatchesTuple = readonly [T, Patch[], Patch[]] +type ValidRecipeReturnType = + | State + | void + | undefined + | (State extends undefined ? typeof NOTHING : never) +type ReturnTypeWithPatchesIfNeeded< + State, + UsePatches extends boolean +> = UsePatches extends true ? PatchesTuple : State +/** + * Core Producer inference + */ +type InferRecipeFromCurried = Curried extends ( + base: infer State, + ...rest: infer Args +) => any + ? ReturnType extends State + ? ( + draft: Draft, + ...rest: Args + ) => ValidRecipeReturnType> + : never + : never +type InferInitialStateFromCurried = Curried extends ( + base: infer State, + ...rest: any[] +) => any + ? State + : never +type InferCurriedFromRecipe< + Recipe, + UsePatches extends boolean +> = Recipe extends (draft: infer DraftState, ...args: infer RestArgs) => any + ? ReturnType extends ValidRecipeReturnType + ? ( + base: Immutable, + ...args: RestArgs + ) => ReturnTypeWithPatchesIfNeeded + : never + : never +type InferCurriedFromInitialStateAndRecipe< + State, + Recipe, + UsePatches extends boolean +> = Recipe extends ( + draft: Draft, + ...rest: infer RestArgs +) => ValidRecipeReturnType + ? ( + base?: State | undefined, + ...args: RestArgs + ) => ReturnTypeWithPatchesIfNeeded + : never +/** + * 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 + */ +interface IProduce { + /** Curried producer that infers the recipe from the curried output function (e.g. when passing to setState) */ + ( + recipe: InferRecipeFromCurried, + initialState?: InferInitialStateFromCurried + ): Curried + /** Curried producer that infers curried from the recipe */ + (recipe: Recipe): InferCurriedFromRecipe< + Recipe, + false + > + /** Curried producer that infers curried from the State generic, which is explicitly passed in. */ + ( + recipe: ( + state: Draft, + initialState: State + ) => ValidRecipeReturnType + ): (state?: State) => State + ( + recipe: ( + state: Draft, + ...args: Args + ) => ValidRecipeReturnType, + initialState: State + ): (state?: State, ...args: Args) => State + (recipe: (state: Draft) => ValidRecipeReturnType): ( + state: State + ) => State + ( + recipe: (state: Draft, ...args: Args) => ValidRecipeReturnType + ): (state: State, ...args: Args) => State + /** Curried producer with initial state, infers recipe from initial state */ + ( + recipe: Recipe, + initialState: State + ): InferCurriedFromInitialStateAndRecipe + /** Normal producer */ + >( // By using a default inferred D, rather than Draft in the recipe, we can override it. + base: Base, + recipe: (draft: D) => ValidRecipeReturnType, + listener?: PatchListener + ): Base +} +/** + * Like `produce`, but instead of just returning the new state, + * a tuple is returned with [nextState, patches, inversePatches] + * + * Like produce, this function supports currying + */ +interface IProduceWithPatches { + (recipe: Recipe): InferCurriedFromRecipe + ( + recipe: Recipe, + initialState: State + ): InferCurriedFromInitialStateAndRecipe + >( + base: Base, + recipe: (draft: D) => ValidRecipeReturnType, + listener?: PatchListener + ): PatchesTuple +} +/** + * The type for `recipe function` + */ +type Producer = (draft: Draft) => ValidRecipeReturnType> + +type Objectish = AnyObject | AnyArray | AnyMap | AnySet +type AnyObject = { + [key: string]: any +} +type AnyArray = Array +type AnySet = Set +type AnyMap = Map + +/** Returns true if the given value is an Immer draft */ +declare let isDraft: (value: any) => boolean +/** Returns true if the given value can be drafted by Immer */ +declare function isDraftable(value: any): boolean +/** Get the underlying object that is represented by the given draft */ +declare function original(value: T): T | undefined +/** + * Freezes draftable objects. Returns the original object. + * By default freezes shallowly, but if the second argument is `true` it will freeze recursively. + * + * @param obj + * @param deep + */ +declare function freeze(obj: T, deep?: boolean): T + +interface ProducersFns { + produce: IProduce + produceWithPatches: IProduceWithPatches +} +type StrictMode = boolean | "class_only" +declare class Immer implements ProducersFns { + autoFreeze_: boolean + useStrictShallowCopy_: StrictMode + useStrictIteration_: boolean + constructor(config?: { + autoFreeze?: boolean + useStrictShallowCopy?: StrictMode + useStrictIteration?: boolean + }) + /** + * 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 + */ + produce: IProduce + produceWithPatches: IProduceWithPatches + createDraft(base: T): Draft + finishDraft>( + draft: D, + patchListener?: PatchListener + ): D extends Draft ? T : never + /** + * Pass true to automatically freeze all copies created by Immer. + * + * By default, auto-freezing is enabled. + */ + setAutoFreeze(value: boolean): void + /** + * Pass true to enable strict shallow copy. + * + * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties. + */ + setUseStrictShallowCopy(value: StrictMode): void + /** + * Pass false to use faster iteration that skips non-enumerable properties + * but still handles symbols for compatibility. + * + * By default, strict iteration is enabled (includes all own properties). + */ + setUseStrictIteration(value: boolean): void + shouldUseStrictIteration(): boolean + applyPatches(base: T, patches: readonly Patch[]): T +} + +/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */ +declare function current(value: T): T + +declare function enablePatches(): void + +declare function enableMapSet(): void + +/** + * Enables optimized array method handling for Immer drafts. + * + * This plugin overrides array methods to avoid unnecessary Proxy creation during iteration, + * significantly improving performance for array-heavy operations. + * + * **Mutating methods** (push, pop, shift, unshift, splice, sort, reverse): + * Operate directly on the copy without creating per-element proxies. + * + * **Non-mutating methods** fall into categories: + * - **Subset operations** (filter, slice, find, findLast): Return draft proxies - mutations track + * - **Transform operations** (concat, flat): Return base values - mutations don't track + * - **Primitive-returning** (indexOf, includes, some, every, etc.): Return primitives + * + * **Important**: Callbacks for overridden methods receive base values, not drafts. + * This is the core performance optimization. + * + * @example + * ```ts + * import { enableArrayMethods, produce } from "immer" + * + * enableArrayMethods() + * + * const next = produce(state, draft => { + * // Optimized - no proxy creation per element + * draft.items.sort((a, b) => a.value - b.value) + * + * // filter returns drafts - mutations propagate + * const filtered = draft.items.filter(x => x.value > 5) + * filtered[0].value = 999 // Affects draft.items[originalIndex] + * }) + * ``` + * + * @see https://immerjs.github.io/immer/array-methods + */ +declare function enableArrayMethods(): void + +/** + * 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 + */ +declare const produce: IProduce +/** + * Like `produce`, but `produceWithPatches` always returns a tuple + * [nextState, patches, inversePatches] (instead of just the next state) + */ +declare const produceWithPatches: IProduceWithPatches +/** + * Pass true to automatically freeze all copies created by Immer. + * + * Always freeze by default, even in production mode + */ +declare const setAutoFreeze: (value: boolean) => void +/** + * Pass true to enable strict shallow copy. + * + * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties. + */ +declare const setUseStrictShallowCopy: (value: StrictMode) => void +/** + * Pass false to use loose iteration that only processes enumerable string properties. + * This skips symbols and non-enumerable properties for maximum performance. + * + * By default, strict iteration is enabled (includes all own properties). + */ +declare const setUseStrictIteration: (value: boolean) => void +/** + * Apply an array of Immer patches to the first argument. + * + * This function is a producer, which means copy-on-write is in effect. + */ +declare const applyPatches: ( + base: T, + patches: readonly Patch[] +) => T +/** + * 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. + */ +declare const createDraft: (base: T) => Draft +/** + * 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. + */ +declare const finishDraft: ( + draft: D, + patchListener?: PatchListener | undefined +) => D extends Draft ? T : never +/** + * 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 + */ +declare let castDraft: (value: T) => Draft +/** + * 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 + */ +declare let castImmutable: (value: T) => Immutable + +declare function isNothing(value: unknown): value is typeof NOTHING + +export { + Draft, + Immer, + Immutable, + Objectish, + Patch, + PatchListener, + Producer, + StrictMode, + WritableDraft, + applyPatches, + castDraft, + castImmutable, + createDraft, + current, + enableArrayMethods, + enableMapSet, + enablePatches, + finishDraft, + freeze, + DRAFTABLE as immerable, + isDraft, + isDraftable, + isNothing, + NOTHING as nothing, + original, + produce, + produceWithPatches, + setAutoFreeze, + setUseStrictIteration, + setUseStrictShallowCopy +} diff --git a/dist/immer.legacy-esm.js b/dist/immer.legacy-esm.js new file mode 100644 index 00000000..1e2c61ce --- /dev/null +++ b/dist/immer.legacy-esm.js @@ -0,0 +1,1718 @@ +var __defProp = Object.defineProperty +var __getOwnPropSymbols = Object.getOwnPropertySymbols +var __hasOwnProp = Object.prototype.hasOwnProperty +var __propIsEnum = Object.prototype.propertyIsEnumerable +var __defNormalProp = (obj, key, value) => + key in obj + ? __defProp(obj, key, { + enumerable: true, + configurable: true, + writable: true, + value + }) + : (obj[key] = value) +var __spreadValues = (a, b) => { + for (var prop in b || (b = {})) + if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]) + if (__getOwnPropSymbols) + for (var prop of __getOwnPropSymbols(b)) { + if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]) + } + return a +} + +// src/utils/env.ts +var NOTHING = Symbol.for("immer-nothing") +var DRAFTABLE = Symbol.for("immer-draftable") +var DRAFT_STATE = Symbol.for("immer-state") + +// src/utils/errors.ts +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, ...args) { + if (process.env.NODE_ENV !== "production") { + const e = errors[error] + const msg = isFunction(e) ? 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` + ) +} + +// src/utils/common.ts +var O = Object +var getPrototypeOf = O.getPrototypeOf +var CONSTRUCTOR = "constructor" +var PROTOTYPE = "prototype" +var CONFIGURABLE = "configurable" +var ENUMERABLE = "enumerable" +var WRITABLE = "writable" +var VALUE = "value" +var isDraft = value => !!value && !!value[DRAFT_STATE] +function isDraftable(value) { + var _a + if (!value) return false + return ( + isPlainObject(value) || + isArray(value) || + !!value[DRAFTABLE] || + !!((_a = value[CONSTRUCTOR]) == null ? void 0 : _a[DRAFTABLE]) || + isMap(value) || + isSet(value) + ) +} +var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString() +var cachedCtorStrings = /* @__PURE__ */ new WeakMap() +function isPlainObject(value) { + if (!value || !isObjectish(value)) return false + const proto = getPrototypeOf(value) + if (proto === null || proto === O[PROTOTYPE]) return true + const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR] + if (Ctor === Object) return true + if (!isFunction(Ctor)) return false + let ctorString = cachedCtorStrings.get(Ctor) + if (ctorString === void 0) { + ctorString = Function.toString.call(Ctor) + cachedCtorStrings.set(Ctor, ctorString) + } + return ctorString === objectCtorString +} +function original(value) { + if (!isDraft(value)) die(15, value) + return value[DRAFT_STATE].base_ +} +function each(obj, iter, strict = true) { + if (getArchtype(obj) === 0 /* Object */) { + const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj) + keys.forEach(key => { + iter(key, obj[key], obj) + }) + } else { + obj.forEach((entry, index) => iter(index, entry, obj)) + } +} +function getArchtype(thing) { + const state = thing[DRAFT_STATE] + return state + ? state.type_ + : isArray(thing) + ? 1 /* Array */ + : isMap(thing) + ? 2 /* Map */ + : isSet(thing) + ? 3 /* Set */ + : 0 /* Object */ +} +var has = (thing, prop, type = getArchtype(thing)) => + type === 2 /* Map */ + ? thing.has(prop) + : O[PROTOTYPE].hasOwnProperty.call(thing, prop) +var get = (thing, prop, type = getArchtype(thing)) => + // @ts-ignore + type === 2 /* Map */ ? thing.get(prop) : thing[prop] +var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => { + if (type === 2 /* Map */) thing.set(propOrOldValue, value) + else if (type === 3 /* Set */) { + thing.add(value) + } else thing[propOrOldValue] = value +} +function is(x, y) { + if (x === y) { + return x !== 0 || 1 / x === 1 / y + } else { + return x !== x && y !== y + } +} +var isArray = Array.isArray +var isMap = target => target instanceof Map +var isSet = target => target instanceof Set +var isObjectish = target => typeof target === "object" +var isFunction = target => typeof target === "function" +var isBoolean = target => typeof target === "boolean" +function isArrayIndex(value) { + const n = +value + return Number.isInteger(n) && String(n) === value +} +var getProxyDraft = value => { + if (!isObjectish(value)) return null + return value == null ? void 0 : value[DRAFT_STATE] +} +var latest = state => state.copy_ || state.base_ +var getValue = value => { + var _a + const proxyDraft = getProxyDraft(value) + return proxyDraft + ? (_a = proxyDraft.copy_) != null + ? _a + : proxyDraft.base_ + : value +} +var getFinalValue = state => (state.modified_ ? state.copy_ : state.base_) +function shallowCopy(base, strict) { + if (isMap(base)) { + return new Map(base) + } + if (isSet(base)) { + return new Set(base) + } + if (isArray(base)) return Array[PROTOTYPE].slice.call(base) + const isPlain = isPlainObject(base) + if (strict === true || (strict === "class_only" && !isPlain)) { + const descriptors = O.getOwnPropertyDescriptors(base) + delete descriptors[DRAFT_STATE] + let keys = Reflect.ownKeys(descriptors) + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + const desc = descriptors[key] + if (desc[WRITABLE] === false) { + desc[WRITABLE] = true + desc[CONFIGURABLE] = true + } + if (desc.get || desc.set) + descriptors[key] = { + [CONFIGURABLE]: true, + [WRITABLE]: true, + // could live with !!desc.set as well here... + [ENUMERABLE]: desc[ENUMERABLE], + [VALUE]: base[key] + } + } + return O.create(getPrototypeOf(base), descriptors) + } else { + const proto = getPrototypeOf(base) + if (proto !== null && isPlain) { + return __spreadValues({}, base) + } + const obj = O.create(proto) + return O.assign(obj, base) + } +} +function freeze(obj, deep = false) { + if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj + if (getArchtype(obj) > 1) { + O.defineProperties(obj, { + set: dontMutateMethodOverride, + add: dontMutateMethodOverride, + clear: dontMutateMethodOverride, + delete: dontMutateMethodOverride + }) + } + O.freeze(obj) + if (deep) + each( + obj, + (_key, value) => { + freeze(value, true) + }, + false + ) + return obj +} +function dontMutateFrozenCollections() { + die(2) +} +var dontMutateMethodOverride = { + [VALUE]: dontMutateFrozenCollections +} +function isFrozen(obj) { + if (obj === null || !isObjectish(obj)) return true + return O.isFrozen(obj) +} + +// src/utils/plugins.ts +var PluginMapSet = "MapSet" +var PluginPatches = "Patches" +var PluginArrayMethods = "ArrayMethods" +var plugins = {} +function getPlugin(pluginKey) { + const plugin = plugins[pluginKey] + if (!plugin) { + die(0, pluginKey) + } + return plugin +} +var isPluginLoaded = pluginKey => !!plugins[pluginKey] +function loadPlugin(pluginKey, implementation) { + if (!plugins[pluginKey]) plugins[pluginKey] = implementation +} + +// src/core/scope.ts +var currentScope +var getCurrentScope = () => currentScope +var createScope = (parent_, immer_) => ({ + drafts_: [], + parent_, + 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, + handledSet_: /* @__PURE__ */ new Set(), + processedForPatches_: /* @__PURE__ */ new Set(), + mapSetPlugin_: isPluginLoaded(PluginMapSet) + ? getPlugin(PluginMapSet) + : void 0, + arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) + ? getPlugin(PluginArrayMethods) + : void 0 +}) +function usePatchesInScope(scope, patchListener) { + if (patchListener) { + scope.patchPlugin_ = getPlugin(PluginPatches) + scope.patches_ = [] + scope.inversePatches_ = [] + scope.patchListener_ = patchListener + } +} +function revokeScope(scope) { + leaveScope(scope) + scope.drafts_.forEach(revokeDraft) + scope.drafts_ = null +} +function leaveScope(scope) { + if (scope === currentScope) { + currentScope = scope.parent_ + } +} +var enterScope = immer2 => (currentScope = createScope(currentScope, immer2)) +function revokeDraft(draft) { + const state = draft[DRAFT_STATE] + if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) + state.revoke_() + else state.revoked_ = true +} + +// src/core/finalize.ts +function processResult(result, scope) { + scope.unfinalizedDrafts_ = scope.drafts_.length + const baseDraft = scope.drafts_[0] + const isReplaced = result !== void 0 && result !== baseDraft + if (isReplaced) { + if (baseDraft[DRAFT_STATE].modified_) { + revokeScope(scope) + die(4) + } + if (isDraftable(result)) { + result = finalize(scope, result) + } + const {patchPlugin_} = scope + if (patchPlugin_) { + patchPlugin_.generateReplacementPatches_( + baseDraft[DRAFT_STATE].base_, + result, + scope + ) + } + } else { + result = finalize(scope, baseDraft) + } + maybeFreeze(scope, result, true) + revokeScope(scope) + if (scope.patches_) { + scope.patchListener_(scope.patches_, scope.inversePatches_) + } + return result !== NOTHING ? result : void 0 +} +function finalize(rootScope, value) { + if (isFrozen(value)) return value + const state = value[DRAFT_STATE] + if (!state) { + const finalValue = handleValue(value, rootScope.handledSet_, rootScope) + return finalValue + } + if (!isSameScope(state, rootScope)) { + return value + } + if (!state.modified_) { + return state.base_ + } + if (!state.finalized_) { + const {callbacks_} = state + if (callbacks_) { + while (callbacks_.length > 0) { + const callback = callbacks_.pop() + callback(rootScope) + } + } + generatePatchesAndFinalize(state, rootScope) + } + return state.copy_ +} +function maybeFreeze(scope, value, deep = false) { + if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) { + freeze(value, deep) + } +} +function markStateFinalized(state) { + state.finalized_ = true + state.scope_.unfinalizedDrafts_-- +} +var isSameScope = (state, rootScope) => state.scope_ === rootScope +var EMPTY_LOCATIONS_RESULT = [] +function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) { + var _a + const parentCopy = latest(parent) + const parentType = parent.type_ + if (originalKey !== void 0) { + const currentValue = get(parentCopy, originalKey, parentType) + if (currentValue === draftValue) { + set(parentCopy, originalKey, finalizedValue, parentType) + return + } + } + if (!parent.draftLocations_) { + const draftLocations = (parent.draftLocations_ = /* @__PURE__ */ new Map()) + each(parentCopy, (key, value) => { + if (isDraft(value)) { + const keys = draftLocations.get(value) || [] + keys.push(key) + draftLocations.set(value, keys) + } + }) + } + const locations = + (_a = parent.draftLocations_.get(draftValue)) != null + ? _a + : EMPTY_LOCATIONS_RESULT + for (const location of locations) { + set(parentCopy, location, finalizedValue, parentType) + } +} +function registerChildFinalizationCallback(parent, child, key) { + parent.callbacks_.push(function childCleanup(rootScope) { + var _a, _b + const state = child + if (!state || !isSameScope(state, rootScope)) { + return + } + ;(_a = rootScope.mapSetPlugin_) == null ? void 0 : _a.fixSetContents(state) + const finalizedValue = getFinalValue(state) + updateDraftInParent( + parent, + (_b = state.draft_) != null ? _b : state, + finalizedValue, + key + ) + generatePatchesAndFinalize(state, rootScope) + }) +} +function generatePatchesAndFinalize(state, rootScope) { + var _a, _b + const shouldFinalize = + state.modified_ && + !state.finalized_ && + (state.type_ === 3 /* Set */ || + (state.type_ === 1 /* Array */ && state.allIndicesReassigned_) || + ((_b = (_a = state.assigned_) == null ? void 0 : _a.size) != null + ? _b + : 0) > 0) + if (shouldFinalize) { + const {patchPlugin_} = rootScope + if (patchPlugin_) { + const basePath = patchPlugin_.getPath(state) + if (basePath) { + patchPlugin_.generatePatches_(state, basePath, rootScope) + } + } + markStateFinalized(state) + } +} +function handleCrossReference(target, key, value) { + const {scope_} = target + if (isDraft(value)) { + const state = value[DRAFT_STATE] + if (isSameScope(state, scope_)) { + state.callbacks_.push(function crossReferenceCleanup() { + prepareCopy(target) + const finalizedValue = getFinalValue(state) + updateDraftInParent(target, value, finalizedValue, key) + }) + } + } else if (isDraftable(value)) { + target.callbacks_.push(function nestedDraftCleanup() { + var _a + const targetCopy = latest(target) + if (get(targetCopy, key, target.type_) === value) { + if ( + scope_.drafts_.length > 1 && + ((_a = target.assigned_.get(key)) != null ? _a : false) === true && + target.copy_ + ) { + handleValue( + get(target.copy_, key, target.type_), + scope_.handledSet_, + scope_ + ) + } + } + }) + } +} +function handleValue(target, handledSet, rootScope) { + if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) { + return target + } + if ( + isDraft(target) || + handledSet.has(target) || + !isDraftable(target) || + isFrozen(target) + ) { + return target + } + handledSet.add(target) + each(target, (key, value) => { + if (isDraft(value)) { + const state = value[DRAFT_STATE] + if (isSameScope(state, rootScope)) { + const updatedValue = getFinalValue(state) + set(target, key, updatedValue, target.type_) + markStateFinalized(state) + } + } else if (isDraftable(value)) { + handleValue(value, handledSet, rootScope) + } + }) + return target +} + +// src/core/proxy.ts +function createProxyProxy(base, parent) { + const baseIsArray = isArray(base) + const state = { + type_: baseIsArray ? 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). + // actually instantiated in `prepareCopy()` + assigned_: void 0, + // The parent draft state. + parent_: parent, + // The base state. + base_: base, + // The base proxy. + draft_: null, + // set below + // The base copy with any updated values. + copy_: null, + // Called by the `produce` function. + revoke_: null, + isManual_: false, + // `callbacks` actually gets assigned in `createProxy` + callbacks_: void 0 + } + let target = state + let traps = objectTraps + if (baseIsArray) { + target = [state] + traps = arrayTraps + } + const {revoke, proxy} = Proxy.revocable(target, traps) + state.draft_ = proxy + state.revoke_ = revoke + return [proxy, state] +} +var objectTraps = { + get(state, prop) { + if (prop === DRAFT_STATE) return state + let arrayPlugin = state.scope_.arrayMethodsPlugin_ + const isArrayWithStringProp = + state.type_ === 1 /* Array */ && typeof prop === "string" + if (isArrayWithStringProp) { + if ( + arrayPlugin == null ? void 0 : arrayPlugin.isArrayOperationMethod(prop) + ) { + return arrayPlugin.createMethodInterceptor(state, prop) + } + } + const source = latest(state) + if (!has(source, prop, state.type_)) { + return readPropFromProto(state, source, prop) + } + const value = source[prop] + if (state.finalized_ || !isDraftable(value)) { + return value + } + if ( + isArrayWithStringProp && + state.operationMethod && + (arrayPlugin == null + ? void 0 + : arrayPlugin.isMutatingArrayMethod(state.operationMethod)) && + isArrayIndex(prop) + ) { + return value + } + if (value === peek(state.base_, prop)) { + prepareCopy(state) + const childKey = state.type_ === 1 /* Array */ ? +prop : prop + const childDraft = createProxy(state.scope_, value, state, childKey) + return (state.copy_[childKey] = childDraft) + } + return value + }, + has(state, prop) { + return prop in latest(state) + }, + ownKeys(state) { + return Reflect.ownKeys(latest(state)) + }, + set(state, prop, value) { + const desc = getDescriptorFromProto(latest(state), prop) + if (desc == null ? void 0 : desc.set) { + desc.set.call(state.draft_, value) + return true + } + if (!state.modified_) { + const current2 = peek(latest(state), prop) + const currentState = current2 == null ? void 0 : current2[DRAFT_STATE] + if (currentState && currentState.base_ === value) { + state.copy_[prop] = value + state.assigned_.set(prop, false) + return true + } + if ( + is(value, current2) && + (value !== void 0 || has(state.base_, prop, state.type_)) + ) + return true + prepareCopy(state) + markChanged(state) + } + if ( + (state.copy_[prop] === value && // special case: handle new props with value 'undefined' + (value !== void 0 || prop in state.copy_)) || // special case: NaN + (Number.isNaN(value) && Number.isNaN(state.copy_[prop])) + ) + return true + state.copy_[prop] = value + state.assigned_.set(prop, true) + handleCrossReference(state, prop, value) + return true + }, + deleteProperty(state, prop) { + prepareCopy(state) + if (peek(state.base_, prop) !== void 0 || prop in state.base_) { + state.assigned_.set(prop, false) + markChanged(state) + } else { + state.assigned_.delete(prop) + } + if (state.copy_) { + 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(state, prop) { + const owner = latest(state) + const 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() { + die(11) + }, + getPrototypeOf(state) { + return getPrototypeOf(state.base_) + }, + setPrototypeOf() { + die(12) + } +} +var arrayTraps = {} +each(objectTraps, (key, fn) => { + arrayTraps[key] = function() { + const args = arguments + args[0] = args[0][0] + return fn.apply(this, args) + } +}) +arrayTraps.deleteProperty = function(state, prop) { + if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13) + return arrayTraps.set.call(this, state, prop, void 0) +} +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]) +} +function peek(draft, prop) { + const state = draft[DRAFT_STATE] + const source = state ? latest(state) : draft + return source[prop] +} +function readPropFromProto(state, source, prop) { + var _a + const 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! + (_a = desc.get) == null + ? void 0 + : _a.call(state.draft_) + : void 0 +} +function getDescriptorFromProto(source, prop) { + if (!(prop in source)) return void 0 + let proto = getPrototypeOf(source) + while (proto) { + const desc = Object.getOwnPropertyDescriptor(proto, prop) + if (desc) return desc + proto = getPrototypeOf(proto) + } + return void 0 +} +function markChanged(state) { + if (!state.modified_) { + state.modified_ = true + if (state.parent_) { + markChanged(state.parent_) + } + } +} +function prepareCopy(state) { + if (!state.copy_) { + state.assigned_ = /* @__PURE__ */ new Map() + state.copy_ = shallowCopy( + state.base_, + state.scope_.immer_.useStrictShallowCopy_ + ) + } +} + +// src/core/immerClass.ts +var Immer2 = class { + constructor(config) { + this.autoFreeze_ = true + this.useStrictShallowCopy_ = false + this.useStrictIteration_ = 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 = (base, recipe, patchListener) => { + if (isFunction(base) && !isFunction(recipe)) { + const defaultBase = recipe + recipe = base + const self = this + return function curriedProduce(base2 = defaultBase, ...args) { + return self.produce(base2, draft => recipe.call(this, draft, ...args)) + } + } + if (!isFunction(recipe)) die(6) + if (patchListener !== void 0 && !isFunction(patchListener)) die(7) + let result + if (isDraftable(base)) { + const scope = enterScope(this) + const proxy = createProxy(scope, base, void 0) + let hasError = true + try { + result = recipe(proxy) + hasError = false + } finally { + if (hasError) revokeScope(scope) + else leaveScope(scope) + } + usePatchesInScope(scope, patchListener) + return processResult(result, scope) + } else if (!base || !isObjectish(base)) { + result = recipe(base) + if (result === void 0) result = base + if (result === NOTHING) result = void 0 + if (this.autoFreeze_) freeze(result, true) + if (patchListener) { + const p = [] + const ip = [] + getPlugin(PluginPatches).generateReplacementPatches_(base, result, { + patches_: p, + inversePatches_: ip + }) + patchListener(p, ip) + } + return result + } else die(1, base) + } + this.produceWithPatches = (base, recipe) => { + if (isFunction(base)) { + return (state, ...args) => + this.produceWithPatches(state, draft => base(draft, ...args)) + } + let patches, inversePatches + const result = this.produce(base, recipe, (p, ip) => { + patches = p + inversePatches = ip + }) + return [result, patches, inversePatches] + } + if (isBoolean(config == null ? void 0 : config.autoFreeze)) + this.setAutoFreeze(config.autoFreeze) + if (isBoolean(config == null ? void 0 : config.useStrictShallowCopy)) + this.setUseStrictShallowCopy(config.useStrictShallowCopy) + if (isBoolean(config == null ? void 0 : config.useStrictIteration)) + this.setUseStrictIteration(config.useStrictIteration) + } + createDraft(base) { + if (!isDraftable(base)) die(8) + if (isDraft(base)) base = current(base) + const scope = enterScope(this) + const proxy = createProxy(scope, base, void 0) + proxy[DRAFT_STATE].isManual_ = true + leaveScope(scope) + return proxy + } + finishDraft(draft, patchListener) { + const state = draft && draft[DRAFT_STATE] + if (!state || !state.isManual_) die(9) + const {scope_: scope} = state + usePatchesInScope(scope, patchListener) + return processResult(void 0, scope) + } + /** + * Pass true to automatically freeze all copies created by Immer. + * + * By default, auto-freezing is enabled. + */ + 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. + */ + setUseStrictShallowCopy(value) { + this.useStrictShallowCopy_ = value + } + /** + * Pass false to use faster iteration that skips non-enumerable properties + * but still handles symbols for compatibility. + * + * By default, strict iteration is enabled (includes all own properties). + */ + setUseStrictIteration(value) { + this.useStrictIteration_ = value + } + shouldUseStrictIteration() { + return this.useStrictIteration_ + } + applyPatches(base, patches) { + let i + for (i = patches.length - 1; i >= 0; i--) { + const patch = patches[i] + if (patch.path.length === 0 && patch.op === "replace") { + base = patch.value + break + } + } + if (i > -1) { + patches = patches.slice(i + 1) + } + const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_ + if (isDraft(base)) { + return applyPatchesImpl(base, patches) + } + return this.produce(base, draft => applyPatchesImpl(draft, patches)) + } +} +function createProxy(rootScope, value, parent, key) { + var _a, _b + const [draft, state] = isMap(value) + ? getPlugin(PluginMapSet).proxyMap_(value, parent) + : isSet(value) + ? getPlugin(PluginMapSet).proxySet_(value, parent) + : createProxyProxy(value, parent) + const scope = + (_a = parent == null ? void 0 : parent.scope_) != null + ? _a + : getCurrentScope() + scope.drafts_.push(draft) + state.callbacks_ = + (_b = parent == null ? void 0 : parent.callbacks_) != null ? _b : [] + state.key_ = key + if (parent && key !== void 0) { + registerChildFinalizationCallback(parent, state, key) + } else { + state.callbacks_.push(function rootDraftCleanup(rootScope2) { + var _a2 + ;(_a2 = rootScope2.mapSetPlugin_) == null + ? void 0 + : _a2.fixSetContents(state) + const {patchPlugin_} = rootScope2 + if (state.modified_ && patchPlugin_) { + patchPlugin_.generatePatches_(state, [], rootScope2) + } + }) + } + return draft +} + +// src/core/current.ts +function current(value) { + if (!isDraft(value)) die(10, value) + return currentImpl(value) +} +function currentImpl(value) { + if (!isDraftable(value) || isFrozen(value)) return value + const state = value[DRAFT_STATE] + let copy + let strict = true + if (state) { + if (!state.modified_) return state.base_ + state.finalized_ = true + copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_) + strict = state.scope_.immer_.shouldUseStrictIteration() + } else { + copy = shallowCopy(value, true) + } + each( + copy, + (key, childValue) => { + set(copy, key, currentImpl(childValue)) + }, + strict + ) + if (state) { + state.finalized_ = false + } + return copy +} + +// src/plugins/patches.ts +function enablePatches() { + const 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" + ) + } + function getPath(state, path = []) { + var _a + if ("key_" in state && state.key_ !== void 0) { + const parentCopy = + (_a = state.parent_.copy_) != null ? _a : state.parent_.base_ + const proxyDraft = getProxyDraft(get(parentCopy, state.key_)) + const valueAtKey = get(parentCopy, state.key_) + if (valueAtKey === void 0) { + return null + } + if ( + valueAtKey !== state.draft_ && + valueAtKey !== state.base_ && + valueAtKey !== state.copy_ + ) { + return null + } + if (proxyDraft != null && proxyDraft.base_ !== state.base_) { + return null + } + const isSet2 = state.parent_.type_ === 3 /* Set */ + let key + if (isSet2) { + const setParent = state.parent_ + key = Array.from(setParent.drafts_.keys()).indexOf(state.key_) + } else { + key = state.key_ + } + if (!((isSet2 && parentCopy.size > key) || has(parentCopy, key))) { + return null + } + path.push(key) + } + if (state.parent_) { + return getPath(state.parent_, path) + } + path.reverse() + try { + resolvePath(state.copy_, path) + } catch (e) { + return null + } + return path + } + function resolvePath(base, path) { + let current2 = base + for (let i = 0; i < path.length - 1; i++) { + const key = path[i] + current2 = get(current2, key) + if (!isObjectish(current2) || current2 === null) { + throw new Error(`Cannot resolve path at '${path.join("/")}'`) + } + } + return current2 + } + const REPLACE = "replace" + const ADD = "add" + const REMOVE = "remove" + function generatePatches_(state, basePath, scope) { + if (state.scope_.processedForPatches_.has(state)) { + return + } + state.scope_.processedForPatches_.add(state) + const {patches_, inversePatches_} = scope + 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) { + let {base_, assigned_} = state + let copy_ = state.copy_ + if (copy_.length < base_.length) { + ;[base_, copy_] = [copy_, base_] + ;[patches, inversePatches] = [inversePatches, patches] + } + const allReassigned = state.allIndicesReassigned_ === true + for (let i = 0; i < base_.length; i++) { + const copiedItem = copy_[i] + const baseItem = base_[i] + const isAssigned = + allReassigned || + (assigned_ == null ? void 0 : assigned_.get(i.toString())) + if (isAssigned && copiedItem !== baseItem) { + const childState = copiedItem == null ? void 0 : copiedItem[DRAFT_STATE] + if (childState && childState.modified_) { + continue + } + const path = basePath.concat([i]) + patches.push({ + op: REPLACE, + 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(copiedItem) + }) + inversePatches.push({ + op: REPLACE, + path, + value: clonePatchValueIfNeeded(baseItem) + }) + } + } + for (let i = base_.length; i < copy_.length; i++) { + const path = basePath.concat([i]) + patches.push({ + op: ADD, + 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 (let i = copy_.length - 1; base_.length <= i; --i) { + const path = basePath.concat([i]) + inversePatches.push({ + op: REMOVE, + path + }) + } + } + function generatePatchesFromAssigned( + state, + basePath, + patches, + inversePatches + ) { + const {base_, copy_, type_} = state + each(state.assigned_, (key, assignedValue) => { + const origValue = get(base_, key, type_) + const value = get(copy_, key, type_) + const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD + if (origValue === value && op === REPLACE) return + const path = basePath.concat(key) + patches.push( + op === REMOVE + ? {op, path} + : {op, path, value: clonePatchValueIfNeeded(value)} + ) + inversePatches.push( + op === ADD + ? {op: REMOVE, path} + : op === REMOVE + ? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)} + : {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)} + ) + }) + } + function generateSetPatches(state, basePath, patches, inversePatches) { + let {base_, copy_} = state + let i = 0 + base_.forEach(value => { + if (!copy_.has(value)) { + const path = basePath.concat([i]) + patches.push({ + op: REMOVE, + path, + value + }) + inversePatches.unshift({ + op: ADD, + path, + value + }) + } + i++ + }) + i = 0 + copy_.forEach(value => { + if (!base_.has(value)) { + const path = basePath.concat([i]) + patches.push({ + op: ADD, + path, + value + }) + inversePatches.unshift({ + op: REMOVE, + path, + value + }) + } + i++ + }) + } + function generateReplacementPatches_(baseValue, replacement, scope) { + const {patches_, inversePatches_} = scope + patches_.push({ + op: REPLACE, + path: [], + value: replacement === NOTHING ? void 0 : replacement + }) + inversePatches_.push({ + op: REPLACE, + path: [], + value: baseValue + }) + } + function applyPatches_(draft, patches) { + patches.forEach(patch => { + const {path, op} = patch + let base = draft + for (let i = 0; i < path.length - 1; i++) { + const parentType = getArchtype(base) + let p = path[i] + if (typeof p !== "string" && typeof p !== "number") { + p = "" + p + } + if ( + (parentType === 0 /* Object */ || parentType === 1) /* Array */ && + (p === "__proto__" || p === CONSTRUCTOR) + ) + die(errorOffset + 3) + if (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3) + base = get(base, p) + if (!isObjectish(base)) die(errorOffset + 2, path.join("/")) + } + const type = getArchtype(base) + const value = deepClonePatchValue(patch.value) + const key = path[path.length - 1] + switch (op) { + case REPLACE: + switch (type) { + case 2 /* Map */: + return base.set(key, value) + case 3 /* Set */: + die(errorOffset) + default: + 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 (isArray(obj)) return obj.map(deepClonePatchValue) + if (isMap(obj)) + return new Map( + Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)]) + ) + if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue)) + const cloned = Object.create(getPrototypeOf(obj)) + for (const 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(PluginPatches, { + applyPatches_, + generatePatches_, + generateReplacementPatches_, + getPath + }) +} + +// src/plugins/mapset.ts +function enableMapSet() { + class DraftMap extends Map { + constructor(target, parent) { + super() + this[DRAFT_STATE] = { + type_: 2 /* Map */, + parent_: parent, + scope_: parent ? parent.scope_ : getCurrentScope(), + modified_: false, + finalized_: false, + copy_: void 0, + assigned_: void 0, + base_: target, + draft_: this, + isManual_: false, + revoked_: false, + callbacks_: [] + } + } + get size() { + return latest(this[DRAFT_STATE]).size + } + has(key) { + return latest(this[DRAFT_STATE]).has(key) + } + set(key, value) { + const 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 + } + delete(key) { + if (!this.has(key)) { + return false + } + const 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 + } + clear() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareMapCopy(state) + markChanged(state) + state.assigned_ = /* @__PURE__ */ new Map() + each(state.base_, key => { + state.assigned_.set(key, false) + }) + state.copy_.clear() + } + } + forEach(cb, thisArg) { + const state = this[DRAFT_STATE] + latest(state).forEach((_value, key, _map) => { + cb.call(thisArg, this.get(key), key, this) + }) + } + get(key) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + const value = latest(state).get(key) + if (state.finalized_ || !isDraftable(value)) { + return value + } + if (value !== state.base_.get(key)) { + return value + } + const draft = createProxy(state.scope_, value, state, key) + prepareMapCopy(state) + state.copy_.set(key, draft) + return draft + } + keys() { + return latest(this[DRAFT_STATE]).keys() + } + values() { + const iterator = this.keys() + return { + [Symbol.iterator]: () => this.values(), + next: () => { + const r = iterator.next() + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value + } + } + } + } + entries() { + const iterator = this.keys() + return { + [Symbol.iterator]: () => this.entries(), + next: () => { + const r = iterator.next() + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value: [r.value, value] + } + } + } + } + [(DRAFT_STATE, Symbol.iterator)]() { + return this.entries() + } + } + function proxyMap_(target, parent) { + const map = new DraftMap(target, parent) + return [map, map[DRAFT_STATE]] + } + function prepareMapCopy(state) { + if (!state.copy_) { + state.assigned_ = /* @__PURE__ */ new Map() + state.copy_ = new Map(state.base_) + } + } + class DraftSet extends Set { + constructor(target, parent) { + super() + this[DRAFT_STATE] = { + type_: 3 /* Set */, + parent_: parent, + scope_: parent ? parent.scope_ : getCurrentScope(), + modified_: false, + finalized_: false, + copy_: void 0, + base_: target, + draft_: this, + drafts_: /* @__PURE__ */ new Map(), + revoked_: false, + isManual_: false, + assigned_: void 0, + callbacks_: [] + } + } + get size() { + return latest(this[DRAFT_STATE]).size + } + has(value) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + 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 + } + add(value) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (!this.has(value)) { + prepareSetCopy(state) + markChanged(state) + state.copy_.add(value) + } + return this + } + delete(value) { + if (!this.has(value)) { + return false + } + const 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) + ) + } + clear() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareSetCopy(state) + markChanged(state) + state.copy_.clear() + } + } + values() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_.values() + } + entries() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_.entries() + } + keys() { + return this.values() + } + [(DRAFT_STATE, Symbol.iterator)]() { + return this.values() + } + forEach(cb, thisArg) { + const iterator = this.values() + let result = iterator.next() + while (!result.done) { + cb.call(thisArg, result.value, result.value, this) + result = iterator.next() + } + } + } + function proxySet_(target, parent) { + const set2 = new DraftSet(target, parent) + return [set2, set2[DRAFT_STATE]] + } + function prepareSetCopy(state) { + if (!state.copy_) { + state.copy_ = /* @__PURE__ */ new Set() + state.base_.forEach(value => { + if (isDraftable(value)) { + const draft = createProxy(state.scope_, value, state, value) + state.drafts_.set(value, draft) + state.copy_.add(draft) + } else { + state.copy_.add(value) + } + }) + } + } + function assertUnrevoked(state) { + if (state.revoked_) die(3, JSON.stringify(latest(state))) + } + function fixSetContents(target) { + if (target.type_ === 3 /* Set */ && target.copy_) { + const copy = new Set(target.copy_) + target.copy_.clear() + copy.forEach(value => { + target.copy_.add(getValue(value)) + }) + } + } + loadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents}) +} + +// src/plugins/arrayMethods.ts +function enableArrayMethods() { + const SHIFTING_METHODS = /* @__PURE__ */ new Set(["shift", "unshift"]) + const QUEUE_METHODS = /* @__PURE__ */ new Set(["push", "pop"]) + const RESULT_RETURNING_METHODS = /* @__PURE__ */ new Set([ + ...QUEUE_METHODS, + ...SHIFTING_METHODS + ]) + const REORDERING_METHODS = /* @__PURE__ */ new Set(["reverse", "sort"]) + const MUTATING_METHODS = /* @__PURE__ */ new Set([ + ...RESULT_RETURNING_METHODS, + ...REORDERING_METHODS, + "splice" + ]) + const FIND_METHODS = /* @__PURE__ */ new Set(["find", "findLast"]) + const NON_MUTATING_METHODS = /* @__PURE__ */ new Set([ + "filter", + "slice", + "concat", + "flat", + ...FIND_METHODS, + "findIndex", + "findLastIndex", + "some", + "every", + "indexOf", + "lastIndexOf", + "includes", + "join", + "toString", + "toLocaleString" + ]) + function isMutatingArrayMethod(method) { + return MUTATING_METHODS.has(method) + } + function isNonMutatingArrayMethod(method) { + return NON_MUTATING_METHODS.has(method) + } + function isArrayOperationMethod(method) { + return isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method) + } + function enterOperation(state, method) { + state.operationMethod = method + } + function exitOperation(state) { + state.operationMethod = void 0 + } + function executeArrayMethod(state, operation, markLength = true) { + prepareCopy(state) + const result = operation() + markChanged(state) + if (markLength) state.assigned_.set("length", true) + return result + } + function markAllIndicesReassigned(state) { + state.allIndicesReassigned_ = true + } + function normalizeSliceIndex(index, length) { + if (index < 0) { + return Math.max(length + index, 0) + } + return Math.min(index, length) + } + function handleSimpleOperation(state, method, args) { + return executeArrayMethod(state, () => { + const result = state.copy_[method](...args) + if (SHIFTING_METHODS.has(method)) { + markAllIndicesReassigned(state) + } + return RESULT_RETURNING_METHODS.has(method) ? result : state.draft_ + }) + } + function handleReorderingOperation(state, method, args) { + return executeArrayMethod( + state, + () => { + state.copy_[method](...args) + markAllIndicesReassigned(state) + return state.draft_ + }, + false + ) + } + function createMethodInterceptor(state, originalMethod) { + return function interceptedMethod(...args) { + const method = originalMethod + enterOperation(state, method) + try { + if (isMutatingArrayMethod(method)) { + if (RESULT_RETURNING_METHODS.has(method)) { + return handleSimpleOperation(state, method, args) + } + if (REORDERING_METHODS.has(method)) { + return handleReorderingOperation(state, method, args) + } + if (method === "splice") { + const res = executeArrayMethod(state, () => + state.copy_.splice(...args) + ) + markAllIndicesReassigned(state) + return res + } + } else { + return handleNonMutatingOperation(state, method, args) + } + } finally { + exitOperation(state) + } + } + } + function handleNonMutatingOperation(state, method, args) { + var _a, _b + const source = latest(state) + if (method === "filter") { + const predicate = args[0] + const result = [] + for (let i = 0; i < source.length; i++) { + if (predicate(source[i], i, source)) { + result.push(state.draft_[i]) + } + } + return result + } + if (FIND_METHODS.has(method)) { + const predicate = args[0] + const isForward = method === "find" + const step = isForward ? 1 : -1 + const start = isForward ? 0 : source.length - 1 + for (let i = start; i >= 0 && i < source.length; i += step) { + if (predicate(source[i], i, source)) { + return state.draft_[i] + } + } + return void 0 + } + if (method === "slice") { + const rawStart = (_a = args[0]) != null ? _a : 0 + const rawEnd = (_b = args[1]) != null ? _b : source.length + const start = normalizeSliceIndex(rawStart, source.length) + const end = normalizeSliceIndex(rawEnd, source.length) + const result = [] + for (let i = start; i < end; i++) { + result.push(state.draft_[i]) + } + return result + } + return source[method](...args) + } + loadPlugin(PluginArrayMethods, { + createMethodInterceptor, + isArrayOperationMethod, + isMutatingArrayMethod + }) +} + +// src/immer.ts +var immer = new Immer2() +var produce = immer.produce +var produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(immer) +var setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer) +var setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind( + immer +) +var setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind( + immer +) +var applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer) +var createDraft = /* @__PURE__ */ immer.createDraft.bind(immer) +var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer) +var castDraft = value => value +var castImmutable = value => value +function isNothing(value) { + return value === NOTHING +} +export { + Immer2 as Immer, + applyPatches, + castDraft, + castImmutable, + createDraft, + current, + enableArrayMethods, + enableMapSet, + enablePatches, + finishDraft, + freeze, + DRAFTABLE as immerable, + isDraft, + isDraftable, + isNothing, + NOTHING as nothing, + original, + produce, + produceWithPatches, + setAutoFreeze, + setUseStrictIteration, + setUseStrictShallowCopy +} +//# sourceMappingURL=immer.legacy-esm.js.map diff --git a/dist/immer.legacy-esm.js.map b/dist/immer.legacy-esm.js.map new file mode 100644 index 00000000..dd57ef0b --- /dev/null +++ b/dist/immer.legacy-esm.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/utils/env.ts","../src/utils/errors.ts","../src/utils/common.ts","../src/utils/plugins.ts","../src/core/scope.ts","../src/core/finalize.ts","../src/core/proxy.ts","../src/core/immerClass.ts","../src/core/current.ts","../src/plugins/patches.ts","../src/plugins/mapset.ts","../src/plugins/arrayMethods.ts","../src/immer.ts"],"sourcesContent":["// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","import {isFunction} from \"../internal\"\n\nexport const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `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}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = isFunction(e) ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nconst O = Object\n\nexport const getPrototypeOf = O.getPrototypeOf\n\nexport const CONSTRUCTOR = \"constructor\"\nexport const PROTOTYPE = \"prototype\"\n\nexport const CONFIGURABLE = \"configurable\"\nexport const ENUMERABLE = \"enumerable\"\nexport const WRITABLE = \"writable\"\nexport const VALUE = \"value\"\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport let isDraft = (value: any): boolean => !!value && !!value[DRAFT_STATE]\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tisArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value[CONSTRUCTOR]?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString()\nconst cachedCtorStrings = new WeakMap()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || !isObjectish(value)) return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null || proto === O[PROTOTYPE]) return true\n\n\tconst Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR]\n\tif (Ctor === Object) return true\n\n\tif (!isFunction(Ctor)) return false\n\n\tlet ctorString = cachedCtorStrings.get(Ctor)\n\tif (ctorString === undefined) {\n\t\tctorString = Function.toString.call(Ctor)\n\t\tcachedCtorStrings.set(Ctor, ctorString)\n\t}\n\n\treturn ctorString === objectCtorString\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n *\n * @param obj The object to iterate over\n * @param iter The iterator function\n * @param strict When true (default), includes symbols and non-enumerable properties.\n * When false, uses looseiteration over only enumerable string properties.\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void,\n\tstrict?: boolean\n): void\nexport function each(obj: any, iter: any, strict: boolean = true) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\t// If strict, we do a full iteration including symbols and non-enumerable properties\n\t\t// Otherwise, we only iterate enumerable string properties for performance\n\t\tconst keys = strict ? Reflect.ownKeys(obj) : O.keys(obj)\n\t\tkeys.forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport let has = (\n\tthing: any,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): boolean =>\n\ttype === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: O[PROTOTYPE].hasOwnProperty.call(thing, prop)\n\n/*#__PURE__*/\nexport let get = (\n\tthing: AnyMap | AnyObject,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): any =>\n\t// @ts-ignore\n\ttype === ArchType.Map ? thing.get(prop) : thing[prop]\n\n/*#__PURE__*/\nexport let set = (\n\tthing: any,\n\tpropOrOldValue: PropertyKey,\n\tvalue: any,\n\ttype = getArchtype(thing)\n) => {\n\tif (type === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (type === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\nexport let isArray = Array.isArray\n\n/*#__PURE__*/\nexport let isMap = (target: any): target is AnyMap => target instanceof Map\n\n/*#__PURE__*/\nexport let isSet = (target: any): target is AnySet => target instanceof Set\n\nexport let isObjectish = (target: any) => typeof target === \"object\"\n\nexport let isFunction = (target: any): target is Function =>\n\ttypeof target === \"function\"\n\nexport let isBoolean = (target: any): target is boolean =>\n\ttypeof target === \"boolean\"\n\nexport function isArrayIndex(value: string | number): value is number | string {\n\tconst n = +value\n\treturn Number.isInteger(n) && String(n) === value\n}\n\nexport let getProxyDraft = (value: T): ImmerState | null => {\n\tif (!isObjectish(value)) return null\n\treturn (value as {[DRAFT_STATE]: any})?.[DRAFT_STATE]\n}\n\n/*#__PURE__*/\nexport let latest = (state: ImmerState): any => state.copy_ || state.base_\n\nexport let getValue = (value: T): T => {\n\tconst proxyDraft = getProxyDraft(value)\n\treturn proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value\n}\n\nexport let getFinalValue = (state: ImmerState): any =>\n\tstate.modified_ ? state.copy_ : state.base_\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (isArray(base)) return Array[PROTOTYPE].slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = O.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc[WRITABLE] === false) {\n\t\t\t\tdesc[WRITABLE] = true\n\t\t\t\tdesc[CONFIGURABLE] = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\t[CONFIGURABLE]: true,\n\t\t\t\t\t[WRITABLE]: true, // could live with !!desc.set as well here...\n\t\t\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t\t\t[VALUE]: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn O.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = O.create(proto)\n\t\treturn O.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tO.defineProperties(obj, {\n\t\t\tset: dontMutateMethodOverride,\n\t\t\tadd: dontMutateMethodOverride,\n\t\t\tclear: dontMutateMethodOverride,\n\t\t\tdelete: dontMutateMethodOverride\n\t\t})\n\t}\n\tO.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.values (only string-like, enumerables) instead of each()\n\t\teach(\n\t\t\tobj,\n\t\t\t(_key, value) => {\n\t\t\t\tfreeze(value, true)\n\t\t\t},\n\t\t\tfalse\n\t\t)\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nconst dontMutateMethodOverride = {\n\t[VALUE]: dontMutateFrozenCollections\n}\n\nexport function isFrozen(obj: any): boolean {\n\t// Fast path: primitives and null/undefined are always \"frozen\"\n\tif (obj === null || !isObjectish(obj)) return true\n\treturn O.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie,\n\tImmerScope,\n\tProxyArrayState\n} from \"../internal\"\n\nexport const PluginMapSet = \"MapSet\"\nexport const PluginPatches = \"Patches\"\nexport const PluginArrayMethods = \"ArrayMethods\"\n\nexport type PatchesPlugin = {\n\tgeneratePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\trootScope: ImmerScope\n\t): void\n\tgenerateReplacementPatches_(\n\t\tbase: any,\n\t\treplacement: any,\n\t\trootScope: ImmerScope\n\t): void\n\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\tgetPath: (state: ImmerState) => PatchPath | null\n}\n\nexport type MapSetPlugin = {\n\tproxyMap_(target: T, parent?: ImmerState): [T, ImmerState]\n\tproxySet_(target: T, parent?: ImmerState): [T, ImmerState]\n\tfixSetContents: (state: ImmerState) => void\n}\n\nexport type ArrayMethodsPlugin = {\n\tcreateMethodInterceptor: (state: ProxyArrayState, method: string) => Function\n\tisArrayOperationMethod: (method: string) => boolean\n\tisMutatingArrayMethod: (method: string) => boolean\n}\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: PatchesPlugin\n\tMapSet?: MapSetPlugin\n\tArrayMethods?: ArrayMethodsPlugin\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport let isPluginLoaded = (pluginKey: K): boolean =>\n\t!!plugins[pluginKey]\n\nexport let clearPlugin = (pluginKey: K): void => {\n\tdelete plugins[pluginKey]\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin,\n\tPatchesPlugin,\n\tMapSetPlugin,\n\tisPluginLoaded,\n\tPluginMapSet,\n\tPluginPatches,\n\tArrayMethodsPlugin,\n\tPluginArrayMethods\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tpatchPlugin_?: PatchesPlugin\n\tmapSetPlugin_?: MapSetPlugin\n\tarrayMethodsPlugin_?: ArrayMethodsPlugin\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n\thandledSet_: Set\n\tprocessedForPatches_: Set\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport let getCurrentScope = () => currentScope!\n\nlet createScope = (\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope => ({\n\tdrafts_: [],\n\tparent_,\n\timmer_,\n\t// Whenever the modified draft contains a draft from another scope, we\n\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\tcanAutoFreeze_: true,\n\tunfinalizedDrafts_: 0,\n\thandledSet_: new Set(),\n\tprocessedForPatches_: new Set(),\n\tmapSetPlugin_: isPluginLoaded(PluginMapSet)\n\t\t? getPlugin(PluginMapSet)\n\t\t: undefined,\n\tarrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods)\n\t\t? getPlugin(PluginArrayMethods)\n\t\t: undefined\n})\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tscope.patchPlugin_ = getPlugin(PluginPatches) // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport let enterScope = (immer: Immer) =>\n\t(currentScope = createScope(currentScope, immer))\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen,\n\tget,\n\tPatch,\n\tlatest,\n\tprepareCopy,\n\tgetFinalValue,\n\tgetValue,\n\tProxyArrayState\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t}\n\t\tconst {patchPlugin_} = scope\n\t\tif (patchPlugin_) {\n\t\t\tpatchPlugin_.generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft)\n\t}\n\n\tmaybeFreeze(scope, result, true)\n\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\tif (!state) {\n\t\tconst finalValue = handleValue(value, rootScope.handledSet_, rootScope)\n\t\treturn finalValue\n\t}\n\n\t// Never finalize drafts owned by another scope\n\tif (!isSameScope(state, rootScope)) {\n\t\treturn value\n\t}\n\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\treturn state.base_\n\t}\n\n\tif (!state.finalized_) {\n\t\t// Execute all registered draft finalization callbacks\n\t\tconst {callbacks_} = state\n\t\tif (callbacks_) {\n\t\t\twhile (callbacks_.length > 0) {\n\t\t\t\tconst callback = callbacks_.pop()!\n\t\t\t\tcallback(rootScope)\n\t\t\t}\n\t\t}\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t}\n\n\t// By now the root copy has been fully updated throughout its tree\n\treturn state.copy_\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n\nfunction markStateFinalized(state: ImmerState) {\n\tstate.finalized_ = true\n\tstate.scope_.unfinalizedDrafts_--\n}\n\nlet isSameScope = (state: ImmerState, rootScope: ImmerScope) =>\n\tstate.scope_ === rootScope\n\n// A reusable empty array to avoid allocations\nconst EMPTY_LOCATIONS_RESULT: (string | symbol | number)[] = []\n\n// Updates all references to a draft in its parent to the finalized value.\n// This handles cases where the same draft appears multiple times in the parent, or has been moved around.\nexport function updateDraftInParent(\n\tparent: ImmerState,\n\tdraftValue: any,\n\tfinalizedValue: any,\n\toriginalKey?: string | number | symbol\n): void {\n\tconst parentCopy = latest(parent)\n\tconst parentType = parent.type_\n\n\t// Fast path: Check if draft is still at original key\n\tif (originalKey !== undefined) {\n\t\tconst currentValue = get(parentCopy, originalKey, parentType)\n\t\tif (currentValue === draftValue) {\n\t\t\t// Still at original location, just update it\n\t\t\tset(parentCopy, originalKey, finalizedValue, parentType)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Slow path: Build reverse mapping of all children\n\t// to their indices in the parent, so that we can\n\t// replace all locations where this draft appears.\n\t// We only have to build this once per parent.\n\tif (!parent.draftLocations_) {\n\t\tconst draftLocations = (parent.draftLocations_ = new Map())\n\n\t\t// Use `each` which works on Arrays, Maps, and Objects\n\t\teach(parentCopy, (key, value) => {\n\t\t\tif (isDraft(value)) {\n\t\t\t\tconst keys = draftLocations.get(value) || []\n\t\t\t\tkeys.push(key)\n\t\t\t\tdraftLocations.set(value, keys)\n\t\t\t}\n\t\t})\n\t}\n\n\t// Look up all locations where this draft appears\n\tconst locations =\n\t\tparent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT\n\n\t// Update all locations\n\tfor (const location of locations) {\n\t\tset(parentCopy, location, finalizedValue, parentType)\n\t}\n}\n\n// Register a callback to finalize a child draft when the parent draft is finalized.\n// This assumes there is a parent -> child relationship between the two drafts,\n// and we have a key to locate the child in the parent.\nexport function registerChildFinalizationCallback(\n\tparent: ImmerState,\n\tchild: ImmerState,\n\tkey: string | number | symbol\n) {\n\tparent.callbacks_.push(function childCleanup(rootScope) {\n\t\tconst state: ImmerState = child\n\n\t\t// Can only continue if this is a draft owned by this scope\n\t\tif (!state || !isSameScope(state, rootScope)) {\n\t\t\treturn\n\t\t}\n\n\t\t// Handle potential set value finalization first\n\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t// Update all locations in the parent that referenced this draft\n\t\tupdateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key)\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t})\n}\n\nfunction generatePatchesAndFinalize(state: ImmerState, rootScope: ImmerScope) {\n\tconst shouldFinalize =\n\t\tstate.modified_ &&\n\t\t!state.finalized_ &&\n\t\t(state.type_ === ArchType.Set ||\n\t\t\t(state.type_ === ArchType.Array &&\n\t\t\t\t(state as ProxyArrayState).allIndicesReassigned_) ||\n\t\t\t(state.assigned_?.size ?? 0) > 0)\n\n\tif (shouldFinalize) {\n\t\tconst {patchPlugin_} = rootScope\n\t\tif (patchPlugin_) {\n\t\t\tconst basePath = patchPlugin_!.getPath(state)\n\n\t\t\tif (basePath) {\n\t\t\t\tpatchPlugin_!.generatePatches_(state, basePath, rootScope)\n\t\t\t}\n\t\t}\n\n\t\tmarkStateFinalized(state)\n\t}\n}\n\nexport function handleCrossReference(\n\ttarget: ImmerState,\n\tkey: string | number | symbol,\n\tvalue: any\n) {\n\tconst {scope_} = target\n\t// Check if value is a draft from this scope\n\tif (isDraft(value)) {\n\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\tif (isSameScope(state, scope_)) {\n\t\t\t// Register callback to update this location when the draft finalizes\n\n\t\t\tstate.callbacks_.push(function crossReferenceCleanup() {\n\t\t\t\t// Update the target location with finalized value\n\t\t\t\tprepareCopy(target)\n\n\t\t\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t\t\tupdateDraftInParent(target, value, finalizedValue, key)\n\t\t\t})\n\t\t}\n\t} else if (isDraftable(value)) {\n\t\t// Handle non-draft objects that might contain drafts\n\t\ttarget.callbacks_.push(function nestedDraftCleanup() {\n\t\t\tconst targetCopy = latest(target)\n\n\t\t\tif (get(targetCopy, key, target.type_) === value) {\n\t\t\t\t// Process the value to replace any nested drafts\n\t\t\t\t// finalizeAssigned(target, key, target.scope_)\n\n\t\t\t\tif (\n\t\t\t\t\tscope_.drafts_.length > 1 &&\n\t\t\t\t\t((target as Exclude).assigned_!.get(key) ??\n\t\t\t\t\t\tfalse) === true &&\n\t\t\t\t\ttarget.copy_\n\t\t\t\t) {\n\t\t\t\t\t// This might be a non-draft value that has drafts\n\t\t\t\t\t// inside. We do need to recurse here to handle those.\n\t\t\t\t\thandleValue(\n\t\t\t\t\t\tget(target.copy_, key, target.type_),\n\t\t\t\t\t\tscope_.handledSet_,\n\t\t\t\t\t\tscope_\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport function handleValue(\n\ttarget: any,\n\thandledSet: Set,\n\trootScope: ImmerScope\n) {\n\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t// This benefits especially adding large data tree's without further processing.\n\t\t// See add-data.js perf test\n\t\treturn target\n\t}\n\n\t// Skip if already handled, frozen, or not draftable\n\tif (\n\t\tisDraft(target) ||\n\t\thandledSet.has(target) ||\n\t\t!isDraftable(target) ||\n\t\tisFrozen(target)\n\t) {\n\t\treturn target\n\t}\n\n\thandledSet.add(target)\n\n\t// Process ALL properties/entries\n\teach(target, (key, value) => {\n\t\tif (isDraft(value)) {\n\t\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\t\tif (isSameScope(state, rootScope)) {\n\t\t\t\t// Replace draft with finalized value\n\n\t\t\t\tconst updatedValue = getFinalValue(state)\n\n\t\t\t\tset(target, key, updatedValue, target.type_)\n\n\t\t\t\tmarkStateFinalized(state)\n\t\t\t}\n\t\t} else if (isDraftable(value)) {\n\t\t\t// Recursively handle nested values\n\t\t\thandleValue(value, handledSet, rootScope)\n\t\t}\n\t})\n\n\treturn target\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope,\n\thandleCrossReference,\n\tWRITABLE,\n\tCONFIGURABLE,\n\tENUMERABLE,\n\tVALUE,\n\tisArray,\n\tisArrayIndex\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted\n\toperationMethod?: string\n\tallIndicesReassigned_?: boolean\n}\n\ntype ProxyState = ProxyObjectState | ProxyArrayState\n\n/**\n * Returns a new draft of the `base` object.\n *\n * The second argument is the parent draft-state (used internally).\n */\nexport function createProxyProxy(\n\tbase: T,\n\tparent?: ImmerState\n): [Drafted, ProxyState] {\n\tconst baseIsArray = isArray(base)\n\tconst state: ProxyState = {\n\t\ttype_: baseIsArray ? ArchType.Array : (ArchType.Object as any),\n\t\t// Track which produce call this is associated with.\n\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t// True for both shallow and deep changes.\n\t\tmodified_: false,\n\t\t// Used during finalization.\n\t\tfinalized_: false,\n\t\t// Track which properties have been assigned (true) or deleted (false).\n\t\t// actually instantiated in `prepareCopy()`\n\t\tassigned_: undefined,\n\t\t// The parent draft state.\n\t\tparent_: parent,\n\t\t// The base state.\n\t\tbase_: base,\n\t\t// The base proxy.\n\t\tdraft_: null as any, // set below\n\t\t// The base copy with any updated values.\n\t\tcopy_: null,\n\t\t// Called by the `produce` function.\n\t\trevoke_: null as any,\n\t\tisManual_: false,\n\t\t// `callbacks` actually gets assigned in `createProxy`\n\t\tcallbacks_: undefined as any\n\t}\n\n\t// the traps must target something, a bit like the 'real' base.\n\t// but also, we need to be able to determine from the target what the relevant state is\n\t// (to avoid creating traps per instance to capture the state in closure,\n\t// and to avoid creating weird hidden properties as well)\n\t// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)\n\t// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb\n\tlet target: T = state as any\n\tlet traps: ProxyHandler> = objectTraps\n\tif (baseIsArray) {\n\t\ttarget = [state] as any\n\t\ttraps = arrayTraps\n\t}\n\n\tconst {revoke, proxy} = Proxy.revocable(target, traps)\n\tstate.draft_ = proxy as any\n\tstate.revoke_ = revoke\n\treturn [proxy as any, state]\n}\n\n/**\n * Object drafts\n */\nexport const objectTraps: ProxyHandler = {\n\tget(state, prop) {\n\t\tif (prop === DRAFT_STATE) return state\n\n\t\tlet arrayPlugin = state.scope_.arrayMethodsPlugin_\n\t\tconst isArrayWithStringProp =\n\t\t\tstate.type_ === ArchType.Array && typeof prop === \"string\"\n\t\t// Intercept array methods so that we can override\n\t\t// behavior and skip proxy creation for perf\n\t\tif (isArrayWithStringProp) {\n\t\t\tif (arrayPlugin?.isArrayOperationMethod(prop)) {\n\t\t\t\treturn arrayPlugin.createMethodInterceptor(state, prop)\n\t\t\t}\n\t\t}\n\n\t\tconst source = latest(state)\n\t\tif (!has(source, prop, state.type_)) {\n\t\t\t// non-existing or non-own property...\n\t\t\treturn readPropFromProto(state, source, prop)\n\t\t}\n\t\tconst value = source[prop]\n\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\treturn value\n\t\t}\n\n\t\t// During mutating array operations, defer proxy creation for array elements\n\t\t// This optimization avoids creating unnecessary proxies during sort/reverse\n\t\tif (\n\t\t\tisArrayWithStringProp &&\n\t\t\t(state as ProxyArrayState).operationMethod &&\n\t\t\tarrayPlugin?.isMutatingArrayMethod(\n\t\t\t\t(state as ProxyArrayState).operationMethod!\n\t\t\t) &&\n\t\t\tisArrayIndex(prop)\n\t\t) {\n\t\t\t// Return raw value during mutating operations, create proxy only if modified\n\t\t\treturn value\n\t\t}\n\t\t// Check for existing draft in modified state.\n\t\t// Assigned values are never drafted. This catches any drafts we created, too.\n\t\tif (value === peek(state.base_, prop)) {\n\t\t\tprepareCopy(state)\n\t\t\t// Ensure array keys are always numbers\n\t\t\tconst childKey = state.type_ === ArchType.Array ? +(prop as string) : prop\n\t\t\tconst childDraft = createProxy(state.scope_, value, state, childKey)\n\n\t\t\treturn (state.copy_![childKey] = childDraft)\n\t\t}\n\t\treturn value\n\t},\n\thas(state, prop) {\n\t\treturn prop in latest(state)\n\t},\n\townKeys(state) {\n\t\treturn Reflect.ownKeys(latest(state))\n\t},\n\tset(\n\t\tstate: ProxyObjectState,\n\t\tprop: string /* strictly not, but helps TS */,\n\t\tvalue\n\t) {\n\t\tconst desc = getDescriptorFromProto(latest(state), prop)\n\t\tif (desc?.set) {\n\t\t\t// special case: if this write is captured by a setter, we have\n\t\t\t// to trigger it with the correct context\n\t\t\tdesc.set.call(state.draft_, value)\n\t\t\treturn true\n\t\t}\n\t\tif (!state.modified_) {\n\t\t\t// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)\n\t\t\t// from setting an existing property with value undefined to undefined (which is not a change)\n\t\t\tconst current = peek(latest(state), prop)\n\t\t\t// special case, if we assigning the original value to a draft, we can ignore the assignment\n\t\t\tconst currentState: ProxyObjectState = current?.[DRAFT_STATE]\n\t\t\tif (currentState && currentState.base_ === value) {\n\t\t\t\tstate.copy_![prop] = value\n\t\t\t\tstate.assigned_!.set(prop, false)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (\n\t\t\t\tis(value, current) &&\n\t\t\t\t(value !== undefined || has(state.base_, prop, state.type_))\n\t\t\t)\n\t\t\t\treturn true\n\t\t\tprepareCopy(state)\n\t\t\tmarkChanged(state)\n\t\t}\n\n\t\tif (\n\t\t\t(state.copy_![prop] === value &&\n\t\t\t\t// special case: handle new props with value 'undefined'\n\t\t\t\t(value !== undefined || prop in state.copy_)) ||\n\t\t\t// special case: NaN\n\t\t\t(Number.isNaN(value) && Number.isNaN(state.copy_![prop]))\n\t\t)\n\t\t\treturn true\n\n\t\t// @ts-ignore\n\t\tstate.copy_![prop] = value\n\t\tstate.assigned_!.set(prop, true)\n\n\t\thandleCrossReference(state, prop, value)\n\t\treturn true\n\t},\n\tdeleteProperty(state, prop: string) {\n\t\tprepareCopy(state)\n\t\t// The `undefined` check is a fast path for pre-existing keys.\n\t\tif (peek(state.base_, prop) !== undefined || prop in state.base_) {\n\t\t\tstate.assigned_!.set(prop, false)\n\t\t\tmarkChanged(state)\n\t\t} else {\n\t\t\t// if an originally not assigned property was deleted\n\t\t\tstate.assigned_!.delete(prop)\n\t\t}\n\t\tif (state.copy_) {\n\t\t\tdelete state.copy_[prop]\n\t\t}\n\t\treturn true\n\t},\n\t// Note: We never coerce `desc.value` into an Immer draft, because we can't make\n\t// the same guarantee in ES5 mode.\n\tgetOwnPropertyDescriptor(state, prop) {\n\t\tconst owner = latest(state)\n\t\tconst desc = Reflect.getOwnPropertyDescriptor(owner, prop)\n\t\tif (!desc) return desc\n\t\treturn {\n\t\t\t[WRITABLE]: true,\n\t\t\t[CONFIGURABLE]: state.type_ !== ArchType.Array || prop !== \"length\",\n\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t[VALUE]: owner[prop]\n\t\t}\n\t},\n\tdefineProperty() {\n\t\tdie(11)\n\t},\n\tgetPrototypeOf(state) {\n\t\treturn getPrototypeOf(state.base_)\n\t},\n\tsetPrototypeOf() {\n\t\tdie(12)\n\t}\n}\n\n/**\n * Array drafts\n */\n\nconst arrayTraps: ProxyHandler<[ProxyArrayState]> = {}\neach(objectTraps, (key, fn) => {\n\t// @ts-ignore\n\tarrayTraps[key] = function() {\n\t\tconst args = arguments\n\t\targs[0] = args[0][0]\n\t\treturn fn.apply(this, args)\n\t}\n})\narrayTraps.deleteProperty = function(state, prop) {\n\tif (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop as any)))\n\t\tdie(13)\n\t// @ts-ignore\n\treturn arrayTraps.set!.call(this, state, prop, undefined)\n}\narrayTraps.set = function(state, prop, value) {\n\tif (\n\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\tprop !== \"length\" &&\n\t\tisNaN(parseInt(prop as any))\n\t)\n\t\tdie(14)\n\treturn objectTraps.set!.call(this, state[0], prop, value, state[0])\n}\n\n// Access a property without creating an Immer draft.\nfunction peek(draft: Drafted, prop: PropertyKey) {\n\tconst state = draft[DRAFT_STATE]\n\tconst source = state ? latest(state) : draft\n\treturn source[prop]\n}\n\nfunction readPropFromProto(state: ImmerState, source: any, prop: PropertyKey) {\n\tconst desc = getDescriptorFromProto(source, prop)\n\treturn desc\n\t\t? VALUE in desc\n\t\t\t? desc[VALUE]\n\t\t\t: // This is a very special case, if the prop is a getter defined by the\n\t\t\t // prototype, we should invoke it with the draft as context!\n\t\t\t desc.get?.call(state.draft_)\n\t\t: undefined\n}\n\nfunction getDescriptorFromProto(\n\tsource: any,\n\tprop: PropertyKey\n): PropertyDescriptor | undefined {\n\t// 'in' checks proto!\n\tif (!(prop in source)) return undefined\n\tlet proto = getPrototypeOf(source)\n\twhile (proto) {\n\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\tif (desc) return desc\n\t\tproto = getPrototypeOf(proto)\n\t}\n\treturn undefined\n}\n\nexport function markChanged(state: ImmerState) {\n\tif (!state.modified_) {\n\t\tstate.modified_ = true\n\t\tif (state.parent_) {\n\t\t\tmarkChanged(state.parent_)\n\t\t}\n\t}\n}\n\nexport function prepareCopy(state: ImmerState) {\n\tif (!state.copy_) {\n\t\t// Actually create the `assigned_` map now that we\n\t\t// know this is a modified draft.\n\t\tstate.assigned_ = new Map()\n\t\tstate.copy_ = shallowCopy(\n\t\t\tstate.base_,\n\t\t\tstate.scope_.immer_.useStrictShallowCopy_\n\t\t)\n\t}\n}\n","import {\n\tIProduceWithPatches,\n\tIProduce,\n\tImmerState,\n\tDrafted,\n\tisDraftable,\n\tprocessResult,\n\tPatch,\n\tObjectish,\n\tDRAFT_STATE,\n\tDraft,\n\tPatchListener,\n\tisDraft,\n\tisMap,\n\tisSet,\n\tcreateProxyProxy,\n\tgetPlugin,\n\tdie,\n\tenterScope,\n\trevokeScope,\n\tleaveScope,\n\tusePatchesInScope,\n\tgetCurrentScope,\n\tNOTHING,\n\tfreeze,\n\tcurrent,\n\tImmerScope,\n\tregisterChildFinalizationCallback,\n\tArchType,\n\tMapSetPlugin,\n\tAnyMap,\n\tAnySet,\n\tisObjectish,\n\tisFunction,\n\tisBoolean,\n\tPluginMapSet,\n\tPluginPatches\n} from \"../internal\"\n\ninterface ProducersFns {\n\tproduce: IProduce\n\tproduceWithPatches: IProduceWithPatches\n}\n\nexport type StrictMode = boolean | \"class_only\"\n\nexport class Immer implements ProducersFns {\n\tautoFreeze_: boolean = true\n\tuseStrictShallowCopy_: StrictMode = false\n\tuseStrictIteration_: boolean = false\n\n\tconstructor(config?: {\n\t\tautoFreeze?: boolean\n\t\tuseStrictShallowCopy?: StrictMode\n\t\tuseStrictIteration?: boolean\n\t}) {\n\t\tif (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config!.autoFreeze)\n\t\tif (isBoolean(config?.useStrictShallowCopy))\n\t\t\tthis.setUseStrictShallowCopy(config!.useStrictShallowCopy)\n\t\tif (isBoolean(config?.useStrictIteration))\n\t\t\tthis.setUseStrictIteration(config!.useStrictIteration)\n\t}\n\n\t/**\n\t * The `produce` function takes a value and a \"recipe function\" (whose\n\t * return value often depends on the base state). The recipe function is\n\t * free to mutate its first argument however it wants. All mutations are\n\t * only ever applied to a __copy__ of the base state.\n\t *\n\t * Pass only a function to create a \"curried producer\" which relieves you\n\t * from passing the recipe function every time.\n\t *\n\t * Only plain objects and arrays are made mutable. All other objects are\n\t * considered uncopyable.\n\t *\n\t * Note: This function is __bound__ to its `Immer` instance.\n\t *\n\t * @param {any} base - the initial state\n\t * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n\t * @param {Function} patchListener - optional function that will be called with all the patches produced here\n\t * @returns {any} a new state, or the initial state if nothing was modified\n\t */\n\tproduce: IProduce = (base: any, recipe?: any, patchListener?: any) => {\n\t\t// curried invocation\n\t\tif (isFunction(base) && !isFunction(recipe)) {\n\t\t\tconst defaultBase = recipe\n\t\t\trecipe = base\n\n\t\t\tconst self = this\n\t\t\treturn function curriedProduce(\n\t\t\t\tthis: any,\n\t\t\t\tbase = defaultBase,\n\t\t\t\t...args: any[]\n\t\t\t) {\n\t\t\t\treturn self.produce(base, (draft: Drafted) => recipe.call(this, draft, ...args)) // prettier-ignore\n\t\t\t}\n\t\t}\n\n\t\tif (!isFunction(recipe)) die(6)\n\t\tif (patchListener !== undefined && !isFunction(patchListener)) die(7)\n\n\t\tlet result\n\n\t\t// Only plain objects, arrays, and \"immerable classes\" are drafted.\n\t\tif (isDraftable(base)) {\n\t\t\tconst scope = enterScope(this)\n\t\t\tconst proxy = createProxy(scope, base, undefined)\n\t\t\tlet hasError = true\n\t\t\ttry {\n\t\t\t\tresult = recipe(proxy)\n\t\t\t\thasError = false\n\t\t\t} finally {\n\t\t\t\t// finally instead of catch + rethrow better preserves original stack\n\t\t\t\tif (hasError) revokeScope(scope)\n\t\t\t\telse leaveScope(scope)\n\t\t\t}\n\t\t\tusePatchesInScope(scope, patchListener)\n\t\t\treturn processResult(result, scope)\n\t\t} else if (!base || !isObjectish(base)) {\n\t\t\tresult = recipe(base)\n\t\t\tif (result === undefined) result = base\n\t\t\tif (result === NOTHING) result = undefined\n\t\t\tif (this.autoFreeze_) freeze(result, true)\n\t\t\tif (patchListener) {\n\t\t\t\tconst p: Patch[] = []\n\t\t\t\tconst ip: Patch[] = []\n\t\t\t\tgetPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n\t\t\t\t\tpatches_: p,\n\t\t\t\t\tinversePatches_: ip\n\t\t\t\t} as ImmerScope) // dummy scope\n\t\t\t\tpatchListener(p, ip)\n\t\t\t}\n\t\t\treturn result\n\t\t} else die(1, base)\n\t}\n\n\tproduceWithPatches: IProduceWithPatches = (base: any, recipe?: any): any => {\n\t\t// curried invocation\n\t\tif (isFunction(base)) {\n\t\t\treturn (state: any, ...args: any[]) =>\n\t\t\t\tthis.produceWithPatches(state, (draft: any) => base(draft, ...args))\n\t\t}\n\n\t\tlet patches: Patch[], inversePatches: Patch[]\n\t\tconst result = this.produce(base, recipe, (p: Patch[], ip: Patch[]) => {\n\t\t\tpatches = p\n\t\t\tinversePatches = ip\n\t\t})\n\t\treturn [result, patches!, inversePatches!]\n\t}\n\n\tcreateDraft(base: T): Draft {\n\t\tif (!isDraftable(base)) die(8)\n\t\tif (isDraft(base)) base = current(base)\n\t\tconst scope = enterScope(this)\n\t\tconst proxy = createProxy(scope, base, undefined)\n\t\tproxy[DRAFT_STATE].isManual_ = true\n\t\tleaveScope(scope)\n\t\treturn proxy as any\n\t}\n\n\tfinishDraft>(\n\t\tdraft: D,\n\t\tpatchListener?: PatchListener\n\t): D extends Draft ? T : never {\n\t\tconst state: ImmerState = draft && (draft as any)[DRAFT_STATE]\n\t\tif (!state || !state.isManual_) die(9)\n\t\tconst {scope_: scope} = state\n\t\tusePatchesInScope(scope, patchListener)\n\t\treturn processResult(undefined, scope)\n\t}\n\n\t/**\n\t * Pass true to automatically freeze all copies created by Immer.\n\t *\n\t * By default, auto-freezing is enabled.\n\t */\n\tsetAutoFreeze(value: boolean) {\n\t\tthis.autoFreeze_ = value\n\t}\n\n\t/**\n\t * Pass true to enable strict shallow copy.\n\t *\n\t * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n\t */\n\tsetUseStrictShallowCopy(value: StrictMode) {\n\t\tthis.useStrictShallowCopy_ = value\n\t}\n\n\t/**\n\t * Pass false to use faster iteration that skips non-enumerable properties\n\t * but still handles symbols for compatibility.\n\t *\n\t * By default, strict iteration is enabled (includes all own properties).\n\t */\n\tsetUseStrictIteration(value: boolean) {\n\t\tthis.useStrictIteration_ = value\n\t}\n\n\tshouldUseStrictIteration(): boolean {\n\t\treturn this.useStrictIteration_\n\t}\n\n\tapplyPatches(base: T, patches: readonly Patch[]): T {\n\t\t// If a patch replaces the entire state, take that replacement as base\n\t\t// before applying patches\n\t\tlet i: number\n\t\tfor (i = patches.length - 1; i >= 0; i--) {\n\t\t\tconst patch = patches[i]\n\t\t\tif (patch.path.length === 0 && patch.op === \"replace\") {\n\t\t\t\tbase = patch.value\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t// If there was a patch that replaced the entire state, start from the\n\t\t// patch after that.\n\t\tif (i > -1) {\n\t\t\tpatches = patches.slice(i + 1)\n\t\t}\n\n\t\tconst applyPatchesImpl = getPlugin(PluginPatches).applyPatches_\n\t\tif (isDraft(base)) {\n\t\t\t// N.B: never hits if some patch a replacement, patches are never drafts\n\t\t\treturn applyPatchesImpl(base, patches)\n\t\t}\n\t\t// Otherwise, produce a copy of the base state.\n\t\treturn this.produce(base, (draft: Drafted) =>\n\t\t\tapplyPatchesImpl(draft, patches)\n\t\t)\n\t}\n}\n\nexport function createProxy(\n\trootScope: ImmerScope,\n\tvalue: T,\n\tparent?: ImmerState,\n\tkey?: string | number | symbol\n): Drafted {\n\t// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft\n\t// returning a tuple here lets us skip a proxy access\n\t// to DRAFT_STATE later\n\tconst [draft, state] = isMap(value)\n\t\t? getPlugin(PluginMapSet).proxyMap_(value, parent)\n\t\t: isSet(value)\n\t\t? getPlugin(PluginMapSet).proxySet_(value, parent)\n\t\t: createProxyProxy(value, parent)\n\n\tconst scope = parent?.scope_ ?? getCurrentScope()\n\tscope.drafts_.push(draft)\n\n\t// Ensure the parent callbacks are passed down so we actually\n\t// track all callbacks added throughout the tree\n\tstate.callbacks_ = parent?.callbacks_ ?? []\n\tstate.key_ = key\n\n\tif (parent && key !== undefined) {\n\t\tregisterChildFinalizationCallback(parent, state, key)\n\t} else {\n\t\t// It's a root draft, register it with the scope\n\t\tstate.callbacks_.push(function rootDraftCleanup(rootScope) {\n\t\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\t\tconst {patchPlugin_} = rootScope\n\n\t\t\tif (state.modified_ && patchPlugin_) {\n\t\t\t\tpatchPlugin_.generatePatches_(state, [], rootScope)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn draft as any\n}\n","import {\n\tdie,\n\tisDraft,\n\tshallowCopy,\n\teach,\n\tDRAFT_STATE,\n\tset,\n\tImmerState,\n\tisDraftable,\n\tisFrozen\n} from \"../internal\"\n\n/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */\nexport function current(value: T): T\nexport function current(value: any): any {\n\tif (!isDraft(value)) die(10, value)\n\treturn currentImpl(value)\n}\n\nfunction currentImpl(value: any): any {\n\tif (!isDraftable(value) || isFrozen(value)) return value\n\tconst state: ImmerState | undefined = value[DRAFT_STATE]\n\tlet copy: any\n\tlet strict = true // Default to strict for compatibility\n\tif (state) {\n\t\tif (!state.modified_) return state.base_\n\t\t// Optimization: avoid generating new drafts during copying\n\t\tstate.finalized_ = true\n\t\tcopy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)\n\t\tstrict = state.scope_.immer_.shouldUseStrictIteration()\n\t} else {\n\t\tcopy = shallowCopy(value, true)\n\t}\n\t// recurse\n\teach(\n\t\tcopy,\n\t\t(key, childValue) => {\n\t\t\tset(copy, key, currentImpl(childValue))\n\t\t},\n\t\tstrict\n\t)\n\tif (state) {\n\t\tstate.finalized_ = false\n\t}\n\treturn copy\n}\n","import {immerable} from \"../immer\"\nimport {\n\tImmerState,\n\tPatch,\n\tSetState,\n\tProxyArrayState,\n\tMapState,\n\tProxyObjectState,\n\tPatchPath,\n\tget,\n\teach,\n\thas,\n\tgetArchtype,\n\tgetPrototypeOf,\n\tisSet,\n\tisMap,\n\tloadPlugin,\n\tArchType,\n\tdie,\n\tisDraft,\n\tisDraftable,\n\tNOTHING,\n\terrors,\n\tDRAFT_STATE,\n\tgetProxyDraft,\n\tImmerScope,\n\tisObjectish,\n\tisFunction,\n\tCONSTRUCTOR,\n\tPluginPatches,\n\tisArray,\n\tPROTOTYPE\n} from \"../internal\"\n\nexport function enablePatches() {\n\tconst errorOffset = 16\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\terrors.push(\n\t\t\t'Sets cannot have \"replace\" patches.',\n\t\t\tfunction(op: string) {\n\t\t\t\treturn \"Unsupported patch operation: \" + op\n\t\t\t},\n\t\t\tfunction(path: string) {\n\t\t\t\treturn \"Cannot apply patch, path doesn't resolve: \" + path\n\t\t\t},\n\t\t\t\"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n\t\t)\n\t}\n\n\tfunction getPath(state: ImmerState, path: PatchPath = []): PatchPath | null {\n\t\t// Step 1: Check if state has a stored key\n\t\tif (\"key_\" in state && state.key_ !== undefined) {\n\t\t\t// Step 2: Validate the key is still valid in parent\n\n\t\t\tconst parentCopy = state.parent_!.copy_ ?? state.parent_!.base_\n\t\t\tconst proxyDraft = getProxyDraft(get(parentCopy, state.key_!))\n\t\t\tconst valueAtKey = get(parentCopy, state.key_!)\n\n\t\t\tif (valueAtKey === undefined) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\t// Check if the value at the key is still related to this draft\n\t\t\t// It should be either the draft itself, the base, or the copy\n\t\t\tif (\n\t\t\t\tvalueAtKey !== state.draft_ &&\n\t\t\t\tvalueAtKey !== state.base_ &&\n\t\t\t\tvalueAtKey !== state.copy_\n\t\t\t) {\n\t\t\t\treturn null // Value was replaced with something else\n\t\t\t}\n\t\t\tif (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n\t\t\t\treturn null // Different draft\n\t\t\t}\n\n\t\t\t// Step 3: Handle Set case specially\n\t\t\tconst isSet = state.parent_!.type_ === ArchType.Set\n\t\t\tlet key: string | number\n\n\t\t\tif (isSet) {\n\t\t\t\t// For Sets, find the index in the drafts_ map\n\t\t\t\tconst setParent = state.parent_ as SetState\n\t\t\t\tkey = Array.from(setParent.drafts_.keys()).indexOf(state.key_)\n\t\t\t} else {\n\t\t\t\tkey = state.key_ as string | number\n\t\t\t}\n\n\t\t\t// Step 4: Validate key still exists in parent\n\t\t\tif (!((isSet && parentCopy.size > key) || has(parentCopy, key))) {\n\t\t\t\treturn null // Key deleted\n\t\t\t}\n\n\t\t\t// Step 5: Add key to path\n\t\t\tpath.push(key)\n\t\t}\n\n\t\t// Step 6: Recurse to parent if exists\n\t\tif (state.parent_) {\n\t\t\treturn getPath(state.parent_, path)\n\t\t}\n\n\t\t// Step 7: At root - reverse path and validate\n\t\tpath.reverse()\n\n\t\ttry {\n\t\t\t// Validate path can be resolved from ROOT\n\t\t\tresolvePath(state.copy_, path)\n\t\t} catch (e) {\n\t\t\treturn null // Path invalid\n\t\t}\n\n\t\treturn path\n\t}\n\n\t// NEW: Add resolvePath helper function\n\tfunction resolvePath(base: any, path: PatchPath): any {\n\t\tlet current = base\n\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\tconst key = path[i]\n\t\t\tcurrent = get(current, key)\n\t\t\tif (!isObjectish(current) || current === null) {\n\t\t\t\tthrow new Error(`Cannot resolve path at '${path.join(\"/\")}'`)\n\t\t\t}\n\t\t}\n\t\treturn current\n\t}\n\n\tconst REPLACE = \"replace\"\n\tconst ADD = \"add\"\n\tconst REMOVE = \"remove\"\n\n\tfunction generatePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\tscope: ImmerScope\n\t): void {\n\t\tif (state.scope_.processedForPatches_.has(state)) {\n\t\t\treturn\n\t\t}\n\n\t\tstate.scope_.processedForPatches_.add(state)\n\n\t\tconst {patches_, inversePatches_} = scope\n\n\t\tswitch (state.type_) {\n\t\t\tcase ArchType.Object:\n\t\t\tcase ArchType.Map:\n\t\t\t\treturn generatePatchesFromAssigned(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Array:\n\t\t\t\treturn generateArrayPatches(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Set:\n\t\t\t\treturn generateSetPatches(\n\t\t\t\t\t(state as any) as SetState,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t}\n\t}\n\n\tfunction generateArrayPatches(\n\t\tstate: ProxyArrayState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, assigned_} = state\n\t\tlet copy_ = state.copy_!\n\n\t\t// Reduce complexity by ensuring `base` is never longer.\n\t\tif (copy_.length < base_.length) {\n\t\t\t// @ts-ignore\n\t\t\t;[base_, copy_] = [copy_, base_]\n\t\t\t;[patches, inversePatches] = [inversePatches, patches]\n\t\t}\n\n\t\tconst allReassigned = state.allIndicesReassigned_ === true\n\n\t\t// Process replaced indices.\n\t\tfor (let i = 0; i < base_.length; i++) {\n\t\t\tconst copiedItem = copy_[i]\n\t\t\tconst baseItem = base_[i]\n\n\t\t\tconst isAssigned = allReassigned || assigned_?.get(i.toString())\n\t\t\tif (isAssigned && copiedItem !== baseItem) {\n\t\t\t\tconst childState = copiedItem?.[DRAFT_STATE]\n\t\t\t\tif (childState && childState.modified_) {\n\t\t\t\t\t// Skip - let the child generate its own patches\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(copiedItem)\n\t\t\t\t})\n\t\t\t\tinversePatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(baseItem)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Process added indices.\n\t\tfor (let i = base_.length; i < copy_.length; i++) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tpatches.push({\n\t\t\t\top: ADD,\n\t\t\t\tpath,\n\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\tvalue: clonePatchValueIfNeeded(copy_[i])\n\t\t\t})\n\t\t}\n\t\tfor (let i = copy_.length - 1; base_.length <= i; --i) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tinversePatches.push({\n\t\t\t\top: REMOVE,\n\t\t\t\tpath\n\t\t\t})\n\t\t}\n\t}\n\n\t// This is used for both Map objects and normal objects.\n\tfunction generatePatchesFromAssigned(\n\t\tstate: MapState | ProxyObjectState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tconst {base_, copy_, type_} = state\n\t\teach(state.assigned_!, (key, assignedValue) => {\n\t\t\tconst origValue = get(base_, key, type_)\n\t\t\tconst value = get(copy_!, key, type_)\n\t\t\tconst op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD\n\t\t\tif (origValue === value && op === REPLACE) return\n\t\t\tconst path = basePath.concat(key as any)\n\t\t\tpatches.push(\n\t\t\t\top === REMOVE\n\t\t\t\t\t? {op, path}\n\t\t\t\t\t: {op, path, value: clonePatchValueIfNeeded(value)}\n\t\t\t)\n\t\t\tinversePatches.push(\n\t\t\t\top === ADD\n\t\t\t\t\t? {op: REMOVE, path}\n\t\t\t\t\t: op === REMOVE\n\t\t\t\t\t? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t\t\t: {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t)\n\t\t})\n\t}\n\n\tfunction generateSetPatches(\n\t\tstate: SetState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, copy_} = state\n\n\t\tlet i = 0\n\t\tbase_.forEach((value: any) => {\n\t\t\tif (!copy_!.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t\ti = 0\n\t\tcopy_!.forEach((value: any) => {\n\t\t\tif (!base_.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t}\n\n\tfunction generateReplacementPatches_(\n\t\tbaseValue: any,\n\t\treplacement: any,\n\t\tscope: ImmerScope\n\t): void {\n\t\tconst {patches_, inversePatches_} = scope\n\t\tpatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: replacement === NOTHING ? undefined : replacement\n\t\t})\n\t\tinversePatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: baseValue\n\t\t})\n\t}\n\n\tfunction applyPatches_(draft: T, patches: readonly Patch[]): T {\n\t\tpatches.forEach(patch => {\n\t\t\tconst {path, op} = patch\n\n\t\t\tlet base: any = draft\n\t\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\t\tconst parentType = getArchtype(base)\n\t\t\t\tlet p = path[i]\n\t\t\t\tif (typeof p !== \"string\" && typeof p !== \"number\") {\n\t\t\t\t\tp = \"\" + p\n\t\t\t\t}\n\n\t\t\t\t// See #738, avoid prototype pollution\n\t\t\t\tif (\n\t\t\t\t\t(parentType === ArchType.Object || parentType === ArchType.Array) &&\n\t\t\t\t\t(p === \"__proto__\" || p === CONSTRUCTOR)\n\t\t\t\t)\n\t\t\t\t\tdie(errorOffset + 3)\n\t\t\t\tif (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3)\n\t\t\t\tbase = get(base, p)\n\t\t\t\tif (!isObjectish(base)) die(errorOffset + 2, path.join(\"/\"))\n\t\t\t}\n\n\t\t\tconst type = getArchtype(base)\n\t\t\tconst value = deepClonePatchValue(patch.value) // used to clone patch to ensure original patch is not modified, see #411\n\t\t\tconst key = path[path.length - 1]\n\t\t\tswitch (op) {\n\t\t\t\tcase REPLACE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\tdie(errorOffset)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t// if value is an object, then it's assigned by reference\n\t\t\t\t\t\t\t// in the following add or remove ops, the value field inside the patch will also be modifyed\n\t\t\t\t\t\t\t// so we use value from the cloned patch\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase ADD:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn key === \"-\"\n\t\t\t\t\t\t\t\t? base.push(value)\n\t\t\t\t\t\t\t\t: base.splice(key as any, 0, value)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.add(value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase REMOVE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn base.splice(key as any, 1)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.delete(key)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.delete(patch.value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn delete base[key]\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tdie(errorOffset + 1, op)\n\t\t\t}\n\t\t})\n\n\t\treturn draft\n\t}\n\n\t// optimize: this is quite a performance hit, can we detect intelligently when it is needed?\n\t// E.g. auto-draft when new objects from outside are assigned and modified?\n\t// (See failing test when deepClone just returns obj)\n\tfunction deepClonePatchValue(obj: T): T\n\tfunction deepClonePatchValue(obj: any) {\n\t\tif (!isDraftable(obj)) return obj\n\t\tif (isArray(obj)) return obj.map(deepClonePatchValue)\n\t\tif (isMap(obj))\n\t\t\treturn new Map(\n\t\t\t\tArray.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n\t\t\t)\n\t\tif (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue))\n\t\tconst cloned = Object.create(getPrototypeOf(obj))\n\t\tfor (const key in obj) cloned[key] = deepClonePatchValue(obj[key])\n\t\tif (has(obj, immerable)) cloned[immerable] = obj[immerable]\n\t\treturn cloned\n\t}\n\n\tfunction clonePatchValueIfNeeded(obj: T): T {\n\t\tif (isDraft(obj)) {\n\t\t\treturn deepClonePatchValue(obj)\n\t\t} else return obj\n\t}\n\n\tloadPlugin(PluginPatches, {\n\t\tapplyPatches_,\n\t\tgeneratePatches_,\n\t\tgenerateReplacementPatches_,\n\t\tgetPath\n\t})\n}\n","// types only!\nimport {\n\tImmerState,\n\tAnyMap,\n\tAnySet,\n\tMapState,\n\tSetState,\n\tDRAFT_STATE,\n\tgetCurrentScope,\n\tlatest,\n\tisDraftable,\n\tcreateProxy,\n\tloadPlugin,\n\tmarkChanged,\n\tdie,\n\tArchType,\n\teach,\n\tgetValue,\n\tPluginMapSet\n} from \"../internal\"\n\nexport function enableMapSet() {\n\tclass DraftMap extends Map {\n\t\t[DRAFT_STATE]: MapState\n\n\t\tconstructor(target: AnyMap, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Map,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this as any,\n\t\t\t\tisManual_: false,\n\t\t\t\trevoked_: false,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(key: any): boolean {\n\t\t\treturn latest(this[DRAFT_STATE]).has(key)\n\t\t}\n\n\t\tset(key: any, value: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!latest(state).has(key) || latest(state).get(key) !== value) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t\tstate.copy_!.set(key, value)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(key: any): boolean {\n\t\t\tif (!this.has(key)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareMapCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\tif (state.base_.has(key)) {\n\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t} else {\n\t\t\t\tstate.assigned_!.delete(key)\n\t\t\t}\n\t\t\tstate.copy_!.delete(key)\n\t\t\treturn true\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_ = new Map()\n\t\t\t\teach(state.base_, key => {\n\t\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t\t})\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tforEach(cb: (value: any, key: any, self: any) => void, thisArg?: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tlatest(state).forEach((_value: any, key: any, _map: any) => {\n\t\t\t\tcb.call(thisArg, this.get(key), key, this)\n\t\t\t})\n\t\t}\n\n\t\tget(key: any): any {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tconst value = latest(state).get(key)\n\t\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\t\treturn value\n\t\t\t}\n\t\t\tif (value !== state.base_.get(key)) {\n\t\t\t\treturn value // either already drafted or reassigned\n\t\t\t}\n\t\t\t// despite what it looks, this creates a draft only once, see above condition\n\t\t\tconst draft = createProxy(state.scope_, value, state, key)\n\t\t\tprepareMapCopy(state)\n\t\t\tstate.copy_!.set(key, draft)\n\t\t\treturn draft\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn latest(this[DRAFT_STATE]).keys()\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.values(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.entries(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue: [r.value, value]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.entries()\n\t\t}\n\t}\n\n\tfunction proxyMap_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, MapState] {\n\t\t// @ts-ignore\n\t\tconst map = new DraftMap(target, parent)\n\t\treturn [map as any, map[DRAFT_STATE]]\n\t}\n\n\tfunction prepareMapCopy(state: MapState) {\n\t\tif (!state.copy_) {\n\t\t\tstate.assigned_ = new Map()\n\t\t\tstate.copy_ = new Map(state.base_)\n\t\t}\n\t}\n\n\tclass DraftSet extends Set {\n\t\t[DRAFT_STATE]: SetState\n\t\tconstructor(target: AnySet, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Set,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this,\n\t\t\t\tdrafts_: new Map(),\n\t\t\t\trevoked_: false,\n\t\t\t\tisManual_: false,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(value: any): boolean {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\t// bit of trickery here, to be able to recognize both the value, and the draft of its value\n\t\t\tif (!state.copy_) {\n\t\t\t\treturn state.base_.has(value)\n\t\t\t}\n\t\t\tif (state.copy_.has(value)) return true\n\t\t\tif (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n\t\t\t\treturn true\n\t\t\treturn false\n\t\t}\n\n\t\tadd(value: any): any {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!this.has(value)) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.add(value)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(value: any): any {\n\t\t\tif (!this.has(value)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\treturn (\n\t\t\t\tstate.copy_!.delete(value) ||\n\t\t\t\t(state.drafts_.has(value)\n\t\t\t\t\t? state.copy_!.delete(state.drafts_.get(value))\n\t\t\t\t\t: /* istanbul ignore next */ false)\n\t\t\t)\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.values()\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.entries()\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn this.values()\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.values()\n\t\t}\n\n\t\tforEach(cb: any, thisArg?: any) {\n\t\t\tconst iterator = this.values()\n\t\t\tlet result = iterator.next()\n\t\t\twhile (!result.done) {\n\t\t\t\tcb.call(thisArg, result.value, result.value, this)\n\t\t\t\tresult = iterator.next()\n\t\t\t}\n\t\t}\n\t}\n\tfunction proxySet_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, SetState] {\n\t\t// @ts-ignore\n\t\tconst set = new DraftSet(target, parent)\n\t\treturn [set as any, set[DRAFT_STATE]]\n\t}\n\n\tfunction prepareSetCopy(state: SetState) {\n\t\tif (!state.copy_) {\n\t\t\t// create drafts for all entries to preserve insertion order\n\t\t\tstate.copy_ = new Set()\n\t\t\tstate.base_.forEach(value => {\n\t\t\t\tif (isDraftable(value)) {\n\t\t\t\t\tconst draft = createProxy(state.scope_, value, state, value)\n\t\t\t\t\tstate.drafts_.set(value, draft)\n\t\t\t\t\tstate.copy_!.add(draft)\n\t\t\t\t} else {\n\t\t\t\t\tstate.copy_!.add(value)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n\n\tfunction assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {\n\t\tif (state.revoked_) die(3, JSON.stringify(latest(state)))\n\t}\n\n\tfunction fixSetContents(target: ImmerState) {\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\tif (target.type_ === ArchType.Set && target.copy_) {\n\t\t\tconst copy = new Set(target.copy_)\n\t\t\ttarget.copy_.clear()\n\t\t\tcopy.forEach(value => {\n\t\t\t\ttarget.copy_!.add(getValue(value))\n\t\t\t})\n\t\t}\n\t}\n\n\tloadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents})\n}\n","import {\n\tPluginArrayMethods,\n\tlatest,\n\tloadPlugin,\n\tmarkChanged,\n\tprepareCopy,\n\tProxyArrayState\n} from \"../internal\"\n\n/**\n * Methods that directly modify the array in place.\n * These operate on the copy without creating per-element proxies:\n * - `push`, `pop`: Add/remove from end\n * - `shift`, `unshift`: Add/remove from start (marks all indices reassigned)\n * - `splice`: Add/remove at arbitrary position (marks all indices reassigned)\n * - `reverse`, `sort`: Reorder elements (marks all indices reassigned)\n */\ntype MutatingArrayMethod =\n\t| \"push\"\n\t| \"pop\"\n\t| \"shift\"\n\t| \"unshift\"\n\t| \"splice\"\n\t| \"reverse\"\n\t| \"sort\"\n\n/**\n * Methods that read from the array without modifying it.\n * These fall into distinct categories based on return semantics:\n *\n * **Subset operations** (return drafts - mutations propagate):\n * - `filter`, `slice`: Return array of draft proxies\n * - `find`, `findLast`: Return single draft proxy or undefined\n *\n * **Transform operations** (return base values - mutations don't track):\n * - `concat`, `flat`: Create new structures, not subsets of original\n *\n * **Primitive-returning** (no draft needed):\n * - `findIndex`, `findLastIndex`, `indexOf`, `lastIndexOf`: Return numbers\n * - `some`, `every`, `includes`: Return booleans\n * - `join`, `toString`, `toLocaleString`: Return strings\n */\ntype NonMutatingArrayMethod =\n\t| \"filter\"\n\t| \"slice\"\n\t| \"concat\"\n\t| \"flat\"\n\t| \"find\"\n\t| \"findIndex\"\n\t| \"findLast\"\n\t| \"findLastIndex\"\n\t| \"some\"\n\t| \"every\"\n\t| \"indexOf\"\n\t| \"lastIndexOf\"\n\t| \"includes\"\n\t| \"join\"\n\t| \"toString\"\n\t| \"toLocaleString\"\n\n/** Union of all array operation methods handled by the plugin. */\nexport type ArrayOperationMethod = MutatingArrayMethod | NonMutatingArrayMethod\n\n/**\n * Enables optimized array method handling for Immer drafts.\n *\n * This plugin overrides array methods to avoid unnecessary Proxy creation during iteration,\n * significantly improving performance for array-heavy operations.\n *\n * **Mutating methods** (push, pop, shift, unshift, splice, sort, reverse):\n * Operate directly on the copy without creating per-element proxies.\n *\n * **Non-mutating methods** fall into categories:\n * - **Subset operations** (filter, slice, find, findLast): Return draft proxies - mutations track\n * - **Transform operations** (concat, flat): Return base values - mutations don't track\n * - **Primitive-returning** (indexOf, includes, some, every, etc.): Return primitives\n *\n * **Important**: Callbacks for overridden methods receive base values, not drafts.\n * This is the core performance optimization.\n *\n * @example\n * ```ts\n * import { enableArrayMethods, produce } from \"immer\"\n *\n * enableArrayMethods()\n *\n * const next = produce(state, draft => {\n * // Optimized - no proxy creation per element\n * draft.items.sort((a, b) => a.value - b.value)\n *\n * // filter returns drafts - mutations propagate\n * const filtered = draft.items.filter(x => x.value > 5)\n * filtered[0].value = 999 // Affects draft.items[originalIndex]\n * })\n * ```\n *\n * @see https://immerjs.github.io/immer/array-methods\n */\nexport function enableArrayMethods() {\n\tconst SHIFTING_METHODS = new Set([\"shift\", \"unshift\"])\n\n\tconst QUEUE_METHODS = new Set([\"push\", \"pop\"])\n\n\tconst RESULT_RETURNING_METHODS = new Set([\n\t\t...QUEUE_METHODS,\n\t\t...SHIFTING_METHODS\n\t])\n\n\tconst REORDERING_METHODS = new Set([\"reverse\", \"sort\"])\n\n\t// Optimized method detection using array-based lookup\n\tconst MUTATING_METHODS = new Set([\n\t\t...RESULT_RETURNING_METHODS,\n\t\t...REORDERING_METHODS,\n\t\t\"splice\"\n\t])\n\n\tconst FIND_METHODS = new Set([\"find\", \"findLast\"])\n\n\tconst NON_MUTATING_METHODS = new Set([\n\t\t\"filter\",\n\t\t\"slice\",\n\t\t\"concat\",\n\t\t\"flat\",\n\t\t...FIND_METHODS,\n\t\t\"findIndex\",\n\t\t\"findLastIndex\",\n\t\t\"some\",\n\t\t\"every\",\n\t\t\"indexOf\",\n\t\t\"lastIndexOf\",\n\t\t\"includes\",\n\t\t\"join\",\n\t\t\"toString\",\n\t\t\"toLocaleString\"\n\t])\n\n\t// Type guard for method detection\n\tfunction isMutatingArrayMethod(\n\t\tmethod: string\n\t): method is MutatingArrayMethod {\n\t\treturn MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isNonMutatingArrayMethod(\n\t\tmethod: string\n\t): method is NonMutatingArrayMethod {\n\t\treturn NON_MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isArrayOperationMethod(\n\t\tmethod: string\n\t): method is ArrayOperationMethod {\n\t\treturn isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method)\n\t}\n\n\tfunction enterOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: ArrayOperationMethod\n\t) {\n\t\tstate.operationMethod = method\n\t}\n\n\tfunction exitOperation(state: ProxyArrayState) {\n\t\tstate.operationMethod = undefined\n\t}\n\n\t// Shared utility functions for array method handlers\n\tfunction executeArrayMethod(\n\t\tstate: ProxyArrayState,\n\t\toperation: () => T,\n\t\tmarkLength = true\n\t): T {\n\t\tprepareCopy(state)\n\t\tconst result = operation()\n\t\tmarkChanged(state)\n\t\tif (markLength) state.assigned_!.set(\"length\", true)\n\t\treturn result\n\t}\n\n\tfunction markAllIndicesReassigned(state: ProxyArrayState) {\n\t\tstate.allIndicesReassigned_ = true\n\t}\n\n\tfunction normalizeSliceIndex(index: number, length: number): number {\n\t\tif (index < 0) {\n\t\t\treturn Math.max(length + index, 0)\n\t\t}\n\t\treturn Math.min(index, length)\n\t}\n\n\t/**\n\t * Handles mutating operations that add/remove elements (push, pop, shift, unshift, splice).\n\t *\n\t * Operates directly on `state.copy_` without creating per-element proxies.\n\t * For shifting methods (shift, unshift), marks all indices as reassigned since\n\t * indices shift.\n\t *\n\t * @returns For push/pop/shift/unshift: the native method result. For others: the draft.\n\t */\n\tfunction handleSimpleOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(state, () => {\n\t\t\tconst result = (state.copy_! as any)[method](...args)\n\n\t\t\t// Handle index reassignment for shifting methods\n\t\t\tif (SHIFTING_METHODS.has(method as MutatingArrayMethod)) {\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t}\n\n\t\t\t// Return appropriate value based on method\n\t\t\treturn RESULT_RETURNING_METHODS.has(method as MutatingArrayMethod)\n\t\t\t\t? result\n\t\t\t\t: state.draft_\n\t\t})\n\t}\n\n\t/**\n\t * Handles reordering operations (reverse, sort) that change element order.\n\t *\n\t * Operates directly on `state.copy_` and marks all indices as reassigned\n\t * since element positions change. Does not mark length as changed since\n\t * these operations preserve array length.\n\t *\n\t * @returns The draft proxy for method chaining.\n\t */\n\tfunction handleReorderingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(\n\t\t\tstate,\n\t\t\t() => {\n\t\t\t\t;(state.copy_! as any)[method](...args)\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\treturn state.draft_\n\t\t\t},\n\t\t\tfalse\n\t\t) // Don't mark length as changed\n\t}\n\n\t/**\n\t * Creates an interceptor function for a specific array method.\n\t *\n\t * The interceptor wraps array method calls to:\n\t * 1. Set `state.operationMethod` flag during execution (allows proxy `get` trap\n\t * to detect we're inside an optimized method and skip proxy creation)\n\t * 2. Route to appropriate handler based on method type\n\t * 3. Clean up the operation flag in `finally` block\n\t *\n\t * The `operationMethod` flag is the key mechanism that enables the proxy's `get`\n\t * trap to return base values instead of creating nested proxies during iteration.\n\t *\n\t * @param state - The proxy array state\n\t * @param originalMethod - Name of the array method being intercepted\n\t * @returns Interceptor function that handles the method call\n\t */\n\tfunction createMethodInterceptor(\n\t\tstate: ProxyArrayState,\n\t\toriginalMethod: string\n\t) {\n\t\treturn function interceptedMethod(...args: any[]) {\n\t\t\t// Enter operation mode - this flag tells the proxy's get trap to return\n\t\t\t// base values instead of creating nested proxies during iteration\n\t\t\tconst method = originalMethod as ArrayOperationMethod\n\t\t\tenterOperation(state, method)\n\n\t\t\ttry {\n\t\t\t\t// Check if this is a mutating method\n\t\t\t\tif (isMutatingArrayMethod(method)) {\n\t\t\t\t\t// Direct method dispatch - no configuration lookup needed\n\t\t\t\t\tif (RESULT_RETURNING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleSimpleOperation(state, method, args)\n\t\t\t\t\t}\n\t\t\t\t\tif (REORDERING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleReorderingOperation(state, method, args)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"splice\") {\n\t\t\t\t\t\tconst res = executeArrayMethod(state, () =>\n\t\t\t\t\t\t\tstate.copy_!.splice(...(args as [number, number, ...any[]]))\n\t\t\t\t\t\t)\n\t\t\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\t\t\treturn res\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Handle non-mutating methods\n\t\t\t\t\treturn handleNonMutatingOperation(state, method, args)\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\t// Always exit operation mode - must be in finally to handle exceptions\n\t\t\t\texitOperation(state)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles non-mutating array methods with different return semantics.\n\t *\n\t * **Subset operations** return draft proxies for mutation tracking:\n\t * - `filter`, `slice`: Return `state.draft_[i]` for each selected element\n\t * - `find`, `findLast`: Return `state.draft_[i]` for the found element\n\t *\n\t * This allows mutations on returned elements to propagate back to the draft:\n\t * ```ts\n\t * const filtered = draft.items.filter(x => x.value > 5)\n\t * filtered[0].value = 999 // Mutates draft.items[originalIndex]\n\t * ```\n\t *\n\t * **Transform operations** return base values (no draft tracking):\n\t * - `concat`, `flat`: These create NEW arrays rather than selecting subsets.\n\t * Since the result structure differs from the original, tracking mutations\n\t * back to specific draft indices would be impractical/impossible.\n\t *\n\t * **Primitive operations** return the native result directly:\n\t * - `indexOf`, `includes`, `some`, `every`, `join`, etc.\n\t *\n\t * @param state - The proxy array state\n\t * @param method - The non-mutating method name\n\t * @param args - Arguments passed to the method\n\t * @returns Drafts for subset operations, base values for transforms, primitives otherwise\n\t */\n\tfunction handleNonMutatingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: NonMutatingArrayMethod,\n\t\targs: any[]\n\t) {\n\t\tconst source = latest(state)\n\n\t\t// Methods that return arrays with selected items - need to return drafts\n\t\tif (method === \"filter\") {\n\t\t\tconst predicate = args[0]\n\t\t\tconst result: any[] = []\n\n\t\t\t// First pass: call predicate on base values to determine which items pass\n\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\t// Only create draft for items that passed the predicate\n\t\t\t\t\tresult.push(state.draft_[i])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\tif (FIND_METHODS.has(method)) {\n\t\t\tconst predicate = args[0]\n\t\t\tconst isForward = method === \"find\"\n\t\t\tconst step = isForward ? 1 : -1\n\t\t\tconst start = isForward ? 0 : source.length - 1\n\n\t\t\tfor (let i = start; i >= 0 && i < source.length; i += step) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\treturn state.draft_[i]\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (method === \"slice\") {\n\t\t\tconst rawStart = args[0] ?? 0\n\t\t\tconst rawEnd = args[1] ?? source.length\n\n\t\t\t// Normalize negative indices\n\t\t\tconst start = normalizeSliceIndex(rawStart, source.length)\n\t\t\tconst end = normalizeSliceIndex(rawEnd, source.length)\n\n\t\t\tconst result: any[] = []\n\n\t\t\t// Return drafts for items in the slice range\n\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\tresult.push(state.draft_[i])\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\t// For other methods, call on base array directly:\n\t\t// - indexOf, includes, join, toString: Return primitives, no draft needed\n\t\t// - concat, flat: Return NEW arrays (not subsets). Elements are base values.\n\t\t// This is intentional - concat/flat create new data structures rather than\n\t\t// selecting subsets of the original, making draft tracking impractical.\n\t\treturn source[method as keyof typeof Array.prototype](...args)\n\t}\n\n\tloadPlugin(PluginArrayMethods, {\n\t\tcreateMethodInterceptor,\n\t\tisArrayOperationMethod,\n\t\tisMutatingArrayMethod\n\t})\n}\n","import {\n\tIProduce,\n\tIProduceWithPatches,\n\tImmer,\n\tDraft,\n\tImmutable,\n\tNOTHING as nothing\n} from \"./internal\"\n\nexport {\n\tDraft,\n\tWritableDraft,\n\tImmutable,\n\tPatch,\n\tPatchListener,\n\tProducer,\n\toriginal,\n\tcurrent,\n\tisDraft,\n\tisDraftable,\n\tDRAFTABLE as immerable,\n\tfreeze,\n\tObjectish,\n\tStrictMode\n} from \"./internal\"\n\nexport {nothing}\n\nconst immer = new Immer()\n\n/**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\nexport const produce: IProduce = /* @__PURE__ */ immer.produce\n\n/**\n * Like `produce`, but `produceWithPatches` always returns a tuple\n * [nextState, patches, inversePatches] (instead of just the next state)\n */\nexport const produceWithPatches: IProduceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(\n\timmer\n)\n\n/**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * Always freeze by default, even in production mode\n */\nexport const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)\n\n/**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\nexport const setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(\n\timmer\n)\n\n/**\n * Pass false to use loose iteration that only processes enumerable string properties.\n * This skips symbols and non-enumerable properties for maximum performance.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\nexport const setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(\n\timmer\n)\n\n/**\n * Apply an array of Immer patches to the first argument.\n *\n * This function is a producer, which means copy-on-write is in effect.\n */\nexport const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)\n\n/**\n * Create an Immer draft from the given base state, which may be a draft itself.\n * The draft can be modified until you finalize it with the `finishDraft` function.\n */\nexport const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)\n\n/**\n * Finalize an Immer draft from a `createDraft` call, returning the base state\n * (if no changes were made) or a modified copy. The draft must *not* be\n * mutated afterwards.\n *\n * Pass a function as the 2nd argument to generate Immer patches based on the\n * changes that were made.\n */\nexport const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)\n\n/**\n * This function is actually a no-op, but can be used to cast an immutable type\n * to an draft type and make TypeScript happy\n *\n * @param value\n */\nexport let castDraft = (value: T): Draft => value as any\n\n/**\n * This function is actually a no-op, but can be used to cast a mutable type\n * to an immutable type and make TypeScript happy\n * @param value\n */\nexport let castImmutable = (value: T): Immutable => value as any\n\nexport {Immer}\n\nexport {enablePatches} from \"./plugins/patches\"\nexport {enableMapSet} from \"./plugins/mapset\"\nexport {enableArrayMethods} from \"./plugins/arrayMethods\"\n\nexport function isNothing(value: unknown): value is typeof nothing {\n\treturn value === nothing\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAKO,IAAM,UAAyB,OAAO,IAAI,eAAe;AAUzD,IAAM,YAA2B,OAAO,IAAI,iBAAiB;AAE7D,IAAM,cAA6B,OAAO,IAAI,aAAa;;;ACf3D,IAAM,SACZ,QAAQ,IAAI,aAAa,eACtB;AAAA;AAAA,EAEA,SAAS,QAAgB;AACxB,WAAO,mBAAmB,yFAAyF;AAAA,EACpH;AAAA,EACA,SAAS,OAAe;AACvB,WAAO,sJAAsJ;AAAA,EAC9J;AAAA,EACA;AAAA,EACA,SAAS,MAAW;AACnB,WACC,yHACA;AAAA,EAEF;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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M,wBAAwC,sBAAM,sBAAsB;AAAA,EAChF;AACD;AAOO,IAAM,eAA+B,sBAAM,aAAa,KAAK,KAAK;AAMlE,IAAM,cAA8B,sBAAM,YAAY,KAAK,KAAK;AAUhE,IAAM,cAA8B,sBAAM,YAAY,KAAK,KAAK;AAQhE,IAAI,YAAY,CAAI,UAAuB;AAO3C,IAAI,gBAAgB,CAAI,UAA2B;AAQnD,SAAS,UAAU,OAAyC;AAClE,SAAO,UAAU;AAClB;","names":["immer","current","Immer","base","rootScope","_a","isSet","current","set","Immer"]} \ No newline at end of file diff --git a/dist/immer.mjs b/dist/immer.mjs new file mode 100644 index 00000000..95f2f1ff --- /dev/null +++ b/dist/immer.mjs @@ -0,0 +1,1655 @@ +// src/utils/env.ts +var NOTHING = Symbol.for("immer-nothing") +var DRAFTABLE = Symbol.for("immer-draftable") +var DRAFT_STATE = Symbol.for("immer-state") + +// src/utils/errors.ts +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, ...args) { + if (process.env.NODE_ENV !== "production") { + const e = errors[error] + const msg = isFunction(e) ? 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` + ) +} + +// src/utils/common.ts +var O = Object +var getPrototypeOf = O.getPrototypeOf +var CONSTRUCTOR = "constructor" +var PROTOTYPE = "prototype" +var CONFIGURABLE = "configurable" +var ENUMERABLE = "enumerable" +var WRITABLE = "writable" +var VALUE = "value" +var isDraft = value => !!value && !!value[DRAFT_STATE] +function isDraftable(value) { + if (!value) return false + return ( + isPlainObject(value) || + isArray(value) || + !!value[DRAFTABLE] || + !!value[CONSTRUCTOR]?.[DRAFTABLE] || + isMap(value) || + isSet(value) + ) +} +var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString() +var cachedCtorStrings = /* @__PURE__ */ new WeakMap() +function isPlainObject(value) { + if (!value || !isObjectish(value)) return false + const proto = getPrototypeOf(value) + if (proto === null || proto === O[PROTOTYPE]) return true + const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR] + if (Ctor === Object) return true + if (!isFunction(Ctor)) return false + let ctorString = cachedCtorStrings.get(Ctor) + if (ctorString === void 0) { + ctorString = Function.toString.call(Ctor) + cachedCtorStrings.set(Ctor, ctorString) + } + return ctorString === objectCtorString +} +function original(value) { + if (!isDraft(value)) die(15, value) + return value[DRAFT_STATE].base_ +} +function each(obj, iter, strict = true) { + if (getArchtype(obj) === 0 /* Object */) { + const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj) + keys.forEach(key => { + iter(key, obj[key], obj) + }) + } else { + obj.forEach((entry, index) => iter(index, entry, obj)) + } +} +function getArchtype(thing) { + const state = thing[DRAFT_STATE] + return state + ? state.type_ + : isArray(thing) + ? 1 /* Array */ + : isMap(thing) + ? 2 /* Map */ + : isSet(thing) + ? 3 /* Set */ + : 0 /* Object */ +} +var has = (thing, prop, type = getArchtype(thing)) => + type === 2 /* Map */ + ? thing.has(prop) + : O[PROTOTYPE].hasOwnProperty.call(thing, prop) +var get = (thing, prop, type = getArchtype(thing)) => + // @ts-ignore + type === 2 /* Map */ ? thing.get(prop) : thing[prop] +var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => { + if (type === 2 /* Map */) thing.set(propOrOldValue, value) + else if (type === 3 /* Set */) { + thing.add(value) + } else thing[propOrOldValue] = value +} +function is(x, y) { + if (x === y) { + return x !== 0 || 1 / x === 1 / y + } else { + return x !== x && y !== y + } +} +var isArray = Array.isArray +var isMap = target => target instanceof Map +var isSet = target => target instanceof Set +var isObjectish = target => typeof target === "object" +var isFunction = target => typeof target === "function" +var isBoolean = target => typeof target === "boolean" +function isArrayIndex(value) { + const n = +value + return Number.isInteger(n) && String(n) === value +} +var getProxyDraft = value => { + if (!isObjectish(value)) return null + return value?.[DRAFT_STATE] +} +var latest = state => state.copy_ || state.base_ +var getValue = value => { + const proxyDraft = getProxyDraft(value) + return proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value +} +var getFinalValue = state => (state.modified_ ? state.copy_ : state.base_) +function shallowCopy(base, strict) { + if (isMap(base)) { + return new Map(base) + } + if (isSet(base)) { + return new Set(base) + } + if (isArray(base)) return Array[PROTOTYPE].slice.call(base) + const isPlain = isPlainObject(base) + if (strict === true || (strict === "class_only" && !isPlain)) { + const descriptors = O.getOwnPropertyDescriptors(base) + delete descriptors[DRAFT_STATE] + let keys = Reflect.ownKeys(descriptors) + for (let i = 0; i < keys.length; i++) { + const key = keys[i] + const desc = descriptors[key] + if (desc[WRITABLE] === false) { + desc[WRITABLE] = true + desc[CONFIGURABLE] = true + } + if (desc.get || desc.set) + descriptors[key] = { + [CONFIGURABLE]: true, + [WRITABLE]: true, + // could live with !!desc.set as well here... + [ENUMERABLE]: desc[ENUMERABLE], + [VALUE]: base[key] + } + } + return O.create(getPrototypeOf(base), descriptors) + } else { + const proto = getPrototypeOf(base) + if (proto !== null && isPlain) { + return {...base} + } + const obj = O.create(proto) + return O.assign(obj, base) + } +} +function freeze(obj, deep = false) { + if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj + if (getArchtype(obj) > 1) { + O.defineProperties(obj, { + set: dontMutateMethodOverride, + add: dontMutateMethodOverride, + clear: dontMutateMethodOverride, + delete: dontMutateMethodOverride + }) + } + O.freeze(obj) + if (deep) + each( + obj, + (_key, value) => { + freeze(value, true) + }, + false + ) + return obj +} +function dontMutateFrozenCollections() { + die(2) +} +var dontMutateMethodOverride = { + [VALUE]: dontMutateFrozenCollections +} +function isFrozen(obj) { + if (obj === null || !isObjectish(obj)) return true + return O.isFrozen(obj) +} + +// src/utils/plugins.ts +var PluginMapSet = "MapSet" +var PluginPatches = "Patches" +var PluginArrayMethods = "ArrayMethods" +var plugins = {} +function getPlugin(pluginKey) { + const plugin = plugins[pluginKey] + if (!plugin) { + die(0, pluginKey) + } + return plugin +} +var isPluginLoaded = pluginKey => !!plugins[pluginKey] +function loadPlugin(pluginKey, implementation) { + if (!plugins[pluginKey]) plugins[pluginKey] = implementation +} + +// src/core/scope.ts +var currentScope +var getCurrentScope = () => currentScope +var createScope = (parent_, immer_) => ({ + drafts_: [], + parent_, + 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, + handledSet_: /* @__PURE__ */ new Set(), + processedForPatches_: /* @__PURE__ */ new Set(), + mapSetPlugin_: isPluginLoaded(PluginMapSet) + ? getPlugin(PluginMapSet) + : void 0, + arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) + ? getPlugin(PluginArrayMethods) + : void 0 +}) +function usePatchesInScope(scope, patchListener) { + if (patchListener) { + scope.patchPlugin_ = getPlugin(PluginPatches) + scope.patches_ = [] + scope.inversePatches_ = [] + scope.patchListener_ = patchListener + } +} +function revokeScope(scope) { + leaveScope(scope) + scope.drafts_.forEach(revokeDraft) + scope.drafts_ = null +} +function leaveScope(scope) { + if (scope === currentScope) { + currentScope = scope.parent_ + } +} +var enterScope = immer2 => (currentScope = createScope(currentScope, immer2)) +function revokeDraft(draft) { + const state = draft[DRAFT_STATE] + if (state.type_ === 0 /* Object */ || state.type_ === 1 /* Array */) + state.revoke_() + else state.revoked_ = true +} + +// src/core/finalize.ts +function processResult(result, scope) { + scope.unfinalizedDrafts_ = scope.drafts_.length + const baseDraft = scope.drafts_[0] + const isReplaced = result !== void 0 && result !== baseDraft + if (isReplaced) { + if (baseDraft[DRAFT_STATE].modified_) { + revokeScope(scope) + die(4) + } + if (isDraftable(result)) { + result = finalize(scope, result) + } + const {patchPlugin_} = scope + if (patchPlugin_) { + patchPlugin_.generateReplacementPatches_( + baseDraft[DRAFT_STATE].base_, + result, + scope + ) + } + } else { + result = finalize(scope, baseDraft) + } + maybeFreeze(scope, result, true) + revokeScope(scope) + if (scope.patches_) { + scope.patchListener_(scope.patches_, scope.inversePatches_) + } + return result !== NOTHING ? result : void 0 +} +function finalize(rootScope, value) { + if (isFrozen(value)) return value + const state = value[DRAFT_STATE] + if (!state) { + const finalValue = handleValue(value, rootScope.handledSet_, rootScope) + return finalValue + } + if (!isSameScope(state, rootScope)) { + return value + } + if (!state.modified_) { + return state.base_ + } + if (!state.finalized_) { + const {callbacks_} = state + if (callbacks_) { + while (callbacks_.length > 0) { + const callback = callbacks_.pop() + callback(rootScope) + } + } + generatePatchesAndFinalize(state, rootScope) + } + return state.copy_ +} +function maybeFreeze(scope, value, deep = false) { + if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) { + freeze(value, deep) + } +} +function markStateFinalized(state) { + state.finalized_ = true + state.scope_.unfinalizedDrafts_-- +} +var isSameScope = (state, rootScope) => state.scope_ === rootScope +var EMPTY_LOCATIONS_RESULT = [] +function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) { + const parentCopy = latest(parent) + const parentType = parent.type_ + if (originalKey !== void 0) { + const currentValue = get(parentCopy, originalKey, parentType) + if (currentValue === draftValue) { + set(parentCopy, originalKey, finalizedValue, parentType) + return + } + } + if (!parent.draftLocations_) { + const draftLocations = (parent.draftLocations_ = /* @__PURE__ */ new Map()) + each(parentCopy, (key, value) => { + if (isDraft(value)) { + const keys = draftLocations.get(value) || [] + keys.push(key) + draftLocations.set(value, keys) + } + }) + } + const locations = + parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT + for (const location of locations) { + set(parentCopy, location, finalizedValue, parentType) + } +} +function registerChildFinalizationCallback(parent, child, key) { + parent.callbacks_.push(function childCleanup(rootScope) { + const state = child + if (!state || !isSameScope(state, rootScope)) { + return + } + rootScope.mapSetPlugin_?.fixSetContents(state) + const finalizedValue = getFinalValue(state) + updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key) + generatePatchesAndFinalize(state, rootScope) + }) +} +function generatePatchesAndFinalize(state, rootScope) { + const shouldFinalize = + state.modified_ && + !state.finalized_ && + (state.type_ === 3 /* Set */ || + (state.type_ === 1 /* Array */ && state.allIndicesReassigned_) || + (state.assigned_?.size ?? 0) > 0) + if (shouldFinalize) { + const {patchPlugin_} = rootScope + if (patchPlugin_) { + const basePath = patchPlugin_.getPath(state) + if (basePath) { + patchPlugin_.generatePatches_(state, basePath, rootScope) + } + } + markStateFinalized(state) + } +} +function handleCrossReference(target, key, value) { + const {scope_} = target + if (isDraft(value)) { + const state = value[DRAFT_STATE] + if (isSameScope(state, scope_)) { + state.callbacks_.push(function crossReferenceCleanup() { + prepareCopy(target) + const finalizedValue = getFinalValue(state) + updateDraftInParent(target, value, finalizedValue, key) + }) + } + } else if (isDraftable(value)) { + target.callbacks_.push(function nestedDraftCleanup() { + const targetCopy = latest(target) + if (get(targetCopy, key, target.type_) === value) { + if ( + scope_.drafts_.length > 1 && + (target.assigned_.get(key) ?? false) === true && + target.copy_ + ) { + handleValue( + get(target.copy_, key, target.type_), + scope_.handledSet_, + scope_ + ) + } + } + }) + } +} +function handleValue(target, handledSet, rootScope) { + if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) { + return target + } + if ( + isDraft(target) || + handledSet.has(target) || + !isDraftable(target) || + isFrozen(target) + ) { + return target + } + handledSet.add(target) + each(target, (key, value) => { + if (isDraft(value)) { + const state = value[DRAFT_STATE] + if (isSameScope(state, rootScope)) { + const updatedValue = getFinalValue(state) + set(target, key, updatedValue, target.type_) + markStateFinalized(state) + } + } else if (isDraftable(value)) { + handleValue(value, handledSet, rootScope) + } + }) + return target +} + +// src/core/proxy.ts +function createProxyProxy(base, parent) { + const baseIsArray = isArray(base) + const state = { + type_: baseIsArray ? 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). + // actually instantiated in `prepareCopy()` + assigned_: void 0, + // The parent draft state. + parent_: parent, + // The base state. + base_: base, + // The base proxy. + draft_: null, + // set below + // The base copy with any updated values. + copy_: null, + // Called by the `produce` function. + revoke_: null, + isManual_: false, + // `callbacks` actually gets assigned in `createProxy` + callbacks_: void 0 + } + let target = state + let traps = objectTraps + if (baseIsArray) { + target = [state] + traps = arrayTraps + } + const {revoke, proxy} = Proxy.revocable(target, traps) + state.draft_ = proxy + state.revoke_ = revoke + return [proxy, state] +} +var objectTraps = { + get(state, prop) { + if (prop === DRAFT_STATE) return state + let arrayPlugin = state.scope_.arrayMethodsPlugin_ + const isArrayWithStringProp = + state.type_ === 1 /* Array */ && typeof prop === "string" + if (isArrayWithStringProp) { + if (arrayPlugin?.isArrayOperationMethod(prop)) { + return arrayPlugin.createMethodInterceptor(state, prop) + } + } + const source = latest(state) + if (!has(source, prop, state.type_)) { + return readPropFromProto(state, source, prop) + } + const value = source[prop] + if (state.finalized_ || !isDraftable(value)) { + return value + } + if ( + isArrayWithStringProp && + state.operationMethod && + arrayPlugin?.isMutatingArrayMethod(state.operationMethod) && + isArrayIndex(prop) + ) { + return value + } + if (value === peek(state.base_, prop)) { + prepareCopy(state) + const childKey = state.type_ === 1 /* Array */ ? +prop : prop + const childDraft = createProxy(state.scope_, value, state, childKey) + return (state.copy_[childKey] = childDraft) + } + return value + }, + has(state, prop) { + return prop in latest(state) + }, + ownKeys(state) { + return Reflect.ownKeys(latest(state)) + }, + set(state, prop, value) { + const desc = getDescriptorFromProto(latest(state), prop) + if (desc?.set) { + desc.set.call(state.draft_, value) + return true + } + if (!state.modified_) { + const current2 = peek(latest(state), prop) + const currentState = current2?.[DRAFT_STATE] + if (currentState && currentState.base_ === value) { + state.copy_[prop] = value + state.assigned_.set(prop, false) + return true + } + if ( + is(value, current2) && + (value !== void 0 || has(state.base_, prop, state.type_)) + ) + return true + prepareCopy(state) + markChanged(state) + } + if ( + (state.copy_[prop] === value && // special case: handle new props with value 'undefined' + (value !== void 0 || prop in state.copy_)) || // special case: NaN + (Number.isNaN(value) && Number.isNaN(state.copy_[prop])) + ) + return true + state.copy_[prop] = value + state.assigned_.set(prop, true) + handleCrossReference(state, prop, value) + return true + }, + deleteProperty(state, prop) { + prepareCopy(state) + if (peek(state.base_, prop) !== void 0 || prop in state.base_) { + state.assigned_.set(prop, false) + markChanged(state) + } else { + state.assigned_.delete(prop) + } + if (state.copy_) { + 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(state, prop) { + const owner = latest(state) + const 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() { + die(11) + }, + getPrototypeOf(state) { + return getPrototypeOf(state.base_) + }, + setPrototypeOf() { + die(12) + } +} +var arrayTraps = {} +each(objectTraps, (key, fn) => { + arrayTraps[key] = function() { + const args = arguments + args[0] = args[0][0] + return fn.apply(this, args) + } +}) +arrayTraps.deleteProperty = function(state, prop) { + if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop))) die(13) + return arrayTraps.set.call(this, state, prop, void 0) +} +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]) +} +function peek(draft, prop) { + const state = draft[DRAFT_STATE] + const source = state ? latest(state) : draft + return source[prop] +} +function readPropFromProto(state, source, prop) { + const 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?.call(state.draft_) + : void 0 +} +function getDescriptorFromProto(source, prop) { + if (!(prop in source)) return void 0 + let proto = getPrototypeOf(source) + while (proto) { + const desc = Object.getOwnPropertyDescriptor(proto, prop) + if (desc) return desc + proto = getPrototypeOf(proto) + } + return void 0 +} +function markChanged(state) { + if (!state.modified_) { + state.modified_ = true + if (state.parent_) { + markChanged(state.parent_) + } + } +} +function prepareCopy(state) { + if (!state.copy_) { + state.assigned_ = /* @__PURE__ */ new Map() + state.copy_ = shallowCopy( + state.base_, + state.scope_.immer_.useStrictShallowCopy_ + ) + } +} + +// src/core/immerClass.ts +var Immer2 = class { + constructor(config) { + this.autoFreeze_ = true + this.useStrictShallowCopy_ = false + this.useStrictIteration_ = 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 = (base, recipe, patchListener) => { + if (isFunction(base) && !isFunction(recipe)) { + const defaultBase = recipe + recipe = base + const self = this + return function curriedProduce(base2 = defaultBase, ...args) { + return self.produce(base2, draft => recipe.call(this, draft, ...args)) + } + } + if (!isFunction(recipe)) die(6) + if (patchListener !== void 0 && !isFunction(patchListener)) die(7) + let result + if (isDraftable(base)) { + const scope = enterScope(this) + const proxy = createProxy(scope, base, void 0) + let hasError = true + try { + result = recipe(proxy) + hasError = false + } finally { + if (hasError) revokeScope(scope) + else leaveScope(scope) + } + usePatchesInScope(scope, patchListener) + return processResult(result, scope) + } else if (!base || !isObjectish(base)) { + result = recipe(base) + if (result === void 0) result = base + if (result === NOTHING) result = void 0 + if (this.autoFreeze_) freeze(result, true) + if (patchListener) { + const p = [] + const ip = [] + getPlugin(PluginPatches).generateReplacementPatches_(base, result, { + patches_: p, + inversePatches_: ip + }) + patchListener(p, ip) + } + return result + } else die(1, base) + } + this.produceWithPatches = (base, recipe) => { + if (isFunction(base)) { + return (state, ...args) => + this.produceWithPatches(state, draft => base(draft, ...args)) + } + let patches, inversePatches + const result = this.produce(base, recipe, (p, ip) => { + patches = p + inversePatches = ip + }) + return [result, patches, inversePatches] + } + if (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config.autoFreeze) + if (isBoolean(config?.useStrictShallowCopy)) + this.setUseStrictShallowCopy(config.useStrictShallowCopy) + if (isBoolean(config?.useStrictIteration)) + this.setUseStrictIteration(config.useStrictIteration) + } + createDraft(base) { + if (!isDraftable(base)) die(8) + if (isDraft(base)) base = current(base) + const scope = enterScope(this) + const proxy = createProxy(scope, base, void 0) + proxy[DRAFT_STATE].isManual_ = true + leaveScope(scope) + return proxy + } + finishDraft(draft, patchListener) { + const state = draft && draft[DRAFT_STATE] + if (!state || !state.isManual_) die(9) + const {scope_: scope} = state + usePatchesInScope(scope, patchListener) + return processResult(void 0, scope) + } + /** + * Pass true to automatically freeze all copies created by Immer. + * + * By default, auto-freezing is enabled. + */ + 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. + */ + setUseStrictShallowCopy(value) { + this.useStrictShallowCopy_ = value + } + /** + * Pass false to use faster iteration that skips non-enumerable properties + * but still handles symbols for compatibility. + * + * By default, strict iteration is enabled (includes all own properties). + */ + setUseStrictIteration(value) { + this.useStrictIteration_ = value + } + shouldUseStrictIteration() { + return this.useStrictIteration_ + } + applyPatches(base, patches) { + let i + for (i = patches.length - 1; i >= 0; i--) { + const patch = patches[i] + if (patch.path.length === 0 && patch.op === "replace") { + base = patch.value + break + } + } + if (i > -1) { + patches = patches.slice(i + 1) + } + const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_ + if (isDraft(base)) { + return applyPatchesImpl(base, patches) + } + return this.produce(base, draft => applyPatchesImpl(draft, patches)) + } +} +function createProxy(rootScope, value, parent, key) { + const [draft, state] = isMap(value) + ? getPlugin(PluginMapSet).proxyMap_(value, parent) + : isSet(value) + ? getPlugin(PluginMapSet).proxySet_(value, parent) + : createProxyProxy(value, parent) + const scope = parent?.scope_ ?? getCurrentScope() + scope.drafts_.push(draft) + state.callbacks_ = parent?.callbacks_ ?? [] + state.key_ = key + if (parent && key !== void 0) { + registerChildFinalizationCallback(parent, state, key) + } else { + state.callbacks_.push(function rootDraftCleanup(rootScope2) { + rootScope2.mapSetPlugin_?.fixSetContents(state) + const {patchPlugin_} = rootScope2 + if (state.modified_ && patchPlugin_) { + patchPlugin_.generatePatches_(state, [], rootScope2) + } + }) + } + return draft +} + +// src/core/current.ts +function current(value) { + if (!isDraft(value)) die(10, value) + return currentImpl(value) +} +function currentImpl(value) { + if (!isDraftable(value) || isFrozen(value)) return value + const state = value[DRAFT_STATE] + let copy + let strict = true + if (state) { + if (!state.modified_) return state.base_ + state.finalized_ = true + copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_) + strict = state.scope_.immer_.shouldUseStrictIteration() + } else { + copy = shallowCopy(value, true) + } + each( + copy, + (key, childValue) => { + set(copy, key, currentImpl(childValue)) + }, + strict + ) + if (state) { + state.finalized_ = false + } + return copy +} + +// src/plugins/patches.ts +function enablePatches() { + const 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" + ) + } + function getPath(state, path = []) { + if ("key_" in state && state.key_ !== void 0) { + const parentCopy = state.parent_.copy_ ?? state.parent_.base_ + const proxyDraft = getProxyDraft(get(parentCopy, state.key_)) + const valueAtKey = get(parentCopy, state.key_) + if (valueAtKey === void 0) { + return null + } + if ( + valueAtKey !== state.draft_ && + valueAtKey !== state.base_ && + valueAtKey !== state.copy_ + ) { + return null + } + if (proxyDraft != null && proxyDraft.base_ !== state.base_) { + return null + } + const isSet2 = state.parent_.type_ === 3 /* Set */ + let key + if (isSet2) { + const setParent = state.parent_ + key = Array.from(setParent.drafts_.keys()).indexOf(state.key_) + } else { + key = state.key_ + } + if (!((isSet2 && parentCopy.size > key) || has(parentCopy, key))) { + return null + } + path.push(key) + } + if (state.parent_) { + return getPath(state.parent_, path) + } + path.reverse() + try { + resolvePath(state.copy_, path) + } catch (e) { + return null + } + return path + } + function resolvePath(base, path) { + let current2 = base + for (let i = 0; i < path.length - 1; i++) { + const key = path[i] + current2 = get(current2, key) + if (!isObjectish(current2) || current2 === null) { + throw new Error(`Cannot resolve path at '${path.join("/")}'`) + } + } + return current2 + } + const REPLACE = "replace" + const ADD = "add" + const REMOVE = "remove" + function generatePatches_(state, basePath, scope) { + if (state.scope_.processedForPatches_.has(state)) { + return + } + state.scope_.processedForPatches_.add(state) + const {patches_, inversePatches_} = scope + 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) { + let {base_, assigned_} = state + let copy_ = state.copy_ + if (copy_.length < base_.length) { + ;[base_, copy_] = [copy_, base_] + ;[patches, inversePatches] = [inversePatches, patches] + } + const allReassigned = state.allIndicesReassigned_ === true + for (let i = 0; i < base_.length; i++) { + const copiedItem = copy_[i] + const baseItem = base_[i] + const isAssigned = allReassigned || assigned_?.get(i.toString()) + if (isAssigned && copiedItem !== baseItem) { + const childState = copiedItem?.[DRAFT_STATE] + if (childState && childState.modified_) { + continue + } + const path = basePath.concat([i]) + patches.push({ + op: REPLACE, + 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(copiedItem) + }) + inversePatches.push({ + op: REPLACE, + path, + value: clonePatchValueIfNeeded(baseItem) + }) + } + } + for (let i = base_.length; i < copy_.length; i++) { + const path = basePath.concat([i]) + patches.push({ + op: ADD, + 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 (let i = copy_.length - 1; base_.length <= i; --i) { + const path = basePath.concat([i]) + inversePatches.push({ + op: REMOVE, + path + }) + } + } + function generatePatchesFromAssigned( + state, + basePath, + patches, + inversePatches + ) { + const {base_, copy_, type_} = state + each(state.assigned_, (key, assignedValue) => { + const origValue = get(base_, key, type_) + const value = get(copy_, key, type_) + const op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD + if (origValue === value && op === REPLACE) return + const path = basePath.concat(key) + patches.push( + op === REMOVE + ? {op, path} + : {op, path, value: clonePatchValueIfNeeded(value)} + ) + inversePatches.push( + op === ADD + ? {op: REMOVE, path} + : op === REMOVE + ? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)} + : {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)} + ) + }) + } + function generateSetPatches(state, basePath, patches, inversePatches) { + let {base_, copy_} = state + let i = 0 + base_.forEach(value => { + if (!copy_.has(value)) { + const path = basePath.concat([i]) + patches.push({ + op: REMOVE, + path, + value + }) + inversePatches.unshift({ + op: ADD, + path, + value + }) + } + i++ + }) + i = 0 + copy_.forEach(value => { + if (!base_.has(value)) { + const path = basePath.concat([i]) + patches.push({ + op: ADD, + path, + value + }) + inversePatches.unshift({ + op: REMOVE, + path, + value + }) + } + i++ + }) + } + function generateReplacementPatches_(baseValue, replacement, scope) { + const {patches_, inversePatches_} = scope + patches_.push({ + op: REPLACE, + path: [], + value: replacement === NOTHING ? void 0 : replacement + }) + inversePatches_.push({ + op: REPLACE, + path: [], + value: baseValue + }) + } + function applyPatches_(draft, patches) { + patches.forEach(patch => { + const {path, op} = patch + let base = draft + for (let i = 0; i < path.length - 1; i++) { + const parentType = getArchtype(base) + let p = path[i] + if (typeof p !== "string" && typeof p !== "number") { + p = "" + p + } + if ( + (parentType === 0 /* Object */ || parentType === 1) /* Array */ && + (p === "__proto__" || p === CONSTRUCTOR) + ) + die(errorOffset + 3) + if (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3) + base = get(base, p) + if (!isObjectish(base)) die(errorOffset + 2, path.join("/")) + } + const type = getArchtype(base) + const value = deepClonePatchValue(patch.value) + const key = path[path.length - 1] + switch (op) { + case REPLACE: + switch (type) { + case 2 /* Map */: + return base.set(key, value) + case 3 /* Set */: + die(errorOffset) + default: + 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 (isArray(obj)) return obj.map(deepClonePatchValue) + if (isMap(obj)) + return new Map( + Array.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)]) + ) + if (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue)) + const cloned = Object.create(getPrototypeOf(obj)) + for (const 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(PluginPatches, { + applyPatches_, + generatePatches_, + generateReplacementPatches_, + getPath + }) +} + +// src/plugins/mapset.ts +function enableMapSet() { + class DraftMap extends Map { + constructor(target, parent) { + super() + this[DRAFT_STATE] = { + type_: 2 /* Map */, + parent_: parent, + scope_: parent ? parent.scope_ : getCurrentScope(), + modified_: false, + finalized_: false, + copy_: void 0, + assigned_: void 0, + base_: target, + draft_: this, + isManual_: false, + revoked_: false, + callbacks_: [] + } + } + get size() { + return latest(this[DRAFT_STATE]).size + } + has(key) { + return latest(this[DRAFT_STATE]).has(key) + } + set(key, value) { + const 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 + } + delete(key) { + if (!this.has(key)) { + return false + } + const 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 + } + clear() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareMapCopy(state) + markChanged(state) + state.assigned_ = /* @__PURE__ */ new Map() + each(state.base_, key => { + state.assigned_.set(key, false) + }) + state.copy_.clear() + } + } + forEach(cb, thisArg) { + const state = this[DRAFT_STATE] + latest(state).forEach((_value, key, _map) => { + cb.call(thisArg, this.get(key), key, this) + }) + } + get(key) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + const value = latest(state).get(key) + if (state.finalized_ || !isDraftable(value)) { + return value + } + if (value !== state.base_.get(key)) { + return value + } + const draft = createProxy(state.scope_, value, state, key) + prepareMapCopy(state) + state.copy_.set(key, draft) + return draft + } + keys() { + return latest(this[DRAFT_STATE]).keys() + } + values() { + const iterator = this.keys() + return { + [Symbol.iterator]: () => this.values(), + next: () => { + const r = iterator.next() + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value + } + } + } + } + entries() { + const iterator = this.keys() + return { + [Symbol.iterator]: () => this.entries(), + next: () => { + const r = iterator.next() + if (r.done) return r + const value = this.get(r.value) + return { + done: false, + value: [r.value, value] + } + } + } + } + [(DRAFT_STATE, Symbol.iterator)]() { + return this.entries() + } + } + function proxyMap_(target, parent) { + const map = new DraftMap(target, parent) + return [map, map[DRAFT_STATE]] + } + function prepareMapCopy(state) { + if (!state.copy_) { + state.assigned_ = /* @__PURE__ */ new Map() + state.copy_ = new Map(state.base_) + } + } + class DraftSet extends Set { + constructor(target, parent) { + super() + this[DRAFT_STATE] = { + type_: 3 /* Set */, + parent_: parent, + scope_: parent ? parent.scope_ : getCurrentScope(), + modified_: false, + finalized_: false, + copy_: void 0, + base_: target, + draft_: this, + drafts_: /* @__PURE__ */ new Map(), + revoked_: false, + isManual_: false, + assigned_: void 0, + callbacks_: [] + } + } + get size() { + return latest(this[DRAFT_STATE]).size + } + has(value) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + 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 + } + add(value) { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (!this.has(value)) { + prepareSetCopy(state) + markChanged(state) + state.copy_.add(value) + } + return this + } + delete(value) { + if (!this.has(value)) { + return false + } + const 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) + ) + } + clear() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + if (latest(state).size) { + prepareSetCopy(state) + markChanged(state) + state.copy_.clear() + } + } + values() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_.values() + } + entries() { + const state = this[DRAFT_STATE] + assertUnrevoked(state) + prepareSetCopy(state) + return state.copy_.entries() + } + keys() { + return this.values() + } + [(DRAFT_STATE, Symbol.iterator)]() { + return this.values() + } + forEach(cb, thisArg) { + const iterator = this.values() + let result = iterator.next() + while (!result.done) { + cb.call(thisArg, result.value, result.value, this) + result = iterator.next() + } + } + } + function proxySet_(target, parent) { + const set2 = new DraftSet(target, parent) + return [set2, set2[DRAFT_STATE]] + } + function prepareSetCopy(state) { + if (!state.copy_) { + state.copy_ = /* @__PURE__ */ new Set() + state.base_.forEach(value => { + if (isDraftable(value)) { + const draft = createProxy(state.scope_, value, state, value) + state.drafts_.set(value, draft) + state.copy_.add(draft) + } else { + state.copy_.add(value) + } + }) + } + } + function assertUnrevoked(state) { + if (state.revoked_) die(3, JSON.stringify(latest(state))) + } + function fixSetContents(target) { + if (target.type_ === 3 /* Set */ && target.copy_) { + const copy = new Set(target.copy_) + target.copy_.clear() + copy.forEach(value => { + target.copy_.add(getValue(value)) + }) + } + } + loadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents}) +} + +// src/plugins/arrayMethods.ts +function enableArrayMethods() { + const SHIFTING_METHODS = /* @__PURE__ */ new Set(["shift", "unshift"]) + const QUEUE_METHODS = /* @__PURE__ */ new Set(["push", "pop"]) + const RESULT_RETURNING_METHODS = /* @__PURE__ */ new Set([ + ...QUEUE_METHODS, + ...SHIFTING_METHODS + ]) + const REORDERING_METHODS = /* @__PURE__ */ new Set(["reverse", "sort"]) + const MUTATING_METHODS = /* @__PURE__ */ new Set([ + ...RESULT_RETURNING_METHODS, + ...REORDERING_METHODS, + "splice" + ]) + const FIND_METHODS = /* @__PURE__ */ new Set(["find", "findLast"]) + const NON_MUTATING_METHODS = /* @__PURE__ */ new Set([ + "filter", + "slice", + "concat", + "flat", + ...FIND_METHODS, + "findIndex", + "findLastIndex", + "some", + "every", + "indexOf", + "lastIndexOf", + "includes", + "join", + "toString", + "toLocaleString" + ]) + function isMutatingArrayMethod(method) { + return MUTATING_METHODS.has(method) + } + function isNonMutatingArrayMethod(method) { + return NON_MUTATING_METHODS.has(method) + } + function isArrayOperationMethod(method) { + return isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method) + } + function enterOperation(state, method) { + state.operationMethod = method + } + function exitOperation(state) { + state.operationMethod = void 0 + } + function executeArrayMethod(state, operation, markLength = true) { + prepareCopy(state) + const result = operation() + markChanged(state) + if (markLength) state.assigned_.set("length", true) + return result + } + function markAllIndicesReassigned(state) { + state.allIndicesReassigned_ = true + } + function normalizeSliceIndex(index, length) { + if (index < 0) { + return Math.max(length + index, 0) + } + return Math.min(index, length) + } + function handleSimpleOperation(state, method, args) { + return executeArrayMethod(state, () => { + const result = state.copy_[method](...args) + if (SHIFTING_METHODS.has(method)) { + markAllIndicesReassigned(state) + } + return RESULT_RETURNING_METHODS.has(method) ? result : state.draft_ + }) + } + function handleReorderingOperation(state, method, args) { + return executeArrayMethod( + state, + () => { + state.copy_[method](...args) + markAllIndicesReassigned(state) + return state.draft_ + }, + false + ) + } + function createMethodInterceptor(state, originalMethod) { + return function interceptedMethod(...args) { + const method = originalMethod + enterOperation(state, method) + try { + if (isMutatingArrayMethod(method)) { + if (RESULT_RETURNING_METHODS.has(method)) { + return handleSimpleOperation(state, method, args) + } + if (REORDERING_METHODS.has(method)) { + return handleReorderingOperation(state, method, args) + } + if (method === "splice") { + const res = executeArrayMethod(state, () => + state.copy_.splice(...args) + ) + markAllIndicesReassigned(state) + return res + } + } else { + return handleNonMutatingOperation(state, method, args) + } + } finally { + exitOperation(state) + } + } + } + function handleNonMutatingOperation(state, method, args) { + const source = latest(state) + if (method === "filter") { + const predicate = args[0] + const result = [] + for (let i = 0; i < source.length; i++) { + if (predicate(source[i], i, source)) { + result.push(state.draft_[i]) + } + } + return result + } + if (FIND_METHODS.has(method)) { + const predicate = args[0] + const isForward = method === "find" + const step = isForward ? 1 : -1 + const start = isForward ? 0 : source.length - 1 + for (let i = start; i >= 0 && i < source.length; i += step) { + if (predicate(source[i], i, source)) { + return state.draft_[i] + } + } + return void 0 + } + if (method === "slice") { + const rawStart = args[0] ?? 0 + const rawEnd = args[1] ?? source.length + const start = normalizeSliceIndex(rawStart, source.length) + const end = normalizeSliceIndex(rawEnd, source.length) + const result = [] + for (let i = start; i < end; i++) { + result.push(state.draft_[i]) + } + return result + } + return source[method](...args) + } + loadPlugin(PluginArrayMethods, { + createMethodInterceptor, + isArrayOperationMethod, + isMutatingArrayMethod + }) +} + +// src/immer.ts +var immer = new Immer2() +var produce = immer.produce +var produceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(immer) +var setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer) +var setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind( + immer +) +var setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind( + immer +) +var applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer) +var createDraft = /* @__PURE__ */ immer.createDraft.bind(immer) +var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer) +var castDraft = value => value +var castImmutable = value => value +function isNothing(value) { + return value === NOTHING +} +export { + Immer2 as Immer, + applyPatches, + castDraft, + castImmutable, + createDraft, + current, + enableArrayMethods, + enableMapSet, + enablePatches, + finishDraft, + freeze, + DRAFTABLE as immerable, + isDraft, + isDraftable, + isNothing, + NOTHING as nothing, + original, + produce, + produceWithPatches, + setAutoFreeze, + setUseStrictIteration, + setUseStrictShallowCopy +} +//# sourceMappingURL=immer.mjs.map diff --git a/dist/immer.mjs.map b/dist/immer.mjs.map new file mode 100644 index 00000000..3b7d63d4 --- /dev/null +++ b/dist/immer.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/utils/env.ts","../src/utils/errors.ts","../src/utils/common.ts","../src/utils/plugins.ts","../src/core/scope.ts","../src/core/finalize.ts","../src/core/proxy.ts","../src/core/immerClass.ts","../src/core/current.ts","../src/plugins/patches.ts","../src/plugins/mapset.ts","../src/plugins/arrayMethods.ts","../src/immer.ts"],"sourcesContent":["// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","import {isFunction} from \"../internal\"\n\nexport const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `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}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = isFunction(e) ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nconst O = Object\n\nexport const getPrototypeOf = O.getPrototypeOf\n\nexport const CONSTRUCTOR = \"constructor\"\nexport const PROTOTYPE = \"prototype\"\n\nexport const CONFIGURABLE = \"configurable\"\nexport const ENUMERABLE = \"enumerable\"\nexport const WRITABLE = \"writable\"\nexport const VALUE = \"value\"\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport let isDraft = (value: any): boolean => !!value && !!value[DRAFT_STATE]\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tisArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value[CONSTRUCTOR]?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString()\nconst cachedCtorStrings = new WeakMap()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || !isObjectish(value)) return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null || proto === O[PROTOTYPE]) return true\n\n\tconst Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR]\n\tif (Ctor === Object) return true\n\n\tif (!isFunction(Ctor)) return false\n\n\tlet ctorString = cachedCtorStrings.get(Ctor)\n\tif (ctorString === undefined) {\n\t\tctorString = Function.toString.call(Ctor)\n\t\tcachedCtorStrings.set(Ctor, ctorString)\n\t}\n\n\treturn ctorString === objectCtorString\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n *\n * @param obj The object to iterate over\n * @param iter The iterator function\n * @param strict When true (default), includes symbols and non-enumerable properties.\n * When false, uses looseiteration over only enumerable string properties.\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void,\n\tstrict?: boolean\n): void\nexport function each(obj: any, iter: any, strict: boolean = true) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\t// If strict, we do a full iteration including symbols and non-enumerable properties\n\t\t// Otherwise, we only iterate enumerable string properties for performance\n\t\tconst keys = strict ? Reflect.ownKeys(obj) : O.keys(obj)\n\t\tkeys.forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport let has = (\n\tthing: any,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): boolean =>\n\ttype === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: O[PROTOTYPE].hasOwnProperty.call(thing, prop)\n\n/*#__PURE__*/\nexport let get = (\n\tthing: AnyMap | AnyObject,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): any =>\n\t// @ts-ignore\n\ttype === ArchType.Map ? thing.get(prop) : thing[prop]\n\n/*#__PURE__*/\nexport let set = (\n\tthing: any,\n\tpropOrOldValue: PropertyKey,\n\tvalue: any,\n\ttype = getArchtype(thing)\n) => {\n\tif (type === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (type === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\nexport let isArray = Array.isArray\n\n/*#__PURE__*/\nexport let isMap = (target: any): target is AnyMap => target instanceof Map\n\n/*#__PURE__*/\nexport let isSet = (target: any): target is AnySet => target instanceof Set\n\nexport let isObjectish = (target: any) => typeof target === \"object\"\n\nexport let isFunction = (target: any): target is Function =>\n\ttypeof target === \"function\"\n\nexport let isBoolean = (target: any): target is boolean =>\n\ttypeof target === \"boolean\"\n\nexport function isArrayIndex(value: string | number): value is number | string {\n\tconst n = +value\n\treturn Number.isInteger(n) && String(n) === value\n}\n\nexport let getProxyDraft = (value: T): ImmerState | null => {\n\tif (!isObjectish(value)) return null\n\treturn (value as {[DRAFT_STATE]: any})?.[DRAFT_STATE]\n}\n\n/*#__PURE__*/\nexport let latest = (state: ImmerState): any => state.copy_ || state.base_\n\nexport let getValue = (value: T): T => {\n\tconst proxyDraft = getProxyDraft(value)\n\treturn proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value\n}\n\nexport let getFinalValue = (state: ImmerState): any =>\n\tstate.modified_ ? state.copy_ : state.base_\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (isArray(base)) return Array[PROTOTYPE].slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = O.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc[WRITABLE] === false) {\n\t\t\t\tdesc[WRITABLE] = true\n\t\t\t\tdesc[CONFIGURABLE] = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\t[CONFIGURABLE]: true,\n\t\t\t\t\t[WRITABLE]: true, // could live with !!desc.set as well here...\n\t\t\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t\t\t[VALUE]: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn O.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = O.create(proto)\n\t\treturn O.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tO.defineProperties(obj, {\n\t\t\tset: dontMutateMethodOverride,\n\t\t\tadd: dontMutateMethodOverride,\n\t\t\tclear: dontMutateMethodOverride,\n\t\t\tdelete: dontMutateMethodOverride\n\t\t})\n\t}\n\tO.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.values (only string-like, enumerables) instead of each()\n\t\teach(\n\t\t\tobj,\n\t\t\t(_key, value) => {\n\t\t\t\tfreeze(value, true)\n\t\t\t},\n\t\t\tfalse\n\t\t)\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nconst dontMutateMethodOverride = {\n\t[VALUE]: dontMutateFrozenCollections\n}\n\nexport function isFrozen(obj: any): boolean {\n\t// Fast path: primitives and null/undefined are always \"frozen\"\n\tif (obj === null || !isObjectish(obj)) return true\n\treturn O.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie,\n\tImmerScope,\n\tProxyArrayState\n} from \"../internal\"\n\nexport const PluginMapSet = \"MapSet\"\nexport const PluginPatches = \"Patches\"\nexport const PluginArrayMethods = \"ArrayMethods\"\n\nexport type PatchesPlugin = {\n\tgeneratePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\trootScope: ImmerScope\n\t): void\n\tgenerateReplacementPatches_(\n\t\tbase: any,\n\t\treplacement: any,\n\t\trootScope: ImmerScope\n\t): void\n\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\tgetPath: (state: ImmerState) => PatchPath | null\n}\n\nexport type MapSetPlugin = {\n\tproxyMap_(target: T, parent?: ImmerState): [T, ImmerState]\n\tproxySet_(target: T, parent?: ImmerState): [T, ImmerState]\n\tfixSetContents: (state: ImmerState) => void\n}\n\nexport type ArrayMethodsPlugin = {\n\tcreateMethodInterceptor: (state: ProxyArrayState, method: string) => Function\n\tisArrayOperationMethod: (method: string) => boolean\n\tisMutatingArrayMethod: (method: string) => boolean\n}\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: PatchesPlugin\n\tMapSet?: MapSetPlugin\n\tArrayMethods?: ArrayMethodsPlugin\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport let isPluginLoaded = (pluginKey: K): boolean =>\n\t!!plugins[pluginKey]\n\nexport let clearPlugin = (pluginKey: K): void => {\n\tdelete plugins[pluginKey]\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin,\n\tPatchesPlugin,\n\tMapSetPlugin,\n\tisPluginLoaded,\n\tPluginMapSet,\n\tPluginPatches,\n\tArrayMethodsPlugin,\n\tPluginArrayMethods\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tpatchPlugin_?: PatchesPlugin\n\tmapSetPlugin_?: MapSetPlugin\n\tarrayMethodsPlugin_?: ArrayMethodsPlugin\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n\thandledSet_: Set\n\tprocessedForPatches_: Set\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport let getCurrentScope = () => currentScope!\n\nlet createScope = (\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope => ({\n\tdrafts_: [],\n\tparent_,\n\timmer_,\n\t// Whenever the modified draft contains a draft from another scope, we\n\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\tcanAutoFreeze_: true,\n\tunfinalizedDrafts_: 0,\n\thandledSet_: new Set(),\n\tprocessedForPatches_: new Set(),\n\tmapSetPlugin_: isPluginLoaded(PluginMapSet)\n\t\t? getPlugin(PluginMapSet)\n\t\t: undefined,\n\tarrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods)\n\t\t? getPlugin(PluginArrayMethods)\n\t\t: undefined\n})\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tscope.patchPlugin_ = getPlugin(PluginPatches) // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport let enterScope = (immer: Immer) =>\n\t(currentScope = createScope(currentScope, immer))\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen,\n\tget,\n\tPatch,\n\tlatest,\n\tprepareCopy,\n\tgetFinalValue,\n\tgetValue,\n\tProxyArrayState\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t}\n\t\tconst {patchPlugin_} = scope\n\t\tif (patchPlugin_) {\n\t\t\tpatchPlugin_.generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft)\n\t}\n\n\tmaybeFreeze(scope, result, true)\n\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\tif (!state) {\n\t\tconst finalValue = handleValue(value, rootScope.handledSet_, rootScope)\n\t\treturn finalValue\n\t}\n\n\t// Never finalize drafts owned by another scope\n\tif (!isSameScope(state, rootScope)) {\n\t\treturn value\n\t}\n\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\treturn state.base_\n\t}\n\n\tif (!state.finalized_) {\n\t\t// Execute all registered draft finalization callbacks\n\t\tconst {callbacks_} = state\n\t\tif (callbacks_) {\n\t\t\twhile (callbacks_.length > 0) {\n\t\t\t\tconst callback = callbacks_.pop()!\n\t\t\t\tcallback(rootScope)\n\t\t\t}\n\t\t}\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t}\n\n\t// By now the root copy has been fully updated throughout its tree\n\treturn state.copy_\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n\nfunction markStateFinalized(state: ImmerState) {\n\tstate.finalized_ = true\n\tstate.scope_.unfinalizedDrafts_--\n}\n\nlet isSameScope = (state: ImmerState, rootScope: ImmerScope) =>\n\tstate.scope_ === rootScope\n\n// A reusable empty array to avoid allocations\nconst EMPTY_LOCATIONS_RESULT: (string | symbol | number)[] = []\n\n// Updates all references to a draft in its parent to the finalized value.\n// This handles cases where the same draft appears multiple times in the parent, or has been moved around.\nexport function updateDraftInParent(\n\tparent: ImmerState,\n\tdraftValue: any,\n\tfinalizedValue: any,\n\toriginalKey?: string | number | symbol\n): void {\n\tconst parentCopy = latest(parent)\n\tconst parentType = parent.type_\n\n\t// Fast path: Check if draft is still at original key\n\tif (originalKey !== undefined) {\n\t\tconst currentValue = get(parentCopy, originalKey, parentType)\n\t\tif (currentValue === draftValue) {\n\t\t\t// Still at original location, just update it\n\t\t\tset(parentCopy, originalKey, finalizedValue, parentType)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Slow path: Build reverse mapping of all children\n\t// to their indices in the parent, so that we can\n\t// replace all locations where this draft appears.\n\t// We only have to build this once per parent.\n\tif (!parent.draftLocations_) {\n\t\tconst draftLocations = (parent.draftLocations_ = new Map())\n\n\t\t// Use `each` which works on Arrays, Maps, and Objects\n\t\teach(parentCopy, (key, value) => {\n\t\t\tif (isDraft(value)) {\n\t\t\t\tconst keys = draftLocations.get(value) || []\n\t\t\t\tkeys.push(key)\n\t\t\t\tdraftLocations.set(value, keys)\n\t\t\t}\n\t\t})\n\t}\n\n\t// Look up all locations where this draft appears\n\tconst locations =\n\t\tparent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT\n\n\t// Update all locations\n\tfor (const location of locations) {\n\t\tset(parentCopy, location, finalizedValue, parentType)\n\t}\n}\n\n// Register a callback to finalize a child draft when the parent draft is finalized.\n// This assumes there is a parent -> child relationship between the two drafts,\n// and we have a key to locate the child in the parent.\nexport function registerChildFinalizationCallback(\n\tparent: ImmerState,\n\tchild: ImmerState,\n\tkey: string | number | symbol\n) {\n\tparent.callbacks_.push(function childCleanup(rootScope) {\n\t\tconst state: ImmerState = child\n\n\t\t// Can only continue if this is a draft owned by this scope\n\t\tif (!state || !isSameScope(state, rootScope)) {\n\t\t\treturn\n\t\t}\n\n\t\t// Handle potential set value finalization first\n\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t// Update all locations in the parent that referenced this draft\n\t\tupdateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key)\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t})\n}\n\nfunction generatePatchesAndFinalize(state: ImmerState, rootScope: ImmerScope) {\n\tconst shouldFinalize =\n\t\tstate.modified_ &&\n\t\t!state.finalized_ &&\n\t\t(state.type_ === ArchType.Set ||\n\t\t\t(state.type_ === ArchType.Array &&\n\t\t\t\t(state as ProxyArrayState).allIndicesReassigned_) ||\n\t\t\t(state.assigned_?.size ?? 0) > 0)\n\n\tif (shouldFinalize) {\n\t\tconst {patchPlugin_} = rootScope\n\t\tif (patchPlugin_) {\n\t\t\tconst basePath = patchPlugin_!.getPath(state)\n\n\t\t\tif (basePath) {\n\t\t\t\tpatchPlugin_!.generatePatches_(state, basePath, rootScope)\n\t\t\t}\n\t\t}\n\n\t\tmarkStateFinalized(state)\n\t}\n}\n\nexport function handleCrossReference(\n\ttarget: ImmerState,\n\tkey: string | number | symbol,\n\tvalue: any\n) {\n\tconst {scope_} = target\n\t// Check if value is a draft from this scope\n\tif (isDraft(value)) {\n\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\tif (isSameScope(state, scope_)) {\n\t\t\t// Register callback to update this location when the draft finalizes\n\n\t\t\tstate.callbacks_.push(function crossReferenceCleanup() {\n\t\t\t\t// Update the target location with finalized value\n\t\t\t\tprepareCopy(target)\n\n\t\t\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t\t\tupdateDraftInParent(target, value, finalizedValue, key)\n\t\t\t})\n\t\t}\n\t} else if (isDraftable(value)) {\n\t\t// Handle non-draft objects that might contain drafts\n\t\ttarget.callbacks_.push(function nestedDraftCleanup() {\n\t\t\tconst targetCopy = latest(target)\n\n\t\t\tif (get(targetCopy, key, target.type_) === value) {\n\t\t\t\t// Process the value to replace any nested drafts\n\t\t\t\t// finalizeAssigned(target, key, target.scope_)\n\n\t\t\t\tif (\n\t\t\t\t\tscope_.drafts_.length > 1 &&\n\t\t\t\t\t((target as Exclude).assigned_!.get(key) ??\n\t\t\t\t\t\tfalse) === true &&\n\t\t\t\t\ttarget.copy_\n\t\t\t\t) {\n\t\t\t\t\t// This might be a non-draft value that has drafts\n\t\t\t\t\t// inside. We do need to recurse here to handle those.\n\t\t\t\t\thandleValue(\n\t\t\t\t\t\tget(target.copy_, key, target.type_),\n\t\t\t\t\t\tscope_.handledSet_,\n\t\t\t\t\t\tscope_\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport function handleValue(\n\ttarget: any,\n\thandledSet: Set,\n\trootScope: ImmerScope\n) {\n\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t// This benefits especially adding large data tree's without further processing.\n\t\t// See add-data.js perf test\n\t\treturn target\n\t}\n\n\t// Skip if already handled, frozen, or not draftable\n\tif (\n\t\tisDraft(target) ||\n\t\thandledSet.has(target) ||\n\t\t!isDraftable(target) ||\n\t\tisFrozen(target)\n\t) {\n\t\treturn target\n\t}\n\n\thandledSet.add(target)\n\n\t// Process ALL properties/entries\n\teach(target, (key, value) => {\n\t\tif (isDraft(value)) {\n\t\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\t\tif (isSameScope(state, rootScope)) {\n\t\t\t\t// Replace draft with finalized value\n\n\t\t\t\tconst updatedValue = getFinalValue(state)\n\n\t\t\t\tset(target, key, updatedValue, target.type_)\n\n\t\t\t\tmarkStateFinalized(state)\n\t\t\t}\n\t\t} else if (isDraftable(value)) {\n\t\t\t// Recursively handle nested values\n\t\t\thandleValue(value, handledSet, rootScope)\n\t\t}\n\t})\n\n\treturn target\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope,\n\thandleCrossReference,\n\tWRITABLE,\n\tCONFIGURABLE,\n\tENUMERABLE,\n\tVALUE,\n\tisArray,\n\tisArrayIndex\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted\n\toperationMethod?: string\n\tallIndicesReassigned_?: boolean\n}\n\ntype ProxyState = ProxyObjectState | ProxyArrayState\n\n/**\n * Returns a new draft of the `base` object.\n *\n * The second argument is the parent draft-state (used internally).\n */\nexport function createProxyProxy(\n\tbase: T,\n\tparent?: ImmerState\n): [Drafted, ProxyState] {\n\tconst baseIsArray = isArray(base)\n\tconst state: ProxyState = {\n\t\ttype_: baseIsArray ? ArchType.Array : (ArchType.Object as any),\n\t\t// Track which produce call this is associated with.\n\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t// True for both shallow and deep changes.\n\t\tmodified_: false,\n\t\t// Used during finalization.\n\t\tfinalized_: false,\n\t\t// Track which properties have been assigned (true) or deleted (false).\n\t\t// actually instantiated in `prepareCopy()`\n\t\tassigned_: undefined,\n\t\t// The parent draft state.\n\t\tparent_: parent,\n\t\t// The base state.\n\t\tbase_: base,\n\t\t// The base proxy.\n\t\tdraft_: null as any, // set below\n\t\t// The base copy with any updated values.\n\t\tcopy_: null,\n\t\t// Called by the `produce` function.\n\t\trevoke_: null as any,\n\t\tisManual_: false,\n\t\t// `callbacks` actually gets assigned in `createProxy`\n\t\tcallbacks_: undefined as any\n\t}\n\n\t// the traps must target something, a bit like the 'real' base.\n\t// but also, we need to be able to determine from the target what the relevant state is\n\t// (to avoid creating traps per instance to capture the state in closure,\n\t// and to avoid creating weird hidden properties as well)\n\t// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)\n\t// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb\n\tlet target: T = state as any\n\tlet traps: ProxyHandler> = objectTraps\n\tif (baseIsArray) {\n\t\ttarget = [state] as any\n\t\ttraps = arrayTraps\n\t}\n\n\tconst {revoke, proxy} = Proxy.revocable(target, traps)\n\tstate.draft_ = proxy as any\n\tstate.revoke_ = revoke\n\treturn [proxy as any, state]\n}\n\n/**\n * Object drafts\n */\nexport const objectTraps: ProxyHandler = {\n\tget(state, prop) {\n\t\tif (prop === DRAFT_STATE) return state\n\n\t\tlet arrayPlugin = state.scope_.arrayMethodsPlugin_\n\t\tconst isArrayWithStringProp =\n\t\t\tstate.type_ === ArchType.Array && typeof prop === \"string\"\n\t\t// Intercept array methods so that we can override\n\t\t// behavior and skip proxy creation for perf\n\t\tif (isArrayWithStringProp) {\n\t\t\tif (arrayPlugin?.isArrayOperationMethod(prop)) {\n\t\t\t\treturn arrayPlugin.createMethodInterceptor(state, prop)\n\t\t\t}\n\t\t}\n\n\t\tconst source = latest(state)\n\t\tif (!has(source, prop, state.type_)) {\n\t\t\t// non-existing or non-own property...\n\t\t\treturn readPropFromProto(state, source, prop)\n\t\t}\n\t\tconst value = source[prop]\n\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\treturn value\n\t\t}\n\n\t\t// During mutating array operations, defer proxy creation for array elements\n\t\t// This optimization avoids creating unnecessary proxies during sort/reverse\n\t\tif (\n\t\t\tisArrayWithStringProp &&\n\t\t\t(state as ProxyArrayState).operationMethod &&\n\t\t\tarrayPlugin?.isMutatingArrayMethod(\n\t\t\t\t(state as ProxyArrayState).operationMethod!\n\t\t\t) &&\n\t\t\tisArrayIndex(prop)\n\t\t) {\n\t\t\t// Return raw value during mutating operations, create proxy only if modified\n\t\t\treturn value\n\t\t}\n\t\t// Check for existing draft in modified state.\n\t\t// Assigned values are never drafted. This catches any drafts we created, too.\n\t\tif (value === peek(state.base_, prop)) {\n\t\t\tprepareCopy(state)\n\t\t\t// Ensure array keys are always numbers\n\t\t\tconst childKey = state.type_ === ArchType.Array ? +(prop as string) : prop\n\t\t\tconst childDraft = createProxy(state.scope_, value, state, childKey)\n\n\t\t\treturn (state.copy_![childKey] = childDraft)\n\t\t}\n\t\treturn value\n\t},\n\thas(state, prop) {\n\t\treturn prop in latest(state)\n\t},\n\townKeys(state) {\n\t\treturn Reflect.ownKeys(latest(state))\n\t},\n\tset(\n\t\tstate: ProxyObjectState,\n\t\tprop: string /* strictly not, but helps TS */,\n\t\tvalue\n\t) {\n\t\tconst desc = getDescriptorFromProto(latest(state), prop)\n\t\tif (desc?.set) {\n\t\t\t// special case: if this write is captured by a setter, we have\n\t\t\t// to trigger it with the correct context\n\t\t\tdesc.set.call(state.draft_, value)\n\t\t\treturn true\n\t\t}\n\t\tif (!state.modified_) {\n\t\t\t// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)\n\t\t\t// from setting an existing property with value undefined to undefined (which is not a change)\n\t\t\tconst current = peek(latest(state), prop)\n\t\t\t// special case, if we assigning the original value to a draft, we can ignore the assignment\n\t\t\tconst currentState: ProxyObjectState = current?.[DRAFT_STATE]\n\t\t\tif (currentState && currentState.base_ === value) {\n\t\t\t\tstate.copy_![prop] = value\n\t\t\t\tstate.assigned_!.set(prop, false)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (\n\t\t\t\tis(value, current) &&\n\t\t\t\t(value !== undefined || has(state.base_, prop, state.type_))\n\t\t\t)\n\t\t\t\treturn true\n\t\t\tprepareCopy(state)\n\t\t\tmarkChanged(state)\n\t\t}\n\n\t\tif (\n\t\t\t(state.copy_![prop] === value &&\n\t\t\t\t// special case: handle new props with value 'undefined'\n\t\t\t\t(value !== undefined || prop in state.copy_)) ||\n\t\t\t// special case: NaN\n\t\t\t(Number.isNaN(value) && Number.isNaN(state.copy_![prop]))\n\t\t)\n\t\t\treturn true\n\n\t\t// @ts-ignore\n\t\tstate.copy_![prop] = value\n\t\tstate.assigned_!.set(prop, true)\n\n\t\thandleCrossReference(state, prop, value)\n\t\treturn true\n\t},\n\tdeleteProperty(state, prop: string) {\n\t\tprepareCopy(state)\n\t\t// The `undefined` check is a fast path for pre-existing keys.\n\t\tif (peek(state.base_, prop) !== undefined || prop in state.base_) {\n\t\t\tstate.assigned_!.set(prop, false)\n\t\t\tmarkChanged(state)\n\t\t} else {\n\t\t\t// if an originally not assigned property was deleted\n\t\t\tstate.assigned_!.delete(prop)\n\t\t}\n\t\tif (state.copy_) {\n\t\t\tdelete state.copy_[prop]\n\t\t}\n\t\treturn true\n\t},\n\t// Note: We never coerce `desc.value` into an Immer draft, because we can't make\n\t// the same guarantee in ES5 mode.\n\tgetOwnPropertyDescriptor(state, prop) {\n\t\tconst owner = latest(state)\n\t\tconst desc = Reflect.getOwnPropertyDescriptor(owner, prop)\n\t\tif (!desc) return desc\n\t\treturn {\n\t\t\t[WRITABLE]: true,\n\t\t\t[CONFIGURABLE]: state.type_ !== ArchType.Array || prop !== \"length\",\n\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t[VALUE]: owner[prop]\n\t\t}\n\t},\n\tdefineProperty() {\n\t\tdie(11)\n\t},\n\tgetPrototypeOf(state) {\n\t\treturn getPrototypeOf(state.base_)\n\t},\n\tsetPrototypeOf() {\n\t\tdie(12)\n\t}\n}\n\n/**\n * Array drafts\n */\n\nconst arrayTraps: ProxyHandler<[ProxyArrayState]> = {}\neach(objectTraps, (key, fn) => {\n\t// @ts-ignore\n\tarrayTraps[key] = function() {\n\t\tconst args = arguments\n\t\targs[0] = args[0][0]\n\t\treturn fn.apply(this, args)\n\t}\n})\narrayTraps.deleteProperty = function(state, prop) {\n\tif (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop as any)))\n\t\tdie(13)\n\t// @ts-ignore\n\treturn arrayTraps.set!.call(this, state, prop, undefined)\n}\narrayTraps.set = function(state, prop, value) {\n\tif (\n\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\tprop !== \"length\" &&\n\t\tisNaN(parseInt(prop as any))\n\t)\n\t\tdie(14)\n\treturn objectTraps.set!.call(this, state[0], prop, value, state[0])\n}\n\n// Access a property without creating an Immer draft.\nfunction peek(draft: Drafted, prop: PropertyKey) {\n\tconst state = draft[DRAFT_STATE]\n\tconst source = state ? latest(state) : draft\n\treturn source[prop]\n}\n\nfunction readPropFromProto(state: ImmerState, source: any, prop: PropertyKey) {\n\tconst desc = getDescriptorFromProto(source, prop)\n\treturn desc\n\t\t? VALUE in desc\n\t\t\t? desc[VALUE]\n\t\t\t: // This is a very special case, if the prop is a getter defined by the\n\t\t\t // prototype, we should invoke it with the draft as context!\n\t\t\t desc.get?.call(state.draft_)\n\t\t: undefined\n}\n\nfunction getDescriptorFromProto(\n\tsource: any,\n\tprop: PropertyKey\n): PropertyDescriptor | undefined {\n\t// 'in' checks proto!\n\tif (!(prop in source)) return undefined\n\tlet proto = getPrototypeOf(source)\n\twhile (proto) {\n\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\tif (desc) return desc\n\t\tproto = getPrototypeOf(proto)\n\t}\n\treturn undefined\n}\n\nexport function markChanged(state: ImmerState) {\n\tif (!state.modified_) {\n\t\tstate.modified_ = true\n\t\tif (state.parent_) {\n\t\t\tmarkChanged(state.parent_)\n\t\t}\n\t}\n}\n\nexport function prepareCopy(state: ImmerState) {\n\tif (!state.copy_) {\n\t\t// Actually create the `assigned_` map now that we\n\t\t// know this is a modified draft.\n\t\tstate.assigned_ = new Map()\n\t\tstate.copy_ = shallowCopy(\n\t\t\tstate.base_,\n\t\t\tstate.scope_.immer_.useStrictShallowCopy_\n\t\t)\n\t}\n}\n","import {\n\tIProduceWithPatches,\n\tIProduce,\n\tImmerState,\n\tDrafted,\n\tisDraftable,\n\tprocessResult,\n\tPatch,\n\tObjectish,\n\tDRAFT_STATE,\n\tDraft,\n\tPatchListener,\n\tisDraft,\n\tisMap,\n\tisSet,\n\tcreateProxyProxy,\n\tgetPlugin,\n\tdie,\n\tenterScope,\n\trevokeScope,\n\tleaveScope,\n\tusePatchesInScope,\n\tgetCurrentScope,\n\tNOTHING,\n\tfreeze,\n\tcurrent,\n\tImmerScope,\n\tregisterChildFinalizationCallback,\n\tArchType,\n\tMapSetPlugin,\n\tAnyMap,\n\tAnySet,\n\tisObjectish,\n\tisFunction,\n\tisBoolean,\n\tPluginMapSet,\n\tPluginPatches\n} from \"../internal\"\n\ninterface ProducersFns {\n\tproduce: IProduce\n\tproduceWithPatches: IProduceWithPatches\n}\n\nexport type StrictMode = boolean | \"class_only\"\n\nexport class Immer implements ProducersFns {\n\tautoFreeze_: boolean = true\n\tuseStrictShallowCopy_: StrictMode = false\n\tuseStrictIteration_: boolean = false\n\n\tconstructor(config?: {\n\t\tautoFreeze?: boolean\n\t\tuseStrictShallowCopy?: StrictMode\n\t\tuseStrictIteration?: boolean\n\t}) {\n\t\tif (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config!.autoFreeze)\n\t\tif (isBoolean(config?.useStrictShallowCopy))\n\t\t\tthis.setUseStrictShallowCopy(config!.useStrictShallowCopy)\n\t\tif (isBoolean(config?.useStrictIteration))\n\t\t\tthis.setUseStrictIteration(config!.useStrictIteration)\n\t}\n\n\t/**\n\t * The `produce` function takes a value and a \"recipe function\" (whose\n\t * return value often depends on the base state). The recipe function is\n\t * free to mutate its first argument however it wants. All mutations are\n\t * only ever applied to a __copy__ of the base state.\n\t *\n\t * Pass only a function to create a \"curried producer\" which relieves you\n\t * from passing the recipe function every time.\n\t *\n\t * Only plain objects and arrays are made mutable. All other objects are\n\t * considered uncopyable.\n\t *\n\t * Note: This function is __bound__ to its `Immer` instance.\n\t *\n\t * @param {any} base - the initial state\n\t * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n\t * @param {Function} patchListener - optional function that will be called with all the patches produced here\n\t * @returns {any} a new state, or the initial state if nothing was modified\n\t */\n\tproduce: IProduce = (base: any, recipe?: any, patchListener?: any) => {\n\t\t// curried invocation\n\t\tif (isFunction(base) && !isFunction(recipe)) {\n\t\t\tconst defaultBase = recipe\n\t\t\trecipe = base\n\n\t\t\tconst self = this\n\t\t\treturn function curriedProduce(\n\t\t\t\tthis: any,\n\t\t\t\tbase = defaultBase,\n\t\t\t\t...args: any[]\n\t\t\t) {\n\t\t\t\treturn self.produce(base, (draft: Drafted) => recipe.call(this, draft, ...args)) // prettier-ignore\n\t\t\t}\n\t\t}\n\n\t\tif (!isFunction(recipe)) die(6)\n\t\tif (patchListener !== undefined && !isFunction(patchListener)) die(7)\n\n\t\tlet result\n\n\t\t// Only plain objects, arrays, and \"immerable classes\" are drafted.\n\t\tif (isDraftable(base)) {\n\t\t\tconst scope = enterScope(this)\n\t\t\tconst proxy = createProxy(scope, base, undefined)\n\t\t\tlet hasError = true\n\t\t\ttry {\n\t\t\t\tresult = recipe(proxy)\n\t\t\t\thasError = false\n\t\t\t} finally {\n\t\t\t\t// finally instead of catch + rethrow better preserves original stack\n\t\t\t\tif (hasError) revokeScope(scope)\n\t\t\t\telse leaveScope(scope)\n\t\t\t}\n\t\t\tusePatchesInScope(scope, patchListener)\n\t\t\treturn processResult(result, scope)\n\t\t} else if (!base || !isObjectish(base)) {\n\t\t\tresult = recipe(base)\n\t\t\tif (result === undefined) result = base\n\t\t\tif (result === NOTHING) result = undefined\n\t\t\tif (this.autoFreeze_) freeze(result, true)\n\t\t\tif (patchListener) {\n\t\t\t\tconst p: Patch[] = []\n\t\t\t\tconst ip: Patch[] = []\n\t\t\t\tgetPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n\t\t\t\t\tpatches_: p,\n\t\t\t\t\tinversePatches_: ip\n\t\t\t\t} as ImmerScope) // dummy scope\n\t\t\t\tpatchListener(p, ip)\n\t\t\t}\n\t\t\treturn result\n\t\t} else die(1, base)\n\t}\n\n\tproduceWithPatches: IProduceWithPatches = (base: any, recipe?: any): any => {\n\t\t// curried invocation\n\t\tif (isFunction(base)) {\n\t\t\treturn (state: any, ...args: any[]) =>\n\t\t\t\tthis.produceWithPatches(state, (draft: any) => base(draft, ...args))\n\t\t}\n\n\t\tlet patches: Patch[], inversePatches: Patch[]\n\t\tconst result = this.produce(base, recipe, (p: Patch[], ip: Patch[]) => {\n\t\t\tpatches = p\n\t\t\tinversePatches = ip\n\t\t})\n\t\treturn [result, patches!, inversePatches!]\n\t}\n\n\tcreateDraft(base: T): Draft {\n\t\tif (!isDraftable(base)) die(8)\n\t\tif (isDraft(base)) base = current(base)\n\t\tconst scope = enterScope(this)\n\t\tconst proxy = createProxy(scope, base, undefined)\n\t\tproxy[DRAFT_STATE].isManual_ = true\n\t\tleaveScope(scope)\n\t\treturn proxy as any\n\t}\n\n\tfinishDraft>(\n\t\tdraft: D,\n\t\tpatchListener?: PatchListener\n\t): D extends Draft ? T : never {\n\t\tconst state: ImmerState = draft && (draft as any)[DRAFT_STATE]\n\t\tif (!state || !state.isManual_) die(9)\n\t\tconst {scope_: scope} = state\n\t\tusePatchesInScope(scope, patchListener)\n\t\treturn processResult(undefined, scope)\n\t}\n\n\t/**\n\t * Pass true to automatically freeze all copies created by Immer.\n\t *\n\t * By default, auto-freezing is enabled.\n\t */\n\tsetAutoFreeze(value: boolean) {\n\t\tthis.autoFreeze_ = value\n\t}\n\n\t/**\n\t * Pass true to enable strict shallow copy.\n\t *\n\t * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n\t */\n\tsetUseStrictShallowCopy(value: StrictMode) {\n\t\tthis.useStrictShallowCopy_ = value\n\t}\n\n\t/**\n\t * Pass false to use faster iteration that skips non-enumerable properties\n\t * but still handles symbols for compatibility.\n\t *\n\t * By default, strict iteration is enabled (includes all own properties).\n\t */\n\tsetUseStrictIteration(value: boolean) {\n\t\tthis.useStrictIteration_ = value\n\t}\n\n\tshouldUseStrictIteration(): boolean {\n\t\treturn this.useStrictIteration_\n\t}\n\n\tapplyPatches(base: T, patches: readonly Patch[]): T {\n\t\t// If a patch replaces the entire state, take that replacement as base\n\t\t// before applying patches\n\t\tlet i: number\n\t\tfor (i = patches.length - 1; i >= 0; i--) {\n\t\t\tconst patch = patches[i]\n\t\t\tif (patch.path.length === 0 && patch.op === \"replace\") {\n\t\t\t\tbase = patch.value\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t// If there was a patch that replaced the entire state, start from the\n\t\t// patch after that.\n\t\tif (i > -1) {\n\t\t\tpatches = patches.slice(i + 1)\n\t\t}\n\n\t\tconst applyPatchesImpl = getPlugin(PluginPatches).applyPatches_\n\t\tif (isDraft(base)) {\n\t\t\t// N.B: never hits if some patch a replacement, patches are never drafts\n\t\t\treturn applyPatchesImpl(base, patches)\n\t\t}\n\t\t// Otherwise, produce a copy of the base state.\n\t\treturn this.produce(base, (draft: Drafted) =>\n\t\t\tapplyPatchesImpl(draft, patches)\n\t\t)\n\t}\n}\n\nexport function createProxy(\n\trootScope: ImmerScope,\n\tvalue: T,\n\tparent?: ImmerState,\n\tkey?: string | number | symbol\n): Drafted {\n\t// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft\n\t// returning a tuple here lets us skip a proxy access\n\t// to DRAFT_STATE later\n\tconst [draft, state] = isMap(value)\n\t\t? getPlugin(PluginMapSet).proxyMap_(value, parent)\n\t\t: isSet(value)\n\t\t? getPlugin(PluginMapSet).proxySet_(value, parent)\n\t\t: createProxyProxy(value, parent)\n\n\tconst scope = parent?.scope_ ?? getCurrentScope()\n\tscope.drafts_.push(draft)\n\n\t// Ensure the parent callbacks are passed down so we actually\n\t// track all callbacks added throughout the tree\n\tstate.callbacks_ = parent?.callbacks_ ?? []\n\tstate.key_ = key\n\n\tif (parent && key !== undefined) {\n\t\tregisterChildFinalizationCallback(parent, state, key)\n\t} else {\n\t\t// It's a root draft, register it with the scope\n\t\tstate.callbacks_.push(function rootDraftCleanup(rootScope) {\n\t\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\t\tconst {patchPlugin_} = rootScope\n\n\t\t\tif (state.modified_ && patchPlugin_) {\n\t\t\t\tpatchPlugin_.generatePatches_(state, [], rootScope)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn draft as any\n}\n","import {\n\tdie,\n\tisDraft,\n\tshallowCopy,\n\teach,\n\tDRAFT_STATE,\n\tset,\n\tImmerState,\n\tisDraftable,\n\tisFrozen\n} from \"../internal\"\n\n/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */\nexport function current(value: T): T\nexport function current(value: any): any {\n\tif (!isDraft(value)) die(10, value)\n\treturn currentImpl(value)\n}\n\nfunction currentImpl(value: any): any {\n\tif (!isDraftable(value) || isFrozen(value)) return value\n\tconst state: ImmerState | undefined = value[DRAFT_STATE]\n\tlet copy: any\n\tlet strict = true // Default to strict for compatibility\n\tif (state) {\n\t\tif (!state.modified_) return state.base_\n\t\t// Optimization: avoid generating new drafts during copying\n\t\tstate.finalized_ = true\n\t\tcopy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)\n\t\tstrict = state.scope_.immer_.shouldUseStrictIteration()\n\t} else {\n\t\tcopy = shallowCopy(value, true)\n\t}\n\t// recurse\n\teach(\n\t\tcopy,\n\t\t(key, childValue) => {\n\t\t\tset(copy, key, currentImpl(childValue))\n\t\t},\n\t\tstrict\n\t)\n\tif (state) {\n\t\tstate.finalized_ = false\n\t}\n\treturn copy\n}\n","import {immerable} from \"../immer\"\nimport {\n\tImmerState,\n\tPatch,\n\tSetState,\n\tProxyArrayState,\n\tMapState,\n\tProxyObjectState,\n\tPatchPath,\n\tget,\n\teach,\n\thas,\n\tgetArchtype,\n\tgetPrototypeOf,\n\tisSet,\n\tisMap,\n\tloadPlugin,\n\tArchType,\n\tdie,\n\tisDraft,\n\tisDraftable,\n\tNOTHING,\n\terrors,\n\tDRAFT_STATE,\n\tgetProxyDraft,\n\tImmerScope,\n\tisObjectish,\n\tisFunction,\n\tCONSTRUCTOR,\n\tPluginPatches,\n\tisArray,\n\tPROTOTYPE\n} from \"../internal\"\n\nexport function enablePatches() {\n\tconst errorOffset = 16\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\terrors.push(\n\t\t\t'Sets cannot have \"replace\" patches.',\n\t\t\tfunction(op: string) {\n\t\t\t\treturn \"Unsupported patch operation: \" + op\n\t\t\t},\n\t\t\tfunction(path: string) {\n\t\t\t\treturn \"Cannot apply patch, path doesn't resolve: \" + path\n\t\t\t},\n\t\t\t\"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n\t\t)\n\t}\n\n\tfunction getPath(state: ImmerState, path: PatchPath = []): PatchPath | null {\n\t\t// Step 1: Check if state has a stored key\n\t\tif (\"key_\" in state && state.key_ !== undefined) {\n\t\t\t// Step 2: Validate the key is still valid in parent\n\n\t\t\tconst parentCopy = state.parent_!.copy_ ?? state.parent_!.base_\n\t\t\tconst proxyDraft = getProxyDraft(get(parentCopy, state.key_!))\n\t\t\tconst valueAtKey = get(parentCopy, state.key_!)\n\n\t\t\tif (valueAtKey === undefined) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\t// Check if the value at the key is still related to this draft\n\t\t\t// It should be either the draft itself, the base, or the copy\n\t\t\tif (\n\t\t\t\tvalueAtKey !== state.draft_ &&\n\t\t\t\tvalueAtKey !== state.base_ &&\n\t\t\t\tvalueAtKey !== state.copy_\n\t\t\t) {\n\t\t\t\treturn null // Value was replaced with something else\n\t\t\t}\n\t\t\tif (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n\t\t\t\treturn null // Different draft\n\t\t\t}\n\n\t\t\t// Step 3: Handle Set case specially\n\t\t\tconst isSet = state.parent_!.type_ === ArchType.Set\n\t\t\tlet key: string | number\n\n\t\t\tif (isSet) {\n\t\t\t\t// For Sets, find the index in the drafts_ map\n\t\t\t\tconst setParent = state.parent_ as SetState\n\t\t\t\tkey = Array.from(setParent.drafts_.keys()).indexOf(state.key_)\n\t\t\t} else {\n\t\t\t\tkey = state.key_ as string | number\n\t\t\t}\n\n\t\t\t// Step 4: Validate key still exists in parent\n\t\t\tif (!((isSet && parentCopy.size > key) || has(parentCopy, key))) {\n\t\t\t\treturn null // Key deleted\n\t\t\t}\n\n\t\t\t// Step 5: Add key to path\n\t\t\tpath.push(key)\n\t\t}\n\n\t\t// Step 6: Recurse to parent if exists\n\t\tif (state.parent_) {\n\t\t\treturn getPath(state.parent_, path)\n\t\t}\n\n\t\t// Step 7: At root - reverse path and validate\n\t\tpath.reverse()\n\n\t\ttry {\n\t\t\t// Validate path can be resolved from ROOT\n\t\t\tresolvePath(state.copy_, path)\n\t\t} catch (e) {\n\t\t\treturn null // Path invalid\n\t\t}\n\n\t\treturn path\n\t}\n\n\t// NEW: Add resolvePath helper function\n\tfunction resolvePath(base: any, path: PatchPath): any {\n\t\tlet current = base\n\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\tconst key = path[i]\n\t\t\tcurrent = get(current, key)\n\t\t\tif (!isObjectish(current) || current === null) {\n\t\t\t\tthrow new Error(`Cannot resolve path at '${path.join(\"/\")}'`)\n\t\t\t}\n\t\t}\n\t\treturn current\n\t}\n\n\tconst REPLACE = \"replace\"\n\tconst ADD = \"add\"\n\tconst REMOVE = \"remove\"\n\n\tfunction generatePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\tscope: ImmerScope\n\t): void {\n\t\tif (state.scope_.processedForPatches_.has(state)) {\n\t\t\treturn\n\t\t}\n\n\t\tstate.scope_.processedForPatches_.add(state)\n\n\t\tconst {patches_, inversePatches_} = scope\n\n\t\tswitch (state.type_) {\n\t\t\tcase ArchType.Object:\n\t\t\tcase ArchType.Map:\n\t\t\t\treturn generatePatchesFromAssigned(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Array:\n\t\t\t\treturn generateArrayPatches(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Set:\n\t\t\t\treturn generateSetPatches(\n\t\t\t\t\t(state as any) as SetState,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t}\n\t}\n\n\tfunction generateArrayPatches(\n\t\tstate: ProxyArrayState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, assigned_} = state\n\t\tlet copy_ = state.copy_!\n\n\t\t// Reduce complexity by ensuring `base` is never longer.\n\t\tif (copy_.length < base_.length) {\n\t\t\t// @ts-ignore\n\t\t\t;[base_, copy_] = [copy_, base_]\n\t\t\t;[patches, inversePatches] = [inversePatches, patches]\n\t\t}\n\n\t\tconst allReassigned = state.allIndicesReassigned_ === true\n\n\t\t// Process replaced indices.\n\t\tfor (let i = 0; i < base_.length; i++) {\n\t\t\tconst copiedItem = copy_[i]\n\t\t\tconst baseItem = base_[i]\n\n\t\t\tconst isAssigned = allReassigned || assigned_?.get(i.toString())\n\t\t\tif (isAssigned && copiedItem !== baseItem) {\n\t\t\t\tconst childState = copiedItem?.[DRAFT_STATE]\n\t\t\t\tif (childState && childState.modified_) {\n\t\t\t\t\t// Skip - let the child generate its own patches\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(copiedItem)\n\t\t\t\t})\n\t\t\t\tinversePatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(baseItem)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Process added indices.\n\t\tfor (let i = base_.length; i < copy_.length; i++) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tpatches.push({\n\t\t\t\top: ADD,\n\t\t\t\tpath,\n\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\tvalue: clonePatchValueIfNeeded(copy_[i])\n\t\t\t})\n\t\t}\n\t\tfor (let i = copy_.length - 1; base_.length <= i; --i) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tinversePatches.push({\n\t\t\t\top: REMOVE,\n\t\t\t\tpath\n\t\t\t})\n\t\t}\n\t}\n\n\t// This is used for both Map objects and normal objects.\n\tfunction generatePatchesFromAssigned(\n\t\tstate: MapState | ProxyObjectState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tconst {base_, copy_, type_} = state\n\t\teach(state.assigned_!, (key, assignedValue) => {\n\t\t\tconst origValue = get(base_, key, type_)\n\t\t\tconst value = get(copy_!, key, type_)\n\t\t\tconst op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD\n\t\t\tif (origValue === value && op === REPLACE) return\n\t\t\tconst path = basePath.concat(key as any)\n\t\t\tpatches.push(\n\t\t\t\top === REMOVE\n\t\t\t\t\t? {op, path}\n\t\t\t\t\t: {op, path, value: clonePatchValueIfNeeded(value)}\n\t\t\t)\n\t\t\tinversePatches.push(\n\t\t\t\top === ADD\n\t\t\t\t\t? {op: REMOVE, path}\n\t\t\t\t\t: op === REMOVE\n\t\t\t\t\t? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t\t\t: {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t)\n\t\t})\n\t}\n\n\tfunction generateSetPatches(\n\t\tstate: SetState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, copy_} = state\n\n\t\tlet i = 0\n\t\tbase_.forEach((value: any) => {\n\t\t\tif (!copy_!.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t\ti = 0\n\t\tcopy_!.forEach((value: any) => {\n\t\t\tif (!base_.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t}\n\n\tfunction generateReplacementPatches_(\n\t\tbaseValue: any,\n\t\treplacement: any,\n\t\tscope: ImmerScope\n\t): void {\n\t\tconst {patches_, inversePatches_} = scope\n\t\tpatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: replacement === NOTHING ? undefined : replacement\n\t\t})\n\t\tinversePatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: baseValue\n\t\t})\n\t}\n\n\tfunction applyPatches_(draft: T, patches: readonly Patch[]): T {\n\t\tpatches.forEach(patch => {\n\t\t\tconst {path, op} = patch\n\n\t\t\tlet base: any = draft\n\t\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\t\tconst parentType = getArchtype(base)\n\t\t\t\tlet p = path[i]\n\t\t\t\tif (typeof p !== \"string\" && typeof p !== \"number\") {\n\t\t\t\t\tp = \"\" + p\n\t\t\t\t}\n\n\t\t\t\t// See #738, avoid prototype pollution\n\t\t\t\tif (\n\t\t\t\t\t(parentType === ArchType.Object || parentType === ArchType.Array) &&\n\t\t\t\t\t(p === \"__proto__\" || p === CONSTRUCTOR)\n\t\t\t\t)\n\t\t\t\t\tdie(errorOffset + 3)\n\t\t\t\tif (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3)\n\t\t\t\tbase = get(base, p)\n\t\t\t\tif (!isObjectish(base)) die(errorOffset + 2, path.join(\"/\"))\n\t\t\t}\n\n\t\t\tconst type = getArchtype(base)\n\t\t\tconst value = deepClonePatchValue(patch.value) // used to clone patch to ensure original patch is not modified, see #411\n\t\t\tconst key = path[path.length - 1]\n\t\t\tswitch (op) {\n\t\t\t\tcase REPLACE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\tdie(errorOffset)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t// if value is an object, then it's assigned by reference\n\t\t\t\t\t\t\t// in the following add or remove ops, the value field inside the patch will also be modifyed\n\t\t\t\t\t\t\t// so we use value from the cloned patch\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase ADD:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn key === \"-\"\n\t\t\t\t\t\t\t\t? base.push(value)\n\t\t\t\t\t\t\t\t: base.splice(key as any, 0, value)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.add(value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase REMOVE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn base.splice(key as any, 1)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.delete(key)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.delete(patch.value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn delete base[key]\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tdie(errorOffset + 1, op)\n\t\t\t}\n\t\t})\n\n\t\treturn draft\n\t}\n\n\t// optimize: this is quite a performance hit, can we detect intelligently when it is needed?\n\t// E.g. auto-draft when new objects from outside are assigned and modified?\n\t// (See failing test when deepClone just returns obj)\n\tfunction deepClonePatchValue(obj: T): T\n\tfunction deepClonePatchValue(obj: any) {\n\t\tif (!isDraftable(obj)) return obj\n\t\tif (isArray(obj)) return obj.map(deepClonePatchValue)\n\t\tif (isMap(obj))\n\t\t\treturn new Map(\n\t\t\t\tArray.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n\t\t\t)\n\t\tif (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue))\n\t\tconst cloned = Object.create(getPrototypeOf(obj))\n\t\tfor (const key in obj) cloned[key] = deepClonePatchValue(obj[key])\n\t\tif (has(obj, immerable)) cloned[immerable] = obj[immerable]\n\t\treturn cloned\n\t}\n\n\tfunction clonePatchValueIfNeeded(obj: T): T {\n\t\tif (isDraft(obj)) {\n\t\t\treturn deepClonePatchValue(obj)\n\t\t} else return obj\n\t}\n\n\tloadPlugin(PluginPatches, {\n\t\tapplyPatches_,\n\t\tgeneratePatches_,\n\t\tgenerateReplacementPatches_,\n\t\tgetPath\n\t})\n}\n","// types only!\nimport {\n\tImmerState,\n\tAnyMap,\n\tAnySet,\n\tMapState,\n\tSetState,\n\tDRAFT_STATE,\n\tgetCurrentScope,\n\tlatest,\n\tisDraftable,\n\tcreateProxy,\n\tloadPlugin,\n\tmarkChanged,\n\tdie,\n\tArchType,\n\teach,\n\tgetValue,\n\tPluginMapSet\n} from \"../internal\"\n\nexport function enableMapSet() {\n\tclass DraftMap extends Map {\n\t\t[DRAFT_STATE]: MapState\n\n\t\tconstructor(target: AnyMap, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Map,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this as any,\n\t\t\t\tisManual_: false,\n\t\t\t\trevoked_: false,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(key: any): boolean {\n\t\t\treturn latest(this[DRAFT_STATE]).has(key)\n\t\t}\n\n\t\tset(key: any, value: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!latest(state).has(key) || latest(state).get(key) !== value) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t\tstate.copy_!.set(key, value)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(key: any): boolean {\n\t\t\tif (!this.has(key)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareMapCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\tif (state.base_.has(key)) {\n\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t} else {\n\t\t\t\tstate.assigned_!.delete(key)\n\t\t\t}\n\t\t\tstate.copy_!.delete(key)\n\t\t\treturn true\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_ = new Map()\n\t\t\t\teach(state.base_, key => {\n\t\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t\t})\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tforEach(cb: (value: any, key: any, self: any) => void, thisArg?: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tlatest(state).forEach((_value: any, key: any, _map: any) => {\n\t\t\t\tcb.call(thisArg, this.get(key), key, this)\n\t\t\t})\n\t\t}\n\n\t\tget(key: any): any {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tconst value = latest(state).get(key)\n\t\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\t\treturn value\n\t\t\t}\n\t\t\tif (value !== state.base_.get(key)) {\n\t\t\t\treturn value // either already drafted or reassigned\n\t\t\t}\n\t\t\t// despite what it looks, this creates a draft only once, see above condition\n\t\t\tconst draft = createProxy(state.scope_, value, state, key)\n\t\t\tprepareMapCopy(state)\n\t\t\tstate.copy_!.set(key, draft)\n\t\t\treturn draft\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn latest(this[DRAFT_STATE]).keys()\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.values(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.entries(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue: [r.value, value]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.entries()\n\t\t}\n\t}\n\n\tfunction proxyMap_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, MapState] {\n\t\t// @ts-ignore\n\t\tconst map = new DraftMap(target, parent)\n\t\treturn [map as any, map[DRAFT_STATE]]\n\t}\n\n\tfunction prepareMapCopy(state: MapState) {\n\t\tif (!state.copy_) {\n\t\t\tstate.assigned_ = new Map()\n\t\t\tstate.copy_ = new Map(state.base_)\n\t\t}\n\t}\n\n\tclass DraftSet extends Set {\n\t\t[DRAFT_STATE]: SetState\n\t\tconstructor(target: AnySet, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Set,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this,\n\t\t\t\tdrafts_: new Map(),\n\t\t\t\trevoked_: false,\n\t\t\t\tisManual_: false,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(value: any): boolean {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\t// bit of trickery here, to be able to recognize both the value, and the draft of its value\n\t\t\tif (!state.copy_) {\n\t\t\t\treturn state.base_.has(value)\n\t\t\t}\n\t\t\tif (state.copy_.has(value)) return true\n\t\t\tif (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n\t\t\t\treturn true\n\t\t\treturn false\n\t\t}\n\n\t\tadd(value: any): any {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!this.has(value)) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.add(value)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(value: any): any {\n\t\t\tif (!this.has(value)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\treturn (\n\t\t\t\tstate.copy_!.delete(value) ||\n\t\t\t\t(state.drafts_.has(value)\n\t\t\t\t\t? state.copy_!.delete(state.drafts_.get(value))\n\t\t\t\t\t: /* istanbul ignore next */ false)\n\t\t\t)\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.values()\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.entries()\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn this.values()\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.values()\n\t\t}\n\n\t\tforEach(cb: any, thisArg?: any) {\n\t\t\tconst iterator = this.values()\n\t\t\tlet result = iterator.next()\n\t\t\twhile (!result.done) {\n\t\t\t\tcb.call(thisArg, result.value, result.value, this)\n\t\t\t\tresult = iterator.next()\n\t\t\t}\n\t\t}\n\t}\n\tfunction proxySet_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, SetState] {\n\t\t// @ts-ignore\n\t\tconst set = new DraftSet(target, parent)\n\t\treturn [set as any, set[DRAFT_STATE]]\n\t}\n\n\tfunction prepareSetCopy(state: SetState) {\n\t\tif (!state.copy_) {\n\t\t\t// create drafts for all entries to preserve insertion order\n\t\t\tstate.copy_ = new Set()\n\t\t\tstate.base_.forEach(value => {\n\t\t\t\tif (isDraftable(value)) {\n\t\t\t\t\tconst draft = createProxy(state.scope_, value, state, value)\n\t\t\t\t\tstate.drafts_.set(value, draft)\n\t\t\t\t\tstate.copy_!.add(draft)\n\t\t\t\t} else {\n\t\t\t\t\tstate.copy_!.add(value)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n\n\tfunction assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {\n\t\tif (state.revoked_) die(3, JSON.stringify(latest(state)))\n\t}\n\n\tfunction fixSetContents(target: ImmerState) {\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\tif (target.type_ === ArchType.Set && target.copy_) {\n\t\t\tconst copy = new Set(target.copy_)\n\t\t\ttarget.copy_.clear()\n\t\t\tcopy.forEach(value => {\n\t\t\t\ttarget.copy_!.add(getValue(value))\n\t\t\t})\n\t\t}\n\t}\n\n\tloadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents})\n}\n","import {\n\tPluginArrayMethods,\n\tlatest,\n\tloadPlugin,\n\tmarkChanged,\n\tprepareCopy,\n\tProxyArrayState\n} from \"../internal\"\n\n/**\n * Methods that directly modify the array in place.\n * These operate on the copy without creating per-element proxies:\n * - `push`, `pop`: Add/remove from end\n * - `shift`, `unshift`: Add/remove from start (marks all indices reassigned)\n * - `splice`: Add/remove at arbitrary position (marks all indices reassigned)\n * - `reverse`, `sort`: Reorder elements (marks all indices reassigned)\n */\ntype MutatingArrayMethod =\n\t| \"push\"\n\t| \"pop\"\n\t| \"shift\"\n\t| \"unshift\"\n\t| \"splice\"\n\t| \"reverse\"\n\t| \"sort\"\n\n/**\n * Methods that read from the array without modifying it.\n * These fall into distinct categories based on return semantics:\n *\n * **Subset operations** (return drafts - mutations propagate):\n * - `filter`, `slice`: Return array of draft proxies\n * - `find`, `findLast`: Return single draft proxy or undefined\n *\n * **Transform operations** (return base values - mutations don't track):\n * - `concat`, `flat`: Create new structures, not subsets of original\n *\n * **Primitive-returning** (no draft needed):\n * - `findIndex`, `findLastIndex`, `indexOf`, `lastIndexOf`: Return numbers\n * - `some`, `every`, `includes`: Return booleans\n * - `join`, `toString`, `toLocaleString`: Return strings\n */\ntype NonMutatingArrayMethod =\n\t| \"filter\"\n\t| \"slice\"\n\t| \"concat\"\n\t| \"flat\"\n\t| \"find\"\n\t| \"findIndex\"\n\t| \"findLast\"\n\t| \"findLastIndex\"\n\t| \"some\"\n\t| \"every\"\n\t| \"indexOf\"\n\t| \"lastIndexOf\"\n\t| \"includes\"\n\t| \"join\"\n\t| \"toString\"\n\t| \"toLocaleString\"\n\n/** Union of all array operation methods handled by the plugin. */\nexport type ArrayOperationMethod = MutatingArrayMethod | NonMutatingArrayMethod\n\n/**\n * Enables optimized array method handling for Immer drafts.\n *\n * This plugin overrides array methods to avoid unnecessary Proxy creation during iteration,\n * significantly improving performance for array-heavy operations.\n *\n * **Mutating methods** (push, pop, shift, unshift, splice, sort, reverse):\n * Operate directly on the copy without creating per-element proxies.\n *\n * **Non-mutating methods** fall into categories:\n * - **Subset operations** (filter, slice, find, findLast): Return draft proxies - mutations track\n * - **Transform operations** (concat, flat): Return base values - mutations don't track\n * - **Primitive-returning** (indexOf, includes, some, every, etc.): Return primitives\n *\n * **Important**: Callbacks for overridden methods receive base values, not drafts.\n * This is the core performance optimization.\n *\n * @example\n * ```ts\n * import { enableArrayMethods, produce } from \"immer\"\n *\n * enableArrayMethods()\n *\n * const next = produce(state, draft => {\n * // Optimized - no proxy creation per element\n * draft.items.sort((a, b) => a.value - b.value)\n *\n * // filter returns drafts - mutations propagate\n * const filtered = draft.items.filter(x => x.value > 5)\n * filtered[0].value = 999 // Affects draft.items[originalIndex]\n * })\n * ```\n *\n * @see https://immerjs.github.io/immer/array-methods\n */\nexport function enableArrayMethods() {\n\tconst SHIFTING_METHODS = new Set([\"shift\", \"unshift\"])\n\n\tconst QUEUE_METHODS = new Set([\"push\", \"pop\"])\n\n\tconst RESULT_RETURNING_METHODS = new Set([\n\t\t...QUEUE_METHODS,\n\t\t...SHIFTING_METHODS\n\t])\n\n\tconst REORDERING_METHODS = new Set([\"reverse\", \"sort\"])\n\n\t// Optimized method detection using array-based lookup\n\tconst MUTATING_METHODS = new Set([\n\t\t...RESULT_RETURNING_METHODS,\n\t\t...REORDERING_METHODS,\n\t\t\"splice\"\n\t])\n\n\tconst FIND_METHODS = new Set([\"find\", \"findLast\"])\n\n\tconst NON_MUTATING_METHODS = new Set([\n\t\t\"filter\",\n\t\t\"slice\",\n\t\t\"concat\",\n\t\t\"flat\",\n\t\t...FIND_METHODS,\n\t\t\"findIndex\",\n\t\t\"findLastIndex\",\n\t\t\"some\",\n\t\t\"every\",\n\t\t\"indexOf\",\n\t\t\"lastIndexOf\",\n\t\t\"includes\",\n\t\t\"join\",\n\t\t\"toString\",\n\t\t\"toLocaleString\"\n\t])\n\n\t// Type guard for method detection\n\tfunction isMutatingArrayMethod(\n\t\tmethod: string\n\t): method is MutatingArrayMethod {\n\t\treturn MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isNonMutatingArrayMethod(\n\t\tmethod: string\n\t): method is NonMutatingArrayMethod {\n\t\treturn NON_MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isArrayOperationMethod(\n\t\tmethod: string\n\t): method is ArrayOperationMethod {\n\t\treturn isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method)\n\t}\n\n\tfunction enterOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: ArrayOperationMethod\n\t) {\n\t\tstate.operationMethod = method\n\t}\n\n\tfunction exitOperation(state: ProxyArrayState) {\n\t\tstate.operationMethod = undefined\n\t}\n\n\t// Shared utility functions for array method handlers\n\tfunction executeArrayMethod(\n\t\tstate: ProxyArrayState,\n\t\toperation: () => T,\n\t\tmarkLength = true\n\t): T {\n\t\tprepareCopy(state)\n\t\tconst result = operation()\n\t\tmarkChanged(state)\n\t\tif (markLength) state.assigned_!.set(\"length\", true)\n\t\treturn result\n\t}\n\n\tfunction markAllIndicesReassigned(state: ProxyArrayState) {\n\t\tstate.allIndicesReassigned_ = true\n\t}\n\n\tfunction normalizeSliceIndex(index: number, length: number): number {\n\t\tif (index < 0) {\n\t\t\treturn Math.max(length + index, 0)\n\t\t}\n\t\treturn Math.min(index, length)\n\t}\n\n\t/**\n\t * Handles mutating operations that add/remove elements (push, pop, shift, unshift, splice).\n\t *\n\t * Operates directly on `state.copy_` without creating per-element proxies.\n\t * For shifting methods (shift, unshift), marks all indices as reassigned since\n\t * indices shift.\n\t *\n\t * @returns For push/pop/shift/unshift: the native method result. For others: the draft.\n\t */\n\tfunction handleSimpleOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(state, () => {\n\t\t\tconst result = (state.copy_! as any)[method](...args)\n\n\t\t\t// Handle index reassignment for shifting methods\n\t\t\tif (SHIFTING_METHODS.has(method as MutatingArrayMethod)) {\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t}\n\n\t\t\t// Return appropriate value based on method\n\t\t\treturn RESULT_RETURNING_METHODS.has(method as MutatingArrayMethod)\n\t\t\t\t? result\n\t\t\t\t: state.draft_\n\t\t})\n\t}\n\n\t/**\n\t * Handles reordering operations (reverse, sort) that change element order.\n\t *\n\t * Operates directly on `state.copy_` and marks all indices as reassigned\n\t * since element positions change. Does not mark length as changed since\n\t * these operations preserve array length.\n\t *\n\t * @returns The draft proxy for method chaining.\n\t */\n\tfunction handleReorderingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(\n\t\t\tstate,\n\t\t\t() => {\n\t\t\t\t;(state.copy_! as any)[method](...args)\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\treturn state.draft_\n\t\t\t},\n\t\t\tfalse\n\t\t) // Don't mark length as changed\n\t}\n\n\t/**\n\t * Creates an interceptor function for a specific array method.\n\t *\n\t * The interceptor wraps array method calls to:\n\t * 1. Set `state.operationMethod` flag during execution (allows proxy `get` trap\n\t * to detect we're inside an optimized method and skip proxy creation)\n\t * 2. Route to appropriate handler based on method type\n\t * 3. Clean up the operation flag in `finally` block\n\t *\n\t * The `operationMethod` flag is the key mechanism that enables the proxy's `get`\n\t * trap to return base values instead of creating nested proxies during iteration.\n\t *\n\t * @param state - The proxy array state\n\t * @param originalMethod - Name of the array method being intercepted\n\t * @returns Interceptor function that handles the method call\n\t */\n\tfunction createMethodInterceptor(\n\t\tstate: ProxyArrayState,\n\t\toriginalMethod: string\n\t) {\n\t\treturn function interceptedMethod(...args: any[]) {\n\t\t\t// Enter operation mode - this flag tells the proxy's get trap to return\n\t\t\t// base values instead of creating nested proxies during iteration\n\t\t\tconst method = originalMethod as ArrayOperationMethod\n\t\t\tenterOperation(state, method)\n\n\t\t\ttry {\n\t\t\t\t// Check if this is a mutating method\n\t\t\t\tif (isMutatingArrayMethod(method)) {\n\t\t\t\t\t// Direct method dispatch - no configuration lookup needed\n\t\t\t\t\tif (RESULT_RETURNING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleSimpleOperation(state, method, args)\n\t\t\t\t\t}\n\t\t\t\t\tif (REORDERING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleReorderingOperation(state, method, args)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"splice\") {\n\t\t\t\t\t\tconst res = executeArrayMethod(state, () =>\n\t\t\t\t\t\t\tstate.copy_!.splice(...(args as [number, number, ...any[]]))\n\t\t\t\t\t\t)\n\t\t\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\t\t\treturn res\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Handle non-mutating methods\n\t\t\t\t\treturn handleNonMutatingOperation(state, method, args)\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\t// Always exit operation mode - must be in finally to handle exceptions\n\t\t\t\texitOperation(state)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles non-mutating array methods with different return semantics.\n\t *\n\t * **Subset operations** return draft proxies for mutation tracking:\n\t * - `filter`, `slice`: Return `state.draft_[i]` for each selected element\n\t * - `find`, `findLast`: Return `state.draft_[i]` for the found element\n\t *\n\t * This allows mutations on returned elements to propagate back to the draft:\n\t * ```ts\n\t * const filtered = draft.items.filter(x => x.value > 5)\n\t * filtered[0].value = 999 // Mutates draft.items[originalIndex]\n\t * ```\n\t *\n\t * **Transform operations** return base values (no draft tracking):\n\t * - `concat`, `flat`: These create NEW arrays rather than selecting subsets.\n\t * Since the result structure differs from the original, tracking mutations\n\t * back to specific draft indices would be impractical/impossible.\n\t *\n\t * **Primitive operations** return the native result directly:\n\t * - `indexOf`, `includes`, `some`, `every`, `join`, etc.\n\t *\n\t * @param state - The proxy array state\n\t * @param method - The non-mutating method name\n\t * @param args - Arguments passed to the method\n\t * @returns Drafts for subset operations, base values for transforms, primitives otherwise\n\t */\n\tfunction handleNonMutatingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: NonMutatingArrayMethod,\n\t\targs: any[]\n\t) {\n\t\tconst source = latest(state)\n\n\t\t// Methods that return arrays with selected items - need to return drafts\n\t\tif (method === \"filter\") {\n\t\t\tconst predicate = args[0]\n\t\t\tconst result: any[] = []\n\n\t\t\t// First pass: call predicate on base values to determine which items pass\n\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\t// Only create draft for items that passed the predicate\n\t\t\t\t\tresult.push(state.draft_[i])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\tif (FIND_METHODS.has(method)) {\n\t\t\tconst predicate = args[0]\n\t\t\tconst isForward = method === \"find\"\n\t\t\tconst step = isForward ? 1 : -1\n\t\t\tconst start = isForward ? 0 : source.length - 1\n\n\t\t\tfor (let i = start; i >= 0 && i < source.length; i += step) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\treturn state.draft_[i]\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (method === \"slice\") {\n\t\t\tconst rawStart = args[0] ?? 0\n\t\t\tconst rawEnd = args[1] ?? source.length\n\n\t\t\t// Normalize negative indices\n\t\t\tconst start = normalizeSliceIndex(rawStart, source.length)\n\t\t\tconst end = normalizeSliceIndex(rawEnd, source.length)\n\n\t\t\tconst result: any[] = []\n\n\t\t\t// Return drafts for items in the slice range\n\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\tresult.push(state.draft_[i])\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\t// For other methods, call on base array directly:\n\t\t// - indexOf, includes, join, toString: Return primitives, no draft needed\n\t\t// - concat, flat: Return NEW arrays (not subsets). Elements are base values.\n\t\t// This is intentional - concat/flat create new data structures rather than\n\t\t// selecting subsets of the original, making draft tracking impractical.\n\t\treturn source[method as keyof typeof Array.prototype](...args)\n\t}\n\n\tloadPlugin(PluginArrayMethods, {\n\t\tcreateMethodInterceptor,\n\t\tisArrayOperationMethod,\n\t\tisMutatingArrayMethod\n\t})\n}\n","import {\n\tIProduce,\n\tIProduceWithPatches,\n\tImmer,\n\tDraft,\n\tImmutable,\n\tNOTHING as nothing\n} from \"./internal\"\n\nexport {\n\tDraft,\n\tWritableDraft,\n\tImmutable,\n\tPatch,\n\tPatchListener,\n\tProducer,\n\toriginal,\n\tcurrent,\n\tisDraft,\n\tisDraftable,\n\tDRAFTABLE as immerable,\n\tfreeze,\n\tObjectish,\n\tStrictMode\n} from \"./internal\"\n\nexport {nothing}\n\nconst immer = new Immer()\n\n/**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\nexport const produce: IProduce = /* @__PURE__ */ immer.produce\n\n/**\n * Like `produce`, but `produceWithPatches` always returns a tuple\n * [nextState, patches, inversePatches] (instead of just the next state)\n */\nexport const produceWithPatches: IProduceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(\n\timmer\n)\n\n/**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * Always freeze by default, even in production mode\n */\nexport const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)\n\n/**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\nexport const setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(\n\timmer\n)\n\n/**\n * Pass false to use loose iteration that only processes enumerable string properties.\n * This skips symbols and non-enumerable properties for maximum performance.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\nexport const setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(\n\timmer\n)\n\n/**\n * Apply an array of Immer patches to the first argument.\n *\n * This function is a producer, which means copy-on-write is in effect.\n */\nexport const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)\n\n/**\n * Create an Immer draft from the given base state, which may be a draft itself.\n * The draft can be modified until you finalize it with the `finishDraft` function.\n */\nexport const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)\n\n/**\n * Finalize an Immer draft from a `createDraft` call, returning the base state\n * (if no changes were made) or a modified copy. The draft must *not* be\n * mutated afterwards.\n *\n * Pass a function as the 2nd argument to generate Immer patches based on the\n * changes that were made.\n */\nexport const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)\n\n/**\n * This function is actually a no-op, but can be used to cast an immutable type\n * to an draft type and make TypeScript happy\n *\n * @param value\n */\nexport let castDraft = (value: T): Draft => value as any\n\n/**\n * This function is actually a no-op, but can be used to cast a mutable type\n * to an immutable type and make TypeScript happy\n * @param value\n */\nexport let castImmutable = (value: T): Immutable => value as any\n\nexport {Immer}\n\nexport {enablePatches} from \"./plugins/patches\"\nexport {enableMapSet} from \"./plugins/mapset\"\nexport {enableArrayMethods} from \"./plugins/arrayMethods\"\n\nexport function isNothing(value: unknown): value is typeof nothing {\n\treturn value === nothing\n}\n"],"mappings":";AAKO,IAAM,UAAyB,OAAO,IAAI,eAAe;AAUzD,IAAM,YAA2B,OAAO,IAAI,iBAAiB;AAE7D,IAAM,cAA6B,OAAO,IAAI,aAAa;;;ACf3D,IAAM,SACZ,QAAQ,IAAI,aAAa,eACtB;AAAA;AAAA,EAEA,SAAS,QAAgB;AACxB,WAAO,mBAAm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AAAA,EACpF;AACD;AAQO,IAAM,wBAAwC,sBAAM,sBAAsB;AAAA,EAChF;AACD;AAOO,IAAM,eAA+B,sBAAM,aAAa,KAAK,KAAK;AAMlE,IAAM,cAA8B,sBAAM,YAAY,KAAK,KAAK;AAUhE,IAAM,cAA8B,sBAAM,YAAY,KAAK,KAAK;AAQhE,IAAI,YAAY,CAAI,UAAuB;AAO3C,IAAI,gBAAgB,CAAI,UAA2B;AAQnD,SAAS,UAAU,OAAyC;AAClE,SAAO,UAAU;AAClB;","names":["immer","current","Immer","base","rootScope","isSet","current","set","Immer"]} \ No newline at end of file diff --git a/dist/immer.production.mjs b/dist/immer.production.mjs new file mode 100644 index 00000000..47563d1f --- /dev/null +++ b/dist/immer.production.mjs @@ -0,0 +1,1103 @@ +var B = Symbol.for("immer-nothing"), + v = Symbol.for("immer-draftable"), + y = Symbol.for("immer-state") +function b(e, ...t) { + throw new Error( + `[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf` + ) +} +var F = Object, + L = F.getPrototypeOf, + ee = "constructor", + te = "prototype", + me = "configurable", + ce = "enumerable", + se = "writable", + re = "value", + w = e => !!e && !!e[y] +function _(e) { + return e ? Re(e) || $(e) || !!e[v] || !!e[ee]?.[v] || q(e) || Y(e) : !1 +} +var $e = F[te][ee].toString(), + Ce = new WeakMap() +function Re(e) { + if (!e || !H(e)) return !1 + let t = L(e) + if (t === null || t === F[te]) return !0 + let r = F.hasOwnProperty.call(t, ee) && t[ee] + if (r === Object) return !0 + if (!j(r)) return !1 + let n = Ce.get(r) + return ( + n === void 0 && ((n = Function.toString.call(r)), Ce.set(r, n)), n === $e + ) +} +function qe(e) { + return w(e) || b(15, e), e[y].t +} +function z(e, t, r = !0) { + K(e) === 0 + ? (r ? Reflect.ownKeys(e) : F.keys(e)).forEach(o => { + t(o, e[o], e) + }) + : e.forEach((n, o) => t(o, n, e)) +} +function K(e) { + let t = e[y] + return t ? t.r : $(e) ? 1 : q(e) ? 2 : Y(e) ? 3 : 0 +} +var G = (e, t, r = K(e)) => + r === 2 ? e.has(t) : F[te].hasOwnProperty.call(e, t), + U = (e, t, r = K(e)) => (r === 2 ? e.get(t) : e[t]), + ne = (e, t, r, n = K(e)) => { + n === 2 ? e.set(t, r) : n === 3 ? e.add(r) : (e[t] = r) + } +function ze(e, t) { + return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t +} +var $ = Array.isArray, + q = e => e instanceof Map, + Y = e => e instanceof Set, + H = e => typeof e == "object", + j = e => typeof e == "function", + Se = e => typeof e == "boolean" +function ke(e) { + let t = +e + return Number.isInteger(t) && String(t) === e +} +var Te = e => (H(e) ? e?.[y] : null), + O = e => e.e || e.t, + Ue = e => { + let t = Te(e) + return t ? t.e ?? t.t : e + }, + Pe = e => (e.s ? e.e : e.t) +function fe(e, t) { + if (q(e)) return new Map(e) + if (Y(e)) return new Set(e) + if ($(e)) return Array[te].slice.call(e) + let r = Re(e) + if (t === !0 || (t === "class_only" && !r)) { + let n = F.getOwnPropertyDescriptors(e) + delete n[y] + let o = Reflect.ownKeys(n) + for (let i = 0; i < o.length; i++) { + let d = o[i], + S = n[d] + S[se] === !1 && ((S[se] = !0), (S[me] = !0)), + (S.get || S.set) && + (n[d] = {[me]: !0, [se]: !0, [ce]: S[ce], [re]: e[d]}) + } + return F.create(L(e), n) + } else { + let n = L(e) + if (n !== null && r) return {...e} + let o = F.create(n) + return F.assign(o, e) + } +} +function ae(e, t = !1) { + return ( + oe(e) || + w(e) || + !_(e) || + (K(e) > 1 && + F.defineProperties(e, {set: he, add: he, clear: he, delete: he}), + F.freeze(e), + t && + z( + e, + (r, n) => { + ae(n, !0) + }, + !1 + )), + e + ) +} +function Ye() { + b(2) +} +var he = {[re]: Ye} +function oe(e) { + return e === null || !H(e) ? !0 : F.isFrozen(e) +} +var W = "MapSet", + J = "Patches", + le = "ArrayMethods", + ge = {} +function V(e) { + let t = ge[e] + return t || b(0, e), t +} +var be = e => !!ge[e] +function ie(e, t) { + ge[e] || (ge[e] = t) +} +var ye, + Q = () => ye, + Je = (e, t) => ({ + o: [], + i: e, + l: t, + F: !0, + m: 0, + A: new Set(), + T: new Set(), + I: be(W) ? V(W) : void 0, + E: be(le) ? V(le) : void 0 + }) +function Oe(e, t) { + t && ((e.P = V(J)), (e.p = []), (e.d = []), (e.C = t)) +} +function de(e) { + xe(e), e.o.forEach(Qe), (e.o = null) +} +function xe(e) { + e === ye && (ye = e.i) +} +var De = e => (ye = Je(ye, e)) +function Qe(e) { + let t = e[y] + t.r === 0 || t.r === 1 ? t.b() : (t.x = !0) +} +function _e(e, t) { + t.m = t.o.length + let r = t.o[0] + if (e !== void 0 && e !== r) { + r[y].s && (de(t), b(4)), _(e) && (e = Le(t, e)) + let {P: o} = t + o && o.M(r[y].t, e, t) + } else e = Le(t, r) + return Xe(t, e, !0), de(t), t.p && t.C(t.p, t.d), e !== B ? e : void 0 +} +function Le(e, t) { + if (oe(t)) return t + let r = t[y] + if (!r) return Ee(t, e.A, e) + if (!Ae(r, e)) return t + if (!r.s) return r.t + if (!r.u) { + let {f: n} = r + if (n) for (; n.length > 0; ) n.pop()(e) + ve(r, e) + } + return r.e +} +function Xe(e, t, r = !1) { + !e.i && e.l.h && e.F && ae(t, r) +} +function je(e) { + ;(e.u = !0), e.n.m-- +} +var Ae = (e, t) => e.n === t, + Ze = [] +function Ve(e, t, r, n) { + let o = O(e), + i = e.r + if (n !== void 0 && U(o, n, i) === t) { + ne(o, n, r, i) + return + } + if (!e.D) { + let S = (e.D = new Map()) + z(o, (p, M) => { + if (w(M)) { + let a = S.get(M) || [] + a.push(p), S.set(M, a) + } + }) + } + let d = e.D.get(t) ?? Ze + for (let S of d) ne(o, S, r, i) +} +function Be(e, t, r) { + e.f.push(function(o) { + let i = t + if (!i || !Ae(i, o)) return + o.I?.fixSetContents(i) + let d = Pe(i) + Ve(e, i.c ?? i, d, r), ve(i, o) + }) +} +function ve(e, t) { + if ( + e.s && + !e.u && + (e.r === 3 || (e.r === 1 && e.R) || (e.a?.size ?? 0) > 0) + ) { + let {P: n} = t + if (n) { + let o = n.getPath(e) + o && n.O(e, o, t) + } + je(e) + } +} +function Ke(e, t, r) { + let {n} = e + if (w(r)) { + let o = r[y] + Ae(o, n) && + o.f.push(function() { + X(e) + let d = Pe(o) + Ve(e, r, d, t) + }) + } else + _(r) && + e.f.push(function() { + let i = O(e) + U(i, t, e.r) === r && + n.o.length > 1 && + (e.a.get(t) ?? !1) === !0 && + e.e && + Ee(U(e.e, t, e.r), n.A, n) + }) +} +function Ee(e, t, r) { + return ( + (!r.l.h && r.m < 1) || + w(e) || + t.has(e) || + !_(e) || + oe(e) || + (t.add(e), + z(e, (n, o) => { + if (w(o)) { + let i = o[y] + if (Ae(i, r)) { + let d = Pe(i) + ne(e, n, d, e.r), je(i) + } + } else _(o) && Ee(o, t, r) + })), + e + ) +} +function He(e, t) { + let r = $(e), + n = { + r: r ? 1 : 0, + n: t ? t.n : Q(), + s: !1, + u: !1, + a: void 0, + i: t, + t: e, + c: null, + e: null, + b: null, + S: !1, + f: void 0 + }, + o = n, + i = Ne + r && ((o = [n]), (i = pe)) + let {revoke: d, proxy: S} = Proxy.revocable(o, i) + return (n.c = S), (n.b = d), [S, n] +} +var Ne = { + get(e, t) { + if (t === y) return e + let r = e.n.E, + n = e.r === 1 && typeof t == "string" + if (n && r?.isArrayOperationMethod(t)) + return r.createMethodInterceptor(e, t) + let o = O(e) + if (!G(o, t, e.r)) return et(e, o, t) + let i = o[t] + if ( + e.u || + !_(i) || + (n && + e.operationMethod && + r?.isMutatingArrayMethod(e.operationMethod) && + ke(t)) + ) + return i + if (i === we(e.t, t)) { + X(e) + let d = e.r === 1 ? +t : t, + S = Z(e.n, i, e, d) + return (e.e[d] = S) + } + return i + }, + has(e, t) { + return t in O(e) + }, + ownKeys(e) { + return Reflect.ownKeys(O(e)) + }, + set(e, t, r) { + let n = We(O(e), t) + if (n?.set) return n.set.call(e.c, r), !0 + if (!e.s) { + let o = we(O(e), t), + i = o?.[y] + if (i && i.t === r) return (e.e[t] = r), e.a.set(t, !1), !0 + if (ze(r, o) && (r !== void 0 || G(e.t, t, e.r))) return !0 + X(e), k(e) + } + return ( + (e.e[t] === r && (r !== void 0 || t in e.e)) || + (Number.isNaN(r) && Number.isNaN(e.e[t])) || + ((e.e[t] = r), e.a.set(t, !0), Ke(e, t, r)), + !0 + ) + }, + deleteProperty(e, t) { + return ( + X(e), + we(e.t, t) !== void 0 || t in e.t + ? (e.a.set(t, !1), k(e)) + : e.a.delete(t), + e.e && delete e.e[t], + !0 + ) + }, + getOwnPropertyDescriptor(e, t) { + let r = O(e), + n = Reflect.getOwnPropertyDescriptor(r, t) + return ( + n && { + [se]: !0, + [me]: e.r !== 1 || t !== "length", + [ce]: n[ce], + [re]: r[t] + } + ) + }, + defineProperty() { + b(11) + }, + getPrototypeOf(e) { + return L(e.t) + }, + setPrototypeOf() { + b(12) + } + }, + pe = {} +z(Ne, (e, t) => { + pe[e] = function() { + let r = arguments + return (r[0] = r[0][0]), t.apply(this, r) + } +}) +pe.deleteProperty = function(e, t) { + return pe.set.call(this, e, t, void 0) +} +pe.set = function(e, t, r) { + return Ne.set.call(this, e[0], t, r, e[0]) +} +function we(e, t) { + let r = e[y] + return (r ? O(r) : e)[t] +} +function et(e, t, r) { + let n = We(t, r) + return n ? (re in n ? n[re] : n.get?.call(e.c)) : void 0 +} +function We(e, t) { + if (!(t in e)) return + let r = L(e) + for (; r; ) { + let n = Object.getOwnPropertyDescriptor(r, t) + if (n) return n + r = L(r) + } +} +function k(e) { + e.s || ((e.s = !0), e.i && k(e.i)) +} +function X(e) { + e.e || ((e.a = new Map()), (e.e = fe(e.t, e.n.l.g))) +} +var Ie = class { + constructor(t) { + this.h = !0 + this.g = !1 + this._ = !1 + this.produce = (t, r, n) => { + if (j(t) && !j(r)) { + let i = r + r = t + let d = this + return function(p = i, ...M) { + return d.produce(p, a => r.call(this, a, ...M)) + } + } + j(r) || b(6), n !== void 0 && !j(n) && b(7) + let o + if (_(t)) { + let i = De(this), + d = Z(i, t, void 0), + S = !0 + try { + ;(o = r(d)), (S = !1) + } finally { + S ? de(i) : xe(i) + } + return Oe(i, n), _e(o, i) + } else if (!t || !H(t)) { + if ( + ((o = r(t)), + o === void 0 && (o = t), + o === B && (o = void 0), + this.h && ae(o, !0), + n) + ) { + let i = [], + d = [] + V(J).M(t, o, {p: i, d}), n(i, d) + } + return o + } else b(1, t) + } + this.produceWithPatches = (t, r) => { + if (j(t)) return (d, ...S) => this.produceWithPatches(d, p => t(p, ...S)) + let n, o + return [ + this.produce(t, r, (d, S) => { + ;(n = d), (o = S) + }), + n, + o + ] + } + Se(t?.autoFreeze) && this.setAutoFreeze(t.autoFreeze), + Se(t?.useStrictShallowCopy) && + this.setUseStrictShallowCopy(t.useStrictShallowCopy), + Se(t?.useStrictIteration) && + this.setUseStrictIteration(t.useStrictIteration) + } + createDraft(t) { + _(t) || b(8), w(t) && (t = Fe(t)) + let r = De(this), + n = Z(r, t, void 0) + return (n[y].S = !0), xe(r), n + } + finishDraft(t, r) { + let n = t && t[y] + ;(!n || !n.S) && b(9) + let {n: o} = n + return Oe(o, r), _e(void 0, o) + } + setAutoFreeze(t) { + this.h = t + } + setUseStrictShallowCopy(t) { + this.g = t + } + setUseStrictIteration(t) { + this._ = t + } + shouldUseStrictIteration() { + return this._ + } + applyPatches(t, r) { + let n + for (n = r.length - 1; n >= 0; n--) { + let i = r[n] + if (i.path.length === 0 && i.op === "replace") { + t = i.value + break + } + } + n > -1 && (r = r.slice(n + 1)) + let o = V(J).N + return w(t) ? o(t, r) : this.produce(t, i => o(i, r)) + } +} +function Z(e, t, r, n) { + let [o, i] = q(t) ? V(W).w(t, r) : Y(t) ? V(W).v(t, r) : He(t, r) + return ( + (r?.n ?? Q()).o.push(o), + (i.f = r?.f ?? []), + (i.y = n), + r && n !== void 0 + ? Be(r, i, n) + : i.f.push(function(p) { + p.I?.fixSetContents(i) + let {P: M} = p + i.s && M && M.O(i, [], p) + }), + o + ) +} +function Fe(e) { + return w(e) || b(10, e), Ge(e) +} +function Ge(e) { + if (!_(e) || oe(e)) return e + let t = e[y], + r, + n = !0 + if (t) { + if (!t.s) return t.t + ;(t.u = !0), (r = fe(e, t.n.l.g)), (n = t.n.l.shouldUseStrictIteration()) + } else r = fe(e, !0) + return ( + z( + r, + (o, i) => { + ne(r, o, Ge(i)) + }, + n + ), + t && (t.u = !1), + r + ) +} +function tt() { + function t(c, P = []) { + if ("key_" in c && c.y !== void 0) { + let m = c.i.e ?? c.i.t, + x = Te(U(m, c.y)), + A = U(m, c.y) + if ( + A === void 0 || + (A !== c.c && A !== c.t && A !== c.e) || + (x != null && x.t !== c.t) + ) + return null + let s = c.i.r === 3, + l + if (s) { + let h = c.i + l = Array.from(h.o.keys()).indexOf(c.y) + } else l = c.y + if (!((s && m.size > l) || G(m, l))) return null + P.push(l) + } + if (c.i) return t(c.i, P) + P.reverse() + try { + r(c.e, P) + } catch { + return null + } + return P + } + function r(c, P) { + let m = c + for (let x = 0; x < P.length - 1; x++) { + let A = P[x] + if (((m = U(m, A)), !H(m) || m === null)) + throw new Error(`Cannot resolve path at '${P.join("/")}'`) + } + return m + } + let n = "replace", + o = "add", + i = "remove" + function d(c, P, m) { + if (c.n.T.has(c)) return + c.n.T.add(c) + let {p: x, d: A} = m + switch (c.r) { + case 0: + case 2: + return p(c, P, x, A) + case 1: + return S(c, P, x, A) + case 3: + return M(c, P, x, A) + } + } + function S(c, P, m, x) { + let {t: A, a: s} = c, + l = c.e + l.length < A.length && (([A, l] = [l, A]), ([m, x] = [x, m])) + let h = c.R === !0 + for (let f = 0; f < A.length; f++) { + let I = l[f], + E = A[f] + if ((h || s?.get(f.toString())) && I !== E) { + let C = I?.[y] + if (C && C.s) continue + let R = P.concat([f]) + m.push({op: n, path: R, value: D(I)}), + x.push({op: n, path: R, value: D(E)}) + } + } + for (let f = A.length; f < l.length; f++) { + let I = P.concat([f]) + m.push({op: o, path: I, value: D(l[f])}) + } + for (let f = l.length - 1; A.length <= f; --f) { + let I = P.concat([f]) + x.push({op: i, path: I}) + } + } + function p(c, P, m, x) { + let {t: A, e: s, r: l} = c + z(c.a, (h, f) => { + let I = U(A, h, l), + E = U(s, h, l), + T = f ? (G(A, h) ? n : o) : i + if (I === E && T === n) return + let C = P.concat(h) + m.push(T === i ? {op: T, path: C} : {op: T, path: C, value: D(E)}), + x.push( + T === o + ? {op: i, path: C} + : T === i + ? {op: o, path: C, value: D(I)} + : {op: n, path: C, value: D(I)} + ) + }) + } + function M(c, P, m, x) { + let {t: A, e: s} = c, + l = 0 + A.forEach(h => { + if (!s.has(h)) { + let f = P.concat([l]) + m.push({op: i, path: f, value: h}), + x.unshift({op: o, path: f, value: h}) + } + l++ + }), + (l = 0), + s.forEach(h => { + if (!A.has(h)) { + let f = P.concat([l]) + m.push({op: o, path: f, value: h}), + x.unshift({op: i, path: f, value: h}) + } + l++ + }) + } + function a(c, P, m) { + let {p: x, d: A} = m + x.push({op: n, path: [], value: P === B ? void 0 : P}), + A.push({op: n, path: [], value: c}) + } + function u(c, P) { + return ( + P.forEach(m => { + let {path: x, op: A} = m, + s = c + for (let I = 0; I < x.length - 1; I++) { + let E = K(s), + T = x[I] + typeof T != "string" && typeof T != "number" && (T = "" + T), + (E === 0 || E === 1) && + (T === "__proto__" || T === ee) && + b(16 + 3), + j(s) && T === te && b(16 + 3), + (s = U(s, T)), + H(s) || b(16 + 2, x.join("/")) + } + let l = K(s), + h = g(m.value), + f = x[x.length - 1] + switch (A) { + case n: + switch (l) { + case 2: + return s.set(f, h) + case 3: + b(16) + default: + return (s[f] = h) + } + case o: + switch (l) { + case 1: + return f === "-" ? s.push(h) : s.splice(f, 0, h) + case 2: + return s.set(f, h) + case 3: + return s.add(h) + default: + return (s[f] = h) + } + case i: + switch (l) { + case 1: + return s.splice(f, 1) + case 2: + return s.delete(f) + case 3: + return s.delete(m.value) + default: + return delete s[f] + } + default: + b(16 + 1, A) + } + }), + c + ) + } + function g(c) { + if (!_(c)) return c + if ($(c)) return c.map(g) + if (q(c)) return new Map(Array.from(c.entries()).map(([m, x]) => [m, g(x)])) + if (Y(c)) return new Set(Array.from(c).map(g)) + let P = Object.create(L(c)) + for (let m in c) P[m] = g(c[m]) + return G(c, v) && (P[v] = c[v]), P + } + function D(c) { + return w(c) ? g(c) : c + } + ie(J, {N: u, O: d, M: a, getPath: t}) +} +function rt() { + class e extends Map { + constructor(a, u) { + super() + this[y] = { + r: 2, + i: u, + n: u ? u.n : Q(), + s: !1, + u: !1, + e: void 0, + a: void 0, + t: a, + c: this, + S: !1, + x: !1, + f: [] + } + } + get size() { + return O(this[y]).size + } + has(a) { + return O(this[y]).has(a) + } + set(a, u) { + let g = this[y] + return ( + d(g), + (!O(g).has(a) || O(g).get(a) !== u) && + (r(g), k(g), g.a.set(a, !0), g.e.set(a, u), g.a.set(a, !0)), + this + ) + } + delete(a) { + if (!this.has(a)) return !1 + let u = this[y] + return ( + d(u), + r(u), + k(u), + u.t.has(a) ? u.a.set(a, !1) : u.a.delete(a), + u.e.delete(a), + !0 + ) + } + clear() { + let a = this[y] + d(a), + O(a).size && + (r(a), + k(a), + (a.a = new Map()), + z(a.t, u => { + a.a.set(u, !1) + }), + a.e.clear()) + } + forEach(a, u) { + let g = this[y] + O(g).forEach((D, c, P) => { + a.call(u, this.get(c), c, this) + }) + } + get(a) { + let u = this[y] + d(u) + let g = O(u).get(a) + if (u.u || !_(g) || g !== u.t.get(a)) return g + let D = Z(u.n, g, u, a) + return r(u), u.e.set(a, D), D + } + keys() { + return O(this[y]).keys() + } + values() { + let a = this.keys() + return { + [Symbol.iterator]: () => this.values(), + next: () => { + let u = a.next() + return u.done ? u : {done: !1, value: this.get(u.value)} + } + } + } + entries() { + let a = this.keys() + return { + [Symbol.iterator]: () => this.entries(), + next: () => { + let u = a.next() + if (u.done) return u + let g = this.get(u.value) + return {done: !1, value: [u.value, g]} + } + } + } + [(y, Symbol.iterator)]() { + return this.entries() + } + } + function t(p, M) { + let a = new e(p, M) + return [a, a[y]] + } + function r(p) { + p.e || ((p.a = new Map()), (p.e = new Map(p.t))) + } + class n extends Set { + constructor(a, u) { + super() + this[y] = { + r: 3, + i: u, + n: u ? u.n : Q(), + s: !1, + u: !1, + e: void 0, + t: a, + c: this, + o: new Map(), + x: !1, + S: !1, + a: void 0, + f: [] + } + } + get size() { + return O(this[y]).size + } + has(a) { + let u = this[y] + return ( + d(u), + u.e ? !!(u.e.has(a) || (u.o.has(a) && u.e.has(u.o.get(a)))) : u.t.has(a) + ) + } + add(a) { + let u = this[y] + return d(u), this.has(a) || (i(u), k(u), u.e.add(a)), this + } + delete(a) { + if (!this.has(a)) return !1 + let u = this[y] + return ( + d(u), + i(u), + k(u), + u.e.delete(a) || (u.o.has(a) ? u.e.delete(u.o.get(a)) : !1) + ) + } + clear() { + let a = this[y] + d(a), O(a).size && (i(a), k(a), a.e.clear()) + } + values() { + let a = this[y] + return d(a), i(a), a.e.values() + } + entries() { + let a = this[y] + return d(a), i(a), a.e.entries() + } + keys() { + return this.values() + } + [(y, Symbol.iterator)]() { + return this.values() + } + forEach(a, u) { + let g = this.values(), + D = g.next() + for (; !D.done; ) a.call(u, D.value, D.value, this), (D = g.next()) + } + } + function o(p, M) { + let a = new n(p, M) + return [a, a[y]] + } + function i(p) { + p.e || + ((p.e = new Set()), + p.t.forEach(M => { + if (_(M)) { + let a = Z(p.n, M, p, M) + p.o.set(M, a), p.e.add(a) + } else p.e.add(M) + })) + } + function d(p) { + p.x && b(3, JSON.stringify(O(p))) + } + function S(p) { + if (p.r === 3 && p.e) { + let M = new Set(p.e) + p.e.clear(), + M.forEach(a => { + p.e.add(Ue(a)) + }) + } + } + ie(W, {w: t, v: o, fixSetContents: S}) +} +function nt() { + let e = new Set(["shift", "unshift"]), + t = new Set(["push", "pop"]), + r = new Set([...t, ...e]), + n = new Set(["reverse", "sort"]), + o = new Set([...r, ...n, "splice"]), + i = new Set(["find", "findLast"]), + d = new Set([ + "filter", + "slice", + "concat", + "flat", + ...i, + "findIndex", + "findLastIndex", + "some", + "every", + "indexOf", + "lastIndexOf", + "includes", + "join", + "toString", + "toLocaleString" + ]) + function S(s) { + return o.has(s) + } + function p(s) { + return d.has(s) + } + function M(s) { + return S(s) || p(s) + } + function a(s, l) { + s.operationMethod = l + } + function u(s) { + s.operationMethod = void 0 + } + function g(s, l, h = !0) { + X(s) + let f = l() + return k(s), h && s.a.set("length", !0), f + } + function D(s) { + s.R = !0 + } + function c(s, l) { + return s < 0 ? Math.max(l + s, 0) : Math.min(s, l) + } + function P(s, l, h) { + return g(s, () => { + let f = s.e[l](...h) + return e.has(l) && D(s), r.has(l) ? f : s.c + }) + } + function m(s, l, h) { + return g(s, () => (s.e[l](...h), D(s), s.c), !1) + } + function x(s, l) { + return function(...f) { + let I = l + a(s, I) + try { + if (S(I)) { + if (r.has(I)) return P(s, I, f) + if (n.has(I)) return m(s, I, f) + if (I === "splice") { + let E = g(s, () => s.e.splice(...f)) + return D(s), E + } + } else return A(s, I, f) + } finally { + u(s) + } + } + } + function A(s, l, h) { + let f = O(s) + if (l === "filter") { + let I = h[0], + E = [] + for (let T = 0; T < f.length; T++) I(f[T], T, f) && E.push(s.c[T]) + return E + } + if (i.has(l)) { + let I = h[0], + E = l === "find", + T = E ? 1 : -1, + C = E ? 0 : f.length - 1 + for (let R = C; R >= 0 && R < f.length; R += T) + if (I(f[R], R, f)) return s.c[R] + return + } + if (l === "slice") { + let I = h[0] ?? 0, + E = h[1] ?? f.length, + T = c(I, f.length), + C = c(E, f.length), + R = [] + for (let Me = T; Me < C; Me++) R.push(s.c[Me]) + return R + } + return f[l](...h) + } + ie(le, { + createMethodInterceptor: x, + isArrayOperationMethod: M, + isMutatingArrayMethod: S + }) +} +var N = new Ie(), + Gr = N.produce, + $r = N.produceWithPatches.bind(N), + qr = N.setAutoFreeze.bind(N), + Yr = N.setUseStrictShallowCopy.bind(N), + Jr = N.setUseStrictIteration.bind(N), + Qr = N.applyPatches.bind(N), + Xr = N.createDraft.bind(N), + Zr = N.finishDraft.bind(N), + en = e => e, + tn = e => e +function rn(e) { + return e === B +} +export { + Ie as Immer, + Qr as applyPatches, + en as castDraft, + tn as castImmutable, + Xr as createDraft, + Fe as current, + nt as enableArrayMethods, + rt as enableMapSet, + tt as enablePatches, + Zr as finishDraft, + ae as freeze, + v as immerable, + w as isDraft, + _ as isDraftable, + rn as isNothing, + B as nothing, + qe as original, + Gr as produce, + $r as produceWithPatches, + qr as setAutoFreeze, + Jr as setUseStrictIteration, + Yr as setUseStrictShallowCopy +} +//# sourceMappingURL=immer.production.mjs.map diff --git a/dist/immer.production.mjs.map b/dist/immer.production.mjs.map new file mode 100644 index 00000000..0c096b7d --- /dev/null +++ b/dist/immer.production.mjs.map @@ -0,0 +1 @@ +{"version":3,"sources":["../src/utils/env.ts","../src/utils/errors.ts","../src/utils/common.ts","../src/utils/plugins.ts","../src/core/scope.ts","../src/core/finalize.ts","../src/core/proxy.ts","../src/core/immerClass.ts","../src/core/current.ts","../src/plugins/patches.ts","../src/plugins/mapset.ts","../src/plugins/arrayMethods.ts","../src/immer.ts"],"sourcesContent":["// Should be no imports here!\n\n/**\n * The sentinel value returned by producers to replace the draft with undefined.\n */\nexport const NOTHING: unique symbol = Symbol.for(\"immer-nothing\")\n\n/**\n * To let Immer treat your class instances as plain immutable objects\n * (albeit with a custom prototype), you must define either an instance property\n * or a static property on each of your custom classes.\n *\n * Otherwise, your class instance will never be drafted, which means it won't be\n * safe to mutate in a produce callback.\n */\nexport const DRAFTABLE: unique symbol = Symbol.for(\"immer-draftable\")\n\nexport const DRAFT_STATE: unique symbol = Symbol.for(\"immer-state\")\n","import {isFunction} from \"../internal\"\n\nexport const errors =\n\tprocess.env.NODE_ENV !== \"production\"\n\t\t? [\n\t\t\t\t// All error codes, starting by 0:\n\t\t\t\tfunction(plugin: string) {\n\t\t\t\t\treturn `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \\`enable${plugin}()\\` when initializing your application.`\n\t\t\t\t},\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `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}'`\n\t\t\t\t},\n\t\t\t\t\"This object has been frozen and should not be mutated\",\n\t\t\t\tfunction(data: any) {\n\t\t\t\t\treturn (\n\t\t\t\t\t\t\"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? \" +\n\t\t\t\t\t\tdata\n\t\t\t\t\t)\n\t\t\t\t},\n\t\t\t\t\"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.\",\n\t\t\t\t\"Immer forbids circular references\",\n\t\t\t\t\"The first or second argument to `produce` must be a function\",\n\t\t\t\t\"The third argument to `produce` must be a function or undefined\",\n\t\t\t\t\"First argument to `createDraft` must be a plain object, an array, or an immerable object\",\n\t\t\t\t\"First argument to `finishDraft` must be a draft returned by `createDraft`\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'current' expects a draft, got: ${thing}`\n\t\t\t\t},\n\t\t\t\t\"Object.defineProperty() cannot be used on an Immer draft\",\n\t\t\t\t\"Object.setPrototypeOf() cannot be used on an Immer draft\",\n\t\t\t\t\"Immer only supports deleting array indices\",\n\t\t\t\t\"Immer only supports setting array indices and the 'length' property\",\n\t\t\t\tfunction(thing: string) {\n\t\t\t\t\treturn `'original' expects a draft, got: ${thing}`\n\t\t\t\t}\n\t\t\t\t// Note: if more errors are added, the errorOffset in Patches.ts should be increased\n\t\t\t\t// See Patches.ts for additional errors\n\t\t ]\n\t\t: []\n\nexport function die(error: number, ...args: any[]): never {\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\tconst e = errors[error]\n\t\tconst msg = isFunction(e) ? e.apply(null, args as any) : e\n\t\tthrow new Error(`[Immer] ${msg}`)\n\t}\n\tthrow new Error(\n\t\t`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`\n\t)\n}\n","import {\n\tDRAFT_STATE,\n\tDRAFTABLE,\n\tObjectish,\n\tDrafted,\n\tAnyObject,\n\tAnyMap,\n\tAnySet,\n\tImmerState,\n\tArchType,\n\tdie,\n\tStrictMode\n} from \"../internal\"\n\nconst O = Object\n\nexport const getPrototypeOf = O.getPrototypeOf\n\nexport const CONSTRUCTOR = \"constructor\"\nexport const PROTOTYPE = \"prototype\"\n\nexport const CONFIGURABLE = \"configurable\"\nexport const ENUMERABLE = \"enumerable\"\nexport const WRITABLE = \"writable\"\nexport const VALUE = \"value\"\n\n/** Returns true if the given value is an Immer draft */\n/*#__PURE__*/\nexport let isDraft = (value: any): boolean => !!value && !!value[DRAFT_STATE]\n\n/** Returns true if the given value can be drafted by Immer */\n/*#__PURE__*/\nexport function isDraftable(value: any): boolean {\n\tif (!value) return false\n\treturn (\n\t\tisPlainObject(value) ||\n\t\tisArray(value) ||\n\t\t!!value[DRAFTABLE] ||\n\t\t!!value[CONSTRUCTOR]?.[DRAFTABLE] ||\n\t\tisMap(value) ||\n\t\tisSet(value)\n\t)\n}\n\nconst objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString()\nconst cachedCtorStrings = new WeakMap()\n/*#__PURE__*/\nexport function isPlainObject(value: any): boolean {\n\tif (!value || !isObjectish(value)) return false\n\tconst proto = getPrototypeOf(value)\n\tif (proto === null || proto === O[PROTOTYPE]) return true\n\n\tconst Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR]\n\tif (Ctor === Object) return true\n\n\tif (!isFunction(Ctor)) return false\n\n\tlet ctorString = cachedCtorStrings.get(Ctor)\n\tif (ctorString === undefined) {\n\t\tctorString = Function.toString.call(Ctor)\n\t\tcachedCtorStrings.set(Ctor, ctorString)\n\t}\n\n\treturn ctorString === objectCtorString\n}\n\n/** Get the underlying object that is represented by the given draft */\n/*#__PURE__*/\nexport function original(value: T): T | undefined\nexport function original(value: Drafted): any {\n\tif (!isDraft(value)) die(15, value)\n\treturn value[DRAFT_STATE].base_\n}\n\n/**\n * Each iterates a map, set or array.\n * Or, if any other kind of object, all of its own properties.\n *\n * @param obj The object to iterate over\n * @param iter The iterator function\n * @param strict When true (default), includes symbols and non-enumerable properties.\n * When false, uses looseiteration over only enumerable string properties.\n */\nexport function each(\n\tobj: T,\n\titer: (key: string | number, value: any, source: T) => void,\n\tstrict?: boolean\n): void\nexport function each(obj: any, iter: any, strict: boolean = true) {\n\tif (getArchtype(obj) === ArchType.Object) {\n\t\t// If strict, we do a full iteration including symbols and non-enumerable properties\n\t\t// Otherwise, we only iterate enumerable string properties for performance\n\t\tconst keys = strict ? Reflect.ownKeys(obj) : O.keys(obj)\n\t\tkeys.forEach(key => {\n\t\t\titer(key, obj[key], obj)\n\t\t})\n\t} else {\n\t\tobj.forEach((entry: any, index: any) => iter(index, entry, obj))\n\t}\n}\n\n/*#__PURE__*/\nexport function getArchtype(thing: any): ArchType {\n\tconst state: undefined | ImmerState = thing[DRAFT_STATE]\n\treturn state\n\t\t? state.type_\n\t\t: isArray(thing)\n\t\t? ArchType.Array\n\t\t: isMap(thing)\n\t\t? ArchType.Map\n\t\t: isSet(thing)\n\t\t? ArchType.Set\n\t\t: ArchType.Object\n}\n\n/*#__PURE__*/\nexport let has = (\n\tthing: any,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): boolean =>\n\ttype === ArchType.Map\n\t\t? thing.has(prop)\n\t\t: O[PROTOTYPE].hasOwnProperty.call(thing, prop)\n\n/*#__PURE__*/\nexport let get = (\n\tthing: AnyMap | AnyObject,\n\tprop: PropertyKey,\n\ttype = getArchtype(thing)\n): any =>\n\t// @ts-ignore\n\ttype === ArchType.Map ? thing.get(prop) : thing[prop]\n\n/*#__PURE__*/\nexport let set = (\n\tthing: any,\n\tpropOrOldValue: PropertyKey,\n\tvalue: any,\n\ttype = getArchtype(thing)\n) => {\n\tif (type === ArchType.Map) thing.set(propOrOldValue, value)\n\telse if (type === ArchType.Set) {\n\t\tthing.add(value)\n\t} else thing[propOrOldValue] = value\n}\n\n/*#__PURE__*/\nexport function is(x: any, y: any): boolean {\n\t// From: https://github.com/facebook/fbjs/blob/c69904a511b900266935168223063dd8772dfc40/packages/fbjs/src/core/shallowEqual.js\n\tif (x === y) {\n\t\treturn x !== 0 || 1 / x === 1 / y\n\t} else {\n\t\treturn x !== x && y !== y\n\t}\n}\n\nexport let isArray = Array.isArray\n\n/*#__PURE__*/\nexport let isMap = (target: any): target is AnyMap => target instanceof Map\n\n/*#__PURE__*/\nexport let isSet = (target: any): target is AnySet => target instanceof Set\n\nexport let isObjectish = (target: any) => typeof target === \"object\"\n\nexport let isFunction = (target: any): target is Function =>\n\ttypeof target === \"function\"\n\nexport let isBoolean = (target: any): target is boolean =>\n\ttypeof target === \"boolean\"\n\nexport function isArrayIndex(value: string | number): value is number | string {\n\tconst n = +value\n\treturn Number.isInteger(n) && String(n) === value\n}\n\nexport let getProxyDraft = (value: T): ImmerState | null => {\n\tif (!isObjectish(value)) return null\n\treturn (value as {[DRAFT_STATE]: any})?.[DRAFT_STATE]\n}\n\n/*#__PURE__*/\nexport let latest = (state: ImmerState): any => state.copy_ || state.base_\n\nexport let getValue = (value: T): T => {\n\tconst proxyDraft = getProxyDraft(value)\n\treturn proxyDraft ? proxyDraft.copy_ ?? proxyDraft.base_ : value\n}\n\nexport let getFinalValue = (state: ImmerState): any =>\n\tstate.modified_ ? state.copy_ : state.base_\n\n/*#__PURE__*/\nexport function shallowCopy(base: any, strict: StrictMode) {\n\tif (isMap(base)) {\n\t\treturn new Map(base)\n\t}\n\tif (isSet(base)) {\n\t\treturn new Set(base)\n\t}\n\tif (isArray(base)) return Array[PROTOTYPE].slice.call(base)\n\n\tconst isPlain = isPlainObject(base)\n\n\tif (strict === true || (strict === \"class_only\" && !isPlain)) {\n\t\t// Perform a strict copy\n\t\tconst descriptors = O.getOwnPropertyDescriptors(base)\n\t\tdelete descriptors[DRAFT_STATE as any]\n\t\tlet keys = Reflect.ownKeys(descriptors)\n\t\tfor (let i = 0; i < keys.length; i++) {\n\t\t\tconst key: any = keys[i]\n\t\t\tconst desc = descriptors[key]\n\t\t\tif (desc[WRITABLE] === false) {\n\t\t\t\tdesc[WRITABLE] = true\n\t\t\t\tdesc[CONFIGURABLE] = true\n\t\t\t}\n\t\t\t// like object.assign, we will read any _own_, get/set accessors. This helps in dealing\n\t\t\t// with libraries that trap values, like mobx or vue\n\t\t\t// unlike object.assign, non-enumerables will be copied as well\n\t\t\tif (desc.get || desc.set)\n\t\t\t\tdescriptors[key] = {\n\t\t\t\t\t[CONFIGURABLE]: true,\n\t\t\t\t\t[WRITABLE]: true, // could live with !!desc.set as well here...\n\t\t\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t\t\t[VALUE]: base[key]\n\t\t\t\t}\n\t\t}\n\t\treturn O.create(getPrototypeOf(base), descriptors)\n\t} else {\n\t\t// perform a sloppy copy\n\t\tconst proto = getPrototypeOf(base)\n\t\tif (proto !== null && isPlain) {\n\t\t\treturn {...base} // assumption: better inner class optimization than the assign below\n\t\t}\n\t\tconst obj = O.create(proto)\n\t\treturn O.assign(obj, base)\n\t}\n}\n\n/**\n * Freezes draftable objects. Returns the original object.\n * By default freezes shallowly, but if the second argument is `true` it will freeze recursively.\n *\n * @param obj\n * @param deep\n */\nexport function freeze(obj: T, deep?: boolean): T\nexport function freeze(obj: any, deep: boolean = false): T {\n\tif (isFrozen(obj) || isDraft(obj) || !isDraftable(obj)) return obj\n\tif (getArchtype(obj) > 1 /* Map or Set */) {\n\t\tO.defineProperties(obj, {\n\t\t\tset: dontMutateMethodOverride,\n\t\t\tadd: dontMutateMethodOverride,\n\t\t\tclear: dontMutateMethodOverride,\n\t\t\tdelete: dontMutateMethodOverride\n\t\t})\n\t}\n\tO.freeze(obj)\n\tif (deep)\n\t\t// See #590, don't recurse into non-enumerable / Symbol properties when freezing\n\t\t// So use Object.values (only string-like, enumerables) instead of each()\n\t\teach(\n\t\t\tobj,\n\t\t\t(_key, value) => {\n\t\t\t\tfreeze(value, true)\n\t\t\t},\n\t\t\tfalse\n\t\t)\n\treturn obj\n}\n\nfunction dontMutateFrozenCollections() {\n\tdie(2)\n}\n\nconst dontMutateMethodOverride = {\n\t[VALUE]: dontMutateFrozenCollections\n}\n\nexport function isFrozen(obj: any): boolean {\n\t// Fast path: primitives and null/undefined are always \"frozen\"\n\tif (obj === null || !isObjectish(obj)) return true\n\treturn O.isFrozen(obj)\n}\n","import {\n\tImmerState,\n\tPatch,\n\tDrafted,\n\tImmerBaseState,\n\tAnyMap,\n\tAnySet,\n\tArchType,\n\tdie,\n\tImmerScope,\n\tProxyArrayState\n} from \"../internal\"\n\nexport const PluginMapSet = \"MapSet\"\nexport const PluginPatches = \"Patches\"\nexport const PluginArrayMethods = \"ArrayMethods\"\n\nexport type PatchesPlugin = {\n\tgeneratePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\trootScope: ImmerScope\n\t): void\n\tgenerateReplacementPatches_(\n\t\tbase: any,\n\t\treplacement: any,\n\t\trootScope: ImmerScope\n\t): void\n\tapplyPatches_(draft: T, patches: readonly Patch[]): T\n\tgetPath: (state: ImmerState) => PatchPath | null\n}\n\nexport type MapSetPlugin = {\n\tproxyMap_(target: T, parent?: ImmerState): [T, ImmerState]\n\tproxySet_(target: T, parent?: ImmerState): [T, ImmerState]\n\tfixSetContents: (state: ImmerState) => void\n}\n\nexport type ArrayMethodsPlugin = {\n\tcreateMethodInterceptor: (state: ProxyArrayState, method: string) => Function\n\tisArrayOperationMethod: (method: string) => boolean\n\tisMutatingArrayMethod: (method: string) => boolean\n}\n\n/** Plugin utilities */\nconst plugins: {\n\tPatches?: PatchesPlugin\n\tMapSet?: MapSetPlugin\n\tArrayMethods?: ArrayMethodsPlugin\n} = {}\n\ntype Plugins = typeof plugins\n\nexport function getPlugin(\n\tpluginKey: K\n): Exclude {\n\tconst plugin = plugins[pluginKey]\n\tif (!plugin) {\n\t\tdie(0, pluginKey)\n\t}\n\t// @ts-ignore\n\treturn plugin\n}\n\nexport let isPluginLoaded = (pluginKey: K): boolean =>\n\t!!plugins[pluginKey]\n\nexport let clearPlugin = (pluginKey: K): void => {\n\tdelete plugins[pluginKey]\n}\n\nexport function loadPlugin(\n\tpluginKey: K,\n\timplementation: Plugins[K]\n): void {\n\tif (!plugins[pluginKey]) plugins[pluginKey] = implementation\n}\n/** Map / Set plugin */\n\nexport interface MapState extends ImmerBaseState {\n\ttype_: ArchType.Map\n\tcopy_: AnyMap | undefined\n\tbase_: AnyMap\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\nexport interface SetState extends ImmerBaseState {\n\ttype_: ArchType.Set\n\tcopy_: AnySet | undefined\n\tbase_: AnySet\n\tdrafts_: Map // maps the original value to the draft value in the new set\n\trevoked_: boolean\n\tdraft_: Drafted\n}\n\n/** Patches plugin */\n\nexport type PatchPath = (string | number)[]\n","import {\n\tPatch,\n\tPatchListener,\n\tDrafted,\n\tImmer,\n\tDRAFT_STATE,\n\tImmerState,\n\tArchType,\n\tgetPlugin,\n\tPatchesPlugin,\n\tMapSetPlugin,\n\tisPluginLoaded,\n\tPluginMapSet,\n\tPluginPatches,\n\tArrayMethodsPlugin,\n\tPluginArrayMethods\n} from \"../internal\"\n\n/** Each scope represents a `produce` call. */\n\nexport interface ImmerScope {\n\tpatches_?: Patch[]\n\tinversePatches_?: Patch[]\n\tpatchPlugin_?: PatchesPlugin\n\tmapSetPlugin_?: MapSetPlugin\n\tarrayMethodsPlugin_?: ArrayMethodsPlugin\n\tcanAutoFreeze_: boolean\n\tdrafts_: any[]\n\tparent_?: ImmerScope\n\tpatchListener_?: PatchListener\n\timmer_: Immer\n\tunfinalizedDrafts_: number\n\thandledSet_: Set\n\tprocessedForPatches_: Set\n}\n\nlet currentScope: ImmerScope | undefined\n\nexport let getCurrentScope = () => currentScope!\n\nlet createScope = (\n\tparent_: ImmerScope | undefined,\n\timmer_: Immer\n): ImmerScope => ({\n\tdrafts_: [],\n\tparent_,\n\timmer_,\n\t// Whenever the modified draft contains a draft from another scope, we\n\t// need to prevent auto-freezing so the unowned draft can be finalized.\n\tcanAutoFreeze_: true,\n\tunfinalizedDrafts_: 0,\n\thandledSet_: new Set(),\n\tprocessedForPatches_: new Set(),\n\tmapSetPlugin_: isPluginLoaded(PluginMapSet)\n\t\t? getPlugin(PluginMapSet)\n\t\t: undefined,\n\tarrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods)\n\t\t? getPlugin(PluginArrayMethods)\n\t\t: undefined\n})\n\nexport function usePatchesInScope(\n\tscope: ImmerScope,\n\tpatchListener?: PatchListener\n) {\n\tif (patchListener) {\n\t\tscope.patchPlugin_ = getPlugin(PluginPatches) // assert we have the plugin\n\t\tscope.patches_ = []\n\t\tscope.inversePatches_ = []\n\t\tscope.patchListener_ = patchListener\n\t}\n}\n\nexport function revokeScope(scope: ImmerScope) {\n\tleaveScope(scope)\n\tscope.drafts_.forEach(revokeDraft)\n\t// @ts-ignore\n\tscope.drafts_ = null\n}\n\nexport function leaveScope(scope: ImmerScope) {\n\tif (scope === currentScope) {\n\t\tcurrentScope = scope.parent_\n\t}\n}\n\nexport let enterScope = (immer: Immer) =>\n\t(currentScope = createScope(currentScope, immer))\n\nfunction revokeDraft(draft: Drafted) {\n\tconst state: ImmerState = draft[DRAFT_STATE]\n\tif (state.type_ === ArchType.Object || state.type_ === ArchType.Array)\n\t\tstate.revoke_()\n\telse state.revoked_ = true\n}\n","import {\n\tImmerScope,\n\tDRAFT_STATE,\n\tisDraftable,\n\tNOTHING,\n\tPatchPath,\n\teach,\n\tfreeze,\n\tImmerState,\n\tisDraft,\n\tSetState,\n\tset,\n\tArchType,\n\tgetPlugin,\n\tdie,\n\trevokeScope,\n\tisFrozen,\n\tget,\n\tPatch,\n\tlatest,\n\tprepareCopy,\n\tgetFinalValue,\n\tgetValue,\n\tProxyArrayState\n} from \"../internal\"\n\nexport function processResult(result: any, scope: ImmerScope) {\n\tscope.unfinalizedDrafts_ = scope.drafts_.length\n\tconst baseDraft = scope.drafts_![0]\n\tconst isReplaced = result !== undefined && result !== baseDraft\n\n\tif (isReplaced) {\n\t\tif (baseDraft[DRAFT_STATE].modified_) {\n\t\t\trevokeScope(scope)\n\t\t\tdie(4)\n\t\t}\n\t\tif (isDraftable(result)) {\n\t\t\t// Finalize the result in case it contains (or is) a subset of the draft.\n\t\t\tresult = finalize(scope, result)\n\t\t}\n\t\tconst {patchPlugin_} = scope\n\t\tif (patchPlugin_) {\n\t\t\tpatchPlugin_.generateReplacementPatches_(\n\t\t\t\tbaseDraft[DRAFT_STATE].base_,\n\t\t\t\tresult,\n\t\t\t\tscope\n\t\t\t)\n\t\t}\n\t} else {\n\t\t// Finalize the base draft.\n\t\tresult = finalize(scope, baseDraft)\n\t}\n\n\tmaybeFreeze(scope, result, true)\n\n\trevokeScope(scope)\n\tif (scope.patches_) {\n\t\tscope.patchListener_!(scope.patches_, scope.inversePatches_!)\n\t}\n\treturn result !== NOTHING ? result : undefined\n}\n\nfunction finalize(rootScope: ImmerScope, value: any) {\n\t// Don't recurse in tho recursive data structures\n\tif (isFrozen(value)) return value\n\n\tconst state: ImmerState = value[DRAFT_STATE]\n\tif (!state) {\n\t\tconst finalValue = handleValue(value, rootScope.handledSet_, rootScope)\n\t\treturn finalValue\n\t}\n\n\t// Never finalize drafts owned by another scope\n\tif (!isSameScope(state, rootScope)) {\n\t\treturn value\n\t}\n\n\t// Unmodified draft, return the (frozen) original\n\tif (!state.modified_) {\n\t\treturn state.base_\n\t}\n\n\tif (!state.finalized_) {\n\t\t// Execute all registered draft finalization callbacks\n\t\tconst {callbacks_} = state\n\t\tif (callbacks_) {\n\t\t\twhile (callbacks_.length > 0) {\n\t\t\t\tconst callback = callbacks_.pop()!\n\t\t\t\tcallback(rootScope)\n\t\t\t}\n\t\t}\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t}\n\n\t// By now the root copy has been fully updated throughout its tree\n\treturn state.copy_\n}\n\nfunction maybeFreeze(scope: ImmerScope, value: any, deep = false) {\n\t// we never freeze for a non-root scope; as it would prevent pruning for drafts inside wrapping objects\n\tif (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {\n\t\tfreeze(value, deep)\n\t}\n}\n\nfunction markStateFinalized(state: ImmerState) {\n\tstate.finalized_ = true\n\tstate.scope_.unfinalizedDrafts_--\n}\n\nlet isSameScope = (state: ImmerState, rootScope: ImmerScope) =>\n\tstate.scope_ === rootScope\n\n// A reusable empty array to avoid allocations\nconst EMPTY_LOCATIONS_RESULT: (string | symbol | number)[] = []\n\n// Updates all references to a draft in its parent to the finalized value.\n// This handles cases where the same draft appears multiple times in the parent, or has been moved around.\nexport function updateDraftInParent(\n\tparent: ImmerState,\n\tdraftValue: any,\n\tfinalizedValue: any,\n\toriginalKey?: string | number | symbol\n): void {\n\tconst parentCopy = latest(parent)\n\tconst parentType = parent.type_\n\n\t// Fast path: Check if draft is still at original key\n\tif (originalKey !== undefined) {\n\t\tconst currentValue = get(parentCopy, originalKey, parentType)\n\t\tif (currentValue === draftValue) {\n\t\t\t// Still at original location, just update it\n\t\t\tset(parentCopy, originalKey, finalizedValue, parentType)\n\t\t\treturn\n\t\t}\n\t}\n\n\t// Slow path: Build reverse mapping of all children\n\t// to their indices in the parent, so that we can\n\t// replace all locations where this draft appears.\n\t// We only have to build this once per parent.\n\tif (!parent.draftLocations_) {\n\t\tconst draftLocations = (parent.draftLocations_ = new Map())\n\n\t\t// Use `each` which works on Arrays, Maps, and Objects\n\t\teach(parentCopy, (key, value) => {\n\t\t\tif (isDraft(value)) {\n\t\t\t\tconst keys = draftLocations.get(value) || []\n\t\t\t\tkeys.push(key)\n\t\t\t\tdraftLocations.set(value, keys)\n\t\t\t}\n\t\t})\n\t}\n\n\t// Look up all locations where this draft appears\n\tconst locations =\n\t\tparent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT\n\n\t// Update all locations\n\tfor (const location of locations) {\n\t\tset(parentCopy, location, finalizedValue, parentType)\n\t}\n}\n\n// Register a callback to finalize a child draft when the parent draft is finalized.\n// This assumes there is a parent -> child relationship between the two drafts,\n// and we have a key to locate the child in the parent.\nexport function registerChildFinalizationCallback(\n\tparent: ImmerState,\n\tchild: ImmerState,\n\tkey: string | number | symbol\n) {\n\tparent.callbacks_.push(function childCleanup(rootScope) {\n\t\tconst state: ImmerState = child\n\n\t\t// Can only continue if this is a draft owned by this scope\n\t\tif (!state || !isSameScope(state, rootScope)) {\n\t\t\treturn\n\t\t}\n\n\t\t// Handle potential set value finalization first\n\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t// Update all locations in the parent that referenced this draft\n\t\tupdateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key)\n\n\t\tgeneratePatchesAndFinalize(state, rootScope)\n\t})\n}\n\nfunction generatePatchesAndFinalize(state: ImmerState, rootScope: ImmerScope) {\n\tconst shouldFinalize =\n\t\tstate.modified_ &&\n\t\t!state.finalized_ &&\n\t\t(state.type_ === ArchType.Set ||\n\t\t\t(state.type_ === ArchType.Array &&\n\t\t\t\t(state as ProxyArrayState).allIndicesReassigned_) ||\n\t\t\t(state.assigned_?.size ?? 0) > 0)\n\n\tif (shouldFinalize) {\n\t\tconst {patchPlugin_} = rootScope\n\t\tif (patchPlugin_) {\n\t\t\tconst basePath = patchPlugin_!.getPath(state)\n\n\t\t\tif (basePath) {\n\t\t\t\tpatchPlugin_!.generatePatches_(state, basePath, rootScope)\n\t\t\t}\n\t\t}\n\n\t\tmarkStateFinalized(state)\n\t}\n}\n\nexport function handleCrossReference(\n\ttarget: ImmerState,\n\tkey: string | number | symbol,\n\tvalue: any\n) {\n\tconst {scope_} = target\n\t// Check if value is a draft from this scope\n\tif (isDraft(value)) {\n\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\tif (isSameScope(state, scope_)) {\n\t\t\t// Register callback to update this location when the draft finalizes\n\n\t\t\tstate.callbacks_.push(function crossReferenceCleanup() {\n\t\t\t\t// Update the target location with finalized value\n\t\t\t\tprepareCopy(target)\n\n\t\t\t\tconst finalizedValue = getFinalValue(state)\n\n\t\t\t\tupdateDraftInParent(target, value, finalizedValue, key)\n\t\t\t})\n\t\t}\n\t} else if (isDraftable(value)) {\n\t\t// Handle non-draft objects that might contain drafts\n\t\ttarget.callbacks_.push(function nestedDraftCleanup() {\n\t\t\tconst targetCopy = latest(target)\n\n\t\t\tif (get(targetCopy, key, target.type_) === value) {\n\t\t\t\t// Process the value to replace any nested drafts\n\t\t\t\t// finalizeAssigned(target, key, target.scope_)\n\n\t\t\t\tif (\n\t\t\t\t\tscope_.drafts_.length > 1 &&\n\t\t\t\t\t((target as Exclude).assigned_!.get(key) ??\n\t\t\t\t\t\tfalse) === true &&\n\t\t\t\t\ttarget.copy_\n\t\t\t\t) {\n\t\t\t\t\t// This might be a non-draft value that has drafts\n\t\t\t\t\t// inside. We do need to recurse here to handle those.\n\t\t\t\t\thandleValue(\n\t\t\t\t\t\tget(target.copy_, key, target.type_),\n\t\t\t\t\t\tscope_.handledSet_,\n\t\t\t\t\t\tscope_\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n}\n\nexport function handleValue(\n\ttarget: any,\n\thandledSet: Set,\n\trootScope: ImmerScope\n) {\n\tif (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {\n\t\t// optimization: if an object is not a draft, and we don't have to\n\t\t// deepfreeze everything, and we are sure that no drafts are left in the remaining object\n\t\t// cause we saw and finalized all drafts already; we can stop visiting the rest of the tree.\n\t\t// This benefits especially adding large data tree's without further processing.\n\t\t// See add-data.js perf test\n\t\treturn target\n\t}\n\n\t// Skip if already handled, frozen, or not draftable\n\tif (\n\t\tisDraft(target) ||\n\t\thandledSet.has(target) ||\n\t\t!isDraftable(target) ||\n\t\tisFrozen(target)\n\t) {\n\t\treturn target\n\t}\n\n\thandledSet.add(target)\n\n\t// Process ALL properties/entries\n\teach(target, (key, value) => {\n\t\tif (isDraft(value)) {\n\t\t\tconst state: ImmerState = value[DRAFT_STATE]\n\t\t\tif (isSameScope(state, rootScope)) {\n\t\t\t\t// Replace draft with finalized value\n\n\t\t\t\tconst updatedValue = getFinalValue(state)\n\n\t\t\t\tset(target, key, updatedValue, target.type_)\n\n\t\t\t\tmarkStateFinalized(state)\n\t\t\t}\n\t\t} else if (isDraftable(value)) {\n\t\t\t// Recursively handle nested values\n\t\t\thandleValue(value, handledSet, rootScope)\n\t\t}\n\t})\n\n\treturn target\n}\n","import {\n\teach,\n\thas,\n\tis,\n\tisDraftable,\n\tshallowCopy,\n\tlatest,\n\tImmerBaseState,\n\tImmerState,\n\tDrafted,\n\tAnyObject,\n\tAnyArray,\n\tObjectish,\n\tgetCurrentScope,\n\tgetPrototypeOf,\n\tDRAFT_STATE,\n\tdie,\n\tcreateProxy,\n\tArchType,\n\tImmerScope,\n\thandleCrossReference,\n\tWRITABLE,\n\tCONFIGURABLE,\n\tENUMERABLE,\n\tVALUE,\n\tisArray,\n\tisArrayIndex\n} from \"../internal\"\n\ninterface ProxyBaseState extends ImmerBaseState {\n\tparent_?: ImmerState\n\trevoke_(): void\n}\n\nexport interface ProxyObjectState extends ProxyBaseState {\n\ttype_: ArchType.Object\n\tbase_: any\n\tcopy_: any\n\tdraft_: Drafted\n}\n\nexport interface ProxyArrayState extends ProxyBaseState {\n\ttype_: ArchType.Array\n\tbase_: AnyArray\n\tcopy_: AnyArray | null\n\tdraft_: Drafted\n\toperationMethod?: string\n\tallIndicesReassigned_?: boolean\n}\n\ntype ProxyState = ProxyObjectState | ProxyArrayState\n\n/**\n * Returns a new draft of the `base` object.\n *\n * The second argument is the parent draft-state (used internally).\n */\nexport function createProxyProxy(\n\tbase: T,\n\tparent?: ImmerState\n): [Drafted, ProxyState] {\n\tconst baseIsArray = isArray(base)\n\tconst state: ProxyState = {\n\t\ttype_: baseIsArray ? ArchType.Array : (ArchType.Object as any),\n\t\t// Track which produce call this is associated with.\n\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t// True for both shallow and deep changes.\n\t\tmodified_: false,\n\t\t// Used during finalization.\n\t\tfinalized_: false,\n\t\t// Track which properties have been assigned (true) or deleted (false).\n\t\t// actually instantiated in `prepareCopy()`\n\t\tassigned_: undefined,\n\t\t// The parent draft state.\n\t\tparent_: parent,\n\t\t// The base state.\n\t\tbase_: base,\n\t\t// The base proxy.\n\t\tdraft_: null as any, // set below\n\t\t// The base copy with any updated values.\n\t\tcopy_: null,\n\t\t// Called by the `produce` function.\n\t\trevoke_: null as any,\n\t\tisManual_: false,\n\t\t// `callbacks` actually gets assigned in `createProxy`\n\t\tcallbacks_: undefined as any\n\t}\n\n\t// the traps must target something, a bit like the 'real' base.\n\t// but also, we need to be able to determine from the target what the relevant state is\n\t// (to avoid creating traps per instance to capture the state in closure,\n\t// and to avoid creating weird hidden properties as well)\n\t// So the trick is to use 'state' as the actual 'target'! (and make sure we intercept everything)\n\t// Note that in the case of an array, we put the state in an array to have better Reflect defaults ootb\n\tlet target: T = state as any\n\tlet traps: ProxyHandler> = objectTraps\n\tif (baseIsArray) {\n\t\ttarget = [state] as any\n\t\ttraps = arrayTraps\n\t}\n\n\tconst {revoke, proxy} = Proxy.revocable(target, traps)\n\tstate.draft_ = proxy as any\n\tstate.revoke_ = revoke\n\treturn [proxy as any, state]\n}\n\n/**\n * Object drafts\n */\nexport const objectTraps: ProxyHandler = {\n\tget(state, prop) {\n\t\tif (prop === DRAFT_STATE) return state\n\n\t\tlet arrayPlugin = state.scope_.arrayMethodsPlugin_\n\t\tconst isArrayWithStringProp =\n\t\t\tstate.type_ === ArchType.Array && typeof prop === \"string\"\n\t\t// Intercept array methods so that we can override\n\t\t// behavior and skip proxy creation for perf\n\t\tif (isArrayWithStringProp) {\n\t\t\tif (arrayPlugin?.isArrayOperationMethod(prop)) {\n\t\t\t\treturn arrayPlugin.createMethodInterceptor(state, prop)\n\t\t\t}\n\t\t}\n\n\t\tconst source = latest(state)\n\t\tif (!has(source, prop, state.type_)) {\n\t\t\t// non-existing or non-own property...\n\t\t\treturn readPropFromProto(state, source, prop)\n\t\t}\n\t\tconst value = source[prop]\n\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\treturn value\n\t\t}\n\n\t\t// During mutating array operations, defer proxy creation for array elements\n\t\t// This optimization avoids creating unnecessary proxies during sort/reverse\n\t\tif (\n\t\t\tisArrayWithStringProp &&\n\t\t\t(state as ProxyArrayState).operationMethod &&\n\t\t\tarrayPlugin?.isMutatingArrayMethod(\n\t\t\t\t(state as ProxyArrayState).operationMethod!\n\t\t\t) &&\n\t\t\tisArrayIndex(prop)\n\t\t) {\n\t\t\t// Return raw value during mutating operations, create proxy only if modified\n\t\t\treturn value\n\t\t}\n\t\t// Check for existing draft in modified state.\n\t\t// Assigned values are never drafted. This catches any drafts we created, too.\n\t\tif (value === peek(state.base_, prop)) {\n\t\t\tprepareCopy(state)\n\t\t\t// Ensure array keys are always numbers\n\t\t\tconst childKey = state.type_ === ArchType.Array ? +(prop as string) : prop\n\t\t\tconst childDraft = createProxy(state.scope_, value, state, childKey)\n\n\t\t\treturn (state.copy_![childKey] = childDraft)\n\t\t}\n\t\treturn value\n\t},\n\thas(state, prop) {\n\t\treturn prop in latest(state)\n\t},\n\townKeys(state) {\n\t\treturn Reflect.ownKeys(latest(state))\n\t},\n\tset(\n\t\tstate: ProxyObjectState,\n\t\tprop: string /* strictly not, but helps TS */,\n\t\tvalue\n\t) {\n\t\tconst desc = getDescriptorFromProto(latest(state), prop)\n\t\tif (desc?.set) {\n\t\t\t// special case: if this write is captured by a setter, we have\n\t\t\t// to trigger it with the correct context\n\t\t\tdesc.set.call(state.draft_, value)\n\t\t\treturn true\n\t\t}\n\t\tif (!state.modified_) {\n\t\t\t// the last check is because we need to be able to distinguish setting a non-existing to undefined (which is a change)\n\t\t\t// from setting an existing property with value undefined to undefined (which is not a change)\n\t\t\tconst current = peek(latest(state), prop)\n\t\t\t// special case, if we assigning the original value to a draft, we can ignore the assignment\n\t\t\tconst currentState: ProxyObjectState = current?.[DRAFT_STATE]\n\t\t\tif (currentState && currentState.base_ === value) {\n\t\t\t\tstate.copy_![prop] = value\n\t\t\t\tstate.assigned_!.set(prop, false)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tif (\n\t\t\t\tis(value, current) &&\n\t\t\t\t(value !== undefined || has(state.base_, prop, state.type_))\n\t\t\t)\n\t\t\t\treturn true\n\t\t\tprepareCopy(state)\n\t\t\tmarkChanged(state)\n\t\t}\n\n\t\tif (\n\t\t\t(state.copy_![prop] === value &&\n\t\t\t\t// special case: handle new props with value 'undefined'\n\t\t\t\t(value !== undefined || prop in state.copy_)) ||\n\t\t\t// special case: NaN\n\t\t\t(Number.isNaN(value) && Number.isNaN(state.copy_![prop]))\n\t\t)\n\t\t\treturn true\n\n\t\t// @ts-ignore\n\t\tstate.copy_![prop] = value\n\t\tstate.assigned_!.set(prop, true)\n\n\t\thandleCrossReference(state, prop, value)\n\t\treturn true\n\t},\n\tdeleteProperty(state, prop: string) {\n\t\tprepareCopy(state)\n\t\t// The `undefined` check is a fast path for pre-existing keys.\n\t\tif (peek(state.base_, prop) !== undefined || prop in state.base_) {\n\t\t\tstate.assigned_!.set(prop, false)\n\t\t\tmarkChanged(state)\n\t\t} else {\n\t\t\t// if an originally not assigned property was deleted\n\t\t\tstate.assigned_!.delete(prop)\n\t\t}\n\t\tif (state.copy_) {\n\t\t\tdelete state.copy_[prop]\n\t\t}\n\t\treturn true\n\t},\n\t// Note: We never coerce `desc.value` into an Immer draft, because we can't make\n\t// the same guarantee in ES5 mode.\n\tgetOwnPropertyDescriptor(state, prop) {\n\t\tconst owner = latest(state)\n\t\tconst desc = Reflect.getOwnPropertyDescriptor(owner, prop)\n\t\tif (!desc) return desc\n\t\treturn {\n\t\t\t[WRITABLE]: true,\n\t\t\t[CONFIGURABLE]: state.type_ !== ArchType.Array || prop !== \"length\",\n\t\t\t[ENUMERABLE]: desc[ENUMERABLE],\n\t\t\t[VALUE]: owner[prop]\n\t\t}\n\t},\n\tdefineProperty() {\n\t\tdie(11)\n\t},\n\tgetPrototypeOf(state) {\n\t\treturn getPrototypeOf(state.base_)\n\t},\n\tsetPrototypeOf() {\n\t\tdie(12)\n\t}\n}\n\n/**\n * Array drafts\n */\n\nconst arrayTraps: ProxyHandler<[ProxyArrayState]> = {}\neach(objectTraps, (key, fn) => {\n\t// @ts-ignore\n\tarrayTraps[key] = function() {\n\t\tconst args = arguments\n\t\targs[0] = args[0][0]\n\t\treturn fn.apply(this, args)\n\t}\n})\narrayTraps.deleteProperty = function(state, prop) {\n\tif (process.env.NODE_ENV !== \"production\" && isNaN(parseInt(prop as any)))\n\t\tdie(13)\n\t// @ts-ignore\n\treturn arrayTraps.set!.call(this, state, prop, undefined)\n}\narrayTraps.set = function(state, prop, value) {\n\tif (\n\t\tprocess.env.NODE_ENV !== \"production\" &&\n\t\tprop !== \"length\" &&\n\t\tisNaN(parseInt(prop as any))\n\t)\n\t\tdie(14)\n\treturn objectTraps.set!.call(this, state[0], prop, value, state[0])\n}\n\n// Access a property without creating an Immer draft.\nfunction peek(draft: Drafted, prop: PropertyKey) {\n\tconst state = draft[DRAFT_STATE]\n\tconst source = state ? latest(state) : draft\n\treturn source[prop]\n}\n\nfunction readPropFromProto(state: ImmerState, source: any, prop: PropertyKey) {\n\tconst desc = getDescriptorFromProto(source, prop)\n\treturn desc\n\t\t? VALUE in desc\n\t\t\t? desc[VALUE]\n\t\t\t: // This is a very special case, if the prop is a getter defined by the\n\t\t\t // prototype, we should invoke it with the draft as context!\n\t\t\t desc.get?.call(state.draft_)\n\t\t: undefined\n}\n\nfunction getDescriptorFromProto(\n\tsource: any,\n\tprop: PropertyKey\n): PropertyDescriptor | undefined {\n\t// 'in' checks proto!\n\tif (!(prop in source)) return undefined\n\tlet proto = getPrototypeOf(source)\n\twhile (proto) {\n\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop)\n\t\tif (desc) return desc\n\t\tproto = getPrototypeOf(proto)\n\t}\n\treturn undefined\n}\n\nexport function markChanged(state: ImmerState) {\n\tif (!state.modified_) {\n\t\tstate.modified_ = true\n\t\tif (state.parent_) {\n\t\t\tmarkChanged(state.parent_)\n\t\t}\n\t}\n}\n\nexport function prepareCopy(state: ImmerState) {\n\tif (!state.copy_) {\n\t\t// Actually create the `assigned_` map now that we\n\t\t// know this is a modified draft.\n\t\tstate.assigned_ = new Map()\n\t\tstate.copy_ = shallowCopy(\n\t\t\tstate.base_,\n\t\t\tstate.scope_.immer_.useStrictShallowCopy_\n\t\t)\n\t}\n}\n","import {\n\tIProduceWithPatches,\n\tIProduce,\n\tImmerState,\n\tDrafted,\n\tisDraftable,\n\tprocessResult,\n\tPatch,\n\tObjectish,\n\tDRAFT_STATE,\n\tDraft,\n\tPatchListener,\n\tisDraft,\n\tisMap,\n\tisSet,\n\tcreateProxyProxy,\n\tgetPlugin,\n\tdie,\n\tenterScope,\n\trevokeScope,\n\tleaveScope,\n\tusePatchesInScope,\n\tgetCurrentScope,\n\tNOTHING,\n\tfreeze,\n\tcurrent,\n\tImmerScope,\n\tregisterChildFinalizationCallback,\n\tArchType,\n\tMapSetPlugin,\n\tAnyMap,\n\tAnySet,\n\tisObjectish,\n\tisFunction,\n\tisBoolean,\n\tPluginMapSet,\n\tPluginPatches\n} from \"../internal\"\n\ninterface ProducersFns {\n\tproduce: IProduce\n\tproduceWithPatches: IProduceWithPatches\n}\n\nexport type StrictMode = boolean | \"class_only\"\n\nexport class Immer implements ProducersFns {\n\tautoFreeze_: boolean = true\n\tuseStrictShallowCopy_: StrictMode = false\n\tuseStrictIteration_: boolean = false\n\n\tconstructor(config?: {\n\t\tautoFreeze?: boolean\n\t\tuseStrictShallowCopy?: StrictMode\n\t\tuseStrictIteration?: boolean\n\t}) {\n\t\tif (isBoolean(config?.autoFreeze)) this.setAutoFreeze(config!.autoFreeze)\n\t\tif (isBoolean(config?.useStrictShallowCopy))\n\t\t\tthis.setUseStrictShallowCopy(config!.useStrictShallowCopy)\n\t\tif (isBoolean(config?.useStrictIteration))\n\t\t\tthis.setUseStrictIteration(config!.useStrictIteration)\n\t}\n\n\t/**\n\t * The `produce` function takes a value and a \"recipe function\" (whose\n\t * return value often depends on the base state). The recipe function is\n\t * free to mutate its first argument however it wants. All mutations are\n\t * only ever applied to a __copy__ of the base state.\n\t *\n\t * Pass only a function to create a \"curried producer\" which relieves you\n\t * from passing the recipe function every time.\n\t *\n\t * Only plain objects and arrays are made mutable. All other objects are\n\t * considered uncopyable.\n\t *\n\t * Note: This function is __bound__ to its `Immer` instance.\n\t *\n\t * @param {any} base - the initial state\n\t * @param {Function} recipe - function that receives a proxy of the base state as first argument and which can be freely modified\n\t * @param {Function} patchListener - optional function that will be called with all the patches produced here\n\t * @returns {any} a new state, or the initial state if nothing was modified\n\t */\n\tproduce: IProduce = (base: any, recipe?: any, patchListener?: any) => {\n\t\t// curried invocation\n\t\tif (isFunction(base) && !isFunction(recipe)) {\n\t\t\tconst defaultBase = recipe\n\t\t\trecipe = base\n\n\t\t\tconst self = this\n\t\t\treturn function curriedProduce(\n\t\t\t\tthis: any,\n\t\t\t\tbase = defaultBase,\n\t\t\t\t...args: any[]\n\t\t\t) {\n\t\t\t\treturn self.produce(base, (draft: Drafted) => recipe.call(this, draft, ...args)) // prettier-ignore\n\t\t\t}\n\t\t}\n\n\t\tif (!isFunction(recipe)) die(6)\n\t\tif (patchListener !== undefined && !isFunction(patchListener)) die(7)\n\n\t\tlet result\n\n\t\t// Only plain objects, arrays, and \"immerable classes\" are drafted.\n\t\tif (isDraftable(base)) {\n\t\t\tconst scope = enterScope(this)\n\t\t\tconst proxy = createProxy(scope, base, undefined)\n\t\t\tlet hasError = true\n\t\t\ttry {\n\t\t\t\tresult = recipe(proxy)\n\t\t\t\thasError = false\n\t\t\t} finally {\n\t\t\t\t// finally instead of catch + rethrow better preserves original stack\n\t\t\t\tif (hasError) revokeScope(scope)\n\t\t\t\telse leaveScope(scope)\n\t\t\t}\n\t\t\tusePatchesInScope(scope, patchListener)\n\t\t\treturn processResult(result, scope)\n\t\t} else if (!base || !isObjectish(base)) {\n\t\t\tresult = recipe(base)\n\t\t\tif (result === undefined) result = base\n\t\t\tif (result === NOTHING) result = undefined\n\t\t\tif (this.autoFreeze_) freeze(result, true)\n\t\t\tif (patchListener) {\n\t\t\t\tconst p: Patch[] = []\n\t\t\t\tconst ip: Patch[] = []\n\t\t\t\tgetPlugin(PluginPatches).generateReplacementPatches_(base, result, {\n\t\t\t\t\tpatches_: p,\n\t\t\t\t\tinversePatches_: ip\n\t\t\t\t} as ImmerScope) // dummy scope\n\t\t\t\tpatchListener(p, ip)\n\t\t\t}\n\t\t\treturn result\n\t\t} else die(1, base)\n\t}\n\n\tproduceWithPatches: IProduceWithPatches = (base: any, recipe?: any): any => {\n\t\t// curried invocation\n\t\tif (isFunction(base)) {\n\t\t\treturn (state: any, ...args: any[]) =>\n\t\t\t\tthis.produceWithPatches(state, (draft: any) => base(draft, ...args))\n\t\t}\n\n\t\tlet patches: Patch[], inversePatches: Patch[]\n\t\tconst result = this.produce(base, recipe, (p: Patch[], ip: Patch[]) => {\n\t\t\tpatches = p\n\t\t\tinversePatches = ip\n\t\t})\n\t\treturn [result, patches!, inversePatches!]\n\t}\n\n\tcreateDraft(base: T): Draft {\n\t\tif (!isDraftable(base)) die(8)\n\t\tif (isDraft(base)) base = current(base)\n\t\tconst scope = enterScope(this)\n\t\tconst proxy = createProxy(scope, base, undefined)\n\t\tproxy[DRAFT_STATE].isManual_ = true\n\t\tleaveScope(scope)\n\t\treturn proxy as any\n\t}\n\n\tfinishDraft>(\n\t\tdraft: D,\n\t\tpatchListener?: PatchListener\n\t): D extends Draft ? T : never {\n\t\tconst state: ImmerState = draft && (draft as any)[DRAFT_STATE]\n\t\tif (!state || !state.isManual_) die(9)\n\t\tconst {scope_: scope} = state\n\t\tusePatchesInScope(scope, patchListener)\n\t\treturn processResult(undefined, scope)\n\t}\n\n\t/**\n\t * Pass true to automatically freeze all copies created by Immer.\n\t *\n\t * By default, auto-freezing is enabled.\n\t */\n\tsetAutoFreeze(value: boolean) {\n\t\tthis.autoFreeze_ = value\n\t}\n\n\t/**\n\t * Pass true to enable strict shallow copy.\n\t *\n\t * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n\t */\n\tsetUseStrictShallowCopy(value: StrictMode) {\n\t\tthis.useStrictShallowCopy_ = value\n\t}\n\n\t/**\n\t * Pass false to use faster iteration that skips non-enumerable properties\n\t * but still handles symbols for compatibility.\n\t *\n\t * By default, strict iteration is enabled (includes all own properties).\n\t */\n\tsetUseStrictIteration(value: boolean) {\n\t\tthis.useStrictIteration_ = value\n\t}\n\n\tshouldUseStrictIteration(): boolean {\n\t\treturn this.useStrictIteration_\n\t}\n\n\tapplyPatches(base: T, patches: readonly Patch[]): T {\n\t\t// If a patch replaces the entire state, take that replacement as base\n\t\t// before applying patches\n\t\tlet i: number\n\t\tfor (i = patches.length - 1; i >= 0; i--) {\n\t\t\tconst patch = patches[i]\n\t\t\tif (patch.path.length === 0 && patch.op === \"replace\") {\n\t\t\t\tbase = patch.value\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\t// If there was a patch that replaced the entire state, start from the\n\t\t// patch after that.\n\t\tif (i > -1) {\n\t\t\tpatches = patches.slice(i + 1)\n\t\t}\n\n\t\tconst applyPatchesImpl = getPlugin(PluginPatches).applyPatches_\n\t\tif (isDraft(base)) {\n\t\t\t// N.B: never hits if some patch a replacement, patches are never drafts\n\t\t\treturn applyPatchesImpl(base, patches)\n\t\t}\n\t\t// Otherwise, produce a copy of the base state.\n\t\treturn this.produce(base, (draft: Drafted) =>\n\t\t\tapplyPatchesImpl(draft, patches)\n\t\t)\n\t}\n}\n\nexport function createProxy(\n\trootScope: ImmerScope,\n\tvalue: T,\n\tparent?: ImmerState,\n\tkey?: string | number | symbol\n): Drafted {\n\t// precondition: createProxy should be guarded by isDraftable, so we know we can safely draft\n\t// returning a tuple here lets us skip a proxy access\n\t// to DRAFT_STATE later\n\tconst [draft, state] = isMap(value)\n\t\t? getPlugin(PluginMapSet).proxyMap_(value, parent)\n\t\t: isSet(value)\n\t\t? getPlugin(PluginMapSet).proxySet_(value, parent)\n\t\t: createProxyProxy(value, parent)\n\n\tconst scope = parent?.scope_ ?? getCurrentScope()\n\tscope.drafts_.push(draft)\n\n\t// Ensure the parent callbacks are passed down so we actually\n\t// track all callbacks added throughout the tree\n\tstate.callbacks_ = parent?.callbacks_ ?? []\n\tstate.key_ = key\n\n\tif (parent && key !== undefined) {\n\t\tregisterChildFinalizationCallback(parent, state, key)\n\t} else {\n\t\t// It's a root draft, register it with the scope\n\t\tstate.callbacks_.push(function rootDraftCleanup(rootScope) {\n\t\t\trootScope.mapSetPlugin_?.fixSetContents(state)\n\n\t\t\tconst {patchPlugin_} = rootScope\n\n\t\t\tif (state.modified_ && patchPlugin_) {\n\t\t\t\tpatchPlugin_.generatePatches_(state, [], rootScope)\n\t\t\t}\n\t\t})\n\t}\n\n\treturn draft as any\n}\n","import {\n\tdie,\n\tisDraft,\n\tshallowCopy,\n\teach,\n\tDRAFT_STATE,\n\tset,\n\tImmerState,\n\tisDraftable,\n\tisFrozen\n} from \"../internal\"\n\n/** Takes a snapshot of the current state of a draft and finalizes it (but without freezing). This is a great utility to print the current state during debugging (no Proxies in the way). The output of current can also be safely leaked outside the producer. */\nexport function current(value: T): T\nexport function current(value: any): any {\n\tif (!isDraft(value)) die(10, value)\n\treturn currentImpl(value)\n}\n\nfunction currentImpl(value: any): any {\n\tif (!isDraftable(value) || isFrozen(value)) return value\n\tconst state: ImmerState | undefined = value[DRAFT_STATE]\n\tlet copy: any\n\tlet strict = true // Default to strict for compatibility\n\tif (state) {\n\t\tif (!state.modified_) return state.base_\n\t\t// Optimization: avoid generating new drafts during copying\n\t\tstate.finalized_ = true\n\t\tcopy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_)\n\t\tstrict = state.scope_.immer_.shouldUseStrictIteration()\n\t} else {\n\t\tcopy = shallowCopy(value, true)\n\t}\n\t// recurse\n\teach(\n\t\tcopy,\n\t\t(key, childValue) => {\n\t\t\tset(copy, key, currentImpl(childValue))\n\t\t},\n\t\tstrict\n\t)\n\tif (state) {\n\t\tstate.finalized_ = false\n\t}\n\treturn copy\n}\n","import {immerable} from \"../immer\"\nimport {\n\tImmerState,\n\tPatch,\n\tSetState,\n\tProxyArrayState,\n\tMapState,\n\tProxyObjectState,\n\tPatchPath,\n\tget,\n\teach,\n\thas,\n\tgetArchtype,\n\tgetPrototypeOf,\n\tisSet,\n\tisMap,\n\tloadPlugin,\n\tArchType,\n\tdie,\n\tisDraft,\n\tisDraftable,\n\tNOTHING,\n\terrors,\n\tDRAFT_STATE,\n\tgetProxyDraft,\n\tImmerScope,\n\tisObjectish,\n\tisFunction,\n\tCONSTRUCTOR,\n\tPluginPatches,\n\tisArray,\n\tPROTOTYPE\n} from \"../internal\"\n\nexport function enablePatches() {\n\tconst errorOffset = 16\n\tif (process.env.NODE_ENV !== \"production\") {\n\t\terrors.push(\n\t\t\t'Sets cannot have \"replace\" patches.',\n\t\t\tfunction(op: string) {\n\t\t\t\treturn \"Unsupported patch operation: \" + op\n\t\t\t},\n\t\t\tfunction(path: string) {\n\t\t\t\treturn \"Cannot apply patch, path doesn't resolve: \" + path\n\t\t\t},\n\t\t\t\"Patching reserved attributes like __proto__, prototype and constructor is not allowed\"\n\t\t)\n\t}\n\n\tfunction getPath(state: ImmerState, path: PatchPath = []): PatchPath | null {\n\t\t// Step 1: Check if state has a stored key\n\t\tif (\"key_\" in state && state.key_ !== undefined) {\n\t\t\t// Step 2: Validate the key is still valid in parent\n\n\t\t\tconst parentCopy = state.parent_!.copy_ ?? state.parent_!.base_\n\t\t\tconst proxyDraft = getProxyDraft(get(parentCopy, state.key_!))\n\t\t\tconst valueAtKey = get(parentCopy, state.key_!)\n\n\t\t\tif (valueAtKey === undefined) {\n\t\t\t\treturn null\n\t\t\t}\n\n\t\t\t// Check if the value at the key is still related to this draft\n\t\t\t// It should be either the draft itself, the base, or the copy\n\t\t\tif (\n\t\t\t\tvalueAtKey !== state.draft_ &&\n\t\t\t\tvalueAtKey !== state.base_ &&\n\t\t\t\tvalueAtKey !== state.copy_\n\t\t\t) {\n\t\t\t\treturn null // Value was replaced with something else\n\t\t\t}\n\t\t\tif (proxyDraft != null && proxyDraft.base_ !== state.base_) {\n\t\t\t\treturn null // Different draft\n\t\t\t}\n\n\t\t\t// Step 3: Handle Set case specially\n\t\t\tconst isSet = state.parent_!.type_ === ArchType.Set\n\t\t\tlet key: string | number\n\n\t\t\tif (isSet) {\n\t\t\t\t// For Sets, find the index in the drafts_ map\n\t\t\t\tconst setParent = state.parent_ as SetState\n\t\t\t\tkey = Array.from(setParent.drafts_.keys()).indexOf(state.key_)\n\t\t\t} else {\n\t\t\t\tkey = state.key_ as string | number\n\t\t\t}\n\n\t\t\t// Step 4: Validate key still exists in parent\n\t\t\tif (!((isSet && parentCopy.size > key) || has(parentCopy, key))) {\n\t\t\t\treturn null // Key deleted\n\t\t\t}\n\n\t\t\t// Step 5: Add key to path\n\t\t\tpath.push(key)\n\t\t}\n\n\t\t// Step 6: Recurse to parent if exists\n\t\tif (state.parent_) {\n\t\t\treturn getPath(state.parent_, path)\n\t\t}\n\n\t\t// Step 7: At root - reverse path and validate\n\t\tpath.reverse()\n\n\t\ttry {\n\t\t\t// Validate path can be resolved from ROOT\n\t\t\tresolvePath(state.copy_, path)\n\t\t} catch (e) {\n\t\t\treturn null // Path invalid\n\t\t}\n\n\t\treturn path\n\t}\n\n\t// NEW: Add resolvePath helper function\n\tfunction resolvePath(base: any, path: PatchPath): any {\n\t\tlet current = base\n\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\tconst key = path[i]\n\t\t\tcurrent = get(current, key)\n\t\t\tif (!isObjectish(current) || current === null) {\n\t\t\t\tthrow new Error(`Cannot resolve path at '${path.join(\"/\")}'`)\n\t\t\t}\n\t\t}\n\t\treturn current\n\t}\n\n\tconst REPLACE = \"replace\"\n\tconst ADD = \"add\"\n\tconst REMOVE = \"remove\"\n\n\tfunction generatePatches_(\n\t\tstate: ImmerState,\n\t\tbasePath: PatchPath,\n\t\tscope: ImmerScope\n\t): void {\n\t\tif (state.scope_.processedForPatches_.has(state)) {\n\t\t\treturn\n\t\t}\n\n\t\tstate.scope_.processedForPatches_.add(state)\n\n\t\tconst {patches_, inversePatches_} = scope\n\n\t\tswitch (state.type_) {\n\t\t\tcase ArchType.Object:\n\t\t\tcase ArchType.Map:\n\t\t\t\treturn generatePatchesFromAssigned(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Array:\n\t\t\t\treturn generateArrayPatches(\n\t\t\t\t\tstate,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t\tcase ArchType.Set:\n\t\t\t\treturn generateSetPatches(\n\t\t\t\t\t(state as any) as SetState,\n\t\t\t\t\tbasePath,\n\t\t\t\t\tpatches_!,\n\t\t\t\t\tinversePatches_!\n\t\t\t\t)\n\t\t}\n\t}\n\n\tfunction generateArrayPatches(\n\t\tstate: ProxyArrayState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, assigned_} = state\n\t\tlet copy_ = state.copy_!\n\n\t\t// Reduce complexity by ensuring `base` is never longer.\n\t\tif (copy_.length < base_.length) {\n\t\t\t// @ts-ignore\n\t\t\t;[base_, copy_] = [copy_, base_]\n\t\t\t;[patches, inversePatches] = [inversePatches, patches]\n\t\t}\n\n\t\tconst allReassigned = state.allIndicesReassigned_ === true\n\n\t\t// Process replaced indices.\n\t\tfor (let i = 0; i < base_.length; i++) {\n\t\t\tconst copiedItem = copy_[i]\n\t\t\tconst baseItem = base_[i]\n\n\t\t\tconst isAssigned = allReassigned || assigned_?.get(i.toString())\n\t\t\tif (isAssigned && copiedItem !== baseItem) {\n\t\t\t\tconst childState = copiedItem?.[DRAFT_STATE]\n\t\t\t\tif (childState && childState.modified_) {\n\t\t\t\t\t// Skip - let the child generate its own patches\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(copiedItem)\n\t\t\t\t})\n\t\t\t\tinversePatches.push({\n\t\t\t\t\top: REPLACE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue: clonePatchValueIfNeeded(baseItem)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\t// Process added indices.\n\t\tfor (let i = base_.length; i < copy_.length; i++) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tpatches.push({\n\t\t\t\top: ADD,\n\t\t\t\tpath,\n\t\t\t\t// Need to maybe clone it, as it can in fact be the original value\n\t\t\t\t// due to the base/copy inversion at the start of this function\n\t\t\t\tvalue: clonePatchValueIfNeeded(copy_[i])\n\t\t\t})\n\t\t}\n\t\tfor (let i = copy_.length - 1; base_.length <= i; --i) {\n\t\t\tconst path = basePath.concat([i])\n\t\t\tinversePatches.push({\n\t\t\t\top: REMOVE,\n\t\t\t\tpath\n\t\t\t})\n\t\t}\n\t}\n\n\t// This is used for both Map objects and normal objects.\n\tfunction generatePatchesFromAssigned(\n\t\tstate: MapState | ProxyObjectState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tconst {base_, copy_, type_} = state\n\t\teach(state.assigned_!, (key, assignedValue) => {\n\t\t\tconst origValue = get(base_, key, type_)\n\t\t\tconst value = get(copy_!, key, type_)\n\t\t\tconst op = !assignedValue ? REMOVE : has(base_, key) ? REPLACE : ADD\n\t\t\tif (origValue === value && op === REPLACE) return\n\t\t\tconst path = basePath.concat(key as any)\n\t\t\tpatches.push(\n\t\t\t\top === REMOVE\n\t\t\t\t\t? {op, path}\n\t\t\t\t\t: {op, path, value: clonePatchValueIfNeeded(value)}\n\t\t\t)\n\t\t\tinversePatches.push(\n\t\t\t\top === ADD\n\t\t\t\t\t? {op: REMOVE, path}\n\t\t\t\t\t: op === REMOVE\n\t\t\t\t\t? {op: ADD, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t\t\t: {op: REPLACE, path, value: clonePatchValueIfNeeded(origValue)}\n\t\t\t)\n\t\t})\n\t}\n\n\tfunction generateSetPatches(\n\t\tstate: SetState,\n\t\tbasePath: PatchPath,\n\t\tpatches: Patch[],\n\t\tinversePatches: Patch[]\n\t) {\n\t\tlet {base_, copy_} = state\n\n\t\tlet i = 0\n\t\tbase_.forEach((value: any) => {\n\t\t\tif (!copy_!.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t\ti = 0\n\t\tcopy_!.forEach((value: any) => {\n\t\t\tif (!base_.has(value)) {\n\t\t\t\tconst path = basePath.concat([i])\n\t\t\t\tpatches.push({\n\t\t\t\t\top: ADD,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t\tinversePatches.unshift({\n\t\t\t\t\top: REMOVE,\n\t\t\t\t\tpath,\n\t\t\t\t\tvalue\n\t\t\t\t})\n\t\t\t}\n\t\t\ti++\n\t\t})\n\t}\n\n\tfunction generateReplacementPatches_(\n\t\tbaseValue: any,\n\t\treplacement: any,\n\t\tscope: ImmerScope\n\t): void {\n\t\tconst {patches_, inversePatches_} = scope\n\t\tpatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: replacement === NOTHING ? undefined : replacement\n\t\t})\n\t\tinversePatches_!.push({\n\t\t\top: REPLACE,\n\t\t\tpath: [],\n\t\t\tvalue: baseValue\n\t\t})\n\t}\n\n\tfunction applyPatches_(draft: T, patches: readonly Patch[]): T {\n\t\tpatches.forEach(patch => {\n\t\t\tconst {path, op} = patch\n\n\t\t\tlet base: any = draft\n\t\t\tfor (let i = 0; i < path.length - 1; i++) {\n\t\t\t\tconst parentType = getArchtype(base)\n\t\t\t\tlet p = path[i]\n\t\t\t\tif (typeof p !== \"string\" && typeof p !== \"number\") {\n\t\t\t\t\tp = \"\" + p\n\t\t\t\t}\n\n\t\t\t\t// See #738, avoid prototype pollution\n\t\t\t\tif (\n\t\t\t\t\t(parentType === ArchType.Object || parentType === ArchType.Array) &&\n\t\t\t\t\t(p === \"__proto__\" || p === CONSTRUCTOR)\n\t\t\t\t)\n\t\t\t\t\tdie(errorOffset + 3)\n\t\t\t\tif (isFunction(base) && p === PROTOTYPE) die(errorOffset + 3)\n\t\t\t\tbase = get(base, p)\n\t\t\t\tif (!isObjectish(base)) die(errorOffset + 2, path.join(\"/\"))\n\t\t\t}\n\n\t\t\tconst type = getArchtype(base)\n\t\t\tconst value = deepClonePatchValue(patch.value) // used to clone patch to ensure original patch is not modified, see #411\n\t\t\tconst key = path[path.length - 1]\n\t\t\tswitch (op) {\n\t\t\t\tcase REPLACE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\tdie(errorOffset)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\t// if value is an object, then it's assigned by reference\n\t\t\t\t\t\t\t// in the following add or remove ops, the value field inside the patch will also be modifyed\n\t\t\t\t\t\t\t// so we use value from the cloned patch\n\t\t\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase ADD:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn key === \"-\"\n\t\t\t\t\t\t\t\t? base.push(value)\n\t\t\t\t\t\t\t\t: base.splice(key as any, 0, value)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.set(key, value)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.add(value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn (base[key] = value)\n\t\t\t\t\t}\n\t\t\t\tcase REMOVE:\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase ArchType.Array:\n\t\t\t\t\t\t\treturn base.splice(key as any, 1)\n\t\t\t\t\t\tcase ArchType.Map:\n\t\t\t\t\t\t\treturn base.delete(key)\n\t\t\t\t\t\tcase ArchType.Set:\n\t\t\t\t\t\t\treturn base.delete(patch.value)\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\treturn delete base[key]\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tdie(errorOffset + 1, op)\n\t\t\t}\n\t\t})\n\n\t\treturn draft\n\t}\n\n\t// optimize: this is quite a performance hit, can we detect intelligently when it is needed?\n\t// E.g. auto-draft when new objects from outside are assigned and modified?\n\t// (See failing test when deepClone just returns obj)\n\tfunction deepClonePatchValue(obj: T): T\n\tfunction deepClonePatchValue(obj: any) {\n\t\tif (!isDraftable(obj)) return obj\n\t\tif (isArray(obj)) return obj.map(deepClonePatchValue)\n\t\tif (isMap(obj))\n\t\t\treturn new Map(\n\t\t\t\tArray.from(obj.entries()).map(([k, v]) => [k, deepClonePatchValue(v)])\n\t\t\t)\n\t\tif (isSet(obj)) return new Set(Array.from(obj).map(deepClonePatchValue))\n\t\tconst cloned = Object.create(getPrototypeOf(obj))\n\t\tfor (const key in obj) cloned[key] = deepClonePatchValue(obj[key])\n\t\tif (has(obj, immerable)) cloned[immerable] = obj[immerable]\n\t\treturn cloned\n\t}\n\n\tfunction clonePatchValueIfNeeded(obj: T): T {\n\t\tif (isDraft(obj)) {\n\t\t\treturn deepClonePatchValue(obj)\n\t\t} else return obj\n\t}\n\n\tloadPlugin(PluginPatches, {\n\t\tapplyPatches_,\n\t\tgeneratePatches_,\n\t\tgenerateReplacementPatches_,\n\t\tgetPath\n\t})\n}\n","// types only!\nimport {\n\tImmerState,\n\tAnyMap,\n\tAnySet,\n\tMapState,\n\tSetState,\n\tDRAFT_STATE,\n\tgetCurrentScope,\n\tlatest,\n\tisDraftable,\n\tcreateProxy,\n\tloadPlugin,\n\tmarkChanged,\n\tdie,\n\tArchType,\n\teach,\n\tgetValue,\n\tPluginMapSet\n} from \"../internal\"\n\nexport function enableMapSet() {\n\tclass DraftMap extends Map {\n\t\t[DRAFT_STATE]: MapState\n\n\t\tconstructor(target: AnyMap, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Map,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this as any,\n\t\t\t\tisManual_: false,\n\t\t\t\trevoked_: false,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(key: any): boolean {\n\t\t\treturn latest(this[DRAFT_STATE]).has(key)\n\t\t}\n\n\t\tset(key: any, value: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!latest(state).has(key) || latest(state).get(key) !== value) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t\tstate.copy_!.set(key, value)\n\t\t\t\tstate.assigned_!.set(key, true)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(key: any): boolean {\n\t\t\tif (!this.has(key)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareMapCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\tif (state.base_.has(key)) {\n\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t} else {\n\t\t\t\tstate.assigned_!.delete(key)\n\t\t\t}\n\t\t\tstate.copy_!.delete(key)\n\t\t\treturn true\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareMapCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.assigned_ = new Map()\n\t\t\t\teach(state.base_, key => {\n\t\t\t\t\tstate.assigned_!.set(key, false)\n\t\t\t\t})\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tforEach(cb: (value: any, key: any, self: any) => void, thisArg?: any) {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tlatest(state).forEach((_value: any, key: any, _map: any) => {\n\t\t\t\tcb.call(thisArg, this.get(key), key, this)\n\t\t\t})\n\t\t}\n\n\t\tget(key: any): any {\n\t\t\tconst state: MapState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tconst value = latest(state).get(key)\n\t\t\tif (state.finalized_ || !isDraftable(value)) {\n\t\t\t\treturn value\n\t\t\t}\n\t\t\tif (value !== state.base_.get(key)) {\n\t\t\t\treturn value // either already drafted or reassigned\n\t\t\t}\n\t\t\t// despite what it looks, this creates a draft only once, see above condition\n\t\t\tconst draft = createProxy(state.scope_, value, state, key)\n\t\t\tprepareMapCopy(state)\n\t\t\tstate.copy_!.set(key, draft)\n\t\t\treturn draft\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn latest(this[DRAFT_STATE]).keys()\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.values(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst iterator = this.keys()\n\t\t\treturn {\n\t\t\t\t[Symbol.iterator]: () => this.entries(),\n\t\t\t\tnext: () => {\n\t\t\t\t\tconst r = iterator.next()\n\t\t\t\t\t/* istanbul ignore next */\n\t\t\t\t\tif (r.done) return r\n\t\t\t\t\tconst value = this.get(r.value)\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdone: false,\n\t\t\t\t\t\tvalue: [r.value, value]\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} as any\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.entries()\n\t\t}\n\t}\n\n\tfunction proxyMap_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, MapState] {\n\t\t// @ts-ignore\n\t\tconst map = new DraftMap(target, parent)\n\t\treturn [map as any, map[DRAFT_STATE]]\n\t}\n\n\tfunction prepareMapCopy(state: MapState) {\n\t\tif (!state.copy_) {\n\t\t\tstate.assigned_ = new Map()\n\t\t\tstate.copy_ = new Map(state.base_)\n\t\t}\n\t}\n\n\tclass DraftSet extends Set {\n\t\t[DRAFT_STATE]: SetState\n\t\tconstructor(target: AnySet, parent?: ImmerState) {\n\t\t\tsuper()\n\t\t\tthis[DRAFT_STATE] = {\n\t\t\t\ttype_: ArchType.Set,\n\t\t\t\tparent_: parent,\n\t\t\t\tscope_: parent ? parent.scope_ : getCurrentScope()!,\n\t\t\t\tmodified_: false,\n\t\t\t\tfinalized_: false,\n\t\t\t\tcopy_: undefined,\n\t\t\t\tbase_: target,\n\t\t\t\tdraft_: this,\n\t\t\t\tdrafts_: new Map(),\n\t\t\t\trevoked_: false,\n\t\t\t\tisManual_: false,\n\t\t\t\tassigned_: undefined,\n\t\t\t\tcallbacks_: []\n\t\t\t}\n\t\t}\n\n\t\tget size(): number {\n\t\t\treturn latest(this[DRAFT_STATE]).size\n\t\t}\n\n\t\thas(value: any): boolean {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\t// bit of trickery here, to be able to recognize both the value, and the draft of its value\n\t\t\tif (!state.copy_) {\n\t\t\t\treturn state.base_.has(value)\n\t\t\t}\n\t\t\tif (state.copy_.has(value)) return true\n\t\t\tif (state.drafts_.has(value) && state.copy_.has(state.drafts_.get(value)))\n\t\t\t\treturn true\n\t\t\treturn false\n\t\t}\n\n\t\tadd(value: any): any {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (!this.has(value)) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.add(value)\n\t\t\t}\n\t\t\treturn this\n\t\t}\n\n\t\tdelete(value: any): any {\n\t\t\tif (!this.has(value)) {\n\t\t\t\treturn false\n\t\t\t}\n\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\tmarkChanged(state)\n\t\t\treturn (\n\t\t\t\tstate.copy_!.delete(value) ||\n\t\t\t\t(state.drafts_.has(value)\n\t\t\t\t\t? state.copy_!.delete(state.drafts_.get(value))\n\t\t\t\t\t: /* istanbul ignore next */ false)\n\t\t\t)\n\t\t}\n\n\t\tclear() {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tif (latest(state).size) {\n\t\t\t\tprepareSetCopy(state)\n\t\t\t\tmarkChanged(state)\n\t\t\t\tstate.copy_!.clear()\n\t\t\t}\n\t\t}\n\n\t\tvalues(): IterableIterator {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.values()\n\t\t}\n\n\t\tentries(): IterableIterator<[any, any]> {\n\t\t\tconst state: SetState = this[DRAFT_STATE]\n\t\t\tassertUnrevoked(state)\n\t\t\tprepareSetCopy(state)\n\t\t\treturn state.copy_!.entries()\n\t\t}\n\n\t\tkeys(): IterableIterator {\n\t\t\treturn this.values()\n\t\t}\n\n\t\t[Symbol.iterator]() {\n\t\t\treturn this.values()\n\t\t}\n\n\t\tforEach(cb: any, thisArg?: any) {\n\t\t\tconst iterator = this.values()\n\t\t\tlet result = iterator.next()\n\t\t\twhile (!result.done) {\n\t\t\t\tcb.call(thisArg, result.value, result.value, this)\n\t\t\t\tresult = iterator.next()\n\t\t\t}\n\t\t}\n\t}\n\tfunction proxySet_(\n\t\ttarget: T,\n\t\tparent?: ImmerState\n\t): [T, SetState] {\n\t\t// @ts-ignore\n\t\tconst set = new DraftSet(target, parent)\n\t\treturn [set as any, set[DRAFT_STATE]]\n\t}\n\n\tfunction prepareSetCopy(state: SetState) {\n\t\tif (!state.copy_) {\n\t\t\t// create drafts for all entries to preserve insertion order\n\t\t\tstate.copy_ = new Set()\n\t\t\tstate.base_.forEach(value => {\n\t\t\t\tif (isDraftable(value)) {\n\t\t\t\t\tconst draft = createProxy(state.scope_, value, state, value)\n\t\t\t\t\tstate.drafts_.set(value, draft)\n\t\t\t\t\tstate.copy_!.add(draft)\n\t\t\t\t} else {\n\t\t\t\t\tstate.copy_!.add(value)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t}\n\n\tfunction assertUnrevoked(state: any /*ES5State | MapState | SetState*/) {\n\t\tif (state.revoked_) die(3, JSON.stringify(latest(state)))\n\t}\n\n\tfunction fixSetContents(target: ImmerState) {\n\t\t// For sets we clone before iterating, otherwise we can get in endless loop due to modifying during iteration, see #628\n\t\t// To preserve insertion order in all cases we then clear the set\n\t\tif (target.type_ === ArchType.Set && target.copy_) {\n\t\t\tconst copy = new Set(target.copy_)\n\t\t\ttarget.copy_.clear()\n\t\t\tcopy.forEach(value => {\n\t\t\t\ttarget.copy_!.add(getValue(value))\n\t\t\t})\n\t\t}\n\t}\n\n\tloadPlugin(PluginMapSet, {proxyMap_, proxySet_, fixSetContents})\n}\n","import {\n\tPluginArrayMethods,\n\tlatest,\n\tloadPlugin,\n\tmarkChanged,\n\tprepareCopy,\n\tProxyArrayState\n} from \"../internal\"\n\n/**\n * Methods that directly modify the array in place.\n * These operate on the copy without creating per-element proxies:\n * - `push`, `pop`: Add/remove from end\n * - `shift`, `unshift`: Add/remove from start (marks all indices reassigned)\n * - `splice`: Add/remove at arbitrary position (marks all indices reassigned)\n * - `reverse`, `sort`: Reorder elements (marks all indices reassigned)\n */\ntype MutatingArrayMethod =\n\t| \"push\"\n\t| \"pop\"\n\t| \"shift\"\n\t| \"unshift\"\n\t| \"splice\"\n\t| \"reverse\"\n\t| \"sort\"\n\n/**\n * Methods that read from the array without modifying it.\n * These fall into distinct categories based on return semantics:\n *\n * **Subset operations** (return drafts - mutations propagate):\n * - `filter`, `slice`: Return array of draft proxies\n * - `find`, `findLast`: Return single draft proxy or undefined\n *\n * **Transform operations** (return base values - mutations don't track):\n * - `concat`, `flat`: Create new structures, not subsets of original\n *\n * **Primitive-returning** (no draft needed):\n * - `findIndex`, `findLastIndex`, `indexOf`, `lastIndexOf`: Return numbers\n * - `some`, `every`, `includes`: Return booleans\n * - `join`, `toString`, `toLocaleString`: Return strings\n */\ntype NonMutatingArrayMethod =\n\t| \"filter\"\n\t| \"slice\"\n\t| \"concat\"\n\t| \"flat\"\n\t| \"find\"\n\t| \"findIndex\"\n\t| \"findLast\"\n\t| \"findLastIndex\"\n\t| \"some\"\n\t| \"every\"\n\t| \"indexOf\"\n\t| \"lastIndexOf\"\n\t| \"includes\"\n\t| \"join\"\n\t| \"toString\"\n\t| \"toLocaleString\"\n\n/** Union of all array operation methods handled by the plugin. */\nexport type ArrayOperationMethod = MutatingArrayMethod | NonMutatingArrayMethod\n\n/**\n * Enables optimized array method handling for Immer drafts.\n *\n * This plugin overrides array methods to avoid unnecessary Proxy creation during iteration,\n * significantly improving performance for array-heavy operations.\n *\n * **Mutating methods** (push, pop, shift, unshift, splice, sort, reverse):\n * Operate directly on the copy without creating per-element proxies.\n *\n * **Non-mutating methods** fall into categories:\n * - **Subset operations** (filter, slice, find, findLast): Return draft proxies - mutations track\n * - **Transform operations** (concat, flat): Return base values - mutations don't track\n * - **Primitive-returning** (indexOf, includes, some, every, etc.): Return primitives\n *\n * **Important**: Callbacks for overridden methods receive base values, not drafts.\n * This is the core performance optimization.\n *\n * @example\n * ```ts\n * import { enableArrayMethods, produce } from \"immer\"\n *\n * enableArrayMethods()\n *\n * const next = produce(state, draft => {\n * // Optimized - no proxy creation per element\n * draft.items.sort((a, b) => a.value - b.value)\n *\n * // filter returns drafts - mutations propagate\n * const filtered = draft.items.filter(x => x.value > 5)\n * filtered[0].value = 999 // Affects draft.items[originalIndex]\n * })\n * ```\n *\n * @see https://immerjs.github.io/immer/array-methods\n */\nexport function enableArrayMethods() {\n\tconst SHIFTING_METHODS = new Set([\"shift\", \"unshift\"])\n\n\tconst QUEUE_METHODS = new Set([\"push\", \"pop\"])\n\n\tconst RESULT_RETURNING_METHODS = new Set([\n\t\t...QUEUE_METHODS,\n\t\t...SHIFTING_METHODS\n\t])\n\n\tconst REORDERING_METHODS = new Set([\"reverse\", \"sort\"])\n\n\t// Optimized method detection using array-based lookup\n\tconst MUTATING_METHODS = new Set([\n\t\t...RESULT_RETURNING_METHODS,\n\t\t...REORDERING_METHODS,\n\t\t\"splice\"\n\t])\n\n\tconst FIND_METHODS = new Set([\"find\", \"findLast\"])\n\n\tconst NON_MUTATING_METHODS = new Set([\n\t\t\"filter\",\n\t\t\"slice\",\n\t\t\"concat\",\n\t\t\"flat\",\n\t\t...FIND_METHODS,\n\t\t\"findIndex\",\n\t\t\"findLastIndex\",\n\t\t\"some\",\n\t\t\"every\",\n\t\t\"indexOf\",\n\t\t\"lastIndexOf\",\n\t\t\"includes\",\n\t\t\"join\",\n\t\t\"toString\",\n\t\t\"toLocaleString\"\n\t])\n\n\t// Type guard for method detection\n\tfunction isMutatingArrayMethod(\n\t\tmethod: string\n\t): method is MutatingArrayMethod {\n\t\treturn MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isNonMutatingArrayMethod(\n\t\tmethod: string\n\t): method is NonMutatingArrayMethod {\n\t\treturn NON_MUTATING_METHODS.has(method as any)\n\t}\n\n\tfunction isArrayOperationMethod(\n\t\tmethod: string\n\t): method is ArrayOperationMethod {\n\t\treturn isMutatingArrayMethod(method) || isNonMutatingArrayMethod(method)\n\t}\n\n\tfunction enterOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: ArrayOperationMethod\n\t) {\n\t\tstate.operationMethod = method\n\t}\n\n\tfunction exitOperation(state: ProxyArrayState) {\n\t\tstate.operationMethod = undefined\n\t}\n\n\t// Shared utility functions for array method handlers\n\tfunction executeArrayMethod(\n\t\tstate: ProxyArrayState,\n\t\toperation: () => T,\n\t\tmarkLength = true\n\t): T {\n\t\tprepareCopy(state)\n\t\tconst result = operation()\n\t\tmarkChanged(state)\n\t\tif (markLength) state.assigned_!.set(\"length\", true)\n\t\treturn result\n\t}\n\n\tfunction markAllIndicesReassigned(state: ProxyArrayState) {\n\t\tstate.allIndicesReassigned_ = true\n\t}\n\n\tfunction normalizeSliceIndex(index: number, length: number): number {\n\t\tif (index < 0) {\n\t\t\treturn Math.max(length + index, 0)\n\t\t}\n\t\treturn Math.min(index, length)\n\t}\n\n\t/**\n\t * Handles mutating operations that add/remove elements (push, pop, shift, unshift, splice).\n\t *\n\t * Operates directly on `state.copy_` without creating per-element proxies.\n\t * For shifting methods (shift, unshift), marks all indices as reassigned since\n\t * indices shift.\n\t *\n\t * @returns For push/pop/shift/unshift: the native method result. For others: the draft.\n\t */\n\tfunction handleSimpleOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(state, () => {\n\t\t\tconst result = (state.copy_! as any)[method](...args)\n\n\t\t\t// Handle index reassignment for shifting methods\n\t\t\tif (SHIFTING_METHODS.has(method as MutatingArrayMethod)) {\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t}\n\n\t\t\t// Return appropriate value based on method\n\t\t\treturn RESULT_RETURNING_METHODS.has(method as MutatingArrayMethod)\n\t\t\t\t? result\n\t\t\t\t: state.draft_\n\t\t})\n\t}\n\n\t/**\n\t * Handles reordering operations (reverse, sort) that change element order.\n\t *\n\t * Operates directly on `state.copy_` and marks all indices as reassigned\n\t * since element positions change. Does not mark length as changed since\n\t * these operations preserve array length.\n\t *\n\t * @returns The draft proxy for method chaining.\n\t */\n\tfunction handleReorderingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: string,\n\t\targs: any[]\n\t) {\n\t\treturn executeArrayMethod(\n\t\t\tstate,\n\t\t\t() => {\n\t\t\t\t;(state.copy_! as any)[method](...args)\n\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\treturn state.draft_\n\t\t\t},\n\t\t\tfalse\n\t\t) // Don't mark length as changed\n\t}\n\n\t/**\n\t * Creates an interceptor function for a specific array method.\n\t *\n\t * The interceptor wraps array method calls to:\n\t * 1. Set `state.operationMethod` flag during execution (allows proxy `get` trap\n\t * to detect we're inside an optimized method and skip proxy creation)\n\t * 2. Route to appropriate handler based on method type\n\t * 3. Clean up the operation flag in `finally` block\n\t *\n\t * The `operationMethod` flag is the key mechanism that enables the proxy's `get`\n\t * trap to return base values instead of creating nested proxies during iteration.\n\t *\n\t * @param state - The proxy array state\n\t * @param originalMethod - Name of the array method being intercepted\n\t * @returns Interceptor function that handles the method call\n\t */\n\tfunction createMethodInterceptor(\n\t\tstate: ProxyArrayState,\n\t\toriginalMethod: string\n\t) {\n\t\treturn function interceptedMethod(...args: any[]) {\n\t\t\t// Enter operation mode - this flag tells the proxy's get trap to return\n\t\t\t// base values instead of creating nested proxies during iteration\n\t\t\tconst method = originalMethod as ArrayOperationMethod\n\t\t\tenterOperation(state, method)\n\n\t\t\ttry {\n\t\t\t\t// Check if this is a mutating method\n\t\t\t\tif (isMutatingArrayMethod(method)) {\n\t\t\t\t\t// Direct method dispatch - no configuration lookup needed\n\t\t\t\t\tif (RESULT_RETURNING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleSimpleOperation(state, method, args)\n\t\t\t\t\t}\n\t\t\t\t\tif (REORDERING_METHODS.has(method)) {\n\t\t\t\t\t\treturn handleReorderingOperation(state, method, args)\n\t\t\t\t\t}\n\n\t\t\t\t\tif (method === \"splice\") {\n\t\t\t\t\t\tconst res = executeArrayMethod(state, () =>\n\t\t\t\t\t\t\tstate.copy_!.splice(...(args as [number, number, ...any[]]))\n\t\t\t\t\t\t)\n\t\t\t\t\t\tmarkAllIndicesReassigned(state)\n\t\t\t\t\t\treturn res\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Handle non-mutating methods\n\t\t\t\t\treturn handleNonMutatingOperation(state, method, args)\n\t\t\t\t}\n\t\t\t} finally {\n\t\t\t\t// Always exit operation mode - must be in finally to handle exceptions\n\t\t\t\texitOperation(state)\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Handles non-mutating array methods with different return semantics.\n\t *\n\t * **Subset operations** return draft proxies for mutation tracking:\n\t * - `filter`, `slice`: Return `state.draft_[i]` for each selected element\n\t * - `find`, `findLast`: Return `state.draft_[i]` for the found element\n\t *\n\t * This allows mutations on returned elements to propagate back to the draft:\n\t * ```ts\n\t * const filtered = draft.items.filter(x => x.value > 5)\n\t * filtered[0].value = 999 // Mutates draft.items[originalIndex]\n\t * ```\n\t *\n\t * **Transform operations** return base values (no draft tracking):\n\t * - `concat`, `flat`: These create NEW arrays rather than selecting subsets.\n\t * Since the result structure differs from the original, tracking mutations\n\t * back to specific draft indices would be impractical/impossible.\n\t *\n\t * **Primitive operations** return the native result directly:\n\t * - `indexOf`, `includes`, `some`, `every`, `join`, etc.\n\t *\n\t * @param state - The proxy array state\n\t * @param method - The non-mutating method name\n\t * @param args - Arguments passed to the method\n\t * @returns Drafts for subset operations, base values for transforms, primitives otherwise\n\t */\n\tfunction handleNonMutatingOperation(\n\t\tstate: ProxyArrayState,\n\t\tmethod: NonMutatingArrayMethod,\n\t\targs: any[]\n\t) {\n\t\tconst source = latest(state)\n\n\t\t// Methods that return arrays with selected items - need to return drafts\n\t\tif (method === \"filter\") {\n\t\t\tconst predicate = args[0]\n\t\t\tconst result: any[] = []\n\n\t\t\t// First pass: call predicate on base values to determine which items pass\n\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\t// Only create draft for items that passed the predicate\n\t\t\t\t\tresult.push(state.draft_[i])\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\tif (FIND_METHODS.has(method)) {\n\t\t\tconst predicate = args[0]\n\t\t\tconst isForward = method === \"find\"\n\t\t\tconst step = isForward ? 1 : -1\n\t\t\tconst start = isForward ? 0 : source.length - 1\n\n\t\t\tfor (let i = start; i >= 0 && i < source.length; i += step) {\n\t\t\t\tif (predicate(source[i], i, source)) {\n\t\t\t\t\treturn state.draft_[i]\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn undefined\n\t\t}\n\n\t\tif (method === \"slice\") {\n\t\t\tconst rawStart = args[0] ?? 0\n\t\t\tconst rawEnd = args[1] ?? source.length\n\n\t\t\t// Normalize negative indices\n\t\t\tconst start = normalizeSliceIndex(rawStart, source.length)\n\t\t\tconst end = normalizeSliceIndex(rawEnd, source.length)\n\n\t\t\tconst result: any[] = []\n\n\t\t\t// Return drafts for items in the slice range\n\t\t\tfor (let i = start; i < end; i++) {\n\t\t\t\tresult.push(state.draft_[i])\n\t\t\t}\n\n\t\t\treturn result\n\t\t}\n\n\t\t// For other methods, call on base array directly:\n\t\t// - indexOf, includes, join, toString: Return primitives, no draft needed\n\t\t// - concat, flat: Return NEW arrays (not subsets). Elements are base values.\n\t\t// This is intentional - concat/flat create new data structures rather than\n\t\t// selecting subsets of the original, making draft tracking impractical.\n\t\treturn source[method as keyof typeof Array.prototype](...args)\n\t}\n\n\tloadPlugin(PluginArrayMethods, {\n\t\tcreateMethodInterceptor,\n\t\tisArrayOperationMethod,\n\t\tisMutatingArrayMethod\n\t})\n}\n","import {\n\tIProduce,\n\tIProduceWithPatches,\n\tImmer,\n\tDraft,\n\tImmutable,\n\tNOTHING as nothing\n} from \"./internal\"\n\nexport {\n\tDraft,\n\tWritableDraft,\n\tImmutable,\n\tPatch,\n\tPatchListener,\n\tProducer,\n\toriginal,\n\tcurrent,\n\tisDraft,\n\tisDraftable,\n\tDRAFTABLE as immerable,\n\tfreeze,\n\tObjectish,\n\tStrictMode\n} from \"./internal\"\n\nexport {nothing}\n\nconst immer = new Immer()\n\n/**\n * The `produce` function takes a value and a \"recipe function\" (whose\n * return value often depends on the base state). The recipe function is\n * free to mutate its first argument however it wants. All mutations are\n * only ever applied to a __copy__ of the base state.\n *\n * Pass only a function to create a \"curried producer\" which relieves you\n * from passing the recipe function every time.\n *\n * Only plain objects and arrays are made mutable. All other objects are\n * considered uncopyable.\n *\n * Note: This function is __bound__ to its `Immer` instance.\n *\n * @param {any} base - the initial state\n * @param {Function} producer - function that receives a proxy of the base state as first argument and which can be freely modified\n * @param {Function} patchListener - optional function that will be called with all the patches produced here\n * @returns {any} a new state, or the initial state if nothing was modified\n */\nexport const produce: IProduce = /* @__PURE__ */ immer.produce\n\n/**\n * Like `produce`, but `produceWithPatches` always returns a tuple\n * [nextState, patches, inversePatches] (instead of just the next state)\n */\nexport const produceWithPatches: IProduceWithPatches = /* @__PURE__ */ immer.produceWithPatches.bind(\n\timmer\n)\n\n/**\n * Pass true to automatically freeze all copies created by Immer.\n *\n * Always freeze by default, even in production mode\n */\nexport const setAutoFreeze = /* @__PURE__ */ immer.setAutoFreeze.bind(immer)\n\n/**\n * Pass true to enable strict shallow copy.\n *\n * By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.\n */\nexport const setUseStrictShallowCopy = /* @__PURE__ */ immer.setUseStrictShallowCopy.bind(\n\timmer\n)\n\n/**\n * Pass false to use loose iteration that only processes enumerable string properties.\n * This skips symbols and non-enumerable properties for maximum performance.\n *\n * By default, strict iteration is enabled (includes all own properties).\n */\nexport const setUseStrictIteration = /* @__PURE__ */ immer.setUseStrictIteration.bind(\n\timmer\n)\n\n/**\n * Apply an array of Immer patches to the first argument.\n *\n * This function is a producer, which means copy-on-write is in effect.\n */\nexport const applyPatches = /* @__PURE__ */ immer.applyPatches.bind(immer)\n\n/**\n * Create an Immer draft from the given base state, which may be a draft itself.\n * The draft can be modified until you finalize it with the `finishDraft` function.\n */\nexport const createDraft = /* @__PURE__ */ immer.createDraft.bind(immer)\n\n/**\n * Finalize an Immer draft from a `createDraft` call, returning the base state\n * (if no changes were made) or a modified copy. The draft must *not* be\n * mutated afterwards.\n *\n * Pass a function as the 2nd argument to generate Immer patches based on the\n * changes that were made.\n */\nexport const finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer)\n\n/**\n * This function is actually a no-op, but can be used to cast an immutable type\n * to an draft type and make TypeScript happy\n *\n * @param value\n */\nexport let castDraft = (value: T): Draft => value as any\n\n/**\n * This function is actually a no-op, but can be used to cast a mutable type\n * to an immutable type and make TypeScript happy\n * @param value\n */\nexport let castImmutable = (value: T): Immutable => value as any\n\nexport {Immer}\n\nexport {enablePatches} from \"./plugins/patches\"\nexport {enableMapSet} from \"./plugins/mapset\"\nexport {enableArrayMethods} from \"./plugins/arrayMethods\"\n\nexport function isNothing(value: unknown): value is typeof nothing {\n\treturn value === nothing\n}\n"],"mappings":"AAKO,IAAMA,EAAyB,OAAO,IAAI,eAAe,EAUnDC,EAA2B,OAAO,IAAI,iBAAiB,EAEvDC,EAA6B,OAAO,IAAI,aAAa,ECuB3D,SAASC,EAAIC,KAAkBC,EAAoB,CAMzD,MAAM,IAAI,MACT,8BAA8BD,0CAC/B,CACD,CCnCA,IAAME,EAAI,OAEGC,EAAiBD,EAAE,eAEnBE,GAAc,cACdC,GAAY,YAEZC,GAAe,eACfC,GAAa,aACbC,GAAW,WACXC,GAAQ,QAIVC,EAAWC,GAAwB,CAAC,CAACA,GAAS,CAAC,CAACA,EAAMC,CAAW,EAIrE,SAASC,EAAYF,EAAqB,CAChD,OAAKA,EAEJG,GAAcH,CAAK,GACnBI,EAAQJ,CAAK,GACb,CAAC,CAACA,EAAMK,CAAS,GACjB,CAAC,CAACL,EAAMP,EAAW,IAAIY,CAAS,GAChCC,EAAMN,CAAK,GACXO,EAAMP,CAAK,EAPO,EASpB,CAEA,IAAMQ,GAAmBjB,EAAEG,EAAS,EAAED,EAAW,EAAE,SAAS,EACtDgB,GAAoB,IAAI,QAEvB,SAASN,GAAcH,EAAqB,CAClD,GAAI,CAACA,GAAS,CAACU,EAAYV,CAAK,EAAG,MAAO,GAC1C,IAAMW,EAAQnB,EAAeQ,CAAK,EAClC,GAAIW,IAAU,MAAQA,IAAUpB,EAAEG,EAAS,EAAG,MAAO,GAErD,IAAMkB,EAAOrB,EAAE,eAAe,KAAKoB,EAAOlB,EAAW,GAAKkB,EAAMlB,EAAW,EAC3E,GAAImB,IAAS,OAAQ,MAAO,GAE5B,GAAI,CAACC,EAAWD,CAAI,EAAG,MAAO,GAE9B,IAAIE,EAAaL,GAAkB,IAAIG,CAAI,EAC3C,OAAIE,IAAe,SAClBA,EAAa,SAAS,SAAS,KAAKF,CAAI,EACxCH,GAAkB,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,CACD,EAOaO,GAA+BP,EAAM,aAAa,KAAKA,CAAK,EAM5DQ,GAA8BR,EAAM,YAAY,KAAKA,CAAK,EAU1DS,GAA8BT,EAAM,YAAY,KAAKA,CAAK,EAQ5DU,GAAgBC,GAAuBA,EAOvCC,GAAoBD,GAA2BA,EAQnD,SAASE,GAAUC,EAAyC,CAClE,OAAOA,IAAUC,CAClB","names":["NOTHING","DRAFTABLE","DRAFT_STATE","die","error","args","O","getPrototypeOf","CONSTRUCTOR","PROTOTYPE","CONFIGURABLE","ENUMERABLE","WRITABLE","VALUE","isDraft","value","DRAFT_STATE","isDraftable","isPlainObject","isArray","DRAFTABLE","isMap","isSet","objectCtorString","cachedCtorStrings","isObjectish","proto","Ctor","isFunction","ctorString","original","die","base_","each","obj","iter","strict","getArchtype","key","entry","index","thing","state","type_","has","prop","type","get","set","propOrOldValue","is","x","y","target","isBoolean","isArrayIndex","n","getProxyDraft","latest","copy_","getValue","proxyDraft","getFinalValue","modified_","shallowCopy","base","isPlain","descriptors","keys","desc","freeze","deep","isFrozen","dontMutateMethodOverride","_key","dontMutateFrozenCollections","PluginMapSet","PluginPatches","PluginArrayMethods","plugins","getPlugin","pluginKey","plugin","die","isPluginLoaded","loadPlugin","pluginKey","implementation","plugins","currentScope","getCurrentScope","createScope","parent_","immer_","drafts_","canAutoFreeze_","unfinalizedDrafts_","handledSet_","processedForPatches_","mapSetPlugin_","isPluginLoaded","PluginMapSet","getPlugin","arrayMethodsPlugin_","PluginArrayMethods","usePatchesInScope","scope","patchListener","patchPlugin_","PluginPatches","patches_","inversePatches_","patchListener_","revokeScope","leaveScope","revokeDraft","enterScope","immer","draft","state","DRAFT_STATE","type_","revoke_","revoked_","processResult","result","scope","unfinalizedDrafts_","drafts_","baseDraft","DRAFT_STATE","modified_","revokeScope","die","isDraftable","finalize","patchPlugin_","generateReplacementPatches_","base_","maybeFreeze","patches_","patchListener_","inversePatches_","NOTHING","rootScope","value","isFrozen","state","handleValue","handledSet_","isSameScope","finalized_","callbacks_","generatePatchesAndFinalize","copy_","deep","parent_","immer_","autoFreeze_","canAutoFreeze_","freeze","markStateFinalized","scope_","EMPTY_LOCATIONS_RESULT","updateDraftInParent","parent","draftValue","finalizedValue","originalKey","parentCopy","latest","parentType","type_","get","set","draftLocations_","draftLocations","each","key","isDraft","keys","locations","location","registerChildFinalizationCallback","child","mapSetPlugin_","getFinalValue","draft_","allIndicesReassigned_","assigned_","basePath","generatePatches_","handleCrossReference","target","prepareCopy","targetCopy","handledSet","updatedValue","createProxyProxy","base","parent","baseIsArray","isArray","state","type_","scope_","getCurrentScope","modified_","finalized_","assigned_","parent_","base_","draft_","copy_","revoke_","isManual_","callbacks_","target","traps","objectTraps","arrayTraps","revoke","proxy","prop","DRAFT_STATE","arrayPlugin","arrayMethodsPlugin_","isArrayWithStringProp","source","latest","has","readPropFromProto","value","isDraftable","isArrayIndex","peek","prepareCopy","childKey","childDraft","createProxy","desc","getDescriptorFromProto","current","currentState","is","markChanged","handleCrossReference","owner","WRITABLE","CONFIGURABLE","ENUMERABLE","VALUE","die","getPrototypeOf","each","key","fn","args","draft","proto","shallowCopy","immer_","useStrictShallowCopy_","Immer","config","autoFreeze_","useStrictShallowCopy_","useStrictIteration_","base","recipe","patchListener","isFunction","defaultBase","self","args","draft","die","result","isDraftable","scope","enterScope","proxy","createProxy","hasError","revokeScope","leaveScope","usePatchesInScope","processResult","isObjectish","NOTHING","freeze","p","ip","getPlugin","PluginPatches","generateReplacementPatches_","patches_","inversePatches_","state","patches","inversePatches","isBoolean","isDraft","current","DRAFT_STATE","isManual_","scope_","value","i","patch","applyPatchesImpl","applyPatches_","rootScope","parent","key","isMap","PluginMapSet","proxyMap_","isSet","proxySet_","createProxyProxy","getCurrentScope","drafts_","callbacks_","key_","registerChildFinalizationCallback","mapSetPlugin_","patchPlugin_","modified_","generatePatches_","current","value","isDraft","die","currentImpl","isDraftable","isFrozen","state","DRAFT_STATE","copy","strict","modified_","base_","finalized_","shallowCopy","scope_","immer_","useStrictShallowCopy_","each","key","childValue","set","enablePatches","getPath","state","path","key_","parentCopy","parent_","copy_","base_","proxyDraft","getProxyDraft","get","valueAtKey","draft_","isSet","type_","key","setParent","drafts_","has","resolvePath","base","current","i","isObjectish","REPLACE","ADD","REMOVE","generatePatches_","basePath","scope","scope_","processedForPatches_","patches_","inversePatches_","generatePatchesFromAssigned","generateArrayPatches","generateSetPatches","patches","inversePatches","assigned_","allReassigned","allIndicesReassigned_","copiedItem","baseItem","childState","DRAFT_STATE","modified_","clonePatchValueIfNeeded","each","assignedValue","origValue","value","op","generateReplacementPatches_","baseValue","replacement","NOTHING","applyPatches_","draft","patch","parentType","getArchtype","p","CONSTRUCTOR","die","isFunction","PROTOTYPE","type","deepClonePatchValue","obj","isDraftable","isArray","isMap","k","v","cloned","getPrototypeOf","DRAFTABLE","isDraft","loadPlugin","PluginPatches","enableMapSet","DraftMap","target","parent","DRAFT_STATE","type_","parent_","scope_","getCurrentScope","modified_","finalized_","copy_","assigned_","base_","draft_","isManual_","revoked_","callbacks_","latest","key","value","state","assertUnrevoked","prepareMapCopy","markChanged","each","cb","thisArg","_value","_map","isDraftable","draft","createProxy","iterator","r","proxyMap_","map","DraftSet","drafts_","prepareSetCopy","result","proxySet_","set","die","fixSetContents","copy","getValue","loadPlugin","PluginMapSet","enableArrayMethods","SHIFTING_METHODS","QUEUE_METHODS","RESULT_RETURNING_METHODS","REORDERING_METHODS","MUTATING_METHODS","FIND_METHODS","NON_MUTATING_METHODS","isMutatingArrayMethod","method","isNonMutatingArrayMethod","isArrayOperationMethod","enterOperation","state","exitOperation","executeArrayMethod","operation","markLength","prepareCopy","result","markChanged","assigned_","markAllIndicesReassigned","allIndicesReassigned_","normalizeSliceIndex","index","length","handleSimpleOperation","args","copy_","draft_","handleReorderingOperation","createMethodInterceptor","originalMethod","res","handleNonMutatingOperation","source","latest","predicate","i","isForward","step","start","rawStart","rawEnd","end","loadPlugin","PluginArrayMethods","immer","Immer","produce","produceWithPatches","setAutoFreeze","setUseStrictShallowCopy","setUseStrictIteration","applyPatches","createDraft","finishDraft","castDraft","value","castImmutable","isNothing","value","NOTHING"]} \ No newline at end of file diff --git a/package.json b/package.json index cf9e7e73..0a4a6787 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { - "name": "immer", - "version": "10.0.3-beta", + "name": "@unional/immer", + "version": "11.1.0-patch", "description": "Create your next immutable state by mutating the current one", "main": "./dist/cjs/index.js", "module": "./dist/immer.legacy-esm.js", @@ -82,8 +82,8 @@ "import-size": "^1.0.2", "lodash": "^4.17.4", "lodash.clonedeep": "^4.5.0", - "prettier": "1.19.1", - "pretty-quick": "^1.8.0", + "prettier": "3.8.0", + "pretty-quick": "^4.2.2", "redux": "^4.0.5", "rimraf": "^2.6.2", "seamless-immutable": "^7.1.3", diff --git a/readme.md b/readme.md index 4e80fcf1..90c5c3ac 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,14 @@ +This is a fork of [immer](https://github.com/immerjs/immer). + +Releasing as `@unional/immer` as the original repo have not been updating for more than a month. + +This release fixes the following issues: + +- fix recursive JSON issue: +- add `isNothing()`: + # Immer [![npm](https://img.shields.io/npm/v/immer.svg)](https://www.npmjs.com/package/immer) [![Build Status](https://github.com/immerjs/immer/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/immerjs/immer/actions?query=branch%3Amain) [![Coverage Status](https://coveralls.io/repos/github/immerjs/immer/badge.svg?branch=main)](https://coveralls.io/github/immerjs/immer?branch=main) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![OpenCollective](https://opencollective.com/immer/backers/badge.svg)](#backers) [![OpenCollective](https://opencollective.com/immer/sponsors/badge.svg)](#sponsors) [![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/immerjs/immer) diff --git a/src/immer.ts b/src/immer.ts index 2ad2e56d..3133e833 100644 --- a/src/immer.ts +++ b/src/immer.ts @@ -3,7 +3,8 @@ import { IProduceWithPatches, Immer, Draft, - Immutable + Immutable, + NOTHING as nothing } from "./internal" export { @@ -17,13 +18,14 @@ export { current, isDraft, isDraftable, - NOTHING as nothing, DRAFTABLE as immerable, freeze, Objectish, StrictMode } from "./internal" +export {nothing} + const immer = new Immer() /** @@ -124,3 +126,7 @@ export {Immer} export {enablePatches} from "./plugins/patches" export {enableMapSet} from "./plugins/mapset" export {enableArrayMethods} from "./plugins/arrayMethods" + +export function isNothing(value: unknown): value is typeof nothing { + return value === nothing +} diff --git a/yarn.lock b/yarn.lock index bfb9e535..5f261b12 100644 --- a/yarn.lock +++ b/yarn.lock @@ -983,6 +983,11 @@ resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33" integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg== +"@pkgr/core@^0.2.7": + version "0.2.9" + resolved "https://registry.yarnpkg.com/@pkgr/core/-/core-0.2.9.tgz#d229a7b7f9dac167a156992ef23c7f023653f53b" + integrity sha512-QNqXyfVS2wm9hweSYD2O7F0G06uurj9kZ96TRQE5Y9hU7+tgdZwIkbAKc5Ocy1HxEY2kuDQa6cQ1WRs/O5LFKA== + "@rollup/rollup-android-arm-eabi@4.50.1": version "4.50.1" resolved "https://registry.yarnpkg.com/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.50.1.tgz#7d41dc45adcfcb272504ebcea9c8a5b2c659e963" @@ -1645,33 +1650,16 @@ arr-union@^3.1.0: resolved "https://registry.yarnpkg.com/arr-union/-/arr-union-3.1.0.tgz#e39b09aea9def866a8f206e288af63919bae39c4" integrity sha1-45sJrqne+Gao8gbiiK9jkZuuOcQ= -array-differ@^2.0.3: - version "2.1.0" - resolved "https://registry.yarnpkg.com/array-differ/-/array-differ-2.1.0.tgz#4b9c1c3f14b906757082925769e8ab904f4801b1" - integrity sha512-KbUpJgx909ZscOc/7CLATBFam7P1Z1QRQInvgT0UztM9Q72aGKCunKASAl7WNW0tnPmPyEMeMhdsfWhfmW037w== - array-ify@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/array-ify/-/array-ify-1.0.0.tgz#9e528762b4a9066ad163a6962a364418e9626ece" integrity sha512-c5AMf34bKdvPhQ7tBGhqkgKNUzMr4WUs+WDtC2ZUGOUncbxKMTvqxYctiseW3+L4bA8ec+GcZ6/A/FW4m8ukng== -array-union@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/array-union/-/array-union-1.0.2.tgz#9a34410e4f4e3da23dea375be5be70f24778ec39" - integrity sha1-mjRBDk9OPaI96jdb5b5w8kd47Dk= - dependencies: - array-uniq "^1.0.1" - array-union@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/array-union/-/array-union-2.1.0.tgz#b798420adbeb1de828d84acd8a2e23d3efe85e8d" integrity sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw== -array-uniq@^1.0.1: - version "1.0.3" - resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6" - integrity sha1-r2rId6Jcx/dOBYiUdThY39sk/bY= - array-unique@^0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.3.2.tgz#a894b75d4bc4f6cd679ef3244a9fd8f46ae2d428" @@ -2550,7 +2538,7 @@ chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^2.0.0, chalk@^2.3.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.3.2, chalk@^2.4.1, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -3049,15 +3037,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.7: safe-buffer "^5.0.1" sha.js "^2.4.8" -cross-spawn@^5.0.1: - version "5.1.0" - resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" - integrity sha512-pTgQJ5KC0d2hcY8eyL1IzlBPYjTkyH72XRZPnLyKus2mBfNjQs3klqbJU2VILqZryAZUt9JOb3h/mWMy23/f5A== - dependencies: - lru-cache "^4.0.1" - shebang-command "^1.2.0" - which "^1.2.9" - cross-spawn@^6.0.0: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" @@ -3702,19 +3681,6 @@ evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: md5.js "^1.3.4" safe-buffer "^5.1.1" -execa@^0.8.0: - version "0.8.0" - resolved "https://registry.yarnpkg.com/execa/-/execa-0.8.0.tgz#d8d76bbc1b55217ed190fd6dd49d3c774ecfc8da" - integrity sha1-2NdrvBtVIX7RkP1t1J08d07PyNo= - dependencies: - cross-spawn "^5.0.1" - get-stream "^3.0.0" - is-stream "^1.1.0" - npm-run-path "^2.0.0" - p-finally "^1.0.0" - signal-exit "^3.0.0" - strip-eof "^1.0.0" - execa@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/execa/-/execa-1.0.0.tgz#c6236a5bb4df6d6f15e88e7f017798216749ddd8" @@ -4133,11 +4099,6 @@ get-stdin@^6.0.0: resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== -get-stream@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" - integrity sha512-GlhdIUuVakc8SJ6kK0zAFbiGzRFzNnY4jUuEbV9UROo4Y+0Ny4fjvcZFVTeDA4odpFyOQzaw6hXukJSq/f28sQ== - get-stream@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-4.1.0.tgz#c1b255575f3dc21d59bfc79cd3d2b46b1c3a54b5" @@ -4552,16 +4513,16 @@ ignore-walk@^3.0.3: dependencies: minimatch "^3.0.4" -ignore@^3.3.7: - version "3.3.10" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043" - integrity sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug== - ignore@^5.2.0: version "5.2.4" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.2.4.tgz#a291c0c6178ff1b960befe47fcdec301674a6324" integrity sha512-MAb38BcSbH0eHNBxn7ql2NH/kX33OkB3lZ1BNdh7ENeRChHTYsTvWrMubiIAMNS2llXEEgZ1MUOBtXChP3kaFQ== +ignore@^7.0.5: + version "7.0.5" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-7.0.5.tgz#4cb5f6cd7d4c7ab0365738c7aea888baa6d7efd9" + integrity sha512-Hs59xBNfUIunMFgWAbGX5cq6893IbWg4KnrjbYwX3tx0ztorVgTDA6B2sxf8ejHJ4wz8BqGUMYlnzNBer5NvGg== + immutable@^3.8.2: version "3.8.2" resolved "https://registry.yarnpkg.com/immutable/-/immutable-3.8.2.tgz#c2439951455bb39913daf281376f1530e104adf3" @@ -5496,14 +5457,6 @@ lru-cache@^10.2.0: resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-10.4.3.tgz#410fc8a17b70e598013df257c2446b7f3383f119" integrity sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ== -lru-cache@^4.0.1: - version "4.1.5" - resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.5.tgz#8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd" - integrity sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g== - dependencies: - pseudomap "^1.0.2" - yallist "^2.1.2" - lru-cache@^5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-5.1.1.tgz#1da27e6710271947695daf6848e847f01d84b920" @@ -5923,10 +5876,10 @@ move-concurrently@^1.0.1: rimraf "^2.5.4" run-queue "^1.0.3" -mri@^1.1.0: - version "1.1.4" - resolved "https://registry.yarnpkg.com/mri/-/mri-1.1.4.tgz#7cb1dd1b9b40905f1fac053abe25b6720f44744a" - integrity sha512-6y7IjGPm8AzlvoUrwAaw1tLnUBudaS3752vcd8JtrpGGQn+rXIe63LFVHm/YMwtqAuh+LJPCFdlLYPWM1nYn6w== +mri@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/mri/-/mri-1.2.0.tgz#6721480fec2a11a4889861115a48b6cbe7cc8f0b" + integrity sha512-tzzskb3bG8LvYGFF/mDTpq3jpI6Q9wc3LEmBaghu+DdCssd1FakN7Bc0hVNmEyGq1bq3RgfkCb3cmQLpNPOroA== ms@2.0.0: version "2.0.0" @@ -5943,16 +5896,6 @@ ms@^2.0.0, ms@^2.1.2, ms@^2.1.3: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== -multimatch@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/multimatch/-/multimatch-3.0.0.tgz#0e2534cc6bc238d9ab67e1b9cd5fcd85a6dbf70b" - integrity sha512-22foS/gqQfANZ3o+W7ST2x25ueHDVNWl/b9OlGcLpy/iKxjCpvcNCM51YCenUi7Mt/jAjjqv8JwZRs8YP5sRjA== - dependencies: - array-differ "^2.0.3" - array-union "^1.0.2" - arrify "^1.0.1" - minimatch "^3.0.4" - mute-stream@~0.0.4: version "0.0.8" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" @@ -6707,6 +6650,11 @@ picomatch@^2.2.1, picomatch@^2.3.1: resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42" integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA== +picomatch@^4.0.2: + version "4.0.3" + resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-4.0.3.tgz#796c76136d1eead715db1e7bad785dedd695a042" + integrity sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q== + pify@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" @@ -7064,22 +7012,23 @@ prepend-http@^1.0.0: resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-1.0.4.tgz#d4f4562b0ce3696e41ac52d0e002e57a635dc6dc" integrity sha1-1PRWKwzjaW5BrFLQ4ALlemNdxtw= -prettier@1.19.1: - version "1.19.1" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" - integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== +prettier@3.8.0: + version "3.8.0" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.8.0.tgz#f72cf71505133f40cfa2ef77a2668cdc558fcd69" + integrity sha512-yEPsovQfpxYfgWNhCfECjG5AQaO+K3dp6XERmOepyPDVqcJm+bjyCVO3pmU+nAPe0N5dDvekfGezt/EIiRe1TA== -pretty-quick@^1.8.0: - version "1.11.1" - resolved "https://registry.yarnpkg.com/pretty-quick/-/pretty-quick-1.11.1.tgz#462ffa2b93d24c05b7a0c3a001e08601a0c55ee4" - integrity sha512-kSXCkcETfak7EQXz6WOkCeCqpbC4GIzrN/vaneTGMP/fAtD8NerA9bPhCUqHAks1geo7biZNl5uEMPceeneLuA== +pretty-quick@^4.2.2: + version "4.2.2" + resolved "https://registry.yarnpkg.com/pretty-quick/-/pretty-quick-4.2.2.tgz#0fc31da666f182fe14e119905fc9829b5b85a234" + integrity sha512-uAh96tBW1SsD34VhhDmWuEmqbpfYc/B3j++5MC/6b3Cb8Ow7NJsvKFhg0eoGu2xXX+o9RkahkTK6sUdd8E7g5w== dependencies: - chalk "^2.3.0" - execa "^0.8.0" - find-up "^2.1.0" - ignore "^3.3.7" - mri "^1.1.0" - multimatch "^3.0.0" + "@pkgr/core" "^0.2.7" + ignore "^7.0.5" + mri "^1.2.0" + picocolors "^1.1.1" + picomatch "^4.0.2" + tinyexec "^0.3.2" + tslib "^2.8.1" private@^0.1.8: version "0.1.8" @@ -7136,11 +7085,6 @@ prr@~1.0.1: resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" integrity sha512-yPw4Sng1gWghHQWj0B3ZggWUm4qVbPwPFcRG8KyxiU7J2OHFSoEHKS+EZ3fv5l1t9CyCiop6l/ZYeWbrgoQejw== -pseudomap@^1.0.2: - version "1.0.2" - resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" - integrity sha512-b/YwNhb8lk1Zz2+bXXpS/LK9OisiZZ1SNsSLxN1x2OXVEhW2Ckr/7mWE5vrC1ZTiJlD9g19jWszTmJsB+oEpFQ== - psl@^1.1.28: version "1.9.0" resolved "https://registry.yarnpkg.com/psl/-/psl-1.9.0.tgz#d0df2a137f00794565fcaf3b2c00cd09f8d5a5a7" @@ -8508,7 +8452,7 @@ tinybench@^2.9.0: resolved "https://registry.yarnpkg.com/tinybench/-/tinybench-2.9.0.tgz#103c9f8ba6d7237a47ab6dd1dcff77251863426b" integrity sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg== -tinyexec@^0.3.1: +tinyexec@^0.3.1, tinyexec@^0.3.2: version "0.3.2" resolved "https://registry.yarnpkg.com/tinyexec/-/tinyexec-0.3.2.tgz#941794e657a85e496577995c6eef66f53f42b3d2" integrity sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA== @@ -8639,6 +8583,11 @@ tslib@^1.9.0: resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== +tslib@^2.8.1: + version "2.8.1" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.8.1.tgz#612efe4ed235d567e8aba5f2a5fab70280ade83f" + integrity sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w== + tsup@^6.7.0: version "6.7.0" resolved "https://registry.yarnpkg.com/tsup/-/tsup-6.7.0.tgz#416f350f32a07b6ae86792ad7e52b0cafc566d64" @@ -9174,11 +9123,6 @@ y18n@^5.0.5: resolved "https://registry.yarnpkg.com/y18n/-/y18n-5.0.8.tgz#7f4934d0f7ca8c56f95314939ddcd2dd91ce1d55" integrity sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA== -yallist@^2.1.2: - version "2.1.2" - resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" - integrity sha512-ncTzHV7NvsQZkYe1DW7cbDLm0YpzHmZF5r/iyP3ZnQtMiJ+pjzisCiMNI+Sj+xQF5pXhSHxSB3uDbsBTzY/c2A== - yallist@^3.0.2: version "3.1.1" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.1.1.tgz#dbb7daf9bfd8bac9ab45ebf602b8cbad0d5d08fd"