@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.
- package/LICENSE +674 -674
- package/README.md +1 -1
- package/dist/assets/translations.d.ts +6 -0
- package/dist/assets/translations.js +67 -0
- package/dist/form-attachments-popup/form-attachments-popup.d.ts +86 -85
- package/dist/form-attachments-popup/form-attachments-popup.helper.d.ts +8 -8
- package/dist/form-attachments-popup/form-attachments-popup.helper.js +14 -14
- package/dist/form-attachments-popup/form-attachments-popup.js +255 -248
- package/dist/form-attachments-popup/form-attachments-popup.tpl.d.ts +3 -3
- package/dist/form-attachments-popup/form-attachments-popup.tpl.js +91 -89
- package/dist/form-attachments-popup/index.d.ts +2 -2
- package/dist/form-attachments-popup/index.js +2 -2
- package/dist/form-fields/abstract-field-base.class.d.ts +33 -28
- package/dist/form-fields/abstract-field-base.class.js +194 -176
- package/dist/form-fields/field-renderer-component.d.ts +20 -20
- package/dist/form-fields/field-renderer-component.js +249 -249
- package/dist/form-fields/index.d.ts +12 -12
- package/dist/form-fields/index.js +12 -12
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.d.ts +17 -17
- package/dist/form-fields/repeatable-fields/repeatable-attachment-field.js +209 -208
- package/dist/form-fields/repeatable-fields/repeatable-base-field.d.ts +20 -20
- package/dist/form-fields/repeatable-fields/repeatable-base-field.js +124 -123
- package/dist/form-fields/repeatable-fields/repeatable-number-field.d.ts +10 -10
- package/dist/form-fields/repeatable-fields/repeatable-number-field.js +67 -66
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.d.ts +15 -15
- package/dist/form-fields/repeatable-fields/repeatable-scale-field.js +108 -108
- package/dist/form-fields/repeatable-fields/repeatable-text-field.d.ts +8 -8
- package/dist/form-fields/repeatable-fields/repeatable-text-field.js +53 -53
- package/dist/form-fields/single-fields/attachment-field.d.ts +16 -16
- package/dist/form-fields/single-fields/attachment-field.js +98 -97
- package/dist/form-fields/single-fields/base-field.d.ts +11 -11
- package/dist/form-fields/single-fields/base-field.js +58 -57
- package/dist/form-fields/single-fields/boolean-field.d.ts +8 -8
- package/dist/form-fields/single-fields/boolean-field.js +49 -49
- package/dist/form-fields/single-fields/number-field.d.ts +10 -10
- package/dist/form-fields/single-fields/number-field.js +67 -66
- package/dist/form-fields/single-fields/scale-field.d.ts +18 -18
- package/dist/form-fields/single-fields/scale-field.js +108 -107
- package/dist/form-fields/single-fields/text-field.d.ts +8 -8
- package/dist/form-fields/single-fields/text-field.js +54 -54
- package/dist/form-groups/form-abstract-group.d.ts +65 -60
- package/dist/form-groups/form-abstract-group.js +375 -353
- package/dist/form-groups/form-card.d.ts +32 -32
- package/dist/form-groups/form-card.js +113 -108
- package/dist/form-groups/form-collapsed-card.d.ts +70 -70
- package/dist/form-groups/form-collapsed-card.js +254 -253
- package/dist/form-groups/index.d.ts +3 -3
- package/dist/form-groups/index.js +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/lib/additional-components/confirmation-dialog.d.ts +18 -16
- package/dist/lib/additional-components/confirmation-dialog.js +72 -65
- package/dist/lib/additional-components/etools-fb-card.d.ts +21 -16
- package/dist/lib/additional-components/etools-fb-card.js +238 -215
- package/dist/lib/styles/attachments.styles.d.ts +2 -2
- package/dist/lib/styles/attachments.styles.js +72 -72
- package/dist/lib/styles/card-styles.d.ts +2 -2
- package/dist/lib/styles/card-styles.js +154 -154
- package/dist/lib/styles/dialog.styles.d.ts +2 -2
- package/dist/lib/styles/dialog.styles.js +85 -85
- package/dist/lib/styles/elevation-styles.d.ts +9 -9
- package/dist/lib/styles/elevation-styles.js +43 -43
- package/dist/lib/styles/flex-layout-classes.d.ts +2 -2
- package/dist/lib/styles/flex-layout-classes.js +319 -319
- package/dist/lib/styles/form-builder-card.styles.d.ts +2 -2
- package/dist/lib/styles/form-builder-card.styles.js +49 -49
- package/dist/lib/styles/input-styles.d.ts +2 -2
- package/dist/lib/styles/input-styles.js +138 -138
- package/dist/lib/styles/page-layout-styles.d.ts +2 -2
- package/dist/lib/styles/page-layout-styles.js +201 -201
- package/dist/lib/styles/shared-styles.d.ts +2 -2
- package/dist/lib/styles/shared-styles.js +70 -70
- package/dist/lib/types/form-builder.interfaces.d.ts +83 -83
- package/dist/lib/types/form-builder.interfaces.js +0 -0
- package/dist/lib/types/form-builder.types.d.ts +59 -59
- package/dist/lib/types/form-builder.types.js +0 -0
- package/dist/lib/types/global.types.d.ts +4 -4
- package/dist/lib/types/global.types.js +0 -0
- package/dist/lib/utils/dialog.d.ts +10 -10
- package/dist/lib/utils/dialog.js +21 -21
- package/dist/lib/utils/fire-custom-event.d.ts +1 -1
- package/dist/lib/utils/fire-custom-event.js +7 -7
- package/dist/lib/utils/translate.d.ts +1 -0
- package/dist/lib/utils/translate.js +9 -0
- package/dist/lib/utils/validations.helper.d.ts +26 -26
- package/dist/lib/utils/validations.helper.js +42 -35
- package/package.json +56 -56
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { TemplateResult } from 'lit-element';
|
|
2
|
-
import { BlueprintField, BlueprintGroup, BlueprintMetadata } from './form-builder.types';
|
|
3
|
-
import { GenericObject } from './global.types';
|
|
4
|
-
/** Component for rendering BlueprintGroup with group.extra.type.includes('abstract') or group.name === 'root' */
|
|
5
|
-
export interface IFormBuilderAbstractGroup {
|
|
6
|
-
groupStructure: BlueprintGroup;
|
|
7
|
-
metadata: BlueprintMetadata;
|
|
8
|
-
parentGroupName: string;
|
|
9
|
-
readonly: boolean;
|
|
10
|
-
value: GenericObject;
|
|
11
|
-
/**
|
|
12
|
-
* Updates groupValue object by this.value[fieldName] = event.details.value
|
|
13
|
-
* @param event - comes from event emitted by rendered BlueprintField or BlueprintGroup child of current Group
|
|
14
|
-
* @param fieldName - name field of BlueprintField or BlueprintGroup child of current Group
|
|
15
|
-
*
|
|
16
|
-
* stopsPropagation of current value-changed event it will be replaced with new event
|
|
17
|
-
* Emits value-changed event with updated groupValue
|
|
18
|
-
*/
|
|
19
|
-
valueChanged(event: CustomEvent, fieldName: string): void;
|
|
20
|
-
/**
|
|
21
|
-
* Returns template for BlueprintField structure depending on their styling
|
|
22
|
-
*
|
|
23
|
-
* without styling (empty array) - standard appearance (label and helper text in left column field element in right)
|
|
24
|
-
* styling.includes('wide') - field takes all parent width
|
|
25
|
-
* styling.includes('additional') - gray background
|
|
26
|
-
*
|
|
27
|
-
* Pass value to field as this.value[BlueprintField.name]
|
|
28
|
-
* Rendered field must emit value-changed event
|
|
29
|
-
* Use it to update current group value:
|
|
30
|
-
* @value-changed="${(event) => this.valueChanged(event, BlueprintField.name)}"
|
|
31
|
-
*/
|
|
32
|
-
renderField(fieldStructure: BlueprintField): TemplateResult;
|
|
33
|
-
/**
|
|
34
|
-
* Returns template for BlueprintGroup structure depending on their styling
|
|
35
|
-
*
|
|
36
|
-
* styling.includes('card') && styling.includes('collapse') - render as IFormBuilderCollapsedCard
|
|
37
|
-
* styling.includes('card') - render as IFormBuilderCard
|
|
38
|
-
* styling.includes('abstract') - render as IFormBuilderAbstractGroup recursively
|
|
39
|
-
*
|
|
40
|
-
* Pass groupValue to group as this.value[BlueprintGroup.name]
|
|
41
|
-
* Rendered group must emit value-changed event
|
|
42
|
-
* Use it to update current group value:
|
|
43
|
-
* @value-changed="${(event) => this.valueChanged(event, BlueprintGroup.name)}"
|
|
44
|
-
*/
|
|
45
|
-
renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
|
|
46
|
-
}
|
|
47
|
-
export interface IFormBuilderCard extends IFormBuilderAbstractGroup {
|
|
48
|
-
/**
|
|
49
|
-
* Overrides parent method.
|
|
50
|
-
* It must doing the same but not sending new event, only stop current.
|
|
51
|
-
* value-changed will be send latter
|
|
52
|
-
*/
|
|
53
|
-
valueChanged(event: CustomEvent, fieldName: string): void;
|
|
54
|
-
/**
|
|
55
|
-
* Show toastr if card has errors, returns;
|
|
56
|
-
* Emits value-changed event for updating changed value
|
|
57
|
-
*/
|
|
58
|
-
saveChanges(): void;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Component for rendering BlueprintGroup as DataCollectionCard.
|
|
62
|
-
* Computes Card title using parentGroupName mapping + currentGroup.name
|
|
63
|
-
* Allows to render attachment group and handles their logic
|
|
64
|
-
*/
|
|
65
|
-
export interface IFormBuilderCollapsedCard extends IFormBuilderAbstractGroup, IFormBuilderCard {
|
|
66
|
-
/**
|
|
67
|
-
* Extend renderGroup() method. It must handle additional type:
|
|
68
|
-
*
|
|
69
|
-
* styling.includes('floating_attachments') - render group as attachment button
|
|
70
|
-
*
|
|
71
|
-
* ---
|
|
72
|
-
* if (styling.includes('floating_attachments')) { ...render attachment button... }
|
|
73
|
-
* else { super.renderGroup(groupStructure); }
|
|
74
|
-
*
|
|
75
|
-
*/
|
|
76
|
-
renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
|
|
77
|
-
/**
|
|
78
|
-
* Use openDialog method. Call valueChanged() on popup resolve with confirmed === true
|
|
79
|
-
*/
|
|
80
|
-
openAttachmentsPopup(): void;
|
|
81
|
-
cancelEdit(): void;
|
|
82
|
-
startEdit(): void;
|
|
83
|
-
}
|
|
1
|
+
import { TemplateResult } from 'lit-element';
|
|
2
|
+
import { BlueprintField, BlueprintGroup, BlueprintMetadata } from './form-builder.types';
|
|
3
|
+
import { GenericObject } from './global.types';
|
|
4
|
+
/** Component for rendering BlueprintGroup with group.extra.type.includes('abstract') or group.name === 'root' */
|
|
5
|
+
export interface IFormBuilderAbstractGroup {
|
|
6
|
+
groupStructure: BlueprintGroup;
|
|
7
|
+
metadata: BlueprintMetadata;
|
|
8
|
+
parentGroupName: string;
|
|
9
|
+
readonly: boolean;
|
|
10
|
+
value: GenericObject;
|
|
11
|
+
/**
|
|
12
|
+
* Updates groupValue object by this.value[fieldName] = event.details.value
|
|
13
|
+
* @param event - comes from event emitted by rendered BlueprintField or BlueprintGroup child of current Group
|
|
14
|
+
* @param fieldName - name field of BlueprintField or BlueprintGroup child of current Group
|
|
15
|
+
*
|
|
16
|
+
* stopsPropagation of current value-changed event it will be replaced with new event
|
|
17
|
+
* Emits value-changed event with updated groupValue
|
|
18
|
+
*/
|
|
19
|
+
valueChanged(event: CustomEvent, fieldName: string): void;
|
|
20
|
+
/**
|
|
21
|
+
* Returns template for BlueprintField structure depending on their styling
|
|
22
|
+
*
|
|
23
|
+
* without styling (empty array) - standard appearance (label and helper text in left column field element in right)
|
|
24
|
+
* styling.includes('wide') - field takes all parent width
|
|
25
|
+
* styling.includes('additional') - gray background
|
|
26
|
+
*
|
|
27
|
+
* Pass value to field as this.value[BlueprintField.name]
|
|
28
|
+
* Rendered field must emit value-changed event
|
|
29
|
+
* Use it to update current group value:
|
|
30
|
+
* @value-changed="${(event) => this.valueChanged(event, BlueprintField.name)}"
|
|
31
|
+
*/
|
|
32
|
+
renderField(fieldStructure: BlueprintField): TemplateResult;
|
|
33
|
+
/**
|
|
34
|
+
* Returns template for BlueprintGroup structure depending on their styling
|
|
35
|
+
*
|
|
36
|
+
* styling.includes('card') && styling.includes('collapse') - render as IFormBuilderCollapsedCard
|
|
37
|
+
* styling.includes('card') - render as IFormBuilderCard
|
|
38
|
+
* styling.includes('abstract') - render as IFormBuilderAbstractGroup recursively
|
|
39
|
+
*
|
|
40
|
+
* Pass groupValue to group as this.value[BlueprintGroup.name]
|
|
41
|
+
* Rendered group must emit value-changed event
|
|
42
|
+
* Use it to update current group value:
|
|
43
|
+
* @value-changed="${(event) => this.valueChanged(event, BlueprintGroup.name)}"
|
|
44
|
+
*/
|
|
45
|
+
renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
|
|
46
|
+
}
|
|
47
|
+
export interface IFormBuilderCard extends IFormBuilderAbstractGroup {
|
|
48
|
+
/**
|
|
49
|
+
* Overrides parent method.
|
|
50
|
+
* It must doing the same but not sending new event, only stop current.
|
|
51
|
+
* value-changed will be send latter
|
|
52
|
+
*/
|
|
53
|
+
valueChanged(event: CustomEvent, fieldName: string): void;
|
|
54
|
+
/**
|
|
55
|
+
* Show toastr if card has errors, returns;
|
|
56
|
+
* Emits value-changed event for updating changed value
|
|
57
|
+
*/
|
|
58
|
+
saveChanges(): void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Component for rendering BlueprintGroup as DataCollectionCard.
|
|
62
|
+
* Computes Card title using parentGroupName mapping + currentGroup.name
|
|
63
|
+
* Allows to render attachment group and handles their logic
|
|
64
|
+
*/
|
|
65
|
+
export interface IFormBuilderCollapsedCard extends IFormBuilderAbstractGroup, IFormBuilderCard {
|
|
66
|
+
/**
|
|
67
|
+
* Extend renderGroup() method. It must handle additional type:
|
|
68
|
+
*
|
|
69
|
+
* styling.includes('floating_attachments') - render group as attachment button
|
|
70
|
+
*
|
|
71
|
+
* ---
|
|
72
|
+
* if (styling.includes('floating_attachments')) { ...render attachment button... }
|
|
73
|
+
* else { super.renderGroup(groupStructure); }
|
|
74
|
+
*
|
|
75
|
+
*/
|
|
76
|
+
renderGroup(groupStructure: BlueprintGroup, groupValue?: GenericObject): TemplateResult | TemplateResult[];
|
|
77
|
+
/**
|
|
78
|
+
* Use openDialog method. Call valueChanged() on popup resolve with confirmed === true
|
|
79
|
+
*/
|
|
80
|
+
openAttachmentsPopup(): void;
|
|
81
|
+
cancelEdit(): void;
|
|
82
|
+
startEdit(): void;
|
|
83
|
+
}
|
|
File without changes
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { FieldValidator } from '../utils/validations.helper';
|
|
2
|
-
import { GenericObject } from './global.types';
|
|
3
|
-
/** JSON file from backend */
|
|
4
|
-
export declare type ChecklistFormJson = {
|
|
5
|
-
blueprint: {
|
|
6
|
-
code: string;
|
|
7
|
-
metadata: BlueprintMetadata;
|
|
8
|
-
structure: BlueprintGroup;
|
|
9
|
-
title: string;
|
|
10
|
-
};
|
|
11
|
-
value: GenericObject;
|
|
12
|
-
};
|
|
13
|
-
/** --------- */
|
|
14
|
-
export declare type BlueprintGroup = {
|
|
15
|
-
type: 'group';
|
|
16
|
-
extra: GenericObject;
|
|
17
|
-
styling: string[];
|
|
18
|
-
name: string;
|
|
19
|
-
repeatable: boolean;
|
|
20
|
-
required: boolean;
|
|
21
|
-
title: string | null;
|
|
22
|
-
children: (BlueprintGroup | BlueprintField | Information)[];
|
|
23
|
-
};
|
|
24
|
-
export declare type BlueprintField = {
|
|
25
|
-
type: 'field';
|
|
26
|
-
extra: GenericObject;
|
|
27
|
-
styling: string[];
|
|
28
|
-
name: string;
|
|
29
|
-
repeatable: boolean;
|
|
30
|
-
required: boolean;
|
|
31
|
-
input_type: 'text' | 'likert_scale' | 'bool' | 'number' | 'number-integer' | 'number-float' | 'file';
|
|
32
|
-
label: string;
|
|
33
|
-
validations: string[];
|
|
34
|
-
help_text: string;
|
|
35
|
-
placeholder: string;
|
|
36
|
-
default_value: null;
|
|
37
|
-
options_key: null;
|
|
38
|
-
};
|
|
39
|
-
export declare type Information = {
|
|
40
|
-
type: 'information';
|
|
41
|
-
extra: GenericObject;
|
|
42
|
-
styling: string[];
|
|
43
|
-
text: string;
|
|
44
|
-
};
|
|
45
|
-
/** Metadata for blueprint structure */
|
|
46
|
-
export declare type BlueprintMetadata = {
|
|
47
|
-
options: GenericObject<BlueprintMetadataOptions>;
|
|
48
|
-
validations: GenericObject<FieldValidator>;
|
|
49
|
-
offline_enabled: boolean;
|
|
50
|
-
allow_multiple_responses: boolean;
|
|
51
|
-
};
|
|
52
|
-
export declare type BlueprintMetadataOptions = {
|
|
53
|
-
option_type: string;
|
|
54
|
-
values: BlueprintMetadataOption[];
|
|
55
|
-
};
|
|
56
|
-
export declare type BlueprintMetadataOption = {
|
|
57
|
-
value: string;
|
|
58
|
-
label: string;
|
|
59
|
-
};
|
|
1
|
+
import { FieldValidator } from '../utils/validations.helper';
|
|
2
|
+
import { GenericObject } from './global.types';
|
|
3
|
+
/** JSON file from backend */
|
|
4
|
+
export declare type ChecklistFormJson = {
|
|
5
|
+
blueprint: {
|
|
6
|
+
code: string;
|
|
7
|
+
metadata: BlueprintMetadata;
|
|
8
|
+
structure: BlueprintGroup;
|
|
9
|
+
title: string;
|
|
10
|
+
};
|
|
11
|
+
value: GenericObject;
|
|
12
|
+
};
|
|
13
|
+
/** --------- */
|
|
14
|
+
export declare type BlueprintGroup = {
|
|
15
|
+
type: 'group';
|
|
16
|
+
extra: GenericObject;
|
|
17
|
+
styling: string[];
|
|
18
|
+
name: string;
|
|
19
|
+
repeatable: boolean;
|
|
20
|
+
required: boolean;
|
|
21
|
+
title: string | null;
|
|
22
|
+
children: (BlueprintGroup | BlueprintField | Information)[];
|
|
23
|
+
};
|
|
24
|
+
export declare type BlueprintField = {
|
|
25
|
+
type: 'field';
|
|
26
|
+
extra: GenericObject;
|
|
27
|
+
styling: string[];
|
|
28
|
+
name: string;
|
|
29
|
+
repeatable: boolean;
|
|
30
|
+
required: boolean;
|
|
31
|
+
input_type: 'text' | 'likert_scale' | 'bool' | 'number' | 'number-integer' | 'number-float' | 'file';
|
|
32
|
+
label: string;
|
|
33
|
+
validations: string[];
|
|
34
|
+
help_text: string;
|
|
35
|
+
placeholder: string;
|
|
36
|
+
default_value: null;
|
|
37
|
+
options_key: null;
|
|
38
|
+
};
|
|
39
|
+
export declare type Information = {
|
|
40
|
+
type: 'information';
|
|
41
|
+
extra: GenericObject;
|
|
42
|
+
styling: string[];
|
|
43
|
+
text: string;
|
|
44
|
+
};
|
|
45
|
+
/** Metadata for blueprint structure */
|
|
46
|
+
export declare type BlueprintMetadata = {
|
|
47
|
+
options: GenericObject<BlueprintMetadataOptions>;
|
|
48
|
+
validations: GenericObject<FieldValidator>;
|
|
49
|
+
offline_enabled: boolean;
|
|
50
|
+
allow_multiple_responses: boolean;
|
|
51
|
+
};
|
|
52
|
+
export declare type BlueprintMetadataOptions = {
|
|
53
|
+
option_type: string;
|
|
54
|
+
values: BlueprintMetadataOption[];
|
|
55
|
+
};
|
|
56
|
+
export declare type BlueprintMetadataOption = {
|
|
57
|
+
value: string;
|
|
58
|
+
label: string;
|
|
59
|
+
};
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type GenericObject<T = any> = {
|
|
2
|
-
[key: string]: T;
|
|
3
|
-
};
|
|
4
|
-
export declare type Callback = (...args: any) => void;
|
|
1
|
+
export declare type GenericObject<T = any> = {
|
|
2
|
+
[key: string]: T;
|
|
3
|
+
};
|
|
4
|
+
export declare type Callback = (...args: any) => void;
|
|
File without changes
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export interface IDialog<D> {
|
|
2
|
-
dialog: string;
|
|
3
|
-
dialogData?: D;
|
|
4
|
-
readonly?: boolean;
|
|
5
|
-
}
|
|
6
|
-
export interface IDialogResponse<R> {
|
|
7
|
-
response?: R;
|
|
8
|
-
confirmed: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function openDialog<D, R = any>({ dialog, dialogData, readonly }: IDialog<D>): Promise<IDialogResponse<R>>;
|
|
1
|
+
export interface IDialog<D> {
|
|
2
|
+
dialog: string;
|
|
3
|
+
dialogData?: D;
|
|
4
|
+
readonly?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface IDialogResponse<R> {
|
|
7
|
+
response?: R;
|
|
8
|
+
confirmed: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function openDialog<D, R = any>({ dialog, dialogData, readonly }: IDialog<D>): Promise<IDialogResponse<R>>;
|
package/dist/lib/utils/dialog.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
export function openDialog({ dialog, dialogData, readonly }) {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
const dialogElement = document.createElement(dialog);
|
|
4
|
-
const body = document.querySelector('body');
|
|
5
|
-
if (body) {
|
|
6
|
-
body.appendChild(dialogElement);
|
|
7
|
-
}
|
|
8
|
-
else {
|
|
9
|
-
reject(new Error('Body not exist'));
|
|
10
|
-
}
|
|
11
|
-
dialogElement.dialogData = dialogData;
|
|
12
|
-
if (readonly) {
|
|
13
|
-
dialogElement.readonly = readonly;
|
|
14
|
-
}
|
|
15
|
-
dialogElement.addEventListener('response', (e) => {
|
|
16
|
-
const event = e;
|
|
17
|
-
resolve(event.detail);
|
|
18
|
-
dialogElement.remove();
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
}
|
|
1
|
+
export function openDialog({ dialog, dialogData, readonly }) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const dialogElement = document.createElement(dialog);
|
|
4
|
+
const body = document.querySelector('body');
|
|
5
|
+
if (body) {
|
|
6
|
+
body.appendChild(dialogElement);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
reject(new Error('Body not exist'));
|
|
10
|
+
}
|
|
11
|
+
dialogElement.dialogData = dialogData;
|
|
12
|
+
if (readonly) {
|
|
13
|
+
dialogElement.readonly = readonly;
|
|
14
|
+
}
|
|
15
|
+
dialogElement.addEventListener('response', (e) => {
|
|
16
|
+
const event = e;
|
|
17
|
+
resolve(event.detail);
|
|
18
|
+
dialogElement.remove();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function fireEvent(el: HTMLElement, eventName: string, detail?: any): void;
|
|
1
|
+
export declare function fireEvent(el: HTMLElement, eventName: string, detail?: any): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export function fireEvent(el, eventName, detail) {
|
|
2
|
-
el.dispatchEvent(new CustomEvent(eventName, {
|
|
3
|
-
detail,
|
|
4
|
-
bubbles: true,
|
|
5
|
-
composed: true
|
|
6
|
-
}));
|
|
7
|
-
}
|
|
1
|
+
export function fireEvent(el, eventName, detail) {
|
|
2
|
+
el.dispatchEvent(new CustomEvent(eventName, {
|
|
3
|
+
detail,
|
|
4
|
+
bubbles: true,
|
|
5
|
+
composed: true
|
|
6
|
+
}));
|
|
7
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getTranslation(lang: string, key: string): string;
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
export declare enum Validations {
|
|
2
|
-
MAX_LENGTH = "max_length",
|
|
3
|
-
REGEX = "regex",
|
|
4
|
-
LOWER_THAN = "lt",
|
|
5
|
-
GREATER_THAN = "gt"
|
|
6
|
-
}
|
|
7
|
-
export declare type MaxLengthValidation = {
|
|
8
|
-
name: Validations.MAX_LENGTH;
|
|
9
|
-
[Validations.MAX_LENGTH]: number;
|
|
10
|
-
};
|
|
11
|
-
export declare type RegexValidation = {
|
|
12
|
-
name: Validations.REGEX;
|
|
13
|
-
[Validations.REGEX]: string;
|
|
14
|
-
};
|
|
15
|
-
export declare type GreaterValidation = {
|
|
16
|
-
name: Validations.GREATER_THAN;
|
|
17
|
-
threshold: number;
|
|
18
|
-
allow_equality: boolean;
|
|
19
|
-
};
|
|
20
|
-
export declare type LowerValidation = {
|
|
21
|
-
name: Validations.LOWER_THAN;
|
|
22
|
-
threshold: number;
|
|
23
|
-
allow_equality: boolean;
|
|
24
|
-
};
|
|
25
|
-
export declare type FieldValidator = MaxLengthValidation | RegexValidation | GreaterValidation | LowerValidation;
|
|
26
|
-
export declare function validate(validators: FieldValidator[], value: any): string | null;
|
|
1
|
+
export declare enum Validations {
|
|
2
|
+
MAX_LENGTH = "max_length",
|
|
3
|
+
REGEX = "regex",
|
|
4
|
+
LOWER_THAN = "lt",
|
|
5
|
+
GREATER_THAN = "gt"
|
|
6
|
+
}
|
|
7
|
+
export declare type MaxLengthValidation = {
|
|
8
|
+
name: Validations.MAX_LENGTH;
|
|
9
|
+
[Validations.MAX_LENGTH]: number;
|
|
10
|
+
};
|
|
11
|
+
export declare type RegexValidation = {
|
|
12
|
+
name: Validations.REGEX;
|
|
13
|
+
[Validations.REGEX]: string;
|
|
14
|
+
};
|
|
15
|
+
export declare type GreaterValidation = {
|
|
16
|
+
name: Validations.GREATER_THAN;
|
|
17
|
+
threshold: number;
|
|
18
|
+
allow_equality: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare type LowerValidation = {
|
|
21
|
+
name: Validations.LOWER_THAN;
|
|
22
|
+
threshold: number;
|
|
23
|
+
allow_equality: boolean;
|
|
24
|
+
};
|
|
25
|
+
export declare type FieldValidator = MaxLengthValidation | RegexValidation | GreaterValidation | LowerValidation;
|
|
26
|
+
export declare function validate(validators: FieldValidator[], value: any, language: string): string | null;
|
|
@@ -1,35 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Validations["
|
|
5
|
-
Validations["
|
|
6
|
-
Validations["
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
case Validations.
|
|
27
|
-
const
|
|
28
|
-
return
|
|
29
|
-
case Validations.
|
|
30
|
-
const
|
|
31
|
-
return Number(value)
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
import { getTranslation } from './translate';
|
|
2
|
+
export var Validations;
|
|
3
|
+
(function (Validations) {
|
|
4
|
+
Validations["MAX_LENGTH"] = "max_length";
|
|
5
|
+
Validations["REGEX"] = "regex";
|
|
6
|
+
Validations["LOWER_THAN"] = "lt";
|
|
7
|
+
Validations["GREATER_THAN"] = "gt";
|
|
8
|
+
})(Validations || (Validations = {}));
|
|
9
|
+
export function validate(validators, value, language) {
|
|
10
|
+
let message = null;
|
|
11
|
+
for (const validator of validators) {
|
|
12
|
+
message = checkValidation(validator, value, language);
|
|
13
|
+
if (message) {
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return message;
|
|
18
|
+
}
|
|
19
|
+
function checkValidation(validation, value, language) {
|
|
20
|
+
switch (validation.name) {
|
|
21
|
+
case Validations.MAX_LENGTH:
|
|
22
|
+
const maxLength = Number(validation[Validations.MAX_LENGTH]) + 1;
|
|
23
|
+
return String(value).length < maxLength
|
|
24
|
+
? null
|
|
25
|
+
: getTranslation(language, 'TEXT_MUST_BE_LESS_CHARS').replace('{0}', String(maxLength));
|
|
26
|
+
case Validations.REGEX:
|
|
27
|
+
const regex = new RegExp(`^${validation[Validations.REGEX]}$`);
|
|
28
|
+
return regex.test(String(value)) ? null : getTranslation(language, 'DOES_NOT_MATCH_PATTERN');
|
|
29
|
+
case Validations.GREATER_THAN:
|
|
30
|
+
const greaterThan = Number(validation.threshold) - Number(validation.allow_equality);
|
|
31
|
+
return Number(value) > greaterThan
|
|
32
|
+
? null
|
|
33
|
+
: getTranslation(language, 'NUMBER_MUST_BE_GREATER_THAN').replace('{0}', String(greaterThan));
|
|
34
|
+
case Validations.LOWER_THAN:
|
|
35
|
+
const lowerThan = Number(validation.threshold) + Number(validation.allow_equality);
|
|
36
|
+
return Number(value) < lowerThan
|
|
37
|
+
? null
|
|
38
|
+
: getTranslation(language, 'NUMBER_MUST_BE_LOWER_THAN').replace('{0}', String(lowerThan));
|
|
39
|
+
default:
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@unicef-polymer/etools-form-builder",
|
|
3
|
-
"description": "Etools FM Form Builder components",
|
|
4
|
-
"version": "2.1.
|
|
5
|
-
"contributors": [
|
|
6
|
-
"eTools Team"
|
|
7
|
-
],
|
|
8
|
-
"license": "BSD-3-Clause",
|
|
9
|
-
"repository": "https://github.com/unicef-polymer/fm-form-builder",
|
|
10
|
-
"main": "dist/index.js",
|
|
11
|
-
"types": "dist/index.d.ts",
|
|
12
|
-
"files": [
|
|
13
|
-
"dist"
|
|
14
|
-
],
|
|
15
|
-
"scripts": {
|
|
16
|
-
"build": "tsc --skipLibCheck",
|
|
17
|
-
"lint": "eslint src/",
|
|
18
|
-
"prepare": "
|
|
19
|
-
"prepublishOnly": "npm run lint"
|
|
20
|
-
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"@polymer/iron-collapse": "^3.0.1",
|
|
23
|
-
"@polymer/iron-icons": "^3.0.1",
|
|
24
|
-
"@polymer/paper-button": "^3.0.1",
|
|
25
|
-
"@polymer/paper-input": "^3.2.1",
|
|
26
|
-
"@polymer/paper-radio-button": "^3.0.1",
|
|
27
|
-
"@polymer/paper-radio-group": "^3.0.1",
|
|
28
|
-
"@polymer/paper-toast": "^3.0.1",
|
|
29
|
-
"@polymer/paper-toggle-button": "^3.0.1",
|
|
30
|
-
"@types/ramda": "^0.26.43",
|
|
31
|
-
"@unicef-polymer/etools-dialog": "^6.0.
|
|
32
|
-
"@unicef-polymer/etools-dropdown": "^3.9.
|
|
33
|
-
"@unicef-polymer/etools-upload": "^4.
|
|
34
|
-
"@webcomponents/webcomponentsjs": "^2.6.0",
|
|
35
|
-
"lit-element": "^2.5.1",
|
|
36
|
-
"lit-translate": "^1.2.1",
|
|
37
|
-
"ramda": "^0.27.1",
|
|
38
|
-
"web-animations-js": "^2.3.2"
|
|
39
|
-
},
|
|
40
|
-
"devDependencies": {
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
|
42
|
-
"@typescript-eslint/parser": "^3.10.1",
|
|
43
|
-
"acorn": "^8.0.4",
|
|
44
|
-
"eslint": "^7.14.0",
|
|
45
|
-
"eslint-config-prettier": "^6.15.0",
|
|
46
|
-
"eslint-plugin-html": "^6.1.1",
|
|
47
|
-
"eslint-plugin-lit": "^1.2.4",
|
|
48
|
-
"eslint-plugin-prettier": "^3.1.3",
|
|
49
|
-
"minimist": ">=0.2.1",
|
|
50
|
-
"prettier": "~2.2.0",
|
|
51
|
-
"typescript": "^3.9.7",
|
|
52
|
-
"lodash": ">=4.17.21",
|
|
53
|
-
"ansi-regex": ">=5.0.1",
|
|
54
|
-
"glob-parent": ">=5.1.2"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@unicef-polymer/etools-form-builder",
|
|
3
|
+
"description": "Etools FM Form Builder components",
|
|
4
|
+
"version": "2.1.2",
|
|
5
|
+
"contributors": [
|
|
6
|
+
"eTools Team"
|
|
7
|
+
],
|
|
8
|
+
"license": "BSD-3-Clause",
|
|
9
|
+
"repository": "https://github.com/unicef-polymer/fm-form-builder",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc --skipLibCheck",
|
|
17
|
+
"lint": "eslint src/",
|
|
18
|
+
"prepare": "npm run build",
|
|
19
|
+
"prepublishOnly": "npm run lint"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@polymer/iron-collapse": "^3.0.1",
|
|
23
|
+
"@polymer/iron-icons": "^3.0.1",
|
|
24
|
+
"@polymer/paper-button": "^3.0.1",
|
|
25
|
+
"@polymer/paper-input": "^3.2.1",
|
|
26
|
+
"@polymer/paper-radio-button": "^3.0.1",
|
|
27
|
+
"@polymer/paper-radio-group": "^3.0.1",
|
|
28
|
+
"@polymer/paper-toast": "^3.0.1",
|
|
29
|
+
"@polymer/paper-toggle-button": "^3.0.1",
|
|
30
|
+
"@types/ramda": "^0.26.43",
|
|
31
|
+
"@unicef-polymer/etools-dialog": "^6.0.4",
|
|
32
|
+
"@unicef-polymer/etools-dropdown": "^3.9.7",
|
|
33
|
+
"@unicef-polymer/etools-upload": "^4.4.1",
|
|
34
|
+
"@webcomponents/webcomponentsjs": "^2.6.0",
|
|
35
|
+
"lit-element": "^2.5.1",
|
|
36
|
+
"lit-translate": "^1.2.1",
|
|
37
|
+
"ramda": "^0.27.1",
|
|
38
|
+
"web-animations-js": "^2.3.2"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^3.10.1",
|
|
42
|
+
"@typescript-eslint/parser": "^3.10.1",
|
|
43
|
+
"acorn": "^8.0.4",
|
|
44
|
+
"eslint": "^7.14.0",
|
|
45
|
+
"eslint-config-prettier": "^6.15.0",
|
|
46
|
+
"eslint-plugin-html": "^6.1.1",
|
|
47
|
+
"eslint-plugin-lit": "^1.2.4",
|
|
48
|
+
"eslint-plugin-prettier": "^3.1.3",
|
|
49
|
+
"minimist": ">=0.2.1",
|
|
50
|
+
"prettier": "~2.2.0",
|
|
51
|
+
"typescript": "^3.9.7",
|
|
52
|
+
"lodash": ">=4.17.21",
|
|
53
|
+
"ansi-regex": ">=5.0.1",
|
|
54
|
+
"glob-parent": ">=5.1.2"
|
|
55
|
+
}
|
|
56
|
+
}
|