@beabee/beabee-common 1.18.0-alpha.4 → 1.18.0-alpha.6

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,15 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stringifyAnswer = exports.isFileUploadAnswer = exports.isAddressAnswer = exports.getCalloutFilters = exports.getCalloutComponents = exports.filterComponents = void 0;
3
+ exports.stringifyAnswer = exports.isFileUploadAnswer = exports.isAddressAnswer = exports.getCalloutFilters = exports.getCalloutComponents = exports.filterComponents = exports.flattenComponents = 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 flattenComponents(components) {
9
- return components.flatMap((component) => isNestableComponent(component)
10
- ? [component, ...flattenComponents(component.components)]
11
- : [component]);
12
- }
13
8
  function convertValuesToOptions(values) {
14
9
  return values.map(({ value, label }) => value);
15
10
  }
@@ -53,6 +48,12 @@ function getNiceAnswer(component, value) {
53
48
  return value;
54
49
  }
55
50
  }
51
+ function flattenComponents(components) {
52
+ return components.flatMap((component) => isNestableComponent(component)
53
+ ? [component, ...flattenComponents(component.components)]
54
+ : [component]);
55
+ }
56
+ exports.flattenComponents = flattenComponents;
56
57
  function filterComponents(components, filterFn) {
57
58
  return components.filter(filterFn).map((component) => {
58
59
  return {
@@ -2,11 +2,6 @@ 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
- function flattenComponents(components) {
6
- return components.flatMap((component) => isNestableComponent(component)
7
- ? [component, ...flattenComponents(component.components)]
8
- : [component]);
9
- }
10
5
  function convertValuesToOptions(values) {
11
6
  return values.map(({ value, label }) => value);
12
7
  }
@@ -50,6 +45,11 @@ function getNiceAnswer(component, value) {
50
45
  return value;
51
46
  }
52
47
  }
48
+ export function flattenComponents(components) {
49
+ return components.flatMap((component) => isNestableComponent(component)
50
+ ? [component, ...flattenComponents(component.components)]
51
+ : [component]);
52
+ }
53
53
  export function filterComponents(components, filterFn) {
54
54
  return components.filter(filterFn).map((component) => {
55
55
  return {
@@ -63,4 +63,7 @@ export interface CalloutResponseAnswerFileUpload {
63
63
  url: string;
64
64
  }
65
65
  export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean> | CalloutResponseAnswerAddress | CalloutResponseAnswerFileUpload;
66
- export type CalloutResponseAnswers = Record<string, CalloutResponseAnswer | CalloutResponseAnswer[]>;
66
+ /**
67
+ * Answers are grouped by slide key: {[slideId]: {[componentKey]: answer | answer[]}}
68
+ */
69
+ export type CalloutResponseAnswers = Record<string, Record<string, CalloutResponseAnswer | CalloutResponseAnswer[]>>;
@@ -1,6 +1,7 @@
1
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 flattenComponents(components: CalloutComponentSchema[]): CalloutComponentSchema[];
4
5
  export declare function filterComponents(components: CalloutComponentSchema[], filterFn: (component: CalloutComponentSchema) => boolean): CalloutComponentSchema[];
5
6
  export declare function getCalloutComponents(formSchema: CalloutFormSchema): CalloutComponentSchema[];
6
7
  export declare function getCalloutFilters(formSchema: CalloutFormSchema): Record<string, FilterArgs & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beabee/beabee-common",
3
- "version": "1.18.0-alpha.4",
3
+ "version": "1.18.0-alpha.6",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",