react-native-my-survey-sdk 3.1.3 → 4.0.0

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 (54) hide show
  1. package/dist/components/XeboDropdownView.d.ts +6 -2
  2. package/dist/components/XeboDropdownView.d.ts.map +1 -1
  3. package/dist/components/XeboDropdownView.js +26 -17
  4. package/dist/components/XeboMultiNPSView.d.ts +4 -2
  5. package/dist/components/XeboMultiNPSView.d.ts.map +1 -1
  6. package/dist/components/XeboMultiNPSView.js +24 -17
  7. package/dist/components/XeboMultiRatingView.d.ts +4 -2
  8. package/dist/components/XeboMultiRatingView.d.ts.map +1 -1
  9. package/dist/components/XeboMultiRatingView.js +23 -16
  10. package/dist/components/XeboMultipleChoiceView.d.ts +6 -2
  11. package/dist/components/XeboMultipleChoiceView.d.ts.map +1 -1
  12. package/dist/components/XeboMultipleChoiceView.js +35 -38
  13. package/dist/components/XeboNPSView.d.ts +8 -2
  14. package/dist/components/XeboNPSView.d.ts.map +1 -1
  15. package/dist/components/XeboNPSView.js +303 -45
  16. package/dist/components/XeboPageView.d.ts +33 -0
  17. package/dist/components/XeboPageView.d.ts.map +1 -0
  18. package/dist/components/XeboPageView.js +190 -0
  19. package/dist/components/XeboRatingView.d.ts +20 -2
  20. package/dist/components/XeboRatingView.d.ts.map +1 -1
  21. package/dist/components/XeboRatingView.js +63 -37
  22. package/dist/components/XeboSingleChoiceView.d.ts +8 -2
  23. package/dist/components/XeboSingleChoiceView.d.ts.map +1 -1
  24. package/dist/components/XeboSingleChoiceView.js +42 -40
  25. package/dist/components/XeboSurveyModal.d.ts.map +1 -1
  26. package/dist/components/XeboSurveyModal.js +151 -35
  27. package/dist/components/XeboTextBoxView.d.ts +4 -2
  28. package/dist/components/XeboTextBoxView.d.ts.map +1 -1
  29. package/dist/components/XeboTextBoxView.js +27 -18
  30. package/dist/core/XeboLanguageService.d.ts.map +1 -1
  31. package/dist/core/XeboLanguageService.js +6 -0
  32. package/dist/core/XeboNetworkService.d.ts +12 -1
  33. package/dist/core/XeboNetworkService.d.ts.map +1 -1
  34. package/dist/core/XeboNetworkService.js +181 -64
  35. package/dist/core/XeboOfflineQueue.d.ts +2 -1
  36. package/dist/core/XeboOfflineQueue.d.ts.map +1 -1
  37. package/dist/core/XeboOfflineQueue.js +24 -10
  38. package/dist/core/XeboSurveyManager.d.ts +16 -1
  39. package/dist/core/XeboSurveyManager.d.ts.map +1 -1
  40. package/dist/core/XeboSurveyManager.js +120 -47
  41. package/dist/i18n/XeboRtl.d.ts +5 -0
  42. package/dist/i18n/XeboRtl.d.ts.map +1 -1
  43. package/dist/i18n/XeboRtl.js +11 -0
  44. package/dist/i18n/XeboStrings.d.ts +6 -0
  45. package/dist/i18n/XeboStrings.d.ts.map +1 -1
  46. package/dist/i18n/XeboStrings.js +19 -5
  47. package/dist/index.d.ts +1 -1
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/models/XeboAPIModels.d.ts +93 -0
  50. package/dist/models/XeboAPIModels.d.ts.map +1 -1
  51. package/dist/models/XeboModels.d.ts +86 -2
  52. package/dist/models/XeboModels.d.ts.map +1 -1
  53. package/dist/models/XeboModels.js +24 -0
  54. package/package.json +3 -4
@@ -1,10 +1,14 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer) => void;
7
+ /** Shown with other questions on one page: no own button. */
8
+ embedded?: boolean;
9
+ /** Fires when an option is picked (drives auto-advance on a shared page). */
10
+ onSelect?: () => void;
7
11
  }
8
- export declare const XeboDropdownView: React.FC<Props>;
12
+ export declare const XeboDropdownView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
13
  export {};
10
14
  //# sourceMappingURL=XeboDropdownView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboDropdownView.d.ts","sourceRoot":"","sources":["../../src/components/XeboDropdownView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAShD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAc,MAAM,sBAAsB,CAAC;AAK5E,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAiH5C,CAAC"}
1
+ {"version":3,"file":"XeboDropdownView.d.ts","sourceRoot":"","sources":["../../src/components/XeboDropdownView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AASjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAc,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAKhG,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAED,eAAO,MAAM,gBAAgB,kFA8H3B,CAAC"}
@@ -39,10 +39,13 @@ const react_native_1 = require("react-native");
39
39
  const XeboTheme_1 = require("../theme/XeboTheme");
40
40
  const XeboStrings_1 = require("../i18n/XeboStrings");
41
41
  const XeboRtl_1 = require("../i18n/XeboRtl");
42
- const XeboDropdownView = ({ question, isLastQuestion, onAnswer }) => {
42
+ exports.XeboDropdownView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, embedded, onSelect }, ref) => {
43
43
  var _a;
44
44
  const theme = (0, XeboTheme_1.getTheme)();
45
- const [selectedChoice, setSelectedChoice] = (0, react_1.useState)(null);
45
+ const [selectedChoice, setSelectedChoice] = (0, react_1.useState)(() => {
46
+ var _a, _b;
47
+ return (_b = (_a = question.options) === null || _a === void 0 ? void 0 : _a.find(o => { var _a, _b, _c, _d; return o.id === ((_c = (_b = (_a = question.previousAnswer) === null || _a === void 0 ? void 0 : _a.value[0]) === null || _b === void 0 ? void 0 : _b.rowId) !== null && _c !== void 0 ? _c : (_d = question.autoSelectOptionIds) === null || _d === void 0 ? void 0 : _d[0]); })) !== null && _b !== void 0 ? _b : null;
48
+ });
46
49
  const [isOpen, setIsOpen] = (0, react_1.useState)(false);
47
50
  const [error, setError] = (0, react_1.useState)('');
48
51
  const shakeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
@@ -58,17 +61,24 @@ const XeboDropdownView = ({ question, isLastQuestion, onAnswer }) => {
58
61
  setSelectedChoice(choice);
59
62
  setIsOpen(false);
60
63
  setError('');
64
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect();
61
65
  };
62
- const handleNext = () => {
66
+ const collect = () => {
63
67
  if (question.isRequired && !selectedChoice) {
64
68
  setError((0, XeboStrings_1.requiredMessage)(question, 'Please select an option.'));
65
69
  shake();
66
- return;
70
+ return null;
67
71
  }
68
- onAnswer({
72
+ return {
69
73
  questionId: question.id,
70
74
  value: selectedChoice ? [{ rowId: selectedChoice.id, text: selectedChoice.text }] : [],
71
- });
75
+ };
76
+ };
77
+ (0, react_1.useImperativeHandle)(ref, () => ({ collect }));
78
+ const handleNext = () => {
79
+ const answer = collect();
80
+ if (answer)
81
+ onAnswer(answer);
72
82
  };
73
83
  return (<react_native_1.View style={styles.container}>
74
84
  <react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
@@ -114,18 +124,17 @@ const XeboDropdownView = ({ question, isLastQuestion, onAnswer }) => {
114
124
 
115
125
  {!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
116
126
 
117
- <react_native_1.TouchableOpacity style={[
118
- styles.button,
119
- { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius },
120
- (question.isRequired && !selectedChoice) && styles.buttonDisabled,
121
- ]} onPress={handleNext} activeOpacity={0.8}>
122
- <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
123
- {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
124
- </react_native_1.Text>
125
- </react_native_1.TouchableOpacity>
127
+ {!embedded && (<react_native_1.TouchableOpacity style={[
128
+ styles.button,
129
+ { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius },
130
+ (question.isRequired && !selectedChoice) && styles.buttonDisabled,
131
+ ]} onPress={handleNext} activeOpacity={0.8}>
132
+ <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
133
+ {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
134
+ </react_native_1.Text>
135
+ </react_native_1.TouchableOpacity>)}
126
136
  </react_native_1.View>);
127
- };
128
- exports.XeboDropdownView = XeboDropdownView;
137
+ });
129
138
  const styles = react_native_1.StyleSheet.create({
130
139
  container: {
131
140
  paddingHorizontal: 20,
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer) => void;
7
+ /** Shown with other questions on one page: no own button, sized to content. */
8
+ embedded?: boolean;
7
9
  }
8
- export declare const XeboMultiNPSView: React.FC<Props>;
10
+ export declare const XeboMultiNPSView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
11
  export {};
10
12
  //# sourceMappingURL=XeboMultiNPSView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboMultiNPSView.d.ts","sourceRoot":"","sources":["../../src/components/XeboMultiNPSView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAShD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKhE,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxC;AAqBD,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAwG5C,CAAC"}
1
+ {"version":3,"file":"XeboMultiNPSView.d.ts","sourceRoot":"","sources":["../../src/components/XeboMultiNPSView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AASjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAmB,MAAM,sBAAsB,CAAC;AAKrG,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAqBD,eAAO,MAAM,gBAAgB,kFAoH3B,CAAC"}
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.XeboMultiNPSView = void 0;
37
37
  const react_1 = __importStar(require("react"));
38
38
  const react_native_1 = require("react-native");
39
+ const XeboModels_1 = require("../models/XeboModels");
39
40
  const XeboTheme_1 = require("../theme/XeboTheme");
40
41
  const XeboStrings_1 = require("../i18n/XeboStrings");
41
42
  const XeboRtl_1 = require("../i18n/XeboRtl");
@@ -59,11 +60,11 @@ function isColorDark(hex) {
59
60
  const b = parseInt(m[3], 16) / 255;
60
61
  return 0.299 * r + 0.587 * g + 0.114 * b < 0.5;
61
62
  }
62
- const XeboMultiNPSView = ({ question, isLastQuestion, onAnswer }) => {
63
+ exports.XeboMultiNPSView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, embedded }, ref) => {
63
64
  var _a;
64
65
  const theme = (0, XeboTheme_1.getTheme)();
65
66
  const rows = (_a = question.options) !== null && _a !== void 0 ? _a : [];
66
- const [scores, setScores] = (0, react_1.useState)({});
67
+ const [scores, setScores] = (0, react_1.useState)(() => (0, XeboModels_1.scaleIndexByRow)(question));
67
68
  const [error, setError] = (0, react_1.useState)('');
68
69
  const shakeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
69
70
  const shake = () => {
@@ -78,13 +79,13 @@ const XeboMultiNPSView = ({ question, isLastQuestion, onAnswer }) => {
78
79
  setScores(prev => (Object.assign(Object.assign({}, prev), { [rowId]: score })));
79
80
  setError('');
80
81
  };
81
- const handleNext = () => {
82
+ const collect = () => {
82
83
  if (question.isRequired && rows.some(r => scores[r.id] === undefined)) {
83
84
  setError((0, XeboStrings_1.requiredMessage)(question, 'Please rate all items.'));
84
85
  shake();
85
- return;
86
+ return null;
86
87
  }
87
- onAnswer({
88
+ return {
88
89
  questionId: question.id,
89
90
  value: rows
90
91
  .filter(r => scores[r.id] !== undefined)
@@ -95,9 +96,15 @@ const XeboMultiNPSView = ({ question, isLastQuestion, onAnswer }) => {
95
96
  colId: ((_c = (_b = (_a = question.columns) === null || _a === void 0 ? void 0 : _a[scores[r.id]]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : scores[r.id].toString()),
96
97
  });
97
98
  }),
98
- });
99
+ };
100
+ };
101
+ (0, react_1.useImperativeHandle)(ref, () => ({ collect }));
102
+ const handleNext = () => {
103
+ const answer = collect();
104
+ if (answer)
105
+ onAnswer(answer);
99
106
  };
100
- return (<react_native_1.View style={styles.container}>
107
+ return (<react_native_1.View style={[styles.container, embedded && styles.embedded]}>
101
108
  <react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
102
109
  {question.title}
103
110
  </react_native_1.Text>
@@ -105,7 +112,7 @@ const XeboMultiNPSView = ({ question, isLastQuestion, onAnswer }) => {
105
112
  {question.subtitle}
106
113
  </react_native_1.Text>)}
107
114
 
108
- <react_native_1.ScrollView style={styles.scroll} showsVerticalScrollIndicator={false}>
115
+ <react_native_1.ScrollView style={[styles.scroll, embedded && styles.embedded]} scrollEnabled={!embedded} showsVerticalScrollIndicator={false}>
109
116
  {rows.map(row => (<react_native_1.View key={row.id} style={styles.rowWrap}>
110
117
  <react_native_1.Text style={[styles.rowLabel, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
111
118
  {row.text}
@@ -137,18 +144,18 @@ const XeboMultiNPSView = ({ question, isLastQuestion, onAnswer }) => {
137
144
 
138
145
  {!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
139
146
 
140
- <react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
141
- <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
142
- <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
143
- {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
144
- </react_native_1.Text>
145
- </react_native_1.TouchableOpacity>
146
- </react_native_1.Animated.View>
147
+ {!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
148
+ <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
149
+ <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
150
+ {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
151
+ </react_native_1.Text>
152
+ </react_native_1.TouchableOpacity>
153
+ </react_native_1.Animated.View>)}
147
154
  </react_native_1.View>);
148
- };
149
- exports.XeboMultiNPSView = XeboMultiNPSView;
155
+ });
150
156
  const styles = react_native_1.StyleSheet.create({
151
157
  container: { flex: 1, paddingHorizontal: 20, paddingTop: 16, paddingBottom: 10 },
158
+ embedded: { flex: 0 },
152
159
  title: { fontSize: 18, fontWeight: '700', marginBottom: 6 },
153
160
  subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
154
161
  scroll: { flex: 1, minHeight: 0, marginBottom: 12 },
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer) => void;
7
+ /** Shown with other questions on one page: no own button, sized to content. */
8
+ embedded?: boolean;
7
9
  }
8
- export declare const XeboMultiRatingView: React.FC<Props>;
10
+ export declare const XeboMultiRatingView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
11
  export {};
10
12
  //# sourceMappingURL=XeboMultiRatingView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboMultiRatingView.d.ts","sourceRoot":"","sources":["../../src/components/XeboMultiRatingView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAShD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKhE,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA2H/C,CAAC"}
1
+ {"version":3,"file":"XeboMultiRatingView.d.ts","sourceRoot":"","sources":["../../src/components/XeboMultiRatingView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AASjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAmB,MAAM,sBAAsB,CAAC;AAKrG,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,mBAAmB,kFAuI9B,CAAC"}
@@ -36,17 +36,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.XeboMultiRatingView = void 0;
37
37
  const react_1 = __importStar(require("react"));
38
38
  const react_native_1 = require("react-native");
39
+ const XeboModels_1 = require("../models/XeboModels");
39
40
  const XeboTheme_1 = require("../theme/XeboTheme");
40
41
  const XeboStrings_1 = require("../i18n/XeboStrings");
41
42
  const XeboRtl_1 = require("../i18n/XeboRtl");
42
- const XeboMultiRatingView = ({ question, isLastQuestion, onAnswer }) => {
43
+ exports.XeboMultiRatingView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, embedded }, ref) => {
43
44
  var _a, _b, _c, _d, _e;
44
45
  const theme = (0, XeboTheme_1.getTheme)();
45
46
  const rows = (_a = question.options) !== null && _a !== void 0 ? _a : [];
46
47
  const totalSteps = (_c = (_b = question.columns) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 5;
47
48
  const ratingColor = (_d = question.ratingColor) !== null && _d !== void 0 ? _d : theme.primaryColor;
48
49
  const ratingStyle = (_e = question.ratingStyle) !== null && _e !== void 0 ? _e : 'star';
49
- const [ratings, setRatings] = (0, react_1.useState)({});
50
+ const [ratings, setRatings] = (0, react_1.useState)(() => (0, XeboModels_1.scaleIndexByRow)(question));
50
51
  const [error, setError] = (0, react_1.useState)('');
51
52
  const shakeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
52
53
  const shake = () => {
@@ -62,13 +63,13 @@ const XeboMultiRatingView = ({ question, isLastQuestion, onAnswer }) => {
62
63
  setError('');
63
64
  };
64
65
  const isCumulative = ratingStyle === 'star' || ratingStyle === 'heart';
65
- const handleNext = () => {
66
+ const collect = () => {
66
67
  if (question.isRequired && rows.some(r => ratings[r.id] === undefined)) {
67
68
  setError((0, XeboStrings_1.requiredMessage)(question, 'Please rate all items.'));
68
69
  shake();
69
- return;
70
+ return null;
70
71
  }
71
- onAnswer({
72
+ return {
72
73
  questionId: question.id,
73
74
  value: rows
74
75
  .filter(r => ratings[r.id] !== undefined)
@@ -79,7 +80,13 @@ const XeboMultiRatingView = ({ question, isLastQuestion, onAnswer }) => {
79
80
  colId: (_c = (_b = (_a = question.columns) === null || _a === void 0 ? void 0 : _a[ratings[r.id]]) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : ratings[r.id].toString(),
80
81
  });
81
82
  }),
82
- });
83
+ };
84
+ };
85
+ (0, react_1.useImperativeHandle)(ref, () => ({ collect }));
86
+ const handleNext = () => {
87
+ const answer = collect();
88
+ if (answer)
89
+ onAnswer(answer);
83
90
  };
84
91
  const starIcon = (filled) => ratingStyle === 'heart' ? (filled ? '♥' : '♡') : filled ? '★' : '☆';
85
92
  return (<react_native_1.View style={styles.container}>
@@ -90,7 +97,7 @@ const XeboMultiRatingView = ({ question, isLastQuestion, onAnswer }) => {
90
97
  {question.subtitle}
91
98
  </react_native_1.Text>)}
92
99
 
93
- <react_native_1.ScrollView style={styles.scroll} showsVerticalScrollIndicator={false}>
100
+ <react_native_1.ScrollView style={[styles.scroll, embedded && styles.embeddedScroll]} scrollEnabled={!embedded} showsVerticalScrollIndicator={false}>
94
101
  {rows.map(row => (<react_native_1.View key={row.id} style={styles.rowWrap}>
95
102
  <react_native_1.Text style={[styles.rowLabel, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
96
103
  {row.text}
@@ -122,21 +129,21 @@ const XeboMultiRatingView = ({ question, isLastQuestion, onAnswer }) => {
122
129
 
123
130
  {!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
124
131
 
125
- <react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
126
- <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
127
- <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
128
- {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
129
- </react_native_1.Text>
130
- </react_native_1.TouchableOpacity>
131
- </react_native_1.Animated.View>
132
+ {!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
133
+ <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
134
+ <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
135
+ {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
136
+ </react_native_1.Text>
137
+ </react_native_1.TouchableOpacity>
138
+ </react_native_1.Animated.View>)}
132
139
  </react_native_1.View>);
133
- };
134
- exports.XeboMultiRatingView = XeboMultiRatingView;
140
+ });
135
141
  const styles = react_native_1.StyleSheet.create({
136
142
  container: { paddingHorizontal: 20, paddingTop: 16, paddingBottom: 10 },
137
143
  title: { fontSize: 18, fontWeight: '700', marginBottom: 16 },
138
144
  subtitle: { fontSize: 14, opacity: 0.6, marginBottom: 16 },
139
145
  scroll: { maxHeight: 280, marginBottom: 12 },
146
+ embeddedScroll: { maxHeight: undefined },
140
147
  rowWrap: { marginBottom: 24 },
141
148
  rowLabel: { fontSize: 15, fontWeight: '500', marginBottom: 8 },
142
149
  iconsRow: { flexDirection: 'row', flexWrap: 'nowrap', justifyContent: 'space-between' },
@@ -1,10 +1,14 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer) => void;
7
+ /** Reports how much taller (or shorter) the sheet must be to fit every option without scrolling. */
8
+ onFitHeight?: (delta: number) => void;
9
+ /** Shown with other questions on one page: no own button, sized to content. */
10
+ embedded?: boolean;
7
11
  }
8
- export declare const XeboMultipleChoiceView: React.FC<Props>;
12
+ export declare const XeboMultipleChoiceView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
13
  export {};
10
14
  //# sourceMappingURL=XeboMultipleChoiceView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboMultipleChoiceView.d.ts","sourceRoot":"","sources":["../../src/components/XeboMultipleChoiceView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAShD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAc,MAAM,sBAAsB,CAAC;AAK5E,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;CACxC;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAqGlD,CAAC"}
1
+ {"version":3,"file":"XeboMultipleChoiceView.d.ts","sourceRoot":"","sources":["../../src/components/XeboMultipleChoiceView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AASjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAc,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAKhG,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACvC,oGAAoG;IACpG,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,eAAO,MAAM,sBAAsB,kFAkHjC,CAAC"}
@@ -39,10 +39,16 @@ const react_native_1 = require("react-native");
39
39
  const XeboTheme_1 = require("../theme/XeboTheme");
40
40
  const XeboStrings_1 = require("../i18n/XeboStrings");
41
41
  const XeboRtl_1 = require("../i18n/XeboRtl");
42
- const XeboMultipleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
42
+ exports.XeboMultipleChoiceView = (0, react_1.forwardRef)(({ question, isLastQuestion, onAnswer, onFitHeight, embedded }, ref) => {
43
43
  var _a;
44
44
  const theme = (0, XeboTheme_1.getTheme)();
45
- const [selectedIds, setSelectedIds] = (0, react_1.useState)(new Set());
45
+ const listHeights = (0, react_1.useRef)({ layout: 0, content: 0 });
46
+ const reportFit = () => {
47
+ const { layout, content } = listHeights.current;
48
+ if (layout > 0 && content > 0)
49
+ onFitHeight === null || onFitHeight === void 0 ? void 0 : onFitHeight(content - layout);
50
+ };
51
+ const [selectedIds, setSelectedIds] = (0, react_1.useState)(() => new Set(question.previousAnswer ? question.previousAnswer.value.map(v => v.rowId) : question.autoSelectOptionIds));
46
52
  const [error, setError] = (0, react_1.useState)('');
47
53
  const shakeAnim = (0, react_1.useRef)(new react_native_1.Animated.Value(0)).current;
48
54
  const shake = () => {
@@ -66,13 +72,13 @@ const XeboMultipleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
66
72
  });
67
73
  setError('');
68
74
  };
69
- const handleNext = () => {
75
+ const collect = () => {
70
76
  if (question.isRequired && selectedIds.size === 0) {
71
77
  setError((0, XeboStrings_1.requiredMessage)(question, 'Please select at least one option.'));
72
78
  shake();
73
- return;
79
+ return null;
74
80
  }
75
- onAnswer({
81
+ return {
76
82
  questionId: question.id,
77
83
  value: Array.from(selectedIds).map(id => {
78
84
  var _a, _b;
@@ -81,9 +87,15 @@ const XeboMultipleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
81
87
  text: (_b = (_a = question.options) === null || _a === void 0 ? void 0 : _a.find((o) => o.id === id)) === null || _b === void 0 ? void 0 : _b.text,
82
88
  });
83
89
  }),
84
- });
90
+ };
91
+ };
92
+ (0, react_1.useImperativeHandle)(ref, () => ({ collect }));
93
+ const handleNext = () => {
94
+ const answer = collect();
95
+ if (answer)
96
+ onAnswer(answer);
85
97
  };
86
- return (<react_native_1.View style={styles.container}>
98
+ return (<react_native_1.View style={[styles.container, embedded && styles.embedded]}>
87
99
  <react_native_1.Text style={[styles.title, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
88
100
  {question.title}
89
101
  </react_native_1.Text>
@@ -91,41 +103,34 @@ const XeboMultipleChoiceView = ({ question, isLastQuestion, onAnswer }) => {
91
103
  {question.subtitle}
92
104
  </react_native_1.Text>)}
93
105
 
94
- <react_native_1.ScrollView style={styles.optionsList} showsVerticalScrollIndicator={false}>
106
+ <react_native_1.ScrollView style={[styles.optionsList, embedded && styles.embedded]} scrollEnabled={!embedded} showsVerticalScrollIndicator={false} onLayout={e => { listHeights.current.layout = e.nativeEvent.layout.height; reportFit(); }} onContentSizeChange={(_, h) => { listHeights.current.content = h; reportFit(); }}>
95
107
  {((_a = question.options) !== null && _a !== void 0 ? _a : []).map((choice) => {
96
108
  const selected = selectedIds.has(choice.id);
97
109
  return (<react_native_1.TouchableOpacity key={choice.id} style={[
98
110
  styles.optionRow,
99
- { borderColor: selected ? theme.primaryColor : '#E5E7EB' },
111
+ selected
112
+ ? { borderColor: theme.primaryColor, backgroundColor: '#F3F4F6' }
113
+ : { borderColor: '#E5E7EB' },
100
114
  ]} onPress={() => toggleChoice(choice)} activeOpacity={0.7}>
101
- <react_native_1.View style={[
102
- styles.checkbox,
103
- {
104
- borderColor: selected ? theme.primaryColor : '#9CA3AF',
105
- backgroundColor: selected ? theme.primaryColor : 'transparent',
106
- },
107
- ]}>
108
- {selected && <react_native_1.Text style={styles.checkmark}>✓</react_native_1.Text>}
109
- </react_native_1.View>
110
115
  <react_native_1.Text style={[styles.optionText, { color: theme.textColor, fontFamily: theme.fontFamily }, (0, XeboRtl_1.rtlText)()]}>
111
116
  {choice.text}
112
117
  </react_native_1.Text>
118
+ {selected && <react_native_1.Text style={[styles.checkmark, { color: theme.primaryColor }]}>✓</react_native_1.Text>}
113
119
  </react_native_1.TouchableOpacity>);
114
120
  })}
115
121
  </react_native_1.ScrollView>
116
122
 
117
123
  {!!error && <react_native_1.Text style={[styles.errorText, (0, XeboRtl_1.rtlText)()]}>{error}</react_native_1.Text>}
118
124
 
119
- <react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
120
- <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
121
- <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
122
- {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
123
- </react_native_1.Text>
124
- </react_native_1.TouchableOpacity>
125
- </react_native_1.Animated.View>
125
+ {!embedded && (<react_native_1.Animated.View style={{ transform: [{ translateX: shakeAnim }] }}>
126
+ <react_native_1.TouchableOpacity style={[styles.button, { backgroundColor: theme.primaryColor, borderRadius: theme.cornerRadius }]} onPress={handleNext} activeOpacity={0.8}>
127
+ <react_native_1.Text style={[styles.buttonText, { fontFamily: theme.fontFamily }]}>
128
+ {(0, XeboStrings_1.actionLabel)(isLastQuestion)}
129
+ </react_native_1.Text>
130
+ </react_native_1.TouchableOpacity>
131
+ </react_native_1.Animated.View>)}
126
132
  </react_native_1.View>);
127
- };
128
- exports.XeboMultipleChoiceView = XeboMultipleChoiceView;
133
+ });
129
134
  const styles = react_native_1.StyleSheet.create({
130
135
  container: {
131
136
  flex: 1,
@@ -133,6 +138,7 @@ const styles = react_native_1.StyleSheet.create({
133
138
  paddingTop: 16,
134
139
  paddingBottom: 10,
135
140
  },
141
+ embedded: { flex: 0 },
136
142
  title: {
137
143
  fontSize: 18,
138
144
  fontWeight: '700',
@@ -155,19 +161,10 @@ const styles = react_native_1.StyleSheet.create({
155
161
  padding: 14,
156
162
  marginBottom: 10,
157
163
  },
158
- checkbox: {
159
- width: 20,
160
- height: 20,
161
- borderRadius: 4,
162
- borderWidth: 2,
163
- alignItems: 'center',
164
- justifyContent: 'center',
165
- marginEnd: 12,
166
- },
167
164
  checkmark: {
168
- color: '#FFFFFF',
169
- fontSize: 13,
165
+ fontSize: 16,
170
166
  fontWeight: '700',
167
+ marginStart: 12,
171
168
  },
172
169
  optionText: {
173
170
  fontSize: 15,
@@ -1,10 +1,16 @@
1
1
  import React from 'react';
2
- import { XeboQuestion, XeboAnswer } from '../models/XeboModels';
2
+ import { XeboQuestion, XeboAnswer, XeboQuestionHandle } from '../models/XeboModels';
3
3
  interface Props {
4
4
  question: XeboQuestion;
5
5
  isLastQuestion: boolean;
6
6
  onAnswer: (answer: XeboAnswer | XeboAnswer[]) => void;
7
+ /** Reports how much taller (or shorter) the sheet must be to fit the content without a gap. */
8
+ onFitHeight?: (delta: number) => void;
9
+ /** Shown with other questions on one page: no own button, sized to content. */
10
+ embedded?: boolean;
11
+ /** Fires when a score is picked (drives auto-advance on a shared page). */
12
+ onSelect?: () => void;
7
13
  }
8
- export declare const XeboNPSView: React.FC<Props>;
14
+ export declare const XeboNPSView: React.ForwardRefExoticComponent<Props & React.RefAttributes<XeboQuestionHandle>>;
9
15
  export {};
10
16
  //# sourceMappingURL=XeboNPSView.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"XeboNPSView.d.ts","sourceRoot":"","sources":["../../src/components/XeboNPSView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2B,MAAM,OAAO,CAAC;AAWhD,OAAO,EAAE,YAAY,EAAE,UAAU,EAA6C,MAAM,sBAAsB,CAAC;AAK3G,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,KAAK,IAAI,CAAC;CACvD;AAuBD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAsNvC,CAAC"}
1
+ {"version":3,"file":"XeboNPSView.d.ts","sourceRoot":"","sources":["../../src/components/XeboNPSView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA4D,MAAM,OAAO,CAAC;AAYjF,OAAO,EAAE,YAAY,EAAE,UAAU,EAA6C,kBAAkB,EAAc,MAAM,sBAAsB,CAAC;AAM3I,UAAU,KAAK;IACb,QAAQ,EAAE,YAAY,CAAC;IACvB,cAAc,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,EAAE,KAAK,IAAI,CAAC;IACtD,+FAA+F;IAC/F,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtC,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB;AAyDD,eAAO,MAAM,WAAW,kFAydtB,CAAC"}