@unicef-polymer/etools-form-builder 3.1.1 → 3.1.2

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 (29) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +1 -1
  3. package/dist/form-attachments-popup/form-attachments-popup.js +135 -135
  4. package/dist/form-fields/abstract-field-base.class.js +101 -101
  5. package/dist/form-fields/field-renderer-component.js +164 -164
  6. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +111 -111
  7. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +22 -22
  8. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +19 -19
  9. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +57 -57
  10. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +19 -19
  11. package/dist/form-fields/single-fields/attachment-field.js +13 -13
  12. package/dist/form-fields/single-fields/boolean-field.js +16 -16
  13. package/dist/form-fields/single-fields/number-field.js +20 -20
  14. package/dist/form-fields/single-fields/scale-field.js +58 -58
  15. package/dist/form-fields/single-fields/text-field.js +24 -24
  16. package/dist/form-groups/form-abstract-group.js +129 -129
  17. package/dist/form-groups/form-card.js +30 -30
  18. package/dist/form-groups/form-collapsed-card.js +34 -34
  19. package/dist/lib/additional-components/confirmation-dialog.js +20 -20
  20. package/dist/lib/additional-components/etools-fb-card.js +144 -144
  21. package/dist/lib/styles/attachments.styles.js +61 -61
  22. package/dist/lib/styles/card-styles.js +147 -147
  23. package/dist/lib/styles/dialog.styles.js +83 -83
  24. package/dist/lib/styles/elevation-styles.js +46 -46
  25. package/dist/lib/styles/flex-layout-classes.js +316 -316
  26. package/dist/lib/styles/form-builder-card.styles.js +53 -53
  27. package/dist/lib/styles/page-layout-styles.js +198 -198
  28. package/dist/lib/styles/shared-styles.js +61 -61
  29. package/package.json +51 -52
@@ -111,8 +111,8 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
111
111
  if (!this.groupStructure || !this.metadata) {
112
112
  return html ``;
113
113
  }
114
- return html `
115
- ${this.groupStructure.children.map((child) => this.renderChild(child))}
114
+ return html `
115
+ ${this.groupStructure.children.map((child) => this.renderChild(child))}
116
116
  `;
117
117
  }
118
118
  renderChild(child) {
@@ -131,19 +131,19 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
131
131
  }
132
132
  renderField(blueprintField) {
133
133
  var _a;
134
- return html `
135
- <field-renderer
136
- .field="${blueprintField}"
137
- .language="${this.language}"
138
- ?readonly="${live(this.isReadonly())}"
139
- .value="${this.value && this.value[blueprintField.name]}"
140
- .validations="${blueprintField.validations.map((validation) => this.metadata.validations[validation])}"
141
- .errorMessage="${this.getErrorMessage(blueprintField.name)}"
142
- .options="${((_a = this.metadata.options[blueprintField.options_key || '']) === null || _a === void 0 ? void 0 : _a.values) || []}"
143
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [blueprintField.name] : [this.groupStructure.name, blueprintField.name])}"
144
- @value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
145
- @error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
146
- ></field-renderer>
134
+ return html `
135
+ <field-renderer
136
+ .field="${blueprintField}"
137
+ .language="${this.language}"
138
+ ?readonly="${live(this.isReadonly())}"
139
+ .value="${this.value && this.value[blueprintField.name]}"
140
+ .validations="${blueprintField.validations.map((validation) => this.metadata.validations[validation])}"
141
+ .errorMessage="${this.getErrorMessage(blueprintField.name)}"
142
+ .options="${((_a = this.metadata.options[blueprintField.options_key || '']) === null || _a === void 0 ? void 0 : _a.values) || []}"
143
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [blueprintField.name] : [this.groupStructure.name, blueprintField.name])}"
144
+ @value-changed="${(event) => this.valueChanged(event, blueprintField.name)}"
145
+ @error-changed="${(event) => this.errorChanged(event, blueprintField.name)}"
146
+ ></field-renderer>
147
147
  `;
148
148
  }
149
149
  renderInformation(information) {
@@ -154,18 +154,18 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
154
154
  return this.getGroupTemplate(groupStructure);
155
155
  }
156
156
  const value = (this.value && this.value[groupStructure.name]) || [{}];
157
- return html `
158
- ${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
159
- <etools-button
160
- variant="primary"
161
- class="add-group save-button"
162
- @click="${() => this.addGroup(groupStructure.name)}"
163
- >
164
- ${getTranslation(this.language, 'ADD')}
157
+ return html `
158
+ ${value.map((_, index) => this.getGroupTemplate(groupStructure, index))}
159
+ <etools-button
160
+ variant="primary"
161
+ class="add-group save-button"
162
+ @click="${() => this.addGroup(groupStructure.name)}"
163
+ >
164
+ ${getTranslation(this.language, 'ADD')}
165
165
  ${!groupStructure.title || groupStructure.title.length > 15
166
166
  ? getTranslation(this.language, 'GROUP')
167
- : groupStructure.title}
168
- </etools-button>
167
+ : groupStructure.title}
168
+ </etools-button>
169
169
  `;
170
170
  }
171
171
  getGroupTemplate(groupStructure, index) {
@@ -181,52 +181,52 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
181
181
  errors = errors && errors[index];
182
182
  }
183
183
  if (isAbstract) {
184
- return html `
185
- <form-abstract-group
186
- .groupStructure="${groupStructure}"
187
- .value="${value}"
188
- .metadata="${this.metadata}"
189
- .parentGroupName="${this.groupStructure.name}"
190
- .collapsed="${this.collapsed}"
191
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
192
- .readonly="${this.isReadonly()}"
193
- .errors="${errors || null}"
194
- @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
195
- @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
196
- ></form-abstract-group>
184
+ return html `
185
+ <form-abstract-group
186
+ .groupStructure="${groupStructure}"
187
+ .value="${value}"
188
+ .metadata="${this.metadata}"
189
+ .parentGroupName="${this.groupStructure.name}"
190
+ .collapsed="${this.collapsed}"
191
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
192
+ .readonly="${this.isReadonly()}"
193
+ .errors="${errors || null}"
194
+ @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
195
+ @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
196
+ ></form-abstract-group>
197
197
  `;
198
198
  }
199
199
  else if (isCard && isCollapsed) {
200
- return html `
201
- <form-collapsed-card
202
- .groupStructure="${groupStructure}"
203
- .value="${value}"
204
- .metadata="${this.metadata}"
205
- .parentGroupName="${this.groupStructure.name}"
206
- .collapsed="${this.collapsed}"
207
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
208
- .readonly="${this.isReadonly()}"
209
- .errors="${errors || null}"
210
- @remove-group="${() => this.removeGroup(groupStructure, index)}"
211
- @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
212
- @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
213
- ></form-collapsed-card>
200
+ return html `
201
+ <form-collapsed-card
202
+ .groupStructure="${groupStructure}"
203
+ .value="${value}"
204
+ .metadata="${this.metadata}"
205
+ .parentGroupName="${this.groupStructure.name}"
206
+ .collapsed="${this.collapsed}"
207
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
208
+ .readonly="${this.isReadonly()}"
209
+ .errors="${errors || null}"
210
+ @remove-group="${() => this.removeGroup(groupStructure, index)}"
211
+ @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
212
+ @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
213
+ ></form-collapsed-card>
214
214
  `;
215
215
  }
216
216
  else if (isCard) {
217
- return html `
218
- <form-card
219
- .groupStructure="${groupStructure}"
220
- .value="${value}"
221
- .metadata="${this.metadata}"
222
- .parentGroupName="${this.groupStructure.name}"
223
- .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
224
- .readonly="${this.isReadonly()}"
225
- .errors="${errors || null}"
226
- @remove-group="${() => this.removeGroup(groupStructure, index)}"
227
- @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
228
- @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
229
- ></form-card>
217
+ return html `
218
+ <form-card
219
+ .groupStructure="${groupStructure}"
220
+ .value="${value}"
221
+ .metadata="${this.metadata}"
222
+ .parentGroupName="${this.groupStructure.name}"
223
+ .computedPath="${this.computedPath.concat(this.groupStructure.name === 'root' ? [] : [this.groupStructure.name])}"
224
+ .readonly="${this.isReadonly()}"
225
+ .errors="${errors || null}"
226
+ @remove-group="${() => this.removeGroup(groupStructure, index)}"
227
+ @value-changed="${(event) => this.valueChanged(event, groupStructure.name, index)}"
228
+ @error-changed="${(event) => this.errorChanged(event, groupStructure.name, index)}"
229
+ ></form-card>
230
230
  `;
231
231
  }
232
232
  else {
@@ -307,70 +307,70 @@ let FormAbstractGroup = class FormAbstractGroup extends LitElement {
307
307
  CardStyles,
308
308
  FlexLayoutClasses,
309
309
  FormBuilderCardStyles,
310
- css `
311
- :host {
312
- display: flex;
313
- flex-direction: column;
314
- }
315
- .add-group {
316
- align-self: flex-end;
317
- margin-right: 23px;
318
- margin-top: 20px;
319
- box-shadow:
320
- 0 4px 5px 0 rgba(0, 0, 0, 0.14),
321
- 0 1px 10px 0 rgba(0, 0, 0, 0.12),
322
- 0 2px 4px -1px rgba(0, 0, 0, 0.4);
323
- }
324
- .card-header {
325
- display: flex;
326
- align-items: center;
327
- justify-content: space-between;
328
- }
329
- .card-header .remove-group {
330
- display: flex;
331
- align-items: center;
332
- justify-content: flex-end;
333
- padding: 0 10px 8px;
334
- cursor: pointer;
335
- width: min-content;
336
- white-space: nowrap;
337
- }
338
- .card-header .title {
339
- padding: 0 24px 8px;
340
- font-size: var(--etools-font-size-18, 18px);
341
- font-weight: bold;
342
- }
343
- .save-button {
344
- margin-top: 8px;
345
- color: var(--primary-background-color);
346
- background-color: var(--primary-color);
347
- }
348
- .information-source {
349
- padding: 0.5% 2% 0.5% 1%;
350
- }
351
-
352
- .additional-field {
353
- padding-top: 15px;
354
- padding-bottom: 20px;
355
- background-color: var(--secondary-background-color);
356
- }
357
-
358
- .actions-container {
359
- padding: 0 25px 5px 45px;
360
- box-sizing: border-box;
361
- }
362
-
363
- .card-container.form-card {
364
- padding: 12px 0 15px;
365
- }
366
-
367
- .attachments-warning {
368
- color: red;
369
- }
370
- etools-icon-button[name='close'] {
371
- cursor: pointer;
372
- color: var(--primary-text-color);
373
- }
310
+ css `
311
+ :host {
312
+ display: flex;
313
+ flex-direction: column;
314
+ }
315
+ .add-group {
316
+ align-self: flex-end;
317
+ margin-right: 23px;
318
+ margin-top: 20px;
319
+ box-shadow:
320
+ 0 4px 5px 0 rgba(0, 0, 0, 0.14),
321
+ 0 1px 10px 0 rgba(0, 0, 0, 0.12),
322
+ 0 2px 4px -1px rgba(0, 0, 0, 0.4);
323
+ }
324
+ .card-header {
325
+ display: flex;
326
+ align-items: center;
327
+ justify-content: space-between;
328
+ }
329
+ .card-header .remove-group {
330
+ display: flex;
331
+ align-items: center;
332
+ justify-content: flex-end;
333
+ padding: 0 10px 8px;
334
+ cursor: pointer;
335
+ width: min-content;
336
+ white-space: nowrap;
337
+ }
338
+ .card-header .title {
339
+ padding: 0 24px 8px;
340
+ font-size: var(--etools-font-size-18, 18px);
341
+ font-weight: bold;
342
+ }
343
+ .save-button {
344
+ margin-top: 8px;
345
+ color: var(--primary-background-color);
346
+ background-color: var(--primary-color);
347
+ }
348
+ .information-source {
349
+ padding: 0.5% 2% 0.5% 1%;
350
+ }
351
+
352
+ .additional-field {
353
+ padding-top: 15px;
354
+ padding-bottom: 20px;
355
+ background-color: var(--secondary-background-color);
356
+ }
357
+
358
+ .actions-container {
359
+ padding: 0 25px 5px 45px;
360
+ box-sizing: border-box;
361
+ }
362
+
363
+ .card-container.form-card {
364
+ padding: 12px 0 15px;
365
+ }
366
+
367
+ .attachments-warning {
368
+ color: red;
369
+ }
370
+ etools-icon-button[name='close'] {
371
+ cursor: pointer;
372
+ color: var(--primary-text-color);
373
+ }
374
374
  `
375
375
  ];
376
376
  }
@@ -47,38 +47,38 @@ let FormCard = class FormCard extends FormAbstractGroup {
47
47
  return [SharedStyles, pageLayoutStyles, elevationStyles, CardStyles, FlexLayoutClasses, FormBuilderCardStyles];
48
48
  }
49
49
  render() {
50
- return html `
51
- <style>
52
- .card-buttons {
53
- padding: 12px 24px;
54
- padding-top: 0;
55
- }
56
- </style>
57
- <section class="elevation page-content card-container form-card" elevation="1">
58
- <div class="card-header">
59
- <div class="title">${this.groupStructure.title}</div>
60
- <div
61
- class="remove-group"
62
- ?hidden="${!this.groupStructure.repeatable}"
63
- @click="${() => this.confirmRemove(this.groupStructure.title || getTranslation(this.language, 'THIS_GROUP'))}"
64
- >
65
- Remove
50
+ return html `
51
+ <style>
52
+ .card-buttons {
53
+ padding: 12px 24px;
54
+ padding-top: 0;
55
+ }
56
+ </style>
57
+ <section class="elevation page-content card-container form-card" elevation="1">
58
+ <div class="card-header">
59
+ <div class="title">${this.groupStructure.title}</div>
60
+ <div
61
+ class="remove-group"
62
+ ?hidden="${!this.groupStructure.repeatable}"
63
+ @click="${() => this.confirmRemove(this.groupStructure.title || getTranslation(this.language, 'THIS_GROUP'))}"
64
+ >
65
+ Remove
66
66
  ${!this.groupStructure.title || this.groupStructure.title.length > 15
67
67
  ? getTranslation(this.language, 'GROUP')
68
- : this.groupStructure.title}
69
- <etools-icon-button class="attachments-warning" name="delete"></etools-icon-button>
70
- </div>
71
- </div>
72
- ${super.render()}
73
-
74
- <etools-collapse ?opened="${this.showSaveButton}">
75
- <div class="layout horizontal end-justified card-buttons actions-container">
76
- <etools-button variant="primary" @click="${this.saveChanges}">
77
- ${getTranslation(this.language, 'SAVE')}
78
- </etools-button>
79
- </div>
80
- </etools-collapse>
81
- </section>
68
+ : this.groupStructure.title}
69
+ <etools-icon-button class="attachments-warning" name="delete"></etools-icon-button>
70
+ </div>
71
+ </div>
72
+ ${super.render()}
73
+
74
+ <etools-collapse ?opened="${this.showSaveButton}">
75
+ <div class="layout horizontal end-justified card-buttons actions-container">
76
+ <etools-button variant="primary" @click="${this.saveChanges}">
77
+ ${getTranslation(this.language, 'SAVE')}
78
+ </etools-button>
79
+ </div>
80
+ </etools-collapse>
81
+ </section>
82
82
  `;
83
83
  }
84
84
  /**
@@ -73,31 +73,31 @@ let FormCollapsedCard = class FormCollapsedCard extends FormAbstractGroup {
73
73
  * and adds etools-card as container wrapper
74
74
  */
75
75
  render() {
76
- return html `
77
- <section class="elevation page-content card-container" elevation="1">
78
- <etools-fb-card
79
- card-title="${this.retrieveTitle(this.parentGroupName) + this.groupStructure.title}"
80
- is-collapsible
81
- ?is-editable="${!this.readonly}"
82
- ?edit="${this.isEditMode}"
83
- .collapsed="${this.collapsed}"
84
- @start-edit="${() => this.startEdit()}"
85
- @save="${() => this.saveChanges()}"
86
- @cancel="${() => this.cancelEdit()}"
87
- >
88
- <!-- Open Attachments popup button -->
89
- <div slot="actions" class="layout horizontal center">${this.getAdditionalButtons()}</div>
90
- <div slot="postfix" class="layout horizontal center" ?hidden="${!this.groupStructure.repeatable}">
91
- <etools-icon-button
92
- class="attachments-warning"
93
- name="close"
94
- @click="${() => this.confirmRemove(this.groupStructure.title || getTranslation(this.language, 'THIS_GROUP'))}"
95
- >
96
- </etools-icon-button>
97
- </div>
98
- <div slot="content">${this.renderGroupChildren()}</div>
99
- </etools-fb-card>
100
- </section>
76
+ return html `
77
+ <section class="elevation page-content card-container" elevation="1">
78
+ <etools-fb-card
79
+ card-title="${this.retrieveTitle(this.parentGroupName) + this.groupStructure.title}"
80
+ is-collapsible
81
+ ?is-editable="${!this.readonly}"
82
+ ?edit="${this.isEditMode}"
83
+ .collapsed="${this.collapsed}"
84
+ @start-edit="${() => this.startEdit()}"
85
+ @save="${() => this.saveChanges()}"
86
+ @cancel="${() => this.cancelEdit()}"
87
+ >
88
+ <!-- Open Attachments popup button -->
89
+ <div slot="actions" class="layout horizontal center">${this.getAdditionalButtons()}</div>
90
+ <div slot="postfix" class="layout horizontal center" ?hidden="${!this.groupStructure.repeatable}">
91
+ <etools-icon-button
92
+ class="attachments-warning"
93
+ name="close"
94
+ @click="${() => this.confirmRemove(this.groupStructure.title || getTranslation(this.language, 'THIS_GROUP'))}"
95
+ >
96
+ </etools-icon-button>
97
+ </div>
98
+ <div slot="content">${this.renderGroupChildren()}</div>
99
+ </etools-fb-card>
100
+ </section>
101
101
  `;
102
102
  }
103
103
  /**
@@ -119,15 +119,15 @@ let FormCollapsedCard = class FormCollapsedCard extends FormAbstractGroup {
119
119
  !this.groupStructure.children.some(({ styling }) => styling.includes(StructureTypes.ATTACHMENTS_BUTTON));
120
120
  return hideAttachmentsButton
121
121
  ? html ``
122
- : html `
123
- <etools-icon id="attachments-warning" name="warning" ?hidden="${!this._errors.attachments}"></etools-icon>
124
- <etools-button id="primary" variant="text" class="primary" @click="${this.openAttachmentsPopup}">
125
- <etools-icon
126
- slot="prefix"
127
- name="${((_d = (_c = this.value) === null || _c === void 0 ? void 0 : _c.attachments) === null || _d === void 0 ? void 0 : _d.length) ? 'file-download' : 'file-upload'}"
128
- ></etools-icon>
129
- ${this.getAttachmentsBtnText((_f = (_e = this.value) === null || _e === void 0 ? void 0 : _e.attachments) === null || _f === void 0 ? void 0 : _f.length)}
130
- </etools-button>
122
+ : html `
123
+ <etools-icon id="attachments-warning" name="warning" ?hidden="${!this._errors.attachments}"></etools-icon>
124
+ <etools-button id="primary" variant="text" class="primary" @click="${this.openAttachmentsPopup}">
125
+ <etools-icon
126
+ slot="prefix"
127
+ name="${((_d = (_c = this.value) === null || _c === void 0 ? void 0 : _c.attachments) === null || _d === void 0 ? void 0 : _d.length) ? 'file-download' : 'file-upload'}"
128
+ ></etools-icon>
129
+ ${this.getAttachmentsBtnText((_f = (_e = this.value) === null || _e === void 0 ? void 0 : _e.attachments) === null || _f === void 0 ? void 0 : _f.length)}
130
+ </etools-button>
131
131
  `;
132
132
  }
133
133
  retrieveTitle(target) {
@@ -21,22 +21,22 @@ let ConfirmationDialog = class ConfirmationDialog extends LitElement {
21
21
  }
22
22
  }
23
23
  render() {
24
- return html `
25
- <etools-dialog
26
- id="confirmation-dialog"
27
- size="md"
28
- no-padding
29
- keep-dialog-open
30
- ?hide-confirm-btn="${this.hideConfirmBtn}"
31
- cancel-btn-text="${getTranslation(this.language, this.hideConfirmBtn ? 'OK' : 'CANCEL')}"
32
- ?opened="${this.dialogOpened}"
33
- theme="confirmation"
34
- dialog-title="${this.dialogTitle}"
35
- @close="${this.onClose}"
36
- @confirm-btn-clicked="${() => this.confirm()}"
37
- >
38
- <div class="confirmation-message">${this.text}</div>
39
- </etools-dialog>
24
+ return html `
25
+ <etools-dialog
26
+ id="confirmation-dialog"
27
+ size="md"
28
+ no-padding
29
+ keep-dialog-open
30
+ ?hide-confirm-btn="${this.hideConfirmBtn}"
31
+ cancel-btn-text="${getTranslation(this.language, this.hideConfirmBtn ? 'OK' : 'CANCEL')}"
32
+ ?opened="${this.dialogOpened}"
33
+ theme="confirmation"
34
+ dialog-title="${this.dialogTitle}"
35
+ @close="${this.onClose}"
36
+ @confirm-btn-clicked="${() => this.confirm()}"
37
+ >
38
+ <div class="confirmation-message">${this.text}</div>
39
+ </etools-dialog>
40
40
  `;
41
41
  }
42
42
  onClose() {
@@ -48,10 +48,10 @@ let ConfirmationDialog = class ConfirmationDialog extends LitElement {
48
48
  static get styles() {
49
49
  // language=CSS
50
50
  return [
51
- css `
52
- .confirmation-message {
53
- padding-left: 24px;
54
- }
51
+ css `
52
+ .confirmation-message {
53
+ padding-left: 24px;
54
+ }
55
55
  `
56
56
  ];
57
57
  }