@gravitee/ui-components 3.25.3-typescript-ad6021f → 3.25.3-typescript-bfd8f67

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.
Files changed (188) hide show
  1. package/package.json +5 -8
  2. package/src/atoms/gv-autocomplete.js +1 -461
  3. package/src/atoms/gv-button.js +1 -410
  4. package/src/atoms/gv-checkbox.js +1 -187
  5. package/src/atoms/gv-date-picker-calendar.js +1 -894
  6. package/src/atoms/gv-date-picker-cell.js +1 -190
  7. package/src/atoms/gv-date-picker.js +1 -671
  8. package/src/atoms/gv-file-upload.js +1 -367
  9. package/src/atoms/gv-icon.js +1 -103
  10. package/src/atoms/gv-image.js +1 -144
  11. package/src/atoms/gv-input-message.js +1 -84
  12. package/src/atoms/gv-input.js +1 -561
  13. package/src/atoms/gv-link.js +1 -210
  14. package/src/atoms/gv-message.js +1 -128
  15. package/src/atoms/gv-metric.js +1 -117
  16. package/src/atoms/gv-relative-time.js +1 -156
  17. package/src/atoms/gv-select-native.js +1 -388
  18. package/src/atoms/gv-select.js +1 -437
  19. package/src/atoms/gv-spinner.js +1 -57
  20. package/src/atoms/gv-state.js +1 -130
  21. package/src/atoms/gv-switch.js +1 -243
  22. package/src/atoms/gv-tag.js +1 -168
  23. package/src/atoms/gv-text.js +1 -168
  24. package/src/charts/gv-chart-bar.js +1 -103
  25. package/src/charts/gv-chart-gauge.js +1 -100
  26. package/src/charts/gv-chart-histogram.js +1 -83
  27. package/src/charts/gv-chart-line.js +1 -224
  28. package/src/charts/gv-chart-map.js +1 -112
  29. package/src/charts/gv-chart-pie.js +1 -91
  30. package/src/index.js +1 -77
  31. package/src/lib/cron-expression.js +1 -205
  32. package/src/lib/date.js +1 -44
  33. package/src/lib/events.js +1 -26
  34. package/src/lib/http-client-schema-form.js +1 -67
  35. package/src/lib/http.js +1 -237
  36. package/src/lib/i18n.js +1 -103
  37. package/src/lib/item.js +1 -118
  38. package/src/lib/properties.js +1 -189
  39. package/src/lib/schema-form.js +1 -44
  40. package/src/lib/studio.js +1 -141
  41. package/src/lib/style.js +1 -41
  42. package/src/lib/text-format.js +1 -69
  43. package/src/lib/theme.js +1 -63
  44. package/src/lib/utils.js +1 -111
  45. package/src/mixins/chart-element.js +1 -165
  46. package/src/mixins/input-element.js +1 -144
  47. package/src/mixins/item-resource.js +1 -120
  48. package/src/mixins/keyboard-element.js +1 -69
  49. package/src/mixins/update-after-browser.js +1 -30
  50. package/src/mixins/with-resize-observer.js +1 -68
  51. package/src/mixins/with-skeleton-attribute.js +1 -112
  52. package/src/molecules/gv-card-full.js +1 -218
  53. package/src/molecules/gv-card-list.js +1 -113
  54. package/src/molecules/gv-card.js +1 -133
  55. package/src/molecules/gv-category-list.js +1 -60
  56. package/src/molecules/gv-category.js +1 -170
  57. package/src/molecules/gv-code.js +1 -359
  58. package/src/molecules/gv-confirm.js +1 -188
  59. package/src/molecules/gv-cron-editor.js +1 -710
  60. package/src/molecules/gv-dropdown-menu.js +1 -116
  61. package/src/molecules/gv-expandable.js +1 -122
  62. package/src/molecules/gv-expression-language.js +1 -270
  63. package/src/molecules/gv-identity-picture.js +1 -148
  64. package/src/molecules/gv-list.js +1 -227
  65. package/src/molecules/gv-metrics.js +1 -162
  66. package/src/molecules/gv-modal.js +1 -213
  67. package/src/molecules/gv-nav.js +1 -196
  68. package/src/molecules/gv-option.js +1 -242
  69. package/src/molecules/gv-plans.js +1 -429
  70. package/src/molecules/gv-popover.js +1 -351
  71. package/src/molecules/gv-promote.js +1 -209
  72. package/src/molecules/gv-rating-list.js +1 -365
  73. package/src/molecules/gv-rating.js +1 -253
  74. package/src/molecules/gv-row-expandable.js +1 -45
  75. package/src/molecules/gv-row.js +1 -210
  76. package/src/molecules/gv-stats.js +1 -121
  77. package/src/molecules/gv-stepper.js +1 -288
  78. package/src/molecules/gv-table.js +1 -685
  79. package/src/molecules/gv-tree.js +1 -250
  80. package/src/organisms/gv-documentation.js +1 -215
  81. package/src/organisms/gv-header.js +1 -288
  82. package/src/organisms/gv-http-client.js +1 -275
  83. package/src/organisms/gv-menu.js +1 -263
  84. package/src/organisms/gv-newsletter-subscription.js +1 -271
  85. package/src/organisms/gv-pagination.js +1 -198
  86. package/src/organisms/gv-properties.js +1 -920
  87. package/src/organisms/gv-resizable-views.js +1 -396
  88. package/src/organisms/gv-resources.js +1 -535
  89. package/src/organisms/gv-schema-form-array.js +1 -250
  90. package/src/organisms/gv-schema-form-control-object.js +1 -154
  91. package/src/organisms/gv-schema-form-control.js +1 -443
  92. package/src/organisms/gv-schema-form.js +1 -751
  93. package/src/organisms/gv-tabs.js +1 -210
  94. package/src/organisms/gv-user-menu.js +1 -314
  95. package/src/organisms/gv-vertical-menu.js +1 -123
  96. package/src/policy-studio/gv-flow-step.js +1 -464
  97. package/src/policy-studio/gv-flow.js +1 -621
  98. package/src/policy-studio/gv-policy-studio-menu.js +1 -750
  99. package/src/policy-studio/gv-policy-studio.js +1 -1842
  100. package/src/styles/empty.js +1 -36
  101. package/src/styles/input.js +1 -263
  102. package/src/styles/link.js +1 -32
  103. package/src/styles/shapes.js +1 -17
  104. package/src/styles/skeleton.js +1 -53
  105. package/src/styles/zoom.js +1 -40
  106. package/src/theme/gv-theme.js +1 -203
  107. package/wc/gv-autocomplete.js +1 -1
  108. package/wc/gv-button.js +1 -1
  109. package/wc/gv-card-full.js +1 -1
  110. package/wc/gv-card-list.js +1 -1
  111. package/wc/gv-card.js +1 -1
  112. package/wc/gv-category-list.js +1 -1
  113. package/wc/gv-category.js +1 -1
  114. package/wc/gv-chart-bar.js +1 -1
  115. package/wc/gv-chart-gauge.js +1 -1
  116. package/wc/gv-chart-histogram.js +1 -1
  117. package/wc/gv-chart-line.js +1 -1
  118. package/wc/gv-chart-map.js +1 -1
  119. package/wc/gv-chart-pie.js +1 -1
  120. package/wc/gv-checkbox.js +1 -1
  121. package/wc/gv-code.js +1 -1
  122. package/wc/gv-confirm.js +1 -1
  123. package/wc/gv-cron-editor.js +1 -1
  124. package/wc/gv-date-picker-calendar.js +1 -1
  125. package/wc/gv-date-picker-cell.js +1 -1
  126. package/wc/gv-date-picker.js +1 -1
  127. package/wc/gv-documentation.js +1 -1
  128. package/wc/gv-dropdown-menu.js +1 -1
  129. package/wc/gv-expandable.js +1 -1
  130. package/wc/gv-expression-language.js +1 -1
  131. package/wc/gv-file-upload.js +1 -1
  132. package/wc/gv-flow-step.js +1 -1
  133. package/wc/gv-flow.js +1 -1
  134. package/wc/gv-header.js +1 -1
  135. package/wc/gv-http-client.js +1 -1
  136. package/wc/gv-icon.js +1 -1
  137. package/wc/gv-identity-picture.js +1 -1
  138. package/wc/gv-image.js +1 -1
  139. package/wc/gv-input-message.js +1 -1
  140. package/wc/gv-input.js +1 -1
  141. package/wc/gv-link.js +1 -1
  142. package/wc/gv-list.js +1 -1
  143. package/wc/gv-menu.js +1 -1
  144. package/wc/gv-message.js +1 -1
  145. package/wc/gv-metric.js +1 -1
  146. package/wc/gv-metrics.js +1 -1
  147. package/wc/gv-modal.js +1 -1
  148. package/wc/gv-nav.js +1 -1
  149. package/wc/gv-newsletter-subscription.js +1 -1
  150. package/wc/gv-option.js +1 -1
  151. package/wc/gv-pagination.js +1 -1
  152. package/wc/gv-plans.js +1 -1
  153. package/wc/gv-policy-studio-menu.js +1 -1
  154. package/wc/gv-policy-studio.js +1 -1
  155. package/wc/gv-popover.js +1 -1
  156. package/wc/gv-promote.js +1 -1
  157. package/wc/gv-properties.js +1 -1
  158. package/wc/gv-rating-list.js +1 -1
  159. package/wc/gv-rating.js +1 -1
  160. package/wc/gv-relative-time.js +1 -1
  161. package/wc/gv-resizable-views.js +1 -1
  162. package/wc/gv-resources.js +1 -1
  163. package/wc/gv-row-expandable.js +1 -1
  164. package/wc/gv-row.js +1 -1
  165. package/wc/gv-schema-form-array.js +1 -1
  166. package/wc/gv-schema-form-control-object.js +1 -1
  167. package/wc/gv-schema-form-control.js +1 -1
  168. package/wc/gv-schema-form.js +1 -1
  169. package/wc/gv-select-native.js +1 -1
  170. package/wc/gv-select.js +1 -1
  171. package/wc/gv-spinner.js +1 -1
  172. package/wc/gv-state.js +1 -1
  173. package/wc/gv-stats.js +1 -1
  174. package/wc/gv-stepper.js +1 -1
  175. package/wc/gv-switch.js +1 -1
  176. package/wc/gv-table.js +1 -1
  177. package/wc/gv-tabs.js +1 -1
  178. package/wc/gv-tag.js +1 -1
  179. package/wc/gv-text.js +1 -1
  180. package/wc/gv-theme.js +1 -1
  181. package/wc/gv-tree.js +1 -1
  182. package/wc/gv-user-menu.js +1 -1
  183. package/wc/gv-vertical-menu.js +1 -1
  184. package/CHANGELOG.md +0 -1292
  185. package/LICENSE.txt +0 -202
  186. package/README.md +0 -195
  187. package/src/.eslintrc.js +0 -19
  188. package/src/theme/definition.json +0 -1762
@@ -1,388 +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 { classMap } from 'lit/directives/class-map';
17
- import { ifDefined } from 'lit/directives/if-defined';
18
- import { repeat } from 'lit/directives/repeat';
19
-
20
- import { css, html, LitElement } from 'lit';
21
- import { skeleton } from '../styles/skeleton';
22
- import { link } from '../styles/link';
23
- import { input } from '../styles/input';
24
- import { dispatchCustomEvent } from '../lib/events';
25
- import { InputElement } from '../mixins/input-element';
26
- import { i18n } from '../lib/i18n';
27
-
28
- /**
29
- * A select native component.
30
- *
31
- * @fires gv-select:select - Event when user select a value (deprecated, use gv-select:input)
32
- * @fires gv-select:input - Event when user select a value
33
- *
34
- * @attr {Boolean} disabled - same as native select element `disabled` attribute
35
- * @attr {Boolean} required - same as native select element `required` attribute
36
- * @attr {Boolean} skeleton - enable skeleton screen UI pattern (loading hint)
37
- * @attr {Array} options - the options of the select
38
- * @attr {String | Array} value - the value of the select
39
- * @attr {String} label - label of the select
40
- * @attr {String} title - title of the select
41
- * @attr {String} name - name of the select
42
- * @attr {String} placeholder - an example value to display in the select when empty
43
- * @attr {String} description - a description
44
- * @attr {Boolean} multiple - enable multiple selection
45
- *
46
- * @cssprop {Color} [--gv-select--bgc=var(--gv-theme-neutral-color-lightest, #ffffff)] - Background color
47
- * @cssprop {Color} [--gv-select--bdc=var(--gv-theme-neutral-color-dark, #d9d9d9)] - Border color
48
- * @cssprop {Color} [--gv-select--c=var(--gv-theme-font-color-dark, #262626)] - Color
49
- * @cssprop {Color} [--gv-select-hover--bgc=var(--gv-theme-color-light, #86c3d0)] - Hover background color
50
- * @cssprop {Color} [--gv-select-selected--bgc=var(--gv-theme-neutral-color-light, #efefef)] - Selected background color
51
- */
52
- export class GvSelectNative extends InputElement(LitElement) {
53
- static get properties() {
54
- return {
55
- ...super.properties,
56
- options: { type: Array },
57
- _options: { type: Array, attribute: false },
58
- large: { type: Boolean },
59
- medium: { type: Boolean },
60
- small: { type: Boolean },
61
- value: { type: String | Array },
62
- label: { type: String },
63
- title: { type: String },
64
- name: { type: String },
65
- placeholder: { type: String },
66
- description: { type: String },
67
- multiple: { type: Boolean, reflect: true },
68
- };
69
- }
70
-
71
- static get styles() {
72
- return [
73
- ...super.styles,
74
- skeleton,
75
- input,
76
- link,
77
- // language=CSS
78
- css`
79
- .box {
80
- --bdc: var(--gv-select--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));
81
- --c: var(--gv-select--c, var(--gv-theme-font-color-dark, #262626));
82
- --bgc: var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));
83
- --bgc-list: var(--gv-select--list-bgc, var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff)));
84
- --hover-bgc: var(--gv-select-hover--bgc, var(--gv-theme-color-light, #86c3d0));
85
- --selected-bgc: var(--gv-select-selected--bgc, var(--gv-theme-neutral-color-light, #efefef));
86
- position: relative;
87
- color: var(--c);
88
- }
89
-
90
- :host([readonly]) div,
91
- :host([readonly]) input,
92
- :host([readonly]) input:read-only:hover {
93
- user-select: auto;
94
- cursor: text;
95
- }
96
-
97
- input:read-only:hover {
98
- cursor: pointer;
99
- }
100
-
101
- label {
102
- color: var(--c);
103
- }
104
-
105
- select,
106
- .multiple .input {
107
- background-image: linear-gradient(45deg, transparent 50%, var(--c) 50%), linear-gradient(135deg, var(--c) 50%, transparent 50%),
108
- linear-gradient(to right, #ccc, #ccc);
109
- background-position: calc(100% - 17px) calc(1em + 2px), calc(100% - 12px) calc(1em + 2px), calc(100% - 2.5em) 0.5em;
110
- background-size: 5px 5px, 5px 5px, 1px 1.5em;
111
- background-repeat: no-repeat;
112
- -webkit-appearance: none;
113
- appearance: none;
114
- background-color: var(--bgc);
115
- }
116
-
117
- .multiple .input {
118
- padding-right: 35px;
119
- text-overflow: ellipsis;
120
- white-space: nowrap;
121
- overflow: hidden;
122
- }
123
-
124
- .multiple gv-icon {
125
- display: none;
126
- }
127
-
128
- .multiple.not-empty :not(.show) .input {
129
- background-image: none, linear-gradient(155deg, var(--c) 0%, transparent 0%), linear-gradient(to right, #ccc, #ccc);
130
- }
131
- .multiple.not-empty gv-icon {
132
- display: block;
133
- }
134
-
135
- .small .multiple .input {
136
- padding-right: 30px;
137
- }
138
-
139
- .small select,
140
- .small.multiple .input {
141
- background-position: calc(100% - 16px) calc(0.8em), calc(100% - 11px) calc(0.8em), calc(100% - 2.5em) 0.5em;
142
- background-size: 5px 5px, 5px 5px, 1px 1em;
143
- }
144
-
145
- .multiple select {
146
- opacity: 0;
147
- position: absolute;
148
- left: 0;
149
- top: 0;
150
- max-height: var(--input-medium--h);
151
- }
152
-
153
- .multiple .show {
154
- min-height: 75px;
155
- }
156
-
157
- .multiple .show select {
158
- opacity: 1;
159
- z-index: 1000;
160
- max-height: 300px;
161
- }
162
-
163
- gv-icon {
164
- --gv-icon--s: 19px;
165
- }
166
-
167
- .medium gv-icon {
168
- --gv-icon--s: 14px;
169
- }
170
-
171
- .small gv-icon {
172
- --gv-icon--s: 11px;
173
- }
174
- `,
175
- ];
176
- }
177
-
178
- constructor() {
179
- super();
180
- this._options = [{ label: '', value: '', disabled: false, title: null }];
181
- }
182
-
183
- getInputElement() {
184
- return this.shadowRoot.querySelector('select');
185
- }
186
-
187
- async firstUpdated(changedProperties) {
188
- super.firstUpdated(changedProperties);
189
- // Give the browser a chance to paint
190
- await new Promise((resolve) => setTimeout(resolve, 0));
191
- const input = this.getInputElement();
192
- if (input) {
193
- input.addEventListener('input', this._onInput.bind(this));
194
- if (this.multiple) {
195
- input.addEventListener('mousedown', this._onEnter.bind(this));
196
- input.addEventListener('focus', this._onEnter.bind(this));
197
- input.addEventListener('mouseleave', this._onLeave.bind(this));
198
- input.addEventListener('blur', this._onLeave.bind(this));
199
- }
200
- }
201
- }
202
-
203
- willUpdate(changedProperties) {
204
- if (changedProperties.has('value')) {
205
- this.updateState(this.value);
206
- }
207
- }
208
-
209
- updateState(value) {
210
- super.updateState(value);
211
- if (value && this._options && this.valid) {
212
- if (this.multiple) {
213
- if (this.required) {
214
- this.setValidity(value.length === 0, 'field is required');
215
- }
216
- if (value.length > 0 && this.valid) {
217
- const possibleValues = this._options.map((o) => o.value);
218
- this.setValidity(!value.some((v) => possibleValues.includes(v)), 'value is not included in the possible values');
219
- }
220
- } else {
221
- this.setValidity(
222
- this.required && this._options.find((option) => option.value === value) == null,
223
- 'value is not included in the possible values',
224
- );
225
- }
226
- this.invalid = !this.valid;
227
- }
228
- }
229
-
230
- _onEnter(e) {
231
- const input = this.getInputElement();
232
- if (!input.parentNode.classList.contains('show')) {
233
- e.stopPropagation();
234
- e.preventDefault();
235
- input.parentNode.classList.add('show');
236
- }
237
- }
238
-
239
- _onLeave() {
240
- this.getInputElement().parentNode.classList.remove('show');
241
- }
242
-
243
- _onInput(e) {
244
- e.stopPropagation();
245
- if (this.multiple) {
246
- const options = this.getInputElement().querySelectorAll('option:checked');
247
- this.value = Array.from(options).map((o) => o.value);
248
- } else {
249
- this.value = e.target.value;
250
- }
251
- this.updateState(this.value);
252
- dispatchCustomEvent(this, 'select', this.value);
253
- dispatchCustomEvent(this, 'input', this.value);
254
- this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
255
- }
256
-
257
- _onClear() {
258
- Array.from(this.getInputElement().querySelectorAll('option:checked')).forEach((option) => option.removeAttribute('checked'));
259
- this.value = [];
260
- dispatchCustomEvent(this, 'select', this.value);
261
- dispatchCustomEvent(this, 'input', this.value);
262
- this.dispatchEvent(new Event('input', { bubbles: true, cancelable: true }));
263
- }
264
-
265
- set options(options) {
266
- if (options) {
267
- this._options = options.map((option) => {
268
- if (typeof option !== 'object') {
269
- return { value: option, label: option };
270
- } else if (!option.label) {
271
- return { value: option.value, label: option.value };
272
- }
273
- return option;
274
- });
275
- }
276
- }
277
-
278
- selectedLabel() {
279
- if (this.value != null) {
280
- const elements = this._options.filter((o) => this.isSelected(o));
281
- if (elements) {
282
- return elements.map((e) => e.label).join(', ');
283
- }
284
- }
285
- return '';
286
- }
287
-
288
- renderSelect() {
289
- const selectedLabel = this.selectedLabel();
290
- if (this.readonly) {
291
- return html`
292
- <input
293
- id=${this._id}
294
- type="text"
295
- .name=${ifDefined(this.name)}
296
- .title=${ifDefined(selectedLabel || this.title || this.label)}
297
- .required=${this.required}
298
- aria-required=${!!this.required}
299
- .placeholder=${ifDefined(this.placeholder)}
300
- .value=${selectedLabel}
301
- readonly="readonly"
302
- />
303
- `;
304
- } else if (this.multiple) {
305
- const height = this._options ? this._options.length * (this.small ? 20 : 25) : 50;
306
- return html`
307
- <input
308
- class="input"
309
- type="text"
310
- .name=${ifDefined(this.name)}
311
- .title=${ifDefined(selectedLabel || this.title || this.label)}
312
- .required=${this.required}
313
- aria-required=${!!this.required}
314
- .placeholder=${ifDefined(this.placeholder)}
315
- .value=${selectedLabel}
316
- readonly="readonly"
317
- />
318
- <select
319
- class="input"
320
- id=${this._id}
321
- .name=${ifDefined(this.name)}
322
- .title=${ifDefined(selectedLabel || this.title || this.label)}
323
- .required=${this.required}
324
- aria-required=${!!this.required}
325
- ?disabled=${this.disabled || this.skeleton}
326
- .placeholder=${ifDefined(this.placeholder)}
327
- multiple
328
- .size="${this._options.length}"
329
- style="height: ${height}px"
330
- >
331
- ${this._options &&
332
- repeat(
333
- this._options,
334
- (option) => option,
335
- (option) => html` <option value="${option.value || ''}" ?selected="${this.isSelected(option)}">${option.label}</option> `,
336
- )}
337
- </select>
338
- <div class="box-icon box-icon-clear">
339
- <gv-icon class="link" shape="code:error" title="${i18n('gv-input.clear')}" @click="${this._onClear}"></gv-icon>
340
- </div>
341
- `;
342
- } else {
343
- return html`<select
344
- class="input"
345
- id=${this._id}
346
- .name=${ifDefined(this.name)}
347
- .title=${ifDefined(selectedLabel || this.title || this.label)}
348
- .required=${this.required}
349
- aria-required=${!!this.required}
350
- ?disabled=${this.disabled || this.skeleton}
351
- .placeholder=${ifDefined(this.placeholder)}
352
- >
353
- ${this._options &&
354
- repeat(
355
- this._options,
356
- (option) => option,
357
- (option) => html` <option value="${option.value || ''}" ?selected="${this.isSelected(option)}">${option.label}</option>`,
358
- )}
359
- </select>`;
360
- }
361
- }
362
-
363
- render() {
364
- const classes = {
365
- box: true,
366
- large: this.large,
367
- medium: this.medium || (!this.large && !this.small),
368
- small: this.small,
369
- skeleton: this.skeleton,
370
- required: this.required,
371
- multiple: this.multiple,
372
- 'not-empty': this._options && this.multiple && this.value && this.value.length > 0,
373
- };
374
-
375
- return html`
376
- <div class="${classMap(classes)}">
377
- <div class="box-input">${this.renderLabel()} ${this.renderSelect()}</div>
378
- </div>
379
- ${this.description != null ? html`<div class="description" .innerHTML="${this.description}"></div>` : ''}
380
- `;
381
- }
382
-
383
- isSelected(option) {
384
- return this.multiple ? this.value && this.value.includes(option.value) : '' + this.value === '' + option.value;
385
- }
386
- }
387
-
388
- window.customElements.define('gv-select-native', GvSelectNative);
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvSelectNative=void 0;const e=require("lit/directives/class-map"),t=require("lit/directives/if-defined"),i=require("lit/directives/repeat"),l=require("lit"),s=require("../styles/skeleton"),n=require("../styles/link"),a=require("../styles/input"),r=require("../lib/events"),o=require("../mixins/input-element"),c=require("../lib/i18n");class p extends((0,o.InputElement)(l.LitElement)){static get properties(){return{...super.properties,options:{type:Array},_options:{type:Array,attribute:!1},large:{type:Boolean},medium:{type:Boolean},small:{type:Boolean},value:{type:String|Array},label:{type:String},title:{type:String},name:{type:String},placeholder:{type:String},description:{type:String},multiple:{type:Boolean,reflect:!0}}}static get styles(){return[...super.styles,s.skeleton,a.input,n.link,l.css`.box{--bdc:var(--gv-select--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));--c:var(--gv-select--c, var(--gv-theme-font-color-dark, #262626));--bgc:var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));--bgc-list:var(--gv-select--list-bgc, var(--gv-select--bgc, var(--gv-theme-neutral-color-lightest, #ffffff)));--hover-bgc:var(--gv-select-hover--bgc, var(--gv-theme-color-light, #86c3d0));--selected-bgc:var(--gv-select-selected--bgc, var(--gv-theme-neutral-color-light, #efefef));position:relative;color:var(--c)}:host([readonly]) div,:host([readonly]) input,:host([readonly]) input:read-only:hover{user-select:auto;cursor:text}input:read-only:hover{cursor:pointer}label{color:var(--c)}.multiple .input,select{background-image:linear-gradient(45deg,transparent 50%,var(--c) 50%),linear-gradient(135deg,var(--c) 50%,transparent 50%),linear-gradient(to right,#ccc,#ccc);background-position:calc(100% - 17px) calc(1em + 2px),calc(100% - 12px) calc(1em + 2px),calc(100% - 2.5em) .5em;background-size:5px 5px,5px 5px,1px 1.5em;background-repeat:no-repeat;-webkit-appearance:none;appearance:none;background-color:var(--bgc)}.multiple .input{padding-right:35px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.multiple gv-icon{display:none}.multiple.not-empty :not(.show) .input{background-image:none,linear-gradient(155deg,var(--c) 0,transparent 0),linear-gradient(to right,#ccc,#ccc)}.multiple.not-empty gv-icon{display:block}.small .multiple .input{padding-right:30px}.small select,.small.multiple .input{background-position:calc(100% - 16px) calc(.8em),calc(100% - 11px) calc(.8em),calc(100% - 2.5em) .5em;background-size:5px 5px,5px 5px,1px 1em}.multiple select{opacity:0;position:absolute;left:0;top:0;max-height:var(--input-medium--h)}.multiple .show{min-height:75px}.multiple .show select{opacity:1;z-index:1000;max-height:300px}gv-icon{--gv-icon--s:19px}.medium gv-icon{--gv-icon--s:14px}.small gv-icon{--gv-icon--s:11px}`]}constructor(){super(),this._options=[{label:"",value:"",disabled:!1,title:null}]}getInputElement(){return this.shadowRoot.querySelector("select")}async firstUpdated(e){super.firstUpdated(e),await new Promise((e=>setTimeout(e,0)));const t=this.getInputElement();t&&(t.addEventListener("input",this._onInput.bind(this)),this.multiple&&(t.addEventListener("mousedown",this._onEnter.bind(this)),t.addEventListener("focus",this._onEnter.bind(this)),t.addEventListener("mouseleave",this._onLeave.bind(this)),t.addEventListener("blur",this._onLeave.bind(this))))}willUpdate(e){e.has("value")&&this.updateState(this.value)}updateState(e){if(super.updateState(e),e&&this._options&&this.valid){if(this.multiple){if(this.required&&this.setValidity(0===e.length,"field is required"),e.length>0&&this.valid){const t=this._options.map((e=>e.value));this.setValidity(!e.some((e=>t.includes(e))),"value is not included in the possible values")}}else this.setValidity(this.required&&null==this._options.find((t=>t.value===e)),"value is not included in the possible values");this.invalid=!this.valid}}_onEnter(e){const t=this.getInputElement();t.parentNode.classList.contains("show")||(e.stopPropagation(),e.preventDefault(),t.parentNode.classList.add("show"))}_onLeave(){this.getInputElement().parentNode.classList.remove("show")}_onInput(e){if(e.stopPropagation(),this.multiple){const e=this.getInputElement().querySelectorAll("option:checked");this.value=Array.from(e).map((e=>e.value))}else this.value=e.target.value;this.updateState(this.value),(0,r.dispatchCustomEvent)(this,"select",this.value),(0,r.dispatchCustomEvent)(this,"input",this.value),this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))}_onClear(){Array.from(this.getInputElement().querySelectorAll("option:checked")).forEach((e=>e.removeAttribute("checked"))),this.value=[],(0,r.dispatchCustomEvent)(this,"select",this.value),(0,r.dispatchCustomEvent)(this,"input",this.value),this.dispatchEvent(new Event("input",{bubbles:!0,cancelable:!0}))}set options(e){e&&(this._options=e.map((e=>"object"!=typeof e?{value:e,label:e}:e.label?e:{value:e.value,label:e.value})))}selectedLabel(){if(null!=this.value){const e=this._options.filter((e=>this.isSelected(e)));if(e)return e.map((e=>e.label)).join(", ")}return""}renderSelect(){const e=this.selectedLabel();if(this.readonly)return l.html`<input id="${this._id}" type="text" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" .placeholder="${(0,t.ifDefined)(this.placeholder)}" .value="${e}" readonly="readonly">`;if(this.multiple){const s=this._options?this._options.length*(this.small?20:25):50;return l.html`<input class="input" type="text" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" .placeholder="${(0,t.ifDefined)(this.placeholder)}" .value="${e}" readonly="readonly"> <select class="input" id="${this._id}" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" ?disabled="${this.disabled||this.skeleton}" .placeholder="${(0,t.ifDefined)(this.placeholder)}" multiple="multiple" .size="${this._options.length}" style="height:${s}">${this._options&&(0,i.repeat)(this._options,(e=>e),(e=>l.html`<option value="${e.value||""}" ?selected="${this.isSelected(e)}">${e.label}</option>`))}</select><div class="box-icon box-icon-clear"><gv-icon class="link" shape="code:error" title="${(0,c.i18n)("gv-input.clear")}" @click="${this._onClear}"></gv-icon></div>`}return l.html`<select class="input" id="${this._id}" .name="${(0,t.ifDefined)(this.name)}" .title="${(0,t.ifDefined)(e||this.title||this.label)}" .required="${this.required}" aria-required="${!!this.required}" ?disabled="${this.disabled||this.skeleton}" .placeholder="${(0,t.ifDefined)(this.placeholder)}">${this._options&&(0,i.repeat)(this._options,(e=>e),(e=>l.html`<option value="${e.value||""}" ?selected="${this.isSelected(e)}">${e.label}</option>`))}</select>`}render(){const t={box:!0,large:this.large,medium:this.medium||!this.large&&!this.small,small:this.small,skeleton:this.skeleton,required:this.required,multiple:this.multiple,"not-empty":this._options&&this.multiple&&this.value&&this.value.length>0};return l.html`<div class="${(0,e.classMap)(t)}"><div class="box-input">${this.renderLabel()} ${this.renderSelect()}</div></div>${null!=this.description?l.html`<div class="description" .innerHTML="${this.description}"></div>`:""}`}isSelected(e){return this.multiple?this.value&&this.value.includes(e.value):""+this.value==""+e.value}}exports.GvSelectNative=p,window.customElements.define("gv-select-native",p);