@unicef-polymer/etools-form-builder 2.1.0-rc.6 → 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,208 +1,208 @@
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
+ 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,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
+ }