cross-state 1.8.4 → 1.8.5

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.
@@ -5,4 +5,4 @@ function isAnyPath(path) {
5
5
 
6
6
  //#endregion
7
7
  export { isAnyPath as t };
8
- //# sourceMappingURL=path-D9AcO8Xm.js.map
8
+ //# sourceMappingURL=path-CCEtQjMB.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-D9AcO8Xm.js","names":[],"sources":["../src/lib/path.ts"],"sourcesContent":["import type {\n ArrayToStringPath,\n Array_,\n IsAny,\n IsNever,\n Object_,\n OptionalPropertyOf,\n StringToArrayPath,\n StringToNumber,\n} from './typeHelpers';\n\nexport type KeyType = string | number | symbol;\n\nexport type AnyPath = string | readonly KeyType[];\n\nexport type GetKeys<T extends Object_ | Array_> = T extends Array_\n ? T extends readonly [] // special case empty tuple => no keys\n ? never\n : '0' extends keyof T // any tuple with at least one element\n ? StringToNumber<keyof T>\n : number // other array\n : keyof T;\n\nexport type _PathAsArray<T, Optional, MaxDepth, Depth extends 1[]> =\n | (Optional extends false ? readonly [] : never)\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._PathAsArray<V, Optional, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | (Optional extends true\n ? K extends OptionalPropertyOf<T>\n ? readonly [K]\n : never\n : readonly [K])\n | readonly [K, ..._PathAsArray<T[K], Optional, MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type PathAsArray<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = _PathAsArray<T, Optional, MaxDepth, []>;\n\nexport type PathAsString<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = ArrayToStringPath<PathAsArray<T, Optional, MaxDepth>>;\n\nexport type Path<T, Optional extends boolean = false, MaxDepth extends number = 5> =\n | PathAsString<T, Optional, MaxDepth>\n | PathAsArray<T, Optional, MaxDepth>;\n\nexport type Value<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? Value<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? Value<V, Rest> | undefined\n : T extends Array_\n ? any[] extends T\n ? Value<T[First & keyof T], Rest> | undefined\n : Value<T[First & keyof T], Rest>\n : T extends Object_\n ? Record<any, any> extends T\n ? Value<T[First], Rest> | undefined\n : Value<T[First], Rest>\n : never\n : never;\n\nexport type _WildcardPathAsArray<T, MaxDepth, Depth extends 1[]> =\n | []\n | (0 extends 1 & T\n ? KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? ['*'] | [K] | [K, ..._WildcardPathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? ['*'] | [number]\n : Record<string, any> extends T\n ? ['*'] | ['*', ..._WildcardPathAsArray<T[string], MaxDepth, [...Depth, 1]>]\n : {\n [K in GetKeys<T>]:\n | ['*']\n | [\n '*',\n ..._WildcardPathAsArray<\n T[T extends readonly any[] ? number : keyof T],\n MaxDepth,\n [...Depth, 1]\n >,\n ]\n | [K]\n | [K, ..._WildcardPathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type WildcardPathAsArray<T, MaxDepth extends number = 5> = _WildcardPathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type WildcardPathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n _WildcardPathAsArray<T, MaxDepth, []>\n>;\nexport type WildcardPath<T, MaxDepth extends number = 5> =\n | WildcardPathAsString<T, MaxDepth>\n | WildcardPathAsArray<T, MaxDepth>;\n\nexport type WildcardValue<T, P> = true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? WildcardValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? WildcardValue<V, Rest> | (First extends '*' ? never : undefined)\n : T extends Array_\n ? First extends '*'\n ? WildcardValue<T[number], Rest>\n : any[] extends T\n ? WildcardValue<T[First & keyof T], Rest> | undefined\n : First extends keyof T\n ? WildcardValue<T[First], Rest>\n : undefined\n : T extends Object_\n ? First extends '*'\n ? WildcardValue<T[keyof T], Rest>\n : Record<any, any> extends T\n ? WildcardValue<T[First], Rest> | undefined\n : WildcardValue<T[First], Rest>\n : never\n : T;\n\nexport type WildcardMatch<S, W> = S extends string\n ? WildcardMatch<StringToArrayPath<S>, W>\n : W extends string\n ? WildcardMatch<S, StringToArrayPath<W>>\n : [S, W] extends [readonly [], readonly []]\n ? true\n : [S, W] extends [\n readonly [infer SFirst, ...infer SRest],\n readonly [infer WFirst, ...infer WRest],\n ]\n ? [WFirst, WRest['length']] extends ['*' | SFirst, SRest['length']]\n ? WildcardMatch<SRest, WRest>\n : false\n : false;\n\nexport type Join<A extends string | number, B extends string | number> = A extends ''\n ? B\n : B extends ''\n ? A\n : `${A}.${B}`;\n\ntype _SettablePathAsArray<T, MaxDepth, Depth extends 1[]> =\n | readonly []\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : undefined extends T\n ? T extends Map<any, any> | Set<any>\n ? never\n : T extends Object_\n ? {\n [K in GetKeys<T>]: Partial<T> extends Omit<T, K>\n ?\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>]\n : readonly [];\n }[GetKeys<T>]\n : never\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._SettablePathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type SettablePathAsArray<T, MaxDepth extends number = 5> = _SettablePathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type SettablePathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n SettablePathAsArray<T, MaxDepth>\n>;\n\nexport type SettablePath<T, MaxDepth extends number = 5> =\n | SettablePathAsString<T, MaxDepth>\n | SettablePathAsArray<T, MaxDepth>;\n\nexport type SettableValue<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? SettableValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? SettableValue<V, Rest>\n : T extends Array_\n ? SettableValue<T[First & keyof T], Rest>\n : T extends Object_\n ? SettableValue<T[First], Rest>\n : never\n : never;\n\nexport function isAnyPath(path: any): path is AnyPath {\n return typeof path === 'string' || Array.isArray(path);\n}\n"],"mappings":";AA8OA,SAAgB,UAAU,MAA4B;AACpD,QAAO,OAAO,SAAS,YAAY,MAAM,QAAQ,KAAK"}
1
+ {"version":3,"file":"path-CCEtQjMB.js","names":[],"sources":["../src/lib/path.ts"],"sourcesContent":["import type {\n ArrayToStringPath,\n Array_,\n IsAny,\n IsNever,\n Object_,\n OptionalPropertyOf,\n StringToArrayPath,\n StringToNumber,\n} from './typeHelpers';\n\nexport type KeyType = string | number | symbol;\n\nexport type AnyPath = string | readonly KeyType[];\n\nexport type GetKeys<T extends Object_ | Array_> = T extends Array_\n ? T extends readonly [] // special case empty tuple => no keys\n ? never\n : '0' extends keyof T // any tuple with at least one element\n ? StringToNumber<keyof T>\n : number // other array\n : keyof T;\n\nexport type _PathAsArray<T, Optional, MaxDepth, Depth extends 1[]> =\n | (Optional extends false ? readonly [] : never)\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._PathAsArray<V, Optional, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | (Optional extends true\n ? K extends OptionalPropertyOf<T>\n ? readonly [K]\n : never\n : readonly [K])\n | readonly [K, ..._PathAsArray<T[K], Optional, MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type PathAsArray<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = _PathAsArray<T, Optional, MaxDepth, []>;\n\nexport type PathAsString<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = ArrayToStringPath<PathAsArray<T, Optional, MaxDepth>>;\n\nexport type Path<T, Optional extends boolean = false, MaxDepth extends number = 5> =\n | PathAsString<T, Optional, MaxDepth>\n | PathAsArray<T, Optional, MaxDepth>;\n\nexport type Value<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? Value<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? Value<V, Rest> | undefined\n : T extends Array_\n ? any[] extends T\n ? Value<T[First & keyof T], Rest> | undefined\n : Value<T[First & keyof T], Rest>\n : T extends Object_\n ? Record<any, any> extends T\n ? Value<T[First], Rest> | undefined\n : Value<T[First], Rest>\n : never\n : never;\n\nexport type _WildcardPathAsArray<T, MaxDepth, Depth extends 1[]> =\n | []\n | (0 extends 1 & T\n ? KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? ['*'] | [K] | [K, ..._WildcardPathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? ['*'] | [number]\n : Record<string, any> extends T\n ? ['*'] | ['*', ..._WildcardPathAsArray<T[string], MaxDepth, [...Depth, 1]>]\n : {\n [K in GetKeys<T>]:\n | ['*']\n | [\n '*',\n ..._WildcardPathAsArray<\n T[T extends readonly any[] ? number : keyof T],\n MaxDepth,\n [...Depth, 1]\n >,\n ]\n | [K]\n | [K, ..._WildcardPathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type WildcardPathAsArray<T, MaxDepth extends number = 5> = _WildcardPathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type WildcardPathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n _WildcardPathAsArray<T, MaxDepth, []>\n>;\nexport type WildcardPath<T, MaxDepth extends number = 5> =\n | WildcardPathAsString<T, MaxDepth>\n | WildcardPathAsArray<T, MaxDepth>;\n\nexport type WildcardValue<T, P> = true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? WildcardValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? WildcardValue<V, Rest> | (First extends '*' ? never : undefined)\n : T extends Array_\n ? First extends '*'\n ? WildcardValue<T[number], Rest>\n : any[] extends T\n ? WildcardValue<T[First & keyof T], Rest> | undefined\n : First extends keyof T\n ? WildcardValue<T[First], Rest>\n : undefined\n : T extends Object_\n ? First extends '*'\n ? WildcardValue<T[keyof T], Rest>\n : Record<any, any> extends T\n ? WildcardValue<T[First], Rest> | undefined\n : WildcardValue<T[First], Rest>\n : never\n : T;\n\nexport type WildcardMatch<S, W> = S extends string\n ? WildcardMatch<StringToArrayPath<S>, W>\n : W extends string\n ? WildcardMatch<S, StringToArrayPath<W>>\n : [S, W] extends [readonly [], readonly []]\n ? true\n : [S, W] extends [\n readonly [infer SFirst, ...infer SRest],\n readonly [infer WFirst, ...infer WRest],\n ]\n ? [WFirst, WRest['length']] extends ['*' | SFirst, SRest['length']]\n ? WildcardMatch<SRest, WRest>\n : false\n : false;\n\nexport type Join<A extends string | number, B extends string | number> = A extends ''\n ? B\n : B extends ''\n ? A\n : `${A}.${B}`;\n\ntype _SettablePathAsArray<T, MaxDepth, Depth extends 1[]> =\n | readonly []\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : undefined extends T\n ? T extends Map<any, any> | Set<any>\n ? never\n : T extends Object_\n ? {\n [K in GetKeys<T>]: Partial<T> extends Omit<T, K>\n ?\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>]\n : readonly [];\n }[GetKeys<T>]\n : never\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._SettablePathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type SettablePathAsArray<T, MaxDepth extends number = 5> = _SettablePathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type SettablePathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n SettablePathAsArray<T, MaxDepth>\n>;\n\nexport type SettablePath<T, MaxDepth extends number = 5> =\n | SettablePathAsString<T, MaxDepth>\n | SettablePathAsArray<T, MaxDepth>;\n\nexport type SettableValue<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? SettableValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? SettableValue<V, Rest>\n : T extends Array_\n ? SettableValue<T[First & keyof T], Rest>\n : T extends Object_\n ? SettableValue<T[First], Rest>\n : never\n : never;\n\nexport function isAnyPath(path: any): path is AnyPath {\n return typeof path === 'string' || Array.isArray(path);\n}\n"],"mappings":";AA8OA,SAAgB,UAAU,MAA4B;AACpD,QAAO,OAAO,SAAS,YAAY,MAAM,QAAQ,KAAK"}
@@ -11,4 +11,4 @@ Object.defineProperty(exports, 'isAnyPath', {
11
11
  return isAnyPath;
12
12
  }
13
13
  });
14
- //# sourceMappingURL=path-DlT18sdG.cjs.map
14
+ //# sourceMappingURL=path-Il5r4PV4.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"path-DlT18sdG.cjs","names":[],"sources":["../src/lib/path.ts"],"sourcesContent":["import type {\n ArrayToStringPath,\n Array_,\n IsAny,\n IsNever,\n Object_,\n OptionalPropertyOf,\n StringToArrayPath,\n StringToNumber,\n} from './typeHelpers';\n\nexport type KeyType = string | number | symbol;\n\nexport type AnyPath = string | readonly KeyType[];\n\nexport type GetKeys<T extends Object_ | Array_> = T extends Array_\n ? T extends readonly [] // special case empty tuple => no keys\n ? never\n : '0' extends keyof T // any tuple with at least one element\n ? StringToNumber<keyof T>\n : number // other array\n : keyof T;\n\nexport type _PathAsArray<T, Optional, MaxDepth, Depth extends 1[]> =\n | (Optional extends false ? readonly [] : never)\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._PathAsArray<V, Optional, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | (Optional extends true\n ? K extends OptionalPropertyOf<T>\n ? readonly [K]\n : never\n : readonly [K])\n | readonly [K, ..._PathAsArray<T[K], Optional, MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type PathAsArray<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = _PathAsArray<T, Optional, MaxDepth, []>;\n\nexport type PathAsString<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = ArrayToStringPath<PathAsArray<T, Optional, MaxDepth>>;\n\nexport type Path<T, Optional extends boolean = false, MaxDepth extends number = 5> =\n | PathAsString<T, Optional, MaxDepth>\n | PathAsArray<T, Optional, MaxDepth>;\n\nexport type Value<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? Value<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? Value<V, Rest> | undefined\n : T extends Array_\n ? any[] extends T\n ? Value<T[First & keyof T], Rest> | undefined\n : Value<T[First & keyof T], Rest>\n : T extends Object_\n ? Record<any, any> extends T\n ? Value<T[First], Rest> | undefined\n : Value<T[First], Rest>\n : never\n : never;\n\nexport type _WildcardPathAsArray<T, MaxDepth, Depth extends 1[]> =\n | []\n | (0 extends 1 & T\n ? KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? ['*'] | [K] | [K, ..._WildcardPathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? ['*'] | [number]\n : Record<string, any> extends T\n ? ['*'] | ['*', ..._WildcardPathAsArray<T[string], MaxDepth, [...Depth, 1]>]\n : {\n [K in GetKeys<T>]:\n | ['*']\n | [\n '*',\n ..._WildcardPathAsArray<\n T[T extends readonly any[] ? number : keyof T],\n MaxDepth,\n [...Depth, 1]\n >,\n ]\n | [K]\n | [K, ..._WildcardPathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type WildcardPathAsArray<T, MaxDepth extends number = 5> = _WildcardPathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type WildcardPathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n _WildcardPathAsArray<T, MaxDepth, []>\n>;\nexport type WildcardPath<T, MaxDepth extends number = 5> =\n | WildcardPathAsString<T, MaxDepth>\n | WildcardPathAsArray<T, MaxDepth>;\n\nexport type WildcardValue<T, P> = true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? WildcardValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? WildcardValue<V, Rest> | (First extends '*' ? never : undefined)\n : T extends Array_\n ? First extends '*'\n ? WildcardValue<T[number], Rest>\n : any[] extends T\n ? WildcardValue<T[First & keyof T], Rest> | undefined\n : First extends keyof T\n ? WildcardValue<T[First], Rest>\n : undefined\n : T extends Object_\n ? First extends '*'\n ? WildcardValue<T[keyof T], Rest>\n : Record<any, any> extends T\n ? WildcardValue<T[First], Rest> | undefined\n : WildcardValue<T[First], Rest>\n : never\n : T;\n\nexport type WildcardMatch<S, W> = S extends string\n ? WildcardMatch<StringToArrayPath<S>, W>\n : W extends string\n ? WildcardMatch<S, StringToArrayPath<W>>\n : [S, W] extends [readonly [], readonly []]\n ? true\n : [S, W] extends [\n readonly [infer SFirst, ...infer SRest],\n readonly [infer WFirst, ...infer WRest],\n ]\n ? [WFirst, WRest['length']] extends ['*' | SFirst, SRest['length']]\n ? WildcardMatch<SRest, WRest>\n : false\n : false;\n\nexport type Join<A extends string | number, B extends string | number> = A extends ''\n ? B\n : B extends ''\n ? A\n : `${A}.${B}`;\n\ntype _SettablePathAsArray<T, MaxDepth, Depth extends 1[]> =\n | readonly []\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : undefined extends T\n ? T extends Map<any, any> | Set<any>\n ? never\n : T extends Object_\n ? {\n [K in GetKeys<T>]: Partial<T> extends Omit<T, K>\n ?\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>]\n : readonly [];\n }[GetKeys<T>]\n : never\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._SettablePathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type SettablePathAsArray<T, MaxDepth extends number = 5> = _SettablePathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type SettablePathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n SettablePathAsArray<T, MaxDepth>\n>;\n\nexport type SettablePath<T, MaxDepth extends number = 5> =\n | SettablePathAsString<T, MaxDepth>\n | SettablePathAsArray<T, MaxDepth>;\n\nexport type SettableValue<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? SettableValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? SettableValue<V, Rest>\n : T extends Array_\n ? SettableValue<T[First & keyof T], Rest>\n : T extends Object_\n ? SettableValue<T[First], Rest>\n : never\n : never;\n\nexport function isAnyPath(path: any): path is AnyPath {\n return typeof path === 'string' || Array.isArray(path);\n}\n"],"mappings":";;AA8OA,SAAgB,UAAU,MAA4B;AACpD,QAAO,OAAO,SAAS,YAAY,MAAM,QAAQ,KAAK"}
1
+ {"version":3,"file":"path-Il5r4PV4.cjs","names":[],"sources":["../src/lib/path.ts"],"sourcesContent":["import type {\n ArrayToStringPath,\n Array_,\n IsAny,\n IsNever,\n Object_,\n OptionalPropertyOf,\n StringToArrayPath,\n StringToNumber,\n} from './typeHelpers';\n\nexport type KeyType = string | number | symbol;\n\nexport type AnyPath = string | readonly KeyType[];\n\nexport type GetKeys<T extends Object_ | Array_> = T extends Array_\n ? T extends readonly [] // special case empty tuple => no keys\n ? never\n : '0' extends keyof T // any tuple with at least one element\n ? StringToNumber<keyof T>\n : number // other array\n : keyof T;\n\nexport type _PathAsArray<T, Optional, MaxDepth, Depth extends 1[]> =\n | (Optional extends false ? readonly [] : never)\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._PathAsArray<V, Optional, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | (Optional extends true\n ? K extends OptionalPropertyOf<T>\n ? readonly [K]\n : never\n : readonly [K])\n | readonly [K, ..._PathAsArray<T[K], Optional, MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type PathAsArray<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = _PathAsArray<T, Optional, MaxDepth, []>;\n\nexport type PathAsString<\n T,\n Optional extends boolean = false,\n MaxDepth extends number = 5,\n> = ArrayToStringPath<PathAsArray<T, Optional, MaxDepth>>;\n\nexport type Path<T, Optional extends boolean = false, MaxDepth extends number = 5> =\n | PathAsString<T, Optional, MaxDepth>\n | PathAsArray<T, Optional, MaxDepth>;\n\nexport type Value<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? Value<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? Value<V, Rest> | undefined\n : T extends Array_\n ? any[] extends T\n ? Value<T[First & keyof T], Rest> | undefined\n : Value<T[First & keyof T], Rest>\n : T extends Object_\n ? Record<any, any> extends T\n ? Value<T[First], Rest> | undefined\n : Value<T[First], Rest>\n : never\n : never;\n\nexport type _WildcardPathAsArray<T, MaxDepth, Depth extends 1[]> =\n | []\n | (0 extends 1 & T\n ? KeyType[]\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? ['*'] | [K] | [K, ..._WildcardPathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? ['*'] | [number]\n : Record<string, any> extends T\n ? ['*'] | ['*', ..._WildcardPathAsArray<T[string], MaxDepth, [...Depth, 1]>]\n : {\n [K in GetKeys<T>]:\n | ['*']\n | [\n '*',\n ..._WildcardPathAsArray<\n T[T extends readonly any[] ? number : keyof T],\n MaxDepth,\n [...Depth, 1]\n >,\n ]\n | [K]\n | [K, ..._WildcardPathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type WildcardPathAsArray<T, MaxDepth extends number = 5> = _WildcardPathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type WildcardPathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n _WildcardPathAsArray<T, MaxDepth, []>\n>;\nexport type WildcardPath<T, MaxDepth extends number = 5> =\n | WildcardPathAsString<T, MaxDepth>\n | WildcardPathAsArray<T, MaxDepth>;\n\nexport type WildcardValue<T, P> = true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? WildcardValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? WildcardValue<V, Rest> | (First extends '*' ? never : undefined)\n : T extends Array_\n ? First extends '*'\n ? WildcardValue<T[number], Rest>\n : any[] extends T\n ? WildcardValue<T[First & keyof T], Rest> | undefined\n : First extends keyof T\n ? WildcardValue<T[First], Rest>\n : undefined\n : T extends Object_\n ? First extends '*'\n ? WildcardValue<T[keyof T], Rest>\n : Record<any, any> extends T\n ? WildcardValue<T[First], Rest> | undefined\n : WildcardValue<T[First], Rest>\n : never\n : T;\n\nexport type WildcardMatch<S, W> = S extends string\n ? WildcardMatch<StringToArrayPath<S>, W>\n : W extends string\n ? WildcardMatch<S, StringToArrayPath<W>>\n : [S, W] extends [readonly [], readonly []]\n ? true\n : [S, W] extends [\n readonly [infer SFirst, ...infer SRest],\n readonly [infer WFirst, ...infer WRest],\n ]\n ? [WFirst, WRest['length']] extends ['*' | SFirst, SRest['length']]\n ? WildcardMatch<SRest, WRest>\n : false\n : false;\n\nexport type Join<A extends string | number, B extends string | number> = A extends ''\n ? B\n : B extends ''\n ? A\n : `${A}.${B}`;\n\ntype _SettablePathAsArray<T, MaxDepth, Depth extends 1[]> =\n | readonly []\n | (true extends IsAny<T>\n ? readonly KeyType[]\n : undefined extends T\n ? T extends Map<any, any> | Set<any>\n ? never\n : T extends Object_\n ? {\n [K in GetKeys<T>]: Partial<T> extends Omit<T, K>\n ?\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>]\n : readonly [];\n }[GetKeys<T>]\n : never\n : T extends never\n ? never\n : T extends Object_\n ? Depth['length'] extends MaxDepth\n ? readonly string[]\n : T extends Map<infer K extends KeyType, infer V>\n ? readonly [K] | readonly [K, ..._SettablePathAsArray<V, MaxDepth, [...Depth, 1]>]\n : T extends Set<any>\n ? readonly [number]\n : {\n [K in GetKeys<T>]:\n | readonly [K]\n | readonly [K, ..._SettablePathAsArray<T[K], MaxDepth, [...Depth, 1]>];\n }[GetKeys<T>]\n : never);\n\nexport type SettablePathAsArray<T, MaxDepth extends number = 5> = _SettablePathAsArray<\n T,\n MaxDepth,\n []\n>;\nexport type SettablePathAsString<T, MaxDepth extends number = 5> = ArrayToStringPath<\n SettablePathAsArray<T, MaxDepth>\n>;\n\nexport type SettablePath<T, MaxDepth extends number = 5> =\n | SettablePathAsString<T, MaxDepth>\n | SettablePathAsArray<T, MaxDepth>;\n\nexport type SettableValue<T, P> = P extends readonly []\n ? T\n : true extends IsAny<T> | IsAny<P>\n ? any\n : true extends IsNever<T> | IsNever<P>\n ? never\n : P extends string\n ? SettableValue<T, StringToArrayPath<P>>\n : P extends readonly [infer First extends KeyType, ...infer Rest extends readonly KeyType[]]\n ? T extends Map<any, infer V> | Set<infer V>\n ? SettableValue<V, Rest>\n : T extends Array_\n ? SettableValue<T[First & keyof T], Rest>\n : T extends Object_\n ? SettableValue<T[First], Rest>\n : never\n : never;\n\nexport function isAnyPath(path: any): path is AnyPath {\n return typeof path === 'string' || Array.isArray(path);\n}\n"],"mappings":";;AA8OA,SAAgB,UAAU,MAA4B;AACpD,QAAO,OAAO,SAAS,YAAY,MAAM,QAAQ,KAAK"}
@@ -1,7 +1,7 @@
1
1
  const require_store = require('../store-CPqOf4y5.cjs');
2
2
  const require_propAccess = require('../propAccess-udIdjqwY.cjs');
3
3
  const require_extendedJson = require('../extendedJson-BwYSvpOA.cjs');
4
- const require_storeMethods = require('../storeMethods-C82xFw-L.cjs');
4
+ const require_storeMethods = require('../storeMethods-BZb4k7Ma.cjs');
5
5
  let react = require("react");
6
6
  let react_jsx_runtime = require("react/jsx-runtime");
7
7
  let mutative = require("mutative");
@@ -1,7 +1,7 @@
1
1
  import { c as debounce, d as queue, h as autobind, m as calcDuration, n as createStore, p as isPromise, r as throttle, t as Store } from "../store-D4q5zD7q.js";
2
2
  import { a as set, c as deepEqual, n as get, o as isObject, r as join, t as castArrayPath } from "../propAccess-BxCKNeOj.js";
3
3
  import { i as toExtendedJsonString, n as fromExtendedJsonString } from "../extendedJson-B1OEqZtF.js";
4
- import { a as useProp, c as useCache, d as useStore, f as useMemoEquals, i as useScope, l as LoadingBoundary, n as scopeMethods, o as useLatestFunction, r as ScopeProvider, s as cacheMethods, t as storeMethods, u as useLoadingBoundary } from "../storeMethods-DX69Iddl.js";
4
+ import { a as useProp, c as useCache, d as useStore, f as useMemoEquals, i as useScope, l as LoadingBoundary, n as scopeMethods, o as useLatestFunction, r as ScopeProvider, s as cacheMethods, t as storeMethods, u as useLoadingBoundary } from "../storeMethods-CWeGkXoz.js";
5
5
  import { Fragment, createContext, createElement, forwardRef, startTransition, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
6
6
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
7
  import { create } from "mutative";
@@ -1,6 +1,6 @@
1
1
  const require_store = require('../store-CPqOf4y5.cjs');
2
2
  const require_scope = require('../scope-DkX72a-2.cjs');
3
- const require_storeMethods = require('../storeMethods-C82xFw-L.cjs');
3
+ const require_storeMethods = require('../storeMethods-BZb4k7Ma.cjs');
4
4
 
5
5
  //#region src/react/register.ts
6
6
  Object.assign(require_store.Store.prototype, require_storeMethods.storeMethods);
@@ -1,6 +1,6 @@
1
1
  import { h as autobind, t as Store } from "../store-D4q5zD7q.js";
2
2
  import { r as Cache, t as Scope } from "../scope-CQE3HDNI.js";
3
- import { n as scopeMethods, s as cacheMethods, t as storeMethods } from "../storeMethods-DX69Iddl.js";
3
+ import { n as scopeMethods, s as cacheMethods, t as storeMethods } from "../storeMethods-CWeGkXoz.js";
4
4
 
5
5
  //#region src/react/register.ts
6
6
  Object.assign(Store.prototype, storeMethods);
@@ -1,20 +1,9 @@
1
1
  const require_store = require('./store-CPqOf4y5.cjs');
2
2
  const require_propAccess = require('./propAccess-udIdjqwY.cjs');
3
- const require_path = require('./path-DlT18sdG.cjs');
3
+ const require_path = require('./path-Il5r4PV4.cjs');
4
4
  let react = require("react");
5
5
  let react_jsx_runtime = require("react/jsx-runtime");
6
6
 
7
- //#region src/react/lib/useMemoEquals.ts
8
- function useMemoEquals(value, equals = require_propAccess.deepEqual) {
9
- const ref = (0, react.useRef)(void 0);
10
- const hasChanged = !ref.current || !equals(ref.current.value, value);
11
- (0, react.useEffect)(() => {
12
- if (hasChanged) ref.current = { value };
13
- });
14
- return hasChanged ? value : ref.current.value;
15
- }
16
-
17
- //#endregion
18
7
  //#region src/lib/trackingProxy.ts
19
8
  const unwrapProxySymbol = /* @__PURE__ */ Symbol("unwrapProxy");
20
9
  function trackingProxy(value, equals = require_propAccess.deepEqual) {
@@ -74,6 +63,17 @@ function trackingProxy(value, equals = require_propAccess.deepEqual) {
74
63
  ];
75
64
  }
76
65
 
66
+ //#endregion
67
+ //#region src/react/lib/useMemoEquals.ts
68
+ function useMemoEquals(value, equals = require_propAccess.deepEqual) {
69
+ const ref = (0, react.useRef)(void 0);
70
+ const hasChanged = !ref.current || !equals(ref.current.value, value);
71
+ (0, react.useEffect)(() => {
72
+ if (hasChanged) ref.current = { value };
73
+ });
74
+ return hasChanged ? value : ref.current.value;
75
+ }
76
+
77
77
  //#endregion
78
78
  //#region src/react/useStore.ts
79
79
  function useStore(store, ...args) {
@@ -254,10 +254,6 @@ function useCache(cache, { passive, disabled, updateOnMount, withViewTransition,
254
254
  withViewTransition,
255
255
  passive: passive || disabled
256
256
  });
257
- result[0] = useMemoEquals(result[0]);
258
- result.value = result[0];
259
- result[1] = useMemoEquals(result[1]);
260
- result.error = result[1];
261
257
  (0, react.useEffect)(() => rootCache.subscribe(() => void 0, { passive: passive || disabled }), [
262
258
  rootCache,
263
259
  passive,
@@ -445,4 +441,4 @@ Object.defineProperty(exports, 'useStore', {
445
441
  return useStore;
446
442
  }
447
443
  });
448
- //# sourceMappingURL=storeMethods-C82xFw-L.cjs.map
444
+ //# sourceMappingURL=storeMethods-BZb4k7Ma.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storeMethods-BZb4k7Ma.cjs","names":["deepEqual","isPlainObject","equals","deepEqual","selectorRaw: Selector<T, S> | AnyPath | undefined","allOptions: UseStoreOptionsWithSelector<T, S>","isAnyPath","makeSelector","deepEqual","strictEqual","_listener: (value: any) => void","lastObservedValue: any","value","revoke: (() => void) | undefined","createStore","rootCache: Cache<any, any>","selector","makeSelector","selector: Selector<T, S> | AnyPath | undefined","updater: ((value: S) => Update<T>) | undefined","options: UseStoreOptions<S> | undefined","isAnyPath","_store: Store<any>","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/lib/useMemoEquals.ts","../src/react/useStore.ts","../src/react/loadingBoundary.tsx","../src/react/useCache.ts","../src/react/cacheMethods.ts","../src/react/lib/useLatestRef.ts","../src/react/lib/useLatestFunction.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 { deepEqual } from '@lib/equals';\nimport { useEffect, useRef } from 'react';\n\nexport default function useMemoEquals<T>(value: T, equals: (a: T, b: T) => boolean = deepEqual): T {\n const ref = useRef<{ value: T }>(undefined);\n const hasChanged = !ref.current || !equals(ref.current.value, value);\n\n useEffect(() => {\n if (hasChanged) {\n ref.current = { value };\n }\n });\n\n return hasChanged ? value : ref.current!.value;\n}\n","import type { Selector, SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { deepEqual, strictEqual } from '@lib/equals';\nimport { makeSelector } from '@lib/makeSelector';\nimport { isAnyPath, type AnyPath, type Path, type Value } from '@lib/path';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport useMemoEquals from '@react/lib/useMemoEquals';\nimport {\n useCallback,\n useDebugValue,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\nexport interface UseStoreOptions<T> 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\n passive?: boolean;\n\n /**\n * (experimental) If true, the a rerender will only be triggered when a property of the returned value changes that was\n * actually accessed during the last render.\n * @default false\n */\n enableTrackingProxy?: boolean;\n\n /**\n * (experimental) If provided, a rerender will be wrapped in a browser view transition.\n */\n withViewTransition?: boolean | ((value: T) => unknown);\n}\n\nexport interface UseStoreOptionsWithSelector<T, S> extends UseStoreOptions<S> {\n /**\n * Equality function to compare the raw store values before reevaluating the selector.\n * Can be used to avoid unnecessary selector evaluations.\n * @default strictEqual\n */\n storeValueEquals?: (newValue: T, oldValue: T) => boolean;\n}\n\nexport function useStore<T, S>(\n store: Store<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptionsWithSelector<T, S>,\n): S;\n\nexport function useStore<T, const P>(\n store: Store<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptionsWithSelector<T, 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>(\n store: Store<T>,\n ...args:\n | [Selector<T, S> | AnyPath, UseStoreOptionsWithSelector<T, S>?]\n | [UseStoreOptionsWithSelector<T, S>?]\n): S {\n let selectorRaw: Selector<T, S> | AnyPath | undefined;\n let allOptions: UseStoreOptionsWithSelector<T, S>;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selectorRaw = args[0];\n allOptions = args[1] ?? {};\n } else {\n allOptions = args[0] ?? {};\n }\n\n const selectorMemoized = useMemoEquals(selectorRaw);\n const selector = useMemo(() => makeSelector<T, S>(selectorMemoized), [selectorMemoized]);\n const lastEqualsRef = useRef<(newValue: S) => boolean | undefined>(undefined);\n\n const {\n enableTrackingProxy,\n equals = store.options.equals ?? deepEqual,\n withViewTransition,\n storeValueEquals = strictEqual,\n ...options\n } = allOptions;\n\n const snapshot = useRef<{ storeValue: T; selector: (value: T) => S; selectedValue: S }>(\n undefined,\n );\n\n const get = useCallback(() => {\n const storeValue = store.get();\n\n if (\n snapshot.current &&\n storeValueEquals(storeValue, snapshot.current.storeValue) &&\n selector === snapshot.current.selector\n ) {\n return snapshot.current.selectedValue;\n }\n\n const selectedValue = selector(storeValue);\n if (!(lastEqualsRef.current?.(selectedValue) ?? false)) {\n snapshot.current = { storeValue, selector, selectedValue };\n }\n\n return snapshot.current!.selectedValue;\n }, [store, storeValueEquals, selector]);\n\n const rootStore = store.derivedFrom?.store ?? store;\n const subOptions = useMemoEquals({ ...options, runNow: false });\n\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 = rootStore.subscribe(_listener, subOptions);\n return () => {\n stopped = true;\n cancel();\n };\n },\n [rootStore, withViewTransition, equals, subOptions],\n );\n\n let value = useSyncExternalStore<S>(subscribe, get, get);\n let lastEquals = (newValue: S) => equals(newValue, value);\n let revoke: (() => void) | undefined;\n\n if (enableTrackingProxy) {\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 // oxlint-disable-next-line exhaustive-deps\n }, [store, 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 // oxlint-disable-next-line exhaustive-deps\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 { useRef } from 'react';\n\nexport default function useLatestRef<T>(value: T): { current: T } {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","import useLatestRef from '@react/lib/useLatestRef';\nimport { useCallback } from 'react';\n\nexport default function useLatestFunction<Args extends any[], R>(\n fn: (...args: Args) => R,\n): (...args: Args) => R {\n const ref = useLatestRef(fn);\n\n return useCallback(\n (...args: Args) => {\n return ref.current(...args);\n },\n [ref],\n );\n}\n","import { type Selector, type Update } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { isAnyPath, type AnyPath, type SettablePath, type Value } from '@lib/path';\nimport useLatestFunction from '@react/lib/useLatestFunction';\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, SettablePath<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 ...args:\n | [Selector<T, S>, (value: S) => Update<T>, UseStoreOptions<S>?]\n | [AnyPath, UseStoreOptions<Value<T, any>>?]\n | [UseStoreOptions<S>?]\n): [value: S, setValue: Store<S>['set']] {\n let selector: Selector<T, S> | AnyPath | undefined;\n let updater: ((value: S) => Update<T>) | undefined;\n let options: UseStoreOptions<S> | undefined;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selector = args[0];\n if (typeof args[1] === 'function') {\n updater = args[1];\n options = args[2];\n } else {\n options = args[1];\n }\n } else {\n options = args[0];\n }\n\n const value = useStore(store, (selector ?? ((x) => x)) as Selector<T, S>, options);\n\n const update = useLatestFunction((update) => {\n let _store: Store<any> = store;\n if (selector) {\n _store = _store.map(selector as Selector<any, any>, updater);\n }\n\n _store.set(update);\n });\n\n return [value, update];\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 '..' {\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,cAAc;AAK/D,SAAgB,cACd,OACA,SAAsCA,8BACpB;AAClB,KAAI,CAACC,iCAAc,MAAM,IAAI,CAAC,MAAM,QAAQ,MAAM,CAChD,QAAO,CAAC,QAAQ,UAAU,OAAO,OAAO,MAAM,CAAC;AAIjD,SAAS,MAAc,sBAAsB;CAE7C,MAAM,OAAO,IAAI,OAA8B;CAC/C,MAAM,cAAc,IAAI,OAAmB;CAC3C,IAAI,UAAU;CAEd,SAAS,iBAAiB,WAAgB,GAAG,MAAa;EACxD,MAAM,CAAC,cAAcC,UAAQ,UAAU,cAAc,UAAU,OAAO,GAAG,KAAK,CAAC;AAE/E,OAAK,MAAM,eAAe;AACxB,OAAI,CAACD,iCAAc,WAAW,IAAI,CAAC,MAAM,QAAQ,WAAW,CAC1D,QAAO;AAGT,UAAOC,SAAO,UAAU,YAAY,GAAG,KAAK,CAAC;IAC7C;AAEF,MAAI,OACF,aAAY,KAAK,OAAO;AAG1B,SAAO;;CAGT,SAAS,gBAAgB,WAAgB,GAAG,MAAa;EACvD,MAAM,kBAAkB,UAAU,OAAO,GAAG,KAAK;AAE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ACtC,MAAM,wCACE,cAAcA,0BAAY,MAAM,aAAa,EACnD,CAAC,OAAO,WAAW,CACpB;AAED,QAAO,2CAAC,QAAQ;EAAS,OAAO;EAAe;GAA4B;;AAG7E,SAAgB,SAAY,OAA2B;AAErD,8BADgB,gBAAgB,MAAM,CACZ;;AAiB5B,SAAgB,cAAiB,OAAiB,GAAG,MAAgB;AAEnE,QAAO,SADO,SAAS,MAAM,EACN,GAAG,KAAK;;AAqBjC,SAAgB,aACd,OACA,GAAG,MACoC;AAEvC,QAAO,QADO,SAAS,MAAM,EACP,GAAG,KAAK;;;;;ACtEhC,SAAS,gBAA2C;AAClD,QAAO,SAAS,KAAK;;AAiBvB,SAAS,mBAAqC,GAAG,MAAa;AAC5D,QAAO,cAAc,MAAM,GAAG,KAAK;;AAqBrC,SAAS,kBAAoC,GAAG,MAAa;AAC3D,QAAO,aAAa,MAAM,GAAG,KAAK;;AAGpC,SAAS,SAA4B,OAAwD;AAC3F,QAAO,cAAc;EAAE,GAAG;EAAO,OAAO;EAAM,CAAC;;AAGjD,MAAaC,eAKT;CACF,UAAU;CACV,UAAU;CACV,SAAS;CACT;CACD;;;;ACrDD,SAAS,cAAgC,GAAG,MAAa;AACvD,QAAO,SAAS,MAAM,GAAG,KAAK;;AAkBhC,SAAS,aAA+B,GAAG,MAAa;AACtD,QAAO,QAAQ,MAAM,GAAG,KAAK;;AAG/B,MAAaC,eAGT;CACF,UAAU;CACV,SAAS;CACV"}
@@ -1,20 +1,9 @@
1
1
  import { l as makeSelector, n as createStore } from "./store-D4q5zD7q.js";
2
2
  import { c as deepEqual, s as isPlainObject, u as strictEqual } from "./propAccess-BxCKNeOj.js";
3
- import { t as isAnyPath } from "./path-D9AcO8Xm.js";
3
+ import { t as isAnyPath } from "./path-CCEtQjMB.js";
4
4
  import { createContext, useCallback, useContext, useDebugValue, useEffect, useLayoutEffect, useMemo, useRef, useSyncExternalStore } from "react";
5
5
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
6
6
 
7
- //#region src/react/lib/useMemoEquals.ts
8
- function useMemoEquals(value, equals = deepEqual) {
9
- const ref = useRef(void 0);
10
- const hasChanged = !ref.current || !equals(ref.current.value, value);
11
- useEffect(() => {
12
- if (hasChanged) ref.current = { value };
13
- });
14
- return hasChanged ? value : ref.current.value;
15
- }
16
-
17
- //#endregion
18
7
  //#region src/lib/trackingProxy.ts
19
8
  const unwrapProxySymbol = /* @__PURE__ */ Symbol("unwrapProxy");
20
9
  function trackingProxy(value, equals = deepEqual) {
@@ -74,6 +63,17 @@ function trackingProxy(value, equals = deepEqual) {
74
63
  ];
75
64
  }
76
65
 
66
+ //#endregion
67
+ //#region src/react/lib/useMemoEquals.ts
68
+ function useMemoEquals(value, equals = deepEqual) {
69
+ const ref = useRef(void 0);
70
+ const hasChanged = !ref.current || !equals(ref.current.value, value);
71
+ useEffect(() => {
72
+ if (hasChanged) ref.current = { value };
73
+ });
74
+ return hasChanged ? value : ref.current.value;
75
+ }
76
+
77
77
  //#endregion
78
78
  //#region src/react/useStore.ts
79
79
  function useStore(store, ...args) {
@@ -254,10 +254,6 @@ function useCache(cache, { passive, disabled, updateOnMount, withViewTransition,
254
254
  withViewTransition,
255
255
  passive: passive || disabled
256
256
  });
257
- result[0] = useMemoEquals(result[0]);
258
- result.value = result[0];
259
- result[1] = useMemoEquals(result[1]);
260
- result.error = result[1];
261
257
  useEffect(() => rootCache.subscribe(() => void 0, { passive: passive || disabled }), [
262
258
  rootCache,
263
259
  passive,
@@ -374,4 +370,4 @@ const storeMethods = {
374
370
 
375
371
  //#endregion
376
372
  export { useProp as a, useCache as c, useStore as d, useMemoEquals as f, useScope as i, LoadingBoundary as l, scopeMethods as n, useLatestFunction as o, ScopeProvider as r, cacheMethods as s, storeMethods as t, useLoadingBoundary as u };
377
- //# sourceMappingURL=storeMethods-DX69Iddl.js.map
373
+ //# sourceMappingURL=storeMethods-CWeGkXoz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storeMethods-CWeGkXoz.js","names":["equals","selectorRaw: Selector<T, S> | AnyPath | undefined","allOptions: UseStoreOptionsWithSelector<T, S>","_listener: (value: any) => void","lastObservedValue: any","value","revoke: (() => void) | undefined","rootCache: Cache<any, any>","selector","selector: Selector<T, S> | AnyPath | undefined","updater: ((value: S) => Update<T>) | undefined","options: UseStoreOptions<S> | undefined","_store: Store<any>","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/lib/useMemoEquals.ts","../src/react/useStore.ts","../src/react/loadingBoundary.tsx","../src/react/useCache.ts","../src/react/cacheMethods.ts","../src/react/lib/useLatestRef.ts","../src/react/lib/useLatestFunction.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 { deepEqual } from '@lib/equals';\nimport { useEffect, useRef } from 'react';\n\nexport default function useMemoEquals<T>(value: T, equals: (a: T, b: T) => boolean = deepEqual): T {\n const ref = useRef<{ value: T }>(undefined);\n const hasChanged = !ref.current || !equals(ref.current.value, value);\n\n useEffect(() => {\n if (hasChanged) {\n ref.current = { value };\n }\n });\n\n return hasChanged ? value : ref.current!.value;\n}\n","import type { Selector, SubscribeOptions } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { deepEqual, strictEqual } from '@lib/equals';\nimport { makeSelector } from '@lib/makeSelector';\nimport { isAnyPath, type AnyPath, type Path, type Value } from '@lib/path';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport useMemoEquals from '@react/lib/useMemoEquals';\nimport {\n useCallback,\n useDebugValue,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\nexport interface UseStoreOptions<T> 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\n passive?: boolean;\n\n /**\n * (experimental) If true, the a rerender will only be triggered when a property of the returned value changes that was\n * actually accessed during the last render.\n * @default false\n */\n enableTrackingProxy?: boolean;\n\n /**\n * (experimental) If provided, a rerender will be wrapped in a browser view transition.\n */\n withViewTransition?: boolean | ((value: T) => unknown);\n}\n\nexport interface UseStoreOptionsWithSelector<T, S> extends UseStoreOptions<S> {\n /**\n * Equality function to compare the raw store values before reevaluating the selector.\n * Can be used to avoid unnecessary selector evaluations.\n * @default strictEqual\n */\n storeValueEquals?: (newValue: T, oldValue: T) => boolean;\n}\n\nexport function useStore<T, S>(\n store: Store<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptionsWithSelector<T, S>,\n): S;\n\nexport function useStore<T, const P>(\n store: Store<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptionsWithSelector<T, 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>(\n store: Store<T>,\n ...args:\n | [Selector<T, S> | AnyPath, UseStoreOptionsWithSelector<T, S>?]\n | [UseStoreOptionsWithSelector<T, S>?]\n): S {\n let selectorRaw: Selector<T, S> | AnyPath | undefined;\n let allOptions: UseStoreOptionsWithSelector<T, S>;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selectorRaw = args[0];\n allOptions = args[1] ?? {};\n } else {\n allOptions = args[0] ?? {};\n }\n\n const selectorMemoized = useMemoEquals(selectorRaw);\n const selector = useMemo(() => makeSelector<T, S>(selectorMemoized), [selectorMemoized]);\n const lastEqualsRef = useRef<(newValue: S) => boolean | undefined>(undefined);\n\n const {\n enableTrackingProxy,\n equals = store.options.equals ?? deepEqual,\n withViewTransition,\n storeValueEquals = strictEqual,\n ...options\n } = allOptions;\n\n const snapshot = useRef<{ storeValue: T; selector: (value: T) => S; selectedValue: S }>(\n undefined,\n );\n\n const get = useCallback(() => {\n const storeValue = store.get();\n\n if (\n snapshot.current &&\n storeValueEquals(storeValue, snapshot.current.storeValue) &&\n selector === snapshot.current.selector\n ) {\n return snapshot.current.selectedValue;\n }\n\n const selectedValue = selector(storeValue);\n if (!(lastEqualsRef.current?.(selectedValue) ?? false)) {\n snapshot.current = { storeValue, selector, selectedValue };\n }\n\n return snapshot.current!.selectedValue;\n }, [store, storeValueEquals, selector]);\n\n const rootStore = store.derivedFrom?.store ?? store;\n const subOptions = useMemoEquals({ ...options, runNow: false });\n\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 = rootStore.subscribe(_listener, subOptions);\n return () => {\n stopped = true;\n cancel();\n };\n },\n [rootStore, withViewTransition, equals, subOptions],\n );\n\n let value = useSyncExternalStore<S>(subscribe, get, get);\n let lastEquals = (newValue: S) => equals(newValue, value);\n let revoke: (() => void) | undefined;\n\n if (enableTrackingProxy) {\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 // oxlint-disable-next-line exhaustive-deps\n }, [store, 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 // oxlint-disable-next-line exhaustive-deps\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 { useRef } from 'react';\n\nexport default function useLatestRef<T>(value: T): { current: T } {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","import useLatestRef from '@react/lib/useLatestRef';\nimport { useCallback } from 'react';\n\nexport default function useLatestFunction<Args extends any[], R>(\n fn: (...args: Args) => R,\n): (...args: Args) => R {\n const ref = useLatestRef(fn);\n\n return useCallback(\n (...args: Args) => {\n return ref.current(...args);\n },\n [ref],\n );\n}\n","import { type Selector, type Update } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { isAnyPath, type AnyPath, type SettablePath, type Value } from '@lib/path';\nimport useLatestFunction from '@react/lib/useLatestFunction';\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, SettablePath<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 ...args:\n | [Selector<T, S>, (value: S) => Update<T>, UseStoreOptions<S>?]\n | [AnyPath, UseStoreOptions<Value<T, any>>?]\n | [UseStoreOptions<S>?]\n): [value: S, setValue: Store<S>['set']] {\n let selector: Selector<T, S> | AnyPath | undefined;\n let updater: ((value: S) => Update<T>) | undefined;\n let options: UseStoreOptions<S> | undefined;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selector = args[0];\n if (typeof args[1] === 'function') {\n updater = args[1];\n options = args[2];\n } else {\n options = args[1];\n }\n } else {\n options = args[0];\n }\n\n const value = useStore(store, (selector ?? ((x) => x)) as Selector<T, S>, options);\n\n const update = useLatestFunction((update) => {\n let _store: Store<any> = store;\n if (selector) {\n _store = _store.map(selector as Selector<any, any>, updater);\n }\n\n _store.set(update);\n });\n\n return [value, update];\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 '..' {\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,cAAc;AAK/D,SAAgB,cACd,OACA,SAAsC,WACpB;AAClB,KAAI,CAAC,cAAc,MAAM,IAAI,CAAC,MAAM,QAAQ,MAAM,CAChD,QAAO,CAAC,QAAQ,UAAU,OAAO,OAAO,MAAM,CAAC;AAIjD,SAAS,MAAc,sBAAsB;CAE7C,MAAM,OAAO,IAAI,OAA8B;CAC/C,MAAM,cAAc,IAAI,OAAmB;CAC3C,IAAI,UAAU;CAEd,SAAS,iBAAiB,WAAgB,GAAG,MAAa;EACxD,MAAM,CAAC,cAAcA,UAAQ,UAAU,cAAc,UAAU,OAAO,GAAG,KAAK,CAAC;AAE/E,OAAK,MAAM,eAAe;AACxB,OAAI,CAAC,cAAc,WAAW,IAAI,CAAC,MAAM,QAAQ,WAAW,CAC1D,QAAO;AAGT,UAAOA,SAAO,UAAU,YAAY,GAAG,KAAK,CAAC;IAC7C;AAEF,MAAI,OACF,aAAY,KAAK,OAAO;AAG1B,SAAO;;CAGT,SAAS,gBAAgB,WAAgB,GAAG,MAAa;EACvD,M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AAO,MAAM;;AAGf,SAAgB,cAAiB,EAC/B,OACA,OAAO,YACP,YACmC;CACnC,MAAM,UAAU,gBAAgB,MAAM;CACtC,MAAM,eAAe,cACb,cAAc,YAAY,MAAM,aAAa,EACnD,CAAC,OAAO,WAAW,CACpB;AAED,QAAO,oBAAC,QAAQ;EAAS,OAAO;EAAe;GAA4B;;AAG7E,SAAgB,SAAY,OAA2B;AAErD,QAAO,WADS,gBAAgB,MAAM,CACZ;;AAiB5B,SAAgB,cAAiB,OAAiB,GAAG,MAAgB;AAEnE,QAAO,SADO,SAAS,MAAM,EACN,GAAG,KAAK;;AAqBjC,SAAgB,aACd,OACA,GAAG,MACoC;AAEvC,QAAO,QADO,SAAS,MAAM,EACP,GAAG,KAAK;;;;;ACtEhC,SAAS,gBAA2C;AAClD,QAAO,SAAS,KAAK;;AAiBvB,SAAS,mBAAqC,GAAG,MAAa;AAC5D,QAAO,cAAc,MAAM,GAAG,KAAK;;AAqBrC,SAAS,kBAAoC,GAAG,MAAa;AAC3D,QAAO,aAAa,MAAM,GAAG,KAAK;;AAGpC,SAAS,SAA4B,OAAwD;AAC3F,QAAO,cAAc;EAAE,GAAG;EAAO,OAAO;EAAM,CAAC;;AAGjD,MAAaC,eAKT;CACF,UAAU;CACV,UAAU;CACV,SAAS;CACT;CACD;;;;ACrDD,SAAS,cAAgC,GAAG,MAAa;AACvD,QAAO,SAAS,MAAM,GAAG,KAAK;;AAkBhC,SAAS,aAA+B,GAAG,MAAa;AACtD,QAAO,QAAQ,MAAM,GAAG,KAAK;;AAG/B,MAAaC,eAGT;CACF,UAAU;CACV,SAAS;CACV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-state",
3
- "version": "1.8.4",
3
+ "version": "1.8.5",
4
4
  "description": "(React) state library",
5
5
  "license": "ISC",
6
6
  "repository": "schummar/cross-state",
@@ -1 +0,0 @@
1
- {"version":3,"file":"storeMethods-C82xFw-L.cjs","names":["deepEqual","deepEqual","isPlainObject","equals","selectorRaw: Selector<T, S> | AnyPath | undefined","allOptions: UseStoreOptionsWithSelector<T, S>","isAnyPath","makeSelector","deepEqual","strictEqual","_listener: (value: any) => void","lastObservedValue: any","value","revoke: (() => void) | undefined","createStore","rootCache: Cache<any, any>","selector","makeSelector","selector: Selector<T, S> | AnyPath | undefined","updater: ((value: S) => Update<T>) | undefined","options: UseStoreOptions<S> | undefined","isAnyPath","_store: Store<any>","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/react/lib/useMemoEquals.ts","../src/lib/trackingProxy.ts","../src/react/useStore.ts","../src/react/loadingBoundary.tsx","../src/react/useCache.ts","../src/react/cacheMethods.ts","../src/react/lib/useLatestRef.ts","../src/react/lib/useLatestFunction.ts","../src/react/useProp.ts","../src/react/scope.tsx","../src/react/scopeMethods.ts","../src/react/storeMethods.ts"],"sourcesContent":["import { deepEqual } from '@lib/equals';\nimport { useEffect, useRef } from 'react';\n\nexport default function useMemoEquals<T>(value: T, equals: (a: T, b: T) => boolean = deepEqual): T {\n const ref = useRef<{ value: T }>(undefined);\n const hasChanged = !ref.current || !equals(ref.current.value, value);\n\n useEffect(() => {\n if (hasChanged) {\n ref.current = { value };\n }\n });\n\n return hasChanged ? value : ref.current!.value;\n}\n","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, strictEqual } from '@lib/equals';\nimport { makeSelector } from '@lib/makeSelector';\nimport { isAnyPath, type AnyPath, type Path, type Value } from '@lib/path';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport useMemoEquals from '@react/lib/useMemoEquals';\nimport {\n useCallback,\n useDebugValue,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\nexport interface UseStoreOptions<T> 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\n passive?: boolean;\n\n /**\n * (experimental) If true, the a rerender will only be triggered when a property of the returned value changes that was\n * actually accessed during the last render.\n * @default false\n */\n enableTrackingProxy?: boolean;\n\n /**\n * (experimental) If provided, a rerender will be wrapped in a browser view transition.\n */\n withViewTransition?: boolean | ((value: T) => unknown);\n}\n\nexport interface UseStoreOptionsWithSelector<T, S> extends UseStoreOptions<S> {\n /**\n * Equality function to compare the raw store values before reevaluating the selector.\n * Can be used to avoid unnecessary selector evaluations.\n * @default strictEqual\n */\n storeValueEquals?: (newValue: T, oldValue: T) => boolean;\n}\n\nexport function useStore<T, S>(\n store: Store<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptionsWithSelector<T, S>,\n): S;\n\nexport function useStore<T, const P>(\n store: Store<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptionsWithSelector<T, 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>(\n store: Store<T>,\n ...args:\n | [Selector<T, S> | AnyPath, UseStoreOptionsWithSelector<T, S>?]\n | [UseStoreOptionsWithSelector<T, S>?]\n): S {\n let selectorRaw: Selector<T, S> | AnyPath | undefined;\n let allOptions: UseStoreOptionsWithSelector<T, S>;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selectorRaw = args[0];\n allOptions = args[1] ?? {};\n } else {\n allOptions = args[0] ?? {};\n }\n\n const selectorMemoized = useMemoEquals(selectorRaw);\n const selector = useMemo(() => makeSelector<T, S>(selectorMemoized), [selectorMemoized]);\n const lastEqualsRef = useRef<(newValue: S) => boolean | undefined>(undefined);\n\n const {\n enableTrackingProxy,\n equals = store.options.equals ?? deepEqual,\n withViewTransition,\n storeValueEquals = strictEqual,\n ...options\n } = allOptions;\n\n const snapshot = useRef<{ storeValue: T; selector: (value: T) => S; selectedValue: S }>(\n undefined,\n );\n\n const get = useCallback(() => {\n const storeValue = store.get();\n\n if (\n snapshot.current &&\n storeValueEquals(storeValue, snapshot.current.storeValue) &&\n selector === snapshot.current.selector\n ) {\n return snapshot.current.selectedValue;\n }\n\n const selectedValue = selector(storeValue);\n if (!(lastEqualsRef.current?.(selectedValue) ?? false)) {\n snapshot.current = { storeValue, selector, selectedValue };\n }\n\n return snapshot.current!.selectedValue;\n }, [store, storeValueEquals, selector]);\n\n const rootStore = store.derivedFrom?.store ?? store;\n const subOptions = useMemoEquals({ ...options, runNow: false });\n\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 = rootStore.subscribe(_listener, subOptions);\n return () => {\n stopped = true;\n cancel();\n };\n },\n [rootStore, withViewTransition, equals, subOptions],\n );\n\n let value = useSyncExternalStore<S>(subscribe, get, get);\n let lastEquals = (newValue: S) => equals(newValue, value);\n let revoke: (() => void) | undefined;\n\n if (enableTrackingProxy) {\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 // oxlint-disable-next-line exhaustive-deps\n }, [store, isLoading]);\n}\n","import type { Cache } from '@core';\nimport type { CacheState } from '@lib/cacheState';\nimport { makeSelector } from '@lib/makeSelector';\nimport useMemoEquals from '@react/lib/useMemoEquals';\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 // oxlint-disable-next-line exhaustive-deps\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 // Memoize value and error to keep their identity stable\n result[0] = useMemoEquals(result[0]);\n result.value = result[0];\n result[1] = useMemoEquals(result[1]);\n result.error = result[1];\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 { useRef } from 'react';\n\nexport default function useLatestRef<T>(value: T): { current: T } {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","import useLatestRef from '@react/lib/useLatestRef';\nimport { useCallback } from 'react';\n\nexport default function useLatestFunction<Args extends any[], R>(\n fn: (...args: Args) => R,\n): (...args: Args) => R {\n const ref = useLatestRef(fn);\n\n return useCallback(\n (...args: Args) => {\n return ref.current(...args);\n },\n [ref],\n );\n}\n","import { type Selector, type Update } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { isAnyPath, type AnyPath, type SettablePath, type Value } from '@lib/path';\nimport useLatestFunction from '@react/lib/useLatestFunction';\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, SettablePath<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 ...args:\n | [Selector<T, S>, (value: S) => Update<T>, UseStoreOptions<S>?]\n | [AnyPath, UseStoreOptions<Value<T, any>>?]\n | [UseStoreOptions<S>?]\n): [value: S, setValue: Store<S>['set']] {\n let selector: Selector<T, S> | AnyPath | undefined;\n let updater: ((value: S) => Update<T>) | undefined;\n let options: UseStoreOptions<S> | undefined;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selector = args[0];\n if (typeof args[1] === 'function') {\n updater = args[1];\n options = args[2];\n } else {\n options = args[1];\n }\n } else {\n options = args[0];\n }\n\n const value = useStore(store, (selector ?? ((x) => x)) as Selector<T, S>, options);\n\n const update = useLatestFunction((update) => {\n let _store: Store<any> = store;\n if (selector) {\n _store = _store.map(selector as Selector<any, any>, updater);\n }\n\n _store.set(update);\n });\n\n return [value, update];\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 '..' {\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,SAAwB,cAAiB,OAAU,SAAkCA,8BAAc;CACjG,MAAM,wBAA2B,OAAU;CAC3C,MAAM,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,IAAI,QAAQ,OAAO,MAAM;AAEpE,4BAAgB;AACd,MAAI,WACF,KAAI,UAAU,EAAE,OAAO;GAEzB;AAEF,QAAO,aAAa,QAAQ,IAAI,QAAS;;;;;ACV3C,MAAM,oBAAoC,uBAAO,cAAc;AAK/D,SAAgB,cACd,OACA,SAAsCC,8BACpB;AAClB,KAAI,CAACC,iCAAc,MAAM,IAAI,CAAC,MAAM,QAAQ,MAAM,CAChD,QAAO,CAAC,QAAQ,UAAU,OAAO,OAAO,MAAM,CAAC;AAIjD,SAAS,MAAc,sBAAsB;CAE7C,MAAM,OAAO,IAA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CACV,SAAS;CACV"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"storeMethods-DX69Iddl.js","names":["equals","selectorRaw: Selector<T, S> | AnyPath | undefined","allOptions: UseStoreOptionsWithSelector<T, S>","_listener: (value: any) => void","lastObservedValue: any","value","revoke: (() => void) | undefined","rootCache: Cache<any, any>","selector","selector: Selector<T, S> | AnyPath | undefined","updater: ((value: S) => Update<T>) | undefined","options: UseStoreOptions<S> | undefined","_store: Store<any>","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/react/lib/useMemoEquals.ts","../src/lib/trackingProxy.ts","../src/react/useStore.ts","../src/react/loadingBoundary.tsx","../src/react/useCache.ts","../src/react/cacheMethods.ts","../src/react/lib/useLatestRef.ts","../src/react/lib/useLatestFunction.ts","../src/react/useProp.ts","../src/react/scope.tsx","../src/react/scopeMethods.ts","../src/react/storeMethods.ts"],"sourcesContent":["import { deepEqual } from '@lib/equals';\nimport { useEffect, useRef } from 'react';\n\nexport default function useMemoEquals<T>(value: T, equals: (a: T, b: T) => boolean = deepEqual): T {\n const ref = useRef<{ value: T }>(undefined);\n const hasChanged = !ref.current || !equals(ref.current.value, value);\n\n useEffect(() => {\n if (hasChanged) {\n ref.current = { value };\n }\n });\n\n return hasChanged ? value : ref.current!.value;\n}\n","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, strictEqual } from '@lib/equals';\nimport { makeSelector } from '@lib/makeSelector';\nimport { isAnyPath, type AnyPath, type Path, type Value } from '@lib/path';\nimport { trackingProxy } from '@lib/trackingProxy';\nimport useMemoEquals from '@react/lib/useMemoEquals';\nimport {\n useCallback,\n useDebugValue,\n useLayoutEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\nexport interface UseStoreOptions<T> 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\n passive?: boolean;\n\n /**\n * (experimental) If true, the a rerender will only be triggered when a property of the returned value changes that was\n * actually accessed during the last render.\n * @default false\n */\n enableTrackingProxy?: boolean;\n\n /**\n * (experimental) If provided, a rerender will be wrapped in a browser view transition.\n */\n withViewTransition?: boolean | ((value: T) => unknown);\n}\n\nexport interface UseStoreOptionsWithSelector<T, S> extends UseStoreOptions<S> {\n /**\n * Equality function to compare the raw store values before reevaluating the selector.\n * Can be used to avoid unnecessary selector evaluations.\n * @default strictEqual\n */\n storeValueEquals?: (newValue: T, oldValue: T) => boolean;\n}\n\nexport function useStore<T, S>(\n store: Store<T>,\n selector: Selector<T, S>,\n option?: UseStoreOptionsWithSelector<T, S>,\n): S;\n\nexport function useStore<T, const P>(\n store: Store<T>,\n selector: Constrain<P, Path<T>>,\n option?: UseStoreOptionsWithSelector<T, 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>(\n store: Store<T>,\n ...args:\n | [Selector<T, S> | AnyPath, UseStoreOptionsWithSelector<T, S>?]\n | [UseStoreOptionsWithSelector<T, S>?]\n): S {\n let selectorRaw: Selector<T, S> | AnyPath | undefined;\n let allOptions: UseStoreOptionsWithSelector<T, S>;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selectorRaw = args[0];\n allOptions = args[1] ?? {};\n } else {\n allOptions = args[0] ?? {};\n }\n\n const selectorMemoized = useMemoEquals(selectorRaw);\n const selector = useMemo(() => makeSelector<T, S>(selectorMemoized), [selectorMemoized]);\n const lastEqualsRef = useRef<(newValue: S) => boolean | undefined>(undefined);\n\n const {\n enableTrackingProxy,\n equals = store.options.equals ?? deepEqual,\n withViewTransition,\n storeValueEquals = strictEqual,\n ...options\n } = allOptions;\n\n const snapshot = useRef<{ storeValue: T; selector: (value: T) => S; selectedValue: S }>(\n undefined,\n );\n\n const get = useCallback(() => {\n const storeValue = store.get();\n\n if (\n snapshot.current &&\n storeValueEquals(storeValue, snapshot.current.storeValue) &&\n selector === snapshot.current.selector\n ) {\n return snapshot.current.selectedValue;\n }\n\n const selectedValue = selector(storeValue);\n if (!(lastEqualsRef.current?.(selectedValue) ?? false)) {\n snapshot.current = { storeValue, selector, selectedValue };\n }\n\n return snapshot.current!.selectedValue;\n }, [store, storeValueEquals, selector]);\n\n const rootStore = store.derivedFrom?.store ?? store;\n const subOptions = useMemoEquals({ ...options, runNow: false });\n\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 = rootStore.subscribe(_listener, subOptions);\n return () => {\n stopped = true;\n cancel();\n };\n },\n [rootStore, withViewTransition, equals, subOptions],\n );\n\n let value = useSyncExternalStore<S>(subscribe, get, get);\n let lastEquals = (newValue: S) => equals(newValue, value);\n let revoke: (() => void) | undefined;\n\n if (enableTrackingProxy) {\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 // oxlint-disable-next-line exhaustive-deps\n }, [store, isLoading]);\n}\n","import type { Cache } from '@core';\nimport type { CacheState } from '@lib/cacheState';\nimport { makeSelector } from '@lib/makeSelector';\nimport useMemoEquals from '@react/lib/useMemoEquals';\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 // oxlint-disable-next-line exhaustive-deps\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 // Memoize value and error to keep their identity stable\n result[0] = useMemoEquals(result[0]);\n result.value = result[0];\n result[1] = useMemoEquals(result[1]);\n result.error = result[1];\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 { useRef } from 'react';\n\nexport default function useLatestRef<T>(value: T): { current: T } {\n const ref = useRef(value);\n ref.current = value;\n return ref;\n}\n","import useLatestRef from '@react/lib/useLatestRef';\nimport { useCallback } from 'react';\n\nexport default function useLatestFunction<Args extends any[], R>(\n fn: (...args: Args) => R,\n): (...args: Args) => R {\n const ref = useLatestRef(fn);\n\n return useCallback(\n (...args: Args) => {\n return ref.current(...args);\n },\n [ref],\n );\n}\n","import { type Selector, type Update } from '@core/commonTypes';\nimport type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { isAnyPath, type AnyPath, type SettablePath, type Value } from '@lib/path';\nimport useLatestFunction from '@react/lib/useLatestFunction';\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, SettablePath<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 ...args:\n | [Selector<T, S>, (value: S) => Update<T>, UseStoreOptions<S>?]\n | [AnyPath, UseStoreOptions<Value<T, any>>?]\n | [UseStoreOptions<S>?]\n): [value: S, setValue: Store<S>['set']] {\n let selector: Selector<T, S> | AnyPath | undefined;\n let updater: ((value: S) => Update<T>) | undefined;\n let options: UseStoreOptions<S> | undefined;\n\n if (typeof args[0] === 'function' || isAnyPath(args[0])) {\n selector = args[0];\n if (typeof args[1] === 'function') {\n updater = args[1];\n options = args[2];\n } else {\n options = args[1];\n }\n } else {\n options = args[0];\n }\n\n const value = useStore(store, (selector ?? ((x) => x)) as Selector<T, S>, options);\n\n const update = useLatestFunction((update) => {\n let _store: Store<any> = store;\n if (selector) {\n _store = _store.map(selector as Selector<any, any>, updater);\n }\n\n _store.set(update);\n });\n\n return [value, update];\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 '..' {\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,SAAwB,cAAiB,OAAU,SAAkC,WAAc;CACjG,MAAM,MAAM,OAAqB,OAAU;CAC3C,MAAM,aAAa,CAAC,IAAI,WAAW,CAAC,OAAO,IAAI,QAAQ,OAAO,MAAM;AAEpE,iBAAgB;AACd,MAAI,WACF,KAAI,UAAU,EAAE,OAAO;GAEzB;AAEF,QAAO,aAAa,QAAQ,IAAI,QAAS;;;;;ACV3C,MAAM,oBAAoC,uBAAO,cAAc;AAK/D,SAAgB,cACd,OACA,SAAsC,WACpB;AAClB,KAAI,CAAC,cAAc,MAAM,IAAI,CAAC,MAAM,QAAQ,MAAM,CAChD,QAAO,CAAC,QAAQ,UAAU,OAAO,OAAO,MAAM,CAAC;AAIjD,SAAS,MAAc,sBAAsB;CAE7C,MAAM,O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