cross-state 0.43.3 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/cjs/hash.cjs.map +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs/index2.cjs +3 -3
  4. package/dist/cjs/index2.cjs.map +1 -1
  5. package/dist/cjs/mutative/register.cjs.map +1 -1
  6. package/dist/cjs/mutativeMethods.cjs.map +1 -1
  7. package/dist/cjs/patches/register.cjs.map +1 -1
  8. package/dist/cjs/persist/register.cjs.map +1 -1
  9. package/dist/cjs/persist.cjs +7 -7
  10. package/dist/cjs/persist.cjs.map +1 -1
  11. package/dist/cjs/propAccess.cjs +4 -4
  12. package/dist/cjs/propAccess.cjs.map +1 -1
  13. package/dist/cjs/react/index.cjs +16 -16
  14. package/dist/cjs/react/index.cjs.map +1 -1
  15. package/dist/cjs/react/register.cjs.map +1 -1
  16. package/dist/cjs/scope.cjs +8 -8
  17. package/dist/cjs/scope.cjs.map +1 -1
  18. package/dist/cjs/store.cjs +36 -36
  19. package/dist/cjs/store.cjs.map +1 -1
  20. package/dist/cjs/storeMethods.cjs +25 -17
  21. package/dist/cjs/storeMethods.cjs.map +1 -1
  22. package/dist/cjs/urlStore.cjs +6 -6
  23. package/dist/cjs/urlStore.cjs.map +1 -1
  24. package/dist/es/hash.mjs.map +1 -1
  25. package/dist/es/index.mjs.map +1 -1
  26. package/dist/es/index2.mjs +3 -3
  27. package/dist/es/index2.mjs.map +1 -1
  28. package/dist/es/mutative/register.mjs.map +1 -1
  29. package/dist/es/mutativeMethods.mjs.map +1 -1
  30. package/dist/es/patches/register.mjs.map +1 -1
  31. package/dist/es/persist/register.mjs.map +1 -1
  32. package/dist/es/persist.mjs +7 -7
  33. package/dist/es/persist.mjs.map +1 -1
  34. package/dist/es/propAccess.mjs +4 -4
  35. package/dist/es/propAccess.mjs.map +1 -1
  36. package/dist/es/react/index.mjs +16 -16
  37. package/dist/es/react/index.mjs.map +1 -1
  38. package/dist/es/react/register.mjs.map +1 -1
  39. package/dist/es/scope.mjs +9 -9
  40. package/dist/es/scope.mjs.map +1 -1
  41. package/dist/es/store.mjs +36 -36
  42. package/dist/es/store.mjs.map +1 -1
  43. package/dist/es/storeMethods.mjs +27 -19
  44. package/dist/es/storeMethods.mjs.map +1 -1
  45. package/dist/es/urlStore.mjs +6 -6
  46. package/dist/es/urlStore.mjs.map +1 -1
  47. package/dist/types/core/cache.d.ts +5 -4
  48. package/dist/types/core/store.d.ts +6 -5
  49. package/dist/types/lib/constrain.d.ts +1 -0
  50. package/dist/types/lib/makeSelector.d.ts +2 -2
  51. package/dist/types/lib/path.d.ts +1 -0
  52. package/dist/types/lib/propAccess.d.ts +4 -3
  53. package/dist/types/mutative/mutativeMethods.d.ts +2 -1
  54. package/dist/types/react/form/form.d.ts +8 -8
  55. package/dist/types/react/form/formField.d.ts +8 -11
  56. package/dist/types/react/form/formForEach.d.ts +4 -5
  57. package/dist/types/react/scope.d.ts +3 -2
  58. package/dist/types/react/scopeMethods.d.ts +3 -2
  59. package/dist/types/react/storeMethods.d.ts +3 -2
  60. package/dist/types/react/useProp.d.ts +2 -1
  61. package/dist/types/react/useStore.d.ts +2 -1
  62. package/package.json +12 -12
@@ -1,5 +1,4 @@
1
- import { type PathAsString } from '../../index';
2
- import { type Value } from '../../lib/path';
1
+ import { type PathAsString, type Value } from '../../lib/path';
3
2
  import { type Component, type ComponentPropsWithoutRef, type ReactNode } from 'react';
4
3
  import { type Field, type Form, type FormInstance } from './form';
5
4
  export interface FormFieldComponentProps<TValue, TPath> {
@@ -12,7 +11,7 @@ export interface FormFieldComponentProps<TValue, TPath> {
12
11
  } | TValue | undefined, ...args: any[]) => void;
13
12
  onBlur: (...args: any[]) => void;
14
13
  }
15
- export type FormFieldInfos<TDraft, TOriginal, TPath extends PathAsString<TDraft>> = Field<TDraft, TOriginal, TPath> & {
14
+ export type FormFieldInfos<TDraft, TOriginal, TPath extends string> = Field<TDraft, TOriginal, TPath> & {
16
15
  hasTriggeredValidations: boolean;
17
16
  };
18
17
  type NativeInputType = 'input' | 'select' | 'textarea';
@@ -27,14 +26,12 @@ type FieldChangeValue<T extends FormFieldComponent> = ComponentPropsWithoutRef<T
27
26
  };
28
27
  } ? V : U : never;
29
28
  type MakeOptional<T, Keys extends string> = Omit<T, Keys> & Partial<Pick<T, Keys & keyof T>>;
30
- export type FormFieldProps<TPath> = {
31
- name?: TPath;
29
+ export type FormFieldProps<TPath, TDraft> = {
30
+ name: TPath & PathAsString<TDraft>;
32
31
  commitOnBlur?: boolean;
33
32
  commitDebounce?: number;
34
- } & (TPath extends '' ? {} : {
35
- name: TPath;
36
- });
37
- export type FormFieldPropsWithRender<TDraft, TOriginal, TPath extends PathAsString<TDraft>> = FormFieldProps<TPath> & NoInfer<{
33
+ };
34
+ export type FormFieldPropsWithRender<TDraft, TOriginal, TPath extends string> = FormFieldProps<TPath, TDraft> & NoInfer<{
38
35
  component?: undefined;
39
36
  render: (props: FormFieldComponentProps<Value<TDraft, TPath>, TPath>, info: FormFieldInfos<TDraft, TOriginal, TPath>) => ReactNode;
40
37
  inputFilter?: undefined;
@@ -46,7 +43,7 @@ export type FormFieldPropsWithRender<TDraft, TOriginal, TPath extends PathAsStri
46
43
  }>;
47
44
  type Serialize<TDraft, TOriginal, TPath, TComponent extends FormFieldComponent> = (value: Value<TDraft, TPath>, formState: FormInstance<TDraft, TOriginal>) => FieldValue<TComponent>;
48
45
  type Deserialize<TDraft, TOriginal, TPath, TComponent extends FormFieldComponent> = (value: FieldChangeValue<TComponent>, formState: FormInstance<TDraft, TOriginal>) => Value<TDraft, TPath>;
49
- export type FormFieldPropsWithComponent<TDraft, TOriginal, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent> = FormFieldProps<TPath> & {
46
+ export type FormFieldPropsWithComponent<TDraft, TOriginal, TPath extends string, TComponent extends FormFieldComponent> = FormFieldProps<TPath, TDraft> & {
50
47
  component?: TComponent;
51
48
  render?: undefined;
52
49
  } & NoInfer<{
@@ -67,5 +64,5 @@ export type FormFieldPropsWithComponent<TDraft, TOriginal, TPath extends PathAsS
67
64
  } : {
68
65
  deserialize: Deserialize<TDraft, TOriginal, TPath, TComponent>;
69
66
  })>;
70
- export declare function FormField<TDraft, TOriginal, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent>(this: Form<TDraft, any>, { name, component, commitOnBlur, commitDebounce, render, inputFilter, defaultValue, serialize, deserialize, onChange, onBlur, ...restProps }: FormFieldPropsWithRender<TDraft, TOriginal, TPath> | FormFieldPropsWithComponent<TDraft, TOriginal, TPath, TComponent>): JSX.Element | null;
67
+ export declare function FormField<TDraft, TOriginal, TPath extends string, TComponent extends FormFieldComponent>(this: Form<TDraft, any>, { name, component, commitOnBlur, commitDebounce, render, inputFilter, defaultValue, serialize, deserialize, onChange, onBlur, ...restProps }: FormFieldPropsWithRender<TDraft, TOriginal, TPath> | FormFieldPropsWithComponent<TDraft, TOriginal, TPath, TComponent>): JSX.Element | null;
71
68
  export {};
@@ -1,10 +1,9 @@
1
1
  import { type GetKeys, type Join, type PathAsString, type Value } from '../../lib/path';
2
2
  import { type ReactNode } from 'react';
3
3
  import { type FieldHelperMethods, type Form } from './form';
4
- export type ForEachPath<T> = PathAsString<T>;
5
- export type ElementName<TDraft, TPath extends PathAsString<TDraft>> = Join<TPath, GetKeys<NonNullable<Value<TDraft, TPath>>> & (string | number)>;
6
- export interface FormForEachProps<TDraft, TPath extends ForEachPath<TDraft>> {
7
- name: TPath;
4
+ export type ElementName<TDraft, TPath extends string> = Join<TPath, GetKeys<NonNullable<Value<TDraft, TPath>>> & (string | number)>;
5
+ export interface FormForEachProps<TDraft, TPath extends string> {
6
+ name: TPath & PathAsString<TDraft>;
8
7
  renderElement?: (props: {
9
8
  name: ElementName<TDraft, TPath>;
10
9
  key: `${GetKeys<NonNullable<Value<TDraft, TPath>>> & (string | number)}`;
@@ -15,4 +14,4 @@ export interface FormForEachProps<TDraft, TPath extends ForEachPath<TDraft>> {
15
14
  setValue: (value: Value<TDraft, TPath> | ((value: Value<TDraft, TPath>) => Value<TDraft, TPath>)) => void;
16
15
  } & FieldHelperMethods<TDraft, TPath>) => ReactNode;
17
16
  }
18
- export declare function FormForEach<TDraft, TPath extends ForEachPath<TDraft>>(this: Form<TDraft, any>, { name, renderElement, children }: FormForEachProps<TDraft, TPath>): JSX.Element;
17
+ export declare function FormForEach<TDraft, TPath extends string>(this: Form<TDraft, any>, { name, renderElement, children }: FormForEachProps<TDraft, TPath>): JSX.Element;
@@ -1,5 +1,6 @@
1
1
  import type { Scope, Selector, Update } from '../core';
2
2
  import { type Store } from '../core/store';
3
+ import type { Constrain } from '../lib/constrain';
3
4
  import type { Path, Value } from '../lib/path';
4
5
  import { type Context, type ReactNode } from 'react';
5
6
  import { type UseStoreOptions } from './useStore';
@@ -16,8 +17,8 @@ declare module '../core' {
16
17
  export declare function ScopeProvider<T>({ scope, store: inputStore, children, }: ScopeProps<T>): JSX.Element;
17
18
  export declare function useScope<T>(scope: Scope<T>): Store<T>;
18
19
  export declare function useScopeStore<T, S>(scope: Scope<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
19
- export declare function useScopeStore<T, P extends Path<T>>(scope: Scope<T>, selector: P, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
20
+ export declare function useScopeStore<T, const P>(scope: Scope<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
20
21
  export declare function useScopeStore<T>(scope: Scope<T>, option?: UseStoreOptions<T>): T;
21
22
  export declare function useScopeProp<T, S>(scope: Scope<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>['set']];
22
- export declare function useScopeProp<T, P extends Path<T>>(scope: Scope<T>, selector: P, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
23
+ export declare function useScopeProp<T, const P>(scope: Scope<T>, selector: Constrain<P, Path<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
23
24
  export declare function useScopeProp<T>(scope: Scope<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>['set']];
@@ -1,13 +1,14 @@
1
1
  import type { Scope, Selector, Store, Update } from '../core';
2
+ import type { Constrain } from '../lib/constrain';
2
3
  import type { Path, Value } from '../lib/path';
3
4
  import { type ScopeProps } from '../react/scope';
4
5
  import type { UseStoreOptions } from '../react/useStore';
5
6
  declare function boundUseScope<T>(this: Scope<T>): Store<T>;
6
7
  declare function boundUseScopeStore<T, S>(this: Scope<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
7
- declare function boundUseScopeStore<T, P extends Path<T>>(this: Scope<T>, selector: P, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
8
+ declare function boundUseScopeStore<T, const P>(this: Scope<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
8
9
  declare function boundUseScopeStore<T>(this: Scope<T>, option?: UseStoreOptions<T>): T;
9
10
  declare function boundUseScopeProp<T, S>(this: Scope<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>['set']];
10
- declare function boundUseScopeProp<T, P extends Path<T>>(this: Scope<T>, selector: P, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
11
+ declare function boundUseScopeProp<T, const P>(this: Scope<T>, selector: Constrain<P, Path<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
11
12
  declare function boundUseScopeProp<T>(this: Scope<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>['set']];
12
13
  declare function Provider<T>(this: Scope<T>, props: Omit<ScopeProps<T>, 'scope'>): JSX.Element;
13
14
  export declare const scopeMethods: {
@@ -1,11 +1,12 @@
1
1
  import type { Selector, Store, Update } from '../core';
2
+ import type { Constrain } from '../lib/constrain';
2
3
  import type { Path, Value } from '../lib/path';
3
4
  import { type UseStoreOptions } from '../react/useStore';
4
5
  declare function boundUseStore<T, S>(this: Store<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
5
- declare function boundUseStore<T, P extends Path<T>>(this: Store<T>, selector: P, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
6
+ declare function boundUseStore<T, const P>(this: Store<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
6
7
  declare function boundUseStore<T>(this: Store<T>, option?: UseStoreOptions<T>): T;
7
8
  declare function boundUseProp<T, S>(this: Store<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>['set']];
8
- declare function boundUseProp<T, P extends Path<T>>(this: Store<T>, selector: P, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
9
+ declare function boundUseProp<T, const P>(this: Store<T>, selector: Constrain<P, Path<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
9
10
  declare function boundUseProp<T>(this: Store<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>['set']];
10
11
  export declare const storeMethods: {
11
12
  useStore: typeof boundUseStore;
@@ -1,7 +1,8 @@
1
1
  import { type Selector, type Update } from '../core/commonTypes';
2
2
  import type { Store } from '../core/store';
3
+ import type { Constrain } from '../lib/constrain';
3
4
  import { type Path, type Value } from '../lib/path';
4
5
  import { type UseStoreOptions } from './useStore';
5
6
  export declare function useProp<T, S>(store: Store<T>, selector: Selector<T, S>, updater: (value: S) => Update<T>, options?: UseStoreOptions<S>): [value: S, setValue: Store<S>['set']];
6
- export declare function useProp<T, P extends Path<T>>(store: Store<T>, selector: P, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
7
+ export declare function useProp<T, const P>(store: Store<T>, selector: Constrain<P, Path<T>>, options?: UseStoreOptions<Value<T, P>>): [value: Value<T, P>, setValue: Store<Value<T, P>>['set']];
7
8
  export declare function useProp<T>(store: Store<T>, options?: UseStoreOptions<T>): [value: T, setValue: Store<T>['set']];
@@ -1,5 +1,6 @@
1
1
  import type { Selector, SubscribeOptions } from '../core/commonTypes';
2
2
  import type { Store } from '../core/store';
3
+ import type { Constrain } from '../lib/constrain';
3
4
  import { type Path, type Value } from '../lib/path';
4
5
  export interface UseStoreOptions<S> extends Omit<SubscribeOptions, 'runNow' | 'passive'> {
5
6
  /**
@@ -11,5 +12,5 @@ export interface UseStoreOptions<S> extends Omit<SubscribeOptions, 'runNow' | 'p
11
12
  withViewTransition?: boolean | ((value: S) => unknown);
12
13
  }
13
14
  export declare function useStore<T, S>(store: Store<T>, selector: Selector<T, S>, option?: UseStoreOptions<S>): S;
14
- export declare function useStore<T, P extends Path<T>>(store: Store<T>, selector: P, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
15
+ export declare function useStore<T, const P>(store: Store<T>, selector: Constrain<P, Path<T>>, option?: UseStoreOptions<Value<T, P>>): Value<T, P>;
15
16
  export declare function useStore<T>(store: Store<T>, option?: UseStoreOptions<T>): T;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cross-state",
3
- "version": "0.43.3",
3
+ "version": "0.44.0",
4
4
  "description": "(React) state library",
5
5
  "license": "ISC",
6
6
  "repository": "schummar/cross-state",
@@ -131,8 +131,8 @@
131
131
  },
132
132
  "devDependencies": {
133
133
  "@emotion/styled": "11.13.0",
134
- "@mantine/core": "7.13.2",
135
- "@mantine/hooks": "^7.13.2",
134
+ "@mantine/core": "7.16.3",
135
+ "@mantine/hooks": "^7.16.3",
136
136
  "@mui/material": "6.1.2",
137
137
  "@schummar/eslint-config": "github:schummar/eslint-config",
138
138
  "@schummar/prettier-config": "github:schummar/prettier-config",
@@ -144,9 +144,9 @@
144
144
  "@types/seedrandom": "3.0.8",
145
145
  "@types/use-sync-external-store": "0.0.6",
146
146
  "@types/ws": "8.5.12",
147
- "@vitejs/plugin-react": "4.3.2",
148
- "@vitest/coverage-v8": "2.1.2",
149
- "@vitest/ui": "^2.1.2",
147
+ "@vitejs/plugin-react": "4.3.4",
148
+ "@vitest/coverage-v8": "3.0.5",
149
+ "@vitest/ui": "^3.0.5",
150
150
  "esbuild": "0.24.0",
151
151
  "eslint": "8.57.0",
152
152
  "happy-dom": "15.7.4",
@@ -161,15 +161,15 @@
161
161
  "semantic-release": "24.1.2",
162
162
  "size-limit": "11.1.6",
163
163
  "tsc-alias": "1.8.10",
164
- "typescript": "5.6.2",
164
+ "typescript": "5.7.3",
165
165
  "use-sync-external-store": "1.2.2",
166
- "vite": "5.4.8",
167
- "vite-tsconfig-paths": "5.0.1",
168
- "vitest": "2.1.2"
166
+ "vite": "6.1.0",
167
+ "vite-tsconfig-paths": "5.1.4",
168
+ "vitest": "3.0.5"
169
169
  },
170
170
  "volta": {
171
- "node": "20.15.0",
172
- "pnpm": "9.4.0"
171
+ "node": "22.13.1",
172
+ "pnpm": "10.2.1"
173
173
  },
174
174
  "eslintConfig": {
175
175
  "extends": [