UNPKG

react-box-tools

Version:

Box tools react components, utils and hooks

987 lines (986 loc) 28.2 kB
var ye = Object.defineProperty; var pe = (e, t, s) => t in e ? ye(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s; var v = (e, t, s) => pe(e, typeof t != "symbol" ? t + "" : t, s); var S = /* @__PURE__ */ ((e) => (e[e.Object = 0] = "Object", e[e.Array = 1] = "Array", e[e.Map = 2] = "Map", e[e.Set = 3] = "Set", e))(S || {}), P = /* @__PURE__ */ ((e) => (e[e.ProxyObject = 0] = "ProxyObject", e[e.ProxyArray = 1] = "ProxyArray", e[e.Map = 2] = "Map", e[e.Set = 3] = "Set", e[e.ES5Object = 4] = "ES5Object", e[e.ES5Array = 5] = "ES5Array", e))(P || {}); function he(e) { return ae(e); } function ae(e) { if (!M(e)) return e; const t = e[d]; let s; const i = C(e); if (t) { if (!t.modified_ && (t.type_ < 4 || !E("ES5").hasChanges_(t))) return t.base_; t.finalized_ = !0, s = oe(e, i), t.finalized_ = !1; } else s = oe(e, i); return z(s, (f, a) => { t && Y(t.base_, f) === a || _e(s, f, ae(a)); }), i === S.Set ? new Set(s) : s; } function oe(e, t) { switch (t) { case S.Map: return new Map(e); case S.Set: return Array.from(e); } return V(e); } function G(e, t) { t.unfinalizedDrafts_ = t.drafts_.length; const s = t.drafts_[0], i = e !== void 0 && e !== s; return t.immutable_.useProxies_ || E("ES5").willFinalizeES5_(t, e, i), i ? (s[d].modified_ && U(t), M(e) && (e = B(t, e), t.parent_ || H(t, e)), t.patches_ && E("Patches").generateReplacementPatches_( s[d].base_, e, t.patches_, t.inversePatches_ )) : e = B(t, s, []), U(t), t.patches_ && t.patchListener_(t.patches_, t.inversePatches_), e !== ne ? e : void 0; } function B(e, t, s) { if (te(t)) return t; const i = t[d]; if (!i) return z( t, (f, a) => ce(e, i, t, f, a, s), !0 // See #590, don't recurse into non-enumerable of non drafted objects ), t; if (i.scope_ !== e) return t; if (!i.modified_) return H(e, i.base_, !0), i.base_; if (!i.finalized_) { i.finalized_ = !0, i.scope_.unfinalizedDrafts_--; const f = ( // For ES5, create a good copy from the draft first, with added keys and without deleted keys. i.type_ === P.ES5Object || i.type_ === P.ES5Array ? i.copy_ = V(i.draft_) : i.copy_ ); z( i.type_ === P.Set ? new Set(f) : f, (a, b) => ce(e, i, f, a, b, s) ), H(e, f, !1), s && e.patches_ && E("Patches").generatePatches_( i, s, e.patches_, e.inversePatches_ ); } return i.copy_; } function ce(e, t, s, i, f, a) { if (D(f)) { const b = a && t && t.type_ !== P.Set && // Set objects are atomic since they have no keys. !x(t.assigned_, i) ? a.concat(i) : void 0, O = B(e, f, b); if (_e(s, i, O), D(O)) e.canAutoFreeze_ = !1; else return; } if (M(f) && !te(f)) { if (!e.immutable_.autoFreeze_ && e.unfinalizedDrafts_ < 1) return; B(e, f), (!t || !t.scope_.parent_) && H(e, f); } } function H(e, t, s = !1) { e.immutable_.autoFreeze_ && e.canAutoFreeze_ && ee(t, s); } class je { constructor(t) { v(this, "useProxies_", Ee); v(this, "autoFreeze_", !0); /** * 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 */ v(this, "create", (t, s, i) => { if (typeof t == "function" && typeof s != "function") { const a = s; s = t; const b = this; return function(l = a, ...y) { return b.create(l, (o) => s.call(this, o, ...y)); }; } let f; if (M(t)) { const a = fe(this), b = k(this, t, void 0); let O = !0; try { f = s(b), O = !1; } finally { O ? U(a) : X(a); } return typeof Promise < "u" && f instanceof Promise ? f.then( (l) => (T(a, i), G(l, a)), (l) => { throw U(a), l; } ) : (T(a, i), G(f, a)); } else if (!t || typeof t != "object") { if (f = s(t), f === void 0 && (f = t), f === ne && (f = void 0), this.autoFreeze_ && ee(f, !0), i) { const a = [], b = []; E("Patches").generateReplacementPatches_(t, f, a, b), i(a, b); } return f; } }); v(this, "produceWithPatches", (t, s) => { if (typeof t == "function") return (b, ...O) => this.produceWithPatches(b, (l) => t(l, ...O)); let i, f; const a = this.create(t, s, (b, O) => { i = b, f = O; }); return typeof Promise < "u" && a instanceof Promise ? a.then((b) => [b, i, f]) : [a, i, f]; }); typeof (t == null ? void 0 : t.useProxies) == "boolean" && this.setUseProxies(t.useProxies), typeof (t == null ? void 0 : t.autoFreeze) == "boolean" && this.setAutoFreeze(t.autoFreeze); } createDraft(t) { D(t) && (t = he(t)); const s = fe(this), i = k(this, t, void 0); return i[d].isManual_ = !0, X(s), i; } finishDraft(t, s) { const i = t && t[d], { scope_: f } = i; return T(f, s), G(void 0, f); } /** * Pass true to automatically freeze all copies * By default, auto-freezing is enabled. */ setAutoFreeze(t) { this.autoFreeze_ = t; } /** * Pass true to use the ES2015 `Proxy` class when creating drafts, which is * always faster than using ES5 proxies. * * By default, feature detection is used, so calling this is rarely necessary. */ setUseProxies(t) { this.useProxies_ = t; } applyPatches(t, s) { let i; for (i = s.length - 1; i >= 0; i--) { const a = s[i]; if (a.path.length === 0 && a.op === "replace") { t = a.value; break; } } i > -1 && (s = s.slice(i + 1)); const f = E("Patches").applyPatches_; return D(t) ? f(t, s) : this.create( t, (a) => f(a, s) ); } } function k(e, t, s) { const i = W(t) ? E("MapSet").proxyMap_(t, s) : q(t) ? E("MapSet").proxySet_(t, s) : e.useProxies_ ? ge(t, s) : E("ES5").createES5Proxy_(t, s); return (s ? s.scope_ : K()).drafts_.push(i), i; } function ge(e, t) { const s = Array.isArray(e), i = { type_: s ? P.ProxyArray : P.ProxyObject, // Track which produce call this is associated with. scope_: t ? t.scope_ : K(), // True for both shallow and deep changes. modified_: !1, // Used during finalization. finalized_: !1, // Track which properties have been assigned (true) or deleted (false). assigned_: {}, // The parent draft state. parent_: t, // The base state. base_: e, // The base proxy. draft_: null, // set below // The base copy with any updated values. copy_: null, // Called by the `produce` function. revoke_: null, isManual_: !1 }, f = {}; z(J, (y, o) => { f[y] = function() { return arguments[0] = arguments[0][0], o.apply(this, arguments); }; }), f.deleteProperty = function(y, o) { return f.set.call(this, y, o, void 0); }, f.set = function(y, o, r) { return J.set.call(this, y[0], o, r, y[0]); }; let a = i, b = J; s && (a = [i], b = f); const { revoke: O, proxy: l } = Proxy.revocable(a, b); return i.draft_ = l, i.revoke_ = O, l; } const J = { get(e, t) { if (t === d) return e; const s = w(e); if (!x(s, t)) return be(e, s, t); const i = s[t]; return e.finalized_ || !M(i) ? i : i === L(e.base_, t) ? (Q(e), e.copy_[t] = k( e.scope_.immutable_, i, e )) : i; }, has(e, t) { return t in w(e); }, ownKeys(e) { return Reflect.ownKeys(w(e)); }, set(e, t, s) { const i = ue(w(e), t); if (i != null && i.set) return i.set.call(e.draft_, s), !0; if (!e.modified_) { const f = L(w(e), t), a = f == null ? void 0 : f[d]; if (a && a.base_ === s) return e.copy_[t] = s, e.assigned_[t] = !1, !0; if (de(s, f) && (s !== void 0 || x(e.base_, t))) return !0; Q(e), A(e); } return e.copy_[t] === s && // special case: NaN typeof s != "number" && // special case: handle new props with value 'undefined' (s !== void 0 || t in e.copy_) || (e.copy_[t] = s, e.assigned_[t] = !0), !0; }, deleteProperty(e, t) { return L(e.base_, t) !== void 0 || t in e.base_ ? (e.assigned_[t] = !1, Q(e), A(e)) : delete e.assigned_[t], e.copy_ && delete e.copy_[t], !0; }, // Note: We never coerce `desc.value` into an Immer draft, because we can't make // the same guarantee in ES5 mode. getOwnPropertyDescriptor(e, t) { const s = w(e), i = Reflect.getOwnPropertyDescriptor(s, t); return i && { writable: !0, configurable: e.type_ !== P.ProxyArray || t !== "length", enumerable: i.enumerable, value: s[t] }; }, getPrototypeOf(e) { return Object.getPrototypeOf(e.base_); } }; function L(e, t) { const s = e[d]; return (s ? w(s) : e)[t]; } function be(e, t, s) { var f; const i = ue(t, s); return i ? "value" in i ? i.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! (f = i.get) == null ? void 0 : f.call(e.draft_) ) : void 0; } function ue(e, t) { if (!(t in e)) return; let s = Object.getPrototypeOf(e); for (; s; ) { const i = Object.getOwnPropertyDescriptor(s, t); if (i) return i; s = Object.getPrototypeOf(s); } } function A(e) { e.modified_ || (e.modified_ = !0, e.parent_ && A(e.parent_)); } function Q(e) { e.copy_ || (e.copy_ = V(e.base_)); } let N; function K() { return N; } function me(e, t) { return { drafts_: [], parent_: e, immutable_: t, // Whenever the modified draft contains a draft from another scope, we // need to prevent auto-freezing so the unowned draft can be finalized. canAutoFreeze_: !0, unfinalizedDrafts_: 0 }; } function T(e, t) { t && (E("Patches"), e.patches_ = [], e.inversePatches_ = [], e.patchListener_ = t); } function U(e) { X(e), e.drafts_.forEach(Pe), e.drafts_ = null; } function X(e) { e === N && (N = e.parent_); } function fe(e) { return N = me(N, e); } function Pe(e) { const t = e[d]; t.type_ === P.ProxyObject || t.type_ === P.ProxyArray ? t.revoke_() : t.revoked_ = !0; } function D(e) { return !!e && !!e[d]; } function M(e) { return e ? Se(e) || Array.isArray(e) || // @ts-ignore !!e[I] || // @ts-ignore !!e.constructor[I] || W(e) || q(e) : !1; } const Oe = Object.prototype.constructor.toString(); function Se(e) { if (!e || typeof e != "object") return !1; const t = Object.getPrototypeOf(e); if (t === null) return !0; const s = Object.hasOwnProperty.call(t, "constructor") && t.constructor; return s === Object ? !0 : typeof s == "function" && Function.toString.call(s) === Oe; } function ve(e) { return e[d].base_; } const F = typeof Reflect < "u" && Reflect.ownKeys ? Reflect.ownKeys : typeof Object.getOwnPropertySymbols < "u" ? (e) => Object.getOwnPropertyNames(e).concat( Object.getOwnPropertySymbols(e) ) : ( /* istanbul ignore next */ Object.getOwnPropertyNames ), le = Object.getOwnPropertyDescriptors || function(t) { const s = {}; return F(t).forEach((i) => { s[i] = Object.getOwnPropertyDescriptor(t, i); }), s; }; function z(e, t, s = !1) { C(e) === S.Object ? (s ? Object.keys : F)(e).forEach((i) => { (!s || typeof i != "symbol") && t(i, e[i], e); }) : e && e.forEach((i, f) => t(f, i, e)); } function C(e) { const t = e[d]; return t ? t.type_ > 3 ? t.type_ - 4 : t.type_ : Array.isArray(e) ? S.Array : W(e) ? S.Map : q(e) ? S.Set : S.Object; } function x(e, t) { return C(e) === S.Map ? e.has(t) : Object.prototype.hasOwnProperty.call(e, t); } function Y(e, t) { return C(e) === S.Map ? e.get(t) : e[t]; } function _e(e, t, s) { const i = C(e); i === S.Map ? e.set(t, s) : i === S.Set ? (e.delete(t), e.add(s)) : e[t] = s; } function de(e, t) { return e === t ? e !== 0 || 1 / e === 1 / t : e !== e && t !== t; } function W(e) { return we && e instanceof Map; } function q(e) { return Ae && e instanceof Set; } function w(e) { return e.copy_ || e.base_; } function V(e) { if (Array.isArray(e)) return Array.prototype.slice.call(e); const t = le(e); delete t[d]; let s = F(t); for (let i = 0; i < s.length; i++) { const f = s[i], a = t[f]; a.writable === !1 && (a.writable = !0, a.configurable = !0), (a.get || a.set) && (t[f] = { configurable: !0, writable: !0, // could live with !!desc.set as well here... enumerable: a.enumerable, value: e[f] }); } return Object.create(Object.getPrototypeOf(e), t); } function ee(e, t = !1) { return te(e) || D(e) || !M(e) || (Object.freeze(e), t && z(e, (s, i) => ee(i, !0), !0)), e; } function te(e) { return e == null || typeof e != "object" ? !0 : Object.isFrozen(e); } const re = typeof Symbol < "u" && typeof Symbol("x") == "symbol", we = typeof Map < "u", Ae = typeof Set < "u", Ee = typeof Proxy < "u" && typeof Proxy.revocable < "u" && typeof Reflect < "u", ne = re ? Symbol.for("immutable-nothing") : { "immutable-nothing": !0 }, I = re ? Symbol.for("immutable-draftable") : "__$immutable_draftable", d = re ? Symbol.for("immutable-state") : "__$immutable_state", $ = typeof Symbol < "u" && Symbol.iterator || "@@iterator"; class Fe { constructor() { // This lets us do `Exclude<T, Nothing>` // @ts-ignore v(this, "_"); } } const Z = {}; function E(e) { return Z[e]; } function se(e, t) { Z[e] || (Z[e] = t); } function Ce() { Me(), ze(), xe(); } function Me() { function e(o, r, n) { n ? D(r) && r[d].scope_ === o && a(o.drafts_) : (o.patches_ && b(o.drafts_[0]), a(o.drafts_)); } function t(o, r) { if (o) { const n = new Array(r.length); for (let c = 0; c < r.length; c++) Object.defineProperty(n, "" + c, f(c, !0)); return n; } else { const n = le(r); delete n[d]; const c = F(n); for (let u = 0; u < c.length; u++) { const h = c[u]; n[h] = f( h, o || !!n[h].enumerable ); } return Object.create(Object.getPrototypeOf(r), n); } } function s(o, r) { const n = Array.isArray(o), c = t(n, o), u = { type_: n ? P.ES5Array : P.ES5Object, scope_: r ? r.scope_ : K(), modified_: !1, finalized_: !1, assigned_: {}, parent_: r, // base is the object we are drafting base_: o, // draft is the draft object itself, that traps all reads and reads from either the base (if unmodified) or copy (if modified) draft_: c, copy_: null, revoked_: !1, isManual_: !1 }; return Object.defineProperty(c, d, { value: u, // enumerable: false <- the default writable: !0 }), c; } const i = {}; function f(o, r) { let n = i[o]; return n ? n.enumerable = r : i[o] = n = { configurable: !0, enumerable: r, get() { const c = this[d]; return objectTraps.get(c, o); }, set(c) { const u = this[d]; objectTraps.set(u, o, c); } }, n; } function a(o) { for (let r = o.length - 1; r >= 0; r--) { const n = o[r][d]; if (!n.modified_) switch (n.type_) { case P.ES5Array: l(n) && A(n); break; case P.ES5Object: O(n) && A(n); break; } } } function b(o) { if (!o || typeof o != "object") return; const r = o[d]; if (!r) return; const { base_: n, draft_: c, assigned_: u, type_: h } = r; if (h === P.ES5Object) z(c, (p) => { p !== d && (n[p] === void 0 && !x(n, p) ? (u[p] = !0, A(r)) : u[p] || b(c[p])); }), z(n, (p) => { c[p] === void 0 && !x(c, p) && (u[p] = !1, A(r)); }); else if (h === P.ES5Array) { if (l(r) && (A(r), u.length = !0), c.length < n.length) for (let _ = c.length; _ < n.length; _++) u[_] = !1; else for (let _ = n.length; _ < c.length; _++) u[_] = !0; const p = Math.min(c.length, n.length); for (let _ = 0; _ < p; _++) c.hasOwnProperty(_) || (u[_] = !0), u[_] === void 0 && b(c[_]); } } function O(o) { const { base_: r, draft_: n } = o, c = F(n); for (let h = c.length - 1; h >= 0; h--) { const p = c[h]; if (p === d) continue; const _ = r[p]; if (_ === void 0 && !x(r, p)) return !0; { const g = n[p], m = g && g[d]; if (m ? m.base_ !== _ : !de(g, _)) return !0; } } const u = !!r[d]; return c.length !== F(r).length + (u ? 0 : 1); } function l(o) { const { draft_: r } = o; if (r.length !== o.base_.length) return !0; const n = Object.getOwnPropertyDescriptor( r, r.length - 1 ); if (n && !n.get) return !0; for (let c = 0; c < r.length; c++) if (!r.hasOwnProperty(c)) return !0; return !1; } function y(o) { return o.type_ === P.ES5Object ? O(o) : l(o); } se("ES5", { createES5Proxy_: s, willFinalizeES5_: e, hasChanges_: y }); } function ze() { var e = function(l, y) { return e = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(o, r) { o.__proto__ = r; } || function(o, r) { for (var n in r) r.hasOwnProperty(n) && (o[n] = r[n]); }, e(l, y); }; function t(l, y) { e(l, y); function o() { this.constructor = l; } l.prototype = // @ts-ignore (o.prototype = y.prototype, new o()); } const s = function(l) { t(y, l); function y(r, n) { return this[d] = { type_: P.Map, parent_: n, scope_: n ? n.scope_ : K(), modified_: !1, finalized_: !1, copy_: void 0, assigned_: void 0, base_: r, draft_: this, isManual_: !1, revoked_: !1 }, this; } const o = y.prototype; return Object.defineProperty(o, "size", { get: function() { return w(this[d]).size; } }), o.has = function(r) { return w(this[d]).has(r); }, o.set = function(r, n) { const c = this[d]; return (!w(c).has(r) || w(c).get(r) !== n) && (f(c), A(c), c.assigned_.set(r, !0), c.copy_.set(r, n), c.assigned_.set(r, !0)), this; }, o.delete = function(r) { if (!this.has(r)) return !1; const n = this[d]; return f(n), A(n), n.base_.has(r) ? n.assigned_.set(r, !1) : n.assigned_.delete(r), n.copy_.delete(r), !0; }, o.clear = function() { const r = this[d]; w(r).size && (f(r), A(r), r.assigned_ = /* @__PURE__ */ new Map(), z(r.base_, (n) => { r.assigned_.set(n, !1); }), r.copy_.clear()); }, o.forEach = function(r, n) { const c = this[d]; w(c).forEach((u, h, p) => { r.call(n, this.get(h), h, this); }); }, o.get = function(r) { const n = this[d], c = w(n).get(r); if (n.finalized_ || !M(c) || c !== n.base_.get(r)) return c; const u = k(n.scope_.immutable_, c, n); return f(n), n.copy_.set(r, u), u; }, o.keys = function() { return w(this[d]).keys(); }, o.values = function() { const r = this.keys(); return { [$]: () => this.values(), next: () => { const n = r.next(); return n.done ? n : { done: !1, value: this.get(n.value) }; } }; }, o.entries = function() { const r = this.keys(); return { [$]: () => this.entries(), next: () => { const n = r.next(); if (n.done) return n; const c = this.get(n.value); return { done: !1, value: [n.value, c] }; } }; }, o[$] = function() { return this.entries(); }, y; }(Map); function i(l, y) { return new s(l, y); } function f(l) { l.copy_ || (l.assigned_ = /* @__PURE__ */ new Map(), l.copy_ = new Map(l.base_)); } const a = function(l) { t(y, l); function y(r, n) { return this[d] = { type_: P.Set, parent_: n, scope_: n ? n.scope_ : K(), modified_: !1, finalized_: !1, copy_: void 0, base_: r, draft_: this, drafts_: /* @__PURE__ */ new Map(), revoked_: !1, isManual_: !1 }, this; } const o = y.prototype; return Object.defineProperty(o, "size", { get: function() { return w(this[d]).size; } // enumerable: true, }), o.has = function(r) { const n = this[d]; return n.copy_ ? !!(n.copy_.has(r) || n.drafts_.has(r) && n.copy_.has(n.drafts_.get(r))) : n.base_.has(r); }, o.add = function(r) { const n = this[d]; return this.has(r) || (O(n), A(n), n.copy_.add(r)), this; }, o.delete = function(r) { if (!this.has(r)) return !1; const n = this[d]; return O(n), A(n), n.copy_.delete(r) || (n.drafts_.has(r) ? n.copy_.delete(n.drafts_.get(r)) : ( /* istanbul ignore next */ !1 )); }, o.clear = function() { const r = this[d]; w(r).size && (O(r), A(r), r.copy_.clear()); }, o.values = function() { const r = this[d]; return O(r), r.copy_.values(); }, o.entries = function() { const n = this[d]; return O(n), n.copy_.entries(); }, o.keys = function() { return this.values(); }, o[$] = function() { return this.values(); }, o.forEach = function(n, c) { const u = this.values(); let h = u.next(); for (; !h.done; ) n.call(c, h.value, h.value, this), h = u.next(); }, y; }(Set); function b(l, y) { return new a(l, y); } function O(l) { l.copy_ || (l.copy_ = /* @__PURE__ */ new Set(), l.base_.forEach((y) => { if (M(y)) { const o = k(l.scope_.immutable_, y, l); l.drafts_.set(y, o), l.copy_.add(o); } else l.copy_.add(y); })); } se("MapSet", { proxyMap_: i, proxySet_: b }); } function xe() { const e = "replace", t = "add", s = "remove"; function i(r, n, c, u) { switch (r.type_) { case P.ProxyObject: case P.ES5Object: case P.Map: return a( r, n, c, u ); case P.ES5Array: case P.ProxyArray: return f(r, n, c, u); case P.Set: return b( r, n, c, u ); } } function f(r, n, c, u) { let { base_: h, assigned_: p } = r, _ = r.copy_; _.length < h.length && ([h, _] = [_, h], [c, u] = [u, c]); for (let g = 0; g < h.length; g++) if (p[g] && _[g] !== h[g]) { const m = n.concat([g]); c.push({ op: e, path: m, // 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: o(_[g]) }), u.push({ op: e, path: m, value: o(h[g]) }); } for (let g = h.length; g < _.length; g++) { const m = n.concat([g]); c.push({ op: t, path: m, // 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: o(_[g]) }); } h.length < _.length && u.push({ op: e, path: n.concat(["length"]), value: h.length }); } function a(r, n, c, u) { const { base_: h, copy_: p } = r; z(r.assigned_, (_, g) => { const m = Y(h, _), ie = Y(p, _), j = g ? x(h, _) ? e : t : s; if (m === ie && j === e) return; const R = n.concat(_); c.push(j === s ? { op: j, path: R } : { op: j, path: R, value: ie }), u.push( j === t ? { op: s, path: R } : j === s ? { op: t, path: R, value: o(m) } : { op: e, path: R, value: o(m) } ); }); } function b(r, n, c, u) { let { base_: h, copy_: p } = r, _ = 0; h.forEach((g) => { if (!p.has(g)) { const m = n.concat([_]); c.push({ op: s, path: m, value: g }), u.unshift({ op: t, path: m, value: g }); } _++; }), _ = 0, p.forEach((g) => { if (!h.has(g)) { const m = n.concat([_]); c.push({ op: t, path: m, value: g }), u.unshift({ op: s, path: m, value: g }); } _++; }); } function O(r, n, c, u) { c.push({ op: e, path: [], value: n === ne ? void 0 : n }), u.push({ op: e, path: [], value: r }); } function l(r, n) { return n.forEach((c) => { const { path: u, op: h } = c; let p = r; const _ = C(p), g = y(c.value), m = u[u.length - 1]; switch (h) { case e: switch (_) { case S.Map: return p.set(m, g); /* istanbul ignore next */ case S.Set: //die(16) default: return p[m] = g; } case t: switch (_) { case S.Array: return m === "-" ? p.push(g) : p.splice(m, 0, g); case S.Map: return p.set(m, g); case S.Set: return p.add(g); default: return p[m] = g; } case s: switch (_) { case S.Array: return p.splice(m, 1); case S.Map: return p.delete(m); case S.Set: return p.delete(c.value); default: return delete p[m]; } } }), r; } function y(r) { if (!M(r)) return r; if (Array.isArray(r)) return r.map(y); if (W(r)) return new Map( Array.from(r.entries()).map(([c, u]) => [c, y(u)]) ); if (q(r)) return new Set(Array.from(r).map(y)); const n = Object.create(Object.getPrototypeOf(r)); for (const c in r) n[c] = y(r[c]); return x(r, I) && (n[I] = r[I]), n; } function o(r) { return D(r) ? y(r) : r; } se("Patches", { applyPatches_: l, generatePatches_: i, generateReplacementPatches_: O }); } export { S as Archtype, I as DRAFTABLE, d as DRAFT_STATE, je as ImmutableManage, ne as NOTHING, Fe as Nothing, P as ProxyType, k as createProxy, ge as createProxyDraft, he as current, z as eachProperty, Ce as enableAllPlugins, Me as enableES5, ze as enableMapSet, xe as enablePatches, fe as enterScope, ee as freeze, C as getArchtype, K as getCurrentScope, le as getOwnPropertyDescriptors, E as getPlugin, Y as getProperty, we as hasMap, x as hasProperty, Ee as hasProxies, Ae as hasSet, D as isDraft, M as isDraftable, de as isEqual, te as isFrozen, W as isMap, Se as isPlainObject, q as isSet, $ as iteratorSymbol, w as latest, X as leaveScope, se as loadPlugin, A as markChanged, J as objectTraps, ve as originalState, F as ownKeys, Q as prepareCopy, G as processResult, U as revokeScope, _e as setProperty, V as shallowCopy, T as usePatchesInScope };