@gravitee/ui-components 3.25.3-typescript-e7256ca → 3.25.3-typescript-9cbc31e
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,348 @@
|
|
|
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 { link } from '../styles/link';
|
|
18
|
+
import { dispatchCustomEvent } from '../lib/events';
|
|
19
|
+
import { ifDefined } from 'lit/directives/if-defined';
|
|
20
|
+
import { i18n } from '../lib/i18n';
|
|
21
|
+
import { classMap } from 'lit/directives/class-map';
|
|
22
|
+
/**
|
|
23
|
+
* File upload
|
|
24
|
+
*
|
|
25
|
+
* ## Details
|
|
26
|
+
* * has @theme facet
|
|
27
|
+
*
|
|
28
|
+
* @fires gv-file-upload:drop - Custom event when user drop file
|
|
29
|
+
*
|
|
30
|
+
* @attr {String} label - Label
|
|
31
|
+
* @attr {String} accept - One or more file type identifiers describing the authorized file types.
|
|
32
|
+
* @attr {String} except - One or more file type identifiers describing unauthorized file types.
|
|
33
|
+
* @attr {Number} limit - Max size limit in bytes.
|
|
34
|
+
* @attr {String} value - Reflected value of uploaded file
|
|
35
|
+
**/
|
|
36
|
+
export class GvFileUpload extends LitElement {
|
|
37
|
+
static get properties() {
|
|
38
|
+
return {
|
|
39
|
+
label: { type: String },
|
|
40
|
+
accept: { type: String },
|
|
41
|
+
except: { type: String },
|
|
42
|
+
limit: { type: Number },
|
|
43
|
+
value: { type: Array, reflect: true },
|
|
44
|
+
_preview: { type: String, attribute: false },
|
|
45
|
+
_files: { type: Array, attribute: false },
|
|
46
|
+
_errors: { type: Array, attribute: false },
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
static get styles() {
|
|
50
|
+
return [
|
|
51
|
+
link,
|
|
52
|
+
// language=CSS
|
|
53
|
+
css `
|
|
54
|
+
:host {
|
|
55
|
+
box-sizing: border-box;
|
|
56
|
+
display: block;
|
|
57
|
+
width: 100%;
|
|
58
|
+
color: var(--gv-theme-color-dark, #28444f);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.box {
|
|
62
|
+
font-size: 1.25rem;
|
|
63
|
+
background-color: var(--gv-theme-neutral-color-lighter, #fafafa);
|
|
64
|
+
position: relative;
|
|
65
|
+
padding: 2rem;
|
|
66
|
+
text-align: center;
|
|
67
|
+
display: block;
|
|
68
|
+
border: 1px dashed #28444f;
|
|
69
|
+
border-radius: 4px;
|
|
70
|
+
transition: outline-offset 0.15s ease-in-out, background-color 0.15s linear;
|
|
71
|
+
height: 100%;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.box .box__icon {
|
|
75
|
+
width: 100%;
|
|
76
|
+
height: 80px;
|
|
77
|
+
display: block;
|
|
78
|
+
margin-bottom: 40px;
|
|
79
|
+
--gv-icon--s: 5rem;
|
|
80
|
+
--gv-icon--c: var(--gv-theme-color-dark, #28444f);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.box__file {
|
|
84
|
+
width: 0.1px;
|
|
85
|
+
height: 0.1px;
|
|
86
|
+
opacity: 0;
|
|
87
|
+
overflow: hidden;
|
|
88
|
+
position: absolute;
|
|
89
|
+
z-index: -1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.box__file + label {
|
|
93
|
+
max-width: 80%;
|
|
94
|
+
text-overflow: ellipsis;
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
cursor: pointer;
|
|
97
|
+
display: inline-block;
|
|
98
|
+
overflow: hidden;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.box.is-dragover {
|
|
102
|
+
background-color: var(--gv-theme-color-light, #28444f);
|
|
103
|
+
border: none;
|
|
104
|
+
outline: 1px dashed #28444f;
|
|
105
|
+
outline-offset: -10px;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.box .box__dragndrop {
|
|
109
|
+
display: inline;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.files {
|
|
113
|
+
box-sizing: border-box;
|
|
114
|
+
display: flex;
|
|
115
|
+
align-items: center;
|
|
116
|
+
--gv-icon--s: 16px;
|
|
117
|
+
padding: 1rem 0.5rem 0;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.filename {
|
|
121
|
+
flex: 1;
|
|
122
|
+
padding: 0.2rem;
|
|
123
|
+
word-break: break-all;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
.error {
|
|
127
|
+
font-style: italic;
|
|
128
|
+
--gv-icon--c: red;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
gv-image {
|
|
132
|
+
position: absolute;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.preview {
|
|
136
|
+
transition: all 300ms ease-in-out;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.box__input {
|
|
140
|
+
position: relative;
|
|
141
|
+
display: flex;
|
|
142
|
+
flex-direction: column;
|
|
143
|
+
justify-content: center;
|
|
144
|
+
height: 100%;
|
|
145
|
+
z-index: 10;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.preview .box__input {
|
|
149
|
+
visibility: hidden;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
.preview:hover .box__input {
|
|
153
|
+
visibility: visible;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.preview:hover gv-image {
|
|
157
|
+
opacity: 0.3;
|
|
158
|
+
}
|
|
159
|
+
`,
|
|
160
|
+
];
|
|
161
|
+
}
|
|
162
|
+
constructor() {
|
|
163
|
+
super();
|
|
164
|
+
this.reader = new FileReader();
|
|
165
|
+
this._files = [];
|
|
166
|
+
this._errors = [];
|
|
167
|
+
this._counter = 0;
|
|
168
|
+
}
|
|
169
|
+
_onDragOver(e) {
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
e.stopPropagation();
|
|
172
|
+
this._counter++;
|
|
173
|
+
const box = this.shadowRoot.querySelector('.box');
|
|
174
|
+
box.classList.add('is-dragover');
|
|
175
|
+
}
|
|
176
|
+
_onDragEnd(e) {
|
|
177
|
+
e.preventDefault();
|
|
178
|
+
e.stopPropagation();
|
|
179
|
+
if (--this._counter === 0) {
|
|
180
|
+
const box = this.shadowRoot.querySelector('.box');
|
|
181
|
+
box.classList.remove('is-dragover');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
_onDrop(e) {
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
e.stopPropagation();
|
|
187
|
+
this.setFiles(e.dataTransfer.files);
|
|
188
|
+
}
|
|
189
|
+
_getRegex(mimeTypes) {
|
|
190
|
+
return `(${mimeTypes.toString().replace(' ', '').replace(/,/g, '.+|').replace(/\*/g, '.+').replace('.+.+', '.+')})`;
|
|
191
|
+
}
|
|
192
|
+
setFiles(files) {
|
|
193
|
+
const errors = [];
|
|
194
|
+
this._files = [...files].filter((file) => {
|
|
195
|
+
if (this.accept && file.type.match(this._getRegex(this.accept)) == null) {
|
|
196
|
+
errors.push({ file, error: i18n('gv-file-upload.error.typeNotAllowed') });
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
if (this.except && file.type.match(this._getRegex(this.except)) != null) {
|
|
200
|
+
errors.push({ file, error: i18n('gv-file-upload.error.typeNotAllowed') });
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (this.limit && file.size > parseInt(this.limit, 10)) {
|
|
204
|
+
errors.push({ file, error: i18n('gv-file-upload.error.maxSize') });
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
return true;
|
|
208
|
+
});
|
|
209
|
+
this._errors = errors;
|
|
210
|
+
if (this._errors.length > 0) {
|
|
211
|
+
dispatchCustomEvent(this, 'error', { errors: this._errors });
|
|
212
|
+
this.dispatchEvent(new Event('invalid', { bubbles: true, cancelable: true }));
|
|
213
|
+
}
|
|
214
|
+
const box = this.shadowRoot.querySelector('.box');
|
|
215
|
+
box.classList.remove('is-dragover');
|
|
216
|
+
if (this._files.length > 0) {
|
|
217
|
+
this.reader.readAsDataURL(this._files[0]);
|
|
218
|
+
this.reader.onload = (event) => {
|
|
219
|
+
if (this._files[0].type.match(this._getRegex('image/*'))) {
|
|
220
|
+
this._preview = event.target.result;
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
this._preview = null;
|
|
224
|
+
}
|
|
225
|
+
this.value = event.target.result;
|
|
226
|
+
this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
|
|
227
|
+
dispatchCustomEvent(this, 'drop', { files: [this.value] });
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
_cancelEvent(e) {
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
e.stopPropagation();
|
|
234
|
+
}
|
|
235
|
+
_removeFile() {
|
|
236
|
+
this._errors = [];
|
|
237
|
+
this._files = [];
|
|
238
|
+
this._preview = null;
|
|
239
|
+
this.value = null;
|
|
240
|
+
this.shadowRoot.querySelector('#file').value = null;
|
|
241
|
+
this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
|
|
242
|
+
}
|
|
243
|
+
_onChange(e) {
|
|
244
|
+
this.setFiles(e.target.files);
|
|
245
|
+
}
|
|
246
|
+
get icon() {
|
|
247
|
+
if (this._files.length > 0) {
|
|
248
|
+
return 'general:clip';
|
|
249
|
+
}
|
|
250
|
+
return 'general:upload';
|
|
251
|
+
}
|
|
252
|
+
render() {
|
|
253
|
+
const label = this._errors.length > 0 || this._files.length > 0 ? i18n('gv-file-upload.chooseAnotherFile') : i18n('gv-file-upload.chooseFile');
|
|
254
|
+
const classes = {
|
|
255
|
+
box: true,
|
|
256
|
+
preview: this._preview != null,
|
|
257
|
+
};
|
|
258
|
+
return html `
|
|
259
|
+
<label for="file">${this.label}</label>
|
|
260
|
+
<div
|
|
261
|
+
class="${classMap(classes)}"
|
|
262
|
+
@drop="${this._onDrop}"
|
|
263
|
+
@ondrop="${this._onDrop}"
|
|
264
|
+
@drag="${this._cancelEvent}"
|
|
265
|
+
@dragstart="${this._cancelEvent}"
|
|
266
|
+
@dragover="${this._onDragOver}"
|
|
267
|
+
@dragenter="${this._onDragOver}"
|
|
268
|
+
@dragleave="${this._onDragEnd}"
|
|
269
|
+
@dragend="${this._onDragEnd}"
|
|
270
|
+
>
|
|
271
|
+
${this._preview != null ? html `<gv-image .src="${this._preview}" @error="${this._onPreviewError}"></gv-image>` : ''}
|
|
272
|
+
<div class="box__input">
|
|
273
|
+
<gv-icon class="box__icon" shape="${this.icon}"></gv-icon>
|
|
274
|
+
<label for="file" class="link">
|
|
275
|
+
<strong>${label}</strong>
|
|
276
|
+
<span class="box__dragndrop">${i18n('gv-file-upload.orDragIt')}</span>
|
|
277
|
+
</label>
|
|
278
|
+
<input
|
|
279
|
+
class="box__file"
|
|
280
|
+
type="file"
|
|
281
|
+
name="files[]"
|
|
282
|
+
id="file"
|
|
283
|
+
files="${this.files}"
|
|
284
|
+
accept="${ifDefined(this.accept)}"
|
|
285
|
+
@change="${this._onChange}"
|
|
286
|
+
/>
|
|
287
|
+
</div>
|
|
288
|
+
</div>
|
|
289
|
+
${this._files.length > 0
|
|
290
|
+
? html `
|
|
291
|
+
<div class="files">
|
|
292
|
+
<gv-icon shape="general:clip"></gv-icon>
|
|
293
|
+
<div class="filename">${this._files[0].name}</div>
|
|
294
|
+
<gv-icon class="link" @click="${this._removeFile.bind(this, 0)}" shape="general:trash"></gv-icon>
|
|
295
|
+
</div>
|
|
296
|
+
`
|
|
297
|
+
: ''}
|
|
298
|
+
${this._errors.length > 0
|
|
299
|
+
? html `
|
|
300
|
+
<div class="files">
|
|
301
|
+
<gv-icon class="error" shape="code:stop"></gv-icon>
|
|
302
|
+
<div class="filename">${this._errors[0].file.name} <span class="error">(${this._errors[0].error})</span></div>
|
|
303
|
+
</div>
|
|
304
|
+
`
|
|
305
|
+
: ''}
|
|
306
|
+
${this.value && this._files.length === 0 && this._errors.length === 0
|
|
307
|
+
? html `
|
|
308
|
+
<div class="files">
|
|
309
|
+
<div class="filename"></div>
|
|
310
|
+
<gv-button link @click="${this._removeFile.bind(this, 0)}">${i18n('gv-file-upload.removePicture')}</gv-button>
|
|
311
|
+
</div>
|
|
312
|
+
`
|
|
313
|
+
: ''}
|
|
314
|
+
`;
|
|
315
|
+
}
|
|
316
|
+
_onPreviewError() {
|
|
317
|
+
this.value = null;
|
|
318
|
+
}
|
|
319
|
+
updated(changedProperties) {
|
|
320
|
+
if (changedProperties.has('value')) {
|
|
321
|
+
if (this.value) {
|
|
322
|
+
this._preview = this.value;
|
|
323
|
+
if (this._files && this._files[0]) {
|
|
324
|
+
this.reader.readAsDataURL(this._files[0]);
|
|
325
|
+
this.reader.onload = (event) => {
|
|
326
|
+
if (this.value !== event.target.result) {
|
|
327
|
+
this._files = [];
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
this._preview = null;
|
|
334
|
+
this._files = [];
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
const preview = this.shadowRoot.querySelector('.preview');
|
|
338
|
+
if (preview) {
|
|
339
|
+
const { width, height } = preview.getBoundingClientRect();
|
|
340
|
+
const img = this.shadowRoot.querySelector('gv-image');
|
|
341
|
+
img.style.width = width - 20 + 'px';
|
|
342
|
+
img.style.height = height - 20 + 'px';
|
|
343
|
+
img.style.left = '10px';
|
|
344
|
+
img.style.top = '10px';
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
window.customElements.define('gv-file-upload', GvFileUpload);
|
package/src/atoms/gv-icon.js
CHANGED
|
@@ -1 +1,93 @@
|
|
|
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, noChange } from 'lit';
|
|
17
|
+
import { Directive, directive } from 'lit/directive';
|
|
18
|
+
import { classMap } from 'lit/directives/class-map';
|
|
19
|
+
class Namespaced extends Directive {
|
|
20
|
+
update(part, [namespace, value]) {
|
|
21
|
+
part.element.setAttributeNS(namespace, part.name, value);
|
|
22
|
+
return noChange;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const namespaced = directive(Namespaced);
|
|
26
|
+
/**
|
|
27
|
+
* An icon
|
|
28
|
+
*
|
|
29
|
+
* ## Details
|
|
30
|
+
* * has @theme facet
|
|
31
|
+
*
|
|
32
|
+
* @cssprop {Color} [--gv-icon--c=var(--gv-theme-font-color-dark, #262626)] - Color
|
|
33
|
+
* @cssprop {Color} [--gv-icon-opacity--c=var(--gv-theme-font-color-dark, #262626)] - Opacity color
|
|
34
|
+
* @cssprop {Length} [--gv-icon--s=32px] - Height and width
|
|
35
|
+
*/
|
|
36
|
+
export class GvIcon extends LitElement {
|
|
37
|
+
static get properties() {
|
|
38
|
+
return {
|
|
39
|
+
/**
|
|
40
|
+
* This is a shape, an concatenation of category name and icon name.
|
|
41
|
+
* @type {"{category}:{iconName}"}
|
|
42
|
+
* @attr
|
|
43
|
+
* @required
|
|
44
|
+
*/
|
|
45
|
+
shape: { type: String },
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
static get excludedShapes() {
|
|
49
|
+
return ['thirdparty:google', 'thirdparty:graviteeio_am'];
|
|
50
|
+
}
|
|
51
|
+
canCustomize() {
|
|
52
|
+
return ![
|
|
53
|
+
'thirdparty:google',
|
|
54
|
+
'thirdparty:graviteeio_am',
|
|
55
|
+
'thirdparty:http',
|
|
56
|
+
'thirdparty:jdbc',
|
|
57
|
+
'thirdparty:microsoft',
|
|
58
|
+
'thirdparty:mongodb',
|
|
59
|
+
].includes(this.shape);
|
|
60
|
+
}
|
|
61
|
+
static get styles() {
|
|
62
|
+
return [
|
|
63
|
+
// language=CSS
|
|
64
|
+
css `
|
|
65
|
+
:host {
|
|
66
|
+
box-sizing: border-box;
|
|
67
|
+
display: inline-flex;
|
|
68
|
+
vertical-align: middle;
|
|
69
|
+
--color: var(--gv-icon--c, var(--gv-theme-font-color-dark, #262626));
|
|
70
|
+
--opacity: var(--gv-icon-opacity--c, var(--gv-theme-font-color-dark, #262626));
|
|
71
|
+
--size: var(--gv-icon--s, 32px);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
svg {
|
|
75
|
+
height: var(--size);
|
|
76
|
+
width: var(--size);
|
|
77
|
+
fill: var(--color);
|
|
78
|
+
}
|
|
79
|
+
`,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
static getHref(shape) {
|
|
83
|
+
const [category, icon] = shape.split(':');
|
|
84
|
+
return `./icons/${category}.svg#${icon}`;
|
|
85
|
+
}
|
|
86
|
+
render() {
|
|
87
|
+
const xlinkNamespace = 'http://www.w3.org/1999/xlink';
|
|
88
|
+
return html `<svg class="${classMap({ 'no-color': !this.canCustomize() })}">
|
|
89
|
+
<use xlink:href="${namespaced(xlinkNamespace, GvIcon.getHref(this.shape))}" />
|
|
90
|
+
</svg>`;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
window.customElements.define('gv-icon', GvIcon);
|
package/src/atoms/gv-image.js
CHANGED
|
@@ -1 +1,135 @@
|
|
|
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 { LitElement, html, css } from 'lit';
|
|
17
|
+
import { dispatchCustomEvent } from '../lib/events';
|
|
18
|
+
import { classMap } from 'lit/directives/class-map';
|
|
19
|
+
import { ifDefined } from 'lit/directives/if-defined';
|
|
20
|
+
import { skeleton } from '../styles/skeleton';
|
|
21
|
+
/**
|
|
22
|
+
* An image
|
|
23
|
+
*
|
|
24
|
+
* ## Details
|
|
25
|
+
* * has @theme facet
|
|
26
|
+
*
|
|
27
|
+
* @fires gv-image:loaded - When image is loaded
|
|
28
|
+
*
|
|
29
|
+
* @attr {String} src - Source of img
|
|
30
|
+
* @attr {String} alt - Alternative text of img
|
|
31
|
+
* @attr {Boolean} skeleton - enable skeleton screen UI pattern (loading hint)
|
|
32
|
+
*
|
|
33
|
+
* @cssprop {String} [--gv-image--of=cover] - set the object-fit of image
|
|
34
|
+
*/
|
|
35
|
+
export class GvImage extends LitElement {
|
|
36
|
+
static get properties() {
|
|
37
|
+
return {
|
|
38
|
+
src: { type: String },
|
|
39
|
+
skeleton: { type: Boolean, reflect: true },
|
|
40
|
+
alt: { type: String },
|
|
41
|
+
_loaded: { type: Boolean, reflect: true },
|
|
42
|
+
_error: { type: Boolean },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static get styles() {
|
|
46
|
+
return [
|
|
47
|
+
// language=CSS
|
|
48
|
+
css `
|
|
49
|
+
:host {
|
|
50
|
+
display: inline-block;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.wrapper,
|
|
55
|
+
img {
|
|
56
|
+
height: 100%;
|
|
57
|
+
width: 100%;
|
|
58
|
+
transition: opacity 0.3s ease-in-out;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.wrapper {
|
|
62
|
+
align-items: center;
|
|
63
|
+
display: flex;
|
|
64
|
+
justify-content: center;
|
|
65
|
+
position: relative;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.wrapper.text:not('.skeleton') {
|
|
69
|
+
background-color: var(--gv-theme-neutral-color);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
img {
|
|
73
|
+
display: block;
|
|
74
|
+
object-fit: var(--gv-image--of, cover);
|
|
75
|
+
object-position: center center;
|
|
76
|
+
opacity: 0;
|
|
77
|
+
position: absolute;
|
|
78
|
+
top: 0;
|
|
79
|
+
transition: opacity 150ms ease-in-out;
|
|
80
|
+
left: 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.wrapper.loaded img {
|
|
84
|
+
opacity: 1;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.error-msg {
|
|
88
|
+
font-size: 0.9rem;
|
|
89
|
+
overflow: hidden;
|
|
90
|
+
padding: 0.25rem;
|
|
91
|
+
text-align: center;
|
|
92
|
+
text-overflow: ellipsis;
|
|
93
|
+
white-space: nowrap;
|
|
94
|
+
}
|
|
95
|
+
`,
|
|
96
|
+
skeleton,
|
|
97
|
+
];
|
|
98
|
+
}
|
|
99
|
+
constructor() {
|
|
100
|
+
super();
|
|
101
|
+
this.skeleton = false;
|
|
102
|
+
this._error = false;
|
|
103
|
+
this._loaded = false;
|
|
104
|
+
}
|
|
105
|
+
set src(newVal) {
|
|
106
|
+
const oldVal = this._src;
|
|
107
|
+
this._src = newVal;
|
|
108
|
+
this.requestUpdate('src', oldVal);
|
|
109
|
+
this._error = false;
|
|
110
|
+
this._loaded = false;
|
|
111
|
+
}
|
|
112
|
+
get src() {
|
|
113
|
+
return this._src;
|
|
114
|
+
}
|
|
115
|
+
_onLoad(e) {
|
|
116
|
+
this._loaded = true;
|
|
117
|
+
this.skeleton = false;
|
|
118
|
+
dispatchCustomEvent(this, 'loaded', { src: this.src, alt: this.alt });
|
|
119
|
+
}
|
|
120
|
+
_onError(e) {
|
|
121
|
+
this._error = true;
|
|
122
|
+
this.skeleton = false;
|
|
123
|
+
this.dispatchEvent(new Event('error'), e);
|
|
124
|
+
}
|
|
125
|
+
render() {
|
|
126
|
+
const displayText = this.src == null || this._error;
|
|
127
|
+
return html `
|
|
128
|
+
<div class="wrapper ${classMap({ skeleton: this.skeleton, loaded: this._loaded, text: displayText })}">
|
|
129
|
+
<img src=${ifDefined(this.src)} @load=${this._onLoad} @error=${this._onError} alt="" />
|
|
130
|
+
${displayText ? html ` <div class="error-msg">${this.alt}</div> ` : ''}
|
|
131
|
+
</div>
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
window.customElements.define('gv-image', GvImage);
|
|
@@ -1 +1,78 @@
|
|
|
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 '../atoms/gv-icon';
|
|
18
|
+
/**
|
|
19
|
+
* Input message component
|
|
20
|
+
*
|
|
21
|
+
* @attr {String} level - level of message ['info', 'error', 'warning']
|
|
22
|
+
*/
|
|
23
|
+
export class GvInputMessage extends LitElement {
|
|
24
|
+
static get properties() {
|
|
25
|
+
return {
|
|
26
|
+
level: { type: String },
|
|
27
|
+
_level: { type: String, attribute: false },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
constructor() {
|
|
31
|
+
super();
|
|
32
|
+
this._level = 'warning';
|
|
33
|
+
}
|
|
34
|
+
set level(level) {
|
|
35
|
+
if (['error', 'info', 'warning'].includes(level)) {
|
|
36
|
+
this._level = level;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
render() {
|
|
40
|
+
return html `<div class="box"><gv-icon class="${this._level}" shape="code:${this._level}"></gv-icon><slot></slot></div>`;
|
|
41
|
+
}
|
|
42
|
+
static get styles() {
|
|
43
|
+
return [
|
|
44
|
+
// language=CSS
|
|
45
|
+
css `
|
|
46
|
+
:host {
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
display: block;
|
|
49
|
+
margin: 0.2rem;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.box {
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
white-space: normal;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
gv-icon {
|
|
59
|
+
margin: 0 0.2rem;
|
|
60
|
+
--gv-icon--s: 24px;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
gv-icon.warning {
|
|
64
|
+
--gv-icon-opacity--c: var(--gv-theme-color-warning, #ff9800);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
gv-icon.error {
|
|
68
|
+
--gv-icon-opacity--c: var(--gv-theme-color-error, #f44336);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
gv-icon.info {
|
|
72
|
+
--gv-icon-opacity--c: var(--gv-theme-color-info, #2196f3);
|
|
73
|
+
}
|
|
74
|
+
`,
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
window.customElements.define('gv-input-message', GvInputMessage);
|