state-jet 2.4.11 → 2.4.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e=require("react"),t=Symbol.for("immer-nothing"),r=Symbol.for("immer-draftable"),n=Symbol.for("immer-state"),o="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){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 '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"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(e){return`'current' expects a draft, got: ${e}`},"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(e){return`'original' expects a draft, got: ${e}`}]:[];function s(e,...t){if("production"!==process.env.NODE_ENV){const r=o[e],n="function"==typeof r?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var a=Object.getPrototypeOf;function i(e){return!!e&&!!e[n]}function c(e){return!!e&&(f(e)||Array.isArray(e)||!!e[r]||!!e.constructor?.[r]||y(e)||h(e))}var u=Object.prototype.constructor.toString();function f(e){if(!e||"object"!=typeof e)return!1;const t=a(e);if(null===t)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===u}function l(e,t){0===p(e)?Reflect.ownKeys(e).forEach((r=>{t(r,e[r],e)})):e.forEach(((r,n)=>t(n,r,e)))}function p(e){const t=e[n];return t?t.type_:Array.isArray(e)?1:y(e)?2:h(e)?3:0}function d(e,t){return 2===p(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function _(e,t,r){const n=p(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function y(e){return e instanceof Map}function h(e){return e instanceof Set}function b(e){return e.copy_||e.base_}function m(e,t){if(y(e))return new Map(e);if(h(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=f(e);if(!0===t||"class_only"===t&&!r){const t=Object.getOwnPropertyDescriptors(e);delete t[n];let r=Reflect.ownKeys(t);for(let n=0;n<r.length;n++){const o=r[n],s=t[o];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[o]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[o]})}return Object.create(a(e),t)}{const t=a(e);if(null!==t&&r)return{...e};const n=Object.create(t);return Object.assign(n,e)}}function v(e,t=!1){return S(e)||i(e)||!c(e)||(p(e)>1&&(e.set=e.add=e.clear=e.delete=g),Object.freeze(e),t&&Object.entries(e).forEach((([e,t])=>v(t,!0)))),e}function g(){s(2)}function S(e){return Object.isFrozen(e)}var w,O={};function P(e){const t=O[e];return t||s(0,e),t}function z(){return w}function E(e,t){t&&(P("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function D(e){N(e),e.drafts_.forEach(x),e.drafts_=null}function N(e){e===w&&(w=e.parent_)}function j(e){return w=function(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}(w,e)}function x(e){const t=e[n];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function A(e,r){r.unfinalizedDrafts_=r.drafts_.length;const o=r.drafts_[0];return void 0!==e&&e!==o?(o[n].modified_&&(D(r),s(4)),c(e)&&(e=F(r,e),r.parent_||C(r,e)),r.patches_&&P("Patches").generateReplacementPatches_(o[n].base_,e,r.patches_,r.inversePatches_)):e=F(r,o,[]),D(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==t?e:void 0}function F(e,t,r){if(S(t))return t;const o=t[n];if(!o)return l(t,((n,s)=>I(e,o,t,n,s,r))),t;if(o.scope_!==e)return t;if(!o.modified_)return C(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;const t=o.copy_;let n=t,s=!1;3===o.type_&&(n=new Set(t),t.clear(),s=!0),l(n,((n,a)=>I(e,o,t,n,a,r,s))),C(e,t,!1),r&&e.patches_&&P("Patches").generatePatches_(o,r,e.patches_,e.inversePatches_)}return o.copy_}function I(e,t,r,n,o,a,u){if("production"!==process.env.NODE_ENV&&o===r&&s(5),i(o)){const s=F(e,o,a&&t&&3!==t.type_&&!d(t.assigned_,n)?a.concat(n):void 0);if(_(r,n,s),!i(s))return;e.canAutoFreeze_=!1}else u&&r.add(o);if(c(o)&&!S(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;F(e,o),(!t||!t.scope_.parent_)&&"symbol"!=typeof n&&Object.prototype.propertyIsEnumerable.call(r,n)&&C(e,o)}}function C(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&v(t,r)}var M={get(e,t){if(t===n)return e;const r=b(e);if(!d(r,t))return function(e,t,r){const n=R(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}(e,r,t);const o=r[t];return e.finalized_||!c(o)?o:o===$(e.base_,t)?(V(e),e.copy_[t]=U(o,e)):o},has:(e,t)=>t in b(e),ownKeys:e=>Reflect.ownKeys(b(e)),set(e,t,r){const o=R(b(e),t);if(o?.set)return o.set.call(e.draft_,r),!0;if(!e.modified_){const o=$(b(e),t),s=o?.[n];if(s&&s.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}(r,o)&&(void 0!==r||d(e.base_,t)))return!0;V(e),k(e)}return e.copy_[t]===r&&(void 0!==r||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty:(e,t)=>(void 0!==$(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,V(e),k(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const r=b(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}},defineProperty(){s(11)},getPrototypeOf:e=>a(e.base_),setPrototypeOf(){s(12)}},T={};function $(e,t){const r=e[n];return(r?b(r):e)[t]}function R(e,t){if(!(t in e))return;let r=a(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=a(r)}}function k(e){e.modified_||(e.modified_=!0,e.parent_&&k(e.parent_))}function V(e){e.copy_||(e.copy_=m(e.base_,e.scope_.immer_.useStrictShallowCopy_))}l(M,((e,t)=>{T[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),T.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&s(13),T.set.call(this,e,t,void 0)},T.set=function(e,t,r){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&s(14),M.set.call(this,e[0],t,r,e[0])};function U(e,t){const r=y(e)?P("MapSet").proxyMap_(e,t):h(e)?P("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:z(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,s=M;r&&(o=[n],s=T);const{revoke:a,proxy:i}=Proxy.revocable(o,s);return n.draft_=i,n.revoke_=a,i}(e,t);return(t?t.scope_:z()).drafts_.push(r),r}function J(e){if(!c(e)||S(e))return e;const t=e[n];let r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=m(e,t.scope_.immer_.useStrictShallowCopy_)}else r=m(e,!0);return l(r,((e,t)=>{_(r,e,J(t))})),t&&(t.finalized_=!1),r}var K=new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(e,r,n)=>{if("function"==typeof e&&"function"!=typeof r){const t=r;r=e;const n=this;return function(e=t,...o){return n.produce(e,(e=>r.call(this,e,...o)))}}let o;if("function"!=typeof r&&s(6),void 0!==n&&"function"!=typeof n&&s(7),c(e)){const t=j(this),s=U(e,void 0);let a=!0;try{o=r(s),a=!1}finally{a?D(t):N(t)}return E(t,n),A(o,t)}if(!e||"object"!=typeof e){if(o=r(e),void 0===o&&(o=e),o===t&&(o=void 0),this.autoFreeze_&&v(o,!0),n){const t=[],r=[];P("Patches").generateReplacementPatches_(e,o,t,r),n(t,r)}return o}s(1,e)},this.produceWithPatches=(e,t)=>{if("function"==typeof e)return(t,...r)=>this.produceWithPatches(t,(t=>e(t,...r)));let r,n;return[this.produce(e,t,((e,t)=>{r=e,n=t})),r,n]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){c(e)||s(8),i(e)&&(e=function(e){return i(e)||s(10,e),J(e)}(e));const t=j(this),r=U(e,void 0);return r[n].isManual_=!0,N(t),r}finishDraft(e,t){const r=e&&e[n];(!r||!r.isManual_)&&s(9);const{scope_:o}=r;return E(o,t),A(void 0,o)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));const n=P("Patches").applyPatches_;return i(e)?n(e,t):this.produce(e,(e=>n(e,t)))}},W=K.produce;K.produceWithPatches.bind(K),K.setAutoFreeze.bind(K),K.setUseStrictShallowCopy.bind(K),K.applyPatches.bind(K),K.createDraft.bind(K),K.finishDraft.bind(K);const L=(e=>{if(!1===e||null===e)throw new Error("Unable to locate global `this`");return e||globalThis})(),q=(e,t)=>{typeof L?.localStorage<"u"&&L.localStorage.setItem(e,JSON.stringify(t))},G=(e,t)=>{if(typeof L?.localStorage<"u"){const r=L.localStorage?.getItem(e);return r?JSON.parse(r):t}return t},X=(e,t)=>{typeof L?.localStorage<"u"&&L.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},B=(e,t)=>{if(typeof L?.localStorage<"u"){const r=L.localStorage?.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t},H={},Q={},Y={},Z=L.__STATE_JET_DEVTOOLS__,ee=(e,t)=>{H[e]||(H[e]=[]),void 0===Q[e]&&(Q[e]=-1),H[e]=H[e].slice(0,Q[e]+1),H[e].push(t),Q[e]++,Z?.updateState&&Z.updateState(e,t,[...H[e]])},te=(e,t)=>{Y[e]||(Y[e]=[]);const r=performance.now();t();const n=performance.now()-r;Y[e].push(n),Z?.updatePerformance&&Z.updatePerformance(e,n)},re=new Map,ne=new Map,oe={},se=new Map;let ae=!1;function ie(t){return re.has(t)||re.set(t,{}),function(r,n,o){const s=re.get(t),a=`${t}:${r}`;if(se.has(a))return se.get(a);s[r]||(s[r]={value:n,listeners:new Set,...o});const i=s[r],c={useState:()=>(e.useEffect((()=>{if(i.persist&&!i.restored){i.restored=!0;const e=i.encrypt?B(a,n):G(a,n);if(e!==n){i.value=e;for(const e of i.listeners)e()}}}),[n]),e.useSyncExternalStore((e=>(i.listeners.add(e),()=>i.listeners.delete(e))),(()=>i.value),(()=>n))),set:async(e,t=!1)=>{if(t){oe[a]||(oe[a]={past:[],present:i.value,future:[]}),oe[a].past.push(i.value),i.value="function"==typeof e?W(i.value,e):e,oe[a].present=i.value,oe[a].future=[];for(const e of i.listeners)e();ee(a,i.value)}else ne.set(a,e),ae||(ae=!0,await async function(){for(;ne.size>0;){const e=Array.from(ne.entries());ne.clear();for(const[t,r]of e){const[e,n]=t.split(":"),o=re.get(e);if(!o)continue;const s=o[n];if(!s)continue;let a=r;const i=s.value;if(oe[t]||(oe[t]={past:[],present:i,future:[]}),oe[t].past.push(i),oe[t].present=a,oe[t].future=[],s.middleware)for(const e of s.middleware)try{const r=e(t,i,a,(e=>{a=e}));if(r instanceof Promise){const e=await r;void 0!==e&&(a=e)}else void 0!==r&&(a=r)}catch(e){console.error(e)}s.value="function"==typeof a?W(s.value,a):a;for(const e of s.listeners)e();ee(t,s.value),te(t,(()=>{})),s.persist&&(s.encrypt?X(t,s.value):q(t,s.value))}}ae=!1}())},get:()=>i.value,undo:()=>{const e=oe[a];if(e&&e.past.length){e.future.unshift(e.present),e.present=e.past.pop(),i.value=e.present;for(const e of i.listeners)e();(e=>{if(Q[e]>0)Q[e]--,H[e][Q[e]]})(a),ee(`${t}.undo`,i.value)}},redo:()=>{const e=oe[a];if(e&&e.future.length){e.past.push(e.present),e.present=e.future.shift(),i.value=e.present;for(const e of i.listeners)e();(e=>{if(Q[e]<H[e]?.length-1)Q[e]++,H[e][Q[e]]})(a),ee(`${t}.redo`,i.value)}},clear:()=>{i.value=n;for(const e of i.listeners)e();ee(`${t}.clear`,n)}};return se.set(a,c),c}}const ce=(e,t)=>({...e,...t,lastUpdated:Date.now()});exports.VERSION="2.4.0",exports.derivedState=(e,t)=>()=>{const r=e.map((e=>e.useState()));return t(...r)},exports.mergeCRDT=ce,exports.optimisticUpdate=async(e,t,r,n)=>{const o=e.useState(),s=t(o);e.set(s);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},exports.restoreEncryptedState=B,exports.restoreState=G,exports.saveEncryptedState=X,exports.saveState=q,exports.syncCRDT=(e,t,r)=>{const n=t();r(ce(n,e))},exports.useSlice=ie,exports.useStateGlobal=function(e,t,r){return ie("global")(e,t,r)},exports.useStore=function(t){const r=e.useRef(null);return r.current||(r.current=t()),r.current};
1
+ "use strict";var e=require("react"),t=Symbol.for("immer-nothing"),r=Symbol.for("immer-draftable"),n=Symbol.for("immer-state"),o="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){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 '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"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(e){return`'current' expects a draft, got: ${e}`},"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(e){return`'original' expects a draft, got: ${e}`}]:[];function s(e,...t){if("production"!==process.env.NODE_ENV){const r=o[e],n="function"==typeof r?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var a=Object.getPrototypeOf;function i(e){return!!e&&!!e[n]}function c(e){return!!e&&(l(e)||Array.isArray(e)||!!e[r]||!!e.constructor?.[r]||h(e)||b(e))}var u=Object.prototype.constructor.toString(),f=new WeakMap;function l(e){if(!e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);if(null===t||t===Object.prototype)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(r===Object)return!0;if("function"!=typeof r)return!1;let n=f.get(r);return void 0===n&&(n=Function.toString.call(r),f.set(r,n)),n===u}function p(e,t,r=!0){0===d(e)?(r?Reflect.ownKeys(e):Object.keys(e)).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function d(e){const t=e[n];return t?t.type_:Array.isArray(e)?1:h(e)?2:b(e)?3:0}function _(e,t){return 2===d(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function y(e,t,r){const n=d(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function h(e){return e instanceof Map}function b(e){return e instanceof Set}function m(e){return e.copy_||e.base_}function v(e,t){if(h(e))return new Map(e);if(b(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=l(e);if(!0===t||"class_only"===t&&!r){const t=Object.getOwnPropertyDescriptors(e);delete t[n];let r=Reflect.ownKeys(t);for(let n=0;n<r.length;n++){const o=r[n],s=t[o];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[o]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[o]})}return Object.create(a(e),t)}{const t=a(e);if(null!==t&&r)return{...e};const n=Object.create(t);return Object.assign(n,e)}}function g(e,t=!1){return w(e)||i(e)||!c(e)||(d(e)>1&&Object.defineProperties(e,{set:S,add:S,clear:S,delete:S}),Object.freeze(e),t&&Object.values(e).forEach(e=>g(e,!0))),e}var S={value:function(){s(2)}};function w(e){return null===e||"object"!=typeof e||Object.isFrozen(e)}var O,P={};function j(e){const t=P[e];return t||s(0,e),t}function E(){return O}function z(e,t){t&&(j("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function I(e){N(e),e.drafts_.forEach(x),e.drafts_=null}function N(e){e===O&&(O=e.parent_)}function D(e){return O=function(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}(O,e)}function x(e){const t=e[n];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function A(e,r){r.unfinalizedDrafts_=r.drafts_.length;const o=r.drafts_[0];return void 0!==e&&e!==o?(o[n].modified_&&(I(r),s(4)),c(e)&&(e=F(r,e),r.parent_||T(r,e)),r.patches_&&j("Patches").generateReplacementPatches_(o[n].base_,e,r.patches_,r.inversePatches_)):e=F(r,o,[]),I(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==t?e:void 0}function F(e,t,r){if(w(t))return t;const o=e.immer_.shouldUseStrictIteration(),s=t[n];if(!s)return p(t,(n,o)=>M(e,s,t,n,o,r),o),t;if(s.scope_!==e)return t;if(!s.modified_)return T(e,s.base_,!0),s.base_;if(!s.finalized_){s.finalized_=!0,s.scope_.unfinalizedDrafts_--;const t=s.copy_;let n=t,a=!1;3===s.type_&&(n=new Set(t),t.clear(),a=!0),p(n,(n,o)=>M(e,s,t,n,o,r,a),o),T(e,t,!1),r&&e.patches_&&j("Patches").generatePatches_(s,r,e.patches_,e.inversePatches_)}return s.copy_}function M(e,t,r,n,o,a,u){if(null==o||"object"!=typeof o&&!u)return;const f=w(o);if(!f||u){if("production"!==process.env.NODE_ENV&&o===r&&s(5),i(o)){const s=F(e,o,a&&t&&3!==t.type_&&!_(t.assigned_,n)?a.concat(n):void 0);if(y(r,n,s),!i(s))return;e.canAutoFreeze_=!1}else u&&r.add(o);if(c(o)&&!f){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[n]===o&&f)return;F(e,o),(!t||!t.scope_.parent_)&&"symbol"!=typeof n&&(h(r)?r.has(n):Object.prototype.propertyIsEnumerable.call(r,n))&&T(e,o)}}}function T(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&g(t,r)}var $={get(e,t){if(t===n)return e;const r=m(e);if(!_(r,t))return function(e,t,r){const n=R(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}(e,r,t);const o=r[t];return e.finalized_||!c(o)?o:o===k(e.base_,t)?(V(e),e.copy_[t]=J(o,e)):o},has:(e,t)=>t in m(e),ownKeys:e=>Reflect.ownKeys(m(e)),set(e,t,r){const o=R(m(e),t);if(o?.set)return o.set.call(e.draft_,r),!0;if(!e.modified_){const o=k(m(e),t),s=o?.[n];if(s&&s.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}(r,o)&&(void 0!==r||_(e.base_,t)))return!0;V(e),U(e)}return e.copy_[t]===r&&(void 0!==r||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty:(e,t)=>(void 0!==k(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,V(e),U(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const r=m(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}},defineProperty(){s(11)},getPrototypeOf:e=>a(e.base_),setPrototypeOf(){s(12)}},C={};function k(e,t){const r=e[n];return(r?m(r):e)[t]}function R(e,t){if(!(t in e))return;let r=a(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=a(r)}}function U(e){e.modified_||(e.modified_=!0,e.parent_&&U(e.parent_))}function V(e){e.copy_||(e.copy_=v(e.base_,e.scope_.immer_.useStrictShallowCopy_))}p($,(e,t)=>{C[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),C.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&s(13),C.set.call(this,e,t,void 0)},C.set=function(e,t,r){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&s(14),$.set.call(this,e[0],t,r,e[0])};function J(e,t){const r=h(e)?j("MapSet").proxyMap_(e,t):b(e)?j("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:E(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,s=$;r&&(o=[n],s=C);const{revoke:a,proxy:i}=Proxy.revocable(o,s);return n.draft_=i,n.revoke_=a,i}(e,t);return(t?t.scope_:E()).drafts_.push(r),r}function K(e){if(!c(e)||w(e))return e;const t=e[n];let r,o=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=v(e,t.scope_.immer_.useStrictShallowCopy_),o=t.scope_.immer_.shouldUseStrictIteration()}else r=v(e,!0);return p(r,(e,t)=>{y(r,e,K(t))},o),t&&(t.finalized_=!1),r}var W=(new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(e,r,n)=>{if("function"==typeof e&&"function"!=typeof r){const t=r;r=e;const n=this;return function(e=t,...o){return n.produce(e,e=>r.call(this,e,...o))}}let o;if("function"!=typeof r&&s(6),void 0!==n&&"function"!=typeof n&&s(7),c(e)){const t=D(this),s=J(e,void 0);let a=!0;try{o=r(s),a=!1}finally{a?I(t):N(t)}return z(t,n),A(o,t)}if(!e||"object"!=typeof e){if(o=r(e),void 0===o&&(o=e),o===t&&(o=void 0),this.autoFreeze_&&g(o,!0),n){const t=[],r=[];j("Patches").generateReplacementPatches_(e,o,t,r),n(t,r)}return o}s(1,e)},this.produceWithPatches=(e,t)=>{if("function"==typeof e)return(t,...r)=>this.produceWithPatches(t,t=>e(t,...r));let r,n;return[this.produce(e,t,(e,t)=>{r=e,n=t}),r,n]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),"boolean"==typeof e?.useStrictIteration&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){c(e)||s(8),i(e)&&(e=function(e){return i(e)||s(10,e),K(e)}(e));const t=D(this),r=J(e,void 0);return r[n].isManual_=!0,N(t),r}finishDraft(e,t){const r=e&&e[n];(!r||!r.isManual_)&&s(9);const{scope_:o}=r;return z(o,t),A(void 0,o)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));const n=j("Patches").applyPatches_;return i(e)?n(e,t):this.produce(e,e=>n(e,t))}}).produce;const L=(e=>{if(!1===e||null===e)throw new Error("Unable to locate global `this`");return e||globalThis})(),q=(e,t)=>{typeof L?.localStorage<"u"&&L.localStorage.setItem(e,JSON.stringify(t))},G=(e,t)=>{if(typeof L?.localStorage<"u"){const r=L.localStorage?.getItem(e);return r?JSON.parse(r):t}return t},X=(e,t)=>{typeof L?.localStorage<"u"&&L.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},B=(e,t)=>{if(typeof L?.localStorage<"u"){const r=L.localStorage?.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t},H={},Q={},Y={},Z=L.__STATE_JET_DEVTOOLS__,ee=(e,t)=>{H[e]||(H[e]=[]),void 0===Q[e]&&(Q[e]=-1),H[e]=H[e].slice(0,Q[e]+1),H[e].push(t),Q[e]++,Z?.updateState&&Z.updateState(e,t,[...H[e]])},te=(e,t)=>{Y[e]||(Y[e]=[]);const r=performance.now();t();const n=performance.now()-r;Y[e].push(n),Z?.updatePerformance&&Z.updatePerformance(e,n)},re=new Map,ne=new Map,oe={},se=new Map;let ae=!1;function ie(t){return re.has(t)||re.set(t,{}),function(r,n,o){const s=re.get(t),a=`${t}:${r}`;if(se.has(a))return se.get(a);s[r]||(s[r]={value:n,listeners:new Set,...o});const i=s[r],c={useState:()=>(e.useEffect(()=>{if(i.persist&&!i.restored){i.restored=!0;const e=i.encrypt?B(a,n):G(a,n);if(e!==n){i.value=e;for(const e of i.listeners)e()}}},[n]),e.useSyncExternalStore(e=>(i.listeners.add(e),()=>i.listeners.delete(e)),()=>i.value,()=>n)),set:async(e,t=!1)=>{if(t){oe[a]||(oe[a]={past:[],present:i.value,future:[]}),oe[a].past.push(i.value),i.value="function"==typeof e?W(i.value,e):e,oe[a].present=i.value,oe[a].future=[];for(const e of i.listeners)e();ee(a,i.value)}else ne.set(a,e),ae||(ae=!0,await async function(){for(;ne.size>0;){const e=Array.from(ne.entries());ne.clear();for(const[t,r]of e){const[e,n]=t.split(":"),o=re.get(e);if(!o)continue;const s=o[n];if(!s)continue;let a=r;const i=s.value;if(oe[t]||(oe[t]={past:[],present:i,future:[]}),oe[t].past.push(i),oe[t].present=a,oe[t].future=[],s.middleware)for(const e of s.middleware)try{const r=e(t,i,a,e=>{a=e});if(r instanceof Promise){const e=await r;void 0!==e&&(a=e)}else void 0!==r&&(a=r)}catch(e){console.error(e)}s.value="function"==typeof a?W(s.value,a):a;for(const e of s.listeners)e();ee(t,s.value),te(t,()=>{}),s.persist&&(s.encrypt?X(t,s.value):q(t,s.value))}}ae=!1}())},get:()=>i.value,undo:()=>{const e=oe[a];if(e&&e.past.length){e.future.unshift(e.present),e.present=e.past.pop(),i.value=e.present;for(const e of i.listeners)e();(e=>{if(Q[e]>0)Q[e]--,H[e][Q[e]]})(a),ee(`${t}.undo`,i.value)}},redo:()=>{const e=oe[a];if(e&&e.future.length){e.past.push(e.present),e.present=e.future.shift(),i.value=e.present;for(const e of i.listeners)e();(e=>{if(Q[e]<H[e]?.length-1)Q[e]++,H[e][Q[e]]})(a),ee(`${t}.redo`,i.value)}},clear:()=>{i.value=n;for(const e of i.listeners)e();ee(`${t}.clear`,n)}};return se.set(a,c),c}}const ce=(e,t)=>({...e,...t,lastUpdated:Date.now()});exports.VERSION="2.4.0",exports.derivedState=(e,t)=>()=>{const r=e.map(e=>e.useState());return t(...r)},exports.mergeCRDT=ce,exports.optimisticUpdate=async(e,t,r,n)=>{const o=e.useState(),s=t(o);e.set(s);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},exports.restoreEncryptedState=B,exports.restoreState=G,exports.saveEncryptedState=X,exports.saveState=q,exports.syncCRDT=(e,t,r)=>{const n=t();r(ce(n,e))},exports.useSlice=ie,exports.useStateGlobal=function(e,t,r){return ie("global")(e,t,r)},exports.useStore=function(t){const r=e.useRef(null);return r.current||(r.current=t()),r.current};
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{useRef as e,useEffect as t,useSyncExternalStore as r}from"react";var n=Symbol.for("immer-nothing"),o=Symbol.for("immer-draftable"),a=Symbol.for("immer-state"),s="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){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 '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"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(e){return`'current' expects a draft, got: ${e}`},"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(e){return`'original' expects a draft, got: ${e}`}]:[];function i(e,...t){if("production"!==process.env.NODE_ENV){const r=s[e],n="function"==typeof r?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var c=Object.getPrototypeOf;function u(e){return!!e&&!!e[a]}function f(e){return!!e&&(p(e)||Array.isArray(e)||!!e[o]||!!e.constructor?.[o]||m(e)||b(e))}var l=Object.prototype.constructor.toString();function p(e){if(!e||"object"!=typeof e)return!1;const t=c(e);if(null===t)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return r===Object||"function"==typeof r&&Function.toString.call(r)===l}function d(e,t){0===_(e)?Reflect.ownKeys(e).forEach((r=>{t(r,e[r],e)})):e.forEach(((r,n)=>t(n,r,e)))}function _(e){const t=e[a];return t?t.type_:Array.isArray(e)?1:m(e)?2:b(e)?3:0}function y(e,t){return 2===_(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function h(e,t,r){const n=_(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function m(e){return e instanceof Map}function b(e){return e instanceof Set}function v(e){return e.copy_||e.base_}function g(e,t){if(m(e))return new Map(e);if(b(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=p(e);if(!0===t||"class_only"===t&&!r){const t=Object.getOwnPropertyDescriptors(e);delete t[a];let r=Reflect.ownKeys(t);for(let n=0;n<r.length;n++){const o=r[n],a=t[o];!1===a.writable&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(t[o]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[o]})}return Object.create(c(e),t)}{const t=c(e);if(null!==t&&r)return{...e};const n=Object.create(t);return Object.assign(n,e)}}function S(e,t=!1){return O(e)||u(e)||!f(e)||(_(e)>1&&(e.set=e.add=e.clear=e.delete=w),Object.freeze(e),t&&Object.entries(e).forEach((([e,t])=>S(t,!0)))),e}function w(){i(2)}function O(e){return Object.isFrozen(e)}var P,z={};function E(e){const t=z[e];return t||i(0,e),t}function D(){return P}function N(e,t){t&&(E("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function j(e){A(e),e.drafts_.forEach(I),e.drafts_=null}function A(e){e===P&&(P=e.parent_)}function F(e){return P=function(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}(P,e)}function I(e){const t=e[a];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function C(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];return void 0!==e&&e!==r?(r[a].modified_&&(j(t),i(4)),f(e)&&(e=M(t,e),t.parent_||$(t,e)),t.patches_&&E("Patches").generateReplacementPatches_(r[a].base_,e,t.patches_,t.inversePatches_)):e=M(t,r,[]),j(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==n?e:void 0}function M(e,t,r){if(O(t))return t;const n=t[a];if(!n)return d(t,((o,a)=>T(e,n,t,o,a,r))),t;if(n.scope_!==e)return t;if(!n.modified_)return $(e,n.base_,!0),n.base_;if(!n.finalized_){n.finalized_=!0,n.scope_.unfinalizedDrafts_--;const t=n.copy_;let o=t,a=!1;3===n.type_&&(o=new Set(t),t.clear(),a=!0),d(o,((o,s)=>T(e,n,t,o,s,r,a))),$(e,t,!1),r&&e.patches_&&E("Patches").generatePatches_(n,r,e.patches_,e.inversePatches_)}return n.copy_}function T(e,t,r,n,o,a,s){if("production"!==process.env.NODE_ENV&&o===r&&i(5),u(o)){const s=M(e,o,a&&t&&3!==t.type_&&!y(t.assigned_,n)?a.concat(n):void 0);if(h(r,n,s),!u(s))return;e.canAutoFreeze_=!1}else s&&r.add(o);if(f(o)&&!O(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;M(e,o),(!t||!t.scope_.parent_)&&"symbol"!=typeof n&&Object.prototype.propertyIsEnumerable.call(r,n)&&$(e,o)}}function $(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&S(t,r)}var R={get(e,t){if(t===a)return e;const r=v(e);if(!y(r,t))return function(e,t,r){const n=V(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}(e,r,t);const n=r[t];return e.finalized_||!f(n)?n:n===k(e.base_,t)?(J(e),e.copy_[t]=K(n,e)):n},has:(e,t)=>t in v(e),ownKeys:e=>Reflect.ownKeys(v(e)),set(e,t,r){const n=V(v(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const n=k(v(e),t),o=n?.[a];if(o&&o.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}(r,n)&&(void 0!==r||y(e.base_,t)))return!0;J(e),U(e)}return e.copy_[t]===r&&(void 0!==r||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty:(e,t)=>(void 0!==k(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,J(e),U(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const r=v(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}},defineProperty(){i(11)},getPrototypeOf:e=>c(e.base_),setPrototypeOf(){i(12)}},x={};function k(e,t){const r=e[a];return(r?v(r):e)[t]}function V(e,t){if(!(t in e))return;let r=c(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=c(r)}}function U(e){e.modified_||(e.modified_=!0,e.parent_&&U(e.parent_))}function J(e){e.copy_||(e.copy_=g(e.base_,e.scope_.immer_.useStrictShallowCopy_))}d(R,((e,t)=>{x[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),x.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&i(13),x.set.call(this,e,t,void 0)},x.set=function(e,t,r){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&i(14),R.set.call(this,e[0],t,r,e[0])};function K(e,t){const r=m(e)?E("MapSet").proxyMap_(e,t):b(e)?E("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:D(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,a=R;r&&(o=[n],a=x);const{revoke:s,proxy:i}=Proxy.revocable(o,a);return n.draft_=i,n.revoke_=s,i}(e,t);return(t?t.scope_:D()).drafts_.push(r),r}function W(e){if(!f(e)||O(e))return e;const t=e[a];let r;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=g(e,t.scope_.immer_.useStrictShallowCopy_)}else r=g(e,!0);return d(r,((e,t)=>{h(r,e,W(t))})),t&&(t.finalized_=!1),r}var L=new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.produce=(e,t,r)=>{if("function"==typeof e&&"function"!=typeof t){const r=t;t=e;const n=this;return function(e=r,...o){return n.produce(e,(e=>t.call(this,e,...o)))}}let o;if("function"!=typeof t&&i(6),void 0!==r&&"function"!=typeof r&&i(7),f(e)){const n=F(this),a=K(e,void 0);let s=!0;try{o=t(a),s=!1}finally{s?j(n):A(n)}return N(n,r),C(o,n)}if(!e||"object"!=typeof e){if(o=t(e),void 0===o&&(o=e),o===n&&(o=void 0),this.autoFreeze_&&S(o,!0),r){const t=[],n=[];E("Patches").generateReplacementPatches_(e,o,t,n),r(t,n)}return o}i(1,e)},this.produceWithPatches=(e,t)=>{if("function"==typeof e)return(t,...r)=>this.produceWithPatches(t,(t=>e(t,...r)));let r,n;return[this.produce(e,t,((e,t)=>{r=e,n=t})),r,n]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy)}createDraft(e){f(e)||i(8),u(e)&&(e=function(e){return u(e)||i(10,e),W(e)}(e));const t=F(this),r=K(e,void 0);return r[a].isManual_=!0,A(t),r}finishDraft(e,t){const r=e&&e[a];(!r||!r.isManual_)&&i(9);const{scope_:n}=r;return N(n,t),C(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));const n=E("Patches").applyPatches_;return u(e)?n(e,t):this.produce(e,(e=>n(e,t)))}},G=L.produce;L.produceWithPatches.bind(L),L.setAutoFreeze.bind(L),L.setUseStrictShallowCopy.bind(L),L.applyPatches.bind(L),L.createDraft.bind(L),L.finishDraft.bind(L);const q=(e=>{if(!1===e||null===e)throw new Error("Unable to locate global `this`");return e||globalThis})(),X=(e,t)=>{typeof q?.localStorage<"u"&&q.localStorage.setItem(e,JSON.stringify(t))},B=(e,t)=>{if(typeof q?.localStorage<"u"){const r=q.localStorage?.getItem(e);return r?JSON.parse(r):t}return t},H=(e,t)=>{typeof q?.localStorage<"u"&&q.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},Q=(e,t)=>{if(typeof q?.localStorage<"u"){const r=q.localStorage?.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t},Y={},Z={},ee={},te=q.__STATE_JET_DEVTOOLS__,re=(e,t)=>{Y[e]||(Y[e]=[]),void 0===Z[e]&&(Z[e]=-1),Y[e]=Y[e].slice(0,Z[e]+1),Y[e].push(t),Z[e]++,te?.updateState&&te.updateState(e,t,[...Y[e]])},ne=(e,t)=>{ee[e]||(ee[e]=[]);const r=performance.now();t();const n=performance.now()-r;ee[e].push(n),te?.updatePerformance&&te.updatePerformance(e,n)},oe=new Map,ae=new Map,se={},ie=new Map;let ce=!1;function ue(e){return oe.has(e)||oe.set(e,{}),function(n,o,a){const s=oe.get(e),i=`${e}:${n}`;if(ie.has(i))return ie.get(i);s[n]||(s[n]={value:o,listeners:new Set,...a});const c=s[n],u={useState:()=>(t((()=>{if(c.persist&&!c.restored){c.restored=!0;const e=c.encrypt?Q(i,o):B(i,o);if(e!==o){c.value=e;for(const e of c.listeners)e()}}}),[o]),r((e=>(c.listeners.add(e),()=>c.listeners.delete(e))),(()=>c.value),(()=>o))),set:async(e,t=!1)=>{if(t){se[i]||(se[i]={past:[],present:c.value,future:[]}),se[i].past.push(c.value),c.value="function"==typeof e?G(c.value,e):e,se[i].present=c.value,se[i].future=[];for(const e of c.listeners)e();re(i,c.value)}else ae.set(i,e),ce||(ce=!0,await async function(){for(;ae.size>0;){const e=Array.from(ae.entries());ae.clear();for(const[t,r]of e){const[e,n]=t.split(":"),o=oe.get(e);if(!o)continue;const a=o[n];if(!a)continue;let s=r;const i=a.value;if(se[t]||(se[t]={past:[],present:i,future:[]}),se[t].past.push(i),se[t].present=s,se[t].future=[],a.middleware)for(const e of a.middleware)try{const r=e(t,i,s,(e=>{s=e}));if(r instanceof Promise){const e=await r;void 0!==e&&(s=e)}else void 0!==r&&(s=r)}catch(e){console.error(e)}a.value="function"==typeof s?G(a.value,s):s;for(const e of a.listeners)e();re(t,a.value),ne(t,(()=>{})),a.persist&&(a.encrypt?H(t,a.value):X(t,a.value))}}ce=!1}())},get:()=>c.value,undo:()=>{const t=se[i];if(t&&t.past.length){t.future.unshift(t.present),t.present=t.past.pop(),c.value=t.present;for(const e of c.listeners)e();(e=>{if(Z[e]>0)Z[e]--,Y[e][Z[e]]})(i),re(`${e}.undo`,c.value)}},redo:()=>{const t=se[i];if(t&&t.future.length){t.past.push(t.present),t.present=t.future.shift(),c.value=t.present;for(const e of c.listeners)e();(e=>{if(Z[e]<Y[e]?.length-1)Z[e]++,Y[e][Z[e]]})(i),re(`${e}.redo`,c.value)}},clear:()=>{c.value=o;for(const e of c.listeners)e();re(`${e}.clear`,o)}};return ie.set(i,u),u}}function fe(e,t,r){return ue("global")(e,t,r)}function le(t){const r=e(null);return r.current||(r.current=t()),r.current}const pe=async(e,t,r,n)=>{const o=e.useState(),a=t(o);e.set(a);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},de=(e,t)=>({...e,...t,lastUpdated:Date.now()}),_e=(e,t,r)=>{const n=t();r(de(n,e))},ye=(e,t)=>()=>{const r=e.map((e=>e.useState()));return t(...r)},he="2.4.0";export{he as VERSION,ye as derivedState,de as mergeCRDT,pe as optimisticUpdate,Q as restoreEncryptedState,B as restoreState,H as saveEncryptedState,X as saveState,_e as syncCRDT,ue as useSlice,fe as useStateGlobal,le as useStore};
1
+ import{useRef as e,useEffect as t,useSyncExternalStore as r}from"react";var n=Symbol.for("immer-nothing"),o=Symbol.for("immer-draftable"),s=Symbol.for("immer-state"),a="production"!==process.env.NODE_ENV?[function(e){return`The plugin for '${e}' has not been loaded into Immer. To enable the plugin, import and call \`enable${e}()\` when initializing your application.`},function(e){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 '${e}'`},"This object has been frozen and should not be mutated",function(e){return"Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+e},"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(e){return`'current' expects a draft, got: ${e}`},"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(e){return`'original' expects a draft, got: ${e}`}]:[];function i(e,...t){if("production"!==process.env.NODE_ENV){const r=a[e],n="function"==typeof r?r.apply(null,t):r;throw new Error(`[Immer] ${n}`)}throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var c=Object.getPrototypeOf;function u(e){return!!e&&!!e[s]}function f(e){return!!e&&(d(e)||Array.isArray(e)||!!e[o]||!!e.constructor?.[o]||b(e)||v(e))}var l=Object.prototype.constructor.toString(),p=new WeakMap;function d(e){if(!e||"object"!=typeof e)return!1;const t=Object.getPrototypeOf(e);if(null===t||t===Object.prototype)return!0;const r=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(r===Object)return!0;if("function"!=typeof r)return!1;let n=p.get(r);return void 0===n&&(n=Function.toString.call(r),p.set(r,n)),n===l}function _(e,t,r=!0){0===y(e)?(r?Reflect.ownKeys(e):Object.keys(e)).forEach(r=>{t(r,e[r],e)}):e.forEach((r,n)=>t(n,r,e))}function y(e){const t=e[s];return t?t.type_:Array.isArray(e)?1:b(e)?2:v(e)?3:0}function h(e,t){return 2===y(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function m(e,t,r){const n=y(e);2===n?e.set(t,r):3===n?e.add(r):e[t]=r}function b(e){return e instanceof Map}function v(e){return e instanceof Set}function g(e){return e.copy_||e.base_}function S(e,t){if(b(e))return new Map(e);if(v(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const r=d(e);if(!0===t||"class_only"===t&&!r){const t=Object.getOwnPropertyDescriptors(e);delete t[s];let r=Reflect.ownKeys(t);for(let n=0;n<r.length;n++){const o=r[n],s=t[o];!1===s.writable&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[o]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[o]})}return Object.create(c(e),t)}{const t=c(e);if(null!==t&&r)return{...e};const n=Object.create(t);return Object.assign(n,e)}}function w(e,t=!1){return P(e)||u(e)||!f(e)||(y(e)>1&&Object.defineProperties(e,{set:O,add:O,clear:O,delete:O}),Object.freeze(e),t&&Object.values(e).forEach(e=>w(e,!0))),e}var O={value:function(){i(2)}};function P(e){return null===e||"object"!=typeof e||Object.isFrozen(e)}var j,E={};function z(e){const t=E[e];return t||i(0,e),t}function I(){return j}function N(e,t){t&&(z("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function D(e){A(e),e.drafts_.forEach(M),e.drafts_=null}function A(e){e===j&&(j=e.parent_)}function F(e){return j=function(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}(j,e)}function M(e){const t=e[s];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function T(e,t){t.unfinalizedDrafts_=t.drafts_.length;const r=t.drafts_[0];return void 0!==e&&e!==r?(r[s].modified_&&(D(t),i(4)),f(e)&&(e=$(t,e),t.parent_||k(t,e)),t.patches_&&z("Patches").generateReplacementPatches_(r[s].base_,e,t.patches_,t.inversePatches_)):e=$(t,r,[]),D(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==n?e:void 0}function $(e,t,r){if(P(t))return t;const n=e.immer_.shouldUseStrictIteration(),o=t[s];if(!o)return _(t,(n,s)=>C(e,o,t,n,s,r),n),t;if(o.scope_!==e)return t;if(!o.modified_)return k(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;const t=o.copy_;let s=t,a=!1;3===o.type_&&(s=new Set(t),t.clear(),a=!0),_(s,(n,s)=>C(e,o,t,n,s,r,a),n),k(e,t,!1),r&&e.patches_&&z("Patches").generatePatches_(o,r,e.patches_,e.inversePatches_)}return o.copy_}function C(e,t,r,n,o,s,a){if(null==o||"object"!=typeof o&&!a)return;const c=P(o);if(!c||a){if("production"!==process.env.NODE_ENV&&o===r&&i(5),u(o)){const a=$(e,o,s&&t&&3!==t.type_&&!h(t.assigned_,n)?s.concat(n):void 0);if(m(r,n,a),!u(a))return;e.canAutoFreeze_=!1}else a&&r.add(o);if(f(o)&&!c){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[n]===o&&c)return;$(e,o),(!t||!t.scope_.parent_)&&"symbol"!=typeof n&&(b(r)?r.has(n):Object.prototype.propertyIsEnumerable.call(r,n))&&k(e,o)}}}function k(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&w(t,r)}var R={get(e,t){if(t===s)return e;const r=g(e);if(!h(r,t))return function(e,t,r){const n=V(t,r);return n?"value"in n?n.value:n.get?.call(e.draft_):void 0}(e,r,t);const n=r[t];return e.finalized_||!f(n)?n:n===x(e.base_,t)?(K(e),e.copy_[t]=W(n,e)):n},has:(e,t)=>t in g(e),ownKeys:e=>Reflect.ownKeys(g(e)),set(e,t,r){const n=V(g(e),t);if(n?.set)return n.set.call(e.draft_,r),!0;if(!e.modified_){const n=x(g(e),t),o=n?.[s];if(o&&o.base_===r)return e.copy_[t]=r,e.assigned_[t]=!1,!0;if(function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}(r,n)&&(void 0!==r||h(e.base_,t)))return!0;K(e),J(e)}return e.copy_[t]===r&&(void 0!==r||t in e.copy_)||Number.isNaN(r)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=r,e.assigned_[t]=!0),!0},deleteProperty:(e,t)=>(void 0!==x(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,K(e),J(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0),getOwnPropertyDescriptor(e,t){const r=g(e),n=Reflect.getOwnPropertyDescriptor(r,t);return n&&{writable:!0,configurable:1!==e.type_||"length"!==t,enumerable:n.enumerable,value:r[t]}},defineProperty(){i(11)},getPrototypeOf:e=>c(e.base_),setPrototypeOf(){i(12)}},U={};function x(e,t){const r=e[s];return(r?g(r):e)[t]}function V(e,t){if(!(t in e))return;let r=c(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=c(r)}}function J(e){e.modified_||(e.modified_=!0,e.parent_&&J(e.parent_))}function K(e){e.copy_||(e.copy_=S(e.base_,e.scope_.immer_.useStrictShallowCopy_))}_(R,(e,t)=>{U[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),U.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&i(13),U.set.call(this,e,t,void 0)},U.set=function(e,t,r){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&i(14),R.set.call(this,e[0],t,r,e[0])};function W(e,t){const r=b(e)?z("MapSet").proxyMap_(e,t):v(e)?z("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:I(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,s=R;r&&(o=[n],s=U);const{revoke:a,proxy:i}=Proxy.revocable(o,s);return n.draft_=i,n.revoke_=a,i}(e,t);return(t?t.scope_:I()).drafts_.push(r),r}function L(e){if(!f(e)||P(e))return e;const t=e[s];let r,n=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,r=S(e,t.scope_.immer_.useStrictShallowCopy_),n=t.scope_.immer_.shouldUseStrictIteration()}else r=S(e,!0);return _(r,(e,t)=>{m(r,e,L(t))},n),t&&(t.finalized_=!1),r}var G=(new class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(e,t,r)=>{if("function"==typeof e&&"function"!=typeof t){const r=t;t=e;const n=this;return function(e=r,...o){return n.produce(e,e=>t.call(this,e,...o))}}let o;if("function"!=typeof t&&i(6),void 0!==r&&"function"!=typeof r&&i(7),f(e)){const n=F(this),s=W(e,void 0);let a=!0;try{o=t(s),a=!1}finally{a?D(n):A(n)}return N(n,r),T(o,n)}if(!e||"object"!=typeof e){if(o=t(e),void 0===o&&(o=e),o===n&&(o=void 0),this.autoFreeze_&&w(o,!0),r){const t=[],n=[];z("Patches").generateReplacementPatches_(e,o,t,n),r(t,n)}return o}i(1,e)},this.produceWithPatches=(e,t)=>{if("function"==typeof e)return(t,...r)=>this.produceWithPatches(t,t=>e(t,...r));let r,n;return[this.produce(e,t,(e,t)=>{r=e,n=t}),r,n]},"boolean"==typeof e?.autoFreeze&&this.setAutoFreeze(e.autoFreeze),"boolean"==typeof e?.useStrictShallowCopy&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),"boolean"==typeof e?.useStrictIteration&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){f(e)||i(8),u(e)&&(e=function(e){return u(e)||i(10,e),L(e)}(e));const t=F(this),r=W(e,void 0);return r[s].isManual_=!0,A(t),r}finishDraft(e,t){const r=e&&e[s];(!r||!r.isManual_)&&i(9);const{scope_:n}=r;return N(n,t),T(void 0,n)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let r;for(r=t.length-1;r>=0;r--){const n=t[r];if(0===n.path.length&&"replace"===n.op){e=n.value;break}}r>-1&&(t=t.slice(r+1));const n=z("Patches").applyPatches_;return u(e)?n(e,t):this.produce(e,e=>n(e,t))}}).produce;const q=(e=>{if(!1===e||null===e)throw new Error("Unable to locate global `this`");return e||globalThis})(),X=(e,t)=>{typeof q?.localStorage<"u"&&q.localStorage.setItem(e,JSON.stringify(t))},B=(e,t)=>{if(typeof q?.localStorage<"u"){const r=q.localStorage?.getItem(e);return r?JSON.parse(r):t}return t},H=(e,t)=>{typeof q?.localStorage<"u"&&q.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},Q=(e,t)=>{if(typeof q?.localStorage<"u"){const r=q.localStorage?.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t},Y={},Z={},ee={},te=q.__STATE_JET_DEVTOOLS__,re=(e,t)=>{Y[e]||(Y[e]=[]),void 0===Z[e]&&(Z[e]=-1),Y[e]=Y[e].slice(0,Z[e]+1),Y[e].push(t),Z[e]++,te?.updateState&&te.updateState(e,t,[...Y[e]])},ne=(e,t)=>{ee[e]||(ee[e]=[]);const r=performance.now();t();const n=performance.now()-r;ee[e].push(n),te?.updatePerformance&&te.updatePerformance(e,n)},oe=new Map,se=new Map,ae={},ie=new Map;let ce=!1;function ue(e){return oe.has(e)||oe.set(e,{}),function(n,o,s){const a=oe.get(e),i=`${e}:${n}`;if(ie.has(i))return ie.get(i);a[n]||(a[n]={value:o,listeners:new Set,...s});const c=a[n],u={useState:()=>(t(()=>{if(c.persist&&!c.restored){c.restored=!0;const e=c.encrypt?Q(i,o):B(i,o);if(e!==o){c.value=e;for(const e of c.listeners)e()}}},[o]),r(e=>(c.listeners.add(e),()=>c.listeners.delete(e)),()=>c.value,()=>o)),set:async(e,t=!1)=>{if(t){ae[i]||(ae[i]={past:[],present:c.value,future:[]}),ae[i].past.push(c.value),c.value="function"==typeof e?G(c.value,e):e,ae[i].present=c.value,ae[i].future=[];for(const e of c.listeners)e();re(i,c.value)}else se.set(i,e),ce||(ce=!0,await async function(){for(;se.size>0;){const e=Array.from(se.entries());se.clear();for(const[t,r]of e){const[e,n]=t.split(":"),o=oe.get(e);if(!o)continue;const s=o[n];if(!s)continue;let a=r;const i=s.value;if(ae[t]||(ae[t]={past:[],present:i,future:[]}),ae[t].past.push(i),ae[t].present=a,ae[t].future=[],s.middleware)for(const e of s.middleware)try{const r=e(t,i,a,e=>{a=e});if(r instanceof Promise){const e=await r;void 0!==e&&(a=e)}else void 0!==r&&(a=r)}catch(e){console.error(e)}s.value="function"==typeof a?G(s.value,a):a;for(const e of s.listeners)e();re(t,s.value),ne(t,()=>{}),s.persist&&(s.encrypt?H(t,s.value):X(t,s.value))}}ce=!1}())},get:()=>c.value,undo:()=>{const t=ae[i];if(t&&t.past.length){t.future.unshift(t.present),t.present=t.past.pop(),c.value=t.present;for(const e of c.listeners)e();(e=>{if(Z[e]>0)Z[e]--,Y[e][Z[e]]})(i),re(`${e}.undo`,c.value)}},redo:()=>{const t=ae[i];if(t&&t.future.length){t.past.push(t.present),t.present=t.future.shift(),c.value=t.present;for(const e of c.listeners)e();(e=>{if(Z[e]<Y[e]?.length-1)Z[e]++,Y[e][Z[e]]})(i),re(`${e}.redo`,c.value)}},clear:()=>{c.value=o;for(const e of c.listeners)e();re(`${e}.clear`,o)}};return ie.set(i,u),u}}function fe(e,t,r){return ue("global")(e,t,r)}function le(t){const r=e(null);return r.current||(r.current=t()),r.current}const pe=async(e,t,r,n)=>{const o=e.useState(),s=t(o);e.set(s);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},de=(e,t)=>({...e,...t,lastUpdated:Date.now()}),_e=(e,t,r)=>{const n=t();r(de(n,e))},ye=(e,t)=>()=>{const r=e.map(e=>e.useState());return t(...r)},he="2.4.0";export{he as VERSION,ye as derivedState,de as mergeCRDT,pe as optimisticUpdate,Q as restoreEncryptedState,B as restoreState,H as saveEncryptedState,X as saveState,_e as syncCRDT,ue as useSlice,fe as useStateGlobal,le as useStore};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-jet",
3
- "version": "2.4.11",
3
+ "version": "2.4.13",
4
4
  "description": "Ultra-lightweight global state management for React",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",