cross-state 0.37.9 → 0.37.11
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/mutative/register.cjs +2 -3
- package/dist/cjs/mutative/register.cjs.map +1 -1
- package/dist/cjs/patches/register.cjs +1 -2
- package/dist/cjs/patches/register.cjs.map +1 -1
- package/dist/cjs/propAccess.cjs +6 -11
- package/dist/cjs/propAccess.cjs.map +1 -1
- package/dist/cjs/react/index.cjs +32 -16
- package/dist/cjs/react/index.cjs.map +1 -1
- package/dist/cjs/react/register.cjs +3 -4
- package/dist/cjs/react/register.cjs.map +1 -1
- package/dist/cjs/scope.cjs +13 -7
- package/dist/cjs/scope.cjs.map +1 -1
- package/dist/cjs/store.cjs +48 -5
- package/dist/cjs/store.cjs.map +1 -1
- package/dist/cjs/storeMethods.cjs.map +1 -1
- package/dist/es/index.mjs +5 -5
- package/dist/es/mutative/register.mjs +1 -2
- package/dist/es/mutative/register.mjs.map +1 -1
- package/dist/es/patches/register.mjs +1 -2
- package/dist/es/patches/register.mjs.map +1 -1
- package/dist/es/propAccess.mjs +6 -11
- package/dist/es/propAccess.mjs.map +1 -1
- package/dist/es/react/index.mjs +33 -17
- package/dist/es/react/index.mjs.map +1 -1
- package/dist/es/react/register.mjs +3 -4
- package/dist/es/react/register.mjs.map +1 -1
- package/dist/es/scope.mjs +14 -8
- package/dist/es/scope.mjs.map +1 -1
- package/dist/es/store.mjs +53 -10
- package/dist/es/store.mjs.map +1 -1
- package/dist/es/storeMethods.mjs.map +1 -1
- package/dist/types/core/store.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lib/path.d.ts +10 -0
- package/dist/types/lib/propAccess.d.ts +2 -2
- package/dist/types/react/form/form.d.ts +5 -5
- package/dist/types/react/form/formField.d.ts +20 -15
- package/package.json +2 -1
- package/dist/cjs/autobind.cjs +0 -41
- package/dist/cjs/autobind.cjs.map +0 -1
- package/dist/es/autobind.mjs +0 -42
- package/dist/es/autobind.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type PathAsString } from '../../index';
|
|
2
2
|
import { type Value } from '../../lib/path';
|
|
3
3
|
import { type Component, type ComponentPropsWithoutRef, type ReactNode } from 'react';
|
|
4
|
-
import { type Form } from './form';
|
|
4
|
+
import { type Form, type FormInstance } from './form';
|
|
5
5
|
export interface FormFieldComponentProps<TValue, TPath> {
|
|
6
6
|
name: TPath;
|
|
7
7
|
value: TValue;
|
|
@@ -24,12 +24,14 @@ type FieldChangeValue<T extends FormFieldComponent> = ComponentPropsWithoutRef<T
|
|
|
24
24
|
};
|
|
25
25
|
} ? V : U : never;
|
|
26
26
|
type MakeOptional<T, Keys extends string> = Omit<T, Keys> & Partial<Pick<T, Keys & keyof T>>;
|
|
27
|
-
export type FormFieldProps<
|
|
28
|
-
name
|
|
27
|
+
export type FormFieldProps<TPath> = {
|
|
28
|
+
name?: TPath;
|
|
29
29
|
commitOnBlur?: boolean;
|
|
30
30
|
commitDebounce?: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
31
|
+
} & (TPath extends '' ? {} : {
|
|
32
|
+
name: TPath;
|
|
33
|
+
});
|
|
34
|
+
export type FormFieldPropsWithRender<TDraft, TPath extends PathAsString<TDraft>> = FormFieldProps<TPath> & NoInfer<{
|
|
33
35
|
component?: undefined;
|
|
34
36
|
render: (props: FormFieldComponentProps<Value<TDraft, TPath>, TPath>) => ReactNode;
|
|
35
37
|
inputFilter?: undefined;
|
|
@@ -38,26 +40,29 @@ export type FormFieldPropsWithRender<TDraft, TPath extends PathAsString<TDraft>>
|
|
|
38
40
|
deserialize?: undefined;
|
|
39
41
|
onChange?: undefined;
|
|
40
42
|
onBlur?: undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
+
}>;
|
|
44
|
+
type Serialize<TDraft, TOriginal, TPath, TComponent extends FormFieldComponent> = (value: Value<TDraft, TPath>, formState: FormInstance<TDraft, TOriginal>) => FieldValue<TComponent>;
|
|
45
|
+
type Deserialize<TDraft, TOriginal, TPath, TComponent extends FormFieldComponent> = (value: FieldChangeValue<TComponent>, formState: FormInstance<TDraft, TOriginal>) => Value<TDraft, TPath>;
|
|
46
|
+
export type FormFieldPropsWithComponent<TDraft, TOriginal, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent> = FormFieldProps<TPath> & {
|
|
43
47
|
component?: TComponent;
|
|
44
48
|
render?: undefined;
|
|
49
|
+
} & NoInfer<{
|
|
45
50
|
inputFilter?: (value: FieldChangeValue<TComponent>) => boolean;
|
|
46
51
|
} & MakeOptional<Omit<ComponentPropsWithoutRef<TComponent>, 'id' | 'name' | 'value' | 'defaultValue'>, 'onChange' | 'onBlur'> & (Value<TDraft, TPath> extends Exclude<FieldValue<TComponent>, undefined> ? {
|
|
47
52
|
defaultValue?: FieldValue<TComponent>;
|
|
48
|
-
serialize?:
|
|
53
|
+
serialize?: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
49
54
|
} : Value<TDraft, TPath> extends FieldValue<TComponent> ? {
|
|
50
55
|
defaultValue: FieldValue<TComponent>;
|
|
51
|
-
serialize?:
|
|
56
|
+
serialize?: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
52
57
|
} | {
|
|
53
58
|
defaultValue?: FieldValue<TComponent>;
|
|
54
|
-
serialize:
|
|
59
|
+
serialize: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
55
60
|
} : {
|
|
56
|
-
serialize:
|
|
61
|
+
serialize: Serialize<TDraft, TOriginal, TPath, TComponent>;
|
|
57
62
|
}) & (FieldChangeValue<TComponent> extends Value<TDraft, TPath> ? {
|
|
58
|
-
deserialize?:
|
|
63
|
+
deserialize?: Deserialize<TDraft, TOriginal, TPath, TComponent>;
|
|
59
64
|
} : {
|
|
60
|
-
deserialize:
|
|
61
|
-
})
|
|
62
|
-
export declare function FormField<TDraft, TPath extends PathAsString<TDraft>, TComponent extends FormFieldComponent>(this: Form<TDraft, any>, { name, component, commitOnBlur, commitDebounce, render, inputFilter, defaultValue, serialize, deserialize, ...restProps }: FormFieldPropsWithRender<TDraft, TPath> | FormFieldPropsWithComponent<TDraft, TPath, TComponent>): JSX.Element | null;
|
|
65
|
+
deserialize: Deserialize<TDraft, TOriginal, TPath, TComponent>;
|
|
66
|
+
})>;
|
|
67
|
+
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, TPath> | FormFieldPropsWithComponent<TDraft, TOriginal, TPath, TComponent>): JSX.Element | null;
|
|
63
68
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-state",
|
|
3
|
-
"version": "0.37.
|
|
3
|
+
"version": "0.37.11",
|
|
4
4
|
"description": "(React) state library",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"repository": "schummar/cross-state",
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"build:compile:js": "vite build",
|
|
100
100
|
"build:compile:types": "tsc && tsc-alias",
|
|
101
101
|
"lint": "runp -i lint:*",
|
|
102
|
+
"lint:prettier": "prettier -l src",
|
|
102
103
|
"lint:eslint": "lint",
|
|
103
104
|
"lint:tsc": "tsc --noEmit --emitDeclarationOnly false",
|
|
104
105
|
"lint:tsc:tests": "tsc --noEmit --emitDeclarationOnly false -p test/tsconfig.json",
|
package/dist/cjs/autobind.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const marker = Symbol("autobind");
|
|
3
|
-
const autobind = (_class) => {
|
|
4
|
-
var _a;
|
|
5
|
-
for (const key of Reflect.ownKeys(_class.prototype)) {
|
|
6
|
-
if (key === "constructor") {
|
|
7
|
-
continue;
|
|
8
|
-
}
|
|
9
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);
|
|
10
|
-
let method = ((_a = descriptor == null ? void 0 : descriptor.get) == null ? void 0 : _a.call(descriptor)) ?? (descriptor == null ? void 0 : descriptor.value);
|
|
11
|
-
let isBinding = false;
|
|
12
|
-
if (typeof method !== "function" || method[marker]) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
Reflect.defineProperty(_class.prototype, key, {
|
|
16
|
-
configurable: true,
|
|
17
|
-
get() {
|
|
18
|
-
if (isBinding || this === _class.prototype || Object.prototype.hasOwnProperty.call(this, key) || typeof method !== "function") {
|
|
19
|
-
return method;
|
|
20
|
-
}
|
|
21
|
-
const boundMethod = (...args) => Reflect.apply(method, this, args);
|
|
22
|
-
boundMethod[marker] = true;
|
|
23
|
-
isBinding = true;
|
|
24
|
-
Object.defineProperty(this, key, {
|
|
25
|
-
configurable: true,
|
|
26
|
-
get() {
|
|
27
|
-
return boundMethod;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
isBinding = false;
|
|
31
|
-
return boundMethod;
|
|
32
|
-
},
|
|
33
|
-
set(v) {
|
|
34
|
-
method = v;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
return _class;
|
|
39
|
-
};
|
|
40
|
-
exports.autobind = autobind;
|
|
41
|
-
//# sourceMappingURL=autobind.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"autobind.cjs","sources":["../../src/lib/autobind.ts"],"sourcesContent":["const marker = Symbol('autobind');\n\nexport const autobind = <\n TClass extends abstract new (...args: any) => any = abstract new (...args: any) => any,\n>(\n _class: TClass,\n): TClass => {\n for (const key of Reflect.ownKeys(_class.prototype)) {\n if (key === 'constructor') {\n continue;\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);\n let method = descriptor?.get?.() ?? descriptor?.value;\n let isBinding = false;\n\n if (typeof method !== 'function' || method[marker]) {\n continue;\n }\n\n Reflect.defineProperty(_class.prototype, key, {\n configurable: true,\n get() {\n if (\n isBinding ||\n this === _class.prototype ||\n Object.prototype.hasOwnProperty.call(this, key) ||\n typeof method !== 'function'\n ) {\n return method;\n }\n\n const boundMethod = (...args: any[]) => Reflect.apply(method, this, args);\n boundMethod[marker] = true;\n isBinding = true;\n\n Object.defineProperty(this, key, {\n configurable: true,\n get() {\n return boundMethod;\n },\n });\n\n isBinding = false;\n return boundMethod;\n },\n set(v) {\n method = v;\n },\n });\n }\n\n return _class;\n};\n"],"names":[],"mappings":";AAAA,MAAM,SAAS,OAAO,UAAU;AAEnB,MAAA,WAAW,CAGtB,WACW;;AACX,aAAW,OAAO,QAAQ,QAAQ,OAAO,SAAS,GAAG;AACnD,QAAI,QAAQ,eAAe;AACzB;AAAA,IACF;AAEA,UAAM,aAAa,QAAQ,yBAAyB,OAAO,WAAW,GAAG;AACzE,QAAI,WAAS,8CAAY,QAAZ,yCAAuB,yCAAY;AAChD,QAAI,YAAY;AAEhB,QAAI,OAAO,WAAW,cAAc,OAAO,MAAM,GAAG;AAClD;AAAA,IACF;AAEQ,YAAA,eAAe,OAAO,WAAW,KAAK;AAAA,MAC5C,cAAc;AAAA,MACd,MAAM;AACJ,YACE,aACA,SAAS,OAAO,aAChB,OAAO,UAAU,eAAe,KAAK,MAAM,GAAG,KAC9C,OAAO,WAAW,YAClB;AACO,iBAAA;AAAA,QACT;AAEA,cAAM,cAAc,IAAI,SAAgB,QAAQ,MAAM,QAAQ,MAAM,IAAI;AACxE,oBAAY,MAAM,IAAI;AACV,oBAAA;AAEL,eAAA,eAAe,MAAM,KAAK;AAAA,UAC/B,cAAc;AAAA,UACd,MAAM;AACG,mBAAA;AAAA,UACT;AAAA,QAAA,CACD;AAEW,oBAAA;AACL,eAAA;AAAA,MACT;AAAA,MACA,IAAI,GAAG;AACI,iBAAA;AAAA,MACX;AAAA,IAAA,CACD;AAAA,EACH;AAEO,SAAA;AACT;;"}
|
package/dist/es/autobind.mjs
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
const marker = Symbol("autobind");
|
|
2
|
-
const autobind = (_class) => {
|
|
3
|
-
var _a;
|
|
4
|
-
for (const key of Reflect.ownKeys(_class.prototype)) {
|
|
5
|
-
if (key === "constructor") {
|
|
6
|
-
continue;
|
|
7
|
-
}
|
|
8
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);
|
|
9
|
-
let method = ((_a = descriptor == null ? void 0 : descriptor.get) == null ? void 0 : _a.call(descriptor)) ?? (descriptor == null ? void 0 : descriptor.value);
|
|
10
|
-
let isBinding = false;
|
|
11
|
-
if (typeof method !== "function" || method[marker]) {
|
|
12
|
-
continue;
|
|
13
|
-
}
|
|
14
|
-
Reflect.defineProperty(_class.prototype, key, {
|
|
15
|
-
configurable: true,
|
|
16
|
-
get() {
|
|
17
|
-
if (isBinding || this === _class.prototype || Object.prototype.hasOwnProperty.call(this, key) || typeof method !== "function") {
|
|
18
|
-
return method;
|
|
19
|
-
}
|
|
20
|
-
const boundMethod = (...args) => Reflect.apply(method, this, args);
|
|
21
|
-
boundMethod[marker] = true;
|
|
22
|
-
isBinding = true;
|
|
23
|
-
Object.defineProperty(this, key, {
|
|
24
|
-
configurable: true,
|
|
25
|
-
get() {
|
|
26
|
-
return boundMethod;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
isBinding = false;
|
|
30
|
-
return boundMethod;
|
|
31
|
-
},
|
|
32
|
-
set(v) {
|
|
33
|
-
method = v;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
return _class;
|
|
38
|
-
};
|
|
39
|
-
export {
|
|
40
|
-
autobind as a
|
|
41
|
-
};
|
|
42
|
-
//# sourceMappingURL=autobind.mjs.map
|
package/dist/es/autobind.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"autobind.mjs","sources":["../../src/lib/autobind.ts"],"sourcesContent":["const marker = Symbol('autobind');\n\nexport const autobind = <\n TClass extends abstract new (...args: any) => any = abstract new (...args: any) => any,\n>(\n _class: TClass,\n): TClass => {\n for (const key of Reflect.ownKeys(_class.prototype)) {\n if (key === 'constructor') {\n continue;\n }\n\n const descriptor = Reflect.getOwnPropertyDescriptor(_class.prototype, key);\n let method = descriptor?.get?.() ?? descriptor?.value;\n let isBinding = false;\n\n if (typeof method !== 'function' || method[marker]) {\n continue;\n }\n\n Reflect.defineProperty(_class.prototype, key, {\n configurable: true,\n get() {\n if (\n isBinding ||\n this === _class.prototype ||\n Object.prototype.hasOwnProperty.call(this, key) ||\n typeof method !== 'function'\n ) {\n return method;\n }\n\n const boundMethod = (...args: any[]) => Reflect.apply(method, this, args);\n boundMethod[marker] = true;\n isBinding = true;\n\n Object.defineProperty(this, key, {\n configurable: true,\n get() {\n return boundMethod;\n },\n });\n\n isBinding = false;\n return boundMethod;\n },\n set(v) {\n method = v;\n },\n });\n }\n\n return _class;\n};\n"],"names":[],"mappings":"AAAA,MAAM,SAAS,OAAO,UAAU;AAEnB,MAAA,WAAW,CAGtB,WACW;AANb;AAOE,aAAW,OAAO,QAAQ,QAAQ,OAAO,SAAS,GAAG;AACnD,QAAI,QAAQ,eAAe;AACzB;AAAA,IACF;AAEA,UAAM,aAAa,QAAQ,yBAAyB,OAAO,WAAW,GAAG;AACzE,QAAI,WAAS,8CAAY,QAAZ,yCAAuB,yCAAY;AAChD,QAAI,YAAY;AAEhB,QAAI,OAAO,WAAW,cAAc,OAAO,MAAM,GAAG;AAClD;AAAA,IACF;AAEQ,YAAA,eAAe,OAAO,WAAW,KAAK;AAAA,MAC5C,cAAc;AAAA,MACd,MAAM;AACJ,YACE,aACA,SAAS,OAAO,aAChB,OAAO,UAAU,eAAe,KAAK,MAAM,GAAG,KAC9C,OAAO,WAAW,YAClB;AACO,iBAAA;AAAA,QACT;AAEA,cAAM,cAAc,IAAI,SAAgB,QAAQ,MAAM,QAAQ,MAAM,IAAI;AACxE,oBAAY,MAAM,IAAI;AACV,oBAAA;AAEL,eAAA,eAAe,MAAM,KAAK;AAAA,UAC/B,cAAc;AAAA,UACd,MAAM;AACG,mBAAA;AAAA,UACT;AAAA,QAAA,CACD;AAEW,oBAAA;AACL,eAAA;AAAA,MACT;AAAA,MACA,IAAI,GAAG;AACI,iBAAA;AAAA,MACX;AAAA,IAAA,CACD;AAAA,EACH;AAEO,SAAA;AACT;"}
|