@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,751 +1 @@
1
- /*
2
- * Copyright (C) 2015 The Gravitee team (http://gravitee.io)
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
- import { LitElement, html, css } from 'lit';
17
- import { get, set, del } from 'object-path';
18
- import { dispatchCustomEvent } from '../lib/events';
19
- import { deepClone, deepEqual } from '../lib/utils';
20
- import { classMap } from 'lit/directives/class-map';
21
- import { repeat } from 'lit/directives/repeat';
22
- import { Validator } from 'jsonschema';
23
- import { empty } from '../styles/empty';
24
- import './gv-schema-form-control';
25
-
26
- /**
27
- * Schema form component
28
- *
29
- * @fires gv-schema-form:submit - event when user submit valid form
30
- * @fires gv-schema-form:error - event when user submit invalid form
31
- * @fires gv-schema-form:change - event when when form change
32
- * @fires gv-schema-form:cancel - event when user cancel form
33
- *
34
- * @attr {Object} schema - the schema form configuration
35
- * @attr {Object} values - the values of fields
36
- * @attr {Object} errors - the map of errors by input key
37
- * @attr {Boolean} validate - to force validation on first render
38
- * @attr {Boolean} readonly - true if readonly
39
- * @attr {Boolean} scrollable - useful for making content scrollable with fixed headers / footers
40
- *
41
- * @cssprop {Color} [--gv-schema-form--bgc=#ffffff] - Background color
42
- * @cssprop {Length} [--gv-schema-form-control--m=0.4rem] - Control margin
43
- */
44
- export class GvSchemaForm extends LitElement {
45
- static get properties() {
46
- return {
47
- schema: { type: Object },
48
- errors: { type: Object },
49
- values: { type: Object },
50
- submitLabel: { type: String },
51
- hasFooter: { type: Boolean, attribute: 'has-footer' },
52
- hasHeader: { type: Boolean, attribute: 'has-header' },
53
- _confirm: { type: Object },
54
- _values: { type: Object, attribute: false },
55
- dirty: { type: Boolean, reflect: true },
56
- hideDeprecated: { type: Boolean, attribute: 'hide-deprecated' },
57
- validateOnRender: { type: Boolean, attribute: 'validate-on-render' },
58
- _validatorResults: { type: Object },
59
- skeleton: { type: Boolean, reflect: true },
60
- _touch: { type: Boolean },
61
- readonly: { type: Boolean, reflect: true },
62
- scrollable: { type: Boolean, reflect: true },
63
- groups: { type: Array },
64
- };
65
- }
66
-
67
- constructor() {
68
- super();
69
- this.hideDeprecated = false;
70
- this._values = {};
71
- this.submitLabel = 'Ok';
72
- this.hasHeader = false;
73
- this.hasFooter = false;
74
- this._touch = false;
75
- this._validator = new Validator();
76
- this._validatorResults = {};
77
- this._ignoreProperties = [];
78
- this._dynamicControls = [];
79
- this._dynamicAttributes = ['disabled', 'required', 'hidden'];
80
- this.groups = null;
81
- this.addEventListener('gv-schema-form-control:default-value', this._onDefaultValue.bind(this));
82
- this.addEventListener('gv-schema-form-control:change', this._onChange.bind(this));
83
- this.addEventListener('gv-schema-form-control:control-ready', this._onControlReady.bind(this));
84
- }
85
-
86
- set values(values) {
87
- if (!deepEqual(this._values, values)) {
88
- if (values) {
89
- this._initialValues = { ...values };
90
- } else {
91
- this._initialValues = {};
92
- }
93
- this._values = deepClone(this._initialValues);
94
- }
95
- }
96
-
97
- get values() {
98
- return this._values;
99
- }
100
-
101
- reset(values = null) {
102
- this._values = deepClone(values || this._initialValues);
103
- this._touch = false;
104
- this._setDirty(false);
105
- this.getControls().forEach((s) => {
106
- s.requestUpdate();
107
- });
108
- }
109
-
110
- _onReset() {
111
- this.reset();
112
- dispatchCustomEvent(this, 'reset');
113
- }
114
-
115
- requestValidation() {
116
- clearTimeout(this._validateTimeout);
117
- this._validateTimeout = setTimeout(() => {
118
- this.validate();
119
- this._updateActions();
120
- }, 350);
121
- }
122
-
123
- submit() {
124
- this._onSubmit();
125
- }
126
-
127
- _onSubmit() {
128
- const validatorResults = this.validate();
129
- if (this.isValid()) {
130
- this._initialValues = deepClone(this._values);
131
- this.dirty = false;
132
- this._touch = false;
133
- dispatchCustomEvent(this, 'submit', { values: this._values, validatorResults });
134
- } else {
135
- dispatchCustomEvent(this, 'error', { values: this._values, validatorResults });
136
- }
137
- }
138
-
139
- _setDirty(dirty = true) {
140
- this.dirty = !!dirty;
141
- }
142
-
143
- _setTouch(touch = true) {
144
- this._touch = !!touch;
145
- }
146
-
147
- confirm() {
148
- if (this.isTouch()) {
149
- if (this._confirm && this._confirm.promise) {
150
- return this._confirm.promise;
151
- }
152
- const promise = new Promise((resolve, reject) => (this._confirm = { resolve, reject }));
153
- this._confirm.promise = promise;
154
- return promise;
155
- }
156
- return Promise.resolve();
157
- }
158
-
159
- _onConfirmReset() {
160
- const { resolve } = this._confirm;
161
- this._confirm = null;
162
- this._onReset();
163
- this.requestUpdate();
164
- this.updateComplete.then(() => {
165
- resolve(this);
166
- });
167
- }
168
-
169
- _onConfirmEdit() {
170
- this._confirm.reject(this);
171
- this._confirm = null;
172
- this._updateChildren(this.validateOnRender);
173
- }
174
-
175
- _getSubmitBtn() {
176
- return this.shadowRoot.querySelector('#submit');
177
- }
178
-
179
- _getResetBtn() {
180
- return this.shadowRoot.querySelector('#reset');
181
- }
182
-
183
- _dispatchChange() {
184
- clearTimeout(this._changeTimeout);
185
- this._changeTimeout = setTimeout(() => {
186
- dispatchCustomEvent(this, 'change', { target: this, values: this._values, validation: this._validatorResults });
187
- }, 50);
188
- }
189
-
190
- _onDefaultValue({ detail: { currentTarget, value, control } }) {
191
- if (control.type === 'integer' && value != null && ((value.trim && value.length > 0) || value.length > 0)) {
192
- value = parseInt(value, 10);
193
- }
194
- set(this._values, currentTarget.id, value);
195
- }
196
-
197
- _onChange({ detail: { currentTarget, value, control } }) {
198
- this._setTouch(true);
199
- if (control.type === 'integer') {
200
- if (typeof value === 'string' && value.trim().length === 0) {
201
- value = null;
202
- } else {
203
- const intValue = Number(value).valueOf();
204
- if (!isNaN(intValue)) {
205
- value = intValue;
206
- } else {
207
- value = null;
208
- }
209
- }
210
- } else if (control.type === 'array' && value.length === 0) {
211
- value = null;
212
- } else if (control.type === 'string' && value.trim().length === 0 && !control.enum) {
213
- value = null;
214
- } else if (control.type === 'object') {
215
- if (Object.keys(value).length === 0) {
216
- value = null;
217
- }
218
- }
219
- if (value == null) {
220
- del(this._values, currentTarget.id);
221
- } else {
222
- set(this._values, currentTarget.id, value);
223
- }
224
-
225
- this._updateDynamicControls();
226
- this._validatorResults = this.validate();
227
- this.dirty = true;
228
- this._updateActions();
229
- this._dispatchChange();
230
- }
231
-
232
- _onControlReady(e) {
233
- e.stopPropagation();
234
- e.preventDefault();
235
- const controlElement = e.detail.control;
236
- const control = controlElement.control;
237
- if (control['x-schema-form']) {
238
- if (control['x-schema-form'].event) {
239
- const event = control['x-schema-form'].event;
240
- dispatchCustomEvent(this, event.name, { ...event, ...e.detail });
241
- } else if (this._hasCondition(control)) {
242
- this._dynamicControls.push(controlElement);
243
- this._updateDynamicControl(controlElement);
244
- }
245
- }
246
- }
247
-
248
- _updateDynamicControls() {
249
- this._ignoreProperties = [];
250
- this._dynamicControls.forEach((controlElement) => {
251
- this._updateDynamicControl(controlElement);
252
- });
253
- }
254
-
255
- _updateDynamicControl(controlElement) {
256
- const control = controlElement.control;
257
- if (control['x-schema-form']) {
258
- this._dynamicAttributes.forEach((attribute) => {
259
- const is = this._evaluateCondition(control, attribute);
260
- if (is) {
261
- controlElement.setAttribute(attribute, '');
262
- if (attribute === 'hidden') {
263
- this._ignoreProperties.push(controlElement.id);
264
- }
265
- } else {
266
- controlElement.removeAttribute(attribute);
267
- }
268
- });
269
- }
270
- return null;
271
- }
272
-
273
- async performUpdate() {
274
- await Promise.all(this.getControls().map((e) => e.updateComplete));
275
- this.getControls().forEach((s) => {
276
- s.requestUpdate();
277
- });
278
- super.performUpdate();
279
- }
280
-
281
- _renderControl(key) {
282
- // This is require to clean cache of <gv-schema-form-control>
283
- const control = { ...this.schema.properties[key] };
284
- const isRequired = (this.schema.required && this.schema.required.includes(key)) || this._evaluateCondition(control, 'required');
285
- const isDisabled = (this.schema.disabled && this.schema.disabled.includes(key)) || this._evaluateCondition(control, 'disabled');
286
- const isHidden = this._evaluateCondition(control, 'hidden');
287
- if (isHidden) {
288
- this._ignoreProperties.push(key);
289
- }
290
- const isReadonly = this.readonly || control.readOnly === true;
291
- const isWriteOnly = control.writeOnly === true;
292
- const value = get(this._values, key);
293
- return html`<gv-schema-form-control
294
- .id="${key}"
295
- .errors="${this.errors}"
296
- .control="${control}"
297
- .skeleton="${this.skeleton}"
298
- .value="${value}"
299
- ?readonly="${isReadonly}"
300
- ?writeonly="${isWriteOnly}"
301
- ?required="${isRequired}"
302
- ?disabled="${isDisabled}"
303
- ?hidden="${isHidden}"
304
- ></gv-schema-form-control>`;
305
- }
306
-
307
- _hasCondition(control) {
308
- if (control['x-schema-form']) {
309
- return this._dynamicAttributes.find((condition) => control['x-schema-form'][condition] != null) != null;
310
- }
311
- return false;
312
- }
313
-
314
- _evaluateCondition(control, conditionKey) {
315
- if (control['x-schema-form'] == null || control['x-schema-form'][conditionKey] == null) {
316
- return false;
317
- }
318
- const condition = control['x-schema-form'][conditionKey];
319
- if (typeof condition === 'boolean') {
320
- return condition;
321
- }
322
- if (!Array.isArray(condition)) {
323
- // condition isn't an array, ignore the condition
324
- console.warn(`'${conditionKey}' attribute of 'x-schema-form' should be an array`);
325
- return false;
326
- }
327
-
328
- let result = true;
329
- for (const operation of condition) {
330
- // operation only have one operator with a single object containing operand values
331
- const operator = Object.keys(operation)[0];
332
-
333
- switch (operator) {
334
- case '$neq':
335
- result = result && this._evaluateNotEqualsCondition(control, operation);
336
- break;
337
- case '$eq':
338
- result = result && this._evaluateEqualsCondition(control, operation);
339
- break;
340
- case '$nodef':
341
- result = result && this._evaluateNotDefCondition(control, operation);
342
- break;
343
- case '$def':
344
- result = result && this._evaluateDefCondition(control, operation);
345
- break;
346
- default:
347
- console.warn(`Unsupported operator '${operator}' on disable condition`);
348
- result = false;
349
- break;
350
- }
351
- }
352
-
353
- return result;
354
- }
355
-
356
- _evaluateNotEqualsCondition(control, condition) {
357
- return !this._evaluateEqualsCondition(control, condition);
358
- }
359
-
360
- _evaluateEqualsCondition(control, condition) {
361
- const operator = Object.keys(condition)[0];
362
- const operands = condition[operator];
363
- const modelAttributes = Object.keys(operands);
364
- return modelAttributes
365
- .map((modelAttribute) => {
366
- const testValue = operands[modelAttribute];
367
- let value = get(this._values, modelAttribute);
368
- if (value == null && control.type === 'string') {
369
- value = '';
370
- }
371
- if (Array.isArray(testValue)) {
372
- return testValue.includes(value);
373
- }
374
- return value === testValue;
375
- })
376
- .reduce((acc, current) => acc || current);
377
- }
378
-
379
- _evaluateNotDefCondition(control, condition) {
380
- const operator = Object.keys(condition)[0];
381
- const modelAttribute = condition[operator];
382
- return get(this._values, modelAttribute) === undefined || get(this._values, modelAttribute) === null;
383
- }
384
-
385
- _evaluateDefCondition(control, condition) {
386
- return !this._evaluateNotDefCondition(control, condition);
387
- }
388
-
389
- _renderPart() {
390
- if (this._confirm) {
391
- return html`<div class="confirm-box">
392
- <div class="error">The configuration is not valid and cannot be saved.</div>
393
- <div class="confirm-box_actions">
394
- <gv-button @gv-button:click="${this._onConfirmReset}" outlined icon="general:update" danger>Lose changes</gv-button>
395
- <gv-button @gv-button:click="${this._onConfirmEdit}" icon="design:edit">Edit</gv-button>
396
- </div>
397
- </div>`;
398
- }
399
- const keys = this.schema.properties ? Object.keys(this.schema.properties) : [];
400
- this._ignoreProperties = [];
401
-
402
- if (this.groups) {
403
- // Remove undefined group items
404
- const groupsCleaned = this.groups.reduce((prev, group) => {
405
- const itemsExistingInSchemaKeys = keys.filter((key) => [...(group.items || [])].includes(key));
406
- prev.push({
407
- ...group,
408
- items: itemsExistingInSchemaKeys || [],
409
- });
410
- return prev;
411
- }, []);
412
-
413
- // Add non grouped items inside default group
414
- const defaultGroup = groupsCleaned.find((g) => g.default) || { default: true, items: [] };
415
- const zipGroupedItems = groupsCleaned.reduce((prev, group) => [...prev, ...group.items], []);
416
- defaultGroup.items = keys.filter((key) => !zipGroupedItems.includes(key));
417
-
418
- return repeat(
419
- groupsCleaned,
420
- (group) =>
421
- html`${group.name
422
- ? html`<h2 class="group-title">${group.name}</h2>
423
- ${repeat(group.items, (key) => this._renderControl(key))}`
424
- : repeat(group.items, (key) => this._renderControl(key))} `,
425
- );
426
- }
427
-
428
- return html`${repeat([1], () =>
429
- repeat(
430
- keys,
431
- (key) => key,
432
- (key) => this._renderControl(key),
433
- ),
434
- )}`;
435
- }
436
-
437
- getControls() {
438
- return Array.from(this.shadowRoot.querySelectorAll('gv-schema-form-control'));
439
- }
440
-
441
- getControl(id) {
442
- return this.shadowRoot.querySelector(`[id="${id}"]`);
443
- }
444
-
445
- _getErrors() {
446
- return (this._validatorResults.errors || []).filter((error) => {
447
- let id = `${error.property.replace('instance.', '')}`;
448
- if (!Array.isArray(error.argument)) {
449
- id = `${id}.${error.argument}`;
450
- }
451
-
452
- const errorKey = `x-schema-form.errors.${id}.${error.name}`;
453
- const errorMessage = get(this.schema, errorKey);
454
- if (errorMessage) {
455
- error.message = errorMessage;
456
- }
457
- return !this._ignoreProperties.includes(id);
458
- });
459
- }
460
-
461
- validate() {
462
- if (this.schema) {
463
- // Additional properties should not block the validation of the form
464
- this._validatorResults = this._validator.validate(this._values, { ...this.schema, additionalProperties: {} });
465
- this.errors = this._getErrors();
466
- }
467
- return this._validatorResults;
468
- }
469
-
470
- isValid() {
471
- if (this._validatorResults.valid) {
472
- return true;
473
- }
474
- return this._getErrors() === 0;
475
- }
476
-
477
- isTouch() {
478
- return this._touch || (this.dirty && this.validateOnRender);
479
- }
480
-
481
- canSubmit() {
482
- return this.isTouch() && this.isValid();
483
- }
484
-
485
- _updateActions() {
486
- const submitBtn = this._getSubmitBtn();
487
- if (submitBtn != null) {
488
- if (this.canSubmit()) {
489
- this._getSubmitBtn().removeAttribute('disabled');
490
- } else {
491
- this._getSubmitBtn().setAttribute('disabled', true);
492
- }
493
- }
494
- const resetBtn = this._getResetBtn();
495
- if (resetBtn != null) {
496
- if (this.dirty) {
497
- resetBtn.removeAttribute('disabled');
498
- } else {
499
- resetBtn.setAttribute('disabled', true);
500
- }
501
- }
502
- }
503
-
504
- _updateChildren(withValidation) {
505
- if (withValidation) {
506
- this._validatorResults = {};
507
- this.errors = null;
508
- this.requestValidation();
509
- } else {
510
- this._updateActionsTimeout = setTimeout(() => this._updateActions(), 0);
511
- }
512
- }
513
-
514
- async updated(changedProperties) {
515
- clearTimeout(this._updateActionsTimeout);
516
- if (changedProperties.has('_values')) {
517
- this.getControls().forEach((control) => {
518
- control.value = get(this._values, control.id);
519
- });
520
- }
521
- this._updateChildren(this.validateOnRender && (changedProperties.has('_values') || changedProperties.has('schema')));
522
- }
523
-
524
- async getUpdateComplete() {
525
- const result = await super.getUpdateComplete();
526
- await Promise.all(this.getControls().map((e) => e.updateComplete));
527
- return result;
528
- }
529
-
530
- render() {
531
- return html`<form class="${classMap({ scrollable: this.scrollable })}">
532
- <div class="${classMap({ container: true, confirm: this._confirm })}">
533
- ${this.hasHeader === true
534
- ? html`
535
- <div class="header">
536
- <div class="${classMap({ title: true, center: this.hasHeader && !this.hasFooter })}">
537
- <slot name="title"></slot>
538
- </div>
539
- <div class="left">
540
- <slot name="header-left"></slot>
541
- </div>
542
- ${this.readonly === true || this.hasFooter === true
543
- ? ''
544
- : html`<div class="right">
545
- <gv-button
546
- id="reset"
547
- outlined
548
- small
549
- @gv-button:click="${this._onReset}"
550
- icon="general:update"
551
- title="Reset"
552
- ></gv-button>
553
- <gv-button
554
- id="submit"
555
- small
556
- @gv-button:click="${this._onSubmit}"
557
- icon="code:check"
558
- .title="${this.submitLabel}"
559
- ></gv-button>
560
- </div> `}
561
- </div>
562
- `
563
- : ''}
564
- <div class="content">${this.schema != null ? this._renderPart() : html``}</div>
565
- ${this.hasFooter === true && this.readonly !== true
566
- ? html`
567
- <div class="footer">
568
- <div class="left"></div>
569
- <div class="right">
570
- <gv-button id="reset" outlined @gv-button:click="${this._onReset}" icon="general:update" title="Reset">Reset</gv-button>
571
- <gv-button id="submit" @gv-button:click="${this._onSubmit}" icon="code:check" .title="${this.submitLabel}"
572
- >${this.submitLabel}</gv-button
573
- >
574
- </div>
575
- </div>
576
- `
577
- : ''}
578
- </div>
579
- </form>`;
580
- }
581
-
582
- static get styles() {
583
- return [
584
- empty,
585
- // language=CSS
586
- css`
587
- :host {
588
- box-sizing: border-box;
589
- margin: 0.2rem;
590
- --bgc: var(--gv-schema-form--bgc, #ffffff);
591
- }
592
-
593
- form {
594
- display: flex;
595
- flex-direction: column;
596
- }
597
-
598
- form.scrollable {
599
- position: absolute;
600
- width: 100%;
601
- top: 0;
602
- bottom: 0;
603
- left: 0;
604
- }
605
-
606
- .container {
607
- flex-grow: 1;
608
-
609
- background-color: var(--bgc);
610
- display: flex;
611
- flex-direction: column;
612
-
613
- /* for Firefox */
614
- min-height: 0;
615
- }
616
-
617
- .header,
618
- .footer,
619
- .content {
620
- background-color: var(--bgc);
621
- }
622
-
623
- .content {
624
- flex-grow: 1;
625
- display: flex;
626
- flex-direction: column;
627
- align-self: center;
628
- width: 100%;
629
-
630
- /* for Firefox */
631
- min-height: 0;
632
- }
633
-
634
- .content > gv-schema-form-control {
635
- align-self: center;
636
- width: 100%;
637
- }
638
-
639
- form.scrollable .content {
640
- overflow: auto;
641
- }
642
-
643
- form.scrollable .content > gv-schema-form-control,
644
- form.scrollable .content > .group-title {
645
- max-width: 775px;
646
- width: 95%;
647
- }
648
-
649
- .header,
650
- .footer {
651
- display: flex;
652
- box-sizing: border-box;
653
- min-height: 45px;
654
- --gv-icon--s: 26px;
655
- --gv-icon--c: #bfbfbf;
656
- align-items: center;
657
- padding: 0 0.5rem;
658
- position: relative;
659
- }
660
-
661
- .header {
662
- border-bottom: 1px solid #d9d9d9;
663
- }
664
-
665
- .footer {
666
- display: flex;
667
- justify-content: space-between;
668
- padding: 1rem;
669
- border-top: 1px solid #d9d9d9;
670
- }
671
-
672
- form.scrollable .footer {
673
- justify-content: center;
674
- }
675
-
676
- .footer .left,
677
- .footer .right {
678
- max-width: 400px;
679
- }
680
-
681
- .header .left,
682
- .footer .left,
683
- .header .right,
684
- .footer .right {
685
- display: flex;
686
- flex: 1;
687
- z-index: 10;
688
- align-items: center;
689
- }
690
-
691
- .header .right,
692
- .footer .right {
693
- justify-content: flex-end;
694
- }
695
-
696
- .header .title {
697
- color: #28444f;
698
- font-size: 18px;
699
- display: flex;
700
- width: 100%;
701
- align-items: center;
702
- }
703
-
704
- .header .title.center {
705
- position: absolute;
706
- top: 0;
707
- left: 0;
708
- bottom: 0;
709
- justify-content: center;
710
- }
711
-
712
- .confirm-box {
713
- height: 100%;
714
- padding: 1rem;
715
- font-style: italic;
716
- display: flex;
717
- flex-direction: column;
718
-
719
- justify-content: center;
720
- align-items: center;
721
- text-align: center;
722
- }
723
-
724
- .confirm-box_actions {
725
- padding: 1rem 0;
726
- }
727
-
728
- .confirm .header .left,
729
- .confirm .header .right,
730
- .confirm .footer .left,
731
- .confirm .footer .right {
732
- display: none;
733
- }
734
-
735
- .group-title {
736
- align-self: center;
737
- width: 100%;
738
- color: var(--gv-theme-font-color-dark);
739
- font-size: 21px;
740
- font-weight: 600;
741
- padding-bottom: 0.3em;
742
- border-bottom: 1px solid var(--gv-theme-font-color-dark);
743
- margin-top: 24px;
744
- margin-bottom: 16px;
745
- }
746
- `,
747
- ];
748
- }
749
- }
750
-
751
- window.customElements.define('gv-schema-form', GvSchemaForm);
1
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.GvSchemaForm=void 0;const t=require("lit"),e=require("object-path"),i=require("../lib/events"),s=require("../lib/utils"),o=require("lit/directives/class-map"),r=require("lit/directives/repeat"),a=require("jsonschema"),n=require("../styles/empty");require("./gv-schema-form-control");class l extends t.LitElement{static get properties(){return{schema:{type:Object},errors:{type:Object},values:{type:Object},submitLabel:{type:String},hasFooter:{type:Boolean,attribute:"has-footer"},hasHeader:{type:Boolean,attribute:"has-header"},_confirm:{type:Object},_values:{type:Object,attribute:!1},dirty:{type:Boolean,reflect:!0},hideDeprecated:{type:Boolean,attribute:"hide-deprecated"},validateOnRender:{type:Boolean,attribute:"validate-on-render"},_validatorResults:{type:Object},skeleton:{type:Boolean,reflect:!0},_touch:{type:Boolean},readonly:{type:Boolean,reflect:!0},scrollable:{type:Boolean,reflect:!0},groups:{type:Array}}}constructor(){super(),this.hideDeprecated=!1,this._values={},this.submitLabel="Ok",this.hasHeader=!1,this.hasFooter=!1,this._touch=!1,this._validator=new a.Validator,this._validatorResults={},this._ignoreProperties=[],this._dynamicControls=[],this._dynamicAttributes=["disabled","required","hidden"],this.groups=null,this.addEventListener("gv-schema-form-control:default-value",this._onDefaultValue.bind(this)),this.addEventListener("gv-schema-form-control:change",this._onChange.bind(this)),this.addEventListener("gv-schema-form-control:control-ready",this._onControlReady.bind(this))}set values(t){(0,s.deepEqual)(this._values,t)||(this._initialValues=t?{...t}:{},this._values=(0,s.deepClone)(this._initialValues))}get values(){return this._values}reset(t=null){this._values=(0,s.deepClone)(t||this._initialValues),this._touch=!1,this._setDirty(!1),this.getControls().forEach((t=>{t.requestUpdate()}))}_onReset(){this.reset(),(0,i.dispatchCustomEvent)(this,"reset")}requestValidation(){clearTimeout(this._validateTimeout),this._validateTimeout=setTimeout((()=>{this.validate(),this._updateActions()}),350)}submit(){this._onSubmit()}_onSubmit(){const t=this.validate();this.isValid()?(this._initialValues=(0,s.deepClone)(this._values),this.dirty=!1,this._touch=!1,(0,i.dispatchCustomEvent)(this,"submit",{values:this._values,validatorResults:t})):(0,i.dispatchCustomEvent)(this,"error",{values:this._values,validatorResults:t})}_setDirty(t=!0){this.dirty=!!t}_setTouch(t=!0){this._touch=!!t}confirm(){if(this.isTouch()){if(this._confirm&&this._confirm.promise)return this._confirm.promise;const t=new Promise(((t,e)=>this._confirm={resolve:t,reject:e}));return this._confirm.promise=t,t}return Promise.resolve()}_onConfirmReset(){const{resolve:t}=this._confirm;this._confirm=null,this._onReset(),this.requestUpdate(),this.updateComplete.then((()=>{t(this)}))}_onConfirmEdit(){this._confirm.reject(this),this._confirm=null,this._updateChildren(this.validateOnRender)}_getSubmitBtn(){return this.shadowRoot.querySelector("#submit")}_getResetBtn(){return this.shadowRoot.querySelector("#reset")}_dispatchChange(){clearTimeout(this._changeTimeout),this._changeTimeout=setTimeout((()=>{(0,i.dispatchCustomEvent)(this,"change",{target:this,values:this._values,validation:this._validatorResults})}),50)}_onDefaultValue({detail:{currentTarget:t,value:i,control:s}}){"integer"===s.type&&null!=i&&(i.trim&&i.length>0||i.length>0)&&(i=parseInt(i,10)),(0,e.set)(this._values,t.id,i)}_onChange({detail:{currentTarget:t,value:i,control:s}}){if(this._setTouch(!0),"integer"===s.type)if("string"==typeof i&&0===i.trim().length)i=null;else{const t=Number(i).valueOf();i=isNaN(t)?null:t}else"array"===s.type&&0===i.length?i=null:"string"!==s.type||0!==i.trim().length||s.enum?"object"===s.type&&0===Object.keys(i).length&&(i=null):i=null;null==i?(0,e.del)(this._values,t.id):(0,e.set)(this._values,t.id,i),this._updateDynamicControls(),this._validatorResults=this.validate(),this.dirty=!0,this._updateActions(),this._dispatchChange()}_onControlReady(t){t.stopPropagation(),t.preventDefault();const e=t.detail.control,s=e.control;if(s["x-schema-form"])if(s["x-schema-form"].event){const e=s["x-schema-form"].event;(0,i.dispatchCustomEvent)(this,e.name,{...e,...t.detail})}else this._hasCondition(s)&&(this._dynamicControls.push(e),this._updateDynamicControl(e))}_updateDynamicControls(){this._ignoreProperties=[],this._dynamicControls.forEach((t=>{this._updateDynamicControl(t)}))}_updateDynamicControl(t){const e=t.control;return e["x-schema-form"]&&this._dynamicAttributes.forEach((i=>{this._evaluateCondition(e,i)?(t.setAttribute(i,""),"hidden"===i&&this._ignoreProperties.push(t.id)):t.removeAttribute(i)})),null}async performUpdate(){await Promise.all(this.getControls().map((t=>t.updateComplete))),this.getControls().forEach((t=>{t.requestUpdate()})),super.performUpdate()}_renderControl(i){const s={...this.schema.properties[i]},o=this.schema.required&&this.schema.required.includes(i)||this._evaluateCondition(s,"required"),r=this.schema.disabled&&this.schema.disabled.includes(i)||this._evaluateCondition(s,"disabled"),a=this._evaluateCondition(s,"hidden");a&&this._ignoreProperties.push(i);const n=this.readonly||!0===s.readOnly,l=!0===s.writeOnly,h=(0,e.get)(this._values,i);return t.html`<gv-schema-form-control .id="${i}" .errors="${this.errors}" .control="${s}" .skeleton="${this.skeleton}" .value="${h}" ?readonly="${n}" ?writeonly="${l}" ?required="${o}" ?disabled="${r}" ?hidden="${a}"></gv-schema-form-control>`}_hasCondition(t){return!!t["x-schema-form"]&&null!=this._dynamicAttributes.find((e=>null!=t["x-schema-form"][e]))}_evaluateCondition(t,e){if(null==t["x-schema-form"]||null==t["x-schema-form"][e])return!1;const i=t["x-schema-form"][e];if("boolean"==typeof i)return i;if(!Array.isArray(i))return console.warn(`'${e}' attribute of 'x-schema-form' should be an array`),!1;let s=!0;for(const e of i){const i=Object.keys(e)[0];switch(i){case"$neq":s=s&&this._evaluateNotEqualsCondition(t,e);break;case"$eq":s=s&&this._evaluateEqualsCondition(t,e);break;case"$nodef":s=s&&this._evaluateNotDefCondition(t,e);break;case"$def":s=s&&this._evaluateDefCondition(t,e);break;default:console.warn(`Unsupported operator '${i}' on disable condition`),s=!1}}return s}_evaluateNotEqualsCondition(t,e){return!this._evaluateEqualsCondition(t,e)}_evaluateEqualsCondition(t,i){const s=i[Object.keys(i)[0]];return Object.keys(s).map((i=>{const o=s[i];let r=(0,e.get)(this._values,i);return null==r&&"string"===t.type&&(r=""),Array.isArray(o)?o.includes(r):r===o})).reduce(((t,e)=>t||e))}_evaluateNotDefCondition(t,i){const s=i[Object.keys(i)[0]];return void 0===(0,e.get)(this._values,s)||null===(0,e.get)(this._values,s)}_evaluateDefCondition(t,e){return!this._evaluateNotDefCondition(t,e)}_renderPart(){if(this._confirm)return t.html`<div class="confirm-box"><div class="error">The configuration is not valid and cannot be saved.</div><div class="confirm-box_actions"><gv-button @gv-button:click="${this._onConfirmReset}" outlined icon="general:update" danger>Lose changes</gv-button><gv-button @gv-button:click="${this._onConfirmEdit}" icon="design:edit">Edit</gv-button></div></div>`;const e=this.schema.properties?Object.keys(this.schema.properties):[];if(this._ignoreProperties=[],this.groups){const i=this.groups.reduce(((t,i)=>{const s=e.filter((t=>[...i.items||[]].includes(t)));return t.push({...i,items:s||[]}),t}),[]),s=i.find((t=>t.default))||{default:!0,items:[]},o=i.reduce(((t,e)=>[...t,...e.items]),[]);return s.items=e.filter((t=>!o.includes(t))),(0,r.repeat)(i,(e=>t.html`${e.name?t.html`<h2 class="group-title">${e.name}</h2>${(0,r.repeat)(e.items,(t=>this._renderControl(t)))}`:(0,r.repeat)(e.items,(t=>this._renderControl(t)))}`))}return t.html`${(0,r.repeat)([1],(()=>(0,r.repeat)(e,(t=>t),(t=>this._renderControl(t)))))}`}getControls(){return Array.from(this.shadowRoot.querySelectorAll("gv-schema-form-control"))}getControl(t){return this.shadowRoot.querySelector(`[id="${t}"]`)}_getErrors(){return(this._validatorResults.errors||[]).filter((t=>{let i=`${t.property.replace("instance.","")}`;Array.isArray(t.argument)||(i=`${i}.${t.argument}`);const s=`x-schema-form.errors.${i}.${t.name}`,o=(0,e.get)(this.schema,s);return o&&(t.message=o),!this._ignoreProperties.includes(i)}))}validate(){return this.schema&&(this._validatorResults=this._validator.validate(this._values,{...this.schema,additionalProperties:{}}),this.errors=this._getErrors()),this._validatorResults}isValid(){return!!this._validatorResults.valid||0===this._getErrors()}isTouch(){return this._touch||this.dirty&&this.validateOnRender}canSubmit(){return this.isTouch()&&this.isValid()}_updateActions(){null!=this._getSubmitBtn()&&(this.canSubmit()?this._getSubmitBtn().removeAttribute("disabled"):this._getSubmitBtn().setAttribute("disabled",!0));const t=this._getResetBtn();null!=t&&(this.dirty?t.removeAttribute("disabled"):t.setAttribute("disabled",!0))}_updateChildren(t){t?(this._validatorResults={},this.errors=null,this.requestValidation()):this._updateActionsTimeout=setTimeout((()=>this._updateActions()),0)}async updated(t){clearTimeout(this._updateActionsTimeout),t.has("_values")&&this.getControls().forEach((t=>{t.value=(0,e.get)(this._values,t.id)})),this._updateChildren(this.validateOnRender&&(t.has("_values")||t.has("schema")))}async getUpdateComplete(){const t=await super.getUpdateComplete();return await Promise.all(this.getControls().map((t=>t.updateComplete))),t}render(){return t.html`<form class="${(0,o.classMap)({scrollable:this.scrollable})}"><div class="${(0,o.classMap)({container:!0,confirm:this._confirm})}">${!0===this.hasHeader?t.html`<div class="header"><div class="${(0,o.classMap)({title:!0,center:this.hasHeader&&!this.hasFooter})}"><slot name="title"></slot></div><div class="left"><slot name="header-left"></slot></div>${!0===this.readonly||!0===this.hasFooter?"":t.html`<div class="right"><gv-button id="reset" outlined small @gv-button:click="${this._onReset}" icon="general:update" title="Reset"></gv-button><gv-button id="submit" small @gv-button:click="${this._onSubmit}" icon="code:check" .title="${this.submitLabel}"></gv-button></div>`}</div>`:""}<div class="content">${null!=this.schema?this._renderPart():t.html``}</div>${!0===this.hasFooter&&!0!==this.readonly?t.html`<div class="footer"><div class="left"></div><div class="right"><gv-button id="reset" outlined @gv-button:click="${this._onReset}" icon="general:update" title="Reset">Reset</gv-button><gv-button id="submit" @gv-button:click="${this._onSubmit}" icon="code:check" .title="${this.submitLabel}">${this.submitLabel}</gv-button></div></div>`:""}</div></form>`}static get styles(){return[n.empty,t.css`:host{box-sizing:border-box;margin:.2rem;--bgc:var(--gv-schema-form--bgc, #ffffff)}form{display:flex;flex-direction:column}form.scrollable{position:absolute;width:100%;top:0;bottom:0;left:0}.container{flex-grow:1;background-color:var(--bgc);display:flex;flex-direction:column;min-height:0}.content,.footer,.header{background-color:var(--bgc)}.content{flex-grow:1;display:flex;flex-direction:column;align-self:center;width:100%;min-height:0}.content>gv-schema-form-control{align-self:center;width:100%}form.scrollable .content{overflow:auto}form.scrollable .content>.group-title,form.scrollable .content>gv-schema-form-control{max-width:775px;width:95%}.footer,.header{display:flex;box-sizing:border-box;min-height:45px;--gv-icon--s:26px;--gv-icon--c:#bfbfbf;align-items:center;padding:0 .5rem;position:relative}.header{border-bottom:1px solid #d9d9d9}.footer{display:flex;justify-content:space-between;padding:1rem;border-top:1px solid #d9d9d9}form.scrollable .footer{justify-content:center}.footer .left,.footer .right{max-width:400px}.footer .left,.footer .right,.header .left,.header .right{display:flex;flex:1;z-index:10;align-items:center}.footer .right,.header .right{justify-content:flex-end}.header .title{color:#28444f;font-size:18px;display:flex;width:100%;align-items:center}.header .title.center{position:absolute;top:0;left:0;bottom:0;justify-content:center}.confirm-box{height:100%;padding:1rem;font-style:italic;display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center}.confirm-box_actions{padding:1rem 0}.confirm .footer .left,.confirm .footer .right,.confirm .header .left,.confirm .header .right{display:none}.group-title{align-self:center;width:100%;color:var(--gv-theme-font-color-dark);font-size:21px;font-weight:600;padding-bottom:.3em;border-bottom:1px solid var(--gv-theme-font-color-dark);margin-top:24px;margin-bottom:16px}`]}}exports.GvSchemaForm=l,window.customElements.define("gv-schema-form",l);