@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,535 +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, html, LitElement } from 'lit';
17
-
18
- import './gv-schema-form';
19
- import './gv-resizable-views';
20
- import './gv-documentation';
21
- import '../molecules/gv-table';
22
- import '../atoms/gv-button';
23
- import '../molecules/gv-option';
24
- import '../atoms/gv-switch';
25
- import '../atoms/gv-icon';
26
- import { dispatchCustomEvent } from '../lib/events';
27
- import { uuid } from '../lib/utils';
28
- import { KeyboardElement, KEYS } from '../mixins/keyboard-element';
29
- import { empty } from '../styles/empty';
30
-
31
- export class GvResources extends KeyboardElement(LitElement) {
32
- static get properties() {
33
- return {
34
- resources: { type: Array },
35
- _resources: { type: Array, attribute: false },
36
- types: { type: Array },
37
- documentation: { type: Object },
38
- _currentResource: { type: Object, attribute: false },
39
- _currentResourceLoading: { type: Boolean, attribute: false },
40
- _filter: { type: String },
41
- readonly: { type: Boolean, reflect: true },
42
- };
43
- }
44
-
45
- constructor() {
46
- super();
47
- this.resources = [];
48
- this.types = [];
49
- this._currentResource = null;
50
- this._emptymessage = 'No resource';
51
- }
52
-
53
- onKeyboard() {
54
- if (this.isPressed(KEYS.Esc)) {
55
- this._onCancelResourceForm();
56
- }
57
- if (this.isPressed(KEYS.Shift, KEYS.Ctrl, KEYS.Space)) {
58
- const search = this.shadowRoot.querySelector('#search-resource');
59
- if (search) {
60
- search.focus();
61
- }
62
- }
63
- }
64
-
65
- firstUpdated() {
66
- const views = this.shadowRoot.querySelector('gv-resizable-views');
67
- if (views != null) {
68
- views.updateComplete.then(() => {
69
- this._maximizeTopView();
70
- });
71
- }
72
- }
73
-
74
- set resources(resources) {
75
- this._resources = this._generateId(resources);
76
- }
77
-
78
- get resources() {
79
- return this._resources;
80
- }
81
-
82
- _generateId(list) {
83
- if (list) {
84
- return list.map((e) => {
85
- if (e._id == null) {
86
- e._id = uuid();
87
- }
88
- return e;
89
- });
90
- }
91
- return list;
92
- }
93
-
94
- _getResizableViews() {
95
- return this.shadowRoot.querySelector('gv-resizable-views');
96
- }
97
-
98
- _maximizeTopView() {
99
- this._getResizableViews().resize(60, 40);
100
- }
101
-
102
- _maximizeBottomView() {
103
- this._getResizableViews().maximizeBottom();
104
- }
105
-
106
- _splitMainViews() {
107
- this._getResizableViews().split();
108
- }
109
-
110
- _onCancelResourceForm() {
111
- this._currentResource = null;
112
- this.documentation = null;
113
- this._maximizeTopView();
114
- }
115
-
116
- _removeResource(item) {
117
- this.resources = this.resources.filter((resource) => resource._id !== item._id);
118
- this._onCancelResourceForm();
119
- dispatchCustomEvent(this, 'change', { resources: this.resources });
120
- }
121
-
122
- _buildResourceSchema(resourceType) {
123
- const defaultSchema = {
124
- properties: {
125
- name: {
126
- type: 'string',
127
- title: 'Resource name',
128
- },
129
- },
130
- required: ['name'],
131
- };
132
-
133
- const schema = typeof resourceType.schema === 'string' ? JSON.parse(resourceType.schema) : resourceType.schema;
134
-
135
- return {
136
- properties: { ...defaultSchema.properties, ...schema.properties },
137
- required: [...defaultSchema.required, ...schema.required],
138
- };
139
- }
140
-
141
- _onCreateResource({ detail }) {
142
- this._currentResourceLoading = true;
143
- const defaultResourceType = this.types.find((type) => type.id === detail.id);
144
- const schema = this._buildResourceSchema(defaultResourceType);
145
- this._currentResource = {
146
- type: defaultResourceType.id,
147
- title: 'Create resource',
148
- icon: 'code:plus',
149
- schema,
150
- values: {},
151
- submitLabel: 'Add',
152
- dirty: true,
153
- };
154
- this._maximizeBottomView();
155
- this._onFetchDocumentation();
156
- setTimeout(() => (this._currentResourceLoading = false), 600);
157
- }
158
-
159
- _onSubmitResourceForm({ detail }) {
160
- delete this._currentResource._values;
161
- const { type } = this._currentResource;
162
- const { _id, name, ...configuration } = detail.values;
163
-
164
- const resource = {
165
- _id,
166
- type,
167
- name,
168
- configuration,
169
- };
170
-
171
- if (detail.values._id != null) {
172
- const index = this.resources.findIndex((r) => r._id === resource._id);
173
- this.resources[index] = { ...this.resources[index], ...resource };
174
- } else {
175
- if (this.resources == null) {
176
- this.resources = [];
177
- }
178
- resource._id = uuid();
179
- resource.enabled = true;
180
- this.resources.push(resource);
181
- }
182
- this._onCancelResourceForm();
183
- dispatchCustomEvent(this, 'change', { resources: this.resources });
184
- }
185
-
186
- _onChangeResourceForm({ detail }) {
187
- this._currentResource._values = detail.values;
188
- }
189
-
190
- _onResetResourceForm() {
191
- delete this._currentResource._values;
192
- }
193
-
194
- _findResourceById(id) {
195
- return this.types.find((resource) => resource.id === id);
196
- }
197
-
198
- // For readonly mode
199
- _onSelectResource({ detail: { items } }) {
200
- if (items.length > 0) {
201
- this._onEditResource(items[0]);
202
- } else {
203
- this._onCancelResourceForm();
204
- }
205
- }
206
-
207
- _onEditResource(resource) {
208
- const values = { ...resource, ...resource.configuration };
209
- delete values.configuration;
210
- const resourceType = this._findResourceById(resource.type);
211
- this._currentResource = {
212
- _id: resource._id,
213
- title: 'Resource configuration',
214
- type: resource.type,
215
- icon: 'design:edit',
216
- schema: this._buildResourceSchema(resourceType),
217
- values,
218
- submitLabel: 'Update',
219
- };
220
- this._splitMainViews();
221
- this._onFetchDocumentation();
222
- }
223
-
224
- _onCloseDocumentation() {
225
- this.documentation = null;
226
- }
227
-
228
- _getCurrentResourceType() {
229
- return this._currentResource ? this._findResourceById(this._currentResource.type) : null;
230
- }
231
-
232
- _onFetchDocumentation() {
233
- dispatchCustomEvent(this, 'fetch-documentation', { target: this, resourceType: this._getCurrentResourceType() });
234
- }
235
-
236
- get dirty() {
237
- const form = this.shadowRoot.querySelector('gv-schema-form');
238
- return form && form.dirty;
239
- }
240
-
241
- confirm() {
242
- const form = this.shadowRoot.querySelector('gv-schema-form');
243
- if (form) {
244
- return form.confirm().then(() => this._onCancelResourceForm());
245
- }
246
- return Promise.resolve();
247
- }
248
-
249
- _onChangeResourceState(item, event) {
250
- const index = this.resources.find((r) => r._id === item._id);
251
- this.resources[index] = { ...this.resources[index], enabled: item.enabled };
252
- dispatchCustomEvent(this, 'change', { resources: this.resources });
253
- }
254
-
255
- _renderForm() {
256
- const values = { ...this._currentResource.values, ...this._currentResource._values };
257
- return html`<gv-schema-form
258
- scrollable
259
- .schema="${this._currentResource.schema}"
260
- .values="${values}"
261
- submitLabel="${this._currentResource.submitLabel}"
262
- has-header
263
- .icon="${this._currentResource.icon}"
264
- validate-on-render
265
- .dirty="${this._currentResource.dirty || this._currentResource._values != null}"
266
- ?readonly="${this.readonly}"
267
- @gv-schema-form:change="${this._onChangeResourceForm}"
268
- @gv-schema-form:reset="${this._onResetResourceForm}"
269
- @gv-schema-form:submit="${this._onSubmitResourceForm}"
270
- >
271
- <div slot="title" class="form-title">${this._currentResource.title}</div>
272
- <gv-button
273
- slot="header-left"
274
- icon="general:close"
275
- outlined
276
- small
277
- @gv-button:click="${this._onCancelResourceForm}"
278
- title="Close (esc)"
279
- ></gv-button>
280
- <gv-button
281
- slot="header-left"
282
- icon="home:book"
283
- ?disabled="${this.documentation != null}"
284
- outlined
285
- small
286
- @gv-button:click="${this._onFetchDocumentation}"
287
- title="Open documentation"
288
- ></gv-button>
289
- </gv-schema-form>`;
290
- }
291
-
292
- _renderDoc() {
293
- return html`<gv-documentation
294
- .text="${this.documentation.content}"
295
- .image="${this.documentation.image}"
296
- @gv-documentation:close="${this._onCloseDocumentation}"
297
- ></gv-documentation>`;
298
- }
299
-
300
- _renderBottom() {
301
- if (this.documentation && this._currentResource) {
302
- return html` <gv-resizable-views direction="horizontal" no-overflow>
303
- <div slot="top">${this._renderForm()}</div>
304
- <div slot="bottom">${this._renderDoc()}</div>
305
- </gv-resizable-views>`;
306
- } else if (this._currentResource) {
307
- return this._renderForm();
308
- } else if (this.documentation) {
309
- return this._renderDoc();
310
- } else if (this.readonly !== true) {
311
- const resourceOpts = this.types.map((resource) => {
312
- return { id: resource.id, title: resource.name, description: resource.description, image: resource.icon };
313
- });
314
-
315
- return html`<div class="resources-bottom-container">
316
- <gv-option class="resource__option" .options="${resourceOpts}" @gv-option:select="${this._onCreateResource}">
317
- </div>`;
318
- } else if (this.readonly && this.resources.length > 0) {
319
- return html`<div class="resources-bottom-container empty">You can see the resource configuration by clicking on it</div>`;
320
- }
321
- }
322
-
323
- _onSearchResource({ detail }) {
324
- this._filter = detail;
325
- }
326
-
327
- _onClearResource() {
328
- this._filter = null;
329
- }
330
-
331
- render() {
332
- const options = {
333
- selectable: true,
334
- data: [
335
- { field: 'name', label: 'Name' },
336
- {
337
- field: 'type',
338
- width: '50px',
339
- type: 'gv-image',
340
- attributes: {
341
- src: (item) => {
342
- const resourceType = this._findResourceById(item.type);
343
- return resourceType ? resourceType.icon : null;
344
- },
345
- style: 'width:40px;height:40px;',
346
- },
347
- },
348
- { field: 'type', label: 'Type' },
349
- {
350
- field: 'enabled',
351
- type: 'gv-switch',
352
- title: (item) => (item.enabled ? 'Click to disable' : 'Click to enable'),
353
- width: '50px',
354
- attributes: {
355
- readonly: this.readonly,
356
- 'ongv-switch:input': (item, event) => this._onChangeResourceState(item, event),
357
- },
358
- },
359
- ],
360
- };
361
-
362
- if (this.readonly !== true) {
363
- options.data.push({
364
- type: 'gv-button',
365
- width: '50px',
366
- attributes: {
367
- onClick: (item) => this._removeResource(item),
368
- title: 'remove',
369
- danger: true,
370
- outlined: true,
371
- icon: 'home:trash',
372
- },
373
- });
374
- }
375
-
376
- const filteredResources =
377
- this._filter != null
378
- ? this.resources.filter((resource) => {
379
- return (resource.name.toLowerCase() + resource.type.toLowerCase()).includes(this._filter);
380
- })
381
- : this.resources;
382
-
383
- return html`<div class="resources">
384
- <gv-resizable-views no-overflow>
385
- <div slot="top" class="box">
386
- <div class="container">
387
- <div class="header">
388
- <div class="title">Manage global resources <span>(${this.resources.length})</span></div>
389
- <gv-input
390
- id="search-resource"
391
- class="search-input"
392
- placeholder="Filter resources (Shift + Ctrl + Space)"
393
- type="search"
394
- small
395
- @gv-input:input="${this._onSearchResource}"
396
- @gv-input:clear="${this._onClearResource}"
397
- ></gv-input>
398
- </div>
399
- <div class="content">
400
- <div class="table-container">
401
- <gv-table
402
- .options="${options}"
403
- .items="${filteredResources}"
404
- emptymessage="${this._emptymessage}"
405
- @gv-table:select="${this._onSelectResource}"
406
- order="name"
407
- rowheight="50px"
408
- ></gv-table>
409
- </div>
410
- </div>
411
- </div>
412
- </div>
413
- <div slot="bottom">${this._renderBottom()}</div>
414
- </gv-resizable-views>
415
- </div>`;
416
- }
417
-
418
- static get styles() {
419
- return [
420
- empty,
421
- // language=CSS
422
- css`
423
- :host {
424
- box-sizing: border-box;
425
- height: 100%;
426
- width: 100%;
427
- display: block;
428
- }
429
-
430
- .resources {
431
- display: flex;
432
- height: 100%;
433
- width: 100%;
434
- }
435
-
436
- gv-resizable-views {
437
- height: 100%;
438
- width: 100%;
439
- }
440
-
441
- gv-table {
442
- --gv-table-rows--ov: none;
443
- }
444
-
445
- .header {
446
- border-bottom: 1px solid #d9d9d9;
447
- display: flex;
448
- min-height: 45px;
449
- align-items: center;
450
- margin-bottom: 0.5rem;
451
- padding: 0 0.5rem;
452
- }
453
-
454
- .header .title {
455
- color: #28444f;
456
- font-size: 18px;
457
- display: flex;
458
- align-items: flex-end;
459
- flex: 1;
460
- }
461
-
462
- .header .title span {
463
- font-size: 12px;
464
- margin-left: 8px;
465
- opacity: 0.7;
466
- }
467
-
468
- .box {
469
- position: absolute;
470
- display: flex;
471
- flex-direction: column;
472
- width: 100%;
473
- top: 0;
474
- bottom: 0;
475
- left: 0;
476
- }
477
-
478
- .container {
479
- flex-grow: 1;
480
-
481
- display: flex;
482
- flex-direction: column;
483
-
484
- /* for Firefox */
485
- min-height: 0;
486
- height: 100%;
487
- }
488
-
489
- .content {
490
- background: white;
491
- flex-grow: 1;
492
-
493
- overflow: auto;
494
-
495
- /* for Firefox */
496
- min-height: 0;
497
- padding: 0.5rem;
498
-
499
- display: flex;
500
- flex-direction: column;
501
- align-items: center;
502
- }
503
-
504
- .form-title {
505
- text-transform: uppercase;
506
- letter-spacing: 0.2rem;
507
- }
508
-
509
- .resources-bottom-container {
510
- display: flex;
511
- justify-content: center;
512
- align-items: center;
513
- height: 100%;
514
- }
515
-
516
- .table-container {
517
- max-width: 1200px;
518
- display: flex;
519
- flex-direction: column;
520
- width: 100%;
521
- }
522
-
523
- .search-input {
524
- width: 300px;
525
- }
526
-
527
- .resource__option {
528
- --gv-option-button--maw: 175px;
529
- }
530
- `,
531
- ];
532
- }
533
- }
534
-
535
- window.customElements.define('gv-resources', GvResources);
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvResources=void 0;const e=require("lit");require("./gv-schema-form"),require("./gv-resizable-views"),require("./gv-documentation"),require("../molecules/gv-table"),require("../atoms/gv-button"),require("../molecules/gv-option"),require("../atoms/gv-switch"),require("../atoms/gv-icon");const t=require("../lib/events"),s=require("../lib/utils"),i=require("../mixins/keyboard-element"),r=require("../styles/empty");class o extends((0,i.KeyboardElement)(e.LitElement)){static get properties(){return{resources:{type:Array},_resources:{type:Array,attribute:!1},types:{type:Array},documentation:{type:Object},_currentResource:{type:Object,attribute:!1},_currentResourceLoading:{type:Boolean,attribute:!1},_filter:{type:String},readonly:{type:Boolean,reflect:!0}}}constructor(){super(),this.resources=[],this.types=[],this._currentResource=null,this._emptymessage="No resource"}onKeyboard(){if(this.isPressed(i.KEYS.Esc)&&this._onCancelResourceForm(),this.isPressed(i.KEYS.Shift,i.KEYS.Ctrl,i.KEYS.Space)){const e=this.shadowRoot.querySelector("#search-resource");e&&e.focus()}}firstUpdated(){const e=this.shadowRoot.querySelector("gv-resizable-views");null!=e&&e.updateComplete.then((()=>{this._maximizeTopView()}))}set resources(e){this._resources=this._generateId(e)}get resources(){return this._resources}_generateId(e){return e?e.map((e=>(null==e._id&&(e._id=(0,s.uuid)()),e))):e}_getResizableViews(){return this.shadowRoot.querySelector("gv-resizable-views")}_maximizeTopView(){this._getResizableViews().resize(60,40)}_maximizeBottomView(){this._getResizableViews().maximizeBottom()}_splitMainViews(){this._getResizableViews().split()}_onCancelResourceForm(){this._currentResource=null,this.documentation=null,this._maximizeTopView()}_removeResource(e){this.resources=this.resources.filter((t=>t._id!==e._id)),this._onCancelResourceForm(),(0,t.dispatchCustomEvent)(this,"change",{resources:this.resources})}_buildResourceSchema(e){const t={properties:{name:{type:"string",title:"Resource name"}},required:["name"]},s="string"==typeof e.schema?JSON.parse(e.schema):e.schema;return{properties:{...t.properties,...s.properties},required:[...t.required,...s.required]}}_onCreateResource({detail:e}){this._currentResourceLoading=!0;const t=this.types.find((t=>t.id===e.id)),s=this._buildResourceSchema(t);this._currentResource={type:t.id,title:"Create resource",icon:"code:plus",schema:s,values:{},submitLabel:"Add",dirty:!0},this._maximizeBottomView(),this._onFetchDocumentation(),setTimeout((()=>this._currentResourceLoading=!1),600)}_onSubmitResourceForm({detail:e}){delete this._currentResource._values;const{type:i}=this._currentResource,{_id:r,name:o,...n}=e.values,c={_id:r,type:i,name:o,configuration:n};if(null!=e.values._id){const e=this.resources.findIndex((e=>e._id===c._id));this.resources[e]={...this.resources[e],...c}}else null==this.resources&&(this.resources=[]),c._id=(0,s.uuid)(),c.enabled=!0,this.resources.push(c);this._onCancelResourceForm(),(0,t.dispatchCustomEvent)(this,"change",{resources:this.resources})}_onChangeResourceForm({detail:e}){this._currentResource._values=e.values}_onResetResourceForm(){delete this._currentResource._values}_findResourceById(e){return this.types.find((t=>t.id===e))}_onSelectResource({detail:{items:e}}){e.length>0?this._onEditResource(e[0]):this._onCancelResourceForm()}_onEditResource(e){const t={...e,...e.configuration};delete t.configuration;const s=this._findResourceById(e.type);this._currentResource={_id:e._id,title:"Resource configuration",type:e.type,icon:"design:edit",schema:this._buildResourceSchema(s),values:t,submitLabel:"Update"},this._splitMainViews(),this._onFetchDocumentation()}_onCloseDocumentation(){this.documentation=null}_getCurrentResourceType(){return this._currentResource?this._findResourceById(this._currentResource.type):null}_onFetchDocumentation(){(0,t.dispatchCustomEvent)(this,"fetch-documentation",{target:this,resourceType:this._getCurrentResourceType()})}get dirty(){const e=this.shadowRoot.querySelector("gv-schema-form");return e&&e.dirty}confirm(){const e=this.shadowRoot.querySelector("gv-schema-form");return e?e.confirm().then((()=>this._onCancelResourceForm())):Promise.resolve()}_onChangeResourceState(e,s){const i=this.resources.find((t=>t._id===e._id));this.resources[i]={...this.resources[i],enabled:e.enabled},(0,t.dispatchCustomEvent)(this,"change",{resources:this.resources})}_renderForm(){const t={...this._currentResource.values,...this._currentResource._values};return e.html`<gv-schema-form scrollable .schema="${this._currentResource.schema}" .values="${t}" submitLabel="${this._currentResource.submitLabel}" has-header .icon="${this._currentResource.icon}" validate-on-render .dirty="${this._currentResource.dirty||null!=this._currentResource._values}" ?readonly="${this.readonly}" @gv-schema-form:change="${this._onChangeResourceForm}" @gv-schema-form:reset="${this._onResetResourceForm}" @gv-schema-form:submit="${this._onSubmitResourceForm}"><div slot="title" class="form-title">${this._currentResource.title}</div><gv-button slot="header-left" icon="general:close" outlined small @gv-button:click="${this._onCancelResourceForm}" title="Close (esc)"></gv-button><gv-button slot="header-left" icon="home:book" ?disabled="${null!=this.documentation}" outlined small @gv-button:click="${this._onFetchDocumentation}" title="Open documentation"></gv-button></gv-schema-form>`}_renderDoc(){return e.html`<gv-documentation .text="${this.documentation.content}" .image="${this.documentation.image}" @gv-documentation:close="${this._onCloseDocumentation}"></gv-documentation>`}_renderBottom(){if(this.documentation&&this._currentResource)return e.html`<gv-resizable-views direction="horizontal" no-overflow><div slot="top">${this._renderForm()}</div><div slot="bottom">${this._renderDoc()}</div></gv-resizable-views>`;if(this._currentResource)return this._renderForm();if(this.documentation)return this._renderDoc();if(!0!==this.readonly){const t=this.types.map((e=>({id:e.id,title:e.name,description:e.description,image:e.icon})));return e.html`<div class="resources-bottom-container"><gv-option class="resource__option" .options="${t}" @gv-option:select="${this._onCreateResource}"></gv-option></div>`}return this.readonly&&this.resources.length>0?e.html`<div class="resources-bottom-container empty">You can see the resource configuration by clicking on it</div>`:void 0}_onSearchResource({detail:e}){this._filter=e}_onClearResource(){this._filter=null}render(){const t={selectable:!0,data:[{field:"name",label:"Name"},{field:"type",width:"50px",type:"gv-image",attributes:{src:e=>{const t=this._findResourceById(e.type);return t?t.icon:null},style:"width:40px;height:40px;"}},{field:"type",label:"Type"},{field:"enabled",type:"gv-switch",title:e=>e.enabled?"Click to disable":"Click to enable",width:"50px",attributes:{readonly:this.readonly,"ongv-switch:input":(e,t)=>this._onChangeResourceState(e,t)}}]};!0!==this.readonly&&t.data.push({type:"gv-button",width:"50px",attributes:{onClick:e=>this._removeResource(e),title:"remove",danger:!0,outlined:!0,icon:"home:trash"}});const s=null!=this._filter?this.resources.filter((e=>(e.name.toLowerCase()+e.type.toLowerCase()).includes(this._filter))):this.resources;return e.html`<div class="resources"><gv-resizable-views no-overflow><div slot="top" class="box"><div class="container"><div class="header"><div class="title">Manage global resources <span>(${this.resources.length})</span></div><gv-input id="search-resource" class="search-input" placeholder="Filter resources (Shift + Ctrl + Space)" type="search" small @gv-input:input="${this._onSearchResource}" @gv-input:clear="${this._onClearResource}"></gv-input></div><div class="content"><div class="table-container"><gv-table .options="${t}" .items="${s}" emptymessage="${this._emptymessage}" @gv-table:select="${this._onSelectResource}" order="name" rowheight="50px"></gv-table></div></div></div></div><div slot="bottom">${this._renderBottom()}</div></gv-resizable-views></div>`}static get styles(){return[r.empty,e.css`:host{box-sizing:border-box;height:100%;width:100%;display:block}.resources{display:flex;height:100%;width:100%}gv-resizable-views{height:100%;width:100%}gv-table{--gv-table-rows--ov:none}.header{border-bottom:1px solid #d9d9d9;display:flex;min-height:45px;align-items:center;margin-bottom:.5rem;padding:0 .5rem}.header .title{color:#28444f;font-size:18px;display:flex;align-items:flex-end;flex:1}.header .title span{font-size:12px;margin-left:8px;opacity:.7}.box{position:absolute;display:flex;flex-direction:column;width:100%;top:0;bottom:0;left:0}.container{flex-grow:1;display:flex;flex-direction:column;min-height:0;height:100%}.content{background:#fff;flex-grow:1;overflow:auto;min-height:0;padding:.5rem;display:flex;flex-direction:column;align-items:center}.form-title{text-transform:uppercase;letter-spacing:.2rem}.resources-bottom-container{display:flex;justify-content:center;align-items:center;height:100%}.table-container{max-width:1200px;display:flex;flex-direction:column;width:100%}.search-input{width:300px}.resource__option{--gv-option-button--maw:175px}`]}}exports.GvResources=o,window.customElements.define("gv-resources",o);