native-document 1.0.176 → 1.0.178
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/docs/components/form/form-control.md +1 -16
- package/package.json +1 -1
- package/router.d.ts +1 -0
- package/src/components/form/FormControl.js +7 -3
- package/src/core/data/Observable.js +2 -2
- package/src/core/data/ObservableResource.js +14 -6
- package/src/core/utils/HasEventEmitter.js +1 -1
- package/src/ui/components/form/fields/PasswordFieldRender.js +1 -1
- package/types/observable.d.ts +1 -0
|
@@ -41,7 +41,6 @@ FormControl.use(FormControlRender);
|
|
|
41
41
|
.dispatchErrors(mapper?)
|
|
42
42
|
.summarizeErrors()
|
|
43
43
|
.dispatchAndSummarize(mapper?)
|
|
44
|
-
.dispatchServerErrors(error)
|
|
45
44
|
|
|
46
45
|
// State
|
|
47
46
|
.disable(fieldName?) // disable all or specific field
|
|
@@ -69,19 +68,5 @@ FormControl.use(FormControlRender);
|
|
|
69
68
|
## Example
|
|
70
69
|
|
|
71
70
|
```javascript
|
|
72
|
-
|
|
73
|
-
.fields((group) => {
|
|
74
|
-
group.add(StringField('name').label('Name').required())
|
|
75
|
-
group.add(EmailField('email').label('Email').required())
|
|
76
|
-
group.add(PasswordField('password').label('Password').required().minLength(8))
|
|
77
|
-
})
|
|
78
|
-
.onSubmit(async (values) => {
|
|
79
|
-
const valid = await control.validate();
|
|
80
|
-
if (valid) {
|
|
81
|
-
await createUser(values);
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
.onError((error) => {
|
|
85
|
-
control.dispatchErrors(error);
|
|
86
|
-
})
|
|
71
|
+
|
|
87
72
|
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "native-document",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.178",
|
|
4
4
|
"description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
|
|
5
5
|
"author": "AfroCodeur <https://github.com/afrocodeur>",
|
|
6
6
|
"license": "MIT",
|
package/router.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export default function FormControl(props) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
FormControl.defaultTemplate = null;
|
|
54
|
+
FormControl.defaultErrorsMapper = null;
|
|
54
55
|
|
|
55
56
|
/**
|
|
56
57
|
* Registers the render template for FormControl.
|
|
@@ -73,6 +74,10 @@ FormControl.use = function(template) {
|
|
|
73
74
|
FormControl.defaultTemplate = template;
|
|
74
75
|
};
|
|
75
76
|
|
|
77
|
+
FormControl.setDefaultErrorsMapper = function(mapper) {
|
|
78
|
+
FormControl.defaultErrorsMapper = mapper;
|
|
79
|
+
};
|
|
80
|
+
|
|
76
81
|
/**
|
|
77
82
|
* @param {GlobalAttributes} [props]
|
|
78
83
|
* @returns {FormControl}
|
|
@@ -235,9 +240,8 @@ FormControl.prototype.renderErrors = function(renderFn) {
|
|
|
235
240
|
|
|
236
241
|
FormControl.prototype.$dispatchServerErrors = function(error) {
|
|
237
242
|
const serverErrors = error.fields;
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
: serverErrors;
|
|
243
|
+
const errorsMapper = this.$description.errorsMapper || FormControl.defaultErrorsMapper;
|
|
244
|
+
const mapped = errorsMapper ? errorsMapper(error) : serverErrors;
|
|
241
245
|
|
|
242
246
|
if(!mapped) {
|
|
243
247
|
return;
|
|
@@ -216,8 +216,8 @@ Observable.json = Observable.init;
|
|
|
216
216
|
|
|
217
217
|
Observable.resource = function(fn, deps = [], options = false) {
|
|
218
218
|
const config = (typeof options === 'boolean')
|
|
219
|
-
? { auto: options, debounce: 0, lazy: false }
|
|
220
|
-
: { auto: false, debounce: 0, lazy: false, ...options };
|
|
219
|
+
? { auto: options, debounce: 0, lazy: false, throw: true }
|
|
220
|
+
: { auto: false, debounce: 0, lazy: false, ...options, throw: true };
|
|
221
221
|
|
|
222
222
|
return new ObservableResource(fn, deps, config);
|
|
223
223
|
};
|
|
@@ -22,6 +22,7 @@ const STATE = {
|
|
|
22
22
|
* @param {boolean} [config.lazy=false] - If true with deps, does not fetch immediately — waits for first dep change
|
|
23
23
|
* @param {number} [config.debounce=0] - Debounce delay in ms for dependency-triggered re-fetches
|
|
24
24
|
* @param {ObservableItem} [config.into] - Observable to write results into instead of creating a new one
|
|
25
|
+
* @param {boolean} [config.throw] - Catch abd throw the error
|
|
25
26
|
* @param {Function} [config.apply] - Custom function to apply the result to this.data
|
|
26
27
|
* @example
|
|
27
28
|
* const userId = Observable(1);
|
|
@@ -86,7 +87,7 @@ ObservableResource.prototype.$runWithAbortController = function(isRefetch = fals
|
|
|
86
87
|
const depValues = this.$dependencies.map(dep => dep.val());
|
|
87
88
|
const args = [...depValues, signal];
|
|
88
89
|
|
|
89
|
-
Promise.resolve(this.$fn(...args))
|
|
90
|
+
return Promise.resolve(this.$fn(...args))
|
|
90
91
|
.then(result => {
|
|
91
92
|
if (signal.aborted) {
|
|
92
93
|
return;
|
|
@@ -98,11 +99,17 @@ ObservableResource.prototype.$runWithAbortController = function(isRefetch = fals
|
|
|
98
99
|
})
|
|
99
100
|
.catch(err => {
|
|
100
101
|
if (signal.aborted) {
|
|
102
|
+
if(this.$config.throw) {
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
101
105
|
return;
|
|
102
106
|
}
|
|
103
107
|
this.error.set(err);
|
|
104
108
|
this.state.set(STATE.ERRORED);
|
|
105
109
|
this.$controller = null;
|
|
110
|
+
if(this.$config.throw) {
|
|
111
|
+
throw err;
|
|
112
|
+
}
|
|
106
113
|
});
|
|
107
114
|
};
|
|
108
115
|
ObservableResource.prototype.$runWithoutAbortController = function(isRefetch = false) {
|
|
@@ -114,7 +121,7 @@ ObservableResource.prototype.$runWithoutAbortController = function(isRefetch = f
|
|
|
114
121
|
|
|
115
122
|
const args = this.$dependencies.map(dep => dep.val());
|
|
116
123
|
|
|
117
|
-
Promise.resolve(this.$fn(...args))
|
|
124
|
+
return Promise.resolve(this.$fn(...args))
|
|
118
125
|
.then(result => {
|
|
119
126
|
this.$applyResult(result);
|
|
120
127
|
this.error.set(null);
|
|
@@ -123,6 +130,9 @@ ObservableResource.prototype.$runWithoutAbortController = function(isRefetch = f
|
|
|
123
130
|
.catch(err => {
|
|
124
131
|
this.error.set(err);
|
|
125
132
|
this.state.set(STATE.ERRORED);
|
|
133
|
+
if(this.$config.throw) {
|
|
134
|
+
throw err;
|
|
135
|
+
}
|
|
126
136
|
});
|
|
127
137
|
};
|
|
128
138
|
|
|
@@ -193,8 +203,7 @@ ObservableResource.prototype.into = function($observable) {
|
|
|
193
203
|
* @returns {this}
|
|
194
204
|
*/
|
|
195
205
|
ObservableResource.prototype.fetch = function() {
|
|
196
|
-
this.$run(false);
|
|
197
|
-
return this;
|
|
206
|
+
return this.$run(false);
|
|
198
207
|
};
|
|
199
208
|
|
|
200
209
|
/**
|
|
@@ -204,8 +213,7 @@ ObservableResource.prototype.fetch = function() {
|
|
|
204
213
|
* @returns {this}
|
|
205
214
|
*/
|
|
206
215
|
ObservableResource.prototype.refetch = function() {
|
|
207
|
-
this.$run(true);
|
|
208
|
-
return this;
|
|
216
|
+
return this.$run(true);
|
|
209
217
|
};
|
|
210
218
|
|
|
211
219
|
/**
|
|
@@ -78,7 +78,7 @@ HasEventEmitter.prototype.trigger = async function(eventName, ...args) {
|
|
|
78
78
|
|
|
79
79
|
let result = null;
|
|
80
80
|
for(let i = 0, length = callbacks.length; i < length; i++) {
|
|
81
|
-
result = await Promise.resolve(
|
|
81
|
+
result = await Promise.resolve(callbacks[i].apply(this, args));
|
|
82
82
|
}
|
|
83
83
|
return result;
|
|
84
84
|
};
|
|
@@ -8,7 +8,7 @@ export default function PasswordFieldRender($desc, instance) {
|
|
|
8
8
|
const $visible = $(false);
|
|
9
9
|
const icons = $desc.visibilityIcons || {show: '👁', hide: '🙈'};
|
|
10
10
|
|
|
11
|
-
const toggleBtn = Button({class: 'field-visibility-toggle'},
|
|
11
|
+
const toggleBtn = Button({ type: 'button', class: 'field-visibility-toggle'},
|
|
12
12
|
$visible.transform(v => v ? icons.hide : icons.show),
|
|
13
13
|
);
|
|
14
14
|
|
package/types/observable.d.ts
CHANGED