cross-state 0.53.3 → 0.54.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.
Files changed (236) hide show
  1. package/dist/chunk-CUT6urMc.cjs +30 -0
  2. package/dist/diff-BQ8bB3Wk.d.cts +22 -0
  3. package/dist/diff-gZezL04N.d.ts +22 -0
  4. package/dist/extendedJson-BZkQBXEv.js +29 -0
  5. package/dist/extendedJson-BZkQBXEv.js.map +1 -0
  6. package/dist/extendedJson-Dn2F7Edo.cjs +53 -0
  7. package/dist/extendedJson-Dn2F7Edo.cjs.map +1 -0
  8. package/dist/hash-BV06P7va.js +19 -0
  9. package/dist/hash-BV06P7va.js.map +1 -0
  10. package/dist/hash-CJPl7SRj.cjs +30 -0
  11. package/dist/hash-CJPl7SRj.cjs.map +1 -0
  12. package/dist/index.cjs +49 -0
  13. package/dist/index.cjs.map +1 -0
  14. package/dist/index.d.cts +59 -0
  15. package/dist/index.d.ts +59 -0
  16. package/dist/index.js +20 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/mutative/index.cjs +3 -0
  19. package/dist/mutative/index.d.cts +3 -0
  20. package/dist/mutative/index.d.ts +3 -0
  21. package/dist/mutative/index.js +3 -0
  22. package/dist/mutative/register.cjs +10 -0
  23. package/dist/mutative/register.cjs.map +1 -0
  24. package/dist/mutative/register.d.cts +11 -0
  25. package/dist/mutative/register.d.ts +9 -0
  26. package/dist/mutative/register.js +10 -0
  27. package/dist/mutative/register.js.map +1 -0
  28. package/dist/mutativeMethods-6QzygG3W.d.cts +13 -0
  29. package/dist/mutativeMethods-Br3xN2Iq.d.ts +13 -0
  30. package/dist/mutativeMethods-CZKeRIDL.js +27 -0
  31. package/dist/mutativeMethods-CZKeRIDL.js.map +1 -0
  32. package/dist/mutativeMethods-CgXk_bMt.cjs +33 -0
  33. package/dist/mutativeMethods-CgXk_bMt.cjs.map +1 -0
  34. package/dist/patchMethods-C3L7Kh8T.d.cts +48 -0
  35. package/dist/patchMethods-D5YJwcpn.cjs +264 -0
  36. package/dist/patchMethods-D5YJwcpn.cjs.map +1 -0
  37. package/dist/patchMethods-DRPfkhAe.js +241 -0
  38. package/dist/patchMethods-DRPfkhAe.js.map +1 -0
  39. package/dist/patchMethods-Dxad6HF6.d.ts +48 -0
  40. package/dist/patches/index.cjs +5 -0
  41. package/dist/patches/index.d.cts +4 -0
  42. package/dist/patches/index.d.ts +4 -0
  43. package/dist/patches/index.js +5 -0
  44. package/dist/patches/register.cjs +11 -0
  45. package/dist/patches/register.cjs.map +1 -0
  46. package/dist/patches/register.d.cts +12 -0
  47. package/dist/patches/register.d.ts +10 -0
  48. package/dist/patches/register.js +11 -0
  49. package/dist/patches/register.js.map +1 -0
  50. package/dist/persist/register.cjs +13 -0
  51. package/dist/persist/register.cjs.map +1 -0
  52. package/dist/persist/register.d.cts +15 -0
  53. package/dist/persist/register.d.ts +13 -0
  54. package/dist/persist/register.js +13 -0
  55. package/dist/persist/register.js.map +1 -0
  56. package/dist/persist-BluRVcW6.js +258 -0
  57. package/dist/persist-BluRVcW6.js.map +1 -0
  58. package/dist/persist-CPjpg6D0.d.ts +61 -0
  59. package/dist/persist-CztClydq.cjs +263 -0
  60. package/dist/persist-CztClydq.cjs.map +1 -0
  61. package/dist/persist-D7MAsyyW.d.cts +61 -0
  62. package/dist/propAccess-ByqBjC19.cjs +173 -0
  63. package/dist/propAccess-ByqBjC19.cjs.map +1 -0
  64. package/dist/propAccess-DGchzVfy.js +113 -0
  65. package/dist/propAccess-DGchzVfy.js.map +1 -0
  66. package/dist/react/index.cjs +610 -0
  67. package/dist/react/index.cjs.map +1 -0
  68. package/dist/react/index.d.cts +305 -0
  69. package/dist/react/index.d.ts +305 -0
  70. package/dist/react/index.js +590 -0
  71. package/dist/react/index.js.map +1 -0
  72. package/dist/react/register.cjs +16 -0
  73. package/dist/react/register.cjs.map +1 -0
  74. package/dist/react/register.d.cts +16 -0
  75. package/dist/react/register.d.ts +14 -0
  76. package/dist/react/register.js +16 -0
  77. package/dist/react/register.js.map +1 -0
  78. package/dist/scope-DI1OFHcr.d.ts +167 -0
  79. package/dist/scope-DO5vpLPV.d.cts +167 -0
  80. package/dist/scope-DU5dFP1T.js +322 -0
  81. package/dist/scope-DU5dFP1T.js.map +1 -0
  82. package/dist/scope-DvqvkIHB.cjs +369 -0
  83. package/dist/scope-DvqvkIHB.cjs.map +1 -0
  84. package/dist/store-BEsiS8y7.d.cts +242 -0
  85. package/dist/store-BWMWEUpu.cjs +819 -0
  86. package/dist/store-BWMWEUpu.cjs.map +1 -0
  87. package/dist/store-DKaeE840.d.ts +242 -0
  88. package/dist/store-Dr8gM3lq.js +730 -0
  89. package/dist/store-Dr8gM3lq.js.map +1 -0
  90. package/dist/storeMethods-AIJSwxHz.js +315 -0
  91. package/dist/storeMethods-AIJSwxHz.js.map +1 -0
  92. package/dist/storeMethods-BQwU2Uia.d.cts +107 -0
  93. package/dist/storeMethods-C4luym7C.d.ts +107 -0
  94. package/dist/storeMethods-DVVsmUg1.cjs +375 -0
  95. package/dist/storeMethods-DVVsmUg1.cjs.map +1 -0
  96. package/package.json +92 -135
  97. package/dist/cjs/hash.cjs +0 -30
  98. package/dist/cjs/hash.cjs.map +0 -1
  99. package/dist/cjs/index.cjs +0 -56
  100. package/dist/cjs/index.cjs.map +0 -1
  101. package/dist/cjs/index2.cjs +0 -300
  102. package/dist/cjs/index2.cjs.map +0 -1
  103. package/dist/cjs/mutative/index.cjs +0 -10
  104. package/dist/cjs/mutative/index.cjs.map +0 -1
  105. package/dist/cjs/mutative/register.cjs +0 -8
  106. package/dist/cjs/mutative/register.cjs.map +0 -1
  107. package/dist/cjs/mutativeMethods.cjs +0 -29
  108. package/dist/cjs/mutativeMethods.cjs.map +0 -1
  109. package/dist/cjs/patches/index.cjs +0 -10
  110. package/dist/cjs/patches/index.cjs.map +0 -1
  111. package/dist/cjs/patches/register.cjs +0 -8
  112. package/dist/cjs/patches/register.cjs.map +0 -1
  113. package/dist/cjs/persist/register.cjs +0 -11
  114. package/dist/cjs/persist/register.cjs.map +0 -1
  115. package/dist/cjs/persist.cjs +0 -302
  116. package/dist/cjs/persist.cjs.map +0 -1
  117. package/dist/cjs/propAccess.cjs +0 -162
  118. package/dist/cjs/propAccess.cjs.map +0 -1
  119. package/dist/cjs/react/index.cjs +0 -628
  120. package/dist/cjs/react/index.cjs.map +0 -1
  121. package/dist/cjs/react/register.cjs +0 -13
  122. package/dist/cjs/react/register.cjs.map +0 -1
  123. package/dist/cjs/scope.cjs +0 -400
  124. package/dist/cjs/scope.cjs.map +0 -1
  125. package/dist/cjs/store.cjs +0 -829
  126. package/dist/cjs/store.cjs.map +0 -1
  127. package/dist/cjs/storeMethods.cjs +0 -856
  128. package/dist/cjs/storeMethods.cjs.map +0 -1
  129. package/dist/cjs/urlStore.cjs +0 -120
  130. package/dist/cjs/urlStore.cjs.map +0 -1
  131. package/dist/es/hash.mjs +0 -27
  132. package/dist/es/hash.mjs.map +0 -1
  133. package/dist/es/index.mjs +0 -20
  134. package/dist/es/index.mjs.map +0 -1
  135. package/dist/es/index2.mjs +0 -291
  136. package/dist/es/index2.mjs.map +0 -1
  137. package/dist/es/mutative/index.mjs +0 -2
  138. package/dist/es/mutative/index.mjs.map +0 -1
  139. package/dist/es/mutative/register.mjs +0 -6
  140. package/dist/es/mutative/register.mjs.map +0 -1
  141. package/dist/es/mutativeMethods.mjs +0 -27
  142. package/dist/es/mutativeMethods.mjs.map +0 -1
  143. package/dist/es/patches/index.mjs +0 -2
  144. package/dist/es/patches/index.mjs.map +0 -1
  145. package/dist/es/patches/register.mjs +0 -6
  146. package/dist/es/patches/register.mjs.map +0 -1
  147. package/dist/es/persist/register.mjs +0 -9
  148. package/dist/es/persist/register.mjs.map +0 -1
  149. package/dist/es/persist.mjs +0 -300
  150. package/dist/es/persist.mjs.map +0 -1
  151. package/dist/es/propAccess.mjs +0 -151
  152. package/dist/es/propAccess.mjs.map +0 -1
  153. package/dist/es/react/index.mjs +0 -611
  154. package/dist/es/react/index.mjs.map +0 -1
  155. package/dist/es/react/register.mjs +0 -11
  156. package/dist/es/react/register.mjs.map +0 -1
  157. package/dist/es/scope.mjs +0 -391
  158. package/dist/es/scope.mjs.map +0 -1
  159. package/dist/es/store.mjs +0 -812
  160. package/dist/es/store.mjs.map +0 -1
  161. package/dist/es/storeMethods.mjs +0 -845
  162. package/dist/es/storeMethods.mjs.map +0 -1
  163. package/dist/es/urlStore.mjs +0 -116
  164. package/dist/es/urlStore.mjs.map +0 -1
  165. package/dist/types/core/cache.d.ts +0 -119
  166. package/dist/types/core/commonTypes.d.ts +0 -76
  167. package/dist/types/core/index.d.ts +0 -6
  168. package/dist/types/core/resourceGroup.d.ts +0 -16
  169. package/dist/types/core/scope.d.ts +0 -5
  170. package/dist/types/core/store.d.ts +0 -86
  171. package/dist/types/core/urlStore.d.ts +0 -21
  172. package/dist/types/index.d.ts +0 -14
  173. package/dist/types/lib/applyPatches.d.ts +0 -2
  174. package/dist/types/lib/autobind.d.ts +0 -1
  175. package/dist/types/lib/cacheState.d.ts +0 -20
  176. package/dist/types/lib/calcDuration.d.ts +0 -2
  177. package/dist/types/lib/calculatedValue.d.ts +0 -9
  178. package/dist/types/lib/castArray.d.ts +0 -1
  179. package/dist/types/lib/clone.d.ts +0 -1
  180. package/dist/types/lib/constrain.d.ts +0 -1
  181. package/dist/types/lib/debounce.d.ts +0 -12
  182. package/dist/types/lib/deferred.d.ts +0 -5
  183. package/dist/types/lib/diff.d.ts +0 -17
  184. package/dist/types/lib/disposable.d.ts +0 -3
  185. package/dist/types/lib/equals.d.ts +0 -3
  186. package/dist/types/lib/extendedJson.d.ts +0 -5
  187. package/dist/types/lib/forwardError.d.ts +0 -1
  188. package/dist/types/lib/hash.d.ts +0 -5
  189. package/dist/types/lib/helpers.d.ts +0 -2
  190. package/dist/types/lib/instanceCache.d.ts +0 -18
  191. package/dist/types/lib/isPromise.d.ts +0 -1
  192. package/dist/types/lib/makeSelector.d.ts +0 -2
  193. package/dist/types/lib/maybePromise.d.ts +0 -1
  194. package/dist/types/lib/path.d.ts +0 -41
  195. package/dist/types/lib/promiseChain.d.ts +0 -5
  196. package/dist/types/lib/promiseWithCancel.d.ts +0 -8
  197. package/dist/types/lib/promiseWithState.d.ts +0 -9
  198. package/dist/types/lib/propAccess.d.ts +0 -7
  199. package/dist/types/lib/queue.d.ts +0 -11
  200. package/dist/types/lib/standardMethods.d.ts +0 -20
  201. package/dist/types/lib/throttle.d.ts +0 -2
  202. package/dist/types/lib/trackingProxy.d.ts +0 -2
  203. package/dist/types/lib/trie.d.ts +0 -11
  204. package/dist/types/lib/typeHelpers.d.ts +0 -12
  205. package/dist/types/lib/unwrapPromise.d.ts +0 -1
  206. package/dist/types/lib/updateHelpers.d.ts +0 -1
  207. package/dist/types/lib/wildcardMatch.d.ts +0 -3
  208. package/dist/types/mutative/index.d.ts +0 -1
  209. package/dist/types/mutative/mutativeMethods.d.ts +0 -11
  210. package/dist/types/mutative/register.d.ts +0 -7
  211. package/dist/types/patches/index.d.ts +0 -1
  212. package/dist/types/patches/patchMethods.d.ts +0 -44
  213. package/dist/types/patches/register.d.ts +0 -7
  214. package/dist/types/persist/index.d.ts +0 -3
  215. package/dist/types/persist/persist.d.ts +0 -40
  216. package/dist/types/persist/persistPathHelpers.d.ts +0 -6
  217. package/dist/types/persist/persistStorage.d.ts +0 -17
  218. package/dist/types/persist/register.d.ts +0 -9
  219. package/dist/types/react/cacheMethods.d.ts +0 -5
  220. package/dist/types/react/form/customInput.d.ts +0 -6
  221. package/dist/types/react/form/form.d.ts +0 -98
  222. package/dist/types/react/form/formField.d.ts +0 -68
  223. package/dist/types/react/form/formForEach.d.ts +0 -19
  224. package/dist/types/react/form/index.d.ts +0 -3
  225. package/dist/types/react/form/useFormAutosave.d.ts +0 -9
  226. package/dist/types/react/index.d.ts +0 -11
  227. package/dist/types/react/loadingBoundary.d.ts +0 -21
  228. package/dist/types/react/register.d.ts +0 -15
  229. package/dist/types/react/scope.d.ts +0 -24
  230. package/dist/types/react/scopeMethods.d.ts +0 -20
  231. package/dist/types/react/storeMethods.d.ts +0 -15
  232. package/dist/types/react/useCache.d.ts +0 -34
  233. package/dist/types/react/useDecoupledState.d.ts +0 -7
  234. package/dist/types/react/useProp.d.ts +0 -8
  235. package/dist/types/react/useStore.d.ts +0 -16
  236. package/dist/types/react/useUrlParamScope.d.ts +0 -4
@@ -0,0 +1,107 @@
1
+ import { Cache, CacheState, Scope } from "./scope-DI1OFHcr.js";
2
+ import { Constrain, Path, Selector, Store, SubscribeOptions, Update, Value } from "./store-DKaeE840.js";
3
+ import { Context, ReactNode } from "react";
4
+
5
+ //#region src/react/useStore.d.ts
6
+ interface UseStoreOptions<S> extends Omit<SubscribeOptions, "runNow" | "passive"> {
7
+ /**
8
+ * If true, the cache content can be consumed but no fetch will be triggered.
9
+ * @default false
10
+ */
11
+ passive?: boolean;
12
+ disableTrackingProxy?: boolean;
13
+ withViewTransition?: boolean | ((value: S) => unknown);
14
+ }
15
+ declare function useStore<T, S>(store: Store<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
16
+ declare function useStore<T, const P>(store: Store<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
17
+ declare function useStore<T>(store: Store<T>, option?: UseStoreOptions<T>): T;
18
+ //#endregion
19
+ //#region src/react/useCache.d.ts
20
+ type UseCacheArray<T> = [value: T | undefined, error: unknown | undefined, isUpdating: boolean, isStale: boolean];
21
+ type UseCacheValue<T> = UseCacheArray<T> & CacheState<T>;
22
+ interface UseCacheOptions<T> extends UseStoreOptions<UseCacheArray<T> & CacheState<T>> {
23
+ /**
24
+ * If true, will always return undefined as value and no fetch will be triggered.
25
+ * @default false
26
+ */
27
+ disabled?: boolean;
28
+ /**
29
+ * If true, the cache will be invalidated when the component mounts.
30
+ * @default false
31
+ */
32
+ updateOnMount?: boolean;
33
+ /**
34
+ * If true, `useCache` will throw a promise when the cache is pending. This can be used with React Suspense.
35
+ * @see https://react.dev/reference/react/Suspense
36
+ * @default false
37
+ */
38
+ suspense?: boolean;
39
+ /**
40
+ * If true, `useCache` will register its loading state with the nearest `LoadingBoundary`.
41
+ * @default false
42
+ */
43
+ loadingBoundary?: boolean;
44
+ }
45
+ declare function useCache<T>(cache: Cache<T, any>, {
46
+ passive,
47
+ disabled,
48
+ updateOnMount,
49
+ withViewTransition,
50
+ suspense,
51
+ loadingBoundary,
52
+ ...options
53
+ }?: UseCacheOptions<T>): UseCacheValue<T>;
54
+ //#endregion
55
+ //#region src/react/cacheMethods.d.ts
56
+ declare const cacheMethods: {
57
+ useCache<T>(this: Cache<T, any>, options?: UseCacheOptions<T>): UseCacheValue<T>;
58
+ };
59
+ //#endregion
60
+ //#region src/react/scope.d.ts
61
+ type ScopeProps<T> = {
62
+ scope: Scope<T>;
63
+ store?: Store<T>;
64
+ children?: ReactNode;
65
+ };
66
+ declare module "@core" {
67
+ interface Scope<T> {
68
+ context?: Context<Store<T>>;
69
+ }
70
+ }
71
+ declare function ScopeProvider<T>({
72
+ scope,
73
+ store: inputStore,
74
+ children
75
+ }: ScopeProps<T>): React.JSX.Element;
76
+ declare function useScope<T>(scope: Scope<T>): Store<T>;
77
+ //#endregion
78
+ //#region src/react/scopeMethods.d.ts
79
+ declare function boundUseScope<T>(this: Scope<T>): Store<T>;
80
+ declare function boundUseScopeStore<T, S>(this: Scope<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
81
+ declare function boundUseScopeStore<T, const P>(this: Scope<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
82
+ declare function boundUseScopeStore<T>(this: Scope<T>, option?: UseStoreOptions<T>): T;
83
+ declare function boundUseScopeProp<T, S>(this: Scope<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>["set"]];
84
+ declare function boundUseScopeProp<T, const P>(this: Scope<T>, selector: Constrain<P, Path<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>["set"]];
85
+ declare function boundUseScopeProp<T>(this: Scope<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>["set"]];
86
+ declare function Provider<T>(this: Scope<T>, props: Omit<ScopeProps<T>, "scope">): React.JSX.Element;
87
+ declare const scopeMethods: {
88
+ useScope: typeof boundUseScope;
89
+ useStore: typeof boundUseScopeStore;
90
+ useProp: typeof boundUseScopeProp;
91
+ Provider: typeof Provider;
92
+ };
93
+ //#endregion
94
+ //#region src/react/storeMethods.d.ts
95
+ declare function boundUseStore<T, S>(this: Store<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
96
+ declare function boundUseStore<T, const P>(this: Store<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
97
+ declare function boundUseStore<T>(this: Store<T>, option?: UseStoreOptions<T>): T;
98
+ declare function boundUseProp<T, S>(this: Store<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>["set"]];
99
+ declare function boundUseProp<T, const P>(this: Store<T>, selector: Constrain<P, Path<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>["set"]];
100
+ declare function boundUseProp<T>(this: Store<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>["set"]];
101
+ declare const storeMethods: {
102
+ useStore: typeof boundUseStore;
103
+ useProp: typeof boundUseProp;
104
+ };
105
+ //#endregion
106
+ export { ScopeProps, ScopeProvider, UseCacheArray, UseCacheValue, UseStoreOptions, cacheMethods, scopeMethods, storeMethods, useCache, useScope, useStore };
107
+ //# sourceMappingURL=storeMethods-C4luym7C.d.ts.map
@@ -0,0 +1,375 @@
1
+ const require_chunk = require('./chunk-CUT6urMc.cjs');
2
+ const require_store = require('./store-BWMWEUpu.cjs');
3
+ const require_propAccess = require('./propAccess-ByqBjC19.cjs');
4
+ const require_hash = require('./hash-CJPl7SRj.cjs');
5
+ const react = require_chunk.__toESM(require("react"));
6
+ const use_sync_external_store_shim_with_selector_js = require_chunk.__toESM(require("use-sync-external-store/shim/with-selector.js"));
7
+ const react_jsx_runtime = require_chunk.__toESM(require("react/jsx-runtime"));
8
+
9
+ //#region src/lib/trackingProxy.ts
10
+ const unwrapProxySymbol = /* @__PURE__ */ Symbol("unwrapProxy");
11
+ function trackingProxy(value, equals = require_propAccess.deepEqual) {
12
+ if (!require_propAccess.isPlainObject(value) && !Array.isArray(value)) return [value, (other) => equals(value, other)];
13
+ value = value[unwrapProxySymbol] ?? value;
14
+ const deps = new Array();
15
+ const revokations = new Array();
16
+ let revoked = false;
17
+ function trackComplexProp(function_, ...args) {
18
+ const [proxiedValue, equals$1, revoke] = trackingProxy(function_(value, ...args));
19
+ deps.push((otherValue) => {
20
+ if (!require_propAccess.isPlainObject(otherValue) && !Array.isArray(otherValue)) return false;
21
+ return equals$1(function_(otherValue, ...args));
22
+ });
23
+ if (revoke) revokations.push(revoke);
24
+ return proxiedValue;
25
+ }
26
+ function trackSimpleProp(function_, ...args) {
27
+ const calculatedValue = function_(value, ...args);
28
+ deps.push((otherValue) => {
29
+ return function_(otherValue, ...args) === calculatedValue;
30
+ });
31
+ return calculatedValue;
32
+ }
33
+ const proxy = new Proxy(value, {
34
+ get(target, p, receiver) {
35
+ if (p === unwrapProxySymbol) return value;
36
+ if (revoked) return target[p];
37
+ const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
38
+ if (writable === false && configurable === false) return target[p];
39
+ return trackComplexProp(Reflect.get, p, receiver);
40
+ },
41
+ getOwnPropertyDescriptor(target, p) {
42
+ const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};
43
+ if (writable === false && configurable === false) return Reflect.getOwnPropertyDescriptor(target, p);
44
+ return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);
45
+ },
46
+ ownKeys() {
47
+ return trackComplexProp(Reflect.ownKeys);
48
+ },
49
+ getPrototypeOf() {
50
+ return trackSimpleProp(Reflect.getPrototypeOf);
51
+ },
52
+ has(_target, p) {
53
+ return trackSimpleProp(Reflect.has, p);
54
+ },
55
+ isExtensible() {
56
+ return trackSimpleProp(Reflect.isExtensible);
57
+ }
58
+ });
59
+ return [
60
+ proxy,
61
+ (other) => !!other && deps.every((equals$1) => equals$1(other)),
62
+ () => {
63
+ revoked = true;
64
+ revokations.forEach((revoke) => revoke());
65
+ }
66
+ ];
67
+ }
68
+
69
+ //#endregion
70
+ //#region src/react/useStore.ts
71
+ function useStore(store, argument1, argument2) {
72
+ const selector = require_store.makeSelector(typeof argument1 === "function" || typeof argument1 === "string" ? argument1 : void 0);
73
+ const allOptions = typeof argument1 === "object" ? argument1 : argument2 ?? {};
74
+ const lastEqualsRef = (0, react.useRef)(void 0);
75
+ if (store.derivedFrom) return useStore(store.derivedFrom.store, (value$1) => {
76
+ for (const selector$1 of store.derivedFrom.selectors) value$1 = require_store.makeSelector(selector$1)(value$1);
77
+ return selector(value$1);
78
+ }, allOptions);
79
+ const { disableTrackingProxy = true, equals = store.options.equals ?? require_propAccess.deepEqual, withViewTransition,...options } = allOptions;
80
+ const subOptions = {
81
+ ...options,
82
+ runNow: false
83
+ };
84
+ const subscribe = (0, react.useCallback)((listener) => {
85
+ let _listener = listener;
86
+ let stopped = false;
87
+ if (withViewTransition && document.startViewTransition) {
88
+ let lastObservedValue;
89
+ _listener = (value$1) => {
90
+ const observedValue = withViewTransition instanceof Function ? withViewTransition(value$1) : value$1;
91
+ if (equals(lastObservedValue, observedValue)) {
92
+ listener();
93
+ return;
94
+ }
95
+ lastObservedValue = observedValue;
96
+ let hasChanges = false;
97
+ const mutationObserver = new MutationObserver(() => {
98
+ hasChanges = true;
99
+ mutationObserver.disconnect();
100
+ });
101
+ mutationObserver.observe(document.body, {
102
+ childList: true,
103
+ subtree: true
104
+ });
105
+ document.startViewTransition(() => {
106
+ mutationObserver.disconnect();
107
+ if (!stopped) listener();
108
+ if (!hasChanges) throw new Error("no change");
109
+ });
110
+ };
111
+ }
112
+ const cancel = store.subscribe(_listener, subOptions);
113
+ return () => {
114
+ stopped = true;
115
+ cancel();
116
+ };
117
+ }, [store, require_hash.simpleHash(subOptions)]);
118
+ let value = (0, use_sync_external_store_shim_with_selector_js.useSyncExternalStoreWithSelector)(subscribe, store.get, void 0, (x) => selector(x), (_v, newValue) => lastEqualsRef.current?.(newValue) ?? false);
119
+ let lastEquals = (newValue) => equals(newValue, value);
120
+ let revoke;
121
+ if (!disableTrackingProxy) [value, lastEquals, revoke] = trackingProxy(value, equals);
122
+ (0, react.useLayoutEffect)(() => {
123
+ lastEqualsRef.current = lastEquals;
124
+ revoke?.();
125
+ });
126
+ (0, react.useDebugValue)(value);
127
+ return value;
128
+ }
129
+
130
+ //#endregion
131
+ //#region src/react/loadingBoundary.tsx
132
+ const LoadingBoundaryContext = (0, react.createContext)(require_store.createStore(/* @__PURE__ */ new Set()));
133
+ function LoadingBoundary({ fallback, children, isLoading: isLoadingExternal }) {
134
+ const store = (0, react.useMemo)(() => require_store.createStore(/* @__PURE__ */ new Set()), []);
135
+ const entries = useStore(store);
136
+ const isLoading = entries.size > 0 || isLoadingExternal;
137
+ const fallbackNode = isLoading ? typeof fallback === "function" ? fallback([...entries]) : fallback : void 0;
138
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadingBoundaryContext.Provider, {
139
+ value: store,
140
+ children: fallbackNode !== void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [fallbackNode, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
141
+ style: { display: "none" },
142
+ children
143
+ })] }) : children
144
+ });
145
+ }
146
+ function useLoadingBoundary(isLoading, label) {
147
+ const store = (0, react.useContext)(LoadingBoundaryContext);
148
+ (0, react.useLayoutEffect)(() => {
149
+ if (!isLoading) return;
150
+ const entry = { label };
151
+ store.set((entries) => new Set(entries).add(entry));
152
+ return () => {
153
+ store.set((entries) => {
154
+ const newEntries = new Set(entries);
155
+ newEntries.delete(entry);
156
+ return newEntries;
157
+ });
158
+ };
159
+ }, [isLoading]);
160
+ }
161
+
162
+ //#endregion
163
+ //#region src/react/useCache.ts
164
+ function useCache(cache, { passive, disabled, updateOnMount, withViewTransition, suspense, loadingBoundary,...options } = {}) {
165
+ if (withViewTransition === true) withViewTransition = (state) => state.value;
166
+ const { rootCache, selector } = (0, react.useMemo)(() => {
167
+ const rootCache$1 = cache.derivedFromCache?.cache ?? cache;
168
+ let selector$1 = (x) => x;
169
+ if (cache.derivedFromCache) selector$1 = (value) => {
170
+ for (const s of cache.derivedFromCache.selectors) value = require_store.makeSelector(s)(value);
171
+ return value;
172
+ };
173
+ return {
174
+ rootCache: rootCache$1,
175
+ selector: selector$1
176
+ };
177
+ }, [cache]);
178
+ const hasMounted = (0, react.useRef)(false);
179
+ (0, react.useEffect)(() => {
180
+ hasMounted.current = true;
181
+ if (updateOnMount) rootCache.invalidate();
182
+ }, []);
183
+ const result = useStore(rootCache.state, (state) => {
184
+ if (disabled) return Object.assign([
185
+ void 0,
186
+ void 0,
187
+ false,
188
+ false
189
+ ], {
190
+ status: "pending",
191
+ isUpdating: false,
192
+ isStale: false,
193
+ isConnected: false
194
+ });
195
+ const isStale = updateOnMount && !hasMounted.current ? true : state.isStale;
196
+ try {
197
+ const value = state.status === "value" ? selector(state.value) : void 0;
198
+ return Object.assign([
199
+ value,
200
+ state.error,
201
+ state.isUpdating,
202
+ isStale
203
+ ], {
204
+ ...state,
205
+ value,
206
+ isStale
207
+ });
208
+ } catch (error) {
209
+ return Object.assign([
210
+ void 0,
211
+ error,
212
+ state.isUpdating,
213
+ isStale
214
+ ], {
215
+ status: "error",
216
+ error,
217
+ isUpdating: state.isUpdating,
218
+ isStale,
219
+ isConnected: state.isConnected
220
+ });
221
+ }
222
+ }, {
223
+ ...options,
224
+ withViewTransition,
225
+ passive: passive || disabled
226
+ });
227
+ (0, react.useEffect)(() => rootCache.subscribe(() => void 0, { passive: passive || disabled }), [rootCache, passive || disabled]);
228
+ useLoadingBoundary(loadingBoundary && !disabled && result.status === "pending");
229
+ if (suspense && result.status === "pending") throw rootCache.get();
230
+ return result;
231
+ }
232
+
233
+ //#endregion
234
+ //#region src/react/cacheMethods.ts
235
+ const cacheMethods = { useCache(options) {
236
+ return useCache(this, options);
237
+ } };
238
+
239
+ //#endregion
240
+ //#region src/react/useProp.ts
241
+ function useProp(store, argument1, argument2, argument3) {
242
+ const selector = typeof argument1 === "function" || typeof argument1 === "string" ? argument1 : void 0;
243
+ const updater = typeof argument2 === "function" ? argument2 : void 0;
244
+ const options = typeof argument1 === "object" ? argument1 : typeof argument2 === "object" ? argument2 : argument3;
245
+ if (selector) store = store.map(selector, updater);
246
+ const value = useStore(store, options);
247
+ return [value, store.set];
248
+ }
249
+
250
+ //#endregion
251
+ //#region src/react/scope.tsx
252
+ function getScopeContext(scope) {
253
+ scope.context ??= (0, react.createContext)(require_store.createStore(scope.defaultValue));
254
+ return scope.context;
255
+ }
256
+ function ScopeProvider({ scope, store: inputStore, children }) {
257
+ const context = getScopeContext(scope);
258
+ const currentStore = (0, react.useMemo)(() => inputStore ?? require_store.createStore(scope.defaultValue), [scope, inputStore]);
259
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(context.Provider, {
260
+ value: currentStore,
261
+ children
262
+ });
263
+ }
264
+ function useScope(scope) {
265
+ const context = getScopeContext(scope);
266
+ return (0, react.useContext)(context);
267
+ }
268
+ function useScopeStore(scope, ...args) {
269
+ const store = useScope(scope);
270
+ return useStore(store, ...args);
271
+ }
272
+ function useScopeProp(scope, ...args) {
273
+ const store = useScope(scope);
274
+ return useProp(store, ...args);
275
+ }
276
+
277
+ //#endregion
278
+ //#region src/react/scopeMethods.ts
279
+ function boundUseScope() {
280
+ return useScope(this);
281
+ }
282
+ function boundUseScopeStore(...args) {
283
+ return useScopeStore(this, ...args);
284
+ }
285
+ function boundUseScopeProp(...args) {
286
+ return useScopeProp(this, ...args);
287
+ }
288
+ function Provider(props) {
289
+ return ScopeProvider({
290
+ ...props,
291
+ scope: this
292
+ });
293
+ }
294
+ const scopeMethods = {
295
+ useScope: boundUseScope,
296
+ useStore: boundUseScopeStore,
297
+ useProp: boundUseScopeProp,
298
+ Provider
299
+ };
300
+
301
+ //#endregion
302
+ //#region src/react/storeMethods.ts
303
+ function boundUseStore(...args) {
304
+ return useStore(this, ...args);
305
+ }
306
+ function boundUseProp(...args) {
307
+ return useProp(this, ...args);
308
+ }
309
+ const storeMethods = {
310
+ useStore: boundUseStore,
311
+ useProp: boundUseProp
312
+ };
313
+
314
+ //#endregion
315
+ Object.defineProperty(exports, 'LoadingBoundary', {
316
+ enumerable: true,
317
+ get: function () {
318
+ return LoadingBoundary;
319
+ }
320
+ });
321
+ Object.defineProperty(exports, 'ScopeProvider', {
322
+ enumerable: true,
323
+ get: function () {
324
+ return ScopeProvider;
325
+ }
326
+ });
327
+ Object.defineProperty(exports, 'cacheMethods', {
328
+ enumerable: true,
329
+ get: function () {
330
+ return cacheMethods;
331
+ }
332
+ });
333
+ Object.defineProperty(exports, 'scopeMethods', {
334
+ enumerable: true,
335
+ get: function () {
336
+ return scopeMethods;
337
+ }
338
+ });
339
+ Object.defineProperty(exports, 'storeMethods', {
340
+ enumerable: true,
341
+ get: function () {
342
+ return storeMethods;
343
+ }
344
+ });
345
+ Object.defineProperty(exports, 'useCache', {
346
+ enumerable: true,
347
+ get: function () {
348
+ return useCache;
349
+ }
350
+ });
351
+ Object.defineProperty(exports, 'useLoadingBoundary', {
352
+ enumerable: true,
353
+ get: function () {
354
+ return useLoadingBoundary;
355
+ }
356
+ });
357
+ Object.defineProperty(exports, 'useProp', {
358
+ enumerable: true,
359
+ get: function () {
360
+ return useProp;
361
+ }
362
+ });
363
+ Object.defineProperty(exports, 'useScope', {
364
+ enumerable: true,
365
+ get: function () {
366
+ return useScope;
367
+ }
368
+ });
369
+ Object.defineProperty(exports, 'useStore', {
370
+ enumerable: true,
371
+ get: function () {
372
+ return useStore;
373
+ }
374
+ });
375
+ //# sourceMappingURL=storeMethods-DVVsmUg1.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storeMethods-DVVsmUg1.cjs","names":["deepEqual","isPlainObject","equals","makeSelector","selector","value","deepEqual","_listener: (value: any) => void","lastObservedValue: any","simpleHash","revoke: (() => void) | undefined","createStore","rootCache: Cache<any, any>","selector","makeSelector","createStore","scopeMethods: {\n useScope: typeof boundUseScope;\n useStore: typeof boundUseScopeStore;\n useProp: typeof boundUseScopeProp;\n Provider: typeof Provider;\n}","storeMethods: {\n useStore: typeof boundUseStore;\n useProp: typeof boundUseProp;\n}"],"sources":["../src/lib/trackingProxy.ts","../src/react/useStore.ts","../src/react/loadingBoundary.tsx","../src/react/useCache.ts","../src/react/cacheMethods.ts","../src/react/useProp.ts","../src/react/scope.tsx","../src/react/scopeMethods.ts","../src/react/storeMethods.ts"],"sourcesContent":["import { isPlainObject } from '@lib/helpers';\nimport { deepEqual } from './equals';\n\nconst unwrapProxySymbol = /* @__PURE__ */ Symbol('unwrapProxy');\n\nexport type TrackingProxy<T> = [value: T, equals: (newValue: T) => boolean, revoke?: () => void];\ntype Object_ = Record<string | symbol, unknown>;\n\nexport function trackingProxy<T>(\n value: T,\n equals: (a: any, b: any) => boolean = deepEqual,\n): TrackingProxy<T> {\n if (!isPlainObject(value) && !Array.isArray(value)) {\n return [value, (other) => equals(value, other)];\n }\n\n // Unpack proxies, we don't want to nest them\n value = (value as any)[unwrapProxySymbol] ?? value;\n\n const deps = new Array<TrackingProxy<any>[1]>();\n const revokations = new Array<() => void>();\n let revoked = false;\n\n function trackComplexProp(function_: any, ...args: any[]) {\n const [proxiedValue, equals, revoke] = trackingProxy(function_(value, ...args));\n\n deps.push((otherValue) => {\n if (!isPlainObject(otherValue) && !Array.isArray(otherValue)) {\n return false;\n }\n\n return equals(function_(otherValue, ...args));\n });\n\n if (revoke) {\n revokations.push(revoke);\n }\n\n return proxiedValue;\n }\n\n function trackSimpleProp(function_: any, ...args: any[]) {\n const calculatedValue = function_(value, ...args);\n\n deps.push((otherValue) => {\n return function_(otherValue, ...args) === calculatedValue;\n });\n\n return calculatedValue;\n }\n\n const proxy = new Proxy(value as T & Object_, {\n get(target, p, receiver) {\n if (p === unwrapProxySymbol) {\n return value;\n }\n\n if (revoked) {\n return target[p];\n }\n\n const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};\n if (writable === false && configurable === false) {\n return target[p];\n }\n\n return trackComplexProp(Reflect.get, p, receiver);\n },\n\n getOwnPropertyDescriptor(target, p) {\n const { writable, configurable } = Object.getOwnPropertyDescriptor(target, p) ?? {};\n if (writable === false && configurable === false) {\n return Reflect.getOwnPropertyDescriptor(target, p);\n }\n\n return trackComplexProp(Reflect.getOwnPropertyDescriptor, p);\n },\n\n ownKeys() {\n return trackComplexProp(Reflect.ownKeys);\n },\n\n getPrototypeOf() {\n return trackSimpleProp(Reflect.getPrototypeOf);\n },\n\n has(_target, p) {\n return trackSimpleProp(Reflect.has, p);\n },\n\n isExtensible() {\n return trackSimpleProp(Reflect.isExtensible);\n },\n });\n\n return [\n proxy,\n (other) => !!other && deps.every((equals) => equals(other)),\n () => {\n revoked = true;\n revokations.forEach((revoke) => revoke());\n },\n ];\n}\n","import type { Selector, SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { deepEqual } from '@lib/equals';\nimport { simpleHash } from '@lib/hash';\nimport { makeSelector } from '@lib/makeSelector';\nimport { type Path, type Value } from '@lib/path';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport { useCallback, useDebugValue, useLayoutEffect, useRef } from 'react';\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector.js';\n\nexport interface UseStoreOptions<S> extends Omit<SubscribeOptions, 'runNow' | 'passive'> {\n /**\n * If true, the cache content can be consumed but no fetch will be triggered.\n * @default false\n */\n passive?: boolean;\n\n disableTrackingProxy?: boolean;\n\n withViewTransition?: boolean | ((value: S) => unknown);\n}\n\nexport function useStore<T, S>(\n store: Store<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptions<S>,\n): S;\n\nexport function useStore<T, const P>(\n store: Store<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\n\nexport function useStore<T>(store: Store<T>, option?: UseStoreOptions<T>): T;\n\nexport function useStore<T, S>(store: Store<T>, argument1?: any, argument2?: any): S {\n const selector = makeSelector<T, S>(\n typeof argument1 === 'function' || typeof argument1 === 'string' ? argument1 : undefined,\n );\n\n const allOptions = (\n typeof argument1 === 'object' ? argument1 : (argument2 ?? {})\n ) as UseStoreOptions<S>;\n\n const lastEqualsRef = useRef<(newValue: S) => boolean | undefined>(undefined);\n\n if (store.derivedFrom) {\n return useStore(\n store.derivedFrom.store,\n (value) => {\n for (const selector of store.derivedFrom!.selectors) {\n value = makeSelector(selector)(value);\n }\n return selector(value);\n },\n allOptions,\n );\n }\n\n const {\n disableTrackingProxy = true,\n equals = store.options.equals ?? deepEqual,\n withViewTransition,\n ...options\n } = allOptions;\n\n const subOptions = { ...options, runNow: false };\n const subscribe = useCallback(\n (listener: () => void) => {\n let _listener: (value: any) => void = listener;\n let stopped = false;\n\n if (withViewTransition && (document as any).startViewTransition) {\n let lastObservedValue: any;\n\n _listener = (value: any) => {\n const observedValue =\n withViewTransition instanceof Function ? withViewTransition(value) : value;\n\n if (equals(lastObservedValue, observedValue)) {\n listener();\n return;\n }\n\n lastObservedValue = observedValue;\n\n let hasChanges = false;\n const mutationObserver = new MutationObserver(() => {\n hasChanges = true;\n mutationObserver.disconnect();\n });\n mutationObserver.observe(document.body, { childList: true, subtree: true });\n\n (document as any).startViewTransition(() => {\n mutationObserver.disconnect();\n\n if (!stopped) {\n listener();\n }\n\n if (!hasChanges) {\n throw new Error('no change');\n }\n });\n };\n }\n\n const cancel = store.subscribe(_listener, subOptions);\n return () => {\n stopped = true;\n cancel();\n };\n },\n [store, simpleHash(subOptions)],\n );\n\n let value = useSyncExternalStoreWithSelector<T, S>(\n //\n subscribe,\n store.get,\n undefined,\n (x) => selector(x),\n (_v, newValue) => lastEqualsRef.current?.(newValue) ?? false,\n );\n let lastEquals = (newValue: S) => equals(newValue, value);\n let revoke: (() => void) | undefined;\n\n if (!disableTrackingProxy) {\n [value, lastEquals, revoke] = trackingProxy(value, equals);\n }\n\n useLayoutEffect(() => {\n lastEqualsRef.current = lastEquals;\n revoke?.();\n });\n\n useDebugValue(value);\n return value;\n}\n","import { createStore } from '@core';\nimport { useStore } from '@react/useStore';\nimport { createContext, useContext, useLayoutEffect, useMemo, type ReactNode } from 'react';\n\nexport interface LoadingBoundaryEntry {\n label?: ReactNode;\n}\n\nexport interface LoadingBoundaryProps {\n /**\n * Fallback node to render when there are loading components within the boundary.\n */\n fallback?: ReactNode | ((entries: LoadingBoundaryEntry[]) => ReactNode);\n\n /**\n * Child node to render when there are no loading components within the boundary.\n */\n children?: ReactNode;\n\n /**\n * Add a loading state from outside the boundary. Useful for when you want to\n * show a loading state for a component that is not a child of the boundary.\n */\n isLoading?: boolean;\n}\n\nconst LoadingBoundaryContext = createContext(createStore(new Set<LoadingBoundaryEntry>()));\n\nexport function LoadingBoundary({\n fallback,\n children,\n isLoading: isLoadingExternal,\n}: LoadingBoundaryProps): React.JSX.Element {\n const store = useMemo(() => createStore(new Set<LoadingBoundaryEntry>()), []);\n const entries = useStore(store);\n const isLoading = entries.size > 0 || isLoadingExternal;\n\n const fallbackNode = isLoading\n ? typeof fallback === 'function'\n ? fallback([...entries])\n : fallback\n : undefined;\n\n return (\n <LoadingBoundaryContext.Provider value={store}>\n {fallbackNode !== undefined ? (\n <>\n {fallbackNode}\n <div style={{ display: 'none' }}>{children}</div>\n </>\n ) : (\n children\n )}\n </LoadingBoundaryContext.Provider>\n );\n}\n\nexport function useLoadingBoundary(isLoading: boolean | undefined, label?: ReactNode): void {\n const store = useContext(LoadingBoundaryContext);\n\n useLayoutEffect(() => {\n if (!isLoading) {\n return;\n }\n\n const entry = { label };\n store.set((entries) => new Set(entries).add(entry));\n\n return () => {\n store.set((entries) => {\n const newEntries = new Set(entries);\n newEntries.delete(entry);\n return newEntries;\n });\n };\n }, [isLoading]);\n}\n","import type { Cache } from '@core';\nimport type { CacheState } from '@lib/cacheState';\nimport { makeSelector } from '@lib/makeSelector';\nimport { useLoadingBoundary } from '@react/loadingBoundary';\nimport { useEffect, useMemo, useRef } from 'react';\nimport { useStore, type UseStoreOptions } from './useStore';\n\nexport type UseCacheArray<T> = [\n value: T | undefined,\n error: unknown | undefined,\n isUpdating: boolean,\n isStale: boolean,\n];\n\nexport type UseCacheValue<T> = UseCacheArray<T> & CacheState<T>;\n\nexport interface UseCacheOptions<T> extends UseStoreOptions<UseCacheArray<T> & CacheState<T>> {\n /**\n * If true, will always return undefined as value and no fetch will be triggered.\n * @default false\n */\n disabled?: boolean;\n\n /**\n * If true, the cache will be invalidated when the component mounts.\n * @default false\n */\n updateOnMount?: boolean;\n\n /**\n * If true, `useCache` will throw a promise when the cache is pending. This can be used with React Suspense.\n * @see https://react.dev/reference/react/Suspense\n * @default false\n */\n suspense?: boolean;\n\n /**\n * If true, `useCache` will register its loading state with the nearest `LoadingBoundary`.\n * @default false\n */\n loadingBoundary?: boolean;\n}\n\nexport function useCache<T>(\n cache: Cache<T, any>,\n {\n passive,\n disabled,\n updateOnMount,\n withViewTransition,\n suspense,\n loadingBoundary,\n ...options\n }: UseCacheOptions<T> = {},\n): UseCacheValue<T> {\n if (withViewTransition === true) {\n withViewTransition = (state) => state.value;\n }\n\n const { rootCache, selector } = useMemo(() => {\n const rootCache: Cache<any, any> = cache.derivedFromCache?.cache ?? cache;\n let selector = (x: any) => x;\n\n if (cache.derivedFromCache) {\n selector = (value: any) => {\n for (const s of cache.derivedFromCache!.selectors) {\n value = makeSelector(s)(value);\n }\n return value;\n };\n }\n\n return { rootCache, selector };\n }, [cache]);\n\n const hasMounted = useRef(false);\n\n useEffect(() => {\n hasMounted.current = true;\n\n if (updateOnMount) {\n rootCache.invalidate();\n }\n }, []);\n\n const result = useStore(\n rootCache.state,\n (state) => {\n if (disabled) {\n return Object.assign<UseCacheArray<T>, CacheState<T>>(\n [undefined, undefined, false, false],\n { status: 'pending', isUpdating: false, isStale: false, isConnected: false },\n );\n }\n\n const isStale = updateOnMount && !hasMounted.current ? true : state.isStale;\n try {\n const value = state.status === 'value' ? selector(state.value) : undefined;\n\n return Object.assign<UseCacheArray<T>, CacheState<T>>(\n [value, state.error, state.isUpdating, isStale],\n { ...state, value, isStale },\n );\n } catch (error) {\n return Object.assign<UseCacheArray<T>, CacheState<T>>(\n [undefined, error, state.isUpdating, isStale],\n {\n status: 'error',\n error,\n isUpdating: state.isUpdating,\n isStale: isStale,\n isConnected: state.isConnected,\n },\n );\n }\n },\n { ...options, withViewTransition, passive: passive || disabled },\n );\n\n useEffect(\n () => rootCache.subscribe(() => undefined, { passive: passive || disabled }),\n [rootCache, passive || disabled],\n );\n\n useLoadingBoundary(loadingBoundary && !disabled && result.status === 'pending');\n\n if (suspense && result.status === 'pending') {\n throw rootCache.get();\n }\n\n return result;\n}\n","import type { Cache } from '@core';\nimport { type UseCacheOptions, type UseCacheValue, useCache } from '@react/useCache';\n\nexport const cacheMethods = {\n useCache<T>(this: Cache<T, any>, options?: UseCacheOptions<T>): UseCacheValue<T> {\n return useCache(this, options);\n },\n};\n","import { type Selector, type Update } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { type Path, type Value } from '@lib/path';\nimport { useStore, type UseStoreOptions } from './useStore';\n\nexport function useProp<T, S>(\n store: Store<T>,\n selector: Selector<T, S>,\n updater: (value: S) => Update<T>,\n options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\n\nexport function useProp<T, const P>(\n store: Store<T>,\n selector: Constrain<P, Path<T>>,\n options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\n\nexport function useProp<T>(\n store: Store<T>,\n options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\n\nexport function useProp<T, S>(\n store: Store<T>,\n argument1?: any,\n argument2?: any,\n argument3?: any,\n): [value: S, setValue: Store<S>['set']] {\n const selector =\n typeof argument1 === 'function' || typeof argument1 === 'string' ? argument1 : undefined;\n const updater = typeof argument2 === 'function' ? argument2 : undefined;\n const options =\n typeof argument1 === 'object'\n ? argument1\n : typeof argument2 === 'object'\n ? argument2\n : argument3;\n\n if (selector) {\n store = store.map(selector, updater);\n }\n\n const value = useStore(store, options) as S;\n return [value, store.set as Store<S>['set']];\n}\n","import type { Scope, Selector, Update } from '@core';\nimport { createStore, type Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport type { Path, Value } from '@lib/path';\nimport { createContext, useContext, useMemo, type Context, type ReactNode } from 'react';\nimport { useProp } from './useProp';\nimport { useStore, type UseStoreOptions } from './useStore';\n\nexport type ScopeProps<T> = { scope: Scope<T>; store?: Store<T>; children?: ReactNode };\n\ndeclare module '@core' {\n interface Scope<T> {\n context?: Context<Store<T>>;\n }\n}\n\nfunction getScopeContext<T>(scope: Scope<T>): Context<Store<T>> {\n scope.context ??= createContext<Store<T>>(createStore(scope.defaultValue));\n return scope.context;\n}\n\nexport function ScopeProvider<T>({\n scope,\n store: inputStore,\n children,\n}: ScopeProps<T>): React.JSX.Element {\n const context = getScopeContext(scope);\n const currentStore = useMemo(\n () => inputStore ?? createStore(scope.defaultValue),\n [scope, inputStore],\n );\n\n return <context.Provider value={currentStore}>{children}</context.Provider>;\n}\n\nexport function useScope<T>(scope: Scope<T>): Store<T> {\n const context = getScopeContext(scope);\n return useContext(context);\n}\n\nexport function useScopeStore<T, S>(\n scope: Scope<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptions<S>,\n): S;\n\nexport function useScopeStore<T, const P>(\n scope: Scope<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\n\nexport function useScopeStore<T>(scope: Scope<T>, option?: UseStoreOptions<T>): T;\n\nexport function useScopeStore<T>(scope: Scope<T>, ...args: any[]): T {\n const store = useScope(scope);\n return useStore(store, ...args);\n}\n\nexport function useScopeProp<T, S>(\n scope: Scope<T>,\n selector: Selector<T, S>,\n updater: (value: S) => Update<T>,\n options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\n\nexport function useScopeProp<T, const P>(\n scope: Scope<T>,\n selector: Constrain<P, Path<T>>,\n options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\n\nexport function useScopeProp<T>(\n scope: Scope<T>,\n options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\n\nexport function useScopeProp<T>(\n scope: Scope<T>,\n ...args: any[]\n): [value: T, setValue: Store<T>['set']] {\n const store = useScope(scope);\n return useProp(store, ...args);\n}\n","import type { Scope, Selector, Store, Update } from '@core';\nimport type { Constrain } from '@lib/constrain';\nimport type { Path, Value } from '@lib/path';\nimport {\n ScopeProvider,\n useScope,\n useScopeProp,\n useScopeStore,\n type ScopeProps,\n} from '@react/scope';\nimport type { UseStoreOptions } from '@react/useStore';\n\nfunction boundUseScope<T>(this: Scope<T>): Store<T> {\n return useScope(this);\n}\n\nfunction boundUseScopeStore<T, S>(\n this: Scope<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptions<S>,\n): S;\n\nfunction boundUseScopeStore<T, const P>(\n this: Scope<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\n\nfunction boundUseScopeStore<T>(this: Scope<T>, option?: UseStoreOptions<T>): T;\n\nfunction boundUseScopeStore(this: Scope<any>, ...args: any[]) {\n return useScopeStore(this, ...args);\n}\n\nfunction boundUseScopeProp<T, S>(\n this: Scope<T>,\n selector: Selector<T, S>,\n updater: (value: S) => Update<T>,\n options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\n\nfunction boundUseScopeProp<T, const P>(\n this: Scope<T>,\n selector: Constrain<P, Path<T>>,\n options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\n\nfunction boundUseScopeProp<T>(\n this: Scope<T>,\n options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\n\nfunction boundUseScopeProp(this: Scope<any>, ...args: any[]) {\n return useScopeProp(this, ...args);\n}\n\nfunction Provider<T>(this: Scope<T>, props: Omit<ScopeProps<T>, 'scope'>): React.JSX.Element {\n return ScopeProvider({ ...props, scope: this });\n}\n\nexport const scopeMethods: {\n useScope: typeof boundUseScope;\n useStore: typeof boundUseScopeStore;\n useProp: typeof boundUseScopeProp;\n Provider: typeof Provider;\n} = {\n useScope: boundUseScope,\n useStore: boundUseScopeStore,\n useProp: boundUseScopeProp,\n Provider,\n};\n","import type { Selector, Store, Update } from '@core';\nimport type { Constrain } from '@lib/constrain';\nimport type { Path, Value } from '@lib/path';\nimport { useProp } from '@react/useProp';\nimport { type UseStoreOptions, useStore } from '@react/useStore';\n\nfunction boundUseStore<T, S>(\n this: Store<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptions<S>,\n): S;\nfunction boundUseStore<T, const P>(\n this: Store<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptions<Value<T, P>>,\n): Value<T, P>;\nfunction boundUseStore<T>(this: Store<T>, option?: UseStoreOptions<T>): T;\nfunction boundUseStore(this: Store<any>, ...args: any[]) {\n return useStore(this, ...args);\n}\n\nfunction boundUseProp<T, S>(\n this: Store<T>,\n selector: Selector<T, S>,\n updater: (value: S) => Update<T>,\n options?: UseStoreOptions<S>,\n): [value: S, setValue: Store<S>['set']];\nfunction boundUseProp<T, const P>(\n this: Store<T>,\n selector: Constrain<P, Path<T>>,\n options?: UseStoreOptions<Value<T, P>>,\n): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];\nfunction boundUseProp<T>(\n this: Store<T>,\n options?: UseStoreOptions<T>,\n): [value: T, setValue: Store<T>['set']];\nfunction boundUseProp(this: Store<any>, ...args: any[]) {\n return useProp(this, ...args);\n}\n\nexport const storeMethods: {\n useStore: typeof boundUseStore;\n useProp: typeof boundUseProp;\n} = {\n useStore: boundUseStore,\n useProp: boundUseProp,\n};\n"],"mappings":";;;;;;;;;AAGA,MAAM,oBAAoC,uBAAO;AAKjD,SAAgB,cACd,OACA,SAAsCA,8BACpB;AAClB,KAAI,CAACC,iCAAc,UAAU,CAAC,MAAM,QAAQ,OAC1C,QAAO,CAAC,QAAQ,UAAU,OAAO,OAAO;AAI1C,SAAS,MAAc,sBAAsB;CAE7C,MAAM,OAAO,IAAI;CACjB,MAAM,cAAc,IAAI;CACxB,IAAI,UAAU;CAEd,SAAS,iBAAiB,WAAgB,GAAG,MAAa;EACxD,MAAM,CAAC,cAAcC,UAAQ,UAAU,cAAc,UAAU,OAAO,GAAG;AAEzE,OAAK,MAAM,eAAe;AACxB,OAAI,CAACD,iCAAc,eAAe,CAAC,MAAM,QAAQ,YAC/C,QAAO;AAGT,UAAOC,SAAO,UAAU,YAAY,GAAG;;AAGzC,MAAI,OACF,aAAY,KAAK;AAGnB,SAAO;;CAGT,SAAS,gBAAgB,WAAgB,GAAG,MAAa;EACvD,MAAM,kBAAkB,UAAU,OAAO,GAAG;AAE5C,OAAK,MAAM,eAAe;AACxB,UAAO,UAAU,YAAY,GAAG,UAAU;;AAG5C,SAAO;;CAGT,MAAM,QAAQ,IAAI,MAAM,OAAsB;EAC5C,IAAI,QAAQ,GAAG,UAAU;AACvB,OAAI,MAAM,kBACR,QAAO;AAGT,OAAI,QACF,QAAO,OAAO;GAGhB,MAAM,EAAE,UAAU,iBAAiB,OAAO,yBAAyB,QAAQ,MAAM;AACjF,OAAI,aAAa,SAAS,iBAAiB,MACzC,QAAO,OAAO;AAGhB,UAAO,iBAAiB,QAAQ,KAAK,GAAG;;EAG1C,yBAAyB,QAAQ,GAAG;GAClC,MAAM,EAAE,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