state-jet 1.0.13 β†’ 1.2.0

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/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  A zero-boilerplate, ultra-fast global state management library for React. No context, reducers, or providersβ€”just simple reactive state.
4
4
 
5
- For more details, see [here](https://statejet.netlify.app).
5
+ For more Information, see [here](https://statejet.netlify.app).
6
6
 
7
7
  ## πŸš€ Why state-jet?
8
+
8
9
  - βœ… **No Context, No Providers** – Works outside React, reducing unnecessary re-renders.
9
10
  - βœ… **Automatic Re-Renders** – Only components using specific state values update.
10
11
  - βœ… **Super Lightweight** – Ultra small!
@@ -19,6 +20,7 @@ Tutorials: https://statejet.netlify.app/docs/category/tutorial
19
20
  API Reference: https://statejet.netlify.app/docs/category/api-reference
20
21
 
21
22
  ## πŸ›  Installation
23
+
22
24
  The Statejet package lives in npm. Please see the [installation guide](https://statejet.netlify.app/docs/getting-started/installation-and-setup/).
23
25
 
24
26
  To install the latest stable version, run the following command:
@@ -26,6 +28,7 @@ To install the latest stable version, run the following command:
26
28
  ```bash
27
29
  npm install state-jet
28
30
  ```
31
+
29
32
  Or if you're using `yarn`:
30
33
 
31
34
  ```bash
@@ -38,7 +41,8 @@ Or if you're using `cdn`:
38
41
  <script src="https://cdn.jsdelivr.net/npm/state-jet@latest/dist/index.cjs"></script>
39
42
  ```
40
43
 
41
- ## Example Usage
44
+ ## Basic Example Usage
45
+
42
46
  ```bash
43
47
  import { useStateGlobal } from "state-jet";
44
48
 
@@ -52,17 +56,16 @@ function Counter() {
52
56
 
53
57
  ## ⚑ Comparison Table
54
58
 
55
- | Feature | Redux | Recoil | MobX | Jotai | Zustand | state-jet |
56
- | ------------------------ | ----------- | --------- | ------------- | --------- | ---------------------- | --------------------- |
57
- | Easy Setup | ❌ No | ❌ No | ⚠️ No | ❌ No | ⚠️ Minimal | βœ… Ultra-Minimal |
58
- | Bundle Size | πŸš€ Large | πŸš€ Medium | ⚑ Small | ⚑ Small | ⚑ Small | πŸ”₯ Ultra-Small |
59
- | Reactivity | ⚠️ Reducers | βœ… Atoms | βœ… Proxy-Based | βœ… Signals | βœ… Proxy-Based | βœ… Signal-Like |
60
- | Renders Only Affected | ❌ No | βœ… Yes | βœ… Yes | βœ… Yes | βœ… Yes | βœ… Yes |
61
- | Derived/Computed State | ❌ No | βœ… Yes | βœ… Yes | βœ… Yes | ⚠️ Manual Selectors | βœ… Yes (Automatic) |
62
- | Optimistic Updates | ❌ No | ❌ No | ❌ No | ❌ No | ⚠️ Requires Middleware | βœ… Built-in |
63
- | Undo/Redo | ❌ No | ❌ No | ❌ No | ❌ No | ⚠️ Requires Middleware | βœ… Built-in | |
64
- | CRDT Conflict Resolution | ❌ No | ❌ No | ❌ No | ❌ No | ❌ No | βœ… Yes |
65
-
59
+ | Feature | Redux | Recoil | MobX | Jotai | Zustand | state-jet |
60
+ | ------------------------ | ----------- | --------- | -------------- | ---------- | ---------------------- | ------------------ | --- |
61
+ | Easy Setup | ❌ No | ❌ No | ⚠️ No | ❌ No | ⚠️ Minimal | βœ… Ultra-Minimal |
62
+ | Bundle Size | πŸš€ Large | πŸš€ Medium | ⚑ Small | ⚑ Small | ⚑ Small | πŸ”₯ Ultra-Small |
63
+ | Reactivity | ⚠️ Reducers | βœ… Atoms | βœ… Proxy-Based | βœ… Signals | βœ… Proxy-Based | βœ… Signal-Like |
64
+ | Renders Only Affected | ❌ No | βœ… Yes | βœ… Yes | βœ… Yes | βœ… Yes | βœ… Yes |
65
+ | Derived/Computed State | ❌ No | βœ… Yes | βœ… Yes | βœ… Yes | ⚠️ Manual Selectors | βœ… Yes (Automatic) |
66
+ | Optimistic Updates | ❌ No | ❌ No | ❌ No | ❌ No | ⚠️ Requires Middleware | βœ… Built-in |
67
+ | Undo/Redo | ❌ No | ❌ No | ❌ No | ❌ No | ⚠️ Requires Middleware | βœ… Built-in | |
68
+ | CRDT Conflict Resolution | ❌ No | ❌ No | ❌ No | ❌ No | ❌ No | βœ… Yes |
66
69
 
67
70
  ## ⚑ Why state-jet Is More Advanced Than Zustand
68
71
 
@@ -77,6 +80,7 @@ function Counter() {
77
80
  If you need the simplest, fastest, and most advanced state management solution for React, state-jet beats Redux, Recoil, MobX, Jotai, and even Zustand in performance, reactivity, and developer experience. πŸš€
78
81
 
79
82
  ## 🎯 Why Use `optimisticUpdate`?
83
+
80
84
  | Feature | Without `optimisticUpdate` | With `optimisticUpdate` |
81
85
  | ----------------------- | -------------------------- | --------------------------- |
82
86
  | **UI Responsiveness** | Delayed (Waits for API) | Instant update (Optimistic) |
@@ -84,35 +88,33 @@ If you need the simplest, fastest, and most advanced state management solution f
84
88
  | **Rollback on Failure** | Manual Handling | Automatic |
85
89
  | **Code Complexity** | High | Low |
86
90
 
87
-
88
91
  ## 🎯 Why Use `syncCRDT`?
89
- | Feature | Without `syncCRDT` | With `syncCRDT` |
90
- | ---------------------- | ------------------ | ------------------------- |
92
+
93
+ | Feature | Without `syncCRDT` | With `syncCRDT` |
94
+ | ---------------------- | ------------------ | -------------------------- |
91
95
  | **Multi-User Sync** | Possible Conflicts | βœ… Automatic Merging |
92
96
  | **Real-Time Updates** | Needs Manual Fixes | βœ… No Data Loss |
93
97
  | **Handles Conflicts** | Can Lose Changes | βœ… Merges Automatically |
94
98
  | **Scalable for Teams** | Hard to Maintain | βœ… Ideal for Collaboration |
95
99
 
96
-
97
100
  ## 🎯 Why Use `derivedState`?
98
101
 
99
- | Feature | Without `derivedState` | With `derivedState` |
100
- | ------------------------- | -------------------------- | ----------------------------- |
102
+ | Feature | Without `derivedState` | With `derivedState` |
103
+ | ------------------------- | --------------------------- | ------------------------------ |
101
104
  | **Manual Recalculations** | ❌ Yes (Recompute manually) | βœ… Automatic |
102
105
  | **Reactivity** | ❌ Requires `useEffect` | βœ… Updates only when needed |
103
106
  | **Performance** | ❌ Unoptimized | βœ… Only recalculates on change |
104
107
  | **Code Complexity** | ❌ High | βœ… Minimal |
105
108
 
106
- ## 🎯 Why Use undo & redo?
109
+ ## 🎯 Why Use `undo & redo`?
107
110
 
108
- | Feature | Without Undo/Redo | With Undo/Redo |
109
- | ---------------------- | ----------------------- | ------------------------- |
111
+ | Feature | Without Undo/Redo | With Undo/Redo |
112
+ | ---------------------- | ------------------------ | -------------------------- |
110
113
  | **Accidental Changes** | ❌ Lost forever | βœ… Easily undone |
111
114
  | **User Experience** | ❌ Frustrating | βœ… Smooth & intuitive |
112
115
  | **Multi-Step Editing** | ❌ Hard to track | βœ… Easy to restore history |
113
116
  | **Performance** | ❌ Needs manual tracking | βœ… Automatic |
114
117
 
115
-
116
118
  ## Contributing
117
119
 
118
120
  Development of State-jet happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving State-jet.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "state-jet",
3
- "version": "1.0.13",
3
+ "version": "1.2.0",
4
4
  "description": "Ultra-lightweight global state management for React",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -21,14 +21,18 @@
21
21
  "type": "git",
22
22
  "url": "https://github.com/venkateshsundaram/state-jet.git"
23
23
  },
24
+ "homepage": "https://github.com/venkateshsundaram/state-jet",
24
25
  "keywords": [
25
26
  "react",
27
+ "state",
28
+ "redux",
26
29
  "state-management",
27
30
  "global-state",
31
+ "global-state-management",
28
32
  "signals",
29
33
  "state-jet",
30
- "state",
31
- "jet"
34
+ "jet",
35
+ "store"
32
36
  ],
33
37
  "author": "venkateshsundaram",
34
38
  "license": "MIT",
@@ -40,7 +44,49 @@
40
44
  "test": "vitest",
41
45
  "clean": "rimraf dist",
42
46
  "publish:npm": "npm publish --access public",
43
- "lint": "eslint src --ext .ts,.tsx"
47
+ "lint": "eslint src --ext .ts,.tsx",
48
+ "format": "prettier --write .",
49
+ "release": "standard-version",
50
+ "postrelease": "git push --follow-tags"
51
+ },
52
+ "husky": {
53
+ "hooks": {
54
+ "pre-commit": "lint-staged"
55
+ }
56
+ },
57
+ "lint-staged": {
58
+ "*.ts": [
59
+ "eslint --fix",
60
+ "prettier --write"
61
+ ]
62
+ },
63
+ "standard-version": {
64
+ "types": [
65
+ {
66
+ "type": "feat",
67
+ "section": "Features"
68
+ },
69
+ {
70
+ "type": "fix",
71
+ "section": "Bug Fixes"
72
+ },
73
+ {
74
+ "type": "chore",
75
+ "section": "Chores"
76
+ },
77
+ {
78
+ "type": "refactor",
79
+ "section": "Refactors"
80
+ },
81
+ {
82
+ "type": "docs",
83
+ "section": "Documentation"
84
+ },
85
+ {
86
+ "type": "test",
87
+ "section": "Testing"
88
+ }
89
+ ]
44
90
  },
45
91
  "devDependencies": {
46
92
  "@rollup/plugin-commonjs": "^28.0.2",
@@ -49,14 +95,22 @@
49
95
  "@types/react": "^19.0.10",
50
96
  "@types/react-dom": "^19.0.4",
51
97
  "@types/use-sync-external-store": "^0.0.6",
98
+ "@typescript-eslint/eslint-plugin": "^8.26.0",
99
+ "@typescript-eslint/parser": "^8.26.0",
52
100
  "eslint": "^8.57.1",
101
+ "eslint-plugin-react": "^7.37.4",
102
+ "eslint-plugin-react-hooks": "^5.2.0",
103
+ "husky": "^9.1.7",
53
104
  "immer": "^10.1.1",
105
+ "lint-staged": "^15.4.3",
106
+ "prettier": "^3.5.3",
54
107
  "react": "19.0.0",
55
108
  "react-dom": "19.0.0",
56
109
  "rimraf": "^5.0.10",
57
110
  "rollup": "^3.29.4",
58
111
  "rollup-plugin-dts": "^5.3.0",
59
112
  "rollup-plugin-esbuild": "^5.0.0",
113
+ "standard-version": "^9.5.0",
60
114
  "typescript": "^5.7.3",
61
115
  "vitest": "^2.1.8"
62
116
  },
package/dist/index.cjs DELETED
@@ -1,19 +0,0 @@
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 a(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 s=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=s(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 p(e,t){0===l(e)?Reflect.ownKeys(e).forEach((r=>{t(r,e[r],e)})):e.forEach(((r,n)=>t(n,r,e)))}function l(e){const t=e[n];return t?t.type_:Array.isArray(e)?1:y(e)?2:h(e)?3:0}function _(e,t){return 2===l(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function d(e,t,r){const n=l(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],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(s(e),t)}{const t=s(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)||i(e)||!c(e)||(l(e)>1&&(e.set=e.add=e.clear=e.delete=v),Object.freeze(e),t&&Object.entries(e).forEach((([e,t])=>S(t,!0)))),e}function v(){a(2)}function O(e){return Object.isFrozen(e)}var w,g={};function E(e){const t=g[e];return t||a(0,e),t}function T(){return w}function D(e,t){t&&(E("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function A(e){P(e),e.drafts_.forEach(x),e.drafts_=null}function P(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 N(e,r){r.unfinalizedDrafts_=r.drafts_.length;const o=r.drafts_[0];return void 0!==e&&e!==o?(o[n].modified_&&(A(r),a(4)),c(e)&&(e=z(r,e),r.parent_||F(r,e)),r.patches_&&E("Patches").generateReplacementPatches_(o[n].base_,e,r.patches_,r.inversePatches_)):e=z(r,o,[]),A(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==t?e:void 0}function z(e,t,r){if(O(t))return t;const o=t[n];if(!o)return p(t,((n,a)=>L(e,o,t,n,a,r))),t;if(o.scope_!==e)return t;if(!o.modified_)return F(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;const t=o.copy_;let n=t,a=!1;3===o.type_&&(n=new Set(t),t.clear(),a=!0),p(n,((n,s)=>L(e,o,t,n,s,r,a))),F(e,t,!1),r&&e.patches_&&E("Patches").generatePatches_(o,r,e.patches_,e.inversePatches_)}return o.copy_}function L(e,t,r,n,o,s,u){if("production"!==process.env.NODE_ENV&&o===r&&a(5),i(o)){const a=z(e,o,s&&t&&3!==t.type_&&!_(t.assigned_,n)?s.concat(n):void 0);if(d(r,n,a),!i(a))return;e.canAutoFreeze_=!1}else u&&r.add(o);if(c(o)&&!O(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;z(e,o),(!t||!t.scope_.parent_)&&"symbol"!=typeof n&&Object.prototype.propertyIsEnumerable.call(r,n)&&F(e,o)}}function F(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&S(t,r)}var I={get(e,t){if(t===n)return e;const r=b(e);if(!_(r,t))return function(e,t,r){const n=M(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===C(e.base_,t)?(K(e),e.copy_[t]=k(o,e)):o},has:(e,t)=>t in b(e),ownKeys:e=>Reflect.ownKeys(b(e)),set(e,t,r){const o=M(b(e),t);if(o?.set)return o.set.call(e.draft_,r),!0;if(!e.modified_){const o=C(b(e),t),a=o?.[n];if(a&&a.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;K(e),R(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!==C(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,K(e),R(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(){a(11)},getPrototypeOf:e=>s(e.base_),setPrototypeOf(){a(12)}},V={};function C(e,t){const r=e[n];return(r?b(r):e)[t]}function M(e,t){if(!(t in e))return;let r=s(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=s(r)}}function R(e){e.modified_||(e.modified_=!0,e.parent_&&R(e.parent_))}function K(e){e.copy_||(e.copy_=m(e.base_,e.scope_.immer_.useStrictShallowCopy_))}p(I,((e,t)=>{V[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),V.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&a(13),V.set.call(this,e,t,void 0)},V.set=function(e,t,r){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&a(14),I.set.call(this,e[0],t,r,e[0])};function k(e,t){const r=y(e)?E("MapSet").proxyMap_(e,t):h(e)?E("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:T(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,a=I;r&&(o=[n],a=V);const{revoke:s,proxy:i}=Proxy.revocable(o,a);return n.draft_=i,n.revoke_=s,i}(e,t);return(t?t.scope_:T()).drafts_.push(r),r}function J(e){if(!c(e)||O(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 p(r,((e,t)=>{d(r,e,J(t))})),t&&(t.finalized_=!1),r}var G=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&&a(6),void 0!==n&&"function"!=typeof n&&a(7),c(e)){const t=j(this),a=k(e,void 0);let s=!0;try{o=r(a),s=!1}finally{s?A(t):P(t)}return D(t,n),N(o,t)}if(!e||"object"!=typeof e){if(o=r(e),void 0===o&&(o=e),o===t&&(o=void 0),this.autoFreeze_&&S(o,!0),n){const t=[],r=[];E("Patches").generateReplacementPatches_(e,o,t,r),n(t,r)}return o}a(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)||a(8),i(e)&&(e=function(e){return i(e)||a(10,e),J(e)}(e));const t=j(this),r=k(e,void 0);return r[n].isManual_=!0,P(t),r}finishDraft(e,t){const r=e&&e[n];(!r||!r.isManual_)&&a(9);const{scope_:o}=r;return D(o,t),N(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=E("Patches").applyPatches_;return i(e)?n(e,t):this.produce(e,(e=>n(e,t)))}},U=G.produce;G.produceWithPatches.bind(G),G.setAutoFreeze.bind(G),G.setUseStrictShallowCopy.bind(G),G.applyPatches.bind(G),G.createDraft.bind(G),G.finishDraft.bind(G);const $=(()=>{if("object"==typeof globalThis&&globalThis)return globalThis;if("object"==typeof self&&self)return self;if("object"==typeof window&&window)return window;throw new Error("Unable to locate global `this`")})(),B=(e,t)=>{typeof $<"u"&&$.localStorage.setItem(e,JSON.stringify(t))},H=(e,t)=>{if(typeof $<"u"){const r=$.localStorage.getItem(e);return r?JSON.parse(r):t}return t},q=(e,t)=>{typeof $<"u"&&$.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},W=(e,t)=>{if(typeof $<"u"){const r=$.localStorage.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t};var X,Y={exports:{}},Q={};
2
- /**
3
- * @license React
4
- * use-sync-external-store-shim.production.js
5
- *
6
- * Copyright (c) Meta Platforms, Inc. and affiliates.
7
- *
8
- * This source code is licensed under the MIT license found in the
9
- * LICENSE file in the root directory of this source tree.
10
- */var Z,ee,te={};
11
- /**
12
- * @license React
13
- * use-sync-external-store-shim.development.js
14
- *
15
- * Copyright (c) Meta Platforms, Inc. and affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- */var re=(ee||(ee=1,"production"===process.env.NODE_ENV?Y.exports=function(){if(X)return Q;X=1;var t=e,r="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=t.useState,o=t.useEffect,a=t.useLayoutEffect,s=t.useDebugValue;function i(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,t){var r=t(),c=n({inst:{value:r,getSnapshot:t}}),u=c[0].inst,f=c[1];return a((function(){u.value=r,u.getSnapshot=t,i(u)&&f({inst:u})}),[e,r,t]),o((function(){return i(u)&&f({inst:u}),e((function(){i(u)&&f({inst:u})}))}),[e]),s(r),r};return Q.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:c,Q}():Y.exports=(Z||(Z=1,"production"!==process.env.NODE_ENV&&function(){function t(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch{return!0}}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=e,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useState,a=r.useEffect,s=r.useLayoutEffect,i=r.useDebugValue,c=!1,u=!1,f=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,f){c||void 0===r.startTransition||(c=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var p=f();if(!u){var l=f();n(p,l)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var _=(l=o({inst:{value:p,getSnapshot:f}}))[0].inst,d=l[1];return s((function(){_.value=p,_.getSnapshot=f,t(_)&&d({inst:_})}),[e,p,f]),a((function(){return t(_)&&d({inst:_}),e((function(){t(_)&&d({inst:_})}))}),[e]),i(p),p};te.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),te)),Y.exports);const ne={},oe={},ae={},se=typeof window<"u"&&window.__STATE_JET_DEVTOOLS__,ie=new Map,ce=new Map,ue={},fe=(e,t)=>({...e,...t,lastUpdated:Date.now()});exports.derivedState=(e,t)=>{const r={value:t(...e.map((e=>e.useStore())))};return e.forEach((n=>n.useStore().listeners.add((()=>{r.value=t(...e.map((e=>e.useStore())))})))),()=>r.value},exports.mergeCRDT=fe,exports.optimisticUpdate=async(e,t,r,n)=>{const o=e.useStore(),a=t(o);e.set(a);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},exports.restoreEncryptedState=W,exports.restoreState=H,exports.saveEncryptedState=q,exports.saveState=B,exports.syncCRDT=(e,t)=>{const r=t.useStore();t(fe(r,e))},exports.useStateGlobal=(e,t,r)=>{ie.has(e)||(ie.set(e,{value:t,listeners:new Set}),r?.persist&&(r?.encrypt?W(e,t):H(e,t)));const n=ie.get(e),o=()=>{ce.forEach(((e,t)=>{let o=e,a=n.value;ue[t]||(ue[t]={past:[],present:a,future:[]}),ue[t].past.push(a),ue[t].present=e,ue[t].future=[],r?.middleware?.forEach((e=>{const r=e(t,a,o);void 0!==r&&(o=r)})),"function"==typeof o?n.value=U(n.value,o):a!==o&&(n.value=o,n.listeners.forEach((e=>e())),((e,t)=>{ne[e]||(ne[e]=[]),void 0===oe[e]&&(oe[e]=-1),ne[e]=ne[e].slice(0,oe[e]+1),ne[e].push(t),oe[e]++,se&&window.__STATE_JET_DEVTOOLS__.updateState&&window.__STATE_JET_DEVTOOLS__.updateState(e,t,ne[e])})(t,o),((e,t)=>{const r=performance.now();t();const n=performance.now()-r;ae[e]||(ae[e]=[]),ae[e].push(n),se&&window.__STATE_JET_DEVTOOLS__.updatePerformance&&window.__STATE_JET_DEVTOOLS__.updatePerformance(e,n)})(t,(()=>{})),r?.persist&&(r?.encrypt?q(t,o):B(t,o)))})),ce.clear()};return{useStore:()=>re.useSyncExternalStore((e=>(n.listeners.add(e),()=>n.listeners.delete(e))),(()=>n.value)),set:t=>{ce.set(e,t),$?.requestAnimationFrame&&$.requestAnimationFrame(o)},undo:()=>{ue[e]?.past.length&&(ue[e].future.unshift(ue[e].present),ue[e].present=ue[e].past.pop(),n.value=ue[e].present,n.listeners.forEach((e=>e())),(e=>{if(oe[e]>0)oe[e]--,ne[e][oe[e]]})(e))},redo:()=>{ue[e]?.future.length&&(ue[e].past.push(ue[e].present),ue[e].present=ue[e].future.shift(),n.value=ue[e].present,n.listeners.forEach((e=>e())),(e=>{if(oe[e]<ne[e].length-1)oe[e]++,ne[e][oe[e]]})(e))}}};
package/dist/index.d.ts DELETED
@@ -1,31 +0,0 @@
1
- type Middleware<T> = (key: string, prev: T, next: T) => T | void;
2
- declare const useStateGlobal: <T>(key: string, initialValue?: T, options?: {
3
- middleware?: Middleware<T>[];
4
- persist?: boolean;
5
- encrypt?: boolean;
6
- }) => {
7
- useStore: () => any;
8
- set: (newValue: T) => void;
9
- undo: () => void;
10
- redo: () => void;
11
- };
12
-
13
- declare const saveState: (key: string, value: any) => void;
14
- declare const restoreState: (key: string, defaultValue?: any) => any;
15
-
16
- declare const optimisticUpdate: <T>(setState: {
17
- set: (value: T) => void;
18
- useStore: () => T;
19
- }, updateFn: (prevState: T) => T, apiCall: () => Promise<any>, rollbackFn?: (prevState: T) => T) => Promise<void>;
20
-
21
- declare const saveEncryptedState: (key: string, value: any) => void;
22
- declare const restoreEncryptedState: (key: string, defaultValue?: any) => any;
23
-
24
- declare const mergeCRDT: <T>(localState: T, remoteState: T) => T;
25
- declare const syncCRDT: <T>(remoteState: T, setState: any) => void;
26
-
27
- declare const derivedState: <T>(dependencies: {
28
- useStore: () => any;
29
- }[], computeFn: (...values: any[]) => T) => () => T;
30
-
31
- export { derivedState, mergeCRDT, optimisticUpdate, restoreEncryptedState, restoreState, saveEncryptedState, saveState, syncCRDT, useStateGlobal };
package/dist/index.mjs DELETED
@@ -1,19 +0,0 @@
1
- import e from"react";var 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 a(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 s=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=s(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 _(e,t){return 2===p(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function d(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],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(s(e),t)}{const t=s(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)||i(e)||!c(e)||(p(e)>1&&(e.set=e.add=e.clear=e.delete=v),Object.freeze(e),t&&Object.entries(e).forEach((([e,t])=>S(t,!0)))),e}function v(){a(2)}function O(e){return Object.isFrozen(e)}var w,g={};function E(e){const t=g[e];return t||a(0,e),t}function T(){return w}function D(e,t){t&&(E("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function A(e){P(e),e.drafts_.forEach(N),e.drafts_=null}function P(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 N(e){const t=e[n];0===t.type_||1===t.type_?t.revoke_():t.revoked_=!0}function z(e,r){r.unfinalizedDrafts_=r.drafts_.length;const o=r.drafts_[0];return void 0!==e&&e!==o?(o[n].modified_&&(A(r),a(4)),c(e)&&(e=L(r,e),r.parent_||F(r,e)),r.patches_&&E("Patches").generateReplacementPatches_(o[n].base_,e,r.patches_,r.inversePatches_)):e=L(r,o,[]),A(r),r.patches_&&r.patchListener_(r.patches_,r.inversePatches_),e!==t?e:void 0}function L(e,t,r){if(O(t))return t;const o=t[n];if(!o)return l(t,((n,a)=>x(e,o,t,n,a,r))),t;if(o.scope_!==e)return t;if(!o.modified_)return F(e,o.base_,!0),o.base_;if(!o.finalized_){o.finalized_=!0,o.scope_.unfinalizedDrafts_--;const t=o.copy_;let n=t,a=!1;3===o.type_&&(n=new Set(t),t.clear(),a=!0),l(n,((n,s)=>x(e,o,t,n,s,r,a))),F(e,t,!1),r&&e.patches_&&E("Patches").generatePatches_(o,r,e.patches_,e.inversePatches_)}return o.copy_}function x(e,t,r,n,o,s,u){if("production"!==process.env.NODE_ENV&&o===r&&a(5),i(o)){const a=L(e,o,s&&t&&3!==t.type_&&!_(t.assigned_,n)?s.concat(n):void 0);if(d(r,n,a),!i(a))return;e.canAutoFreeze_=!1}else u&&r.add(o);if(c(o)&&!O(o)){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1)return;L(e,o),(!t||!t.scope_.parent_)&&"symbol"!=typeof n&&Object.prototype.propertyIsEnumerable.call(r,n)&&F(e,o)}}function F(e,t,r=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&S(t,r)}var I={get(e,t){if(t===n)return e;const r=b(e);if(!_(r,t))return function(e,t,r){const n=M(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===C(e.base_,t)?(K(e),e.copy_[t]=k(o,e)):o},has:(e,t)=>t in b(e),ownKeys:e=>Reflect.ownKeys(b(e)),set(e,t,r){const o=M(b(e),t);if(o?.set)return o.set.call(e.draft_,r),!0;if(!e.modified_){const o=C(b(e),t),a=o?.[n];if(a&&a.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;K(e),R(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!==C(e.base_,t)||t in e.base_?(e.assigned_[t]=!1,K(e),R(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(){a(11)},getPrototypeOf:e=>s(e.base_),setPrototypeOf(){a(12)}},V={};function C(e,t){const r=e[n];return(r?b(r):e)[t]}function M(e,t){if(!(t in e))return;let r=s(e);for(;r;){const e=Object.getOwnPropertyDescriptor(r,t);if(e)return e;r=s(r)}}function R(e){e.modified_||(e.modified_=!0,e.parent_&&R(e.parent_))}function K(e){e.copy_||(e.copy_=m(e.base_,e.scope_.immer_.useStrictShallowCopy_))}l(I,((e,t)=>{V[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),V.deleteProperty=function(e,t){return"production"!==process.env.NODE_ENV&&isNaN(parseInt(t))&&a(13),V.set.call(this,e,t,void 0)},V.set=function(e,t,r){return"production"!==process.env.NODE_ENV&&"length"!==t&&isNaN(parseInt(t))&&a(14),I.set.call(this,e[0],t,r,e[0])};function k(e,t){const r=y(e)?E("MapSet").proxyMap_(e,t):h(e)?E("MapSet").proxySet_(e,t):function(e,t){const r=Array.isArray(e),n={type_:r?1:0,scope_:t?t.scope_:T(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let o=n,a=I;r&&(o=[n],a=V);const{revoke:s,proxy:i}=Proxy.revocable(o,a);return n.draft_=i,n.revoke_=s,i}(e,t);return(t?t.scope_:T()).drafts_.push(r),r}function J(e){if(!c(e)||O(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)=>{d(r,e,J(t))})),t&&(t.finalized_=!1),r}var G=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&&a(6),void 0!==n&&"function"!=typeof n&&a(7),c(e)){const t=j(this),a=k(e,void 0);let s=!0;try{o=r(a),s=!1}finally{s?A(t):P(t)}return D(t,n),z(o,t)}if(!e||"object"!=typeof e){if(o=r(e),void 0===o&&(o=e),o===t&&(o=void 0),this.autoFreeze_&&S(o,!0),n){const t=[],r=[];E("Patches").generateReplacementPatches_(e,o,t,r),n(t,r)}return o}a(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)||a(8),i(e)&&(e=function(e){return i(e)||a(10,e),J(e)}(e));const t=j(this),r=k(e,void 0);return r[n].isManual_=!0,P(t),r}finishDraft(e,t){const r=e&&e[n];(!r||!r.isManual_)&&a(9);const{scope_:o}=r;return D(o,t),z(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=E("Patches").applyPatches_;return i(e)?n(e,t):this.produce(e,(e=>n(e,t)))}},U=G.produce;G.produceWithPatches.bind(G),G.setAutoFreeze.bind(G),G.setUseStrictShallowCopy.bind(G),G.applyPatches.bind(G),G.createDraft.bind(G),G.finishDraft.bind(G);const $=(()=>{if("object"==typeof globalThis&&globalThis)return globalThis;if("object"==typeof self&&self)return self;if("object"==typeof window&&window)return window;throw new Error("Unable to locate global `this`")})(),B=(e,t)=>{typeof $<"u"&&$.localStorage.setItem(e,JSON.stringify(t))},H=(e,t)=>{if(typeof $<"u"){const r=$.localStorage.getItem(e);return r?JSON.parse(r):t}return t},W=(e,t)=>{typeof $<"u"&&$.localStorage.setItem(e,(e=>btoa(JSON.stringify(e)))(t))},q=(e,t)=>{if(typeof $<"u"){const r=$.localStorage.getItem(e);return r?(e=>JSON.parse(atob(e)))(r):t}return t};var X,Y={exports:{}},Q={};
2
- /**
3
- * @license React
4
- * use-sync-external-store-shim.production.js
5
- *
6
- * Copyright (c) Meta Platforms, Inc. and affiliates.
7
- *
8
- * This source code is licensed under the MIT license found in the
9
- * LICENSE file in the root directory of this source tree.
10
- */var Z,ee,te={};
11
- /**
12
- * @license React
13
- * use-sync-external-store-shim.development.js
14
- *
15
- * Copyright (c) Meta Platforms, Inc. and affiliates.
16
- *
17
- * This source code is licensed under the MIT license found in the
18
- * LICENSE file in the root directory of this source tree.
19
- */var re=(ee||(ee=1,"production"===process.env.NODE_ENV?Y.exports=function(){if(X)return Q;X=1;var t=e,r="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},n=t.useState,o=t.useEffect,a=t.useLayoutEffect,s=t.useDebugValue;function i(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!r(e,n)}catch{return!0}}var c=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,t){var r=t(),c=n({inst:{value:r,getSnapshot:t}}),u=c[0].inst,f=c[1];return a((function(){u.value=r,u.getSnapshot=t,i(u)&&f({inst:u})}),[e,r,t]),o((function(){return i(u)&&f({inst:u}),e((function(){i(u)&&f({inst:u})}))}),[e]),s(r),r};return Q.useSyncExternalStore=void 0!==t.useSyncExternalStore?t.useSyncExternalStore:c,Q}():Y.exports=(Z||(Z=1,"production"!==process.env.NODE_ENV&&function(){function t(e){var t=e.getSnapshot;e=e.value;try{var r=t();return!n(e,r)}catch{return!0}}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=e,n="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},o=r.useState,a=r.useEffect,s=r.useLayoutEffect,i=r.useDebugValue,c=!1,u=!1,f=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?function(e,t){return t()}:function(e,f){c||void 0===r.startTransition||(c=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var l=f();if(!u){var p=f();n(l,p)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}var _=(p=o({inst:{value:l,getSnapshot:f}}))[0].inst,d=p[1];return s((function(){_.value=l,_.getSnapshot=f,t(_)&&d({inst:_})}),[e,l,f]),a((function(){return t(_)&&d({inst:_}),e((function(){t(_)&&d({inst:_})}))}),[e]),i(l),l};te.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),te)),Y.exports);const ne={},oe={},ae={},se=typeof window<"u"&&window.__STATE_JET_DEVTOOLS__,ie=new Map,ce=new Map,ue={},fe=(e,t,r)=>{ie.has(e)||(ie.set(e,{value:t,listeners:new Set}),r?.persist&&(r?.encrypt?q(e,t):H(e,t)));const n=ie.get(e),o=()=>{ce.forEach(((e,t)=>{let o=e,a=n.value;ue[t]||(ue[t]={past:[],present:a,future:[]}),ue[t].past.push(a),ue[t].present=e,ue[t].future=[],r?.middleware?.forEach((e=>{const r=e(t,a,o);void 0!==r&&(o=r)})),"function"==typeof o?n.value=U(n.value,o):a!==o&&(n.value=o,n.listeners.forEach((e=>e())),((e,t)=>{ne[e]||(ne[e]=[]),void 0===oe[e]&&(oe[e]=-1),ne[e]=ne[e].slice(0,oe[e]+1),ne[e].push(t),oe[e]++,se&&window.__STATE_JET_DEVTOOLS__.updateState&&window.__STATE_JET_DEVTOOLS__.updateState(e,t,ne[e])})(t,o),((e,t)=>{const r=performance.now();t();const n=performance.now()-r;ae[e]||(ae[e]=[]),ae[e].push(n),se&&window.__STATE_JET_DEVTOOLS__.updatePerformance&&window.__STATE_JET_DEVTOOLS__.updatePerformance(e,n)})(t,(()=>{})),r?.persist&&(r?.encrypt?W(t,o):B(t,o)))})),ce.clear()};return{useStore:()=>re.useSyncExternalStore((e=>(n.listeners.add(e),()=>n.listeners.delete(e))),(()=>n.value)),set:t=>{ce.set(e,t),$?.requestAnimationFrame&&$.requestAnimationFrame(o)},undo:()=>{ue[e]?.past.length&&(ue[e].future.unshift(ue[e].present),ue[e].present=ue[e].past.pop(),n.value=ue[e].present,n.listeners.forEach((e=>e())),(e=>{if(oe[e]>0)oe[e]--,ne[e][oe[e]]})(e))},redo:()=>{ue[e]?.future.length&&(ue[e].past.push(ue[e].present),ue[e].present=ue[e].future.shift(),n.value=ue[e].present,n.listeners.forEach((e=>e())),(e=>{if(oe[e]<ne[e].length-1)oe[e]++,ne[e][oe[e]]})(e))}}},le=async(e,t,r,n)=>{const o=e.useStore(),a=t(o);e.set(a);try{await r()}catch(t){console.error("API request failed:",t),e.set(n?n(o):o)}},pe=(e,t)=>({...e,...t,lastUpdated:Date.now()}),_e=(e,t)=>{const r=t.useStore();t(pe(r,e))},de=(e,t)=>{const r={value:t(...e.map((e=>e.useStore())))};return e.forEach((n=>n.useStore().listeners.add((()=>{r.value=t(...e.map((e=>e.useStore())))})))),()=>r.value};export{de as derivedState,pe as mergeCRDT,le as optimisticUpdate,q as restoreEncryptedState,H as restoreState,W as saveEncryptedState,B as saveState,_e as syncCRDT,fe as useStateGlobal};