relay-forms-nodeps 1.0.0 → 1.1.1
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/README.md +23 -108
- package/lib/RelayFormsTypes.d.ts +1 -0
- package/lib/Utils.d.ts +5 -8
- package/lib/Utils.js +10 -65
- package/lib/es/RelayFormsTypes.d.ts +1 -0
- package/lib/es/Utils.d.ts +5 -8
- package/lib/es/Utils.js +10 -67
- package/lib/es/relay/RelayRecordProxy.d.ts +1 -0
- package/lib/es/relay/RelayRecordProxy.js +3 -0
- package/lib/es/relay/RelayRecordSourceMutator.d.ts +1 -0
- package/lib/es/relay/RelayRecordSourceMutator.js +13 -0
- package/lib/es/relay/RelayTypes.d.ts +1 -0
- package/lib/es/relay/queries.d.ts +6 -4
- package/lib/es/relay/queries.js +6 -3
- package/lib/es/useFormSetValue.d.ts +5 -1
- package/lib/es/useFormSetValue.js +162 -64
- package/lib/es/useFormState.d.ts +12 -2
- package/lib/es/useFormState.js +10 -40
- package/lib/es/useFormSubmit.js +104 -89
- package/lib/es/useFormValue.js +1 -1
- package/lib/relay/RelayRecordProxy.d.ts +1 -0
- package/lib/relay/RelayRecordProxy.js +3 -0
- package/lib/relay/RelayRecordSourceMutator.d.ts +1 -0
- package/lib/relay/RelayRecordSourceMutator.js +13 -0
- package/lib/relay/RelayTypes.d.ts +1 -0
- package/lib/relay/queries.d.ts +6 -4
- package/lib/relay/queries.js +6 -3
- package/lib/umd/relay-forms-nodeps.js +319 -273
- package/lib/umd/relay-forms-nodeps.js.map +1 -1
- package/lib/umd/relay-forms-nodeps.min.js +1 -1
- package/lib/umd/relay-forms-nodeps.min.js.map +1 -1
- package/lib/useFormSetValue.d.ts +5 -1
- package/lib/useFormSetValue.js +162 -63
- package/lib/useFormState.d.ts +12 -2
- package/lib/useFormState.js +10 -40
- package/lib/useFormSubmit.js +103 -88
- package/lib/useFormValue.js +1 -1
- package/package.json +15 -2
- package/yarn-error.log +31 -31
package/README.md
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
Build forms in React with Relay
|
|
1
|
+
## Build forms in React with Relay
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
This repository manages the three libraries to manage forms by exploiting the potential and stability of the relay store.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
* [react-relay-forms](./docs/ReactRelayForms-Introduction.md): it has the official [react-relay](https://github.com/facebook/relay) dependency [](https://www.npmjs.com/package/react-relay-forms) [](https://www.npmjs.com/package/react-relay-forms) 
|
|
6
|
+
* [relay-forms](./docs/RelayForms-Introduction.md): depends on [relay-hooks](https://github.com/relay-tools/relay-hooks), my OSS version of relay hooks [](https://www.npmjs.com/package/relay-forms) [](https://www.npmjs.com/package/relay-forms) 
|
|
7
|
+
* [relay-forms-nodeps](./docs/RelayFormsNoDeps-Introduction.md): it has no dependencies, I only brought the relay functions needed to manage the store into the library, doing a careful cleaning to optimize the bundle size [](https://www.npmjs.com/package/relay-forms-nodeps) [](https://www.npmjs.com/package/relay-forms-nodeps) 
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
yarn add relay-forms-nodeps
|
|
10
|
-
```
|
|
9
|
+
[See full documentation here](https://morrys.github.io/relay-forms/docs/relay-forms.html)
|
|
11
10
|
|
|
12
11
|
## Contributing
|
|
13
12
|
|
|
@@ -21,104 +20,20 @@ yarn add relay-forms-nodeps
|
|
|
21
20
|
|
|
22
21
|
## Simple Example
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export const HAVE_ERRORS = 'have errors';
|
|
44
|
-
|
|
45
|
-
export const Errors: React.FC<any> = () => {
|
|
46
|
-
const { errors, isSubmitting, isValidating } = useFormState();
|
|
47
|
-
return (
|
|
48
|
-
<>
|
|
49
|
-
<div>{errors ? HAVE_ERRORS : ''}</div>;
|
|
50
|
-
<div>{'' + isSubmitting}</div>;
|
|
51
|
-
<div>{'' + isValidating}</div>;
|
|
52
|
-
</>
|
|
53
|
-
);
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const validateField = (value: any, name: string) => {
|
|
57
|
-
if (value && value.length < 5) {
|
|
58
|
-
return getFieldError(name, value);
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
export const FormInternal: React.FC<any> = ({ onSubmit }) => {
|
|
64
|
-
const data = useFormSubmit({ onSubmit });
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<form onSubmit={data.submit} action="#">
|
|
68
|
-
<div>
|
|
69
|
-
<Field fieldKey="firstName" placeholder="first name" validate={validateField} />
|
|
70
|
-
</div>
|
|
71
|
-
<div>
|
|
72
|
-
<Field fieldKey="lastName" placeholder="last name" />
|
|
73
|
-
</div>
|
|
74
|
-
<div>
|
|
75
|
-
<Field fieldKey="email" placeholder="email" validate={validateField} />
|
|
76
|
-
</div>
|
|
77
|
-
<Errors />
|
|
78
|
-
<button type="button" data-testid={'button-validate'} onClick={data.validate}>
|
|
79
|
-
only validate
|
|
80
|
-
</button>
|
|
81
|
-
<button data-testid={'button-submit'} type="submit">
|
|
82
|
-
submit
|
|
83
|
-
</button>
|
|
84
|
-
</form>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const getFieldError = (name, value) =>
|
|
89
|
-
name + ' wrong length, minimum 5 current ' + value.length;
|
|
90
|
-
|
|
91
|
-
export const Field: React.FC<any> = ({ placeholder, fieldKey, validate }) => {
|
|
92
|
-
const validateCallback = useCallback(
|
|
93
|
-
(value: any) => {
|
|
94
|
-
return validate(value, fieldKey);
|
|
95
|
-
},
|
|
96
|
-
[fieldKey, validate],
|
|
97
|
-
);
|
|
98
|
-
|
|
99
|
-
const [{ error }, setValue] = useFormSetValue({
|
|
100
|
-
key: fieldKey,
|
|
101
|
-
validate: validate ? validateCallback : undefined,
|
|
102
|
-
initialValue: "try",
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const setValueCallback = useCallback(
|
|
106
|
-
(event) => {
|
|
107
|
-
const value = event.target.value;
|
|
108
|
-
setValue(value);
|
|
109
|
-
},
|
|
110
|
-
[setValue],
|
|
111
|
-
);
|
|
112
|
-
return (
|
|
113
|
-
<>
|
|
114
|
-
{error && <div>{error}</div>}
|
|
115
|
-
<input
|
|
116
|
-
type="text"
|
|
117
|
-
value="try"
|
|
118
|
-
placeholder={placeholder}
|
|
119
|
-
onChange={(value) => setValueCallback(value)}
|
|
120
|
-
/>
|
|
121
|
-
</>
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
```
|
|
23
|
+
[See SimpleExample.md](./docs/RelaySimpleExample.md)
|
|
24
|
+
|
|
25
|
+
## useFormSetValue
|
|
26
|
+
|
|
27
|
+
[See useFormSetValue.md](./docs/useFormSetValue.md)
|
|
28
|
+
|
|
29
|
+
## useFormSubmit
|
|
30
|
+
|
|
31
|
+
[See useFormSubmit.md](./docs/useFormSubmit.md)
|
|
32
|
+
|
|
33
|
+
## useFormState
|
|
34
|
+
|
|
35
|
+
[See useFormState.md](./docs/useFormState.md)
|
|
36
|
+
|
|
37
|
+
## useFormValue
|
|
38
|
+
|
|
39
|
+
[See useFormValue.md](./docs/useFormValue.md)
|
package/lib/RelayFormsTypes.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare type FormSetValueOptions<ValueType> = {
|
|
|
13
13
|
initialValue?: ValueType;
|
|
14
14
|
validate?: (value: ValueType) => Promise<string | undefined> | string | undefined;
|
|
15
15
|
validateOnChange?: boolean;
|
|
16
|
+
label?: string;
|
|
16
17
|
};
|
|
17
18
|
export declare type FormSetValueStateReturn<ValueType> = {
|
|
18
19
|
error: undefined | null | Error;
|
package/lib/Utils.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RecordProxy, RecordSourceProxy, Snapshot, Store } from './relay/RelayTypes';
|
|
2
|
+
declare type FormStoreUpdater = (store: RecordSourceProxy, form: RecordProxy) => void;
|
|
3
|
+
export declare function getFieldId(key: any): string;
|
|
2
4
|
export declare function getSnapshot(environment: Store, fragment: any, key: string): Snapshot;
|
|
3
|
-
export declare
|
|
4
|
-
export declare const commitValidateIntoRelay: (entries: any, isSubmitting: any, environment: any) => void;
|
|
5
|
-
export declare const commitSubmitEndRelay: (environment: any) => void;
|
|
6
|
-
export declare const commitValidateEndRelay: (environment: any) => void;
|
|
7
|
-
export declare const commitResetField: (environment: any, key: any) => void;
|
|
8
|
-
export declare const commitValue: (key: any, value: any, check: any, environment: any) => void;
|
|
9
|
-
export declare const commitErrorIntoRelay: (key: any, error: any, environment: any) => void;
|
|
5
|
+
export declare function commit(environment: Store, updater: FormStoreUpdater): void;
|
|
10
6
|
export declare const operationQueryForm: any;
|
|
11
7
|
export declare const operationQueryErrorsForm: any;
|
|
8
|
+
export {};
|
package/lib/Utils.js
CHANGED
|
@@ -6,19 +6,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
var queries_1 = require("./relay/queries");
|
|
7
7
|
var RelayModernSelector_1 = require("./relay/RelayModernSelector");
|
|
8
8
|
var PREFIX_LOCAL_FORM = 'local:form';
|
|
9
|
-
var internalCommitLocalUpdate = function (environment, updater) {
|
|
10
|
-
environment.commitUpdate(function (store) {
|
|
11
|
-
var localForm = store.get(PREFIX_LOCAL_FORM);
|
|
12
|
-
if (!localForm) {
|
|
13
|
-
localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries');
|
|
14
|
-
store.getRoot().setLinkedRecord(localForm, 'form');
|
|
15
|
-
}
|
|
16
|
-
updater(store, localForm);
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
9
|
function getFieldId(key) {
|
|
20
10
|
return PREFIX_LOCAL_FORM + '.' + key;
|
|
21
11
|
}
|
|
12
|
+
exports.getFieldId = getFieldId;
|
|
22
13
|
function getSnapshot(environment, fragment, key) {
|
|
23
14
|
var item = {
|
|
24
15
|
__id: getFieldId(key)
|
|
@@ -26,62 +17,16 @@ function getSnapshot(environment, fragment, key) {
|
|
|
26
17
|
return environment.lookup(RelayModernSelector_1.getSingularSelector(fragment, item));
|
|
27
18
|
}
|
|
28
19
|
exports.getSnapshot = getSnapshot;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
exports.commitValidateIntoRelay = function (entries, isSubmitting, environment) {
|
|
39
|
-
internalCommitLocalUpdate(environment, function (store, form) {
|
|
40
|
-
form.setValue(isSubmitting, 'isSubmitting');
|
|
41
|
-
form.setValue(true, 'isValidating');
|
|
42
|
-
entries.forEach(function (entry) {
|
|
43
|
-
return store.get(getFieldId(entry.key)).setValue('START', 'check');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
};
|
|
47
|
-
exports.commitSubmitEndRelay = function (environment) {
|
|
48
|
-
internalCommitLocalUpdate(environment, function (_, form) {
|
|
49
|
-
form.setValue(false, 'isSubmitting');
|
|
50
|
-
});
|
|
51
|
-
};
|
|
52
|
-
exports.commitValidateEndRelay = function (environment) {
|
|
53
|
-
internalCommitLocalUpdate(environment, function (_, form) {
|
|
54
|
-
form.setValue(false, 'isValidating');
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
exports.commitResetField = function (environment, key) {
|
|
58
|
-
var id = getFieldId(key);
|
|
59
|
-
internalCommitLocalUpdate(environment, function (store, form) {
|
|
60
|
-
var entriesArray = form.getLinkedRecords('entries');
|
|
61
|
-
var newEntries = entriesArray.filter(function (value) {
|
|
62
|
-
return value.getDataID() != id;
|
|
63
|
-
});
|
|
64
|
-
form.setLinkedRecords(newEntries, 'entries');
|
|
65
|
-
store.delete(id);
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
exports.commitValue = function (key, value, check, environment) {
|
|
69
|
-
var id = getFieldId(key);
|
|
70
|
-
internalCommitLocalUpdate(environment, function (store, form) {
|
|
71
|
-
var field = store.get(id);
|
|
72
|
-
if (!field) {
|
|
73
|
-
field = store.create(id);
|
|
74
|
-
var entriesArray = form.getLinkedRecords('entries');
|
|
75
|
-
entriesArray.push(field);
|
|
76
|
-
form.setLinkedRecords(entriesArray, 'entries');
|
|
20
|
+
function commit(environment, updater) {
|
|
21
|
+
environment.commitUpdate(function (store) {
|
|
22
|
+
var localForm = store.get(PREFIX_LOCAL_FORM);
|
|
23
|
+
if (!localForm) {
|
|
24
|
+
localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries').setLinkedRecords([], 'errors');
|
|
25
|
+
store.getRoot().setLinkedRecord(localForm, 'form');
|
|
77
26
|
}
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
exports.commitErrorIntoRelay = function (key, error, environment) {
|
|
82
|
-
internalCommitLocalUpdate(environment, function (store) {
|
|
83
|
-
store.get(getFieldId(key)).setValue(error, 'error').setValue('DONE', 'check');
|
|
27
|
+
updater(store, localForm);
|
|
84
28
|
});
|
|
85
|
-
}
|
|
29
|
+
}
|
|
30
|
+
exports.commit = commit;
|
|
86
31
|
exports.operationQueryForm = RelayModernSelector_1.createOperationDescriptor(queries_1.QueryFields);
|
|
87
32
|
exports.operationQueryErrorsForm = RelayModernSelector_1.createOperationDescriptor(queries_1.QueryErrors);
|
|
@@ -13,6 +13,7 @@ export declare type FormSetValueOptions<ValueType> = {
|
|
|
13
13
|
initialValue?: ValueType;
|
|
14
14
|
validate?: (value: ValueType) => Promise<string | undefined> | string | undefined;
|
|
15
15
|
validateOnChange?: boolean;
|
|
16
|
+
label?: string;
|
|
16
17
|
};
|
|
17
18
|
export declare type FormSetValueStateReturn<ValueType> = {
|
|
18
19
|
error: undefined | null | Error;
|
package/lib/es/Utils.d.ts
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RecordProxy, RecordSourceProxy, Snapshot, Store } from './relay/RelayTypes';
|
|
2
|
+
declare type FormStoreUpdater = (store: RecordSourceProxy, form: RecordProxy) => void;
|
|
3
|
+
export declare function getFieldId(key: any): string;
|
|
2
4
|
export declare function getSnapshot(environment: Store, fragment: any, key: string): Snapshot;
|
|
3
|
-
export declare
|
|
4
|
-
export declare const commitValidateIntoRelay: (entries: any, isSubmitting: any, environment: any) => void;
|
|
5
|
-
export declare const commitSubmitEndRelay: (environment: any) => void;
|
|
6
|
-
export declare const commitValidateEndRelay: (environment: any) => void;
|
|
7
|
-
export declare const commitResetField: (environment: any, key: any) => void;
|
|
8
|
-
export declare const commitValue: (key: any, value: any, check: any, environment: any) => void;
|
|
9
|
-
export declare const commitErrorIntoRelay: (key: any, error: any, environment: any) => void;
|
|
5
|
+
export declare function commit(environment: Store, updater: FormStoreUpdater): void;
|
|
10
6
|
export declare const operationQueryForm: any;
|
|
11
7
|
export declare const operationQueryErrorsForm: any;
|
|
8
|
+
export {};
|
package/lib/es/Utils.js
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { QueryErrors, QueryFields } from './relay/queries';
|
|
2
|
-
import {
|
|
2
|
+
import { createOperationDescriptor, getSingularSelector } from './relay/RelayModernSelector';
|
|
3
3
|
var PREFIX_LOCAL_FORM = 'local:form';
|
|
4
|
-
|
|
5
|
-
environment.commitUpdate(function (store) {
|
|
6
|
-
var localForm = store.get(PREFIX_LOCAL_FORM);
|
|
7
|
-
if (!localForm) {
|
|
8
|
-
localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries');
|
|
9
|
-
store.getRoot().setLinkedRecord(localForm, 'form');
|
|
10
|
-
}
|
|
11
|
-
updater(store, localForm);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
14
|
-
function getFieldId(key) {
|
|
4
|
+
export function getFieldId(key) {
|
|
15
5
|
return PREFIX_LOCAL_FORM + '.' + key;
|
|
16
6
|
}
|
|
17
7
|
export function getSnapshot(environment, fragment, key) {
|
|
@@ -20,62 +10,15 @@ export function getSnapshot(environment, fragment, key) {
|
|
|
20
10
|
};
|
|
21
11
|
return environment.lookup(getSingularSelector(fragment, item));
|
|
22
12
|
}
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
export var commitValidateIntoRelay = function (entries, isSubmitting, environment) {
|
|
33
|
-
internalCommitLocalUpdate(environment, function (store, form) {
|
|
34
|
-
form.setValue(isSubmitting, 'isSubmitting');
|
|
35
|
-
form.setValue(true, 'isValidating');
|
|
36
|
-
entries.forEach(function (entry) {
|
|
37
|
-
return store.get(getFieldId(entry.key)).setValue('START', 'check');
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
export var commitSubmitEndRelay = function (environment) {
|
|
42
|
-
internalCommitLocalUpdate(environment, function (_, form) {
|
|
43
|
-
form.setValue(false, 'isSubmitting');
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
export var commitValidateEndRelay = function (environment) {
|
|
47
|
-
internalCommitLocalUpdate(environment, function (_, form) {
|
|
48
|
-
form.setValue(false, 'isValidating');
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
export var commitResetField = function (environment, key) {
|
|
52
|
-
var id = getFieldId(key);
|
|
53
|
-
internalCommitLocalUpdate(environment, function (store, form) {
|
|
54
|
-
var entriesArray = form.getLinkedRecords('entries');
|
|
55
|
-
var newEntries = entriesArray.filter(function (value) {
|
|
56
|
-
return value.getDataID() != id;
|
|
57
|
-
});
|
|
58
|
-
form.setLinkedRecords(newEntries, 'entries');
|
|
59
|
-
store.delete(id);
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
export var commitValue = function (key, value, check, environment) {
|
|
63
|
-
var id = getFieldId(key);
|
|
64
|
-
internalCommitLocalUpdate(environment, function (store, form) {
|
|
65
|
-
var field = store.get(id);
|
|
66
|
-
if (!field) {
|
|
67
|
-
field = store.create(id);
|
|
68
|
-
var entriesArray = form.getLinkedRecords('entries');
|
|
69
|
-
entriesArray.push(field);
|
|
70
|
-
form.setLinkedRecords(entriesArray, 'entries');
|
|
13
|
+
export function commit(environment, updater) {
|
|
14
|
+
environment.commitUpdate(function (store) {
|
|
15
|
+
var localForm = store.get(PREFIX_LOCAL_FORM);
|
|
16
|
+
if (!localForm) {
|
|
17
|
+
localForm = store.create(PREFIX_LOCAL_FORM).setLinkedRecords([], 'entries').setLinkedRecords([], 'errors');
|
|
18
|
+
store.getRoot().setLinkedRecord(localForm, 'form');
|
|
71
19
|
}
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
export var commitErrorIntoRelay = function (key, error, environment) {
|
|
76
|
-
internalCommitLocalUpdate(environment, function (store) {
|
|
77
|
-
store.get(getFieldId(key)).setValue(error, 'error').setValue('DONE', 'check');
|
|
20
|
+
updater(store, localForm);
|
|
78
21
|
});
|
|
79
|
-
}
|
|
22
|
+
}
|
|
80
23
|
export var operationQueryForm = createOperationDescriptor(QueryFields);
|
|
81
24
|
export var operationQueryErrorsForm = createOperationDescriptor(QueryErrors);
|
|
@@ -22,6 +22,7 @@ export declare class RelayRecordProxy implements RecordProxy {
|
|
|
22
22
|
constructor(source: any, mutator: any, dataID: any);
|
|
23
23
|
getDataID(): string;
|
|
24
24
|
setValue(value: any, name: string): this;
|
|
25
|
+
getValue(name: any): any;
|
|
25
26
|
setLinkedRecord(record: RecordProxy, name: string): this;
|
|
26
27
|
getLinkedRecords(name: string): Array<RecordProxy | null | undefined> | null | undefined;
|
|
27
28
|
setLinkedRecords(records: any, name: string): RecordProxy;
|
|
@@ -30,6 +30,9 @@ var RelayRecordProxy = /** @class */function () {
|
|
|
30
30
|
this._mutator.setValue(this._dataID, name, value);
|
|
31
31
|
return this;
|
|
32
32
|
};
|
|
33
|
+
RelayRecordProxy.prototype.getValue = function (name) {
|
|
34
|
+
return this._mutator.getValue(this._dataID, name);
|
|
35
|
+
};
|
|
33
36
|
RelayRecordProxy.prototype.setLinkedRecord = function (record, name) {
|
|
34
37
|
var linkedID = record.getDataID();
|
|
35
38
|
this._mutator.setLinkedRecordID(this._dataID, name, linkedID);
|
|
@@ -29,6 +29,7 @@ export declare class RelayRecordSourceMutator {
|
|
|
29
29
|
create(dataID: any): void;
|
|
30
30
|
delete(dataID: any): void;
|
|
31
31
|
getStatus(dataID: any): "EXISTENT" | "NONEXISTENT" | "UNKNOWN";
|
|
32
|
+
getValue(dataID: any, storageKey: string): any;
|
|
32
33
|
setValue(dataID: any, storageKey: string, value: any): void;
|
|
33
34
|
setLinkedRecordID(dataID: any, storageKey: any, linkedID: any): void;
|
|
34
35
|
getLinkedRecordIDs(dataID: any, storageKey: string): any;
|
|
@@ -45,6 +45,19 @@ var RelayRecordSourceMutator = /** @class */function () {
|
|
|
45
45
|
RelayRecordSourceMutator.prototype.getStatus = function (dataID) {
|
|
46
46
|
return this._sink.has(dataID) ? this._sink.getStatus(dataID) : this._base.getStatus(dataID);
|
|
47
47
|
};
|
|
48
|
+
RelayRecordSourceMutator.prototype.getValue = function (dataID, storageKey) {
|
|
49
|
+
for (var ii = 0; ii < this.__sources.length; ii++) {
|
|
50
|
+
var record = this.__sources[ii].get(dataID);
|
|
51
|
+
if (record) {
|
|
52
|
+
var value = RelayModernRecord.getValue(record, storageKey);
|
|
53
|
+
if (value !== undefined) {
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
} else if (record === null) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
48
61
|
RelayRecordSourceMutator.prototype.setValue = function (dataID, storageKey, value) {
|
|
49
62
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
50
63
|
RelayModernRecord.setValue(sinkRecord, storageKey, value);
|
|
@@ -4,6 +4,7 @@ export declare type Disposable = {
|
|
|
4
4
|
};
|
|
5
5
|
export interface RecordProxy {
|
|
6
6
|
getDataID(): string;
|
|
7
|
+
getValue(name: string): any;
|
|
7
8
|
getLinkedRecords(name: string): Array<RecordProxy | null | undefined> | null | undefined;
|
|
8
9
|
setLinkedRecord(record: RecordProxy, name: string): RecordProxy;
|
|
9
10
|
setLinkedRecords(records: Array<RecordProxy>, name: string): RecordProxy;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export declare type QueryErrorsData = {
|
|
2
2
|
readonly form: {
|
|
3
|
-
readonly
|
|
4
|
-
readonly check:
|
|
3
|
+
readonly errors: ReadonlyArray<{
|
|
4
|
+
readonly check: number | null;
|
|
5
5
|
readonly error: string | null;
|
|
6
6
|
readonly id: string;
|
|
7
7
|
readonly key: string;
|
|
8
|
+
readonly label: string | null;
|
|
8
9
|
} | null> | null;
|
|
9
10
|
readonly isSubmitting: boolean | null;
|
|
11
|
+
readonly isValid: boolean | null;
|
|
10
12
|
readonly isValidating: boolean | null;
|
|
11
13
|
} | null;
|
|
12
14
|
};
|
|
@@ -38,7 +40,7 @@ export declare const QueryErrors: {
|
|
|
38
40
|
export declare type QueryFieldsData = {
|
|
39
41
|
readonly form: {
|
|
40
42
|
readonly entries: ReadonlyArray<{
|
|
41
|
-
readonly check:
|
|
43
|
+
readonly check: number | null;
|
|
42
44
|
readonly error: string | null;
|
|
43
45
|
readonly id: string;
|
|
44
46
|
readonly key: string;
|
|
@@ -67,7 +69,7 @@ export declare const QueryFields: {
|
|
|
67
69
|
};
|
|
68
70
|
};
|
|
69
71
|
export declare type FragmentSetData = {
|
|
70
|
-
readonly check:
|
|
72
|
+
readonly check: number | null;
|
|
71
73
|
readonly id: string;
|
|
72
74
|
};
|
|
73
75
|
export declare const FragmentSet: {
|
package/lib/es/relay/queries.js
CHANGED
|
@@ -14,6 +14,9 @@ var error = {
|
|
|
14
14
|
var value = {
|
|
15
15
|
name: 'value'
|
|
16
16
|
};
|
|
17
|
+
var label = {
|
|
18
|
+
name: 'label'
|
|
19
|
+
};
|
|
17
20
|
var kindFragment = 'Fragment';
|
|
18
21
|
export var QueryErrors = {
|
|
19
22
|
id: '1',
|
|
@@ -30,9 +33,9 @@ export var QueryErrors = {
|
|
|
30
33
|
name: 'isValidating'
|
|
31
34
|
}, {
|
|
32
35
|
kind: LINKED_FIELD,
|
|
33
|
-
name: '
|
|
36
|
+
name: 'errors',
|
|
34
37
|
plural: true,
|
|
35
|
-
selections: [id, key, error, check]
|
|
38
|
+
selections: [id, key, error, check, label]
|
|
36
39
|
}]
|
|
37
40
|
}] /*: any*/
|
|
38
41
|
}
|
|
@@ -64,5 +67,5 @@ export var FragmentSet = {
|
|
|
64
67
|
export var FragmentValue = {
|
|
65
68
|
kind: kindFragment,
|
|
66
69
|
name: 'fragmentValue',
|
|
67
|
-
selections: [id, value, error]
|
|
70
|
+
selections: [id, value, error, label]
|
|
68
71
|
};
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { FormSetValueOptions, FormSetValueReturn } from './RelayFormsTypes';
|
|
2
|
-
export declare
|
|
2
|
+
export declare const TOBEVALIDATE = 1;
|
|
3
|
+
export declare const VALIDATING = 2;
|
|
4
|
+
export declare const RESET = 5;
|
|
5
|
+
export declare function isDone(check: any): boolean;
|
|
6
|
+
export declare function useFormSetValue<ValueType>({ key, initialValue, validate, validateOnChange, label, }: FormSetValueOptions<ValueType>): FormSetValueReturn<ValueType>;
|