@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,685 +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 { skeleton } from '../styles/skeleton';
18
- import { empty } from '../styles/empty';
19
- import { link } from '../styles/link';
20
- import { classMap } from 'lit/directives/class-map';
21
- import { repeat } from 'lit/directives/repeat';
22
- import { dispatchCustomEvent } from '../lib/events';
23
- import { getLanguage, i18n } from '../lib/i18n';
24
- import { until } from 'lit/directives/until';
25
- import { styleMap } from 'lit/directives/style-map';
26
- import { withResizeObserver } from '../mixins/with-resize-observer';
27
- import { ifDefined } from 'lit/directives/if-defined';
28
- import '../atoms/gv-image';
29
- import '../organisms/gv-pagination';
30
- import { getCssVar } from '../lib/style';
31
-
32
- /**
33
- * Table component
34
- *
35
- * ## Details
36
- * * has @theme facet
37
- *
38
- * @fires gv-table:select - when table row is selected
39
- * @fires gv-table:mouseenter - when the pointer is entering on a table row
40
- * @fires gv-table:mouseleave - when the pointer is leaving a table row
41
- * @fires gv-table:sort - when the order is changed
42
- *
43
- * @attr {Array<any>} items - A list of items to display
44
- * @attr {String} title - A title to display
45
- * @attr {String} order - If defined, the table will be ordered by the field. Start with '-' to sort in desc
46
- * @attr {Array<any>} options - The list of options to display
47
- * @attr {Boolean} noheader - Used to hide the table header
48
- * @attr {Boolean} nosort - Used to disable the click on header to sort
49
- * @attr {String} rowsheight - The height of the table rows
50
- * @attr {String} rowheight - The height of the table single row
51
- * @attr {String} emptymessage - The empty message to display
52
- * @attr {Function} format - A function to format table headers and string cells
53
- * @attr {Function} compareFn - A function to define how to sort. Default function will sort selected field ignoring case
54
- * @attr {Array<any>} selected - A list of selected ids of the items displayed
55
- * @attr {String} total - Total of data displayed on the table (useful with in case of pagination)
56
- * @attr {Boolean} skeleton - Force gv-table to be in skeleton mode
57
- *
58
- * @cssprop {Color} [--gv-table-selected--bgc=var(--gv-theme-color, #5a7684)] - Selected background color
59
- * @cssprop {Color} [--gv-table-hover--bgc=var(--gv-theme-neutral-color-lighter, #fafafa)] - Row background color on hover
60
- * @cssprop {Color} [--gv-table--bgc=var(--gv-theme-neutral-color-lightest, #ffffff)] - Background color
61
- * @cssprop {Color} [--gv-table--bdc=var(--gv-theme-neutral-color-dark, #d9d9d9)] - Border color
62
- * @cssprop {String} [--gv-table-header--fz=var(--gv-theme-font-size-l, 20px)] - Title font size
63
- * @cssprop {Length} [--gv-table-header--p=2rem 4rem] - Title padding
64
- * @cssprop {String} [--gv-table-rows--ov=auto] - Overflow on table
65
- * @cssprop {Length} [--gv-table--colmg=0.2rem] - Column gap
66
- * @cssprop {String} [--gv-table-row--ai=center] - Row align-items
67
- * @cssprop {String} [--gv-table-row--ac=center] - Row align-content
68
- * @cssprop {String} [--gv-table-cell--d=flex] - Cell display
69
- */
70
- export class GvTable extends withResizeObserver(LitElement) {
71
- static get properties() {
72
- return {
73
- items: { type: Array },
74
- title: { type: String },
75
- order: { type: String },
76
- options: { type: Array },
77
- noheader: { type: Boolean },
78
- nosort: { type: Boolean },
79
- rowsheight: { type: String },
80
- rowheight: { type: String },
81
- emptymessage: { type: String },
82
- format: { type: Function },
83
- compareFn: { type: Function },
84
- selected: { type: Array, reflect: true },
85
- total: { type: String },
86
- skeleton: { type: Boolean },
87
- _items: { type: Array, attribute: false },
88
- _skeleton: { type: Boolean, attribute: false },
89
- _error: { type: Boolean, attribute: false },
90
- _empty: { type: Boolean, attribute: false },
91
- _itemsProvider: { type: Array, attribute: false },
92
- _page: { type: Number, attribute: false },
93
- };
94
- }
95
-
96
- static get styles() {
97
- return [
98
- link,
99
- skeleton,
100
- empty,
101
- // language=CSS
102
- css`
103
- :host {
104
- --selected--bgc: var(--gv-table-selected--bgc, var(--gv-theme-color, #5a7684));
105
- --hover-bgc: var(--gv-table-hover--bgc, var(--gv-theme-neutral-color-lighter, #fafafa));
106
- --bgc: var(--gv-table--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));
107
- --bdc: var(--gv-table--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));
108
- display: block;
109
- height: 100%;
110
- margin: 0.2rem;
111
- box-sizing: border-box;
112
- }
113
-
114
- .table {
115
- background-color: var(--bgc);
116
- flex-direction: column;
117
- height: 100%;
118
- display: flex;
119
- width: 100%;
120
- }
121
-
122
- .rows {
123
- -ms-overflow-style: none;
124
- scrollbar-width: none;
125
- overflow: var(--gv-table-rows--ov, auto);
126
- flex: 1;
127
- height: 100%;
128
- transition: height 250ms ease-in-out;
129
- }
130
-
131
- .rows::-webkit-scrollbar {
132
- display: none;
133
- }
134
-
135
- :host([w-lt-768]) .row {
136
- height: 70px;
137
- }
138
-
139
- :host([w-lt-580]) .row {
140
- height: 60px;
141
- }
142
-
143
- :host([w-lt-400]) .row {
144
- height: 50px;
145
- }
146
-
147
- .theader {
148
- background-color: var(--gv-theme-neutral-color-lighter);
149
- font-weight: bold;
150
- padding: 0 0.2rem;
151
- }
152
-
153
- .row,
154
- .theader {
155
- align-items: var(--gv-table-row--ai, center);
156
- align-content: var(--gv-table-row--ac, center);
157
- border-right: solid thick transparent;
158
- display: grid;
159
- }
160
-
161
- div {
162
- box-sizing: border-box;
163
- }
164
-
165
- .cell {
166
- height: 100%;
167
- display: var(--gv-table-cell--d, flex);
168
- align-items: center;
169
- }
170
-
171
- .row:not(:last-child) {
172
- box-shadow: 0 5px 3px -6px var(--bdc);
173
- }
174
-
175
- .row:hover,
176
- .row.selected {
177
- background-color: var(--hover-bgc);
178
- }
179
-
180
- .row.selected {
181
- border-color: var(--selected--bgc);
182
- box-sizing: border-box;
183
- }
184
-
185
- .header {
186
- border-bottom: 1px solid var(--bdc);
187
- padding: var(--gv-table-header--p, 2rem 4rem);
188
- }
189
-
190
- .title {
191
- margin: 0;
192
- text-transform: uppercase;
193
- font-size: var(--gv-table-header--fz, var(--gv-theme-font-size-l, 20px));
194
- line-height: var(--gv-table-header--fz, var(--gv-theme-font-size-l, 20px));
195
- opacity: 0.6;
196
- }
197
-
198
- .title span {
199
- font-weight: 600;
200
- font-size: var(--gv-theme-font-size-s);
201
- line-height: var(--gv-theme-font-size-s);
202
- margin-left: 8px;
203
- opacity: 0.7;
204
- }
205
-
206
- gv-identity-picture {
207
- height: 35px;
208
- width: 35px;
209
- --gv-image--of: contain;
210
- margin-left: 20px;
211
- }
212
-
213
- gv-icon {
214
- transform: rotate(0deg);
215
- --gv-icon--s: 18px;
216
- }
217
-
218
- gv-icon.desc {
219
- transform: rotate(180deg);
220
- }
221
-
222
- gv-pagination {
223
- align-self: flex-end;
224
- }
225
-
226
- .cell > *:not(gv-tag) {
227
- margin: auto;
228
- width: 100%;
229
- }
230
- `,
231
- ];
232
- }
233
-
234
- constructor() {
235
- super();
236
- this._id = new Date().getTime();
237
- this.breakpoints = {
238
- width: [400, 580, 768],
239
- };
240
- this._empty = false;
241
- this.order = '';
242
- this._page = 1;
243
- this._itemsProvider = [];
244
- this.selected = [];
245
- this.compareFn = (item, item2, value) => {
246
- const itemData =
247
- this._getDataFromField(item, value) && this._getDataFromField(item, value).toLowerCase
248
- ? this._getDataFromField(item, value).toLowerCase()
249
- : '';
250
- const itemData2 =
251
- this._getDataFromField(item2, value) && this._getDataFromField(item2, value).toLowerCase
252
- ? this._getDataFromField(item2, value).toLowerCase()
253
- : '';
254
- if (this.order.startsWith('-')) {
255
- return itemData2.localeCompare(itemData);
256
- } else {
257
- return itemData.localeCompare(itemData2);
258
- }
259
- };
260
- this.addEventListener('gv-pagination:paginate', (e) => {
261
- this._page = e.detail.page;
262
- });
263
- }
264
-
265
- set items(items) {
266
- this._skeleton = true;
267
- Promise.resolve(items)
268
- .then((items) => {
269
- if (items) {
270
- this._itemsProvider = items.map((item, index) => {
271
- item._id = item.id == null ? index : item.id;
272
- return item;
273
- });
274
- this._onSortChanged();
275
- this._empty = this._itemsProvider.length === 0;
276
- this._skeleton = false;
277
- }
278
- })
279
- .catch((e) => {
280
- console.error(e);
281
- this._error = true;
282
- this._skeleton = false;
283
- this._itemsProvider = [];
284
- });
285
- }
286
-
287
- get items() {
288
- return this._itemsProvider;
289
- }
290
-
291
- _onSortChanged(field, e) {
292
- if (e) {
293
- e.preventDefault();
294
- }
295
- if (this._itemsProvider && this.order) {
296
- const desc = this.order.startsWith('-');
297
- const previousOrder = desc ? this.order.substring(1) : this.order;
298
- const value = field || previousOrder;
299
- if (field) {
300
- this.order = previousOrder === value ? (desc ? value : '-' + value) : value;
301
- }
302
- this._itemsProvider = this._itemsProvider.sort((item, item2) => this.compareFn(item, item2, value));
303
- if (field) {
304
- dispatchCustomEvent(this, 'sort', { order: this.order });
305
- }
306
- }
307
- }
308
-
309
- get _items() {
310
- if (this._itemsProvider) {
311
- if (this.options && this.options.paging && this.options.paging < this._itemsProvider.length) {
312
- const index = (this._page - 1) * this.options.paging;
313
- return [...this._itemsProvider].splice(index, this.options.paging);
314
- }
315
- return this._itemsProvider;
316
- }
317
- return [];
318
- }
319
-
320
- _getItemId(item) {
321
- return item.id == null ? item._id : item.id;
322
- }
323
-
324
- _onSelect(item, event) {
325
- if (!this._skeleton && !event.target.dataset.preventSelect) {
326
- if (this.options.selectable) {
327
- const itemId = this._getItemId(item);
328
- if (this._isSelected(item)) {
329
- this.selected = this.selected.filter((id) => itemId !== id);
330
- } else if (this.options.selectable === 'multi') {
331
- this.selected = [...this.selected, itemId];
332
- } else {
333
- this.selected = [itemId];
334
- }
335
- dispatchCustomEvent(this, 'select', { items: this.selectedItems, options: this.options });
336
- } else {
337
- dispatchCustomEvent(this, 'select', { items: [item] });
338
- }
339
- }
340
- }
341
-
342
- get selectedItems() {
343
- if (this.selected && this._itemsProvider) {
344
- return this._itemsProvider.filter((item) => this.selected && this.selected.includes(this._getItemId(item)));
345
- }
346
- return [];
347
- }
348
-
349
- _onMouseEnter(item) {
350
- if (!(this.selected && this.selected.length > 0) && !this._skeleton) {
351
- dispatchCustomEvent(this, 'mouseenter', { item });
352
- }
353
- }
354
-
355
- _onMouseLeave() {
356
- if (!(this.selected && this.selected.length > 0) && !this._skeleton) {
357
- dispatchCustomEvent(this, 'mouseleave');
358
- }
359
- }
360
-
361
- _renderHeader(styleGridColumns) {
362
- if (this.noheader) {
363
- return '';
364
- } else {
365
- const style = {
366
- ...styleGridColumns,
367
- ...{
368
- height: this.rowheight,
369
- 'grid-auto-rows': this.rowheight ? null : 'minmax(80px, auto)',
370
- },
371
- };
372
-
373
- return html` <div class=${classMap({ theader: true })} style=${styleMap(style)}>
374
- ${this.options && this.options.data && this._items && this._items.length
375
- ? repeat(
376
- this.options.data,
377
- (option) => option,
378
- (option) => {
379
- const orderValue = this.order && this.order.startsWith('-') ? this.order.substring(1) : this.order;
380
- const label = this.format && option.label ? this.format(option.label) : option.label;
381
- const style = typeof option.headerStyle === 'function' ? option.headerStyle(label) : option.headerStyle;
382
- return html` <div style="${style || ''}">
383
- ${this.order && !this.nosort
384
- ? html`
385
- <gv-button link @click="${this._onSortChanged.bind(this, option.field || option.tag)}">${until(label)}</gv-button>
386
- ${
387
- orderValue === option.tag || (orderValue === option.field && option.type !== 'image')
388
- ? html` <gv-icon class=${classMap({ desc: this.order.startsWith('-') })} shape="design:triangle"></gv-icon>`
389
- : ''
390
- }
391
- </a>`
392
- : until(label)}
393
- </div>`;
394
- },
395
- )
396
- : ''}
397
- </div>`;
398
- }
399
- }
400
-
401
- _renderIcon(item, itemIndex, option) {
402
- const icon = typeof option.icon === 'function' ? option.icon(item) : option.icon;
403
- const iconTitle = typeof option.iconTitle === 'function' ? option.iconTitle(item) : option.iconTitle;
404
- if (icon) {
405
- return html` <gv-icon shape="${icon}" title="${iconTitle}"></gv-icon>`;
406
- }
407
- return '';
408
- }
409
-
410
- _renderComponent(item, itemIndex, option, value, type) {
411
- if (option.condition && !option.condition(item)) {
412
- return '';
413
- }
414
- const element = document.createElement(type);
415
- element.value = value;
416
- if (option.attributes) {
417
- Object.keys(option.attributes).forEach((attribute) => {
418
- if (attribute.startsWith('on')) {
419
- const event = attribute.replace('on', '').toLowerCase();
420
- if (event === 'click') {
421
- element.classList.add('link');
422
- }
423
- element.dataset.preventSelect = true;
424
- element.addEventListener(event, (e) => {
425
- e.stopPropagation();
426
- const optionConfirm = typeof option.confirm === 'function' ? option.confirm(item) : option.confirm;
427
- if (optionConfirm == null) {
428
- setTimeout(() => {
429
- option.attributes[attribute](item, e, element, this);
430
- }, 0);
431
- }
432
- });
433
- } else if (typeof option.attributes[attribute] === 'function') {
434
- const value = option.attributes[attribute](item);
435
- if (value != null) {
436
- element[attribute] = value;
437
- }
438
- } else {
439
- if (this.format && typeof option.attributes[attribute] === 'string') {
440
- this.format(option.attributes[attribute]).then((t) => {
441
- element[attribute] = t;
442
- });
443
- } else {
444
- element[attribute] = option.attributes[attribute];
445
- }
446
- }
447
- });
448
- }
449
- element.addEventListener('input', (event) => {
450
- this._items[itemIndex][option.field] = event.target.value;
451
- });
452
-
453
- const optionConfirm = typeof option.confirm === 'function' ? option.confirm(item) : option.confirm;
454
-
455
- if (optionConfirm) {
456
- const confirm = document.createElement('gv-confirm');
457
- if (this.format) {
458
- this.format(optionConfirm.msg).then((t) => (confirm.message = t));
459
- } else {
460
- confirm.message = optionConfirm.msg;
461
- }
462
- if (optionConfirm.danger) {
463
- confirm.danger = true;
464
- }
465
- confirm.addEventListener('click', (e) => e.stopPropagation());
466
- confirm.addEventListener('gv-confirm:ok', (e) => {
467
- e.stopPropagation();
468
- option.attributes.onClick(item, e, element);
469
- });
470
- confirm.appendChild(element);
471
- return confirm;
472
- }
473
- return element;
474
- }
475
-
476
- _renderCell(formattedValue, option, item, itemIndex) {
477
- if (option.type) {
478
- if (option.type === 'image') {
479
- let alt = '';
480
- if (option.alt) {
481
- if (typeof option.alt === 'function') {
482
- alt = option.alt(item);
483
- } else {
484
- alt = this._getDataFromField(item, option.alt);
485
- }
486
- }
487
- return this._renderImage(formattedValue, alt);
488
- } else if (typeof option.type === 'function') {
489
- return this._renderComponent(item, itemIndex, option, formattedValue, option.type(item));
490
- } else if (option.type.startsWith('gv-')) {
491
- return this._renderComponent(item, itemIndex, option, formattedValue, option.type);
492
- }
493
- }
494
- return until(formattedValue);
495
- }
496
-
497
- _getFormattedCellValue(option, item) {
498
- let value = option.field ? this._getDataFromField(item, option.field) : '';
499
-
500
- if (value) {
501
- if (option.type === 'date') {
502
- value = new Date(value).toLocaleDateString(getLanguage());
503
- } else if (option.type === 'datetime') {
504
- value = new Date(value).toLocaleString(getLanguage());
505
- } else if (option.type === 'time') {
506
- value = new Date(value).toLocaleTimeString(getLanguage());
507
- }
508
- }
509
-
510
- if (option.format) {
511
- value = option.format(value);
512
- }
513
-
514
- return value;
515
- }
516
-
517
- _isSelected(item) {
518
- return this.selected && this.selected.includes(this._getItemId(item));
519
- }
520
-
521
- _renderRows(styleGridColumns) {
522
- return html` <div
523
- class="rows"
524
- style=${styleMap({ height: this.rowsheight, 'user-select': this.options.selectable ? 'none' : '' })}
525
- @mouseleave="${this._onMouseLeave.bind(this)}"
526
- >
527
- ${this._items && this._items.length
528
- ? repeat(
529
- this._items,
530
- (item) => item,
531
- (item, itemIndex) => {
532
- return html`
533
- <div class=${classMap({
534
- row: true,
535
- skeleton: this._skeleton,
536
- selected: this._isSelected(item),
537
- })} style=${styleMap({
538
- ...styleGridColumns,
539
- ...{
540
- height: this.rowheight,
541
- 'grid-auto-rows': this.rowheight ? null : 'minmax(80px, auto)',
542
- cursor: this.options.selectable ? 'pointer' : '',
543
- 'border-color': this.options.selectable && this._isSelected(item) ? 'var(--selected--bgc)' : '',
544
- 'column-gap': 'var(--gv-table--colmg, 0.2rem)',
545
- },
546
- })}
547
- @click="${this._onSelect.bind(this, item)}"
548
- @mouseenter="${this._onMouseEnter.bind(this, item)}">
549
- ${
550
- this.options && this.options.data
551
- ? repeat(
552
- this.options.data,
553
- (option) => option,
554
- (option) => {
555
- const style = typeof option.style === 'function' ? option.style(item) : option.style;
556
- const formattedValue = this._getFormattedCellValue(option, item);
557
- return html`<div class="cell" style="${ifDefined(style)}" title="${formattedValue}">
558
- ${this._renderCell(formattedValue, option, item, itemIndex)}${this._renderTag(option, item)}${option.icon
559
- ? this._renderIcon(item, itemIndex, option)
560
- : ''}
561
- </div> `;
562
- },
563
- )
564
- : ''
565
- }
566
- </div>
567
- </div>`;
568
- },
569
- )
570
- : ''}
571
- </div>`;
572
- }
573
-
574
- _renderItems() {
575
- let widthTemplate = this.options.data.map((o) => {
576
- if (o.width) {
577
- return o.width;
578
- } else if (o.type === 'image') {
579
- return '80px';
580
- } else if (o.type === 'icon') {
581
- return '40px';
582
- }
583
- return null;
584
- });
585
- const fixedData = widthTemplate.filter((width) => width !== null);
586
- const fixedWidth = fixedData.reduce((acc, width) => {
587
- return acc + parseInt(width.replace('px', ''), 10);
588
- }, 0);
589
-
590
- widthTemplate = widthTemplate.map((width) => {
591
- if (width == null) {
592
- const columnGap = getCssVar(this, '--gv-table--colmg', '0.2rem');
593
- return `calc((100% - ( ${fixedWidth}px + ${this.options.data.length - 1} * ${columnGap} ) ) / ${
594
- this.options.data.length - fixedData.length
595
- })`;
596
- }
597
- return width;
598
- });
599
-
600
- const styleGridColumns = { 'grid-template-columns': widthTemplate.join(' ') };
601
- return html` ${this._renderHeader(styleGridColumns)} ${this._renderRows(styleGridColumns)} ${this._renderPagination()} `;
602
- }
603
-
604
- _renderPagination() {
605
- if (this.options && this.options.paging && this._itemsProvider) {
606
- const paginationData = {
607
- first: 1,
608
- last: this._itemsProvider.length / this.options.paging,
609
- total: this._itemsProvider.length,
610
- current_page: this._page,
611
- total_pages: this._itemsProvider.length / this.options.paging,
612
- };
613
- return html`<gv-pagination .data="${paginationData}" widget="true"></gv-pagination>`;
614
- }
615
- }
616
-
617
- _getDataFromField(item, field) {
618
- if (typeof field === 'function') {
619
- return field(item);
620
- } else {
621
- return field.split('.').reduce((p, c) => p && p[c], item);
622
- }
623
- }
624
-
625
- _renderTag(option, item) {
626
- if (option.tag) {
627
- let tag;
628
- if (typeof option.tag === 'function') {
629
- tag = option.tag(item);
630
- } else {
631
- tag = option.format ? option.format(this._getDataFromField(item, option.tag)) : this._getDataFromField(item, option.tag);
632
- }
633
- if (tag) {
634
- return html` <gv-tag ?skeleton="${this._skeleton}">${tag}</gv-tag>`;
635
- }
636
- }
637
- return '';
638
- }
639
-
640
- _onImageLoaded() {
641
- this._skeleton = false;
642
- }
643
-
644
- _renderImage(picture, alt) {
645
- return html`<gv-identity-picture .picture="${picture}" .display_name="${alt}"></gv-identity-picture>`;
646
- }
647
-
648
- updated(props) {
649
- this._onSortChanged();
650
- }
651
-
652
- render() {
653
- if (this._error) {
654
- return html`<div class="error">${i18n('gv-table.error')}</div>`;
655
- }
656
-
657
- const classes = {
658
- table: true,
659
- skeleton: this._skeleton || this.skeleton,
660
- };
661
-
662
- const emptyStyle = {
663
- height: this.rowsheight ? this.rowsheight : '',
664
- };
665
-
666
- return html`
667
- <div class=${classMap(classes)} style="${styleMap({ display: this.rowsheight ? 'block' : 'flex' })}">
668
- ${this.title
669
- ? html` <div class="header">
670
- <h3 class="title">
671
- ${this.title} ${!this._empty ? html`<span>(${this.total || (this._items && this._items.length)})</span>` : ''}
672
- </h3>
673
- </div>`
674
- : ''}
675
- ${!this._empty && this.options && this.options.data
676
- ? this._renderItems()
677
- : html` <div class="empty" style="${styleMap(emptyStyle)}">
678
- ${this.emptymessage ? this.emptymessage : i18n('gv-table.empty')}
679
- </div>`}
680
- </div>
681
- `;
682
- }
683
- }
684
-
685
- window.customElements.define('gv-table', GvTable);
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvTable=void 0;const t=require("lit"),e=require("../styles/skeleton"),i=require("../styles/empty"),s=require("../styles/link"),r=require("lit/directives/class-map"),o=require("lit/directives/repeat"),n=require("../lib/events"),a=require("../lib/i18n"),l=require("lit/directives/until"),h=require("lit/directives/style-map"),d=require("../mixins/with-resize-observer"),g=require("lit/directives/if-defined");require("../atoms/gv-image"),require("../organisms/gv-pagination");const c=require("../lib/style");class p extends((0,d.withResizeObserver)(t.LitElement)){static get properties(){return{items:{type:Array},title:{type:String},order:{type:String},options:{type:Array},noheader:{type:Boolean},nosort:{type:Boolean},rowsheight:{type:String},rowheight:{type:String},emptymessage:{type:String},format:{type:Function},compareFn:{type:Function},selected:{type:Array,reflect:!0},total:{type:String},skeleton:{type:Boolean},_items:{type:Array,attribute:!1},_skeleton:{type:Boolean,attribute:!1},_error:{type:Boolean,attribute:!1},_empty:{type:Boolean,attribute:!1},_itemsProvider:{type:Array,attribute:!1},_page:{type:Number,attribute:!1}}}static get styles(){return[s.link,e.skeleton,i.empty,t.css`:host{--selected--bgc:var(--gv-table-selected--bgc, var(--gv-theme-color, #5a7684));--hover-bgc:var(--gv-table-hover--bgc, var(--gv-theme-neutral-color-lighter, #fafafa));--bgc:var(--gv-table--bgc, var(--gv-theme-neutral-color-lightest, #ffffff));--bdc:var(--gv-table--bdc, var(--gv-theme-neutral-color-dark, #d9d9d9));display:block;height:100%;margin:.2rem;box-sizing:border-box}.table{background-color:var(--bgc);flex-direction:column;height:100%;display:flex;width:100%}.rows{-ms-overflow-style:none;scrollbar-width:none;overflow:var(--gv-table-rows--ov,auto);flex:1;height:100%;transition:height 250ms ease-in-out}.rows::-webkit-scrollbar{display:none}:host([w-lt-768]) .row{height:70px}:host([w-lt-580]) .row{height:60px}:host([w-lt-400]) .row{height:50px}.theader{background-color:var(--gv-theme-neutral-color-lighter);font-weight:700;padding:0 .2rem}.row,.theader{align-items:var(--gv-table-row--ai,center);align-content:var(--gv-table-row--ac,center);border-right:solid thick transparent;display:grid}div{box-sizing:border-box}.cell{height:100%;display:var(--gv-table-cell--d,flex);align-items:center}.row:not(:last-child){box-shadow:0 5px 3px -6px var(--bdc)}.row.selected,.row:hover{background-color:var(--hover-bgc)}.row.selected{border-color:var(--selected--bgc);box-sizing:border-box}.header{border-bottom:1px solid var(--bdc);padding:var(--gv-table-header--p,2rem 4rem)}.title{margin:0;text-transform:uppercase;font-size:var(--gv-table-header--fz,var(--gv-theme-font-size-l,20px));line-height:var(--gv-table-header--fz,var(--gv-theme-font-size-l,20px));opacity:.6}.title span{font-weight:600;font-size:var(--gv-theme-font-size-s);line-height:var(--gv-theme-font-size-s);margin-left:8px;opacity:.7}gv-identity-picture{height:35px;width:35px;--gv-image--of:contain;margin-left:20px}gv-icon{transform:rotate(0);--gv-icon--s:18px}gv-icon.desc{transform:rotate(180deg)}gv-pagination{align-self:flex-end}.cell>:not(gv-tag){margin:auto;width:100%}`]}constructor(){super(),this._id=(new Date).getTime(),this.breakpoints={width:[400,580,768]},this._empty=!1,this.order="",this._page=1,this._itemsProvider=[],this.selected=[],this.compareFn=(t,e,i)=>{const s=this._getDataFromField(t,i)&&this._getDataFromField(t,i).toLowerCase?this._getDataFromField(t,i).toLowerCase():"",r=this._getDataFromField(e,i)&&this._getDataFromField(e,i).toLowerCase?this._getDataFromField(e,i).toLowerCase():"";return this.order.startsWith("-")?r.localeCompare(s):s.localeCompare(r)},this.addEventListener("gv-pagination:paginate",(t=>{this._page=t.detail.page}))}set items(t){this._skeleton=!0,Promise.resolve(t).then((t=>{t&&(this._itemsProvider=t.map(((t,e)=>(t._id=null==t.id?e:t.id,t))),this._onSortChanged(),this._empty=0===this._itemsProvider.length,this._skeleton=!1)})).catch((t=>{console.error(t),this._error=!0,this._skeleton=!1,this._itemsProvider=[]}))}get items(){return this._itemsProvider}_onSortChanged(t,e){if(e&&e.preventDefault(),this._itemsProvider&&this.order){const e=this.order.startsWith("-"),i=e?this.order.substring(1):this.order,s=t||i;t&&(this.order=i===s?e?s:"-"+s:s),this._itemsProvider=this._itemsProvider.sort(((t,e)=>this.compareFn(t,e,s))),t&&(0,n.dispatchCustomEvent)(this,"sort",{order:this.order})}}get _items(){if(this._itemsProvider){if(this.options&&this.options.paging&&this.options.paging<this._itemsProvider.length){const t=(this._page-1)*this.options.paging;return[...this._itemsProvider].splice(t,this.options.paging)}return this._itemsProvider}return[]}_getItemId(t){return null==t.id?t._id:t.id}_onSelect(t,e){if(!this._skeleton&&!e.target.dataset.preventSelect)if(this.options.selectable){const e=this._getItemId(t);this._isSelected(t)?this.selected=this.selected.filter((t=>e!==t)):"multi"===this.options.selectable?this.selected=[...this.selected,e]:this.selected=[e],(0,n.dispatchCustomEvent)(this,"select",{items:this.selectedItems,options:this.options})}else(0,n.dispatchCustomEvent)(this,"select",{items:[t]})}get selectedItems(){return this.selected&&this._itemsProvider?this._itemsProvider.filter((t=>this.selected&&this.selected.includes(this._getItemId(t)))):[]}_onMouseEnter(t){this.selected&&this.selected.length>0||this._skeleton||(0,n.dispatchCustomEvent)(this,"mouseenter",{item:t})}_onMouseLeave(){this.selected&&this.selected.length>0||this._skeleton||(0,n.dispatchCustomEvent)(this,"mouseleave")}_renderHeader(e){if(this.noheader)return"";{const i={...e,height:this.rowheight,"grid-auto-rows":this.rowheight?null:"minmax(80px, auto)"};return t.html`<div class="${(0,r.classMap)({theader:!0})}" style="${(0,h.styleMap)(i)}">${this.options&&this.options.data&&this._items&&this._items.length?(0,o.repeat)(this.options.data,(t=>t),(e=>{const i=this.order&&this.order.startsWith("-")?this.order.substring(1):this.order,s=this.format&&e.label?this.format(e.label):e.label,o="function"==typeof e.headerStyle?e.headerStyle(s):e.headerStyle;return t.html`<div style="${o||""}">${this.order&&!this.nosort?t.html`<gv-button link @click="${this._onSortChanged.bind(this,e.field||e.tag)}">${(0,l.until)(s)}</gv-button>${i===e.tag||i===e.field&&"image"!==e.type?t.html`<gv-icon class="${(0,r.classMap)({desc:this.order.startsWith("-")})}" shape="design:triangle"></gv-icon>`:""}`:(0,l.until)(s)}</div>`})):""}</div>`}}_renderIcon(e,i,s){const r="function"==typeof s.icon?s.icon(e):s.icon,o="function"==typeof s.iconTitle?s.iconTitle(e):s.iconTitle;return r?t.html`<gv-icon shape="${r}" title="${o}"></gv-icon>`:""}_renderComponent(t,e,i,s,r){if(i.condition&&!i.condition(t))return"";const o=document.createElement(r);o.value=s,i.attributes&&Object.keys(i.attributes).forEach((e=>{if(e.startsWith("on")){const s=e.replace("on","").toLowerCase();"click"===s&&o.classList.add("link"),o.dataset.preventSelect=!0,o.addEventListener(s,(s=>{s.stopPropagation();null==("function"==typeof i.confirm?i.confirm(t):i.confirm)&&setTimeout((()=>{i.attributes[e](t,s,o,this)}),0)}))}else if("function"==typeof i.attributes[e]){const s=i.attributes[e](t);null!=s&&(o[e]=s)}else this.format&&"string"==typeof i.attributes[e]?this.format(i.attributes[e]).then((t=>{o[e]=t})):o[e]=i.attributes[e]})),o.addEventListener("input",(t=>{this._items[e][i.field]=t.target.value}));const n="function"==typeof i.confirm?i.confirm(t):i.confirm;if(n){const e=document.createElement("gv-confirm");return this.format?this.format(n.msg).then((t=>e.message=t)):e.message=n.msg,n.danger&&(e.danger=!0),e.addEventListener("click",(t=>t.stopPropagation())),e.addEventListener("gv-confirm:ok",(e=>{e.stopPropagation(),i.attributes.onClick(t,e,o)})),e.appendChild(o),e}return o}_renderCell(t,e,i,s){if(e.type){if("image"===e.type){let s="";return e.alt&&(s="function"==typeof e.alt?e.alt(i):this._getDataFromField(i,e.alt)),this._renderImage(t,s)}if("function"==typeof e.type)return this._renderComponent(i,s,e,t,e.type(i));if(e.type.startsWith("gv-"))return this._renderComponent(i,s,e,t,e.type)}return(0,l.until)(t)}_getFormattedCellValue(t,e){let i=t.field?this._getDataFromField(e,t.field):"";return i&&("date"===t.type?i=new Date(i).toLocaleDateString((0,a.getLanguage)()):"datetime"===t.type?i=new Date(i).toLocaleString((0,a.getLanguage)()):"time"===t.type&&(i=new Date(i).toLocaleTimeString((0,a.getLanguage)()))),t.format&&(i=t.format(i)),i}_isSelected(t){return this.selected&&this.selected.includes(this._getItemId(t))}_renderRows(e){return t.html`<div class="rows" style="${(0,h.styleMap)({height:this.rowsheight,"user-select":this.options.selectable?"none":""})}" @mouseleave="${this._onMouseLeave.bind(this)}">${this._items&&this._items.length?(0,o.repeat)(this._items,(t=>t),((i,s)=>t.html`<div class="${(0,r.classMap)({row:!0,skeleton:this._skeleton,selected:this._isSelected(i)})}" style="${(0,h.styleMap)({...e,height:this.rowheight,"grid-auto-rows":this.rowheight?null:"minmax(80px, auto)",cursor:this.options.selectable?"pointer":"","border-color":this.options.selectable&&this._isSelected(i)?"var(--selected--bgc)":"","column-gap":"var(--gv-table--colmg, 0.2rem)"})}" @click="${this._onSelect.bind(this,i)}" @mouseenter="${this._onMouseEnter.bind(this,i)}">${this.options&&this.options.data?(0,o.repeat)(this.options.data,(t=>t),(e=>{const r="function"==typeof e.style?e.style(i):e.style,o=this._getFormattedCellValue(e,i);return t.html`<div class="cell" style="${(0,g.ifDefined)(r)}" title="${o}">${this._renderCell(o,e,i,s)}${this._renderTag(e,i)}${e.icon?this._renderIcon(i,s,e):""}</div>`})):""}</div>`)):""}</div>`}_renderItems(){let e=this.options.data.map((t=>t.width?t.width:"image"===t.type?"80px":"icon"===t.type?"40px":null));const i=e.filter((t=>null!==t)),s=i.reduce(((t,e)=>t+parseInt(e.replace("px",""),10)),0);e=e.map((t=>{if(null==t){const t=(0,c.getCssVar)(this,"--gv-table--colmg","0.2rem");return`calc((100% - ( ${s}px + ${this.options.data.length-1} * ${t} ) ) / ${this.options.data.length-i.length})`}return t}));const r={"grid-template-columns":e.join(" ")};return t.html`${this._renderHeader(r)} ${this._renderRows(r)} ${this._renderPagination()}`}_renderPagination(){if(this.options&&this.options.paging&&this._itemsProvider){const e={first:1,last:this._itemsProvider.length/this.options.paging,total:this._itemsProvider.length,current_page:this._page,total_pages:this._itemsProvider.length/this.options.paging};return t.html`<gv-pagination .data="${e}" widget="true"></gv-pagination>`}}_getDataFromField(t,e){return"function"==typeof e?e(t):e.split(".").reduce(((t,e)=>t&&t[e]),t)}_renderTag(e,i){if(e.tag){let s;if(s="function"==typeof e.tag?e.tag(i):e.format?e.format(this._getDataFromField(i,e.tag)):this._getDataFromField(i,e.tag),s)return t.html`<gv-tag ?skeleton="${this._skeleton}">${s}</gv-tag>`}return""}_onImageLoaded(){this._skeleton=!1}_renderImage(e,i){return t.html`<gv-identity-picture .picture="${e}" .display_name="${i}"></gv-identity-picture>`}updated(t){this._onSortChanged()}render(){if(this._error)return t.html`<div class="error">${(0,a.i18n)("gv-table.error")}</div>`;const e={table:!0,skeleton:this._skeleton||this.skeleton},i={height:this.rowsheight?this.rowsheight:""};return t.html`<div class="${(0,r.classMap)(e)}" style="${(0,h.styleMap)({display:this.rowsheight?"block":"flex"})}">${this.title?t.html`<div class="header"><h3 class="title">${this.title} ${this._empty?"":t.html`<span>(${this.total||this._items&&this._items.length})</span>`}</h3></div>`:""} ${!this._empty&&this.options&&this.options.data?this._renderItems():t.html`<div class="empty" style="${(0,h.styleMap)(i)}">${this.emptymessage?this.emptymessage:(0,a.i18n)("gv-table.empty")}</div>`}</div>`}}exports.GvTable=p,window.customElements.define("gv-table",p);