@unicef-polymer/etools-form-builder 2.1.0 → 2.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 (87) hide show
  1. package/LICENSE +674 -674
  2. package/README.md +1 -1
  3. package/dist/assets/translations.d.ts +6 -0
  4. package/dist/assets/translations.js +67 -0
  5. package/dist/form-attachments-popup/form-attachments-popup.d.ts +86 -85
  6. package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
  7. package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
  8. package/dist/form-attachments-popup/form-attachments-popup.js +255 -248
  9. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +3 -3
  10. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +91 -89
  11. package/dist/form-attachments-popup/index.d.ts +2 -2
  12. package/dist/form-attachments-popup/index.js +2 -2
  13. package/dist/form-fields/abstract-field-base.class.d.ts +33 -28
  14. package/dist/form-fields/abstract-field-base.class.js +194 -176
  15. package/dist/form-fields/field-renderer-component.d.ts +20 -20
  16. package/dist/form-fields/field-renderer-component.js +249 -249
  17. package/dist/form-fields/index.d.ts +12 -12
  18. package/dist/form-fields/index.js +12 -12
  19. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -17
  20. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +209 -208
  21. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -20
  22. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +124 -123
  23. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
  24. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +67 -66
  25. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
  26. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -108
  27. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
  28. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -53
  29. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
  30. package/dist/form-fields/single-fields/attachment-field.js +98 -97
  31. package/dist/form-fields/single-fields/base-field.d.ts +11 -11
  32. package/dist/form-fields/single-fields/base-field.js +58 -57
  33. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
  34. package/dist/form-fields/single-fields/boolean-field.js +49 -49
  35. package/dist/form-fields/single-fields/number-field.d.ts +10 -10
  36. package/dist/form-fields/single-fields/number-field.js +67 -66
  37. package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
  38. package/dist/form-fields/single-fields/scale-field.js +108 -107
  39. package/dist/form-fields/single-fields/text-field.d.ts +8 -8
  40. package/dist/form-fields/single-fields/text-field.js +54 -54
  41. package/dist/form-groups/form-abstract-group.d.ts +65 -60
  42. package/dist/form-groups/form-abstract-group.js +375 -353
  43. package/dist/form-groups/form-card.d.ts +32 -32
  44. package/dist/form-groups/form-card.js +113 -108
  45. package/dist/form-groups/form-collapsed-card.d.ts +70 -70
  46. package/dist/form-groups/form-collapsed-card.js +254 -253
  47. package/dist/form-groups/index.d.ts +3 -3
  48. package/dist/form-groups/index.js +3 -3
  49. package/dist/index.d.ts +3 -3
  50. package/dist/index.js +3 -3
  51. package/dist/lib/additional-components/confirmation-dialog.d.ts +18 -16
  52. package/dist/lib/additional-components/confirmation-dialog.js +72 -65
  53. package/dist/lib/additional-components/etools-fb-card.d.ts +21 -16
  54. package/dist/lib/additional-components/etools-fb-card.js +238 -215
  55. package/dist/lib/styles/attachments.styles.d.ts +2 -2
  56. package/dist/lib/styles/attachments.styles.js +72 -72
  57. package/dist/lib/styles/card-styles.d.ts +2 -2
  58. package/dist/lib/styles/card-styles.js +154 -154
  59. package/dist/lib/styles/dialog.styles.d.ts +2 -2
  60. package/dist/lib/styles/dialog.styles.js +85 -85
  61. package/dist/lib/styles/elevation-styles.d.ts +9 -9
  62. package/dist/lib/styles/elevation-styles.js +43 -43
  63. package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
  64. package/dist/lib/styles/flex-layout-classes.js +319 -319
  65. package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
  66. package/dist/lib/styles/form-builder-card.styles.js +49 -49
  67. package/dist/lib/styles/input-styles.d.ts +2 -2
  68. package/dist/lib/styles/input-styles.js +138 -138
  69. package/dist/lib/styles/page-layout-styles.d.ts +2 -2
  70. package/dist/lib/styles/page-layout-styles.js +201 -201
  71. package/dist/lib/styles/shared-styles.d.ts +2 -2
  72. package/dist/lib/styles/shared-styles.js +70 -70
  73. package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
  74. package/dist/lib/types/form-builder.interfaces.js +0 -0
  75. package/dist/lib/types/form-builder.types.d.ts +59 -59
  76. package/dist/lib/types/form-builder.types.js +0 -0
  77. package/dist/lib/types/global.types.d.ts +4 -4
  78. package/dist/lib/types/global.types.js +0 -0
  79. package/dist/lib/utils/dialog.d.ts +10 -10
  80. package/dist/lib/utils/dialog.js +21 -21
  81. package/dist/lib/utils/fire-custom-event.d.ts +1 -1
  82. package/dist/lib/utils/fire-custom-event.js +7 -7
  83. package/dist/lib/utils/translate.d.ts +1 -0
  84. package/dist/lib/utils/translate.js +9 -0
  85. package/dist/lib/utils/validations.helper.d.ts +26 -26
  86. package/dist/lib/utils/validations.helper.js +42 -35
  87. package/package.json +56 -56
@@ -1,208 +1,209 @@
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 '@unicef-polymer/etools-upload/etools-upload';
8
- import { RepeatableBaseField } from './repeatable-base-field';
9
- import { AttachmentsHelper } from '../../form-attachments-popup';
10
- import { html, css, customElement } from 'lit-element';
11
- import { fireEvent } from '../../lib/utils/fire-custom-event';
12
- import { SharedStyles } from '../../lib/styles/shared-styles';
13
- import { AttachmentsStyles } from '../../lib/styles/attachments.styles';
14
- let RepeatableAttachmentField = class RepeatableAttachmentField extends RepeatableBaseField {
15
- constructor() {
16
- super(...arguments);
17
- this.computedPath = [];
18
- }
19
- get uploadUrl() {
20
- return AttachmentsHelper.uploadUrl;
21
- }
22
- get jwtLocalStorageKey() {
23
- return AttachmentsHelper.jwtLocalStorageKey;
24
- }
25
- render() {
26
- var _a;
27
- const values = this.getValues();
28
- return html `
29
- <div class="finding-container">
30
- <div class="question layout start"><slot>${this.questionTemplate()}</slot></div>
31
- <div class="question-control layout vertical center-justified start">
32
- ${values.map((value, index) => value
33
- ? html `
34
- <div class="layout horizontal file-container">
35
- <!-- File name component -->
36
- <div class="filename-container file-selector__filename">
37
- <iron-icon class="file-icon" icon="attachment"></iron-icon>
38
- <span class="filename" title="${value.filename}">${value.filename}</span>
39
- </div>
40
-
41
- <!-- Download Button -->
42
- <paper-button
43
- ?hidden="${!value.url}"
44
- class="download-button file-selector__download"
45
- @tap="${() => this.downloadFile(value)}"
46
- >
47
- <iron-icon icon="cloud-download" class="dw-icon"></iron-icon>
48
- Download
49
- </paper-button>
50
-
51
- <!-- Delete Button -->
52
- <paper-button
53
- class="delete-button file-selector__delete"
54
- ?hidden="${this.isReadonly}"
55
- @tap="${() => this.removeControl(index)}"
56
- >
57
- Delete
58
- </paper-button>
59
- </div>
60
- `
61
- : '')}
62
- <!-- Upload button -->
63
- <etools-upload-multi
64
- class="with-padding"
65
- activate-offline
66
- ?hidden="${this.isReadonly}"
67
- @upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
68
- .endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
69
- .jwtLocalStorageKey="${this.jwtLocalStorageKey}"
70
- >
71
- </etools-upload-multi>
72
- <div ?hidden="${!this.isReadonly || ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length)}">—</div>
73
- </div>
74
- </div>
75
- `;
76
- }
77
- controlTemplate() {
78
- return html ``;
79
- }
80
- customValidation() {
81
- return null;
82
- }
83
- attachmentsUploaded({ success, error }) {
84
- success === null || success === void 0 ? void 0 : success.forEach((file, index) => {
85
- var _a, _b;
86
- const newIndex = ((_b = Number((_a = this.editedValues) === null || _a === void 0 ? void 0 : _a.length)) !== null && _b !== void 0 ? _b : 0) + index;
87
- if (this.isUploadedAttachment(file)) {
88
- this.valueChanged({
89
- url: file.file_link,
90
- attachment: file.id,
91
- filename: file.filename,
92
- file_type: null
93
- }, newIndex);
94
- }
95
- else if (this.isOfflineSavedAttachment(file)) {
96
- this.valueChanged({
97
- attachment: file.id,
98
- filename: file.filename,
99
- composedPath: [],
100
- file_type: null
101
- }, newIndex);
102
- }
103
- else {
104
- console.warn('Missing fields in parsed attachment');
105
- }
106
- });
107
- if (error && error.length) {
108
- console.error(error);
109
- fireEvent(this, 'toast', { text: 'Can not upload attachments. Please try again later' });
110
- }
111
- }
112
- downloadFile(attachment) {
113
- if (!(attachment === null || attachment === void 0 ? void 0 : attachment.url)) {
114
- return;
115
- }
116
- const link = document.createElement('a');
117
- link.target = '_blank';
118
- link.href = attachment.url;
119
- link.click();
120
- window.URL.revokeObjectURL(attachment.url);
121
- }
122
- isUploadedAttachment(attachment) {
123
- return (attachment.hasOwnProperty('filename') &&
124
- attachment.hasOwnProperty('id') &&
125
- attachment.hasOwnProperty('file_link') &&
126
- !attachment.hasOwnProperty('unsynced'));
127
- }
128
- isOfflineSavedAttachment(attachment) {
129
- return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
130
- }
131
- static get styles() {
132
- // language=CSS
133
- return [
134
- ...RepeatableBaseField.styles,
135
- SharedStyles,
136
- AttachmentsStyles,
137
- css `
138
- .file-selector__type-dropdown {
139
- flex-basis: 25%;
140
- padding-left: 8px;
141
- padding-right: 8px;
142
- }
143
-
144
- .file-selector__filename {
145
- flex-basis: 35%;
146
- }
147
-
148
- .file-selector__download {
149
- flex-basis: 10%;
150
- }
151
-
152
- .file-selector__delete {
153
- flex-basis: 10%;
154
- }
155
-
156
- .file-selector-container.with-type-dropdown {
157
- flex-wrap: nowrap;
158
- }
159
-
160
- .popup-container {
161
- padding: 12px 12px 0;
162
- }
163
-
164
- .file-container {
165
- padding: 8px 0;
166
- }
167
-
168
- @media (max-width: 380px) {
169
- .file-selector-container.with-type-dropdown {
170
- justify-content: center;
171
- }
172
-
173
- .file-selector-container.with-type-dropdown etools-dropdown.type-dropdown {
174
- flex-basis: 90%;
175
- }
176
-
177
- .file-selector__filename {
178
- flex-basis: 90%;
179
- }
180
-
181
- .file-selector__download {
182
- flex-basis: 5%;
183
- }
184
-
185
- .file-selector__delete {
186
- flex-basis: 5%;
187
- }
188
- }
189
-
190
- @media (max-width: 600px) {
191
- etools-dropdown {
192
- padding: 0;
193
- }
194
-
195
- .file-selector-container.with-type-dropdown {
196
- border-bottom: 1px solid lightgrey;
197
- flex-wrap: wrap;
198
- padding-bottom: 10px;
199
- }
200
- }
201
- `
202
- ];
203
- }
204
- };
205
- RepeatableAttachmentField = __decorate([
206
- customElement('repeatable-attachments-field')
207
- ], RepeatableAttachmentField);
208
- export { RepeatableAttachmentField };
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 '@unicef-polymer/etools-upload/etools-upload';
8
+ import { RepeatableBaseField } from './repeatable-base-field';
9
+ import { AttachmentsHelper } from '../../form-attachments-popup';
10
+ import { html, css, customElement } from 'lit-element';
11
+ import { fireEvent } from '../../lib/utils/fire-custom-event';
12
+ import { SharedStyles } from '../../lib/styles/shared-styles';
13
+ import { AttachmentsStyles } from '../../lib/styles/attachments.styles';
14
+ import { getTranslation } from '../../lib/utils/translate';
15
+ let RepeatableAttachmentField = class RepeatableAttachmentField extends RepeatableBaseField {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.computedPath = [];
19
+ }
20
+ get uploadUrl() {
21
+ return AttachmentsHelper.uploadUrl;
22
+ }
23
+ get jwtLocalStorageKey() {
24
+ return AttachmentsHelper.jwtLocalStorageKey;
25
+ }
26
+ render() {
27
+ var _a;
28
+ const values = this.getValues();
29
+ return html `
30
+ <div class="finding-container">
31
+ <div class="question layout start"><slot>${this.questionTemplate()}</slot></div>
32
+ <div class="question-control layout vertical center-justified start">
33
+ ${values.map((value, index) => value
34
+ ? html `
35
+ <div class="layout horizontal file-container">
36
+ <!-- File name component -->
37
+ <div class="filename-container file-selector__filename">
38
+ <iron-icon class="file-icon" icon="attachment"></iron-icon>
39
+ <span class="filename" title="${value.filename}">${value.filename}</span>
40
+ </div>
41
+
42
+ <!-- Download Button -->
43
+ <paper-button
44
+ ?hidden="${!value.url}"
45
+ class="download-button file-selector__download"
46
+ @tap="${() => this.downloadFile(value)}"
47
+ >
48
+ <iron-icon icon="cloud-download" class="dw-icon"></iron-icon>
49
+ ${getTranslation(this.language, 'DOWNLOAD')}
50
+ </paper-button>
51
+
52
+ <!-- Delete Button -->
53
+ <paper-button
54
+ class="delete-button file-selector__delete"
55
+ ?hidden="${this.isReadonly}"
56
+ @tap="${() => this.removeControl(index)}"
57
+ >
58
+ ${getTranslation(this.language, 'DELETE')}
59
+ </paper-button>
60
+ </div>
61
+ `
62
+ : '')}
63
+ <!-- Upload button -->
64
+ <etools-upload-multi
65
+ class="with-padding"
66
+ activate-offline
67
+ ?hidden="${this.isReadonly}"
68
+ @upload-finished="${({ detail }) => this.attachmentsUploaded(detail)}"
69
+ .endpointInfo="${{ endpoint: this.uploadUrl, extraInfo: { composedPath: this.computedPath } }}"
70
+ .jwtLocalStorageKey="${this.jwtLocalStorageKey}"
71
+ >
72
+ </etools-upload-multi>
73
+ <div ?hidden="${!this.isReadonly || ((_a = this.value) === null || _a === void 0 ? void 0 : _a.length)}">—</div>
74
+ </div>
75
+ </div>
76
+ `;
77
+ }
78
+ controlTemplate() {
79
+ return html ``;
80
+ }
81
+ customValidation() {
82
+ return null;
83
+ }
84
+ attachmentsUploaded({ success, error }) {
85
+ success === null || success === void 0 ? void 0 : success.forEach((file, index) => {
86
+ var _a, _b;
87
+ const newIndex = ((_b = Number((_a = this.editedValues) === null || _a === void 0 ? void 0 : _a.length)) !== null && _b !== void 0 ? _b : 0) + index;
88
+ if (this.isUploadedAttachment(file)) {
89
+ this.valueChanged({
90
+ url: file.file_link,
91
+ attachment: file.id,
92
+ filename: file.filename,
93
+ file_type: null
94
+ }, newIndex);
95
+ }
96
+ else if (this.isOfflineSavedAttachment(file)) {
97
+ this.valueChanged({
98
+ attachment: file.id,
99
+ filename: file.filename,
100
+ composedPath: [],
101
+ file_type: null
102
+ }, newIndex);
103
+ }
104
+ else {
105
+ console.warn('Missing fields in parsed attachment');
106
+ }
107
+ });
108
+ if (error && error.length) {
109
+ console.error(error);
110
+ fireEvent(this, 'toast', { text: 'Can not upload attachments. Please try again later' });
111
+ }
112
+ }
113
+ downloadFile(attachment) {
114
+ if (!(attachment === null || attachment === void 0 ? void 0 : attachment.url)) {
115
+ return;
116
+ }
117
+ const link = document.createElement('a');
118
+ link.target = '_blank';
119
+ link.href = attachment.url;
120
+ link.click();
121
+ window.URL.revokeObjectURL(attachment.url);
122
+ }
123
+ isUploadedAttachment(attachment) {
124
+ return (attachment.hasOwnProperty('filename') &&
125
+ attachment.hasOwnProperty('id') &&
126
+ attachment.hasOwnProperty('file_link') &&
127
+ !attachment.hasOwnProperty('unsynced'));
128
+ }
129
+ isOfflineSavedAttachment(attachment) {
130
+ return (attachment.hasOwnProperty('filename') && attachment.hasOwnProperty('id') && attachment.hasOwnProperty('unsynced'));
131
+ }
132
+ static get styles() {
133
+ // language=CSS
134
+ return [
135
+ ...RepeatableBaseField.styles,
136
+ SharedStyles,
137
+ AttachmentsStyles,
138
+ css `
139
+ .file-selector__type-dropdown {
140
+ flex-basis: 25%;
141
+ padding-left: 8px;
142
+ padding-right: 8px;
143
+ }
144
+
145
+ .file-selector__filename {
146
+ flex-basis: 35%;
147
+ }
148
+
149
+ .file-selector__download {
150
+ flex-basis: 10%;
151
+ }
152
+
153
+ .file-selector__delete {
154
+ flex-basis: 10%;
155
+ }
156
+
157
+ .file-selector-container.with-type-dropdown {
158
+ flex-wrap: nowrap;
159
+ }
160
+
161
+ .popup-container {
162
+ padding: 12px 12px 0;
163
+ }
164
+
165
+ .file-container {
166
+ padding: 8px 0;
167
+ }
168
+
169
+ @media (max-width: 380px) {
170
+ .file-selector-container.with-type-dropdown {
171
+ justify-content: center;
172
+ }
173
+
174
+ .file-selector-container.with-type-dropdown etools-dropdown.type-dropdown {
175
+ flex-basis: 90%;
176
+ }
177
+
178
+ .file-selector__filename {
179
+ flex-basis: 90%;
180
+ }
181
+
182
+ .file-selector__download {
183
+ flex-basis: 5%;
184
+ }
185
+
186
+ .file-selector__delete {
187
+ flex-basis: 5%;
188
+ }
189
+ }
190
+
191
+ @media (max-width: 600px) {
192
+ etools-dropdown {
193
+ padding: 0;
194
+ }
195
+
196
+ .file-selector-container.with-type-dropdown {
197
+ border-bottom: 1px solid lightgrey;
198
+ flex-wrap: wrap;
199
+ padding-bottom: 10px;
200
+ }
201
+ }
202
+ `
203
+ ];
204
+ }
205
+ };
206
+ RepeatableAttachmentField = __decorate([
207
+ customElement('repeatable-attachments-field')
208
+ ], RepeatableAttachmentField);
209
+ export { RepeatableAttachmentField };
@@ -1,20 +1,20 @@
1
- import { CSSResultArray, TemplateResult } from 'lit-element';
2
- import { AbstractFieldBaseClass } from '../abstract-field-base.class';
3
- export declare abstract class RepeatableBaseField<T> extends AbstractFieldBaseClass<T[]> {
4
- set errorMessage(messages: (string | null)[]);
5
- get errorMessage(): (string | null)[];
6
- protected _errorMessage: (string | null)[];
7
- protected editedValues: (T | null)[] | null;
8
- protected render(): TemplateResult;
9
- protected questionTemplate(): TemplateResult;
10
- protected valueChanged(newValue: T, index: number): void;
11
- protected setValue(value: (T | null)[]): void;
12
- protected validateField(value: T[]): void;
13
- protected validateField(value: T, index: number): void;
14
- protected addNewField(): void;
15
- protected removeControl(index: number): void;
16
- protected getValues(): (T | null)[];
17
- private isArrayData;
18
- protected abstract controlTemplate(value: T | null, index: number): TemplateResult;
19
- static get styles(): CSSResultArray;
20
- }
1
+ import { CSSResultArray, TemplateResult } from 'lit-element';
2
+ import { AbstractFieldBaseClass } from '../abstract-field-base.class';
3
+ export declare abstract class RepeatableBaseField<T> extends AbstractFieldBaseClass<T[]> {
4
+ set errorMessage(messages: (string | null)[]);
5
+ get errorMessage(): (string | null)[];
6
+ protected _errorMessage: (string | null)[];
7
+ protected editedValues: (T | null)[] | null;
8
+ protected render(): TemplateResult;
9
+ protected questionTemplate(): TemplateResult;
10
+ protected valueChanged(newValue: T, index: number): void;
11
+ protected setValue(value: (T | null)[]): void;
12
+ protected validateField(value: T[]): void;
13
+ protected validateField(value: T, index: number): void;
14
+ protected addNewField(): void;
15
+ protected removeControl(index: number): void;
16
+ protected getValues(): (T | null)[];
17
+ private isArrayData;
18
+ protected abstract controlTemplate(value: T | null, index: number): TemplateResult;
19
+ static get styles(): CSSResultArray;
20
+ }