@directive-run/react 1.0.0 → 1.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/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -3
- package/dist/index.d.ts +68 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { DistributableSnapshot, createRequirementStatusPlugin, ModuleSchema, InferFacts, InferDerivations, Plugin, HistoryOption, TraceOption, ErrorBoundaryConfig, ModulesMap, ModuleDef, SingleModuleSystem, InferEvents,
|
|
2
|
+
import { DistributableSnapshot, createRequirementStatusPlugin, ModuleSchema, InferFacts, InferDerivations, Plugin, HistoryOption, TraceOption, ErrorBoundaryConfig, ModulesMap, ModuleDef, SingleModuleSystem, InferEvents, InferSelectorState, HistoryState, NamespacedSystem, RequirementTypeStatus } from '@directive-run/core';
|
|
3
3
|
export { RequirementTypeStatus } from '@directive-run/core';
|
|
4
|
-
import {
|
|
4
|
+
import { InspectState, ConstraintInfo } from '@directive-run/core/adapter-utils';
|
|
5
5
|
export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
7
|
|
|
@@ -361,5 +361,70 @@ declare function useQuerySystem<T extends {
|
|
|
361
361
|
* ```
|
|
362
362
|
*/
|
|
363
363
|
declare function useSuspenseQuery<T = unknown>(system: SingleModuleSystem<any>, queryName: string): T;
|
|
364
|
+
/**
|
|
365
|
+
* Create a React context for a Directive system, eliminating prop-drilling.
|
|
366
|
+
*
|
|
367
|
+
* Returns a Provider component and context-bound hooks that automatically
|
|
368
|
+
* use the system from context — no need to pass `system` to every hook.
|
|
369
|
+
*
|
|
370
|
+
* **Note:** The returned hooks (e.g., `Counter.useFact("count")`) follow React
|
|
371
|
+
* hook rules but eslint-plugin-react-hooks may not recognize them as hooks since
|
|
372
|
+
* they're object methods. This is the same pattern used by XState's
|
|
373
|
+
* `createActorContext`. Suppress with `// eslint-disable-next-line react-hooks/rules-of-hooks`
|
|
374
|
+
* if your linter flags it.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```tsx
|
|
378
|
+
* const Counter = createDirectiveContext(counterSystem);
|
|
379
|
+
*
|
|
380
|
+
* function App() {
|
|
381
|
+
* return (
|
|
382
|
+
* <Counter.Provider>
|
|
383
|
+
* <Display />
|
|
384
|
+
* </Counter.Provider>
|
|
385
|
+
* );
|
|
386
|
+
* }
|
|
387
|
+
*
|
|
388
|
+
* function Display() {
|
|
389
|
+
* const count = Counter.useFact("count");
|
|
390
|
+
* const doubled = Counter.useDerived("doubled");
|
|
391
|
+
* const events = Counter.useEvents();
|
|
392
|
+
* return <button onClick={() => events.increment()}>{count} ({doubled})</button>;
|
|
393
|
+
* }
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function createDirectiveContext<M extends ModuleSchema>(system: SingleModuleSystem<M>): {
|
|
397
|
+
/** Wrap your component tree to provide the system via context. */
|
|
398
|
+
Provider: {
|
|
399
|
+
({ children, system: overrideSystem, }: {
|
|
400
|
+
children: ReactNode;
|
|
401
|
+
/** Override the system for testing or conditional logic. */
|
|
402
|
+
system?: SingleModuleSystem<M>;
|
|
403
|
+
}): react_jsx_runtime.JSX.Element;
|
|
404
|
+
displayName: string;
|
|
405
|
+
};
|
|
406
|
+
/** Get the underlying system instance from context. */
|
|
407
|
+
useSystem: () => SingleModuleSystem<M>;
|
|
408
|
+
/** Read a fact value (reactive — re-renders on change). */
|
|
409
|
+
useFact: <K extends keyof InferFacts<M> & string>(factKey: K) => InferFacts<M>[K] | undefined;
|
|
410
|
+
/** Read a derived value (reactive — re-renders on change). */
|
|
411
|
+
useDerived: <K extends keyof InferDerivations<M> & string>(derivationId: K) => InferDerivations<M>[K];
|
|
412
|
+
/** Get the typed events accessor. */
|
|
413
|
+
useEvents: () => M["events"] extends Record<string, unknown> ? { [E in keyof M["events"]]: M["events"][E] extends Record<string, unknown> ? keyof M["events"][E] extends never ? () => void : (payload: M["events"][E] extends infer T ? T extends M["events"][E] ? T extends Record<string, unknown> ? { [K in keyof T]: T[K] extends {
|
|
414
|
+
_type: infer T_1;
|
|
415
|
+
} ? T_1 : T[K]; } : never : never : never) => void : () => void; } : Record<string, never>;
|
|
416
|
+
/** Get a dispatch function for raw events. */
|
|
417
|
+
useDispatch: () => (event: InferEvents<M>) => void;
|
|
418
|
+
/** Run a selector with auto-tracked dependencies. */
|
|
419
|
+
useSelector: <R>(selector: (state: InferSelectorState<M>) => R, equalityFn?: (a: R, b: R) => boolean) => R;
|
|
420
|
+
/** Watch a key and call a callback on change. */
|
|
421
|
+
useWatch: <K extends string>(key: K, callback: (newValue: unknown, previousValue: unknown) => void) => void;
|
|
422
|
+
/** Get the current inspection state. */
|
|
423
|
+
useInspect: () => InspectState;
|
|
424
|
+
/** Explain a requirement. */
|
|
425
|
+
useExplain: (requirementId: string) => string | null;
|
|
426
|
+
/** Get history state. */
|
|
427
|
+
useHistory: () => HistoryState | null;
|
|
428
|
+
};
|
|
364
429
|
|
|
365
|
-
export { DirectiveHydrator, type HydratorProps, type OptimisticUpdateResult, type StatusPlugin, type UseDirectiveOptions, type UseDirectiveRefNamespacedOptions, type UseDirectiveRefOptions, type UseDirectiveReturn, type UseDirectiveReturnWithStatus, type UseInspectOptions, createTypedHooks, useConstraintStatus, useDerived, useDirective, useDirectiveRef, useDispatch, useEvents, useExplain, useFact, useHistory, useHydratedSystem, useInspect, useNamespacedSelector, useOptimisticUpdate, useQuerySystem, useRequirementStatus, useSelector, useSuspenseQuery, useSuspenseRequirement, useWatch };
|
|
430
|
+
export { DirectiveHydrator, type HydratorProps, type OptimisticUpdateResult, type StatusPlugin, type UseDirectiveOptions, type UseDirectiveRefNamespacedOptions, type UseDirectiveRefOptions, type UseDirectiveReturn, type UseDirectiveReturnWithStatus, type UseInspectOptions, createDirectiveContext, createTypedHooks, useConstraintStatus, useDerived, useDirective, useDirectiveRef, useDispatch, useEvents, useExplain, useFact, useHistory, useHydratedSystem, useInspect, useNamespacedSelector, useOptimisticUpdate, useQuerySystem, useRequirementStatus, useSelector, useSuspenseQuery, useSuspenseRequirement, useWatch };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { DistributableSnapshot, createRequirementStatusPlugin, ModuleSchema, InferFacts, InferDerivations, Plugin, HistoryOption, TraceOption, ErrorBoundaryConfig, ModulesMap, ModuleDef, SingleModuleSystem, InferEvents,
|
|
2
|
+
import { DistributableSnapshot, createRequirementStatusPlugin, ModuleSchema, InferFacts, InferDerivations, Plugin, HistoryOption, TraceOption, ErrorBoundaryConfig, ModulesMap, ModuleDef, SingleModuleSystem, InferEvents, InferSelectorState, HistoryState, NamespacedSystem, RequirementTypeStatus } from '@directive-run/core';
|
|
3
3
|
export { RequirementTypeStatus } from '@directive-run/core';
|
|
4
|
-
import {
|
|
4
|
+
import { InspectState, ConstraintInfo } from '@directive-run/core/adapter-utils';
|
|
5
5
|
export { ConstraintInfo, InspectState, shallowEqual } from '@directive-run/core/adapter-utils';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
7
|
|
|
@@ -361,5 +361,70 @@ declare function useQuerySystem<T extends {
|
|
|
361
361
|
* ```
|
|
362
362
|
*/
|
|
363
363
|
declare function useSuspenseQuery<T = unknown>(system: SingleModuleSystem<any>, queryName: string): T;
|
|
364
|
+
/**
|
|
365
|
+
* Create a React context for a Directive system, eliminating prop-drilling.
|
|
366
|
+
*
|
|
367
|
+
* Returns a Provider component and context-bound hooks that automatically
|
|
368
|
+
* use the system from context — no need to pass `system` to every hook.
|
|
369
|
+
*
|
|
370
|
+
* **Note:** The returned hooks (e.g., `Counter.useFact("count")`) follow React
|
|
371
|
+
* hook rules but eslint-plugin-react-hooks may not recognize them as hooks since
|
|
372
|
+
* they're object methods. This is the same pattern used by XState's
|
|
373
|
+
* `createActorContext`. Suppress with `// eslint-disable-next-line react-hooks/rules-of-hooks`
|
|
374
|
+
* if your linter flags it.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```tsx
|
|
378
|
+
* const Counter = createDirectiveContext(counterSystem);
|
|
379
|
+
*
|
|
380
|
+
* function App() {
|
|
381
|
+
* return (
|
|
382
|
+
* <Counter.Provider>
|
|
383
|
+
* <Display />
|
|
384
|
+
* </Counter.Provider>
|
|
385
|
+
* );
|
|
386
|
+
* }
|
|
387
|
+
*
|
|
388
|
+
* function Display() {
|
|
389
|
+
* const count = Counter.useFact("count");
|
|
390
|
+
* const doubled = Counter.useDerived("doubled");
|
|
391
|
+
* const events = Counter.useEvents();
|
|
392
|
+
* return <button onClick={() => events.increment()}>{count} ({doubled})</button>;
|
|
393
|
+
* }
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
declare function createDirectiveContext<M extends ModuleSchema>(system: SingleModuleSystem<M>): {
|
|
397
|
+
/** Wrap your component tree to provide the system via context. */
|
|
398
|
+
Provider: {
|
|
399
|
+
({ children, system: overrideSystem, }: {
|
|
400
|
+
children: ReactNode;
|
|
401
|
+
/** Override the system for testing or conditional logic. */
|
|
402
|
+
system?: SingleModuleSystem<M>;
|
|
403
|
+
}): react_jsx_runtime.JSX.Element;
|
|
404
|
+
displayName: string;
|
|
405
|
+
};
|
|
406
|
+
/** Get the underlying system instance from context. */
|
|
407
|
+
useSystem: () => SingleModuleSystem<M>;
|
|
408
|
+
/** Read a fact value (reactive — re-renders on change). */
|
|
409
|
+
useFact: <K extends keyof InferFacts<M> & string>(factKey: K) => InferFacts<M>[K] | undefined;
|
|
410
|
+
/** Read a derived value (reactive — re-renders on change). */
|
|
411
|
+
useDerived: <K extends keyof InferDerivations<M> & string>(derivationId: K) => InferDerivations<M>[K];
|
|
412
|
+
/** Get the typed events accessor. */
|
|
413
|
+
useEvents: () => M["events"] extends Record<string, unknown> ? { [E in keyof M["events"]]: M["events"][E] extends Record<string, unknown> ? keyof M["events"][E] extends never ? () => void : (payload: M["events"][E] extends infer T ? T extends M["events"][E] ? T extends Record<string, unknown> ? { [K in keyof T]: T[K] extends {
|
|
414
|
+
_type: infer T_1;
|
|
415
|
+
} ? T_1 : T[K]; } : never : never : never) => void : () => void; } : Record<string, never>;
|
|
416
|
+
/** Get a dispatch function for raw events. */
|
|
417
|
+
useDispatch: () => (event: InferEvents<M>) => void;
|
|
418
|
+
/** Run a selector with auto-tracked dependencies. */
|
|
419
|
+
useSelector: <R>(selector: (state: InferSelectorState<M>) => R, equalityFn?: (a: R, b: R) => boolean) => R;
|
|
420
|
+
/** Watch a key and call a callback on change. */
|
|
421
|
+
useWatch: <K extends string>(key: K, callback: (newValue: unknown, previousValue: unknown) => void) => void;
|
|
422
|
+
/** Get the current inspection state. */
|
|
423
|
+
useInspect: () => InspectState;
|
|
424
|
+
/** Explain a requirement. */
|
|
425
|
+
useExplain: (requirementId: string) => string | null;
|
|
426
|
+
/** Get history state. */
|
|
427
|
+
useHistory: () => HistoryState | null;
|
|
428
|
+
};
|
|
364
429
|
|
|
365
|
-
export { DirectiveHydrator, type HydratorProps, type OptimisticUpdateResult, type StatusPlugin, type UseDirectiveOptions, type UseDirectiveRefNamespacedOptions, type UseDirectiveRefOptions, type UseDirectiveReturn, type UseDirectiveReturnWithStatus, type UseInspectOptions, createTypedHooks, useConstraintStatus, useDerived, useDirective, useDirectiveRef, useDispatch, useEvents, useExplain, useFact, useHistory, useHydratedSystem, useInspect, useNamespacedSelector, useOptimisticUpdate, useQuerySystem, useRequirementStatus, useSelector, useSuspenseQuery, useSuspenseRequirement, useWatch };
|
|
430
|
+
export { DirectiveHydrator, type HydratorProps, type OptimisticUpdateResult, type StatusPlugin, type UseDirectiveOptions, type UseDirectiveRefNamespacedOptions, type UseDirectiveRefOptions, type UseDirectiveReturn, type UseDirectiveReturnWithStatus, type UseInspectOptions, createDirectiveContext, createTypedHooks, useConstraintStatus, useDerived, useDirective, useDirectiveRef, useDispatch, useEvents, useExplain, useFact, useHistory, useHydratedSystem, useInspect, useNamespacedSelector, useOptimisticUpdate, useQuerySystem, useRequirementStatus, useSelector, useSuspenseQuery, useSuspenseRequirement, useWatch };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {assertSystem,defaultEquality,runTrackedSelector,createThrottle,buildHistoryState,mergeHydrationFacts,depsChanged,computeInspectState}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';import {createContext,useCallback,useSyncExternalStore,useRef,useMemo,useEffect,useState,useContext}from'react';import {jsx}from'react/jsx-runtime';var J=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var b=Symbol("directive.uninitialized");function ue(e,t){return assertSystem("useFact",e),process.env.NODE_ENV!=="production"&&typeof t=="function"&&console.error("[Directive] useFact() received a function. Did you mean useSelector()? useFact() takes a string key or array of keys, not a selector function."),Array.isArray(t)?ce(e,t):ie(e,t)}function ie(e,t){process.env.NODE_ENV!=="production"&&(t in e.facts.$store.toObject()||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let r=useCallback(n=>e.facts.$store.subscribe([t],n),[e,t]),o=useCallback(()=>e.facts.$store.get(t),[e,t]);return useSyncExternalStore(r,o,o)}function ce(e,t){let r=useRef(b),o=useCallback(u=>e.facts.$store.subscribe(t,u),[e,...t]),n=useCallback(()=>{let u={};for(let s of t)u[s]=e.facts.$store.get(s);if(r.current!==b){let s=true;for(let i of t)if(!Object.is(r.current[i],u[i])){s=false;break}if(s)return r.current}return r.current=u,u},[e,...t]);return useSyncExternalStore(o,n,n)}function ae(e,t){return assertSystem("useDerived",e),process.env.NODE_ENV!=="production"&&typeof t=="function"&&console.error("[Directive] useDerived() received a function. Did you mean useSelector()? useDerived() takes a string key or array of keys, not a selector function."),Array.isArray(t)?de(e,t):le(e,t)}function le(e,t){process.env.NODE_ENV!=="production"&&(t in e.derive||console.warn(`[Directive] useDerived("${t}") \u2014 derivation not found. Check that "${t}" is defined in your module's derive property.`));let r=useCallback(n=>e.subscribe([t],n),[e,t]),o=useCallback(()=>e.read(t),[e,t]);return useSyncExternalStore(r,o,o)}function de(e,t){let r=useRef(b),o=useCallback(u=>e.subscribe(t,u),[e,...t]),n=useCallback(()=>{let u={};for(let s of t)u[s]=e.read(s);if(r.current!==b){let s=true;for(let i of t)if(!Object.is(r.current[i],u[i])){s=false;break}if(s)return r.current}return r.current=u,u},[e,...t]);return useSyncExternalStore(o,n,n)}function Fe(e,t,r,o){if(e&&e._mode==="namespaced")return fe(e,t,r,o);let n=e,u,s=false,i=o??defaultEquality;r!==void 0&&(u=r,s=true),process.env.NODE_ENV!=="production"&&!n&&!s&&console.error("[Directive] useSelector() received a null/undefined system without a default value. Provide a default value as the 3rd parameter: useSelector(system, selector, defaultValue)");let f=useRef(t),l=useRef(i),c=useRef(u),g=useRef(t),y=useRef(0);g.current!==t&&(g.current=t,y.current++),f.current=t,l.current=i,c.current=u;let K=y.current,v=useRef([]),k=useRef([]),x=useRef(b),m=useRef([]),P=useMemo(()=>n?new Set(Object.keys(n.derive)):new Set,[n]),F=useCallback(()=>n?runTrackedSelector(n,P,f.current):{value:c.current,factKeys:[],deriveKeys:[]},[n,P]),I=useCallback(S=>{if(!n)return ()=>{};let p=()=>{for(let M of m.current)M();m.current=[];let{factKeys:R,deriveKeys:w}=F();v.current=R,k.current=w,R.length>0?m.current.push(n.facts.$store.subscribe(R,()=>{let M=F();depsChanged(v.current,M.factKeys,k.current,M.deriveKeys)&&p(),S();})):w.length===0&&m.current.push(n.facts.$store.subscribeAll(S)),w.length>0&&m.current.push(n.subscribe(w,()=>{let M=F();depsChanged(v.current,M.factKeys,k.current,M.deriveKeys)&&p(),S();}));};return p(),()=>{for(let R of m.current)R();m.current=[];}},[n,F,K]),C=useCallback(()=>{let S;if(!n)S=c.current;else {let{value:p}=F();S=p===void 0&&s?c.current:p;}return x.current!==b&&l.current(x.current,S)?x.current:(x.current=S,S)},[F,n,s]);return useSyncExternalStore(I,C,C)}function fe(e,t,r,o){let n=r!==void 0,u=o??defaultEquality,s=useRef(t),i=useRef(u),f=useRef(r);s.current=t,i.current=u,f.current=r;let l=useRef(b),c=useMemo(()=>Object.keys(e.facts),[e]),g=useCallback(K=>{let v=c.map(k=>`${k}.*`);return e.subscribe(v,K)},[e,c]),y=useCallback(()=>{let K=s.current(e),v=K===void 0&&n?f.current:K;return l.current!==b&&i.current(l.current,v)?l.current:(l.current=v,v)},[e,n]);return useSyncExternalStore(g,y,y)}function Se(e){return assertSystem("useDispatch",e),useCallback(t=>{e.dispatch(t);},[e])}function pe(e,t,r){assertSystem("useWatch",e);let o=useRef(r);o.current=r,useEffect(()=>e.watch(t,(n,u)=>{o.current(n,u);}),[e,t]);}function ge(e,t){assertSystem("useInspect",e);let r=ve(e),o=t?.throttleMs,[n,u]=useState(r),s=useRef(null);return useEffect(()=>{if(!o||o<=0){s.current?.cleanup(),s.current=null;return}return s.current?.cleanup(),s.current=createThrottle((...i)=>{u(i[0]);},o),()=>{s.current?.cleanup(),s.current=null;}},[o]),useEffect(()=>{s.current&&s.current.throttled(r);},[r]),!o||o<=0?r:n}function ye(e){return computeInspectState(e)}function ve(e){let t=useRef(null),r=useRef([]),o=useRef([]),n=useRef(null),u=useCallback(i=>{let f=e.facts.$store.subscribeAll(i),l=e.onSettledChange(i);return ()=>{f(),l();}},[e]),s=useCallback(()=>{let i=ye(e),f=i.unmet.length===r.current.length&&i.unmet.every((g,y)=>g.id===r.current[y]),l=i.inflight.length===o.current.length&&i.inflight.every((g,y)=>g.id===o.current[y]),c=i.isSettled===n.current;return f&&l&&c&&t.current?t.current:(t.current=i,r.current=i.unmet.map(g=>g.id),o.current=i.inflight.map(g=>g.id),n.current=i.isSettled,i)},[e]);return useSyncExternalStore(u,s,s)}function Ee(e){assertSystem("useHistory",e);let t=useRef(null),r=useCallback(n=>e.onHistoryChange(n),[e]),o=useCallback(()=>{let n=buildHistoryState(e);return n?(t.current&&t.current.canGoBack===n.canGoBack&&t.current.canGoForward===n.canGoForward&&t.current.currentIndex===n.currentIndex&&t.current.totalSnapshots===n.totalSnapshots&&t.current.isPaused===n.isPaused||(t.current=n),t.current):null},[e]);return useSyncExternalStore(r,o,o)}function Pe(e,t){return Array.isArray(t)?me(e,t):Me(e,t)}function Me(e,t){let r=useRef(b),o=useCallback(u=>e.subscribe(u),[e]),n=useCallback(()=>{let u=e.getStatus(t);if(r.current!==b){let s=r.current;if(s.pending===u.pending&&s.inflight===u.inflight&&s.failed===u.failed&&s.isLoading===u.isLoading&&s.hasError===u.hasError&&s.lastError===u.lastError)return r.current}return r.current=u,u},[e,t]);return useSyncExternalStore(o,n,n)}function me(e,t){let r=useRef(null),o=useRef(""),n=useCallback(s=>e.subscribe(s),[e]),u=useCallback(()=>{let s={},i=[];for(let l of t){let c=e.getStatus(l);s[l]=c,i.push(`${l}:${c.pending}:${c.inflight}:${c.failed}:${c.hasError}:${c.lastError?.message??""}`);}let f=i.join("|");return f!==o.current&&(o.current=f,r.current=s),r.current??s},[e,...t]);return useSyncExternalStore(n,u,u)}var j=new WeakMap;function W(e){let t=j.get(e);return t||(t=new Map,j.set(e,t)),t}function Ce(e,t){return Array.isArray(t)?he(e,t):Re(e,t)}function Re(e,t){let r=e.getStatus(t);if(r.hasError&&r.lastError)throw r.lastError;if(r.isLoading){let o=W(e),n=o.get(t);throw n||(n=new Promise(u=>{let s=e.subscribe(()=>{e.getStatus(t).isLoading||(o.delete(t),s(),u());});}),o.set(t,n)),n}return r}function he(e,t){let r={},o=false,n=null;for(let u of t){let s=e.getStatus(u);r[u]=s,s.hasError&&s.lastError&&!n&&(n=s.lastError),s.isLoading&&(o=true);}if(n)throw n;if(o){let u=W(e),s=t.slice().sort().join(","),i=u.get(s);throw i||(i=new Promise(f=>{let l=e.subscribe(()=>{t.every(g=>!e.getStatus(g).isLoading)&&(u.delete(s),l(),f());});}),u.set(s,i)),i}return r}function _(e,t){let r=useRef(null),o=useRef(null),n=useRef(null),u=t?.status===true,s="modules"in e;return r.current||(n.current=()=>{if(s){let{modules:F,...I}=e,C=t?.plugins??I.plugins??[],S=t?.history??I.history,p=t?.trace??I.trace,R=t?.errorBoundary??I.errorBoundary,w=t?.tickMs??I.tickMs,M=t?.zeroConfig??I.zeroConfig,T=t?.initialFacts??I.initialFacts,N=createSystem({modules:F,plugins:C.length>0?C:void 0,history:S,trace:p,errorBoundary:R,tickMs:w,zeroConfig:M,initialFacts:T});return N.initialize(),typeof window<"u"&&N.start(),N}let i="id"in e&&"schema"in e,f=i?e:e.module,l=i?{}:e,c=t?.plugins??l.plugins??[],g=t?.history??l.history,y=t?.trace??l.trace,K=t?.errorBoundary??l.errorBoundary,v=t?.tickMs??l.tickMs,k=t?.zeroConfig??l.zeroConfig,x=t?.initialFacts??l.initialFacts,m=[...c];u&&(o.current=createRequirementStatusPlugin(),m=[...m,o.current.plugin]);let P=createSystem({module:f,plugins:m.length>0?m:void 0,history:g,trace:y,errorBoundary:K,tickMs:v,zeroConfig:k,initialFacts:x});return P.initialize(),typeof window<"u"&&P.start(),P},r.current=n.current()),useEffect(()=>(!r.current&&n.current&&(r.current=n.current()),()=>{r.current?.destroy(),r.current=null,o.current=null;}),[]),u&&!s?{system:r.current,statusPlugin:o.current}:r.current}function Te(e,t,r){let o=useRef(t);o.current=t;let n=useRef(r);n.current=r;let u=useCallback(i=>e.subscribe(o.current,i),[e]),s=useCallback(()=>n.current(e),[e]);return useSyncExternalStore(u,s,s)}function Ue(e,t={}){let{facts:r,derived:o,status:n,...u}=t,s=r??[],i=o??[],f=s.length===0&&i.length===0,l=n?_(e,{status:true,...u}):_(e,u),c=n?l.system:l,g=n?l.statusPlugin:void 0,y=useMemo(()=>f?Object.keys(c.derive):[],[c,f]),K=useCallback(S=>{let p=[];return f?(p.push(c.facts.$store.subscribeAll(S)),y.length>0&&p.push(c.subscribe(y,S))):(s.length>0&&p.push(c.facts.$store.subscribe(s,S)),i.length>0&&p.push(c.subscribe(i,S))),()=>{for(let R of p)R();}},[c,f,...s,...i,...y]),v=useRef(b),k=useRef(b),x=useRef(null),m=useCallback(()=>{let S,p,R,w;if(f){S=c.facts.$store.toObject(),R=Object.keys(S),p={};for(let h of y)p[h]=c.read(h);w=y;}else {S={};for(let h of s)S[h]=c.facts[h];R=s,p={};for(let h of i)p[h]=c.read(h);w=i;}let M=v.current!==b;if(M){let h=v.current;if(Object.keys(h).length!==R.length)M=false;else for(let O of R)if(!Object.is(h[O],S[O])){M=false;break}}let T=k.current!==b;if(T){let h=k.current;if(Object.keys(h).length!==w.length)T=false;else for(let O of w)if(!Object.is(h[O],p[O])){T=false;break}}let N=M?v.current:S,Z=T?k.current:p;return M||(v.current=S),T||(k.current=p),M&&T&&x.current||(x.current={facts:N,derived:Z}),x.current},[c,f,...s,...i,...y]),P=useSyncExternalStore(K,m,m),F=useCallback(S=>c.dispatch(S),[c]),I=z(c),C={system:c,dispatch:F,events:I,facts:P.facts,derived:P.derived};return n&&g?{...C,statusPlugin:g}:C}function z(e){return assertSystem("useEvents",e),useMemo(()=>e.events,[e])}function Ve(e,t){assertSystem("useExplain",e);let r=useCallback(n=>{let u=e.facts.$store.subscribeAll(n),s=e.onSettledChange(n);return ()=>{u(),s();}},[e]),o=useCallback(()=>e.explain(t),[e,t]);return useSyncExternalStore(r,o,o)}function Ne(e,t){assertSystem("useConstraintStatus",e);let r=ge(e);return useMemo(()=>{let o=e.inspect();return t?o.constraints.find(n=>n.id===t)??null:o.constraints},[e,t,r])}function Oe(e,t,r){assertSystem("useOptimisticUpdate",e);let[o,n]=useState(false),[u,s]=useState(null),i=useRef(null),f=useCallback(()=>{i.current&&(e.restore(i.current),i.current=null),n(false),s(null);},[e]),l=useCallback(c=>{i.current=e.getSnapshot(),n(true),s(null),e.batch(c);},[e]);return useEffect(()=>{if(!(!t||!r||!o))return t.subscribe(()=>{let c=t.getStatus(r);!c.isLoading&&!c.hasError?(i.current=null,n(false)):c.hasError&&(s(c.lastError),f());})},[t,r,o,f]),{mutate:l,isPending:o,error:u,rollback:f}}var Q=createContext(null);function qe({snapshot:e,children:t}){return jsx(Q.Provider,{value:e,children:t})}function $e(e,t){let r=useContext(Q),o=useMemo(()=>{let n=mergeHydrationFacts(r,t?.initialFacts);return {...t??{},initialFacts:n}},[r,t]);return _(e,o)}function Be(){return {useFact:(e,t)=>ue(e,t),useDerived:(e,t)=>ae(e,t),useDispatch:e=>Se(e),useEvents:e=>z(e),useWatch:(e,t,r)=>pe(e,t,r)}}var q=null;function be(){if(!q)try{q=J("@directive-run/query").createQuerySystem;}catch{throw new Error("[Directive] @directive-run/query is not installed. Install it with: pnpm add @directive-run/query")}return q}function _e(e){let t=useRef(e),r=useMemo(()=>{let u=be();return ()=>u(t.current)},[]),o=useRef(null),n=useRef(r);return n.current=r,o.current||(o.current=n.current()),useEffect(()=>(!o.current&&n.current&&(o.current=n.current()),typeof window<"u"&&o.current&&!o.current.isRunning&&o.current.start(),()=>{o.current?.destroy(),o.current=null;}),[]),o.current}var $=new WeakMap;function He(e,t){let r=useCallback(s=>e.subscribe([t],s),[e,t]),o=useCallback(()=>e.read(t),[e,t]),n=useSyncExternalStore(r,o,o);$.has(e)||$.set(e,new Map);let u=$.get(e);if(n?.status==="success"&&n?.data!==null)return u.has(t)&&(u.get(t).resolve(),u.delete(t)),n.data;if(n?.status==="error"&&n?.error)throw u.has(t)&&(u.get(t).resolve(),u.delete(t)),n.error;if(!u.has(t)){let s,i=new Promise(l=>{s=l;});u.set(t,{promise:i,resolve:s});let f=e.subscribe([t],()=>{let l=e.read(t);if(l?.status==="success"||l?.status==="error"){let c=u.get(t);c&&(c.resolve(),u.delete(t)),f();}});}throw u.get(t).promise}export{qe as DirectiveHydrator,Be as createTypedHooks,Ne as useConstraintStatus,ae as useDerived,Ue as useDirective,_ as useDirectiveRef,Se as useDispatch,z as useEvents,Ve as useExplain,ue as useFact,Ee as useHistory,$e as useHydratedSystem,ge as useInspect,Te as useNamespacedSelector,Oe as useOptimisticUpdate,_e as useQuerySystem,Pe as useRequirementStatus,Fe as useSelector,He as useSuspenseQuery,Ce as useSuspenseRequirement,pe as useWatch};//# sourceMappingURL=index.js.map
|
|
1
|
+
import {createSystem,createRequirementStatusPlugin}from'@directive-run/core';import {assertSystem,defaultEquality,runTrackedSelector,createThrottle,buildHistoryState,mergeHydrationFacts,depsChanged,computeInspectState}from'@directive-run/core/adapter-utils';export{shallowEqual}from'@directive-run/core/adapter-utils';import {createContext,useCallback,useSyncExternalStore,useRef,useMemo,useEffect,useState,useContext}from'react';import {jsx}from'react/jsx-runtime';var oe=(e=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(e,{get:(t,r)=>(typeof require<"u"?require:t)[r]}):e)(function(e){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var b=Symbol("directive.uninitialized");function Z(e,t){return assertSystem("useFact",e),process.env.NODE_ENV!=="production"&&typeof t=="function"&&console.error("[Directive] useFact() received a function. Did you mean useSelector()? useFact() takes a string key or array of keys, not a selector function."),Array.isArray(t)?Se(e,t):fe(e,t)}function fe(e,t){process.env.NODE_ENV!=="production"&&(t in e.facts.$store.toObject()||console.warn(`[Directive] useFact("${t}") \u2014 fact not found in store. Check that "${t}" is defined in your module's schema.`));let r=useCallback(n=>e.facts.$store.subscribe([t],n),[e,t]),o=useCallback(()=>e.facts.$store.get(t),[e,t]);return useSyncExternalStore(r,o,o)}function Se(e,t){let r=useRef(b),o=useCallback(u=>e.facts.$store.subscribe(t,u),[e,...t]),n=useCallback(()=>{let u={};for(let s of t)u[s]=e.facts.$store.get(s);if(r.current!==b){let s=true;for(let i of t)if(!Object.is(r.current[i],u[i])){s=false;break}if(s)return r.current}return r.current=u,u},[e,...t]);return useSyncExternalStore(o,n,n)}function G(e,t){return assertSystem("useDerived",e),process.env.NODE_ENV!=="production"&&typeof t=="function"&&console.error("[Directive] useDerived() received a function. Did you mean useSelector()? useDerived() takes a string key or array of keys, not a selector function."),Array.isArray(t)?ge(e,t):pe(e,t)}function pe(e,t){process.env.NODE_ENV!=="production"&&(t in e.derive||console.warn(`[Directive] useDerived("${t}") \u2014 derivation not found. Check that "${t}" is defined in your module's derive property.`));let r=useCallback(n=>e.subscribe([t],n),[e,t]),o=useCallback(()=>e.read(t),[e,t]);return useSyncExternalStore(r,o,o)}function ge(e,t){let r=useRef(b),o=useCallback(u=>e.subscribe(t,u),[e,...t]),n=useCallback(()=>{let u={};for(let s of t)u[s]=e.read(s);if(r.current!==b){let s=true;for(let i of t)if(!Object.is(r.current[i],u[i])){s=false;break}if(s)return r.current}return r.current=u,u},[e,...t]);return useSyncExternalStore(o,n,n)}function ye(e,t,r,o){if(e&&e._mode==="namespaced")return ve(e,t,r,o);let n=e,u,s=false,i=o??defaultEquality;r!==void 0&&(u=r,s=true),process.env.NODE_ENV!=="production"&&!n&&!s&&console.error("[Directive] useSelector() received a null/undefined system without a default value. Provide a default value as the 3rd parameter: useSelector(system, selector, defaultValue)");let f=useRef(t),l=useRef(i),c=useRef(u),g=useRef(t),y=useRef(0);g.current!==t&&(g.current=t,y.current++),f.current=t,l.current=i,c.current=u;let K=y.current,v=useRef([]),x=useRef([]),k=useRef(b),m=useRef([]),P=useMemo(()=>n?new Set(Object.keys(n.derive)):new Set,[n]),F=useCallback(()=>n?runTrackedSelector(n,P,f.current):{value:c.current,factKeys:[],deriveKeys:[]},[n,P]),I=useCallback(S=>{if(!n)return ()=>{};let p=()=>{for(let M of m.current)M();m.current=[];let{factKeys:R,deriveKeys:w}=F();v.current=R,x.current=w,R.length>0?m.current.push(n.facts.$store.subscribe(R,()=>{let M=F();depsChanged(v.current,M.factKeys,x.current,M.deriveKeys)&&p(),S();})):w.length===0&&m.current.push(n.facts.$store.subscribeAll(S)),w.length>0&&m.current.push(n.subscribe(w,()=>{let M=F();depsChanged(v.current,M.factKeys,x.current,M.deriveKeys)&&p(),S();}));};return p(),()=>{for(let R of m.current)R();m.current=[];}},[n,F,K]),C=useCallback(()=>{let S;if(!n)S=c.current;else {let{value:p}=F();S=p===void 0&&s?c.current:p;}return k.current!==b&&l.current(k.current,S)?k.current:(k.current=S,S)},[F,n,s]);return useSyncExternalStore(I,C,C)}function ve(e,t,r,o){let n=r!==void 0,u=o??defaultEquality,s=useRef(t),i=useRef(u),f=useRef(r);s.current=t,i.current=u,f.current=r;let l=useRef(b),c=useMemo(()=>Object.keys(e.facts),[e]),g=useCallback(K=>{let v=c.map(x=>`${x}.*`);return e.subscribe(v,K)},[e,c]),y=useCallback(()=>{let K=s.current(e),v=K===void 0&&n?f.current:K;return l.current!==b&&i.current(l.current,v)?l.current:(l.current=v,v)},[e,n]);return useSyncExternalStore(g,y,y)}function J(e){return assertSystem("useDispatch",e),useCallback(t=>{e.dispatch(t);},[e])}function X(e,t,r){assertSystem("useWatch",e);let o=useRef(r);o.current=r,useEffect(()=>e.watch(t,(n,u)=>{o.current(n,u);}),[e,t]);}function Y(e,t){assertSystem("useInspect",e);let r=me(e),o=t?.throttleMs,[n,u]=useState(r),s=useRef(null);return useEffect(()=>{if(!o||o<=0){s.current?.cleanup(),s.current=null;return}return s.current?.cleanup(),s.current=createThrottle((...i)=>{u(i[0]);},o),()=>{s.current?.cleanup(),s.current=null;}},[o]),useEffect(()=>{s.current&&s.current.throttled(r);},[r]),!o||o<=0?r:n}function Me(e){return computeInspectState(e)}function me(e){let t=useRef(null),r=useRef([]),o=useRef([]),n=useRef(null),u=useCallback(i=>{let f=e.facts.$store.subscribeAll(i),l=e.onSettledChange(i);return ()=>{f(),l();}},[e]),s=useCallback(()=>{let i=Me(e),f=i.unmet.length===r.current.length&&i.unmet.every((g,y)=>g.id===r.current[y]),l=i.inflight.length===o.current.length&&i.inflight.every((g,y)=>g.id===o.current[y]),c=i.isSettled===n.current;return f&&l&&c&&t.current?t.current:(t.current=i,r.current=i.unmet.map(g=>g.id),o.current=i.inflight.map(g=>g.id),n.current=i.isSettled,i)},[e]);return useSyncExternalStore(u,s,s)}function Re(e){assertSystem("useHistory",e);let t=useRef(null),r=useCallback(n=>e.onHistoryChange(n),[e]),o=useCallback(()=>{let n=buildHistoryState(e);return n?(t.current&&t.current.canGoBack===n.canGoBack&&t.current.canGoForward===n.canGoForward&&t.current.currentIndex===n.currentIndex&&t.current.totalSnapshots===n.totalSnapshots&&t.current.isPaused===n.isPaused||(t.current=n),t.current):null},[e]);return useSyncExternalStore(r,o,o)}function Ce(e,t){return Array.isArray(t)?be(e,t):he(e,t)}function he(e,t){let r=useRef(b),o=useCallback(u=>e.subscribe(u),[e]),n=useCallback(()=>{let u=e.getStatus(t);if(r.current!==b){let s=r.current;if(s.pending===u.pending&&s.inflight===u.inflight&&s.failed===u.failed&&s.isLoading===u.isLoading&&s.hasError===u.hasError&&s.lastError===u.lastError)return r.current}return r.current=u,u},[e,t]);return useSyncExternalStore(o,n,n)}function be(e,t){let r=useRef(null),o=useRef(""),n=useCallback(s=>e.subscribe(s),[e]),u=useCallback(()=>{let s={},i=[];for(let l of t){let c=e.getStatus(l);s[l]=c,i.push(`${l}:${c.pending}:${c.inflight}:${c.failed}:${c.hasError}:${c.lastError?.message??""}`);}let f=i.join("|");return f!==o.current&&(o.current=f,r.current=s),r.current??s},[e,...t]);return useSyncExternalStore(n,u,u)}var j=new WeakMap;function ee(e){let t=j.get(e);return t||(t=new Map,j.set(e,t)),t}function Ve(e,t){return Array.isArray(t)?xe(e,t):De(e,t)}function De(e,t){let r=e.getStatus(t);if(r.hasError&&r.lastError)throw r.lastError;if(r.isLoading){let o=ee(e),n=o.get(t);throw n||(n=new Promise(u=>{let s=e.subscribe(()=>{e.getStatus(t).isLoading||(o.delete(t),s(),u());});}),o.set(t,n)),n}return r}function xe(e,t){let r={},o=false,n=null;for(let u of t){let s=e.getStatus(u);r[u]=s,s.hasError&&s.lastError&&!n&&(n=s.lastError),s.isLoading&&(o=true);}if(n)throw n;if(o){let u=ee(e),s=t.slice().sort().join(","),i=u.get(s);throw i||(i=new Promise(f=>{let l=e.subscribe(()=>{t.every(g=>!e.getStatus(g).isLoading)&&(u.delete(s),l(),f());});}),u.set(s,i)),i}return r}function H(e,t){let r=useRef(null),o=useRef(null),n=useRef(null),u=t?.status===true,s="modules"in e;return r.current||(n.current=()=>{if(s){let{modules:F,...I}=e,C=t?.plugins??I.plugins??[],S=t?.history??I.history,p=t?.trace??I.trace,R=t?.errorBoundary??I.errorBoundary,w=t?.tickMs??I.tickMs,M=t?.zeroConfig??I.zeroConfig,V=t?.initialFacts??I.initialFacts,U=createSystem({modules:F,plugins:C.length>0?C:void 0,history:S,trace:p,errorBoundary:R,tickMs:w,zeroConfig:M,initialFacts:V});return U.initialize(),typeof window<"u"&&U.start(),U}let i="id"in e&&"schema"in e,f=i?e:e.module,l=i?{}:e,c=t?.plugins??l.plugins??[],g=t?.history??l.history,y=t?.trace??l.trace,K=t?.errorBoundary??l.errorBoundary,v=t?.tickMs??l.tickMs,x=t?.zeroConfig??l.zeroConfig,k=t?.initialFacts??l.initialFacts,m=[...c];u&&(o.current=createRequirementStatusPlugin(),m=[...m,o.current.plugin]);let P=createSystem({module:f,plugins:m.length>0?m:void 0,history:g,trace:y,errorBoundary:K,tickMs:v,zeroConfig:x,initialFacts:k});return P.initialize(),typeof window<"u"&&P.start(),P},r.current=n.current()),useEffect(()=>(!r.current&&n.current&&(r.current=n.current()),()=>{r.current?.destroy(),r.current=null,o.current=null;}),[]),u&&!s?{system:r.current,statusPlugin:o.current}:r.current}function Te(e,t,r){let o=useRef(t);o.current=t;let n=useRef(r);n.current=r;let u=useCallback(i=>e.subscribe(o.current,i),[e]),s=useCallback(()=>n.current(e),[e]);return useSyncExternalStore(u,s,s)}function Ne(e,t={}){let{facts:r,derived:o,status:n,...u}=t,s=r??[],i=o??[],f=s.length===0&&i.length===0,l=n?H(e,{status:true,...u}):H(e,u),c=n?l.system:l,g=n?l.statusPlugin:void 0,y=useMemo(()=>f?Object.keys(c.derive):[],[c,f]),K=useCallback(S=>{let p=[];return f?(p.push(c.facts.$store.subscribeAll(S)),y.length>0&&p.push(c.subscribe(y,S))):(s.length>0&&p.push(c.facts.$store.subscribe(s,S)),i.length>0&&p.push(c.subscribe(i,S))),()=>{for(let R of p)R();}},[c,f,...s,...i,...y]),v=useRef(b),x=useRef(b),k=useRef(null),m=useCallback(()=>{let S,p,R,w;if(f){S=c.facts.$store.toObject(),R=Object.keys(S),p={};for(let h of y)p[h]=c.read(h);w=y;}else {S={};for(let h of s)S[h]=c.facts[h];R=s,p={};for(let h of i)p[h]=c.read(h);w=i;}let M=v.current!==b;if(M){let h=v.current;if(Object.keys(h).length!==R.length)M=false;else for(let O of R)if(!Object.is(h[O],S[O])){M=false;break}}let V=x.current!==b;if(V){let h=x.current;if(Object.keys(h).length!==w.length)V=false;else for(let O of w)if(!Object.is(h[O],p[O])){V=false;break}}let U=M?v.current:S,re=V?x.current:p;return M||(v.current=S),V||(x.current=p),M&&V&&k.current||(k.current={facts:U,derived:re}),k.current},[c,f,...s,...i,...y]),P=useSyncExternalStore(K,m,m),F=useCallback(S=>c.dispatch(S),[c]),I=_(c),C={system:c,dispatch:F,events:I,facts:P.facts,derived:P.derived};return n&&g?{...C,statusPlugin:g}:C}function _(e){return assertSystem("useEvents",e),useMemo(()=>e.events,[e])}function ke(e,t){assertSystem("useExplain",e);let r=useCallback(n=>{let u=e.facts.$store.subscribeAll(n),s=e.onSettledChange(n);return ()=>{u(),s();}},[e]),o=useCallback(()=>e.explain(t),[e,t]);return useSyncExternalStore(r,o,o)}function Ue(e,t){assertSystem("useConstraintStatus",e);let r=Y(e);return useMemo(()=>{let o=e.inspect();return t?o.constraints.find(n=>n.id===t)??null:o.constraints},[e,t,r])}function Oe(e,t,r){assertSystem("useOptimisticUpdate",e);let[o,n]=useState(false),[u,s]=useState(null),i=useRef(null),f=useCallback(()=>{i.current&&(e.restore(i.current),i.current=null),n(false),s(null);},[e]),l=useCallback(c=>{i.current=e.getSnapshot(),n(true),s(null),e.batch(c);},[e]);return useEffect(()=>{if(!(!t||!r||!o))return t.subscribe(()=>{let c=t.getStatus(r);!c.isLoading&&!c.hasError?(i.current=null,n(false)):c.hasError&&(s(c.lastError),f());})},[t,r,o,f]),{mutate:l,isPending:o,error:u,rollback:f}}var te=createContext(null);function qe({snapshot:e,children:t}){return jsx(te.Provider,{value:e,children:t})}function $e(e,t){let r=useContext(te),o=useMemo(()=>{let n=mergeHydrationFacts(r,t?.initialFacts);return {...t??{},initialFacts:n}},[r,t]);return H(e,o)}function Be(){return {useFact:(e,t)=>Z(e,t),useDerived:(e,t)=>G(e,t),useDispatch:e=>J(e),useEvents:e=>_(e),useWatch:(e,t,r)=>X(e,t,r)}}var q=null;function Ie(){if(!q)try{q=oe("@directive-run/query").createQuerySystem;}catch{throw new Error("[Directive] @directive-run/query is not installed. Install it with: pnpm add @directive-run/query")}return q}function He(e){let t=useRef(e),r=useMemo(()=>{let u=Ie();return ()=>u(t.current)},[]),o=useRef(null),n=useRef(r);return n.current=r,o.current||(o.current=n.current()),useEffect(()=>(!o.current&&n.current&&(o.current=n.current()),typeof window<"u"&&o.current&&!o.current.isRunning&&o.current.start(),()=>{o.current?.destroy(),o.current=null;}),[]),o.current}var $=new WeakMap;function _e(e,t){let r=useCallback(s=>e.subscribe([t],s),[e,t]),o=useCallback(()=>e.read(t),[e,t]),n=useSyncExternalStore(r,o,o);$.has(e)||$.set(e,new Map);let u=$.get(e);if(n?.status==="success"&&n?.data!==null)return u.has(t)&&(u.get(t).resolve(),u.delete(t)),n.data;if(n?.status==="error"&&n?.error)throw u.has(t)&&(u.get(t).resolve(),u.delete(t)),n.error;if(!u.has(t)){let s,i=new Promise(l=>{s=l;});u.set(t,{promise:i,resolve:s});let f=e.subscribe([t],()=>{let l=e.read(t);if(l?.status==="success"||l?.status==="error"){let c=u.get(t);c&&(c.resolve(),u.delete(t)),f();}});}throw u.get(t).promise}function We(e){let t=createContext(null);function r(){let n=useContext(t);if(!n)throw new Error("[Directive] useSystem called outside of <Provider>. Wrap your component tree with the Provider from createDirectiveContext().");return n}function o({children:n,system:u}){return jsx(t.Provider,{value:u??e,children:n})}return o.displayName="DirectiveProvider",{Provider:o,useSystem:r,useFact:n=>Z(r(),n),useDerived:n=>G(r(),n),useEvents:()=>_(r()),useDispatch:()=>J(r()),useSelector:(n,u)=>ye(r(),n,u),useWatch:(n,u)=>X(r(),n,u),useInspect:()=>Y(r()),useExplain:n=>ke(r(),n),useHistory:()=>Re(r())}}export{qe as DirectiveHydrator,We as createDirectiveContext,Be as createTypedHooks,Ue as useConstraintStatus,G as useDerived,Ne as useDirective,H as useDirectiveRef,J as useDispatch,_ as useEvents,ke as useExplain,Z as useFact,Re as useHistory,$e as useHydratedSystem,Y as useInspect,Te as useNamespacedSelector,Oe as useOptimisticUpdate,He as useQuerySystem,Ce as useRequirementStatus,ye as useSelector,_e as useSuspenseQuery,Ve as useSuspenseRequirement,X as useWatch};//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|