cross-state 0.16.7 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +4 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/react/index.cjs +60 -4
- package/dist/cjs/react/index.cjs.map +1 -1
- package/dist/cjs/store.cjs +3 -7
- package/dist/cjs/store.cjs.map +1 -1
- package/dist/es/index.mjs +13 -13
- package/dist/es/index.mjs.map +1 -1
- package/dist/es/react/index.mjs +63 -7
- package/dist/es/react/index.mjs.map +1 -1
- package/dist/es/store.mjs +10 -14
- package/dist/es/store.mjs.map +1 -1
- package/dist/es/useCache.mjs +1 -1
- package/dist/types/core/commonTypes.d.ts +1 -1
- package/dist/types/core/subscriptionCache.d.ts +19 -8
- package/dist/types/lib/calculationHelper.d.ts +2 -2
- package/dist/types/react/form/form.d.ts +13 -3
- package/dist/types/react/form/formArray.d.ts +21 -0
- package/dist/types/react/form/formField.d.ts +5 -20
- package/package.json +21 -13
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type PathAsString, type Value } from '../../lib/path';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type Form } from './form';
|
|
4
|
+
export type ArrayPath<T> = keyof {
|
|
5
|
+
[P in PathAsString<T> as Value<T, P> extends readonly any[] | undefined ? P : never]: never;
|
|
6
|
+
} & PathAsString<T> & string;
|
|
7
|
+
export interface FormArrayProps<TDraft, TPath extends ArrayPath<TDraft>> {
|
|
8
|
+
name: TPath;
|
|
9
|
+
renderElement?: (props: {
|
|
10
|
+
name: `${TPath}.${number}`;
|
|
11
|
+
index: number;
|
|
12
|
+
remove: () => void;
|
|
13
|
+
}) => ReactNode;
|
|
14
|
+
children?: (props: {
|
|
15
|
+
names: `${TPath}.${number}`[];
|
|
16
|
+
append: (...elements: Value<TDraft, `${TPath}.${number}`>[]) => void;
|
|
17
|
+
remove: (index: number) => void;
|
|
18
|
+
setValue: (value: Value<TDraft, TPath> | ((value: Value<TDraft, TPath>) => Value<TDraft, TPath>)) => void;
|
|
19
|
+
}) => ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export declare function FormArray<TDraft, TPath extends ArrayPath<TDraft>>(this: Form<TDraft, any>, { name, renderElement, children }: FormArrayProps<TDraft, TPath>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -17,12 +17,8 @@ interface FormFieldComponentProps<TValue, TPath> {
|
|
|
17
17
|
type NativeInputType = 'input' | 'select' | 'textarea';
|
|
18
18
|
type PartialComponentType<P> = (new (props: P, context?: any) => Component<P, any>) | ((props: P, context?: any) => ReactNode);
|
|
19
19
|
export type FormFieldComponent<TValue, TPath> = (string | number extends TValue ? NativeInputType : never) | PartialComponentType<FormFieldComponentProps<TValue, TPath>>;
|
|
20
|
-
type FieldValue<T extends FormFieldComponent<any, any>> = ComponentPropsWithoutRef<T
|
|
21
|
-
|
|
22
|
-
} ? U : ComponentPropsWithoutRef<T & 'input'> extends {
|
|
23
|
-
value?: infer U;
|
|
24
|
-
} ? U | undefined : never;
|
|
25
|
-
type FieldChangeValue<T extends FormFieldComponent<any, any>> = ComponentPropsWithoutRef<T & 'input'> extends {
|
|
20
|
+
type FieldValue<T extends FormFieldComponent<any, any>> = ComponentPropsWithoutRef<T>['value'];
|
|
21
|
+
type FieldChangeValue<T extends FormFieldComponent<any, any>> = ComponentPropsWithoutRef<T> extends {
|
|
26
22
|
onChange?: (update: infer U) => void;
|
|
27
23
|
} ? U extends {
|
|
28
24
|
target: {
|
|
@@ -31,22 +27,11 @@ type FieldChangeValue<T extends FormFieldComponent<any, any>> = ComponentPropsWi
|
|
|
31
27
|
} ? V : U : never;
|
|
32
28
|
export type FormFieldProps<TDraft, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent<any, TPath>> = {
|
|
33
29
|
name: TPath;
|
|
30
|
+
component: TComponent;
|
|
34
31
|
commitOnBlur?: boolean;
|
|
35
32
|
commitDebounce?: number;
|
|
36
33
|
inputFilter?: (value: FieldChangeValue<TComponent>) => boolean;
|
|
37
|
-
|
|
38
|
-
onBlur?: ComponentPropsWithoutRef<TComponent>['onBlur'];
|
|
39
|
-
} & (TComponent extends 'input' | ((props: ComponentPropsWithoutRef<'input'> & {
|
|
40
|
-
name: TPath;
|
|
41
|
-
}) => JSX.Element) ? {
|
|
42
|
-
component?: TComponent;
|
|
43
|
-
} | {
|
|
44
|
-
children?: TComponent;
|
|
45
|
-
} : {
|
|
46
|
-
component: TComponent;
|
|
47
|
-
} | {
|
|
48
|
-
children: TComponent;
|
|
49
|
-
}) & Omit<ComponentPropsWithoutRef<TComponent>, 'form' | 'name' | 'component' | 'commitOnBlur' | 'commitDebounce' | 'value' | 'onChange' | 'onBlur' | 'children'> & (Value<TDraft, TPath> extends FieldValue<TComponent> ? {
|
|
34
|
+
} & Omit<ComponentPropsWithoutRef<TComponent>, 'name' | 'component' | 'commitOnBlur' | 'commitDebounce' | 'inputFilter' | keyof FormFieldComponentProps<any, any>> & Partial<Pick<ComponentPropsWithoutRef<TComponent>, keyof FormFieldComponentProps<any, any>>> & (Value<TDraft, TPath> extends FieldValue<TComponent> ? {
|
|
50
35
|
serialize?: (value: Value<TDraft, TPath>) => FieldValue<TComponent>;
|
|
51
36
|
} : {
|
|
52
37
|
serialize: (value: Value<TDraft, TPath>) => FieldValue<TComponent>;
|
|
@@ -55,5 +40,5 @@ export type FormFieldProps<TDraft, TPath extends PathAsString<TDraft>, TComponen
|
|
|
55
40
|
} : {
|
|
56
41
|
deserialize: (value: FieldChangeValue<TComponent>) => Value<TDraft, TPath>;
|
|
57
42
|
});
|
|
58
|
-
export declare function FormField<TDraft, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent<any, any>>(this: Form<TDraft, any>, { name, commitOnBlur, commitDebounce, inputFilter, serialize, deserialize, ...restProps }: FormFieldProps<TDraft, TPath, TComponent>): JSX.Element;
|
|
43
|
+
export declare function FormField<TDraft, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent<any, any>>(this: Form<TDraft, any>, { name, component, commitOnBlur, commitDebounce, inputFilter, serialize, deserialize, ...restProps }: FormFieldProps<TDraft, TPath, TComponent>): JSX.Element;
|
|
59
44
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-state",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "(React) state library",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "schummar/cross-state",
|
|
@@ -74,16 +74,16 @@
|
|
|
74
74
|
},
|
|
75
75
|
"scripts": {
|
|
76
76
|
"start": "tsc --watch",
|
|
77
|
-
"build": "runp -
|
|
77
|
+
"build": "runp -i build:clean :p build:compile:*",
|
|
78
78
|
"build:clean": "rimraf dist",
|
|
79
79
|
"build:compile:js": "vite build",
|
|
80
80
|
"build:compile:types": "tsc && tsc-alias",
|
|
81
|
-
"lint": "runp lint:*",
|
|
81
|
+
"lint": "runp -i lint:*",
|
|
82
82
|
"lint:eslint": "lint",
|
|
83
83
|
"lint:tsc": "tsc --noEmit --emitDeclarationOnly false",
|
|
84
84
|
"lint:tsc:tests": "tsc --noEmit --emitDeclarationOnly false -p test/tsconfig.json",
|
|
85
85
|
"size": "size-limit",
|
|
86
|
-
"prepublishOnly": "runp lint test build :p size publint",
|
|
86
|
+
"prepublishOnly": "runp -i lint test build :p size publint",
|
|
87
87
|
"test": "pnpm test:watch run --coverage",
|
|
88
88
|
"test:watch": "node --expose-gc node_modules/vitest/vitest.mjs",
|
|
89
89
|
"test:ui": "node --expose-gc node_modules/vitest/vitest.mjs --ui",
|
|
@@ -106,25 +106,27 @@
|
|
|
106
106
|
}
|
|
107
107
|
},
|
|
108
108
|
"devDependencies": {
|
|
109
|
+
"@emotion/styled": "11.11.0",
|
|
110
|
+
"@mantine/core": "6.0.19",
|
|
111
|
+
"@mui/material": "5.14.5",
|
|
109
112
|
"@schummar/eslint-config": "github:schummar/eslint-config",
|
|
110
113
|
"@schummar/prettier-config": "github:schummar/prettier-config",
|
|
111
|
-
"@schummar/runp": "1.
|
|
114
|
+
"@schummar/runp": "1.13.2",
|
|
112
115
|
"@size-limit/preset-small-lib": "8.2.6",
|
|
113
116
|
"@testing-library/react": "14.0.0",
|
|
114
|
-
"@types/react": "18.2.
|
|
117
|
+
"@types/react": "18.2.20",
|
|
115
118
|
"@types/react-dom": "18.2.7",
|
|
116
119
|
"@types/seedrandom": "3.0.5",
|
|
117
120
|
"@types/use-sync-external-store": "0.0.3",
|
|
118
121
|
"@types/ws": "8.5.5",
|
|
119
122
|
"@vitejs/plugin-react": "4.0.4",
|
|
120
|
-
"@vitest/coverage-v8": "0.34.
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"happy-dom": "10.9.0",
|
|
123
|
+
"@vitest/coverage-v8": "0.34.2",
|
|
124
|
+
"esbuild": "0.19.2",
|
|
125
|
+
"eslint": "8.47.0",
|
|
126
|
+
"happy-dom": "10.10.4",
|
|
125
127
|
"immer": "10.0.2",
|
|
126
128
|
"jsdom": "22.1.0",
|
|
127
|
-
"prettier": "3.0.
|
|
129
|
+
"prettier": "3.0.2",
|
|
128
130
|
"publint": "0.2.0",
|
|
129
131
|
"react": "18.2.0",
|
|
130
132
|
"react-dom": "18.2.0",
|
|
@@ -137,7 +139,7 @@
|
|
|
137
139
|
"use-sync-external-store": "1.2.0",
|
|
138
140
|
"vite": "4.4.9",
|
|
139
141
|
"vite-tsconfig-paths": "4.2.0",
|
|
140
|
-
"vitest": "0.34.
|
|
142
|
+
"vitest": "0.34.2"
|
|
141
143
|
},
|
|
142
144
|
"volta": {
|
|
143
145
|
"node": "18.16.1",
|
|
@@ -209,6 +211,12 @@
|
|
|
209
211
|
"name": "/immer",
|
|
210
212
|
"path": "dist/es/immer/index.mjs",
|
|
211
213
|
"limit": "250 B"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "empty",
|
|
217
|
+
"path": "dist/es/index.mjs",
|
|
218
|
+
"import": "{}",
|
|
219
|
+
"limit": "0"
|
|
212
220
|
}
|
|
213
221
|
]
|
|
214
222
|
}
|