@unicef-polymer/etools-form-builder 1.0.3 → 2.0.0-rc.5

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 (59) hide show
  1. package/dist/form-attachments-popup/form-attachments-popup.d.ts +10 -2
  2. package/dist/form-attachments-popup/form-attachments-popup.js +12 -3
  3. package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +0 -5
  4. package/dist/form-attachments-popup/form-attachments-popup.tpl.js +0 -5
  5. package/dist/form-fields/abstract-field-base.class.d.ts +28 -0
  6. package/dist/form-fields/{base-field.js → abstract-field-base.class.js} +64 -38
  7. package/dist/form-fields/field-renderer-component.d.ts +20 -0
  8. package/dist/form-fields/field-renderer-component.js +249 -0
  9. package/dist/form-fields/index.d.ts +11 -5
  10. package/dist/form-fields/index.js +11 -5
  11. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -0
  12. package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +208 -0
  13. package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -0
  14. package/dist/form-fields/repeatable-fields/repeatable-base-field.js +123 -0
  15. package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -0
  16. package/dist/form-fields/repeatable-fields/repeatable-number-field.js +66 -0
  17. package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -0
  18. package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -0
  19. package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -0
  20. package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -0
  21. package/dist/form-fields/single-fields/attachment-field.d.ts +16 -0
  22. package/dist/form-fields/single-fields/attachment-field.js +97 -0
  23. package/dist/form-fields/single-fields/base-field.d.ts +11 -0
  24. package/dist/form-fields/single-fields/base-field.js +57 -0
  25. package/dist/form-fields/single-fields/boolean-field.d.ts +8 -0
  26. package/dist/form-fields/single-fields/boolean-field.js +49 -0
  27. package/dist/form-fields/{number-field.d.ts → single-fields/number-field.d.ts} +1 -0
  28. package/dist/form-fields/single-fields/number-field.js +66 -0
  29. package/dist/form-fields/{scale-field.d.ts → single-fields/scale-field.d.ts} +4 -2
  30. package/dist/form-fields/{scale-field.js → single-fields/scale-field.js} +21 -5
  31. package/dist/form-fields/{text-field.d.ts → single-fields/text-field.d.ts} +0 -0
  32. package/dist/form-fields/{wide-field.js → single-fields/text-field.js} +29 -26
  33. package/dist/form-groups/form-abstract-group.d.ts +12 -12
  34. package/dist/form-groups/form-abstract-group.js +141 -114
  35. package/dist/form-groups/form-card.d.ts +1 -0
  36. package/dist/form-groups/form-card.js +32 -3
  37. package/dist/form-groups/form-collapsed-card.d.ts +3 -1
  38. package/dist/form-groups/form-collapsed-card.js +31 -7
  39. package/dist/index.d.ts +3 -14
  40. package/dist/index.js +3 -19
  41. package/dist/lib/additional-components/confirmation-dialog.d.ts +16 -0
  42. package/dist/lib/additional-components/confirmation-dialog.js +65 -0
  43. package/dist/lib/additional-components/etools-fb-card.js +7 -0
  44. package/dist/lib/styles/attachments.styles.js +5 -2
  45. package/dist/lib/styles/form-builder-card.styles.js +8 -3
  46. package/dist/lib/styles/page-layout-styles.js +1 -1
  47. package/dist/lib/types/form-builder.interfaces.d.ts +2 -2
  48. package/dist/lib/types/form-builder.types.d.ts +8 -2
  49. package/dist/lib/utils/validations.helper.d.ts +3 -3
  50. package/dist/lib/utils/validations.helper.js +7 -7
  51. package/package.json +3 -2
  52. package/dist/form-fields/base-field.d.ts +0 -20
  53. package/dist/form-fields/custom-elements.define.d.ts +0 -1
  54. package/dist/form-fields/custom-elements.define.js +0 -11
  55. package/dist/form-fields/number-field.js +0 -43
  56. package/dist/form-fields/text-field.js +0 -39
  57. package/dist/form-fields/wide-field.d.ts +0 -11
  58. package/dist/form-groups/custom-elements.define.d.ts +0 -1
  59. package/dist/form-groups/custom-elements.define.js +0 -9
@@ -0,0 +1,65 @@
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 { fireEvent } from '../utils/fire-custom-event';
9
+ let ConfirmationDialog = class ConfirmationDialog extends LitElement {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.dialogOpened = true;
13
+ this.text = '';
14
+ this.dialogTitle = '';
15
+ this.hideConfirmBtn = false;
16
+ }
17
+ set dialogData({ text, dialogTitle = 'Are you', hideConfirmBtn = false }) {
18
+ this.text = text;
19
+ this.dialogTitle = dialogTitle;
20
+ this.hideConfirmBtn = hideConfirmBtn;
21
+ this.requestUpdate();
22
+ }
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="${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
+ `;
41
+ }
42
+ onClose() {
43
+ fireEvent(this, 'response', { confirmed: false });
44
+ }
45
+ confirm() {
46
+ fireEvent(this, 'response', { confirmed: true });
47
+ }
48
+ static get styles() {
49
+ // language=CSS
50
+ return [
51
+ css `
52
+ .confirmation-message {
53
+ padding-left: 24px;
54
+ }
55
+ `
56
+ ];
57
+ }
58
+ };
59
+ __decorate([
60
+ property()
61
+ ], ConfirmationDialog.prototype, "dialogOpened", void 0);
62
+ ConfirmationDialog = __decorate([
63
+ customElement('confirmation-popup')
64
+ ], ConfirmationDialog);
65
+ export { ConfirmationDialog };
@@ -83,6 +83,9 @@ let EtoolsFbCard = class EtoolsFbCard extends LitElement {
83
83
  display: flex;
84
84
  flex-basis: auto;
85
85
  }
86
+ .flex-header__postfix {
87
+ order: 3;
88
+ }
86
89
  .flex-header__edit {
87
90
  order: 2;
88
91
  }
@@ -111,6 +114,9 @@ let EtoolsFbCard = class EtoolsFbCard extends LitElement {
111
114
  border-top: 1px solid lightgrey;
112
115
  justify-content: flex-end;
113
116
  }
117
+ .flex-header__postfix {
118
+ order: 3;
119
+ }
114
120
  .flex-header__edit {
115
121
  order: 1;
116
122
  flex-basis: 20%;
@@ -165,6 +171,7 @@ let EtoolsFbCard = class EtoolsFbCard extends LitElement {
165
171
  `
166
172
  : ''}
167
173
  </div>
174
+ <div class="flex-header__postfix"><slot name="postfix"></slot></div>
168
175
  </header>
169
176
  <iron-collapse ?opened="${!this.collapsed}">
170
177
  <section class="card-content-block">
@@ -11,11 +11,14 @@ export const AttachmentsStyles = css `
11
11
  display: flex;
12
12
  align-items: center;
13
13
  border-bottom: 1px solid var(--secondary-text-color, rgba(0, 0, 0, 0.54));
14
- margin: 0 14px;
14
+ margin: 0 14px 0 0;
15
15
  min-width: 145px;
16
16
  overflow-wrap: break-word;
17
17
  font-size: 16px;
18
18
  }
19
+ :host([is-readonly]) .filename-container {
20
+ border-bottom-color: transparent;
21
+ }
19
22
  .filename {
20
23
  overflow: hidden;
21
24
  text-overflow: ellipsis;
@@ -63,7 +66,7 @@ export const AttachmentsStyles = css `
63
66
  margin-top: 15px;
64
67
  }
65
68
  etools-upload-multi.with-padding {
66
- padding: 12px 9px;
69
+ padding: 12px 9px 12px 0;
67
70
  box-sizing: border-box;
68
71
  }
69
72
  `;
@@ -5,11 +5,13 @@ export const FormBuilderCardStyles = css `
5
5
  padding: 15px 25px 20px 45px;
6
6
  background-color: var(--secondary-background-color);
7
7
  }
8
- .finding-container {
8
+ field-renderer {
9
+ position: relative;
10
+ display: block;
9
11
  border-bottom: 1px solid var(--light-divider-color);
10
12
  }
11
- .finding-container:last-child {
12
- /*border-bottom: none;*/
13
+ field-renderer:last-of-type {
14
+ border-bottom: none;
13
15
  }
14
16
  .attachments-button {
15
17
  color: var(--primary-color);
@@ -26,6 +28,9 @@ export const FormBuilderCardStyles = css `
26
28
  .question-container {
27
29
  padding: 7px 0;
28
30
  width: 100%;
31
+ min-height: 57px;
32
+ box-sizing: border-box;
33
+ justify-content: center;
29
34
  }
30
35
  .question-text {
31
36
  font-weight: 500;
@@ -2,7 +2,7 @@ import { css } from 'lit-element';
2
2
  // language=CSS
3
3
  export const pageLayoutStyles = css `
4
4
  .page-content {
5
- margin: 24px;
5
+ margin: 24px 24px 0;
6
6
  }
7
7
 
8
8
  .page-content.filters {
@@ -42,7 +42,7 @@ export interface IFormBuilderAbstractGroup {
42
42
  * Use it to update current group value:
43
43
  * @value-changed="${(event) => this.valueChanged(event, BlueprintGroup.name)}"
44
44
  */
45
- renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult;
45
+ renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
46
46
  }
47
47
  export interface IFormBuilderCard extends IFormBuilderAbstractGroup {
48
48
  /**
@@ -73,7 +73,7 @@ export interface IFormBuilderCollapsedCard extends IFormBuilderAbstractGroup, IF
73
73
  * else { super.renderGroup(groupStructure); }
74
74
  *
75
75
  */
76
- renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult;
76
+ renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
77
77
  /**
78
78
  * Use openDialog method. Call valueChanged() on popup resolve with confirmed === true
79
79
  */
@@ -19,7 +19,7 @@ export declare type BlueprintGroup = {
19
19
  repeatable: boolean;
20
20
  required: boolean;
21
21
  title: string | null;
22
- children: (BlueprintGroup | BlueprintField)[];
22
+ children: (BlueprintGroup | BlueprintField | Information)[];
23
23
  };
24
24
  export declare type BlueprintField = {
25
25
  type: 'field';
@@ -28,7 +28,7 @@ export declare type BlueprintField = {
28
28
  name: string;
29
29
  repeatable: boolean;
30
30
  required: boolean;
31
- input_type: 'text' | 'likert_scale' | 'bool' | 'number' | 'number-integer' | 'number-float';
31
+ input_type: 'text' | 'likert_scale' | 'bool' | 'number' | 'number-integer' | 'number-float' | 'file';
32
32
  label: string;
33
33
  validations: string[];
34
34
  help_text: string;
@@ -36,6 +36,12 @@ export declare type BlueprintField = {
36
36
  default_value: null;
37
37
  options_key: null;
38
38
  };
39
+ export declare type Information = {
40
+ type: 'information';
41
+ extra: GenericObject;
42
+ styling: string[];
43
+ text: string;
44
+ };
39
45
  /** Metadata for blueprint structure */
40
46
  export declare type BlueprintMetadata = {
41
47
  options: GenericObject<BlueprintMetadataOptions>;
@@ -6,7 +6,7 @@ export declare enum Validations {
6
6
  }
7
7
  export declare type MaxLengthValidation = {
8
8
  name: Validations.MAX_LENGTH;
9
- [Validations.MAX_LENGTH]: string;
9
+ [Validations.MAX_LENGTH]: number;
10
10
  };
11
11
  export declare type RegexValidation = {
12
12
  name: Validations.REGEX;
@@ -14,12 +14,12 @@ export declare type RegexValidation = {
14
14
  };
15
15
  export declare type GreaterValidation = {
16
16
  name: Validations.GREATER_THAN;
17
- [Validations.GREATER_THAN]: string;
17
+ threshold: number;
18
18
  allow_equality: boolean;
19
19
  };
20
20
  export declare type LowerValidation = {
21
21
  name: Validations.LOWER_THAN;
22
- [Validations.LOWER_THAN]: string;
22
+ threshold: number;
23
23
  allow_equality: boolean;
24
24
  };
25
25
  export declare type FieldValidator = MaxLengthValidation | RegexValidation | GreaterValidation | LowerValidation;
@@ -18,17 +18,17 @@ export function validate(validators, value) {
18
18
  function checkValidation(validation, value) {
19
19
  switch (validation.name) {
20
20
  case Validations.MAX_LENGTH:
21
- const maxLength = Number(validation[Validations.MAX_LENGTH]);
21
+ const maxLength = Number(validation[Validations.MAX_LENGTH]) + 1;
22
22
  return String(value).length < maxLength ? null : `Text must be less than ${maxLength} character`;
23
23
  case Validations.REGEX:
24
- // TODO: Implements Regex validation
25
- return null;
24
+ const regex = new RegExp(`^${validation[Validations.REGEX]}$`);
25
+ return regex.test(String(value)) ? null : `Doesn't match allowed pattern`;
26
26
  case Validations.GREATER_THAN:
27
- const greaterThan = Number(validation[Validations.GREATER_THAN]) - Number(validation.allow_equality);
28
- return Number(value) > greaterThan ? null : `Number must be greater than ${greaterThan} character`;
27
+ const greaterThan = Number(validation.threshold) - Number(validation.allow_equality);
28
+ return Number(value) > greaterThan ? null : `Number must be greater than ${greaterThan}`;
29
29
  case Validations.LOWER_THAN:
30
- const lowerThan = Number(validation[Validations.LOWER_THAN]) + Number(validation.allow_equality);
31
- return Number(value) < lowerThan ? null : `Number must be lower than ${lowerThan} character`;
30
+ const lowerThan = Number(validation.threshold) + Number(validation.allow_equality);
31
+ return Number(value) < lowerThan ? null : `Number must be lower than ${lowerThan}`;
32
32
  default:
33
33
  return null;
34
34
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unicef-polymer/etools-form-builder",
3
3
  "description": "Etools FM Form Builder components",
4
- "version": "1.0.3",
4
+ "version": "2.0.0-rc.5",
5
5
  "contributors": [
6
6
  "eTools Team"
7
7
  ],
@@ -26,10 +26,11 @@
26
26
  "@polymer/paper-radio-button": "^3.0.1",
27
27
  "@polymer/paper-radio-group": "^3.0.1",
28
28
  "@polymer/paper-toast": "^3.0.1",
29
+ "@polymer/paper-toggle-button": "^3.0.1",
29
30
  "@types/ramda": "^0.26.43",
30
31
  "@unicef-polymer/etools-dialog": "5.0.0-rc.2",
31
32
  "@unicef-polymer/etools-dropdown": "^3.7.6",
32
- "@unicef-polymer/etools-upload": "^3.5.0",
33
+ "@unicef-polymer/etools-upload": "^4.2.1-rc.3",
33
34
  "@webcomponents/webcomponentsjs": "^2.6.0",
34
35
  "lit-element": "^2.4.0",
35
36
  "lit-translate": "^1.2.1",
@@ -1,20 +0,0 @@
1
- import { CSSResultArray, LitElement, TemplateResult } from 'lit-element';
2
- import { FieldValidator } from '../lib/utils/validations.helper';
3
- export declare abstract class BaseField<T> extends LitElement {
4
- questionText: string;
5
- isReadonly: boolean;
6
- required: boolean;
7
- value: T | null;
8
- protected _errorMessage: string | null;
9
- validators: FieldValidator[];
10
- set errorMessage(message: string | null);
11
- get errorMessage(): string | null;
12
- protected render(): TemplateResult;
13
- protected questionTemplate(): TemplateResult;
14
- protected valueChanged(newValue: T): void;
15
- protected validateField(value: T): void;
16
- protected metaValidation(value: T): string | null;
17
- protected abstract customValidation(value: T): string | null;
18
- protected abstract controlTemplate(): TemplateResult;
19
- static get styles(): CSSResultArray;
20
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- /**
2
- * Form field elements
3
- */
4
- import { TextField } from './text-field';
5
- import { NumberField } from './number-field';
6
- import { ScaleField } from './scale-field';
7
- import { WideField } from './wide-field';
8
- window.customElements.define('number-field', NumberField);
9
- window.customElements.define('text-field', TextField);
10
- window.customElements.define('scale-field', ScaleField);
11
- window.customElements.define('wide-field', WideField);
@@ -1,43 +0,0 @@
1
- import { css, html } from 'lit-element';
2
- import { BaseField } from './base-field';
3
- import '@polymer/paper-input/paper-input';
4
- import { InputStyles } from '../lib/styles/input-styles';
5
- export class NumberField extends BaseField {
6
- controlTemplate() {
7
- return html `
8
- ${InputStyles}
9
- <paper-input
10
- class="without-border no-padding-left form-control"
11
- no-label-float
12
- .value="${this.value}"
13
- @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
14
- placeholder="&#8212;"
15
- ?invalid="${this.errorMessage}"
16
- error-message="${this.errorMessage}"
17
- ?disabled="${this.isReadonly}"
18
- >
19
- </paper-input>
20
- `;
21
- }
22
- valueChanged(newValue) {
23
- const formatted = Number(newValue);
24
- const isNumber = !isNaN(formatted) && `${newValue}` !== '' && `${newValue}` !== 'null';
25
- super.valueChanged(isNumber ? formatted : newValue);
26
- }
27
- customValidation(value) {
28
- return value && isNaN(value) ? 'Must be a number' : null;
29
- }
30
- static get styles() {
31
- // language=CSS
32
- return [
33
- ...BaseField.styles,
34
- css `
35
- @media (max-width: 380px) {
36
- .no-padding-left {
37
- padding-left: 0;
38
- }
39
- }
40
- `
41
- ];
42
- }
43
- }
@@ -1,39 +0,0 @@
1
- import { css, html } from 'lit-element';
2
- import { BaseField } from './base-field';
3
- import '@polymer/paper-input/paper-textarea';
4
- import { InputStyles } from '../lib/styles/input-styles';
5
- export class TextField extends BaseField {
6
- controlTemplate() {
7
- return html `
8
- ${InputStyles}
9
- <paper-textarea
10
- id="textarea"
11
- class="no-padding-left form-control"
12
- no-label-float
13
- .value="${this.value}"
14
- @value-changed="${({ detail }) => this.valueChanged(detail.value)}"
15
- placeholder="&#8212;"
16
- ?disabled="${this.isReadonly}"
17
- ?invalid="${this.errorMessage}"
18
- error-message="${this.errorMessage}"
19
- >
20
- </paper-textarea>
21
- `;
22
- }
23
- customValidation() {
24
- return null;
25
- }
26
- static get styles() {
27
- // language=CSS
28
- return [
29
- ...BaseField.styles,
30
- css `
31
- @media (max-width: 380px) {
32
- .no-padding-left {
33
- padding-left: 0;
34
- }
35
- }
36
- `
37
- ];
38
- }
39
- }
@@ -1,11 +0,0 @@
1
- import { TemplateResult, CSSResultArray } from 'lit-element';
2
- import { BaseField } from './base-field';
3
- import '@polymer/paper-input/paper-textarea';
4
- export declare class WideField extends BaseField<string> {
5
- label: string;
6
- placeholder: string;
7
- protected render(): TemplateResult;
8
- protected controlTemplate(): TemplateResult;
9
- protected customValidation(): string | null;
10
- static get styles(): CSSResultArray;
11
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- /**
2
- * Form group elements
3
- */
4
- import { FormAbstractGroup } from './form-abstract-group';
5
- import { FormCard } from './form-card';
6
- import { FormCollapsedCard } from './form-collapsed-card';
7
- window.customElements.define('form-abstract-group', FormAbstractGroup);
8
- window.customElements.define('form-card', FormCard);
9
- window.customElements.define('form-collapsed-card', FormCollapsedCard);