@unicef-polymer/etools-form-builder 2.1.0 → 2.1.1

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 (83) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +1 -1
  3. package/dist/form-attachments-popup/form-attachments-popup.d.ts +85 -85
  4. package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
  5. package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
  6. package/dist/form-attachments-popup/form-attachments-popup.js +248 -248
  7. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +3 -3
  8. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +89 -89
  9. package/dist/form-attachments-popup/index.d.ts +2 -2
  10. package/dist/form-attachments-popup/index.js +2 -2
  11. package/dist/form-fields/abstract-field-base.class.d.ts +28 -28
  12. package/dist/form-fields/abstract-field-base.class.js +176 -176
  13. package/dist/form-fields/field-renderer-component.d.ts +20 -20
  14. package/dist/form-fields/field-renderer-component.js +249 -249
  15. package/dist/form-fields/index.d.ts +12 -12
  16. package/dist/form-fields/index.js +12 -12
  17. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -17
  18. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +208 -208
  19. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -20
  20. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -123
  21. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
  22. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +66 -66
  23. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
  24. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -108
  25. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
  26. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -53
  27. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
  28. package/dist/form-fields/single-fields/attachment-field.js +97 -97
  29. package/dist/form-fields/single-fields/base-field.d.ts +11 -11
  30. package/dist/form-fields/single-fields/base-field.js +57 -57
  31. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
  32. package/dist/form-fields/single-fields/boolean-field.js +49 -49
  33. package/dist/form-fields/single-fields/number-field.d.ts +10 -10
  34. package/dist/form-fields/single-fields/number-field.js +66 -66
  35. package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
  36. package/dist/form-fields/single-fields/scale-field.js +107 -107
  37. package/dist/form-fields/single-fields/text-field.d.ts +8 -8
  38. package/dist/form-fields/single-fields/text-field.js +54 -54
  39. package/dist/form-groups/form-abstract-group.d.ts +60 -60
  40. package/dist/form-groups/form-abstract-group.js +353 -353
  41. package/dist/form-groups/form-card.d.ts +32 -32
  42. package/dist/form-groups/form-card.js +108 -108
  43. package/dist/form-groups/form-collapsed-card.d.ts +70 -70
  44. package/dist/form-groups/form-collapsed-card.js +253 -253
  45. package/dist/form-groups/index.d.ts +3 -3
  46. package/dist/form-groups/index.js +3 -3
  47. package/dist/index.d.ts +3 -3
  48. package/dist/index.js +3 -3
  49. package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -16
  50. package/dist/lib/additional-components/confirmation-dialog.js +65 -65
  51. package/dist/lib/additional-components/etools-fb-card.d.ts +16 -16
  52. package/dist/lib/additional-components/etools-fb-card.js +215 -215
  53. package/dist/lib/styles/attachments.styles.d.ts +2 -2
  54. package/dist/lib/styles/attachments.styles.js +72 -72
  55. package/dist/lib/styles/card-styles.d.ts +2 -2
  56. package/dist/lib/styles/card-styles.js +154 -154
  57. package/dist/lib/styles/dialog.styles.d.ts +2 -2
  58. package/dist/lib/styles/dialog.styles.js +85 -85
  59. package/dist/lib/styles/elevation-styles.d.ts +9 -9
  60. package/dist/lib/styles/elevation-styles.js +43 -43
  61. package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
  62. package/dist/lib/styles/flex-layout-classes.js +319 -319
  63. package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
  64. package/dist/lib/styles/form-builder-card.styles.js +49 -49
  65. package/dist/lib/styles/input-styles.d.ts +2 -2
  66. package/dist/lib/styles/input-styles.js +138 -138
  67. package/dist/lib/styles/page-layout-styles.d.ts +2 -2
  68. package/dist/lib/styles/page-layout-styles.js +201 -201
  69. package/dist/lib/styles/shared-styles.d.ts +2 -2
  70. package/dist/lib/styles/shared-styles.js +70 -70
  71. package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
  72. package/dist/lib/types/form-builder.interfaces.js +0 -0
  73. package/dist/lib/types/form-builder.types.d.ts +59 -59
  74. package/dist/lib/types/form-builder.types.js +0 -0
  75. package/dist/lib/types/global.types.d.ts +4 -4
  76. package/dist/lib/types/global.types.js +0 -0
  77. package/dist/lib/utils/dialog.d.ts +10 -10
  78. package/dist/lib/utils/dialog.js +21 -21
  79. package/dist/lib/utils/fire-custom-event.d.ts +1 -1
  80. package/dist/lib/utils/fire-custom-event.js +7 -7
  81. package/dist/lib/utils/validations.helper.d.ts +26 -26
  82. package/dist/lib/utils/validations.helper.js +35 -35
  83. package/package.json +56 -56
@@ -1,353 +1,353 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- import { LitElement, property, html, css, customElement } from 'lit-element';
8
- import '../form-fields/single-fields/text-field';
9
- import '../form-fields/single-fields/number-field';
10
- import '../form-fields/single-fields/scale-field';
11
- import '@polymer/paper-input/paper-textarea';
12
- import { SharedStyles } from '../lib/styles/shared-styles';
13
- import { pageLayoutStyles } from '../lib/styles/page-layout-styles';
14
- import { elevationStyles } from '../lib/styles/elevation-styles';
15
- import { CardStyles } from '../lib/styles/card-styles';
16
- import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
17
- import { fireEvent } from '../lib/utils/fire-custom-event';
18
- import { clone } from 'ramda';
19
- import { live } from 'lit-html/directives/live';
20
- import { openDialog } from '../lib/utils/dialog';
21
- import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
22
- export var FieldTypes;
23
- (function (FieldTypes) {
24
- FieldTypes["FILE_TYPE"] = "file";
25
- FieldTypes["TEXT_TYPE"] = "text";
26
- FieldTypes["NUMBER_TYPE"] = "number";
27
- FieldTypes["BOOL_TYPE"] = "bool";
28
- FieldTypes["SCALE_TYPE"] = "likert_scale";
29
- FieldTypes["NUMBER_INTEGER_TYPE"] = "number-integer";
30
- FieldTypes["NUMBER_FLOAT_TYPE"] = "number-float";
31
- })(FieldTypes || (FieldTypes = {}));
32
- export var StructureTypes;
33
- (function (StructureTypes) {
34
- StructureTypes["WIDE"] = "wide";
35
- StructureTypes["ADDITIONAL"] = "additional";
36
- StructureTypes["CARD"] = "card";
37
- StructureTypes["ABSTRACT"] = "abstract";
38
- StructureTypes["COLLAPSED"] = "collapse";
39
- StructureTypes["ATTACHMENTS_BUTTON"] = "floating_attachments";
40
- })(StructureTypes || (StructureTypes = {}));
41
- let FormAbstractGroup = class FormAbstractGroup extends LitElement {
42
- constructor() {
43
- super(...arguments);
44
- this.parentGroupName = '';
45
- this.readonly = false;
46
- this._errors = {};
47
- this._value = {};
48
- this.computedPath = [];
49
- }
50
- /**
51
- * Make value property immutable
52
- * @param value
53
- */
54
- set value(value) {
55
- this._value = this.groupStructure.name === 'root' ? clone(value) : value;
56
- }
57
- get value() {
58
- return this._value;
59
- }
60
- /**
61
- * Setter for handling error.
62
- * Normally we wouldn't have errors as string or string[] for FormGroups.
63
- * In cases they appear - show toast with error text and reset it.
64
- * Otherwise it will be impossible to clear that error from field elements
65
- * @param errors
66
- */
67
- set errors(errors) {
68
- if (Array.isArray(errors)) {
69
- fireEvent(this, 'toast', { text: errors[0] });
70
- fireEvent(this, 'error-changed', { error: null });
71
- }
72
- else if (errors) {
73
- this._errors = errors;
74
- }
75
- }
76
- render() {
77
- if (!this.groupStructure || !this.metadata) {
78
- return html ``;
79
- }
80
- return html `
81
- ${this.groupStructure.children.map((child) => this.renderChild(child))}
82
- `;
83
- }
84
- renderChild(child) {
85
- const type = child.type;
86
- switch (child.type) {
87
- case 'field':
88
- return this.renderField(child);
89
- case 'group':
90
- return this.renderGroup(child);
91
- case 'information':
92
- return this.renderInformation(child);
93
- default:
94
- console.warn(`FormBuilderGroup: Unknown group type ${type}. Please, specify rendering method`);
95
- return html ``;
96
- }
97
- }
98
- renderField(blueprintField) {
99
- var _a;
100
- return html `
101
- <field-renderer
102
- .field="${blueprintField}"
103
- ?readonly="${live(this.readonly)}"
104
- .value="${this.value && this.value[blueprintField.name]}"
105
- .validations="${blueprintField.validations.map((validation) => this.metadata.validations[validation])}"
106
- .errorMessage="${this.getErrorMessage(blueprintField.name)}"
107
- .options="${((_a = this.metadata.options[blueprintField.options_key || '']) === null || _a === void 0 ? void 0 : _a.values) || []}"
108
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [blueprintField.name] : [this.groupStructure.name, blueprintField.name])}"
109
- @value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
110
- @error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
111
- ></field-renderer>
112
- `;
113
- }
114
- renderInformation(information) {
115
- return html `<section class="elevation page-content" elevation="1">${information.text}</section>`;
116
- }
117
- renderGroup(groupStructure) {
118
- if (!groupStructure.repeatable) {
119
- return this.getGroupTemplate(groupStructure);
120
- }
121
- const value = (this.value && this.value[groupStructure.name]) || [{}];
122
- return html `
123
- ${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
124
- <paper-button class="add-group save-button" @click="${() => this.addGroup(groupStructure.name)}">
125
- Add ${!groupStructure.title || groupStructure.title.length > 15 ? 'group' : groupStructure.title}
126
- </paper-button>
127
- `;
128
- }
129
- getGroupTemplate(groupStructure, index) {
130
- const isAbstract = groupStructure.styling.includes(StructureTypes.ABSTRACT);
131
- const isCard = groupStructure.styling.includes(StructureTypes.CARD);
132
- const isCollapsed = groupStructure.styling.includes(StructureTypes.COLLAPSED);
133
- let value = this.value && this.value[groupStructure.name];
134
- if (typeof index === 'number') {
135
- value = value && value[index];
136
- }
137
- let errors = this._errors[groupStructure.name];
138
- if (typeof index === 'number') {
139
- errors = errors && errors[index];
140
- }
141
- if (isAbstract) {
142
- return html `
143
- <form-abstract-group
144
- .groupStructure="${groupStructure}"
145
- .value="${value}"
146
- .metadata="${this.metadata}"
147
- .parentGroupName="${this.groupStructure.name}"
148
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
149
- .readonly="${this.readonly}"
150
- .errors="${errors || null}"
151
- @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
152
- @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
153
- ></form-abstract-group>
154
- `;
155
- }
156
- else if (isCard && isCollapsed) {
157
- return html `
158
- <form-collapsed-card
159
- .groupStructure="${groupStructure}"
160
- .value="${value}"
161
- .metadata="${this.metadata}"
162
- .parentGroupName="${this.groupStructure.name}"
163
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
164
- .readonly="${this.readonly}"
165
- .errors="${errors || null}"
166
- @remove-group="${() => this.removeGroup(groupStructure, index)}"
167
- @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
168
- @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
169
- ></form-collapsed-card>
170
- `;
171
- }
172
- else if (isCard) {
173
- return html `
174
- <form-card
175
- .groupStructure="${groupStructure}"
176
- .value="${value}"
177
- .metadata="${this.metadata}"
178
- .parentGroupName="${this.groupStructure.name}"
179
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
180
- .readonly="${this.readonly}"
181
- .errors="${errors || null}"
182
- @remove-group="${() => this.removeGroup(groupStructure, index)}"
183
- @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
184
- @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
185
- ></form-card>
186
- `;
187
- }
188
- else {
189
- console.warn(`FormBuilderGroup: Unknown group type: ${groupStructure.styling}`);
190
- return html ``;
191
- }
192
- }
193
- valueChanged(event, name, index) {
194
- if (!this.value) {
195
- this.value = {};
196
- }
197
- if (typeof index === 'number') {
198
- const value = this.value[name] || [];
199
- value[index] = event.detail.value;
200
- this.value[name] = value;
201
- }
202
- else {
203
- this.value[name] = event.detail.value;
204
- }
205
- if (event.stopPropagation) {
206
- event.stopPropagation();
207
- }
208
- fireEvent(this, 'value-changed', { value: this.value });
209
- this.requestUpdate();
210
- }
211
- errorChanged(event, name, index) {
212
- const errorMessage = event.detail.error;
213
- if (typeof index === 'number') {
214
- const errors = this._errors[name] || (this.value && new Array(this.value[name].length).fill(null)) || [];
215
- errors.splice(index, 1, errorMessage);
216
- const hasErrors = errors.some((error) => error !== null);
217
- this._errors[name] = hasErrors ? errors : null;
218
- }
219
- else if (errorMessage) {
220
- this._errors[name] = errorMessage;
221
- }
222
- else {
223
- delete this._errors[name];
224
- }
225
- event.stopPropagation();
226
- const errors = Object.keys(this._errors).length ? this._errors : null;
227
- fireEvent(this, 'error-changed', { error: errors });
228
- }
229
- addGroup(name) {
230
- const value = this.value[name] || [];
231
- value.push({});
232
- this.valueChanged({ detail: { value } }, name);
233
- }
234
- removeGroup(group, index) {
235
- if (typeof index !== 'number') {
236
- return;
237
- }
238
- const value = (this.value && this.value[group.name]) || [];
239
- if (group.required && value.length < 2) {
240
- openDialog({
241
- dialog: 'confirmation-popup',
242
- dialogData: {
243
- text: `Group is required. At least one group must exist`,
244
- hideConfirmBtn: true,
245
- dialogTitle: ''
246
- }
247
- });
248
- return;
249
- }
250
- value.splice(index, 1);
251
- this.valueChanged({ detail: { value } }, group.name);
252
- }
253
- getErrorMessage(fieldName) {
254
- const error = this._errors && this._errors[fieldName];
255
- return Array.isArray(error) ? error[0] : error || null;
256
- }
257
- static get styles() {
258
- // language=CSS
259
- return [
260
- SharedStyles,
261
- pageLayoutStyles,
262
- elevationStyles,
263
- CardStyles,
264
- FlexLayoutClasses,
265
- FormBuilderCardStyles,
266
- css `
267
- :host {
268
- display: flex;
269
- flex-direction: column;
270
- }
271
- .add-group {
272
- align-self: flex-end;
273
- margin-right: 23px;
274
- margin-top: 20px;
275
- box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12),
276
- 0 2px 4px -1px rgba(0, 0, 0, 0.4);
277
- }
278
- .card-header {
279
- display: flex;
280
- align-items: center;
281
- justify-content: space-between;
282
- }
283
- .card-header .remove-group {
284
- display: flex;
285
- align-items: center;
286
- justify-content: flex-end;
287
- padding: 0 10px 8px;
288
- cursor: pointer;
289
- width: min-content;
290
- white-space: nowrap;
291
- }
292
- .card-header .title {
293
- padding: 0 24px 8px;
294
- font-size: 18px;
295
- font-weight: bold;
296
- }
297
- .save-button {
298
- margin-top: 8px;
299
- color: var(--primary-background-color);
300
- background-color: var(--primary-color);
301
- }
302
- .information-source {
303
- padding: 0.5% 2% 0.5% 1%;
304
- }
305
-
306
- .additional-field {
307
- padding-top: 15px;
308
- padding-bottom: 20px;
309
- background-color: var(--secondary-background-color);
310
- }
311
-
312
- .actions-container {
313
- padding: 0 25px 5px 45px;
314
- box-sizing: border-box;
315
- }
316
-
317
- .card-container.form-card {
318
- padding: 12px 0 15px;
319
- }
320
-
321
- .attachments-warning {
322
- color: red;
323
- }
324
- paper-icon-button[icon='close'] {
325
- cursor: pointer;
326
- color: var(--primary-text-color);
327
- }
328
- `
329
- ];
330
- }
331
- };
332
- __decorate([
333
- property({ type: Object })
334
- ], FormAbstractGroup.prototype, "groupStructure", void 0);
335
- __decorate([
336
- property({ type: Object })
337
- ], FormAbstractGroup.prototype, "metadata", void 0);
338
- __decorate([
339
- property({ type: String })
340
- ], FormAbstractGroup.prototype, "parentGroupName", void 0);
341
- __decorate([
342
- property({ type: Boolean, attribute: 'readonly' })
343
- ], FormAbstractGroup.prototype, "readonly", void 0);
344
- __decorate([
345
- property()
346
- ], FormAbstractGroup.prototype, "_errors", void 0);
347
- __decorate([
348
- property()
349
- ], FormAbstractGroup.prototype, "_value", void 0);
350
- FormAbstractGroup = __decorate([
351
- customElement('form-abstract-group')
352
- ], FormAbstractGroup);
353
- export { FormAbstractGroup };
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { LitElement, property, html, css, customElement } from 'lit-element';
8
+ import '../form-fields/single-fields/text-field';
9
+ import '../form-fields/single-fields/number-field';
10
+ import '../form-fields/single-fields/scale-field';
11
+ import '@polymer/paper-input/paper-textarea';
12
+ import { SharedStyles } from '../lib/styles/shared-styles';
13
+ import { pageLayoutStyles } from '../lib/styles/page-layout-styles';
14
+ import { elevationStyles } from '../lib/styles/elevation-styles';
15
+ import { CardStyles } from '../lib/styles/card-styles';
16
+ import { FlexLayoutClasses } from '../lib/styles/flex-layout-classes';
17
+ import { fireEvent } from '../lib/utils/fire-custom-event';
18
+ import { clone } from 'ramda';
19
+ import { live } from 'lit-html/directives/live';
20
+ import { openDialog } from '../lib/utils/dialog';
21
+ import { FormBuilderCardStyles } from '../lib/styles/form-builder-card.styles';
22
+ export var FieldTypes;
23
+ (function (FieldTypes) {
24
+ FieldTypes["FILE_TYPE"] = "file";
25
+ FieldTypes["TEXT_TYPE"] = "text";
26
+ FieldTypes["NUMBER_TYPE"] = "number";
27
+ FieldTypes["BOOL_TYPE"] = "bool";
28
+ FieldTypes["SCALE_TYPE"] = "likert_scale";
29
+ FieldTypes["NUMBER_INTEGER_TYPE"] = "number-integer";
30
+ FieldTypes["NUMBER_FLOAT_TYPE"] = "number-float";
31
+ })(FieldTypes || (FieldTypes = {}));
32
+ export var StructureTypes;
33
+ (function (StructureTypes) {
34
+ StructureTypes["WIDE"] = "wide";
35
+ StructureTypes["ADDITIONAL"] = "additional";
36
+ StructureTypes["CARD"] = "card";
37
+ StructureTypes["ABSTRACT"] = "abstract";
38
+ StructureTypes["COLLAPSED"] = "collapse";
39
+ StructureTypes["ATTACHMENTS_BUTTON"] = "floating_attachments";
40
+ })(StructureTypes || (StructureTypes = {}));
41
+ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
42
+ constructor() {
43
+ super(...arguments);
44
+ this.parentGroupName = '';
45
+ this.readonly = false;
46
+ this._errors = {};
47
+ this._value = {};
48
+ this.computedPath = [];
49
+ }
50
+ /**
51
+ * Make value property immutable
52
+ * @param value
53
+ */
54
+ set value(value) {
55
+ this._value = this.groupStructure.name === 'root' ? clone(value) : value;
56
+ }
57
+ get value() {
58
+ return this._value;
59
+ }
60
+ /**
61
+ * Setter for handling error.
62
+ * Normally we wouldn't have errors as string or string[] for FormGroups.
63
+ * In cases they appear - show toast with error text and reset it.
64
+ * Otherwise it will be impossible to clear that error from field elements
65
+ * @param errors
66
+ */
67
+ set errors(errors) {
68
+ if (Array.isArray(errors)) {
69
+ fireEvent(this, 'toast', { text: errors[0] });
70
+ fireEvent(this, 'error-changed', { error: null });
71
+ }
72
+ else if (errors) {
73
+ this._errors = errors;
74
+ }
75
+ }
76
+ render() {
77
+ if (!this.groupStructure || !this.metadata) {
78
+ return html ``;
79
+ }
80
+ return html `
81
+ ${this.groupStructure.children.map((child) => this.renderChild(child))}
82
+ `;
83
+ }
84
+ renderChild(child) {
85
+ const type = child.type;
86
+ switch (child.type) {
87
+ case 'field':
88
+ return this.renderField(child);
89
+ case 'group':
90
+ return this.renderGroup(child);
91
+ case 'information':
92
+ return this.renderInformation(child);
93
+ default:
94
+ console.warn(`FormBuilderGroup: Unknown group type ${type}. Please, specify rendering method`);
95
+ return html ``;
96
+ }
97
+ }
98
+ renderField(blueprintField) {
99
+ var _a;
100
+ return html `
101
+ <field-renderer
102
+ .field="${blueprintField}"
103
+ ?readonly="${live(this.readonly)}"
104
+ .value="${this.value && this.value[blueprintField.name]}"
105
+ .validations="${blueprintField.validations.map((validation) => this.metadata.validations[validation])}"
106
+ .errorMessage="${this.getErrorMessage(blueprintField.name)}"
107
+ .options="${((_a = this.metadata.options[blueprintField.options_key || '']) === null || _a === void 0 ? void 0 : _a.values) || []}"
108
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [blueprintField.name] : [this.groupStructure.name, blueprintField.name])}"
109
+ @value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
110
+ @error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
111
+ ></field-renderer>
112
+ `;
113
+ }
114
+ renderInformation(information) {
115
+ return html `<section class="elevation page-content" elevation="1">${information.text}</section>`;
116
+ }
117
+ renderGroup(groupStructure) {
118
+ if (!groupStructure.repeatable) {
119
+ return this.getGroupTemplate(groupStructure);
120
+ }
121
+ const value = (this.value && this.value[groupStructure.name]) || [{}];
122
+ return html `
123
+ ${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
124
+ <paper-button class="add-group save-button" @click="${() => this.addGroup(groupStructure.name)}">
125
+ Add ${!groupStructure.title || groupStructure.title.length > 15 ? 'group' : groupStructure.title}
126
+ </paper-button>
127
+ `;
128
+ }
129
+ getGroupTemplate(groupStructure, index) {
130
+ const isAbstract = groupStructure.styling.includes(StructureTypes.ABSTRACT);
131
+ const isCard = groupStructure.styling.includes(StructureTypes.CARD);
132
+ const isCollapsed = groupStructure.styling.includes(StructureTypes.COLLAPSED);
133
+ let value = this.value && this.value[groupStructure.name];
134
+ if (typeof index === 'number') {
135
+ value = value && value[index];
136
+ }
137
+ let errors = this._errors[groupStructure.name];
138
+ if (typeof index === 'number') {
139
+ errors = errors && errors[index];
140
+ }
141
+ if (isAbstract) {
142
+ return html `
143
+ <form-abstract-group
144
+ .groupStructure="${groupStructure}"
145
+ .value="${value}"
146
+ .metadata="${this.metadata}"
147
+ .parentGroupName="${this.groupStructure.name}"
148
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
149
+ .readonly="${this.readonly}"
150
+ .errors="${errors || null}"
151
+ @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
152
+ @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
153
+ ></form-abstract-group>
154
+ `;
155
+ }
156
+ else if (isCard && isCollapsed) {
157
+ return html `
158
+ <form-collapsed-card
159
+ .groupStructure="${groupStructure}"
160
+ .value="${value}"
161
+ .metadata="${this.metadata}"
162
+ .parentGroupName="${this.groupStructure.name}"
163
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
164
+ .readonly="${this.readonly}"
165
+ .errors="${errors || null}"
166
+ @remove-group="${() => this.removeGroup(groupStructure, index)}"
167
+ @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
168
+ @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
169
+ ></form-collapsed-card>
170
+ `;
171
+ }
172
+ else if (isCard) {
173
+ return html `
174
+ <form-card
175
+ .groupStructure="${groupStructure}"
176
+ .value="${value}"
177
+ .metadata="${this.metadata}"
178
+ .parentGroupName="${this.groupStructure.name}"
179
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
180
+ .readonly="${this.readonly}"
181
+ .errors="${errors || null}"
182
+ @remove-group="${() => this.removeGroup(groupStructure, index)}"
183
+ @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
184
+ @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
185
+ ></form-card>
186
+ `;
187
+ }
188
+ else {
189
+ console.warn(`FormBuilderGroup: Unknown group type: ${groupStructure.styling}`);
190
+ return html ``;
191
+ }
192
+ }
193
+ valueChanged(event, name, index) {
194
+ if (!this.value) {
195
+ this.value = {};
196
+ }
197
+ if (typeof index === 'number') {
198
+ const value = this.value[name] || [];
199
+ value[index] = event.detail.value;
200
+ this.value[name] = value;
201
+ }
202
+ else {
203
+ this.value[name] = event.detail.value;
204
+ }
205
+ if (event.stopPropagation) {
206
+ event.stopPropagation();
207
+ }
208
+ fireEvent(this, 'value-changed', { value: this.value });
209
+ this.requestUpdate();
210
+ }
211
+ errorChanged(event, name, index) {
212
+ const errorMessage = event.detail.error;
213
+ if (typeof index === 'number') {
214
+ const errors = this._errors[name] || (this.value && new Array(this.value[name].length).fill(null)) || [];
215
+ errors.splice(index, 1, errorMessage);
216
+ const hasErrors = errors.some((error) => error !== null);
217
+ this._errors[name] = hasErrors ? errors : null;
218
+ }
219
+ else if (errorMessage) {
220
+ this._errors[name] = errorMessage;
221
+ }
222
+ else {
223
+ delete this._errors[name];
224
+ }
225
+ event.stopPropagation();
226
+ const errors = Object.keys(this._errors).length ? this._errors : null;
227
+ fireEvent(this, 'error-changed', { error: errors });
228
+ }
229
+ addGroup(name) {
230
+ const value = this.value[name] || [];
231
+ value.push({});
232
+ this.valueChanged({ detail: { value } }, name);
233
+ }
234
+ removeGroup(group, index) {
235
+ if (typeof index !== 'number') {
236
+ return;
237
+ }
238
+ const value = (this.value && this.value[group.name]) || [];
239
+ if (group.required && value.length < 2) {
240
+ openDialog({
241
+ dialog: 'confirmation-popup',
242
+ dialogData: {
243
+ text: `Group is required. At least one group must exist`,
244
+ hideConfirmBtn: true,
245
+ dialogTitle: ''
246
+ }
247
+ });
248
+ return;
249
+ }
250
+ value.splice(index, 1);
251
+ this.valueChanged({ detail: { value } }, group.name);
252
+ }
253
+ getErrorMessage(fieldName) {
254
+ const error = this._errors && this._errors[fieldName];
255
+ return Array.isArray(error) ? error[0] : error || null;
256
+ }
257
+ static get styles() {
258
+ // language=CSS
259
+ return [
260
+ SharedStyles,
261
+ pageLayoutStyles,
262
+ elevationStyles,
263
+ CardStyles,
264
+ FlexLayoutClasses,
265
+ FormBuilderCardStyles,
266
+ css `
267
+ :host {
268
+ display: flex;
269
+ flex-direction: column;
270
+ }
271
+ .add-group {
272
+ align-self: flex-end;
273
+ margin-right: 23px;
274
+ margin-top: 20px;
275
+ box-shadow: 0 4px 5px 0 rgba(0, 0, 0, 0.14), 0 1px 10px 0 rgba(0, 0, 0, 0.12),
276
+ 0 2px 4px -1px rgba(0, 0, 0, 0.4);
277
+ }
278
+ .card-header {
279
+ display: flex;
280
+ align-items: center;
281
+ justify-content: space-between;
282
+ }
283
+ .card-header .remove-group {
284
+ display: flex;
285
+ align-items: center;
286
+ justify-content: flex-end;
287
+ padding: 0 10px 8px;
288
+ cursor: pointer;
289
+ width: min-content;
290
+ white-space: nowrap;
291
+ }
292
+ .card-header .title {
293
+ padding: 0 24px 8px;
294
+ font-size: 18px;
295
+ font-weight: bold;
296
+ }
297
+ .save-button {
298
+ margin-top: 8px;
299
+ color: var(--primary-background-color);
300
+ background-color: var(--primary-color);
301
+ }
302
+ .information-source {
303
+ padding: 0.5% 2% 0.5% 1%;
304
+ }
305
+
306
+ .additional-field {
307
+ padding-top: 15px;
308
+ padding-bottom: 20px;
309
+ background-color: var(--secondary-background-color);
310
+ }
311
+
312
+ .actions-container {
313
+ padding: 0 25px 5px 45px;
314
+ box-sizing: border-box;
315
+ }
316
+
317
+ .card-container.form-card {
318
+ padding: 12px 0 15px;
319
+ }
320
+
321
+ .attachments-warning {
322
+ color: red;
323
+ }
324
+ paper-icon-button[icon='close'] {
325
+ cursor: pointer;
326
+ color: var(--primary-text-color);
327
+ }
328
+ `
329
+ ];
330
+ }
331
+ };
332
+ __decorate([
333
+ property({ type: Object })
334
+ ], FormAbstractGroup.prototype, "groupStructure", void 0);
335
+ __decorate([
336
+ property({ type: Object })
337
+ ], FormAbstractGroup.prototype, "metadata", void 0);
338
+ __decorate([
339
+ property({ type: String })
340
+ ], FormAbstractGroup.prototype, "parentGroupName", void 0);
341
+ __decorate([
342
+ property({ type: Boolean, attribute: 'readonly' })
343
+ ], FormAbstractGroup.prototype, "readonly", void 0);
344
+ __decorate([
345
+ property()
346
+ ], FormAbstractGroup.prototype, "_errors", void 0);
347
+ __decorate([
348
+ property()
349
+ ], FormAbstractGroup.prototype, "_value", void 0);
350
+ FormAbstractGroup = __decorate([
351
+ customElement('form-abstract-group')
352
+ ], FormAbstractGroup);
353
+ export { FormAbstractGroup };