@beabee/beabee-common 1.18.0-alpha.2 → 1.18.0-alpha.4
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.
|
@@ -1,30 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringifyAnswer = exports.isFileUploadAnswer = exports.isAddressAnswer = exports.
|
|
3
|
+
exports.stringifyAnswer = exports.isFileUploadAnswer = exports.isAddressAnswer = exports.getCalloutFilters = exports.getCalloutComponents = exports.filterComponents = void 0;
|
|
4
4
|
function isNestableComponent(component) {
|
|
5
5
|
// Addresses have embedded components we don't want to include
|
|
6
6
|
return "components" in component && component.type !== "address";
|
|
7
7
|
}
|
|
8
|
-
function filterComponents(components, filterFn) {
|
|
9
|
-
return components.filter(filterFn).map((component) => {
|
|
10
|
-
return {
|
|
11
|
-
...component,
|
|
12
|
-
...(isNestableComponent(component) && {
|
|
13
|
-
components: filterComponents(component.components, filterFn),
|
|
14
|
-
}),
|
|
15
|
-
};
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
exports.filterComponents = filterComponents;
|
|
19
8
|
function flattenComponents(components) {
|
|
20
9
|
return components.flatMap((component) => isNestableComponent(component)
|
|
21
10
|
? [component, ...flattenComponents(component.components)]
|
|
22
11
|
: [component]);
|
|
23
12
|
}
|
|
24
|
-
function getCalloutComponents(callout) {
|
|
25
|
-
return callout.slides.flatMap((slide) => flattenComponents(slide.components));
|
|
26
|
-
}
|
|
27
|
-
exports.getCalloutComponents = getCalloutComponents;
|
|
28
13
|
function convertValuesToOptions(values) {
|
|
29
14
|
return values.map(({ value, label }) => value);
|
|
30
15
|
}
|
|
@@ -57,13 +42,6 @@ function convertComponentToFilter(component) {
|
|
|
57
42
|
return { ...baseItem, type: "text" };
|
|
58
43
|
}
|
|
59
44
|
}
|
|
60
|
-
function convertComponentsToFilters(components) {
|
|
61
|
-
const items = components.map((c) => {
|
|
62
|
-
return [`answers.${c.key}`, convertComponentToFilter(c)];
|
|
63
|
-
});
|
|
64
|
-
return Object.fromEntries(items);
|
|
65
|
-
}
|
|
66
|
-
exports.convertComponentsToFilters = convertComponentsToFilters;
|
|
67
45
|
function getNiceAnswer(component, value) {
|
|
68
46
|
switch (component.type) {
|
|
69
47
|
case "radio":
|
|
@@ -75,6 +53,33 @@ function getNiceAnswer(component, value) {
|
|
|
75
53
|
return value;
|
|
76
54
|
}
|
|
77
55
|
}
|
|
56
|
+
function filterComponents(components, filterFn) {
|
|
57
|
+
return components.filter(filterFn).map((component) => {
|
|
58
|
+
return {
|
|
59
|
+
...component,
|
|
60
|
+
...(isNestableComponent(component) && {
|
|
61
|
+
components: filterComponents(component.components, filterFn),
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exports.filterComponents = filterComponents;
|
|
67
|
+
function getCalloutComponents(formSchema) {
|
|
68
|
+
return formSchema.slides.flatMap((slide) => flattenComponents(slide.components));
|
|
69
|
+
}
|
|
70
|
+
exports.getCalloutComponents = getCalloutComponents;
|
|
71
|
+
function getCalloutFilters(formSchema) {
|
|
72
|
+
const items = formSchema.slides.flatMap((slide) => {
|
|
73
|
+
return slide.components.map((c) => {
|
|
74
|
+
return [
|
|
75
|
+
`answers.${slide.id}.${c.key}`,
|
|
76
|
+
convertComponentToFilter(c),
|
|
77
|
+
];
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
return Object.fromEntries(items);
|
|
81
|
+
}
|
|
82
|
+
exports.getCalloutFilters = getCalloutFilters;
|
|
78
83
|
function isAddressAnswer(answer) {
|
|
79
84
|
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
80
85
|
}
|
|
@@ -2,24 +2,11 @@ function isNestableComponent(component) {
|
|
|
2
2
|
// Addresses have embedded components we don't want to include
|
|
3
3
|
return "components" in component && component.type !== "address";
|
|
4
4
|
}
|
|
5
|
-
export function filterComponents(components, filterFn) {
|
|
6
|
-
return components.filter(filterFn).map((component) => {
|
|
7
|
-
return {
|
|
8
|
-
...component,
|
|
9
|
-
...(isNestableComponent(component) && {
|
|
10
|
-
components: filterComponents(component.components, filterFn),
|
|
11
|
-
}),
|
|
12
|
-
};
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
5
|
function flattenComponents(components) {
|
|
16
6
|
return components.flatMap((component) => isNestableComponent(component)
|
|
17
7
|
? [component, ...flattenComponents(component.components)]
|
|
18
8
|
: [component]);
|
|
19
9
|
}
|
|
20
|
-
export function getCalloutComponents(callout) {
|
|
21
|
-
return callout.slides.flatMap((slide) => flattenComponents(slide.components));
|
|
22
|
-
}
|
|
23
10
|
function convertValuesToOptions(values) {
|
|
24
11
|
return values.map(({ value, label }) => value);
|
|
25
12
|
}
|
|
@@ -52,12 +39,6 @@ function convertComponentToFilter(component) {
|
|
|
52
39
|
return { ...baseItem, type: "text" };
|
|
53
40
|
}
|
|
54
41
|
}
|
|
55
|
-
export function convertComponentsToFilters(components) {
|
|
56
|
-
const items = components.map((c) => {
|
|
57
|
-
return [`answers.${c.key}`, convertComponentToFilter(c)];
|
|
58
|
-
});
|
|
59
|
-
return Object.fromEntries(items);
|
|
60
|
-
}
|
|
61
42
|
function getNiceAnswer(component, value) {
|
|
62
43
|
switch (component.type) {
|
|
63
44
|
case "radio":
|
|
@@ -69,6 +50,30 @@ function getNiceAnswer(component, value) {
|
|
|
69
50
|
return value;
|
|
70
51
|
}
|
|
71
52
|
}
|
|
53
|
+
export function filterComponents(components, filterFn) {
|
|
54
|
+
return components.filter(filterFn).map((component) => {
|
|
55
|
+
return {
|
|
56
|
+
...component,
|
|
57
|
+
...(isNestableComponent(component) && {
|
|
58
|
+
components: filterComponents(component.components, filterFn),
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function getCalloutComponents(formSchema) {
|
|
64
|
+
return formSchema.slides.flatMap((slide) => flattenComponents(slide.components));
|
|
65
|
+
}
|
|
66
|
+
export function getCalloutFilters(formSchema) {
|
|
67
|
+
const items = formSchema.slides.flatMap((slide) => {
|
|
68
|
+
return slide.components.map((c) => {
|
|
69
|
+
return [
|
|
70
|
+
`answers.${slide.id}.${c.key}`,
|
|
71
|
+
convertComponentToFilter(c),
|
|
72
|
+
];
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
return Object.fromEntries(items);
|
|
76
|
+
}
|
|
72
77
|
export function isAddressAnswer(answer) {
|
|
73
78
|
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
74
79
|
}
|
|
@@ -2,8 +2,8 @@ import { CalloutComponentSchema, CalloutFormSchema, CalloutResponseAnswer } from
|
|
|
2
2
|
import { FilterArgs } from "../search";
|
|
3
3
|
import { CalloutResponseAnswerAddress, CalloutResponseAnswerFileUpload } from "../data/callouts";
|
|
4
4
|
export declare function filterComponents(components: CalloutComponentSchema[], filterFn: (component: CalloutComponentSchema) => boolean): CalloutComponentSchema[];
|
|
5
|
-
export declare function getCalloutComponents(
|
|
6
|
-
export declare function
|
|
5
|
+
export declare function getCalloutComponents(formSchema: CalloutFormSchema): CalloutComponentSchema[];
|
|
6
|
+
export declare function getCalloutFilters(formSchema: CalloutFormSchema): Record<string, FilterArgs & {
|
|
7
7
|
label: string;
|
|
8
8
|
}>;
|
|
9
9
|
export declare function isAddressAnswer(answer: CalloutResponseAnswer): answer is CalloutResponseAnswerAddress;
|