@beabee/beabee-common 1.17.1 → 1.18.0-alpha.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/dist/cjs/search/callouts.js +2 -0
- package/dist/cjs/search/contacts.js +1 -0
- package/dist/cjs/utils/callouts.js +37 -4
- package/dist/esm/search/callouts.js +2 -0
- package/dist/esm/search/contacts.js +1 -0
- package/dist/esm/utils/callouts.js +33 -3
- package/dist/types/data/callouts.d.ts +23 -14
- package/dist/types/search/callouts.d.ts +2 -0
- package/dist/types/search/contacts.d.ts +1 -0
- package/dist/types/utils/callouts.d.ts +7 -3
- package/package.json +1 -1
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringifyAnswer = exports.convertComponentsToFilters = exports.
|
|
3
|
+
exports.stringifyAnswer = exports.isFileUploadAnswer = exports.isAddressAnswer = exports.convertComponentsToFilters = exports.getCalloutComponents = exports.filterComponents = void 0;
|
|
4
4
|
function isNestableComponent(component) {
|
|
5
|
-
|
|
5
|
+
// Addresses have embedded components we don't want to include
|
|
6
|
+
return "components" in component && component.type !== "address";
|
|
6
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;
|
|
7
19
|
function flattenComponents(components) {
|
|
8
20
|
return components.flatMap((component) => isNestableComponent(component)
|
|
9
21
|
? [component, ...flattenComponents(component.components)]
|
|
10
22
|
: [component]);
|
|
11
23
|
}
|
|
12
|
-
|
|
24
|
+
function getCalloutComponents(callout) {
|
|
25
|
+
return callout.slides.flatMap((slide) => flattenComponents(slide.components));
|
|
26
|
+
}
|
|
27
|
+
exports.getCalloutComponents = getCalloutComponents;
|
|
13
28
|
function convertValuesToOptions(values) {
|
|
14
29
|
return values.map(({ value, label }) => value);
|
|
15
30
|
}
|
|
@@ -60,11 +75,29 @@ function getNiceAnswer(component, value) {
|
|
|
60
75
|
return value;
|
|
61
76
|
}
|
|
62
77
|
}
|
|
78
|
+
function isAddressAnswer(answer) {
|
|
79
|
+
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
80
|
+
}
|
|
81
|
+
exports.isAddressAnswer = isAddressAnswer;
|
|
82
|
+
function isFileUploadAnswer(answer) {
|
|
83
|
+
return !!answer && typeof answer === "object" && "url" in answer;
|
|
84
|
+
}
|
|
85
|
+
exports.isFileUploadAnswer = isFileUploadAnswer;
|
|
63
86
|
function stringifyAnswer(component, answer) {
|
|
64
|
-
if (
|
|
87
|
+
if (Array.isArray(answer)) {
|
|
88
|
+
return answer.map((a) => stringifyAnswer(component, a)).join(", ");
|
|
89
|
+
}
|
|
90
|
+
else if (!answer) {
|
|
65
91
|
return "";
|
|
66
92
|
}
|
|
93
|
+
else if (isAddressAnswer(answer)) {
|
|
94
|
+
return answer.formatted_address;
|
|
95
|
+
}
|
|
96
|
+
else if (isFileUploadAnswer(answer)) {
|
|
97
|
+
return answer.url;
|
|
98
|
+
}
|
|
67
99
|
else if (typeof answer === "object") {
|
|
100
|
+
// Checkboxes
|
|
68
101
|
return Object.entries(answer)
|
|
69
102
|
.filter(([, selected]) => selected)
|
|
70
103
|
.map(([value]) => getNiceAnswer(component, value))
|
|
@@ -1,11 +1,25 @@
|
|
|
1
1
|
function isNestableComponent(component) {
|
|
2
|
-
|
|
2
|
+
// Addresses have embedded components we don't want to include
|
|
3
|
+
return "components" in component && component.type !== "address";
|
|
3
4
|
}
|
|
4
|
-
export function
|
|
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
|
+
function flattenComponents(components) {
|
|
5
16
|
return components.flatMap((component) => isNestableComponent(component)
|
|
6
17
|
? [component, ...flattenComponents(component.components)]
|
|
7
18
|
: [component]);
|
|
8
19
|
}
|
|
20
|
+
export function getCalloutComponents(callout) {
|
|
21
|
+
return callout.slides.flatMap((slide) => flattenComponents(slide.components));
|
|
22
|
+
}
|
|
9
23
|
function convertValuesToOptions(values) {
|
|
10
24
|
return values.map(({ value, label }) => value);
|
|
11
25
|
}
|
|
@@ -55,11 +69,27 @@ function getNiceAnswer(component, value) {
|
|
|
55
69
|
return value;
|
|
56
70
|
}
|
|
57
71
|
}
|
|
72
|
+
export function isAddressAnswer(answer) {
|
|
73
|
+
return !!answer && typeof answer === "object" && "geometry" in answer;
|
|
74
|
+
}
|
|
75
|
+
export function isFileUploadAnswer(answer) {
|
|
76
|
+
return !!answer && typeof answer === "object" && "url" in answer;
|
|
77
|
+
}
|
|
58
78
|
export function stringifyAnswer(component, answer) {
|
|
59
|
-
if (
|
|
79
|
+
if (Array.isArray(answer)) {
|
|
80
|
+
return answer.map((a) => stringifyAnswer(component, a)).join(", ");
|
|
81
|
+
}
|
|
82
|
+
else if (!answer) {
|
|
60
83
|
return "";
|
|
61
84
|
}
|
|
85
|
+
else if (isAddressAnswer(answer)) {
|
|
86
|
+
return answer.formatted_address;
|
|
87
|
+
}
|
|
88
|
+
else if (isFileUploadAnswer(answer)) {
|
|
89
|
+
return answer.url;
|
|
90
|
+
}
|
|
62
91
|
else if (typeof answer === "object") {
|
|
92
|
+
// Checkboxes
|
|
63
93
|
return Object.entries(answer)
|
|
64
94
|
.filter(([, selected]) => selected)
|
|
65
95
|
.map(([value]) => getNiceAnswer(component, value))
|
|
@@ -2,8 +2,9 @@ export interface BaseCalloutComponentSchema {
|
|
|
2
2
|
id: string;
|
|
3
3
|
type: string;
|
|
4
4
|
key: string;
|
|
5
|
-
label
|
|
6
|
-
input
|
|
5
|
+
label?: string;
|
|
6
|
+
input?: boolean;
|
|
7
|
+
adminOnly?: boolean;
|
|
7
8
|
[key: string]: unknown;
|
|
8
9
|
}
|
|
9
10
|
export interface NestableCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
@@ -12,7 +13,7 @@ export interface NestableCalloutComponentSchema extends BaseCalloutComponentSche
|
|
|
12
13
|
components: CalloutComponentSchema[];
|
|
13
14
|
}
|
|
14
15
|
export interface InputCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
15
|
-
type: "address" | "button" | "checkbox" | "email" | "number" | "password" | "textfield" | "textarea";
|
|
16
|
+
type: "address" | "button" | "checkbox" | "email" | "file" | "number" | "password" | "textfield" | "textarea";
|
|
16
17
|
input: true;
|
|
17
18
|
}
|
|
18
19
|
export interface SelectCalloutComponentSchema extends BaseCalloutComponentSchema {
|
|
@@ -34,22 +35,30 @@ export interface RadioCalloutComponentSchema extends BaseCalloutComponentSchema
|
|
|
34
35
|
}[];
|
|
35
36
|
}
|
|
36
37
|
export type CalloutComponentSchema = SelectCalloutComponentSchema | RadioCalloutComponentSchema | InputCalloutComponentSchema | NestableCalloutComponentSchema;
|
|
37
|
-
export interface CalloutPageSchema extends NestableCalloutComponentSchema {
|
|
38
|
-
type: "panel";
|
|
39
|
-
title: string;
|
|
40
|
-
navigation: CalloutNavigationSchema;
|
|
41
|
-
}
|
|
42
38
|
export interface CalloutNavigationSchema {
|
|
43
|
-
showPrev: boolean;
|
|
44
|
-
showNext: boolean;
|
|
45
39
|
prevText: string;
|
|
46
40
|
nextText: string;
|
|
47
41
|
nextSlideId: string;
|
|
48
42
|
submitText: string;
|
|
49
43
|
}
|
|
44
|
+
export interface CalloutSlideSchema {
|
|
45
|
+
components: CalloutComponentSchema[];
|
|
46
|
+
navigation: CalloutNavigationSchema;
|
|
47
|
+
}
|
|
50
48
|
export interface CalloutFormSchema {
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
slides: CalloutSlideSchema[];
|
|
50
|
+
}
|
|
51
|
+
export interface CalloutResponseAnswerAddress {
|
|
52
|
+
formatted_address: string;
|
|
53
|
+
geometry: {
|
|
54
|
+
location: {
|
|
55
|
+
lat: number;
|
|
56
|
+
lng: number;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export interface CalloutResponseAnswerFileUpload {
|
|
61
|
+
url: string;
|
|
53
62
|
}
|
|
54
|
-
export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean
|
|
55
|
-
export type CalloutResponseAnswers = Record<string, CalloutResponseAnswer>;
|
|
63
|
+
export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean> | CalloutResponseAnswerAddress | CalloutResponseAnswerFileUpload;
|
|
64
|
+
export type CalloutResponseAnswers = Record<string, CalloutResponseAnswer | CalloutResponseAnswer[]>;
|
|
@@ -12,9 +12,11 @@ export declare const calloutFilters: {
|
|
|
12
12
|
};
|
|
13
13
|
readonly starts: {
|
|
14
14
|
readonly type: "date";
|
|
15
|
+
readonly nullable: true;
|
|
15
16
|
};
|
|
16
17
|
readonly expires: {
|
|
17
18
|
readonly type: "date";
|
|
19
|
+
readonly nullable: true;
|
|
18
20
|
};
|
|
19
21
|
readonly hidden: {
|
|
20
22
|
readonly type: "boolean";
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { CalloutComponentSchema, CalloutResponseAnswer } from "../data/callouts";
|
|
1
|
+
import { CalloutComponentSchema, CalloutFormSchema, CalloutResponseAnswer } from "../data/callouts";
|
|
2
2
|
import { FilterArgs } from "../search";
|
|
3
|
-
|
|
3
|
+
import { CalloutResponseAnswerAddress, CalloutResponseAnswerFileUpload } from "../data/callouts";
|
|
4
|
+
export declare function filterComponents(components: CalloutComponentSchema[], filterFn: (component: CalloutComponentSchema) => boolean): CalloutComponentSchema[];
|
|
5
|
+
export declare function getCalloutComponents(callout: CalloutFormSchema): CalloutComponentSchema[];
|
|
4
6
|
export declare function convertComponentsToFilters(components: CalloutComponentSchema[]): Record<string, FilterArgs & {
|
|
5
7
|
label: string;
|
|
6
8
|
}>;
|
|
7
|
-
export declare function
|
|
9
|
+
export declare function isAddressAnswer(answer: CalloutResponseAnswer): answer is CalloutResponseAnswerAddress;
|
|
10
|
+
export declare function isFileUploadAnswer(answer: CalloutResponseAnswer): answer is CalloutResponseAnswerFileUpload;
|
|
11
|
+
export declare function stringifyAnswer(component: CalloutComponentSchema, answer: CalloutResponseAnswer | CalloutResponseAnswer[]): string;
|