@anglr/common 12.0.0-beta.20220413111906 → 12.0.0-beta.20220414120442
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/changelog.md +51 -2
- package/es2015/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.js +53 -0
- package/es2015/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.js.map +1 -0
- package/es2015/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.js +75 -0
- package/es2015/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.js.map +1 -0
- package/es2015/forms/src/components/index.js +4 -0
- package/es2015/forms/src/components/index.js.map +1 -0
- package/es2015/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.js +75 -0
- package/es2015/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.js.map +1 -0
- package/es2015/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.js +31 -0
- package/es2015/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.js.map +1 -0
- package/es2015/forms/src/directives/hasError/hasError.directive.js +38 -8
- package/es2015/forms/src/directives/hasError/hasError.directive.js.map +1 -1
- package/es2015/forms/src/directives/index.js +3 -0
- package/es2015/forms/src/directives/index.js.map +1 -0
- package/es2015/forms/src/directives/validationErrorsContainer/validationErrorsContainer.directive.js +24 -0
- package/es2015/forms/src/directives/validationErrorsContainer/validationErrorsContainer.directive.js.map +1 -0
- package/es2015/forms/src/index.js +4 -1
- package/es2015/forms/src/index.js.map +1 -1
- package/es2015/forms/src/misc/tokens.js +14 -0
- package/es2015/forms/src/misc/tokens.js.map +1 -0
- package/es2015/forms/src/misc/validationErrorsContainerView.js +31 -0
- package/es2015/forms/src/misc/validationErrorsContainerView.js.map +1 -0
- package/es2015/forms/src/modules/errorMessage/components/groupErrors/groupErrors.component.js +3 -2
- package/es2015/forms/src/modules/errorMessage/components/groupErrors/groupErrors.component.js.map +1 -1
- package/es2015/forms/src/modules/errorMessage/directives/errorMessage/errorMessage.directive.js +1 -1
- package/es2015/forms/src/modules/errorMessage/directives/errorMessage/errorMessage.directive.js.map +1 -1
- package/es2015/forms/src/modules/errorMessage/pipes/withErrorMessage/withErrorMessage.pipe.js +1 -1
- package/es2015/forms/src/modules/errorMessage/pipes/withErrorMessage/withErrorMessage.pipe.js.map +1 -1
- package/es2015/forms/src/modules/hasError.module.js +27 -5
- package/es2015/forms/src/modules/hasError.module.js.map +1 -1
- package/es2015/forms/src/services/errorMessagesExtractor/errorMessagesExtractor.service.js +12 -5
- package/es2015/forms/src/services/errorMessagesExtractor/errorMessagesExtractor.service.js.map +1 -1
- package/es2015/forms/src/services/validationErrorRenderer/validationErrorRenderer.interface.js.map +1 -1
- package/es2015/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.js +31 -145
- package/es2015/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.js.map +1 -1
- package/es2020/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.js +53 -0
- package/es2020/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.js.map +1 -0
- package/es2020/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.js +75 -0
- package/es2020/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.js.map +1 -0
- package/es2020/forms/src/components/index.js +4 -0
- package/es2020/forms/src/components/index.js.map +1 -0
- package/es2020/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.js +75 -0
- package/es2020/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.js.map +1 -0
- package/es2020/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.js +31 -0
- package/es2020/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.js.map +1 -0
- package/es2020/forms/src/directives/hasError/hasError.directive.js +37 -8
- package/es2020/forms/src/directives/hasError/hasError.directive.js.map +1 -1
- package/es2020/forms/src/directives/index.js +3 -0
- package/es2020/forms/src/directives/index.js.map +1 -0
- package/es2020/forms/src/directives/validationErrorsContainer/validationErrorsContainer.directive.js +24 -0
- package/es2020/forms/src/directives/validationErrorsContainer/validationErrorsContainer.directive.js.map +1 -0
- package/es2020/forms/src/index.js +4 -1
- package/es2020/forms/src/index.js.map +1 -1
- package/es2020/forms/src/misc/tokens.js +14 -0
- package/es2020/forms/src/misc/tokens.js.map +1 -0
- package/es2020/forms/src/misc/validationErrorsContainerView.js +31 -0
- package/es2020/forms/src/misc/validationErrorsContainerView.js.map +1 -0
- package/es2020/forms/src/modules/errorMessage/components/groupErrors/groupErrors.component.js +3 -2
- package/es2020/forms/src/modules/errorMessage/components/groupErrors/groupErrors.component.js.map +1 -1
- package/es2020/forms/src/modules/errorMessage/directives/errorMessage/errorMessage.directive.js +1 -1
- package/es2020/forms/src/modules/errorMessage/directives/errorMessage/errorMessage.directive.js.map +1 -1
- package/es2020/forms/src/modules/errorMessage/pipes/withErrorMessage/withErrorMessage.pipe.js +1 -1
- package/es2020/forms/src/modules/errorMessage/pipes/withErrorMessage/withErrorMessage.pipe.js.map +1 -1
- package/es2020/forms/src/modules/hasError.module.js +27 -5
- package/es2020/forms/src/modules/hasError.module.js.map +1 -1
- package/es2020/forms/src/services/errorMessagesExtractor/errorMessagesExtractor.service.js +12 -5
- package/es2020/forms/src/services/errorMessagesExtractor/errorMessagesExtractor.service.js.map +1 -1
- package/es2020/forms/src/services/validationErrorRenderer/validationErrorRenderer.interface.js.map +1 -1
- package/es2020/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.js +31 -143
- package/es2020/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.js.map +1 -1
- package/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.css +4 -0
- package/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.d.ts +32 -0
- package/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.d.ts.map +1 -0
- package/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.html +3 -0
- package/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.css +4 -0
- package/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.d.ts +51 -0
- package/forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.d.ts.map +1 -0
- package/forms/src/components/index.d.ts +4 -0
- package/forms/src/components/index.d.ts.map +1 -0
- package/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.css +4 -0
- package/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.d.ts +53 -0
- package/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.d.ts.map +1 -0
- package/forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.html +3 -0
- package/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.d.ts +10 -0
- package/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.d.ts.map +1 -0
- package/forms/src/directives/hasError/hasError.directive.d.ts +21 -6
- package/forms/src/directives/hasError/hasError.directive.d.ts.map +1 -1
- package/forms/src/directives/index.d.ts +3 -0
- package/forms/src/directives/index.d.ts.map +1 -0
- package/forms/src/directives/validationErrorsContainer/validationErrorsContainer.directive.d.ts +12 -0
- package/forms/src/directives/validationErrorsContainer/validationErrorsContainer.directive.d.ts.map +1 -0
- package/forms/src/index.d.ts +4 -1
- package/forms/src/index.d.ts.map +1 -1
- package/forms/src/misc/tokens.d.ts +16 -0
- package/forms/src/misc/tokens.d.ts.map +1 -0
- package/forms/src/misc/validationErrorsContainerView.d.ts +25 -0
- package/forms/src/misc/validationErrorsContainerView.d.ts.map +1 -0
- package/forms/src/modules/errorMessage/components/groupErrors/groupErrors.component.d.ts.map +1 -1
- package/forms/src/modules/errorMessage/components/groupErrors/groupErrors.component.html +1 -1
- package/forms/src/modules/hasError.module.d.ts +7 -1
- package/forms/src/modules/hasError.module.d.ts.map +1 -1
- package/forms/src/services/errorMessagesExtractor/errorMessagesExtractor.service.d.ts +3 -2
- package/forms/src/services/errorMessagesExtractor/errorMessagesExtractor.service.d.ts.map +1 -1
- package/forms/src/services/validationErrorRenderer/validationErrorRenderer.interface.d.ts +43 -12
- package/forms/src/services/validationErrorRenderer/validationErrorRenderer.interface.d.ts.map +1 -1
- package/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.d.ts +15 -63
- package/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.d.ts.map +1 -1
- package/package.json +1 -1
- package/version.bak +1 -1
- package/es2015/forms/src/misc/types.js +0 -6
- package/es2015/forms/src/misc/types.js.map +0 -1
- package/es2020/forms/src/misc/types.js +0 -6
- package/es2020/forms/src/misc/types.js.map +0 -1
- package/forms/src/misc/types.d.ts +0 -7
- package/forms/src/misc/types.d.ts.map +0 -1
package/es2015/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.js
CHANGED
|
@@ -1,46 +1,37 @@
|
|
|
1
|
-
import { Injectable, Inject,
|
|
2
|
-
import { DOCUMENT } from '@angular/common';
|
|
1
|
+
import { Injectable, Inject, Optional } from '@angular/core';
|
|
3
2
|
import { extend } from '@jscrpt/common';
|
|
4
3
|
import { ErrorMessagesExtractor } from '../errorMessagesExtractor/errorMessagesExtractor.service';
|
|
4
|
+
import { VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS } from '../../misc/tokens';
|
|
5
|
+
import { DefaultValidationErrorsComponent, DefaultValidationErrorsContainerComponent } from '../../components';
|
|
5
6
|
import * as i0 from "@angular/core";
|
|
6
7
|
import * as i1 from "../errorMessagesExtractor/errorMessagesExtractor.service";
|
|
7
|
-
/**
|
|
8
|
-
* Injection token used for injecting global options for ValidationErrorRendererFactory
|
|
9
|
-
*/
|
|
10
|
-
export const VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS = new InjectionToken('VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS');
|
|
11
|
-
//TODO: div renderer as custom component, wrapper div renderer
|
|
12
8
|
/**
|
|
13
9
|
* Service used for creating validation errors renderer
|
|
14
10
|
*/
|
|
15
11
|
export class ValidationErrorRendererFactory {
|
|
16
12
|
//######################### constructor #########################
|
|
17
|
-
constructor(_errorMessagesExtractor,
|
|
13
|
+
constructor(_errorMessagesExtractor, options) {
|
|
18
14
|
this._errorMessagesExtractor = _errorMessagesExtractor;
|
|
19
|
-
this._document = _document;
|
|
20
15
|
this._options = extend(true, {}, DEFAULT_OPTIONS, options);
|
|
21
16
|
}
|
|
22
17
|
//######################### public methods #########################
|
|
23
18
|
/**
|
|
24
19
|
* Creates new instance of ValidationErrorRenderer
|
|
25
20
|
* @param control - Control that is being processed for errors
|
|
26
|
-
* @param
|
|
21
|
+
* @param containerView - Class that stores view container for rendering errors
|
|
22
|
+
* @param injector - Injector for obtaining dependencies
|
|
27
23
|
* @param isSubmittedOrDirty - Function used for testing if control is submitted or dirty
|
|
28
|
-
* @param options - Options for validation errors renderer factory
|
|
29
24
|
*/
|
|
30
|
-
create(control,
|
|
31
|
-
|
|
32
|
-
return new opts.rendererType(this._errorMessagesExtractor, control, controlElement, this._document, injector, isSubmittedOrDirty, opts);
|
|
25
|
+
create(control, containerView, injector, isSubmittedOrDirty) {
|
|
26
|
+
return new this._options.rendererType(this._errorMessagesExtractor, control, containerView, injector, isSubmittedOrDirty, this._options);
|
|
33
27
|
}
|
|
34
28
|
}
|
|
35
|
-
ValidationErrorRendererFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ValidationErrorRendererFactory, deps: [{ token: i1.ErrorMessagesExtractor }, { token:
|
|
29
|
+
ValidationErrorRendererFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ValidationErrorRendererFactory, deps: [{ token: i1.ErrorMessagesExtractor }, { token: VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
36
30
|
ValidationErrorRendererFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ValidationErrorRendererFactory, providedIn: 'root' });
|
|
37
31
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ValidationErrorRendererFactory, decorators: [{
|
|
38
32
|
type: Injectable,
|
|
39
33
|
args: [{ providedIn: 'root' }]
|
|
40
|
-
}], ctorParameters: function () { return [{ type: i1.ErrorMessagesExtractor }, { type:
|
|
41
|
-
type: Inject,
|
|
42
|
-
args: [DOCUMENT]
|
|
43
|
-
}] }, { type: undefined, decorators: [{
|
|
34
|
+
}], ctorParameters: function () { return [{ type: i1.ErrorMessagesExtractor }, { type: undefined, decorators: [{
|
|
44
35
|
type: Optional
|
|
45
36
|
}, {
|
|
46
37
|
type: Inject,
|
|
@@ -51,11 +42,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImpor
|
|
|
51
42
|
*/
|
|
52
43
|
export class DefaultValidationErrorRenderer {
|
|
53
44
|
//######################### constructor #########################
|
|
54
|
-
constructor(_errorMessagesExtractor, _control,
|
|
45
|
+
constructor(_errorMessagesExtractor, _control, _containerView, _injector, _isSubmittedOrDirty, _options) {
|
|
55
46
|
this._errorMessagesExtractor = _errorMessagesExtractor;
|
|
56
47
|
this._control = _control;
|
|
57
|
-
this.
|
|
58
|
-
this._document = _document;
|
|
48
|
+
this._containerView = _containerView;
|
|
59
49
|
this._injector = _injector;
|
|
60
50
|
this._isSubmittedOrDirty = _isSubmittedOrDirty;
|
|
61
51
|
this._options = _options;
|
|
@@ -63,157 +53,53 @@ export class DefaultValidationErrorRenderer {
|
|
|
63
53
|
}
|
|
64
54
|
//######################### public methods - implementation of ValiDationErrorRenderer #########################
|
|
65
55
|
/**
|
|
66
|
-
*
|
|
56
|
+
* @inheritdoc
|
|
67
57
|
*/
|
|
68
58
|
destroy() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this._injector.get(ApplicationRef).detachView(this._component.hostView);
|
|
72
|
-
this._component.destroy();
|
|
73
|
-
this._component = null;
|
|
74
|
-
}
|
|
75
|
-
(_a = this.wrapperElement) === null || _a === void 0 ? void 0 : _a.remove();
|
|
76
|
-
this.wrapperElement = null;
|
|
59
|
+
this._containerView.viewContainer.clear();
|
|
60
|
+
this._container = null;
|
|
77
61
|
}
|
|
78
62
|
/**
|
|
79
|
-
*
|
|
80
|
-
* @param errorMessages - Object storing error messages to be used as override
|
|
81
|
-
* @param onlyShow - Indication that update performs only displaying of existing errors
|
|
63
|
+
* @inheritdoc
|
|
82
64
|
*/
|
|
83
|
-
update(errorMessages) {
|
|
65
|
+
update(options, errorMessages) {
|
|
84
66
|
let result = false;
|
|
85
|
-
//hides old errors
|
|
86
|
-
this._toggleErrors(false);
|
|
87
67
|
this._lastErrors = this._errorMessagesExtractor.getErrors(this._control, errorMessages);
|
|
68
|
+
//has errors
|
|
88
69
|
if (this._lastErrors) {
|
|
89
70
|
this._isSubmittedOrDirty(() => {
|
|
90
|
-
this.
|
|
91
|
-
this.
|
|
71
|
+
// const errorsClasses = this._lastErrors.errors.map(error => `${this._options.prefix}${error.toLowerCase()}${this._options.suffix}`);
|
|
72
|
+
const opts = extend(true, {}, this._options, options);
|
|
73
|
+
this._container.instance.show(this._lastErrors, opts);
|
|
92
74
|
result = true;
|
|
93
75
|
}, () => {
|
|
94
|
-
this.
|
|
76
|
+
this._container.instance.hide();
|
|
95
77
|
result = false;
|
|
96
78
|
});
|
|
97
79
|
}
|
|
98
80
|
else {
|
|
99
|
-
this.
|
|
81
|
+
this._container.instance.hide();
|
|
100
82
|
result = false;
|
|
101
83
|
}
|
|
102
84
|
return result;
|
|
103
85
|
}
|
|
104
|
-
//######################### protected methods #########################
|
|
105
|
-
/**
|
|
106
|
-
* Toggles css classes for errors that are currently set
|
|
107
|
-
* @param add - Indication whether add or remove errors
|
|
108
|
-
*/
|
|
109
|
-
_toggleErrors(add = true) {
|
|
110
|
-
if (!this._lastErrors) {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const errorsClasses = this._lastErrors.errors.map(error => `${this._options.prefix}${error.toLowerCase()}${this._options.suffix}`);
|
|
114
|
-
(add ? this._controlElement.classList.add : this._controlElement.classList.remove).apply(this._controlElement.classList, errorsClasses);
|
|
115
|
-
(add ? this.wrapperElement.classList.add : this.wrapperElement.classList.remove).apply(this.wrapperElement.classList, errorsClasses);
|
|
116
|
-
this._errorMessageAttr.value = (add ? this._lastErrors.errorMessages : [])
|
|
117
|
-
.join(' ');
|
|
118
|
-
this._render(add);
|
|
119
|
-
}
|
|
120
86
|
/**
|
|
121
87
|
* Initialize renderer
|
|
122
88
|
*/
|
|
123
89
|
_initialize() {
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
this.wrapperElement.classList.add(this._options.wrapperDivClass);
|
|
127
|
-
this._errorMessageAttr = this._document.createAttribute('data-error-message');
|
|
128
|
-
this.wrapperElement.attributes.setNamedItem(this._errorMessageAttr);
|
|
129
|
-
this._controlElement.after(this.wrapperElement);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Renders error messages
|
|
133
|
-
* @param add - Indication whether add or remove errors
|
|
134
|
-
*/
|
|
135
|
-
_render(add) {
|
|
136
|
-
if (this._options.component) {
|
|
137
|
-
this._renderComponent(add);
|
|
138
|
-
}
|
|
139
|
-
else if (this._options.template) {
|
|
140
|
-
this._renderTemplate(add);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
this._renderDivs(add);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Renders divs with errors
|
|
148
|
-
* @param add - Indication whether add or remove errors
|
|
149
|
-
*/
|
|
150
|
-
_renderDivs(add = true) {
|
|
151
|
-
var _a, _b;
|
|
152
|
-
if (!add) {
|
|
153
|
-
const children = this.wrapperElement.children;
|
|
154
|
-
//first clean old messages
|
|
155
|
-
for (let x = children.length - 1; x >= 0; x--) {
|
|
156
|
-
children.item(x).remove();
|
|
157
|
-
}
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if ((_b = (_a = this._lastErrors) === null || _a === void 0 ? void 0 : _a.errorMessages) === null || _b === void 0 ? void 0 : _b.length) {
|
|
161
|
-
this._lastErrors.errorMessages.forEach(message => {
|
|
162
|
-
const errorDiv = this._document.createElement('div');
|
|
163
|
-
errorDiv.innerText = message;
|
|
164
|
-
this.wrapperElement.append(errorDiv);
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Renders component with errors
|
|
170
|
-
* @param add - Indication whether add or remove errors
|
|
171
|
-
*/
|
|
172
|
-
_renderComponent(add = true) {
|
|
173
|
-
if (add) {
|
|
174
|
-
//render component
|
|
175
|
-
if (!this._component) {
|
|
176
|
-
// 1. Create a component reference from the component
|
|
177
|
-
this._component = this._injector.get(ComponentFactoryResolver)
|
|
178
|
-
.resolveComponentFactory(this._options.component)
|
|
179
|
-
.create(this._injector);
|
|
180
|
-
// 2. Attach component to the appRef so that it's inside the ng component tree
|
|
181
|
-
this._injector.get(ApplicationRef).attachView(this._component.hostView);
|
|
182
|
-
// 3. Get DOM element from component
|
|
183
|
-
const domElem = this._component.hostView
|
|
184
|
-
.rootNodes[0];
|
|
185
|
-
// 4. Append DOM element to the body
|
|
186
|
-
this.wrapperElement.append(domElem);
|
|
187
|
-
}
|
|
188
|
-
this._component.instance.show(this._lastErrors);
|
|
189
|
-
}
|
|
190
|
-
else if (this._component) {
|
|
191
|
-
this._component.instance.show(null);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Renders template with errors
|
|
196
|
-
* @param add - Indication whether add or remove errors
|
|
197
|
-
*/
|
|
198
|
-
_renderTemplate(_add = true) {
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Shows wrapper element
|
|
202
|
-
*/
|
|
203
|
-
_show() {
|
|
204
|
-
this.wrapperElement.style.display = 'block';
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Hides wrapper element
|
|
208
|
-
*/
|
|
209
|
-
_hide() {
|
|
210
|
-
this.wrapperElement.style.display = 'none';
|
|
90
|
+
this._container = this._containerView.viewContainer.createComponent(this._options.container, { injector: this._injector });
|
|
91
|
+
this._container.instance.hide();
|
|
211
92
|
}
|
|
212
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Default options for validation error renderer factory
|
|
96
|
+
*/
|
|
213
97
|
const DEFAULT_OPTIONS = {
|
|
214
98
|
prefix: 'ng-',
|
|
215
99
|
suffix: '-error',
|
|
216
100
|
wrapperDivClass: 'validation-error-div',
|
|
217
|
-
rendererType: DefaultValidationErrorRenderer
|
|
101
|
+
rendererType: DefaultValidationErrorRenderer,
|
|
102
|
+
component: DefaultValidationErrorsComponent,
|
|
103
|
+
container: DefaultValidationErrorsContainerComponent,
|
|
218
104
|
};
|
|
219
105
|
//# sourceMappingURL=validationErrorRenderer.service.js.map
|
package/es2015/forms/src/services/validationErrorRenderer/validationErrorRenderer.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationErrorRenderer.service.js","sourceRoot":"","sources":["../../../../../forms/src/services/validationErrorRenderer/validationErrorRenderer.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAY,wBAAwB,EAAE,cAAc,EAAgC,MAAM,eAAe,CAAC;AAE9J,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAC,MAAM,EAAmB,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAC,sBAAsB,EAAC,MAAM,0DAA0D,CAAC;;;AAIhG;;GAEG;AACH,MAAM,CAAC,MAAM,yCAAyC,GAA0D,IAAI,cAAc,CAAwC,2CAA2C,CAA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,GACrB;IACI,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,QAAQ;IAChB,eAAe,EAAE,sBAAsB;IACvC,YAAY,EAAE,8BAA8B;CAC/C,CAAC","sourcesContent":["import {Injectable, Inject, InjectionToken, Optional, Injector, ComponentFactoryResolver, ApplicationRef, EmbeddedViewRef, ComponentRef} from '@angular/core';\nimport {FormControl} from '@angular/forms';\nimport {DOCUMENT} from '@angular/common';\nimport {extend, StringDictionary} from '@jscrpt/common';\n\nimport {ErrorMessagesExtractor} from '../errorMessagesExtractor/errorMessagesExtractor.service';\nimport {ValidationErrorRenderer, IsSubmittedOrDirtyFunc, ValidationErrorsRendererOptions, ValidationErrorRendererFactoryOptions, ValidationErrorsComponent} from './validationErrorRenderer.interface';\nimport {ValidationErrorsResult} from '../errorMessagesExtractor/errorMessagesExtractor.interface';\n\n/**\n * Injection token used for injecting global options for ValidationErrorRendererFactory\n */\nexport const VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS: InjectionToken<ValidationErrorRendererFactoryOptions> = new InjectionToken<ValidationErrorRendererFactoryOptions>('VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS');\n\n//TODO: div renderer as custom component, wrapper div renderer\n\n/**\n * Service used for creating validation errors renderer\n */\n@Injectable({providedIn: 'root'})\nexport class ValidationErrorRendererFactory\n{\n //######################### protected fields #########################\n\n /**\n * Options for validation error renderer factory\n */\n protected _options: ValidationErrorRendererFactoryOptions;\n\n //######################### constructor #########################\n constructor(protected _errorMessagesExtractor: ErrorMessagesExtractor,\n @Inject(DOCUMENT) protected _document: Document,\n @Optional() @Inject(VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS) options: ValidationErrorRendererFactoryOptions)\n {\n this._options = extend(true, {}, DEFAULT_OPTIONS, options);\n }\n\n //######################### public methods #########################\n\n /**\n * Creates new instance of ValidationErrorRenderer\n * @param control - Control that is being processed for errors\n * @param controlElement - Html element that represents control that is being processed\n * @param isSubmittedOrDirty - Function used for testing if control is submitted or dirty\n * @param options - Options for validation errors renderer factory\n */\n public create(control: FormControl,\n controlElement: HTMLElement,\n injector: Injector,\n isSubmittedOrDirty: IsSubmittedOrDirtyFunc,\n options: ValidationErrorRendererFactoryOptions): ValidationErrorRenderer\n {\n const opts: ValidationErrorRendererFactoryOptions = extend(true, {}, this._options, options);\n\n return new opts.rendererType(this._errorMessagesExtractor,\n control,\n controlElement,\n this._document,\n injector,\n isSubmittedOrDirty,\n opts);\n }\n}\n\n/**\n * Default implementation of validation error renderer\n */\nexport class DefaultValidationErrorRenderer implements ValidationErrorRenderer\n{\n //######################### protected fields #########################\n\n /**\n * Html element attribute storing error messages\n */\n protected _errorMessageAttr: Attr;\n\n /**\n * Object storing last obtained errors\n */\n protected _lastErrors: ValidationErrorsResult;\n\n /**\n * Component used for displaying errors\n */\n protected _component: ComponentRef<ValidationErrorsComponent>;\n\n //######################### public properties - implementation of ValidationErrorRenderer #########################\n\n /**\n * Html element that is wrapping errors\n */\n public wrapperElement: HTMLElement;\n\n //######################### constructor #########################\n constructor(protected _errorMessagesExtractor: ErrorMessagesExtractor,\n protected _control: FormControl,\n protected _controlElement: HTMLElement,\n protected _document: Document,\n protected _injector: Injector,\n protected _isSubmittedOrDirty: IsSubmittedOrDirtyFunc,\n protected _options: ValidationErrorsRendererOptions)\n {\n this._initialize();\n }\n\n //######################### public methods - implementation of ValiDationErrorRenderer #########################\n\n /**\n * Destroys renderer and everything that was rendered\n */\n public destroy(): void\n {\n if(this._component)\n {\n this._injector.get(ApplicationRef).detachView(this._component.hostView);\n this._component.destroy();\n this._component = null;\n }\n\n this.wrapperElement?.remove();\n this.wrapperElement = null;\n }\n\n /**\n * Updates rendered errors for current state and returns true if errors were rendered, otherwise false\n * @param errorMessages - Object storing error messages to be used as override\n * @param onlyShow - Indication that update performs only displaying of existing errors\n */\n public update(errorMessages?: StringDictionary): boolean\n {\n let result = false;\n\n //hides old errors\n this._toggleErrors(false);\n this._lastErrors = this._errorMessagesExtractor.getErrors(this._control, errorMessages);\n\n if(this._lastErrors)\n {\n this._isSubmittedOrDirty(() =>\n {\n this._show();\n this._toggleErrors();\n result = true;\n },\n () =>\n {\n this._hide();\n result = false;\n });\n }\n else\n {\n this._hide();\n result = false;\n }\n\n return result;\n }\n\n //######################### protected methods #########################\n\n /**\n * Toggles css classes for errors that are currently set\n * @param add - Indication whether add or remove errors\n */\n protected _toggleErrors(add: boolean = true): void\n {\n if(!this._lastErrors)\n {\n return;\n }\n\n const errorsClasses = this._lastErrors.errors.map(error => `${this._options.prefix}${error.toLowerCase()}${this._options.suffix}`);\n\n (add ? this._controlElement.classList.add : this._controlElement.classList.remove).apply(this._controlElement.classList, errorsClasses);\n (add ? this.wrapperElement.classList.add : this.wrapperElement.classList.remove).apply(this.wrapperElement.classList, errorsClasses);\n\n this._errorMessageAttr.value = (add ? this._lastErrors.errorMessages : [])\n .join(' ');\n\n this._render(add);\n }\n\n /**\n * Initialize renderer\n */\n protected _initialize(): void\n {\n this.wrapperElement = this._document.createElement('div');\n this._hide();\n this.wrapperElement.classList.add(this._options.wrapperDivClass);\n\n this._errorMessageAttr = this._document.createAttribute('data-error-message');\n\n this.wrapperElement.attributes.setNamedItem(this._errorMessageAttr);\n this._controlElement.after(this.wrapperElement);\n }\n\n /**\n * Renders error messages\n * @param add - Indication whether add or remove errors\n */\n protected _render(add: boolean): void\n {\n if(this._options.component)\n {\n this._renderComponent(add);\n }\n else if(this._options.template)\n {\n this._renderTemplate(add);\n }\n else\n {\n this._renderDivs(add);\n }\n }\n\n /**\n * Renders divs with errors\n * @param add - Indication whether add or remove errors\n */\n protected _renderDivs(add: boolean = true): void\n {\n if(!add)\n {\n const children = this.wrapperElement.children;\n \n //first clean old messages\n for(let x = children.length - 1; x >= 0; x--)\n {\n children.item(x).remove();\n }\n\n return;\n }\n\n if(this._lastErrors?.errorMessages?.length)\n {\n this._lastErrors.errorMessages.forEach(message =>\n {\n const errorDiv = this._document.createElement('div');\n\n errorDiv.innerText = message;\n\n this.wrapperElement.append(errorDiv);\n });\n }\n }\n\n /**\n * Renders component with errors\n * @param add - Indication whether add or remove errors\n */\n protected _renderComponent(add: boolean = true): void\n {\n if(add)\n {\n //render component\n if(!this._component)\n {\n // 1. Create a component reference from the component \n this._component = this._injector.get(ComponentFactoryResolver)\n .resolveComponentFactory(this._options.component)\n .create(this._injector);\n\n // 2. Attach component to the appRef so that it's inside the ng component tree\n this._injector.get(ApplicationRef).attachView(this._component.hostView);\n\n // 3. Get DOM element from component\n const domElem = (this._component.hostView as EmbeddedViewRef<any>)\n .rootNodes[0] as HTMLElement;\n\n // 4. Append DOM element to the body\n this.wrapperElement.append(domElem);\n }\n\n this._component.instance.show(this._lastErrors);\n }\n else if(this._component)\n {\n this._component.instance.show(null);\n }\n }\n\n /**\n * Renders template with errors\n * @param add - Indication whether add or remove errors\n */\n protected _renderTemplate(_add: boolean = true): void\n {\n\n }\n\n /**\n * Shows wrapper element\n */\n protected _show(): void\n {\n this.wrapperElement.style.display = 'block';\n }\n\n /**\n * Hides wrapper element\n */\n protected _hide(): void\n {\n this.wrapperElement.style.display = 'none';\n }\n}\n\nconst DEFAULT_OPTIONS: ValidationErrorRendererFactoryOptions =\n{\n prefix: 'ng-',\n suffix: '-error',\n wrapperDivClass: 'validation-error-div',\n rendererType: DefaultValidationErrorRenderer\n};"]}
|
|
1
|
+
{"version":3,"file":"validationErrorRenderer.service.js","sourceRoot":"","sources":["../../../../../forms/src/services/validationErrorRenderer/validationErrorRenderer.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAyB,MAAM,eAAe,CAAC;AAEnF,OAAO,EAAC,MAAM,EAAmB,MAAM,gBAAgB,CAAC;AAExD,OAAO,EAAC,sBAAsB,EAAC,MAAM,0DAA0D,CAAC;AAGhG,OAAO,EAAC,yCAAyC,EAAC,MAAM,mBAAmB,CAAC;AAE5E,OAAO,EAAC,gCAAgC,EAAE,yCAAyC,EAAC,MAAM,kBAAkB,CAAC;;;AA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,YAAY,EAAE,8BAA8B;IAC5C,SAAS,EAAE,gCAAgC;IAC3C,SAAS,EAAE,yCAAyC;CACvD,CAAC","sourcesContent":["import {Injectable, Inject, Optional, Injector, ComponentRef} from '@angular/core';\nimport {FormControl} from '@angular/forms';\nimport {extend, StringDictionary} from '@jscrpt/common';\n\nimport {ErrorMessagesExtractor} from '../errorMessagesExtractor/errorMessagesExtractor.service';\nimport {ValidationErrorRenderer, IsSubmittedOrDirtyFunc, ValidationErrorsRendererOptions, ValidationErrorRendererFactoryOptions, ValidationErrorsContainerComponent} from './validationErrorRenderer.interface';\nimport {ValidationErrorsResult} from '../errorMessagesExtractor/errorMessagesExtractor.interface';\nimport {VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS} from '../../misc/tokens';\nimport {ValidationErrorsContainerView} from '../../misc/validationErrorsContainerView';\nimport {DefaultValidationErrorsComponent, DefaultValidationErrorsContainerComponent} from '../../components';\n\n/**\n * Service used for creating validation errors renderer\n */\n@Injectable({providedIn: 'root'})\nexport class ValidationErrorRendererFactory\n{\n //######################### protected fields #########################\n\n /**\n * Options for validation error renderer factory\n */\n protected _options: ValidationErrorRendererFactoryOptions;\n\n //######################### constructor #########################\n constructor(protected _errorMessagesExtractor: ErrorMessagesExtractor,\n @Optional() @Inject(VALIDATION_ERROR_RENDERER_FACTORY_OPTIONS) options: ValidationErrorRendererFactoryOptions)\n {\n this._options = extend(true, {}, DEFAULT_OPTIONS, options);\n }\n\n //######################### public methods #########################\n\n /**\n * Creates new instance of ValidationErrorRenderer\n * @param control - Control that is being processed for errors\n * @param containerView - Class that stores view container for rendering errors\n * @param injector - Injector for obtaining dependencies\n * @param isSubmittedOrDirty - Function used for testing if control is submitted or dirty\n */\n public create(control: FormControl,\n containerView: ValidationErrorsContainerView,\n injector: Injector,\n isSubmittedOrDirty: IsSubmittedOrDirtyFunc): ValidationErrorRenderer\n {\n return new this._options.rendererType(this._errorMessagesExtractor,\n control,\n containerView,\n injector,\n isSubmittedOrDirty,\n this._options);\n }\n}\n\n/**\n * Default implementation of validation error renderer\n */\nexport class DefaultValidationErrorRenderer implements ValidationErrorRenderer\n{\n //######################### protected fields #########################\n\n /**\n * Object storing last obtained errors\n */\n protected _lastErrors: ValidationErrorsResult;\n\n /**\n * Component used as validation errors container\n */\n protected _container: ComponentRef<ValidationErrorsContainerComponent>;\n\n //######################### constructor #########################\n constructor(protected _errorMessagesExtractor: ErrorMessagesExtractor,\n protected _control: FormControl,\n protected _containerView: ValidationErrorsContainerView,\n protected _injector: Injector,\n protected _isSubmittedOrDirty: IsSubmittedOrDirtyFunc,\n protected _options: ValidationErrorsRendererOptions)\n {\n this._initialize();\n }\n\n //######################### public methods - implementation of ValiDationErrorRenderer #########################\n\n /**\n * @inheritdoc\n */\n public destroy(): void\n {\n this._containerView.viewContainer.clear();\n this._container = null;\n }\n\n /**\n * @inheritdoc\n */\n public update(options: ValidationErrorsRendererOptions, errorMessages?: StringDictionary): boolean\n {\n let result = false;\n this._lastErrors = this._errorMessagesExtractor.getErrors(this._control, errorMessages);\n\n //has errors\n if(this._lastErrors)\n {\n this._isSubmittedOrDirty(() =>\n {\n // const errorsClasses = this._lastErrors.errors.map(error => `${this._options.prefix}${error.toLowerCase()}${this._options.suffix}`);\n const opts = extend(true, {}, this._options, options);\n\n this._container.instance.show(this._lastErrors, opts);\n result = true;\n },\n () =>\n {\n this._container.instance.hide();\n result = false;\n });\n }\n else\n {\n this._container.instance.hide();\n result = false;\n }\n\n return result;\n }\n\n /**\n * Initialize renderer\n */\n protected _initialize(): void\n {\n this._container = this._containerView.viewContainer.createComponent(this._options.container, {injector: this._injector});\n this._container.instance.hide();\n }\n}\n\n/**\n * Default options for validation error renderer factory\n */\nconst DEFAULT_OPTIONS: ValidationErrorRendererFactoryOptions =\n{\n prefix: 'ng-',\n suffix: '-error',\n wrapperDivClass: 'validation-error-div',\n rendererType: DefaultValidationErrorRenderer,\n component: DefaultValidationErrorsComponent,\n container: DefaultValidationErrorsContainerComponent,\n};"]}
|
package/es2020/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Component, ChangeDetectionStrategy, ChangeDetectorRef, HostBinding } from '@angular/core';
|
|
2
|
+
import { animateChild, query, transition, trigger } from '@angular/animations';
|
|
3
|
+
import { slideInOutTrigger } from '@anglr/animations';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
import * as i1 from "@angular/common";
|
|
6
|
+
//TODO: move animation to common
|
|
7
|
+
/**
|
|
8
|
+
* Default validation errors component, displaying validation errors
|
|
9
|
+
*/
|
|
10
|
+
export class DefaultValidationErrorsComponent {
|
|
11
|
+
//######################### constructor #########################
|
|
12
|
+
constructor(_changeDetector) {
|
|
13
|
+
this._changeDetector = _changeDetector;
|
|
14
|
+
//######################### public properties - host #########################
|
|
15
|
+
/**
|
|
16
|
+
* Enables leave animations for internal stuff
|
|
17
|
+
*/
|
|
18
|
+
this.animate = true;
|
|
19
|
+
}
|
|
20
|
+
//######################### public methods - implementation of ValidationErrorsComponent #########################
|
|
21
|
+
/**
|
|
22
|
+
* @inheritdoc
|
|
23
|
+
*/
|
|
24
|
+
show(errors, options) {
|
|
25
|
+
this.errors = errors;
|
|
26
|
+
this.options = options;
|
|
27
|
+
this._changeDetector.detectChanges();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
DefaultValidationErrorsComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DefaultValidationErrorsComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
31
|
+
DefaultValidationErrorsComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.2", type: DefaultValidationErrorsComponent, selector: "default-validation-errors", host: { properties: { "@componentContent": "this.animate" } }, ngImport: i0, template: "<div [ngClass]=\"options?.wrapperDivClass\" *ngIf=\"errors?.errorMessages?.length\" @slideInOut>\n <div *ngFor=\"let error of errors?.errorMessages\">{{error}}</div>\n</div>", styles: [":host\n{\n display: contents;\n}"], directives: [{ type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i1.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], animations: [
|
|
32
|
+
slideInOutTrigger,
|
|
33
|
+
trigger('componentContent', [
|
|
34
|
+
transition(':enter, :leave', [
|
|
35
|
+
query('@*', animateChild(), { optional: true })
|
|
36
|
+
])
|
|
37
|
+
])
|
|
38
|
+
], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
39
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DefaultValidationErrorsComponent, decorators: [{
|
|
40
|
+
type: Component,
|
|
41
|
+
args: [{ selector: 'default-validation-errors', animations: [
|
|
42
|
+
slideInOutTrigger,
|
|
43
|
+
trigger('componentContent', [
|
|
44
|
+
transition(':enter, :leave', [
|
|
45
|
+
query('@*', animateChild(), { optional: true })
|
|
46
|
+
])
|
|
47
|
+
])
|
|
48
|
+
], changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [ngClass]=\"options?.wrapperDivClass\" *ngIf=\"errors?.errorMessages?.length\" @slideInOut>\n <div *ngFor=\"let error of errors?.errorMessages\">{{error}}</div>\n</div>", styles: [":host\n{\n display: contents;\n}"] }]
|
|
49
|
+
}], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { animate: [{
|
|
50
|
+
type: HostBinding,
|
|
51
|
+
args: ['@componentContent']
|
|
52
|
+
}] } });
|
|
53
|
+
//# sourceMappingURL=defaultValidationErrors.component.js.map
|
package/es2020/forms/src/components/defaultValidationErrors/defaultValidationErrors.component.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultValidationErrors.component.js","sourceRoot":"","sources":["../../../../../forms/src/components/defaultValidationErrors/defaultValidationErrors.component.ts","../../../../../forms/src/components/defaultValidationErrors/defaultValidationErrors.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,WAAW,EAAC,MAAM,eAAe,CAAC;AACjG,OAAO,EAAC,YAAY,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,EAAC,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAC,iBAAiB,EAAC,MAAM,mBAAmB,CAAC;;;AAKpD,gCAAgC;AAEhC;;GAEG;AAmBH,MAAM,OAAO,gCAAgC;IAwBzC,iEAAiE;IACjE,YAAsB,eAAkC;QAAlC,oBAAe,GAAf,eAAe,CAAmB;QATxD,8EAA8E;QAE9E;;WAEG;QAEI,YAAO,GAAY,IAAI,CAAC;IAK/B,CAAC;IAED,kHAAkH;IAElH;;OAEG;IACI,IAAI,CAAC,MAA8B,EAAE,OAAgC;QAExE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,eAAe,CAAC,aAAa,EAAE,CAAC;IACzC,CAAC;;6HAxCQ,gCAAgC;iHAAhC,gCAAgC,gIC9B7C,kLAEM,mVDgBF;QACI,iBAAiB;QACjB,OAAO,CAAC,kBAAkB,EAC1B;YACI,UAAU,CAAC,gBAAgB,EAC3B;gBACI,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;aAChD,CAAC;SACL,CAAC;KACL;2FAGQ,gCAAgC;kBAlB5C,SAAS;+BAEI,2BAA2B,cAIrC;wBACI,iBAAiB;wBACjB,OAAO,CAAC,kBAAkB,EAC1B;4BACI,UAAU,CAAC,gBAAgB,EAC3B;gCACI,KAAK,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC;6BAChD,CAAC;yBACL,CAAC;qBACL,mBACgB,uBAAuB,CAAC,MAAM;wGAwBxC,OAAO;sBADb,WAAW;uBAAC,mBAAmB","sourcesContent":["import {Component, ChangeDetectionStrategy, ChangeDetectorRef, HostBinding} from '@angular/core';\nimport {animateChild, query, transition, trigger} from '@angular/animations';\nimport {slideInOutTrigger} from '@anglr/animations';\n\nimport {ValidationErrorsResult} from '../../services/errorMessagesExtractor/errorMessagesExtractor.interface';\nimport {ValidationErrorsComponent, ValidationErrorsOptions} from '../../services/validationErrorRenderer/validationErrorRenderer.interface';\n\n//TODO: move animation to common\n\n/**\n * Default validation errors component, displaying validation errors\n */\n@Component(\n{\n selector: 'default-validation-errors',\n templateUrl: 'defaultValidationErrors.component.html',\n styleUrls: ['defaultValidationErrors.component.css'],\n animations: \n [\n slideInOutTrigger,\n trigger('componentContent',\n [\n transition(':enter, :leave',\n [\n query('@*', animateChild(), {optional: true})\n ])\n ])\n ],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class DefaultValidationErrorsComponent implements ValidationErrorsComponent\n{\n //######################### public properties - template bindings #########################\n\n /**\n * Errors to be shown\n * @internal\n */\n public errors: ValidationErrorsResult;\n \n /**\n * Options used for displaying validation errors\n * @internal\n */\n public options: ValidationErrorsOptions;\n\n //######################### public properties - host #########################\n\n /**\n * Enables leave animations for internal stuff\n */\n @HostBinding('@componentContent')\n public animate: boolean = true;\n\n //######################### constructor #########################\n constructor(protected _changeDetector: ChangeDetectorRef)\n {\n }\n\n //######################### public methods - implementation of ValidationErrorsComponent #########################\n\n /**\n * @inheritdoc\n */\n public show(errors: ValidationErrorsResult, options: ValidationErrorsOptions): void\n {\n this.errors = errors;\n this.options = options;\n\n this._changeDetector.detectChanges();\n }\n}","<div [ngClass]=\"options?.wrapperDivClass\" *ngIf=\"errors?.errorMessages?.length\" @slideInOut>\n <div *ngFor=\"let error of errors?.errorMessages\">{{error}}</div>\n</div>"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Component, ChangeDetectionStrategy, ViewContainerRef } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* Component that serves as container for validation errors, either component or templates
|
|
5
|
+
*/
|
|
6
|
+
export class DefaultValidationErrorsContainerComponent {
|
|
7
|
+
//######################### constructor #########################
|
|
8
|
+
constructor(_viewContainer) {
|
|
9
|
+
this._viewContainer = _viewContainer;
|
|
10
|
+
}
|
|
11
|
+
//######################### public methods - implementation of #########################
|
|
12
|
+
/**
|
|
13
|
+
* Shows validation errors
|
|
14
|
+
* @param errors - Errors to be shown
|
|
15
|
+
* @param options - Options used for displaying validation errors
|
|
16
|
+
* @param errorClasses - Array of css error classes
|
|
17
|
+
*/
|
|
18
|
+
show(errors, options) {
|
|
19
|
+
this._errors = errors;
|
|
20
|
+
this._options = options;
|
|
21
|
+
if (options.template) {
|
|
22
|
+
this._renderTemplate();
|
|
23
|
+
}
|
|
24
|
+
else if (options.component) {
|
|
25
|
+
this._renderComponent();
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('Missing template or component for rendering validation errors!');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Hides validation errors
|
|
33
|
+
*/
|
|
34
|
+
hide() {
|
|
35
|
+
this._viewContainer.clear();
|
|
36
|
+
this._component = null;
|
|
37
|
+
this._template = null;
|
|
38
|
+
}
|
|
39
|
+
//######################### protected methods #########################
|
|
40
|
+
/**
|
|
41
|
+
* Renders validation errors component
|
|
42
|
+
*/
|
|
43
|
+
_renderComponent() {
|
|
44
|
+
if (!this._component) {
|
|
45
|
+
this._component = this._viewContainer.createComponent(this._options.component);
|
|
46
|
+
}
|
|
47
|
+
this._component.instance.show(this._errors, this._options);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Renders validation errors template
|
|
51
|
+
*/
|
|
52
|
+
_renderTemplate() {
|
|
53
|
+
if (!this._template) {
|
|
54
|
+
this._template = this._viewContainer.createEmbeddedView(this._options.template, {
|
|
55
|
+
$implicit: this._errors,
|
|
56
|
+
options: this._options
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this._template.context =
|
|
61
|
+
{
|
|
62
|
+
$implicit: this._errors,
|
|
63
|
+
options: this._options
|
|
64
|
+
};
|
|
65
|
+
this._template.detectChanges();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
DefaultValidationErrorsContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DefaultValidationErrorsContainerComponent, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
70
|
+
DefaultValidationErrorsContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.2", type: DefaultValidationErrorsContainerComponent, selector: "default-validation-errors-container", ngImport: i0, template: '', isInline: true, styles: [":host\n{\n display: contents;\n}"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
71
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: DefaultValidationErrorsContainerComponent, decorators: [{
|
|
72
|
+
type: Component,
|
|
73
|
+
args: [{ selector: 'default-validation-errors-container', template: '', changeDetection: ChangeDetectionStrategy.OnPush, styles: [":host\n{\n display: contents;\n}"] }]
|
|
74
|
+
}], ctorParameters: function () { return [{ type: i0.ViewContainerRef }]; } });
|
|
75
|
+
//# sourceMappingURL=defaultValidationErrorsContainer.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaultValidationErrorsContainer.component.js","sourceRoot":"","sources":["../../../../../forms/src/components/defaultValidationErrorsContainer/defaultValidationErrorsContainer.component.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,uBAAuB,EAAE,gBAAgB,EA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;gBACvB,OAAO,EAAE,IAAI,CAAC,QAAQ;aACzB,CAAC,CAAC;SACN;aAED;YACI,IAAI,CAAC,SAAS,CAAC,OAAO;gBACtB;oBACI,SAAS,EAAE,IAAI,CAAC,OAAO;oBACvB,OAAO,EAAE,IAAI,CAAC,QAAQ;iBACzB,CAAC;YAEF,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;SAClC;IACL,CAAC;;sIA1GQ,yCAAyC;0HAAzC,yCAAyC,2EAJxC,EAAE;2FAIH,yCAAyC;kBAPrD,SAAS;+BAEI,qCAAqC,YACrC,EAAE,mBAEK,uBAAuB,CAAC,MAAM","sourcesContent":["import {Component, ChangeDetectionStrategy, ViewContainerRef, ComponentRef, EmbeddedViewRef} from '@angular/core';\n\nimport {ValidationErrorsResult} from '../../services/errorMessagesExtractor/errorMessagesExtractor.interface';\nimport {ValidationErrorsComponent, ValidationErrorsContainerComponent, ValidationErrorsContainerOptions, ValidationErrorsTemplateContext} from '../../services/validationErrorRenderer/validationErrorRenderer.interface';\n\n/**\n * Component that serves as container for validation errors, either component or templates\n */\n@Component(\n{\n selector: 'default-validation-errors-container',\n template: '',\n styleUrls: ['defaultValidationErrorsContainer.component.css'],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class DefaultValidationErrorsContainerComponent implements ValidationErrorsContainerComponent\n{\n //######################### protected fields #########################\n\n /**\n * Errors to be shown\n * @internal\n */\n protected _errors: ValidationErrorsResult;\n \n /**\n * Options used for displaying validation errors\n * @internal\n */\n protected _options: ValidationErrorsContainerOptions;\n\n /**\n * Instance of component reference for rendered errors\n */\n protected _component: ComponentRef<ValidationErrorsComponent>;\n\n /**\n * Instance of template reference for rendered errors\n */\n protected _template: EmbeddedViewRef<ValidationErrorsTemplateContext>;\n\n //######################### constructor #########################\n constructor(protected _viewContainer: ViewContainerRef)\n {\n }\n\n //######################### public methods - implementation of #########################\n\n /**\n * Shows validation errors\n * @param errors - Errors to be shown\n * @param options - Options used for displaying validation errors\n * @param errorClasses - Array of css error classes\n */\n public show(errors: ValidationErrorsResult, options: ValidationErrorsContainerOptions): void\n {\n this._errors = errors;\n this._options = options;\n\n if(options.template)\n {\n this._renderTemplate();\n }\n else if(options.component)\n {\n this._renderComponent();\n }\n else\n {\n throw new Error('Missing template or component for rendering validation errors!');\n }\n }\n\n /**\n * Hides validation errors\n */\n public hide(): void\n {\n this._viewContainer.clear();\n this._component = null;\n this._template = null;\n }\n\n //######################### protected methods #########################\n\n /**\n * Renders validation errors component\n */\n protected _renderComponent(): void\n {\n if(!this._component)\n {\n this._component = this._viewContainer.createComponent(this._options.component);\n }\n\n this._component.instance.show(this._errors, this._options);\n }\n\n /**\n * Renders validation errors template\n */\n protected _renderTemplate(): void\n {\n if(!this._template)\n {\n this._template = this._viewContainer.createEmbeddedView(this._options.template,\n {\n $implicit: this._errors,\n options: this._options\n });\n }\n else\n {\n this._template.context =\n {\n $implicit: this._errors,\n options: this._options\n };\n\n this._template.detectChanges();\n }\n }\n}"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export * from './defaultValidationErrors/defaultValidationErrors.component';
|
|
2
|
+
export * from './defaultValidationErrorsContainer/defaultValidationErrorsContainer.component';
|
|
3
|
+
export * from './reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component';
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../forms/src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,6DAA6D,CAAC;AAC5E,cAAc,+EAA+E,CAAC;AAC9F,cAAc,2FAA2F,CAAC","sourcesContent":["export * from './defaultValidationErrors/defaultValidationErrors.component';\nexport * from './defaultValidationErrorsContainer/defaultValidationErrorsContainer.component';\nexport * from './reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component';\n"]}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Component, ChangeDetectionStrategy, ViewContainerRef, ViewChild } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
//TODO: optimize duplicit code
|
|
4
|
+
/**
|
|
5
|
+
* Component that serves as container for validation errors, either component or templates with reserved space for errors
|
|
6
|
+
*/
|
|
7
|
+
export class ReservedSpaceValidationErrorsContainerComponent {
|
|
8
|
+
//######################### public methods - implementation of #########################
|
|
9
|
+
/**
|
|
10
|
+
* Shows validation errors
|
|
11
|
+
* @param errors - Errors to be shown
|
|
12
|
+
* @param options - Options used for displaying validation errors
|
|
13
|
+
* @param errorClasses - Array of css error classes
|
|
14
|
+
*/
|
|
15
|
+
show(errors, options) {
|
|
16
|
+
this._errors = errors;
|
|
17
|
+
this._options = options;
|
|
18
|
+
if (options.template) {
|
|
19
|
+
this._renderTemplate();
|
|
20
|
+
}
|
|
21
|
+
else if (options.component) {
|
|
22
|
+
this._renderComponent();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
throw new Error('Missing template or component for rendering validation errors!');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hides validation errors
|
|
30
|
+
*/
|
|
31
|
+
hide() {
|
|
32
|
+
this.viewContainer.clear();
|
|
33
|
+
this._component = null;
|
|
34
|
+
this._template = null;
|
|
35
|
+
}
|
|
36
|
+
//######################### protected methods #########################
|
|
37
|
+
/**
|
|
38
|
+
* Renders validation errors component
|
|
39
|
+
*/
|
|
40
|
+
_renderComponent() {
|
|
41
|
+
if (!this._component) {
|
|
42
|
+
this._component = this.viewContainer.createComponent(this._options.component);
|
|
43
|
+
}
|
|
44
|
+
this._component.instance.show(this._errors, this._options);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Renders validation errors template
|
|
48
|
+
*/
|
|
49
|
+
_renderTemplate() {
|
|
50
|
+
if (!this._template) {
|
|
51
|
+
this._template = this.viewContainer.createEmbeddedView(this._options.template, {
|
|
52
|
+
$implicit: this._errors,
|
|
53
|
+
options: this._options
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this._template.context =
|
|
58
|
+
{
|
|
59
|
+
$implicit: this._errors,
|
|
60
|
+
options: this._options
|
|
61
|
+
};
|
|
62
|
+
this._template.detectChanges();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
ReservedSpaceValidationErrorsContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ReservedSpaceValidationErrorsContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
67
|
+
ReservedSpaceValidationErrorsContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.2", type: ReservedSpaceValidationErrorsContainerComponent, selector: "reserved-space-validation-errors-container", viewQueries: [{ propertyName: "viewContainer", first: true, predicate: ["container"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: "<div>\n <ng-container #container></ng-container>\n</div>", styles: [":host\n{\n display: contents;\n}"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
68
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: ReservedSpaceValidationErrorsContainerComponent, decorators: [{
|
|
69
|
+
type: Component,
|
|
70
|
+
args: [{ selector: 'reserved-space-validation-errors-container', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div>\n <ng-container #container></ng-container>\n</div>", styles: [":host\n{\n display: contents;\n}"] }]
|
|
71
|
+
}], propDecorators: { viewContainer: [{
|
|
72
|
+
type: ViewChild,
|
|
73
|
+
args: ['container', { static: true, read: ViewContainerRef }]
|
|
74
|
+
}] } });
|
|
75
|
+
//# sourceMappingURL=reservedSpaceValidationErrorsContainer.component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reservedSpaceValidationErrorsContainer.component.js","sourceRoot":"","sources":["../../../../../forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.ts","../../../../../forms/src/components/reservedSpaceValidationErrorsContainer/reservedSpaceValidationErrorsContainer.component.html"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,uBAAuB,EAAE,gBAAgB,EAAiC,SAAS,EAAC,MAAM,eAAe,CAAC;;AAK7H,8BAA8B;AAE9B;;GAEG;AAQH,MAAM,OAAO,+CAA+C;IAkCxD,yFAAyF;IAEzF;;;;;OAKG;IACI,IAAI,CAAC,MAA8B,EAAE,OAAyC;QAEjF,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QAExB,IAAG,OAAO,CAAC,QAAQ,EACnB;YACI,IAAI,CAAC,eAAe,EAAE,CAAC;SAC1B;aACI,IAAG,OAAO,CAAC,SAAS,EACzB;YACI,IAAI,CAAC,gBAAgB,EAAE,CAAC;SAC3B;aAED;YACI,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;SACrF;IACL,CAAC;IAED;;OAEG;IACI,IAAI;QAEP,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAC3B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,uEAAuE;IAEvE;;OAEG;IACO,gBAAgB;QAEtB,IAAG,CAAC,IAAI,CAAC,UAAU,EACnB;YACI,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;SACjF;QAED,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/D,CAAC;IAED;;OAEG;IACO,eAAe;QAErB,IAAG,CAAC,IAAI,CAAC,SAAS,EAClB;YACI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAC7E;gBACI,SAAS,EAAE,IAAI,CAAC,OAAO;gBACvB,OAAO,EAAE,IAAI,CAAC,QAAQ;aACzB,CAAC,CAAC;SACN;aAED;YACI,IAAI,CAAC,SAAS,CAAC,OAAO;gBACtB;oBACI,SAAS,EAAE,IAAI,CAAC,OAAO;oBACvB,OAAO,EAAE,IAAI,CAAC,QAAQ;iBACzB,CAAC;YAEF,IAAI,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;SAClC;IACL,CAAC;;4IA7GQ,+CAA+C;gIAA/C,+CAA+C,yKA+BX,gBAAgB,2CChDjE,6DAEM;2FDeO,+CAA+C;kBAP3D,SAAS;+BAEI,4CAA4C,mBAGrC,uBAAuB,CAAC,MAAM;8BAkCxC,aAAa;sBADnB,SAAS;uBAAC,WAAW,EAAE,EAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAC","sourcesContent":["import {Component, ChangeDetectionStrategy, ViewContainerRef, ComponentRef, EmbeddedViewRef, ViewChild} from '@angular/core';\n\nimport {ValidationErrorsResult} from '../../services/errorMessagesExtractor/errorMessagesExtractor.interface';\nimport {ValidationErrorsComponent, ValidationErrorsContainerComponent, ValidationErrorsContainerOptions, ValidationErrorsTemplateContext} from '../../services/validationErrorRenderer/validationErrorRenderer.interface';\n\n//TODO: optimize duplicit code\n\n/**\n * Component that serves as container for validation errors, either component or templates with reserved space for errors\n */\n@Component(\n{\n selector: 'reserved-space-validation-errors-container',\n templateUrl: 'reservedSpaceValidationErrorsContainer.component.html',\n styleUrls: ['reservedSpaceValidationErrorsContainer.component.css'],\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class ReservedSpaceValidationErrorsContainerComponent implements ValidationErrorsContainerComponent\n{\n //######################### protected fields #########################\n\n /**\n * Errors to be shown\n * @internal\n */\n protected _errors: ValidationErrorsResult;\n \n /**\n * Options used for displaying validation errors\n * @internal\n */\n protected _options: ValidationErrorsContainerOptions;\n\n /**\n * Instance of component reference for rendered errors\n */\n protected _component: ComponentRef<ValidationErrorsComponent>;\n\n /**\n * Instance of template reference for rendered errors\n */\n protected _template: EmbeddedViewRef<ValidationErrorsTemplateContext>;\n\n //######################### public properties - children #########################\n\n /**\n * View container for rendering validation errors\n */\n @ViewChild('container', {static: true, read: ViewContainerRef})\n public viewContainer: ViewContainerRef;\n\n //######################### public methods - implementation of #########################\n\n /**\n * Shows validation errors\n * @param errors - Errors to be shown\n * @param options - Options used for displaying validation errors\n * @param errorClasses - Array of css error classes\n */\n public show(errors: ValidationErrorsResult, options: ValidationErrorsContainerOptions): void\n {\n this._errors = errors;\n this._options = options;\n\n if(options.template)\n {\n this._renderTemplate();\n }\n else if(options.component)\n {\n this._renderComponent();\n }\n else\n {\n throw new Error('Missing template or component for rendering validation errors!');\n }\n }\n\n /**\n * Hides validation errors\n */\n public hide(): void\n {\n this.viewContainer.clear();\n this._component = null;\n this._template = null;\n }\n\n //######################### protected methods #########################\n\n /**\n * Renders validation errors component\n */\n protected _renderComponent(): void\n {\n if(!this._component)\n {\n this._component = this.viewContainer.createComponent(this._options.component);\n }\n\n this._component.instance.show(this._errors, this._options);\n }\n\n /**\n * Renders validation errors template\n */\n protected _renderTemplate(): void\n {\n if(!this._template)\n {\n this._template = this.viewContainer.createEmbeddedView(this._options.template,\n {\n $implicit: this._errors,\n options: this._options\n });\n }\n else\n {\n this._template.context =\n {\n $implicit: this._errors,\n options: this._options\n };\n\n this._template.detectChanges();\n }\n }\n}","<div>\n <ng-container #container></ng-container>\n</div>"]}
|
package/es2020/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Directive } from '@angular/core';
|
|
2
|
+
import { ValidationErrorsContainerView } from '../../misc/validationErrorsContainerView';
|
|
3
|
+
import { GroupHasErrorDirective } from '../groupHasError/groupHasError.directive';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* Directive that is attached to parent element of inputs group and handles css class that is added to this element and registers provider for ValidationErrorsContainerView
|
|
7
|
+
*/
|
|
8
|
+
export class GroupHasErrorContainerDirective extends GroupHasErrorDirective {
|
|
9
|
+
}
|
|
10
|
+
GroupHasErrorContainerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: GroupHasErrorContainerDirective, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
11
|
+
GroupHasErrorContainerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.2", type: GroupHasErrorContainerDirective, selector: "[groupHasErrorContainer]", providers: [
|
|
12
|
+
{
|
|
13
|
+
provide: GroupHasErrorDirective,
|
|
14
|
+
useExisting: GroupHasErrorContainerDirective
|
|
15
|
+
},
|
|
16
|
+
ValidationErrorsContainerView
|
|
17
|
+
], usesInheritance: true, ngImport: i0 });
|
|
18
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.2", ngImport: i0, type: GroupHasErrorContainerDirective, decorators: [{
|
|
19
|
+
type: Directive,
|
|
20
|
+
args: [{
|
|
21
|
+
selector: '[groupHasErrorContainer]',
|
|
22
|
+
providers: [
|
|
23
|
+
{
|
|
24
|
+
provide: GroupHasErrorDirective,
|
|
25
|
+
useExisting: GroupHasErrorContainerDirective
|
|
26
|
+
},
|
|
27
|
+
ValidationErrorsContainerView
|
|
28
|
+
]
|
|
29
|
+
}]
|
|
30
|
+
}] });
|
|
31
|
+
//# sourceMappingURL=groupHasErrorContainer.directive.js.map
|
package/es2020/forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupHasErrorContainer.directive.js","sourceRoot":"","sources":["../../../../../forms/src/directives/groupHasErrorContainer/groupHasErrorContainer.directive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAmB,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAC,6BAA6B,EAAC,MAAM,0CAA0C,CAAC;AACvF,OAAO,EAAC,sBAAsB,EAAC,MAAM,0CAA0C,CAAC;;AAEhF;;GAEG;AAcH,MAAM,OAAO,+BAAgC,SAAQ,sBAAsB;;4HAA9D,+BAA+B;gHAA/B,+BAA+B,mDATxC;QAEI;YACI,OAAO,EAAE,sBAAsB;YAC/B,WAAW,EAAE,+BAA+B;SAC/C;QACD,6BAA6B;KAChC;2FAEQ,+BAA+B;kBAb3C,SAAS;mBACV;oBACI,QAAQ,EAAE,0BAA0B;oBACpC,SAAS,EACT;wBAEI;4BACI,OAAO,EAAE,sBAAsB;4BAC/B,WAAW,iCAAiC;yBAC/C;wBACD,6BAA6B;qBAChC;iBACJ","sourcesContent":["import {Directive, ExistingProvider} from '@angular/core';\n\nimport {ValidationErrorsContainerView} from '../../misc/validationErrorsContainerView';\nimport {GroupHasErrorDirective} from '../groupHasError/groupHasError.directive';\n\n/**\n * Directive that is attached to parent element of inputs group and handles css class that is added to this element and registers provider for ValidationErrorsContainerView\n */\n@Directive(\n{\n selector: '[groupHasErrorContainer]',\n providers:\n [\n <ExistingProvider>\n {\n provide: GroupHasErrorDirective,\n useExisting: GroupHasErrorContainerDirective\n },\n ValidationErrorsContainerView\n ]\n})\nexport class GroupHasErrorContainerDirective extends GroupHasErrorDirective\n{\n}"]}
|