@gravitee/ui-components 3.25.3-typescript-50960c3 → 3.25.3-typescript-9d19b68
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/package.json +5 -13
- package/src/atoms/gv-autocomplete.js +422 -1
- package/src/atoms/gv-button.js +397 -1
- package/src/atoms/gv-checkbox.js +178 -1
- package/src/atoms/gv-date-picker-calendar.js +812 -1
- package/src/atoms/gv-date-picker-cell.js +174 -1
- package/src/atoms/gv-date-picker.js +638 -1
- package/src/atoms/gv-file-upload.js +348 -1
- package/src/atoms/gv-icon.js +93 -1
- package/src/atoms/gv-image.js +135 -1
- package/src/atoms/gv-input-message.js +78 -1
- package/src/atoms/gv-input.js +508 -1
- package/src/atoms/gv-link.js +204 -1
- package/src/atoms/gv-message.js +133 -1
- package/src/atoms/gv-metric.js +112 -1
- package/src/atoms/gv-relative-time.js +143 -1
- package/src/atoms/gv-select-native.js +363 -1
- package/src/atoms/gv-select.js +413 -1
- package/src/atoms/gv-spinner.js +54 -1
- package/src/atoms/gv-state.js +125 -1
- package/src/atoms/gv-switch.js +235 -1
- package/src/atoms/gv-tag.js +162 -1
- package/src/atoms/gv-text.js +160 -1
- package/src/charts/gv-chart-bar.js +101 -1
- package/src/charts/gv-chart-gauge.js +92 -1
- package/src/charts/gv-chart-histogram.js +78 -1
- package/src/charts/gv-chart-line.js +218 -1
- package/src/charts/gv-chart-map.js +111 -1
- package/src/charts/gv-chart-pie.js +89 -1
- package/src/index.js +77 -1
- package/src/lib/cron-expression.js +176 -1
- package/src/lib/date.js +43 -1
- package/src/lib/events.js +26 -1
- package/src/lib/http-client-schema-form.js +67 -1
- package/src/lib/http.js +237 -1
- package/src/lib/i18n.js +93 -1
- package/src/lib/item.js +110 -1
- package/src/lib/properties.js +171 -1
- package/src/lib/schema-form.js +39 -1
- package/src/lib/studio.js +144 -1
- package/src/lib/style.js +39 -1
- package/src/lib/text-format.js +65 -1
- package/src/lib/theme.js +60 -1
- package/src/lib/utils.js +106 -1
- package/src/mixins/chart-element.js +153 -1
- package/src/mixins/input-element.js +136 -1
- package/src/mixins/item-resource.js +102 -1
- package/src/mixins/keyboard-element.js +62 -1
- package/src/mixins/update-after-browser.js +30 -1
- package/src/mixins/with-resize-observer.js +62 -1
- package/src/mixins/with-skeleton-attribute.js +109 -1
- package/src/molecules/gv-card-full.js +209 -1
- package/src/molecules/gv-card-list.js +101 -1
- package/src/molecules/gv-card.js +130 -1
- package/src/molecules/gv-category-list.js +56 -1
- package/src/molecules/gv-category.js +163 -1
- package/src/molecules/gv-code.js +334 -1
- package/src/molecules/gv-confirm.js +175 -1
- package/src/molecules/gv-cron-editor.js +685 -1
- package/src/molecules/gv-dropdown-menu.js +108 -1
- package/src/molecules/gv-expandable.js +116 -1
- package/src/molecules/gv-expression-language.js +263 -1
- package/src/molecules/gv-identity-picture.js +139 -1
- package/src/molecules/gv-list.js +214 -1
- package/src/molecules/gv-metrics.js +147 -1
- package/src/molecules/gv-modal.js +203 -1
- package/src/molecules/gv-nav.js +180 -1
- package/src/molecules/gv-option.js +230 -1
- package/src/molecules/gv-plans.js +400 -1
- package/src/molecules/gv-popover.js +323 -1
- package/src/molecules/gv-promote.js +203 -1
- package/src/molecules/gv-rating-list.js +341 -1
- package/src/molecules/gv-rating.js +234 -1
- package/src/molecules/gv-row-expandable.js +42 -1
- package/src/molecules/gv-row.js +205 -1
- package/src/molecules/gv-stats.js +110 -1
- package/src/molecules/gv-stepper.js +274 -1
- package/src/molecules/gv-table.js +644 -1
- package/src/molecules/gv-tree.js +238 -1
- package/src/organisms/gv-documentation.js +205 -1
- package/src/organisms/gv-header.js +276 -1
- package/src/organisms/gv-http-client.js +258 -1
- package/src/organisms/gv-menu.js +258 -1
- package/src/organisms/gv-newsletter-subscription.js +258 -1
- package/src/organisms/gv-pagination.js +179 -1
- package/src/organisms/gv-properties.js +860 -1
- package/src/organisms/gv-resizable-views.js +371 -1
- package/src/organisms/gv-resources.js +496 -1
- package/src/organisms/gv-schema-form-array.js +237 -1
- package/src/organisms/gv-schema-form-control-object.js +141 -1
- package/src/organisms/gv-schema-form-control.js +419 -1
- package/src/organisms/gv-schema-form.js +700 -1
- package/src/organisms/gv-tabs.js +201 -1
- package/src/organisms/gv-user-menu.js +298 -1
- package/src/organisms/gv-vertical-menu.js +119 -1
- package/src/policy-studio/gv-flow-step.js +443 -1
- package/src/policy-studio/gv-flow.js +595 -1
- package/src/policy-studio/gv-policy-studio-menu.js +689 -1
- package/src/policy-studio/gv-policy-studio.js +1712 -1
- package/src/styles/empty.js +35 -1
- package/src/styles/input.js +262 -1
- package/src/styles/link.js +31 -1
- package/src/styles/shapes.js +17 -1
- package/src/styles/skeleton.js +52 -1
- package/src/styles/zoom.js +39 -1
- package/src/theme/gv-theme.js +197 -1
- package/wc/gv-autocomplete.js +1 -1
- package/wc/gv-button.js +1 -1
- package/wc/gv-card-full.js +1 -1
- package/wc/gv-card-list.js +1 -1
- package/wc/gv-card.js +1 -1
- package/wc/gv-category-list.js +1 -1
- package/wc/gv-category.js +1 -1
- package/wc/gv-chart-bar.js +1 -1
- package/wc/gv-chart-gauge.js +1 -1
- package/wc/gv-chart-histogram.js +1 -1
- package/wc/gv-chart-line.js +1 -1
- package/wc/gv-chart-map.js +1 -1
- package/wc/gv-chart-pie.js +1 -1
- package/wc/gv-checkbox.js +1 -1
- package/wc/gv-code.js +1 -1
- package/wc/gv-confirm.js +1 -1
- package/wc/gv-cron-editor.js +1 -1
- package/wc/gv-date-picker-calendar.js +1 -1
- package/wc/gv-date-picker-cell.js +1 -1
- package/wc/gv-date-picker.js +1 -1
- package/wc/gv-documentation.js +1 -1
- package/wc/gv-dropdown-menu.js +1 -1
- package/wc/gv-expandable.js +1 -1
- package/wc/gv-expression-language.js +1 -1
- package/wc/gv-file-upload.js +1 -1
- package/wc/gv-flow-step.js +1 -1
- package/wc/gv-flow.js +1 -1
- package/wc/gv-header.js +1 -1
- package/wc/gv-http-client.js +1 -1
- package/wc/gv-icon.js +1 -1
- package/wc/gv-identity-picture.js +1 -1
- package/wc/gv-image.js +1 -1
- package/wc/gv-input-message.js +1 -1
- package/wc/gv-input.js +1 -1
- package/wc/gv-link.js +1 -1
- package/wc/gv-list.js +1 -1
- package/wc/gv-menu.js +1 -1
- package/wc/gv-message.js +1 -1
- package/wc/gv-metric.js +1 -1
- package/wc/gv-metrics.js +1 -1
- package/wc/gv-modal.js +1 -1
- package/wc/gv-nav.js +1 -1
- package/wc/gv-newsletter-subscription.js +1 -1
- package/wc/gv-option.js +1 -1
- package/wc/gv-pagination.js +1 -1
- package/wc/gv-plans.js +1 -1
- package/wc/gv-policy-studio-menu.js +1 -1
- package/wc/gv-policy-studio.js +1 -1
- package/wc/gv-popover.js +1 -1
- package/wc/gv-promote.js +1 -1
- package/wc/gv-properties.js +1 -1
- package/wc/gv-rating-list.js +1 -1
- package/wc/gv-rating.js +1 -1
- package/wc/gv-relative-time.js +1 -1
- package/wc/gv-resizable-views.js +1 -1
- package/wc/gv-resources.js +1 -1
- package/wc/gv-row-expandable.js +1 -1
- package/wc/gv-row.js +1 -1
- package/wc/gv-schema-form-array.js +1 -1
- package/wc/gv-schema-form-control-object.js +1 -1
- package/wc/gv-schema-form-control.js +1 -1
- package/wc/gv-schema-form.js +1 -1
- package/wc/gv-select-native.js +1 -1
- package/wc/gv-select.js +1 -1
- package/wc/gv-spinner.js +1 -1
- package/wc/gv-state.js +1 -1
- package/wc/gv-stats.js +1 -1
- package/wc/gv-stepper.js +1 -1
- package/wc/gv-switch.js +1 -1
- package/wc/gv-table.js +1 -1
- package/wc/gv-tabs.js +1 -1
- package/wc/gv-tag.js +1 -1
- package/wc/gv-text.js +1 -1
- package/wc/gv-theme.js +1 -1
- package/wc/gv-tree.js +1 -1
- package/wc/gv-user-menu.js +1 -1
- package/wc/gv-vertical-menu.js +1 -1
|
@@ -1 +1,419 @@
|
|
|
1
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { css, LitElement, html } from 'lit';
|
|
17
|
+
import { dispatchCustomEvent } from '../lib/events';
|
|
18
|
+
import '../atoms/gv-input';
|
|
19
|
+
import '../atoms/gv-input-message';
|
|
20
|
+
import '../atoms/gv-text';
|
|
21
|
+
import '../atoms/gv-select';
|
|
22
|
+
import '../atoms/gv-select-native';
|
|
23
|
+
import '../atoms/gv-switch';
|
|
24
|
+
import '../molecules/gv-code';
|
|
25
|
+
import '../molecules/gv-expression-language';
|
|
26
|
+
import '../molecules/gv-cron-editor';
|
|
27
|
+
import '../atoms/gv-autocomplete';
|
|
28
|
+
import '../organisms/gv-schema-form-array';
|
|
29
|
+
import '../organisms/gv-schema-form-control-object';
|
|
30
|
+
import { isCodemirror, isObject, isComplexArray } from '../lib/schema-form';
|
|
31
|
+
import { UpdateAfterBrowser } from '../mixins/update-after-browser';
|
|
32
|
+
export class GvSchemaFormControl extends UpdateAfterBrowser(LitElement) {
|
|
33
|
+
static get properties() {
|
|
34
|
+
return {
|
|
35
|
+
type: { type: String },
|
|
36
|
+
id: { type: String, reflect: true },
|
|
37
|
+
name: { type: String, reflect: true },
|
|
38
|
+
required: { type: Boolean, reflect: true },
|
|
39
|
+
disabled: { type: Boolean, reflect: true },
|
|
40
|
+
readonly: { type: Boolean, reflect: true },
|
|
41
|
+
title: { type: String, reflect: true },
|
|
42
|
+
pattern: { type: String },
|
|
43
|
+
control: { type: Object },
|
|
44
|
+
errors: { type: Array },
|
|
45
|
+
value: { type: Object, reflect: true },
|
|
46
|
+
skeleton: { type: Boolean, reflect: true },
|
|
47
|
+
hidden: { type: Boolean, reflect: true },
|
|
48
|
+
writeOnly: { type: Boolean, reflect: true },
|
|
49
|
+
compact: { type: Boolean },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
constructor() {
|
|
53
|
+
super();
|
|
54
|
+
// When form has errors, the control is not update to conserve the error state.
|
|
55
|
+
// This list is used to force the update of properties even in error case.
|
|
56
|
+
this._observedProperties = ['disabled', 'readonly', 'required'];
|
|
57
|
+
}
|
|
58
|
+
isExpressionLanguage() {
|
|
59
|
+
return this.control['x-schema-form'] && this.control['x-schema-form']['expression-language'] != null;
|
|
60
|
+
}
|
|
61
|
+
isCronExpression() {
|
|
62
|
+
return this.control['x-schema-form'] && this.control['x-schema-form']['cron-expression'] === true;
|
|
63
|
+
}
|
|
64
|
+
isPassword() {
|
|
65
|
+
return (this.control.writeOnly === true ||
|
|
66
|
+
(this.control['x-schema-form'] && this.control['x-schema-form'].type != null && this.control['x-schema-form'].type === 'password'));
|
|
67
|
+
}
|
|
68
|
+
getPlaceholder() {
|
|
69
|
+
return this.control['x-schema-form'] && this.control['x-schema-form'].placeholder ? this.control['x-schema-form'].placeholder : null;
|
|
70
|
+
}
|
|
71
|
+
isCodemirror() {
|
|
72
|
+
return isCodemirror(this.control);
|
|
73
|
+
}
|
|
74
|
+
isObject() {
|
|
75
|
+
return isObject(this.control);
|
|
76
|
+
}
|
|
77
|
+
isAutocomplete() {
|
|
78
|
+
return this.control['x-schema-form'] && this.control['x-schema-form'].event != null && this.control.type === 'string';
|
|
79
|
+
}
|
|
80
|
+
isText() {
|
|
81
|
+
return this.control['x-schema-form'] && this.control['x-schema-form'].type === 'text' && this.control.type === 'string';
|
|
82
|
+
}
|
|
83
|
+
getElementName() {
|
|
84
|
+
if (this.isObject()) {
|
|
85
|
+
return 'gv-schema-form-control-object';
|
|
86
|
+
}
|
|
87
|
+
if ((this.control.enum || (this.control.items && this.control.items.enum)) && !this.isAutocomplete()) {
|
|
88
|
+
if (this.control.type === 'array') {
|
|
89
|
+
return 'gv-select';
|
|
90
|
+
}
|
|
91
|
+
return 'gv-select-native';
|
|
92
|
+
}
|
|
93
|
+
else if (isComplexArray(this.control)) {
|
|
94
|
+
return 'gv-schema-form-array';
|
|
95
|
+
}
|
|
96
|
+
else if (this.control.type === 'array') {
|
|
97
|
+
return 'gv-button';
|
|
98
|
+
}
|
|
99
|
+
else if (this.control.type === 'boolean') {
|
|
100
|
+
return 'gv-switch';
|
|
101
|
+
}
|
|
102
|
+
else if (this.isExpressionLanguage()) {
|
|
103
|
+
return 'gv-expression-language';
|
|
104
|
+
}
|
|
105
|
+
else if (this.isCodemirror()) {
|
|
106
|
+
return 'gv-code';
|
|
107
|
+
}
|
|
108
|
+
else if (this.isCronExpression()) {
|
|
109
|
+
return 'gv-cron-editor';
|
|
110
|
+
}
|
|
111
|
+
else if (this.isText()) {
|
|
112
|
+
return 'gv-text';
|
|
113
|
+
}
|
|
114
|
+
return 'gv-input';
|
|
115
|
+
}
|
|
116
|
+
_updateProperties(element) {
|
|
117
|
+
if (element != null) {
|
|
118
|
+
this._observedProperties.forEach((property) => {
|
|
119
|
+
if (this[property] != null) {
|
|
120
|
+
element[property] = this[property];
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_renderControl() {
|
|
126
|
+
const elementName = this.getElementName();
|
|
127
|
+
const element = document.createElement(elementName);
|
|
128
|
+
element.id = this.id;
|
|
129
|
+
element.name = this.id;
|
|
130
|
+
element.skeleton = this.skeleton;
|
|
131
|
+
element.classList.add('form__control');
|
|
132
|
+
if (this.value == null && this.control.default != null) {
|
|
133
|
+
this.value = this.control.default;
|
|
134
|
+
dispatchCustomEvent(this, 'default-value', { value: this.value, currentTarget: element, control: this.control });
|
|
135
|
+
}
|
|
136
|
+
if (this.value != null) {
|
|
137
|
+
this._setValue(element);
|
|
138
|
+
}
|
|
139
|
+
if (this.control.type === 'object') {
|
|
140
|
+
element.schema = this.control;
|
|
141
|
+
}
|
|
142
|
+
else if (isComplexArray(this.control)) {
|
|
143
|
+
element.schema = this.control.items;
|
|
144
|
+
}
|
|
145
|
+
this._updateProperties(element);
|
|
146
|
+
if (this.control.title) {
|
|
147
|
+
element.label = this.control.title;
|
|
148
|
+
element.title = this.control.title;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const tmp = this.id.split('.');
|
|
152
|
+
const title = tmp[tmp.length - 1];
|
|
153
|
+
if (isNaN(parseInt(title, 10))) {
|
|
154
|
+
element.label = title;
|
|
155
|
+
element.title = title;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (this.control.pattern) {
|
|
159
|
+
element.pattern = this.control.pattern;
|
|
160
|
+
}
|
|
161
|
+
if (this.control.type === 'integer') {
|
|
162
|
+
element.type = 'number';
|
|
163
|
+
}
|
|
164
|
+
if (this.isText()) {
|
|
165
|
+
element.rows = 3;
|
|
166
|
+
element.autosize = true;
|
|
167
|
+
element.placeholder = this.control.description;
|
|
168
|
+
}
|
|
169
|
+
const placeholder = this.getPlaceholder();
|
|
170
|
+
if (this.control.enum || (this.control.items && this.control.items.enum)) {
|
|
171
|
+
const options = this.control.enum || this.control.items.enum;
|
|
172
|
+
if (this.control['x-schema-form'] && this.control['x-schema-form'].titleMap) {
|
|
173
|
+
element.options = options.map((value) => ({
|
|
174
|
+
value,
|
|
175
|
+
label: this.control['x-schema-form'].titleMap[value] || value,
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
element.options = options;
|
|
180
|
+
}
|
|
181
|
+
if (this.control.type === 'array') {
|
|
182
|
+
element.multiple = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (this.isCodemirror()) {
|
|
186
|
+
element.options = this.control['x-schema-form'].codemirrorOptions;
|
|
187
|
+
if (this.control.default != null && element.options.value == null) {
|
|
188
|
+
element.options.value = this.control.default;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
else if (this.isExpressionLanguage()) {
|
|
192
|
+
element.options = {};
|
|
193
|
+
element.rows = 1;
|
|
194
|
+
}
|
|
195
|
+
else if (this.isPassword()) {
|
|
196
|
+
element.type = 'password';
|
|
197
|
+
}
|
|
198
|
+
if (this.control.description) {
|
|
199
|
+
element.description = this.control.description;
|
|
200
|
+
}
|
|
201
|
+
if (this.compact) {
|
|
202
|
+
element.placeholder = element.description || element.label;
|
|
203
|
+
element.label = null;
|
|
204
|
+
element.description = null;
|
|
205
|
+
element.compact = this.compact;
|
|
206
|
+
}
|
|
207
|
+
if (placeholder != null) {
|
|
208
|
+
if (this.isExpressionLanguage() || this.isCodemirror()) {
|
|
209
|
+
element.options.placeholder = placeholder;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
element.placeholder = placeholder;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
element.addEventListener(`${elementName}:input`, this._onInput.bind(this));
|
|
216
|
+
let currentTarget;
|
|
217
|
+
if (this.isAutocomplete()) {
|
|
218
|
+
const autocomplete = document.createElement('gv-autocomplete');
|
|
219
|
+
autocomplete.minChars = 0;
|
|
220
|
+
autocomplete.filter = true;
|
|
221
|
+
element.clearable = true;
|
|
222
|
+
autocomplete.id = this.id;
|
|
223
|
+
autocomplete.appendChild(element);
|
|
224
|
+
autocomplete.addEventListener(`gv-autocomplete:select`, this._onInput.bind(this));
|
|
225
|
+
element.addEventListener(`gv-input:clear`, this._onInput.bind(this));
|
|
226
|
+
currentTarget = autocomplete;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
currentTarget = element;
|
|
230
|
+
}
|
|
231
|
+
if (this.control['x-schema-form'] != null) {
|
|
232
|
+
dispatchCustomEvent(this, 'control-ready', {
|
|
233
|
+
currentTarget,
|
|
234
|
+
control: this,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
return currentTarget;
|
|
238
|
+
}
|
|
239
|
+
_onInput(e) {
|
|
240
|
+
e.preventDefault();
|
|
241
|
+
e.stopPropagation();
|
|
242
|
+
let value = null;
|
|
243
|
+
if (e.target.tagName === 'GV-AUTOCOMPLETE') {
|
|
244
|
+
value = e.detail.value;
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
value = e.detail;
|
|
248
|
+
}
|
|
249
|
+
dispatchCustomEvent(this, 'change', { value, currentTarget: e.target, control: this.control });
|
|
250
|
+
}
|
|
251
|
+
getControls() {
|
|
252
|
+
return [
|
|
253
|
+
...Array.from(this.shadowRoot.querySelectorAll('gv-schema-form-control')),
|
|
254
|
+
...Array.from(this.shadowRoot.querySelectorAll('gv-schema-form-control-array')),
|
|
255
|
+
...Array.from(this.shadowRoot.querySelectorAll('gv-schema-form-control-object')),
|
|
256
|
+
];
|
|
257
|
+
}
|
|
258
|
+
getControl(id) {
|
|
259
|
+
if (id == null) {
|
|
260
|
+
id = this.id;
|
|
261
|
+
}
|
|
262
|
+
return this.shadowRoot.querySelector(`[id="${id}"]`);
|
|
263
|
+
}
|
|
264
|
+
_setValue(controlElement) {
|
|
265
|
+
if (this.value != null && controlElement != null) {
|
|
266
|
+
if (this.control.type === 'boolean' || this.control.type === 'array' || this.control.type === 'object') {
|
|
267
|
+
controlElement.value = this.value;
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
controlElement.value = this.value.toString ? this.value.toString() : this.value;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return controlElement;
|
|
274
|
+
}
|
|
275
|
+
async updated(changedProperties) {
|
|
276
|
+
if (changedProperties.has('value')) {
|
|
277
|
+
Promise.all(this.getControls().map((control) => control.updateComplete)).then(() => {
|
|
278
|
+
this._setValue(this.getControl());
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
async getUpdateComplete() {
|
|
283
|
+
await super.getUpdateComplete();
|
|
284
|
+
await Promise.all(this.getControls().map((e) => e.updateComplete));
|
|
285
|
+
}
|
|
286
|
+
formatErrorMessage(error) {
|
|
287
|
+
let title;
|
|
288
|
+
if (this.control.properties != null && this.control.properties[error.argument] != null) {
|
|
289
|
+
title = this.control.properties[error.argument].title;
|
|
290
|
+
}
|
|
291
|
+
else {
|
|
292
|
+
title = this.control.title;
|
|
293
|
+
}
|
|
294
|
+
if (title) {
|
|
295
|
+
return `<span>${error.message.replace(error.argument, title)}</span>`;
|
|
296
|
+
}
|
|
297
|
+
return `<span>${error.message}</span>`;
|
|
298
|
+
}
|
|
299
|
+
shouldUpdate(changedProperties) {
|
|
300
|
+
if (this._observedProperties.find((property) => changedProperties.has(property)) != null) {
|
|
301
|
+
this._updateProperties(this.getControl());
|
|
302
|
+
}
|
|
303
|
+
if (changedProperties.has('errors') && this.errors != null) {
|
|
304
|
+
// Set errors to complex controls
|
|
305
|
+
this.getControls().forEach((control) => {
|
|
306
|
+
control.errors = this.errors;
|
|
307
|
+
});
|
|
308
|
+
// Find simple controls and append error message
|
|
309
|
+
const errorContainer = this.shadowRoot.querySelectorAll('.form__control-error');
|
|
310
|
+
errorContainer.forEach((container) => (container.innerHTML = ''));
|
|
311
|
+
this.errors.forEach((error) => {
|
|
312
|
+
const key = error.property === 'instance' ? error.argument : error.property.replace('instance.', '');
|
|
313
|
+
const errorContainer = this.shadowRoot.querySelector(`[id="${key}-error"]`);
|
|
314
|
+
if (errorContainer) {
|
|
315
|
+
const message = document.createElement('gv-input-message');
|
|
316
|
+
message.innerHTML = this.formatErrorMessage(error);
|
|
317
|
+
message.level = 'warn';
|
|
318
|
+
errorContainer.appendChild(message);
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
return super.shouldUpdate(changedProperties);
|
|
324
|
+
}
|
|
325
|
+
render() {
|
|
326
|
+
return html `
|
|
327
|
+
${this._renderControl()}
|
|
328
|
+
<div class="form__control-error" id="${this.id + '-error'}"></div>
|
|
329
|
+
`;
|
|
330
|
+
}
|
|
331
|
+
static get styles() {
|
|
332
|
+
return [
|
|
333
|
+
// language=CSS
|
|
334
|
+
css `
|
|
335
|
+
:host {
|
|
336
|
+
box-sizing: border-box;
|
|
337
|
+
margin: var(--gv-schema-form-control--m, 0.4rem);
|
|
338
|
+
display: block;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
:host([hidden]) {
|
|
342
|
+
visibility: hidden;
|
|
343
|
+
height: 0;
|
|
344
|
+
margin: 0;
|
|
345
|
+
padding: 0;
|
|
346
|
+
overflow: hidden;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.form__control-description,
|
|
350
|
+
.form__control-error {
|
|
351
|
+
font-size: 12px;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.form__control-description {
|
|
355
|
+
opacity: 0.8;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
.form__control-label {
|
|
359
|
+
display: flex;
|
|
360
|
+
flex-direction: row;
|
|
361
|
+
border-bottom: 1px solid #d9d9d9;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
label {
|
|
365
|
+
margin: 0.2rem;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
.form__control-label label {
|
|
369
|
+
flex: 1;
|
|
370
|
+
text-transform: capitalize;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
.form__control-array,
|
|
374
|
+
.form__control-object {
|
|
375
|
+
display: flex;
|
|
376
|
+
flex-direction: column;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
.form__control-enum {
|
|
380
|
+
display: flex;
|
|
381
|
+
/*align-items: flex-end;*/
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
.form__control-array gv-button {
|
|
385
|
+
align-self: flex-end;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
.form__control {
|
|
389
|
+
position: relative;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
gv-select,
|
|
393
|
+
gv-select-native,
|
|
394
|
+
gv-input,
|
|
395
|
+
gv-code,
|
|
396
|
+
gv-switch,
|
|
397
|
+
gv-expression-language {
|
|
398
|
+
width: 100%;
|
|
399
|
+
margin: 0.2rem 0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
gv-select:hover,
|
|
403
|
+
gv-select-native:hover,
|
|
404
|
+
gv-autocomplete:hover {
|
|
405
|
+
z-index: 70;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
.error {
|
|
409
|
+
color: var(--gv-theme-color-error, #f44336);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
.warning {
|
|
413
|
+
color: var(--gv-theme-color-warning, #ff9800);
|
|
414
|
+
}
|
|
415
|
+
`,
|
|
416
|
+
];
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
window.customElements.define('gv-schema-form-control', GvSchemaFormControl);
|