react-intent-engine-z 1.0.0 → 2.1.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
@@ -1,71 +1,57 @@
1
1
  ## 📘 react-intent-engine-z
2
2
 
3
- - Intent-first orchestration engine for React
4
- - Decouple UI from async flows, side effects, and business logic.
3
+ [![NPM](https://img.shields.io/npm/v/react-intent-engine-z.svg)](https://www.npmjs.com/package/react-intent-engine-z)
4
+ ![Downloads](https://img.shields.io/npm/dt/react-intent-engine-z.svg)
5
5
 
6
6
  ---
7
7
 
8
- #### Why react-intent-engine-z?
8
+ An **intent-first orchestration engine for React**.
9
+ Decouples UI from async flows, side effects, and business logic.
9
10
 
10
- - Modern React apps often suffer from:
11
+ [Live Example](https://codesandbox.io/p/sandbox/kjstrf)
11
12
 
12
- - Business logic leaking into components
13
-
14
- - Complex async flows spread across hooks
15
-
16
- - Hard-to-test side effects
17
-
18
- - Overloaded global stores
19
-
20
- - react-intent-engine solves this by introducing an intent-driven architecture:
21
-
22
- - Components declare what they want to do — the engine decides how it happens.
23
-
24
- - Works great with:
25
-
26
- - react-scoped-store
13
+ ---
27
14
 
28
- - React Query / TanStack Query
15
+ ### Why Use It
29
16
 
30
- - Hexagonal / DDD architectures
17
+ - Separate business logic from UI
18
+ - Handle async flows declaratively
19
+ - Easy testing of intents
20
+ - Supports multiple engines & scoped state
21
+ - Works with React 17+, React Query, DDD-style architectures
31
22
 
32
23
  ---
33
24
 
34
- #### 📦 Installation
35
- ```ts
25
+ ### 📦 Installation
26
+
27
+ ```bash
36
28
  npm install react-intent-engine-z use-sync-external-store
37
29
  ```
38
-
39
30
  - use-sync-external-store is required for React 17 compatibility.
40
31
 
41
32
  ---
42
33
 
43
- #### 🧠 Mental Model
44
- ```ts
45
- UI
46
- └─ emit intent
47
-
34
+ ### 🧠 Mental Model
35
+ ```bash
36
+ UI Component
37
+ └─ emits intent
38
+
48
39
  Intent Engine
49
40
  ├─ async orchestration
50
41
  ├─ business rules
51
42
  └─ side effects
52
- ```
43
+ ```
53
44
 
54
45
  ---
55
46
 
56
- #### 🚀 Basic Usage
57
- ##### 1️⃣ Create engine
47
+ ### 🚀 Basic Usage
58
48
 
49
+ ##### 1️⃣ Create Engine
59
50
  ```ts
60
51
  import { createIntentEngine } from "react-intent-engine-z"
61
52
 
62
- export const engine = createIntentEngine({
63
- initialState: {
64
- auth: {
65
- user: null,
66
- loading: false,
67
- },
68
- },
53
+ export const authEngine = createIntentEngine({
54
+ initialState: { auth: { user: null, loading: false } },
69
55
  effects: {
70
56
  auth: {
71
57
  login: async ({ email, password }) => {
@@ -77,29 +63,26 @@ export const engine = createIntentEngine({
77
63
  })
78
64
  ```
79
65
 
80
- ##### 2️⃣ Register intent handlers
66
+ ##### 2️⃣ Register Handlers
81
67
  ```ts
82
- engine.on("auth.login.submit", async (intent, ctx) => {
68
+ authEngine.on("auth.login.submit", async (intent, ctx) => {
83
69
  ctx.set("auth.loading", true)
84
-
85
70
  const user = await ctx.effects.auth.login(intent.payload)
86
-
87
71
  ctx.set("auth.user", user)
88
72
  ctx.set("auth.loading", false)
89
73
  })
90
74
  ```
75
+ ##### 3️⃣ Provide Engine to React
91
76
 
92
- ##### 3️⃣ Provide engine to React
93
77
  ```ts
94
78
  import { IntentProvider } from "react-intent-engine-z"
95
-
96
- <IntentProvider engine={engine}>
97
- <App />
79
+ <IntentProvider engine={authEngine}>
80
+ <LoginForm />
98
81
  </IntentProvider>
99
82
  ```
100
83
 
101
- ##### 4️⃣ Emit intent from UI
102
- ```ts
84
+ ##### 4️⃣ Emit Intent from UI
85
+ ```tsx
103
86
  import { useIntent, useIntentState } from "react-intent-engine-z"
104
87
 
105
88
  function LoginButton() {
@@ -109,92 +92,89 @@ function LoginButton() {
109
92
  return (
110
93
  <button
111
94
  disabled={loading}
112
- onClick={() =>
113
- emit({
114
- type: "auth.login.submit",
115
- payload: { email: "a@b.com", password: "123" },
116
- })
117
- }
95
+ onClick={() => emit({
96
+ type: "auth.login.submit",
97
+ payload: { email: "a@b.com", password: "123" }
98
+ })}
118
99
  >
119
- Login
100
+ {loading ? "Logging in..." : "Login"}
120
101
  </button>
121
102
  )
122
103
  }
123
104
  ```
124
105
 
125
- - UI components never call APIs or use cases directly.
106
+ ---
126
107
 
127
- ##### 🔄 Intent Status
128
- - Track lifecycle state of an intent:
108
+ ### 🔄 Track Intent Status
129
109
  ```ts
130
110
  import { useIntentStatus } from "react-intent-engine-z"
131
111
 
132
- const status = useIntentStatus("auth.login.submit")
133
- // idle | pending | success
112
+ const status = useIntentStatus("auth.login.submit") // idle | pending | success
134
113
  ```
135
114
 
136
115
  ---
137
116
 
138
- #### 🧩 Combine with react-scoped-store
117
+ ### 🧩 Middleware Example
139
118
  ```ts
140
- const useLoginStore = createScopedStore(() => ({
141
- email: "",
142
- password: "",
143
- }))
119
+ import { Middleware, createIntentEngine } from "react-intent-engine-z"
144
120
 
145
- function LoginForm() {
146
- const { email, password } = useLoginStore()
147
- const emit = useIntent()
121
+ // Logs every intent
122
+ const logger: Middleware = async (intent, next, ctx) => {
123
+ console.log("[Logger]", intent.type, intent.payload)
124
+ await next()
125
+ }
148
126
 
149
- return (
150
- <form
151
- onSubmit={() =>
152
- emit({
153
- type: "auth.login.submit",
154
- payload: { email, password },
155
- })
156
- }
157
- />
158
- )
127
+ // Blocks auth intents if not logged in
128
+ const authGuard: Middleware = async (intent, next, ctx) => {
129
+ const user = ctx.store.getState().auth.user
130
+ if (intent.type.startsWith("auth.") && !user) {
131
+ console.warn("[AuthGuard] Not logged in, blocking:", intent.type)
132
+ return
133
+ }
134
+ await next()
159
135
  }
160
- ```
161
136
 
162
- - react-scoped-store local UI state
137
+ const engine = createIntentEngine({
138
+ initialState: { auth: { user: null, loading: false } },
139
+ effects: {
140
+ auth: { login: async () => ({ id: 1, email: "a@b.com" }) }
141
+ },
142
+ middleware: [logger, authGuard]
143
+ })
163
144
 
164
- - react-intent-engine → async flow & orchestration
145
+ ```
165
146
 
166
147
  ---
167
148
 
168
- #### 🧪 Testing (headless)
169
- - Intent logic can be tested without React:
149
+ ### 🧪 Testing (headless)
170
150
  ```ts
171
151
  await engine.emit({
172
152
  type: "auth.login.submit",
173
- payload: { email: "a@b.com", password: "123" },
153
+ payload: { email: "a@b.com", password: "123" }
174
154
  })
175
155
 
176
156
  expect(engine.store.getState().auth.user).toBeDefined()
177
157
  ```
178
-
179
158
  ---
180
159
 
181
- #### 🧠 When to use?
182
-
183
- - Use react-intent-engine when your app has:
160
+ ### Multiple Engines
161
+ ```tsx
162
+ import { IntentProvider } from "react-intent-engine-z"
184
163
 
185
- - Complex async workflows
164
+ <IntentProvider engine={authEngine}>
165
+ <LoginForm />
166
+ </IntentProvider>
186
167
 
187
- - Business logic outside UI
168
+ <IntentProvider engine={notifEngine}>
169
+ <NotificationCenter />
170
+ </IntentProvider>
188
171
 
189
- - Multiple side effects per action
172
+ ```
173
+ - Each engine is scoped
190
174
 
191
- - Large or growing teams
175
+ - Supports role-based UI and multiple async flows
192
176
 
193
- - Hexagonal / DDD-inspired architecture
194
-
195
- - This library focuses on behavior and flow, not data fetching or UI state.
196
177
  ---
197
178
 
198
- #### 📜 License
199
-
179
+ ### 📜 License
200
180
  MIT
package/build/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var i=t.createContext(null),a=i.Provider;function c(){var e=t.useContext(i);if(!e)throw new Error("Missing IntentProvider");return e}function s(t){var e={exports:{}};return t(e,e.exports),e.exports}var f="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},l=n.default.useState,d=n.default.useEffect,p=n.default.useLayoutEffect,v=n.default.useDebugValue;function S(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!f(t,n)}catch(t){return!0}}var y="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=l({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return p(function(){o.value=n,o.getSnapshot=e,S(o)&&u({inst:o})},[t,n,e]),d(function(){return S(o)&&u({inst:o}),t(function(){S(o)&&u({inst:o})})},[t]),v(n),n},h={useSyncExternalStore:void 0!==n.default.useSyncExternalStore?n.default.useSyncExternalStore:y},_=s(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=n.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,a=r.useLayoutEffect,c=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,n){s||void 0===r.startTransition||(s=!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=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=n,t(p)&&v({inst:p})},[e,l,n]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(l),l};e.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),E=s(function(t){"production"===process.env.NODE_ENV?t.exports=h:t.exports=_});exports.IntentProvider=a,exports.createIntentEngine=function(t){var e,n,i,a,c,s,f=(i=t.initialState,a=structuredClone(i),c=new Set,{getState:function(){return a},setState:function(t){a=t(a),c.forEach(function(t){return t()})},subscribe:function(t){return c.add(t),function(){return c.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(a){switch(a.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}},exports.useEngine=c,exports.useIntent=function(){var t=c();return function(e){return t.emit(e)}},exports.useIntentState=function(t){var e=c();return E.useSyncExternalStore(e.store.subscribe,function(){return t(e.store.getState())})},exports.useIntentStatus=function(t){return c().getStatus(t)};
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var n=e(t);function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var i=t.createContext(null);function a(){var e=t.useContext(i);if(!e)throw new Error("Missing IntentProvider");return e}function c(t){var e={exports:{}};return t(e,e.exports),e.exports}var s="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},f=n.default.useState,l=n.default.useEffect,d=n.default.useLayoutEffect,p=n.default.useDebugValue;function v(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!s(t,n)}catch(t){return!0}}var S="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=f({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return d(function(){o.value=n,o.getSnapshot=e,v(o)&&u({inst:o})},[t,n,e]),l(function(){return v(o)&&u({inst:o}),t(function(){v(o)&&u({inst:o})})},[t]),p(n),n},y={useSyncExternalStore:void 0!==n.default.useSyncExternalStore?n.default.useSyncExternalStore:S},h=c(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=n.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,a=r.useLayoutEffect,c=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,n){s||void 0===r.startTransition||(s=!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=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=n,t(p)&&v({inst:p})},[e,l,n]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(l),l};e.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),_=c(function(t){"production"===process.env.NODE_ENV?t.exports=y:t.exports=h});exports.IntentProvider=function(t){var e=t.engine,r=t.children;return n.default.createElement(i.Provider,{value:e},r)},exports.createIntentEngine=function(t){var e,n,i,a,c,s,f=(i=t.initialState,a=structuredClone(i),c=new Set,{getState:function(){return a},setState:function(t){a=t(a),c.forEach(function(t){return t()})},subscribe:function(t){return c.add(t),function(){return c.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(a){switch(a.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}},exports.useEngine=a,exports.useIntent=function(){var t=a();return function(e){return t.emit(e)}},exports.useIntentState=function(e){var n=a(),r=t.useRef();return _.useSyncExternalStore(n.store.subscribe,function(){var t=e(n.store.getState());return Object.is(t,r.current)?r.current:(r.current=t,t)})},exports.useIntentStatus=function(t){var e=a();return _.useSyncExternalStore(function(n){return e.subscribeStatus(t,n)},function(){return e.getStatus(t)})};
@@ -1 +1 @@
1
- import t,{createContext as e,useContext as n}from"react";function r(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{a(r.next(t))}catch(t){u(t)}}function c(t){try{a(r.throw(t))}catch(t){u(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,c)}a((r=r.apply(t,e||[])).next())})}function o(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function u(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function i(t){var e,n,i,c,a,s,f=(i=t.initialState,c=structuredClone(i),a=new Set,{getState:function(){return c},setState:function(t){c=t(c),a.forEach(function(t){return t()})},subscribe:function(t){return a.add(t),function(){return a.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function u(i){return r(this,void 0,void 0,function(){var r;return o(this,function(o){if(i<=n)throw new Error("next() called twice");return n=i,(r=s[i])?[2,r(t,function(){return u(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return r(this,void 0,void 0,function(){var u,i=this;return o(this,function(c){switch(c.label){case 0:return u=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,c=0;c<u.length-1;c++)i=i[r=u[c]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(u)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return r(i,void 0,void 0,function(){var t,n,r;return o(this,function(o){switch(o.label){case 0:t=0,n=null!==(r=d.get(e.type))&&void 0!==r?r:[],o.label=1;case 1:return t<n.length?[4,(0,n[t])(e,u)]:[3,4];case 2:o.sent(),o.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return c.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,u(u([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,u(u([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}}"function"==typeof SuppressedError&&SuppressedError;var c=e(null),a=c.Provider;function s(){var t=n(c);if(!t)throw new Error("Missing IntentProvider");return t}function f(){var t=s();return function(e){return t.emit(e)}}function l(t){var e={exports:{}};return t(e,e.exports),e.exports}var d="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},p=t.useState,v=t.useEffect,S=t.useLayoutEffect,y=t.useDebugValue;function h(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!d(t,n)}catch(t){return!0}}var _="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=p({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return S(function(){o.value=n,o.getSnapshot=e,h(o)&&u({inst:o})},[t,n,e]),v(function(){return h(o)&&u({inst:o}),t(function(){h(o)&&u({inst:o})})},[t]),y(n),n},E={useSyncExternalStore:void 0!==t.useSyncExternalStore?t.useSyncExternalStore:_},O=l(function(e,n){"production"!==process.env.NODE_ENV&&function(){function e(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=t,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,c=r.useLayoutEffect,a=r.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,n){s||void 0===r.startTransition||(s=!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=n();if(!f){var d=n();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:n}}))[0].inst,v=d[1];return c(function(){p.value=l,p.getSnapshot=n,e(p)&&v({inst:p})},[t,l,n]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),a(l),l};n.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),w=l(function(t){"production"===process.env.NODE_ENV?t.exports=E:t.exports=O});function g(t){var e=s();return w.useSyncExternalStore(e.store.subscribe,function(){return t(e.store.getState())})}function b(t){return s().getStatus(t)}export{a as IntentProvider,i as createIntentEngine,s as useEngine,f as useIntent,g as useIntentState,b as useIntentStatus};
1
+ import t,{createContext as e,useContext as n,useRef as r}from"react";function o(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{a(r.next(t))}catch(t){u(t)}}function c(t){try{a(r.throw(t))}catch(t){u(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,c)}a((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=c(0),i.throw=c(1),i.return=c(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(a){return function(c){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&c[0]?r.return:c[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,c[1])).done)return o;switch(r=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,r=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],r=0}finally{n=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,a])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}function c(t){var e,n,r,c,a,s,l=(r=t.initialState,c=structuredClone(r),a=new Set,{getState:function(){return c},setState:function(t){c=t(c),a.forEach(function(t){return t()})},subscribe:function(t){return a.add(t),function(){return a.delete(t)}}}),f=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,S=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function r(i){return o(this,void 0,void 0,function(){var o;return u(this,function(u){if(i<=n)throw new Error("next() called twice");return n=i,(o=s[i])?[2,o(t,function(){return r(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return o(this,void 0,void 0,function(){var r,i=this;return u(this,function(c){switch(c.label){case 0:return r=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,c=0;c<u.length-1;c++)i=i[r=u[c]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(l,t,f),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(r)}))?[2]:(v.set(e.type,"pending"),[4,S(e,function(){return o(i,void 0,void 0,function(){var t,n,o;return u(this,function(u){switch(u.label){case 0:t=0,n=null!==(o=d.get(e.type))&&void 0!==o?o:[],u.label=1;case 1:return t<n.length?[4,(0,n[t])(e,r)]:[3,4];case 2:u.sent(),u.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return c.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,i(i([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,i(i([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:l,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}}"function"==typeof SuppressedError&&SuppressedError;var a=e(null);function s(e){var n=e.engine,r=e.children;return t.createElement(a.Provider,{value:n},r)}function l(){var t=n(a);if(!t)throw new Error("Missing IntentProvider");return t}function f(){var t=l();return function(e){return t.emit(e)}}function d(t){var e={exports:{}};return t(e,e.exports),e.exports}var p="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},v=t.useState,S=t.useEffect,y=t.useLayoutEffect,h=t.useDebugValue;function _(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!p(t,n)}catch(t){return!0}}var E="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=v({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return y(function(){o.value=n,o.getSnapshot=e,_(o)&&u({inst:o})},[t,n,e]),S(function(){return _(o)&&u({inst:o}),t(function(){_(o)&&u({inst:o})})},[t]),h(n),n},O={useSyncExternalStore:void 0!==t.useSyncExternalStore?t.useSyncExternalStore:E},g=d(function(e,n){"production"!==process.env.NODE_ENV&&function(){function e(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var r=t,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=r.useState,i=r.useEffect,c=r.useLayoutEffect,a=r.useDebugValue,s=!1,l=!1,f="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,n){s||void 0===r.startTransition||(s=!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 f=n();if(!l){var d=n();o(f,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),l=!0)}var p=(d=u({inst:{value:f,getSnapshot:n}}))[0].inst,v=d[1];return c(function(){p.value=f,p.getSnapshot=n,e(p)&&v({inst:p})},[t,f,n]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),a(f),f};n.useSyncExternalStore=void 0!==r.useSyncExternalStore?r.useSyncExternalStore:f,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),w=d(function(t){"production"===process.env.NODE_ENV?t.exports=O:t.exports=g});function b(t){var e=l(),n=r();return w.useSyncExternalStore(e.store.subscribe,function(){var r=t(e.store.getState());return Object.is(r,n.current)?n.current:(n.current=r,r)})}function x(t){var e=l();return w.useSyncExternalStore(function(n){return e.subscribeStatus(t,n)},function(){return e.getStatus(t)})}export{s as IntentProvider,c as createIntentEngine,l as useEngine,f as useIntent,b as useIntentState,x as useIntentStatus};
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).ReactIntentEngine={},t.React)}(this,function(t,e){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=n(e);function o(t,e,n,r){return new(n||(n=Promise))(function(o,u){function i(t){try{c(r.next(t))}catch(t){u(t)}}function a(t){try{c(r.throw(t))}catch(t){u(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(i,a)}c((r=r.apply(t,e||[])).next())})}function u(t,e){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=e.call(t,u)}catch(t){a=[6,t],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(t,e,n){if(n||2===arguments.length)for(var r,o=0,u=e.length;o<u;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var a=e.createContext(null),c=a.Provider;function s(){var t=e.useContext(a);if(!t)throw new Error("Missing IntentProvider");return t}function f(t){var e={exports:{}};return t(e,e.exports),e.exports}var l="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},d=r.default.useState,p=r.default.useEffect,v=r.default.useLayoutEffect,y=r.default.useDebugValue;function S(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!l(t,n)}catch(t){return!0}}var h="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(t,e){var n=e(),r=d({inst:{value:n,getSnapshot:e}}),o=r[0].inst,u=r[1];return v(function(){o.value=n,o.getSnapshot=e,S(o)&&u({inst:o})},[t,n,e]),p(function(){return S(o)&&u({inst:o}),t(function(){S(o)&&u({inst:o})})},[t]),y(n),n},_={useSyncExternalStore:void 0!==r.default.useSyncExternalStore?r.default.useSyncExternalStore:h},g=f(function(t,e){"production"!==process.env.NODE_ENV&&function(){function t(t){var e=t.getSnapshot;t=t.value;try{var n=e();return!o(t,n)}catch(t){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=r.default,o="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},u=n.useState,i=n.useEffect,a=n.useLayoutEffect,c=n.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(t,e){return e()}:function(e,r){s||void 0===n.startTransition||(s=!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=r();if(!f){var d=r();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:r}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=r,t(p)&&v({inst:p})},[e,l,r]),i(function(){return t(p)&&v({inst:p}),e(function(){t(p)&&v({inst:p})})},[e]),c(l),l};e.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),E=f(function(t){"production"===process.env.NODE_ENV?t.exports=_:t.exports=g});t.IntentProvider=c,t.createIntentEngine=function(t){var e,n,r,a,c,s,f=(r=t.initialState,a=structuredClone(r),c=new Set,{getState:function(){return a},setState:function(t){a=t(a),c.forEach(function(t){return t()})},subscribe:function(t){return c.add(t),function(){return c.delete(t)}}}),l=null!==(e=t.effects)&&void 0!==e?e:{},d=new Map,p=new Map,v=new Map,y=(s=null!==(n=t.middleware)&&void 0!==n?n:[],function(t,e){var n=-1;return function r(i){return o(this,void 0,void 0,function(){var o;return u(this,function(u){if(i<=n)throw new Error("next() called twice");return n=i,(o=s[i])?[2,o(t,function(){return r(i+1)})]:[2,e()]})})}(0)});return{emit:function t(e){var n;return o(this,void 0,void 0,function(){var r,i=this;return u(this,function(a){switch(a.label){case 0:return r=function(t,e,n){return{get:function(e){return e.split(".").reduce(function(t,e){return null==t?void 0:t[e]},t.getState())},set:function(e,n){t.setState(function(t){for(var r,o=structuredClone(t),u=e.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:e,effects:n}}(f,t,l),(null===(n=p.get(e.type))||void 0===n?void 0:n.some(function(t){return!t(r)}))?[2]:(v.set(e.type,"pending"),[4,y(e,function(){return o(i,void 0,void 0,function(){var t,n,o;return u(this,function(u){switch(u.label){case 0:t=0,n=null!==(o=d.get(e.type))&&void 0!==o?o:[],u.label=1;case 1:return t<n.length?[4,(0,n[t])(e,r)]:[3,4];case 2:u.sent(),u.label=3;case 3:return t++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(e.type,"success"),[2]}})})},on:function(t,e){var n;d.set(t,i(i([],null!==(n=d.get(t))&&void 0!==n?n:[],!0),[e],!1))},guard:function(t,e){var n;p.set(t,i(i([],null!==(n=p.get(t))&&void 0!==n?n:[],!0),[e],!1))},store:f,getStatus:function(t){var e;return null!==(e=v.get(t))&&void 0!==e?e:"idle"}}},t.useEngine=s,t.useIntent=function(){var t=s();return function(e){return t.emit(e)}},t.useIntentState=function(t){var e=s();return E.useSyncExternalStore(e.store.subscribe,function(){return t(e.store.getState())})},t.useIntentStatus=function(t){return s().getStatus(t)},Object.defineProperty(t,"__esModule",{value:!0})});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactIntentEngine={},e.React)}(this,function(e,t){"use strict";function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(t);function o(e,t,n,r){return new(n||(n=Promise))(function(o,u){function i(e){try{c(r.next(e))}catch(e){u(e)}}function a(e){try{c(r.throw(e))}catch(e){u(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(i,a)}c((r=r.apply(e,t||[])).next())})}function u(e,t){var n,r,o,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},i=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return i.next=a(0),i.throw=a(1),i.return=a(2),"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,a[0]&&(u=0)),u;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,r=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){u.label=a[1];break}if(6===a[0]&&u.label<o[1]){u.label=o[1],o=a;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(a);break}o[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}function i(e,t,n){if(n||2===arguments.length)for(var r,o=0,u=t.length;o<u;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var a=t.createContext(null);function c(){var e=t.useContext(a);if(!e)throw new Error("Missing IntentProvider");return e}function s(e){var t={exports:{}};return e(t,t.exports),t.exports}var f="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},l=r.default.useState,d=r.default.useEffect,p=r.default.useLayoutEffect,v=r.default.useDebugValue;function y(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!f(e,n)}catch(e){return!0}}var S="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(e,t){var n=t(),r=l({inst:{value:n,getSnapshot:t}}),o=r[0].inst,u=r[1];return p(function(){o.value=n,o.getSnapshot=t,y(o)&&u({inst:o})},[e,n,t]),d(function(){return y(o)&&u({inst:o}),e(function(){y(o)&&u({inst:o})})},[e]),v(n),n},h={useSyncExternalStore:void 0!==r.default.useSyncExternalStore?r.default.useSyncExternalStore:S},_=s(function(e,t){"production"!==process.env.NODE_ENV&&function(){function e(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!o(e,n)}catch(e){return!0}}"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var n=r.default,o="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},u=n.useState,i=n.useEffect,a=n.useLayoutEffect,c=n.useDebugValue,s=!1,f=!1,l="undefined"==typeof window||void 0===window.document||void 0===window.document.createElement?function(e,t){return t()}:function(t,r){s||void 0===n.startTransition||(s=!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=r();if(!f){var d=r();o(l,d)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),f=!0)}var p=(d=u({inst:{value:l,getSnapshot:r}}))[0].inst,v=d[1];return a(function(){p.value=l,p.getSnapshot=r,e(p)&&v({inst:p})},[t,l,r]),i(function(){return e(p)&&v({inst:p}),t(function(){e(p)&&v({inst:p})})},[t]),c(l),l};t.useSyncExternalStore=void 0!==n.useSyncExternalStore?n.useSyncExternalStore:l,"undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()}),E=s(function(e){"production"===process.env.NODE_ENV?e.exports=h:e.exports=_});e.IntentProvider=function(e){var t=e.engine,n=e.children;return r.default.createElement(a.Provider,{value:t},n)},e.createIntentEngine=function(e){var t,n,r,a,c,s,f=(r=e.initialState,a=structuredClone(r),c=new Set,{getState:function(){return a},setState:function(e){a=e(a),c.forEach(function(e){return e()})},subscribe:function(e){return c.add(e),function(){return c.delete(e)}}}),l=null!==(t=e.effects)&&void 0!==t?t:{},d=new Map,p=new Map,v=new Map,y=(s=null!==(n=e.middleware)&&void 0!==n?n:[],function(e,t){var n=-1;return function r(i){return o(this,void 0,void 0,function(){var o;return u(this,function(u){if(i<=n)throw new Error("next() called twice");return n=i,(o=s[i])?[2,o(e,function(){return r(i+1)})]:[2,t()]})})}(0)});return{emit:function e(t){var n;return o(this,void 0,void 0,function(){var r,i=this;return u(this,function(a){switch(a.label){case 0:return r=function(e,t,n){return{get:function(t){return t.split(".").reduce(function(e,t){return null==e?void 0:e[t]},e.getState())},set:function(t,n){e.setState(function(e){for(var r,o=structuredClone(e),u=t.split("."),i=o,a=0;a<u.length-1;a++)i=i[r=u[a]]||(i[r]={});return i[u.at(-1)]=n,o})},emit:t,effects:n}}(f,e,l),(null===(n=p.get(t.type))||void 0===n?void 0:n.some(function(e){return!e(r)}))?[2]:(v.set(t.type,"pending"),[4,y(t,function(){return o(i,void 0,void 0,function(){var e,n,o;return u(this,function(u){switch(u.label){case 0:e=0,n=null!==(o=d.get(t.type))&&void 0!==o?o:[],u.label=1;case 1:return e<n.length?[4,(0,n[e])(t,r)]:[3,4];case 2:u.sent(),u.label=3;case 3:return e++,[3,1];case 4:return[2]}})})})]);case 1:return a.sent(),v.set(t.type,"success"),[2]}})})},on:function(e,t){var n;d.set(e,i(i([],null!==(n=d.get(e))&&void 0!==n?n:[],!0),[t],!1))},guard:function(e,t){var n;p.set(e,i(i([],null!==(n=p.get(e))&&void 0!==n?n:[],!0),[t],!1))},store:f,getStatus:function(e){var t;return null!==(t=v.get(e))&&void 0!==t?t:"idle"}}},e.useEngine=c,e.useIntent=function(){var e=c();return function(t){return e.emit(t)}},e.useIntentState=function(e){var n=c(),r=t.useRef();return E.useSyncExternalStore(n.store.subscribe,function(){var t=e(n.store.getState());return Object.is(t,r.current)?r.current:(r.current=t,t)})},e.useIntentStatus=function(e){var t=c();return E.useSyncExternalStore(function(n){return t.subscribeStatus(e,n)},function(){return t.getStatus(e)})},Object.defineProperty(e,"__esModule",{value:!0})});
@@ -1,3 +1,8 @@
1
- /// <reference types="react" />
2
- export declare const IntentProvider: import("react").Provider<any>;
1
+ import React, { ReactNode } from "react";
2
+ type EngineContextType = any;
3
+ export declare function IntentProvider({ engine, children, }: {
4
+ engine: EngineContextType;
5
+ children: ReactNode;
6
+ }): React.JSX.Element;
3
7
  export declare function useEngine(): any;
8
+ export {};
@@ -1 +1 @@
1
- export declare function useIntentState<T>(selector: (s: any) => T): T;
1
+ export declare function useIntentState<T>(selector: (state: any) => T): T;
@@ -1 +1 @@
1
- export declare function useIntentStatus(type: string): any;
1
+ export declare function useIntentStatus(intentType: string): any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-intent-engine-z",
3
- "version": "1.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Intent-first orchestration engine for React applications",
5
5
  "license": "MIT",
6
6
  "author": "Delpi.Kye",