@posthog/browser-common 0.9.5 → 0.9.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.
- package/dist/client.d.ts +6 -0
- package/dist/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +58 -10
- package/dist/index.mjs +1 -0
- package/dist/survey-action-matcher.d.ts +27 -0
- package/dist/survey-action-matcher.js +169 -0
- package/dist/survey-action-matcher.mjs +131 -0
- package/dist/survey-constants.d.ts +86 -0
- package/dist/survey-constants.js +144 -0
- package/dist/survey-constants.mjs +76 -0
- package/dist/survey-event-host.d.ts +15 -0
- package/dist/survey-event-host.js +18 -0
- package/dist/survey-event-host.mjs +1 -0
- package/dist/survey-event-receiver-base.d.ts +180 -0
- package/dist/survey-event-receiver-base.js +354 -0
- package/dist/survey-event-receiver-base.mjs +316 -0
- package/dist/survey-event-receiver.d.ts +36 -0
- package/dist/survey-event-receiver.js +133 -0
- package/dist/survey-event-receiver.mjs +95 -0
- package/dist/survey-render-context.d.ts +13 -0
- package/dist/survey-render-context.js +45 -0
- package/dist/survey-render-context.mjs +7 -0
- package/dist/surveys/components/BottomSection.d.ts +12 -0
- package/dist/surveys/components/BottomSection.js +82 -0
- package/dist/surveys/components/BottomSection.mjs +44 -0
- package/dist/surveys/components/ConfirmationMessage.d.ts +10 -0
- package/dist/surveys/components/ConfirmationMessage.js +92 -0
- package/dist/surveys/components/ConfirmationMessage.mjs +54 -0
- package/dist/surveys/components/IntroScreen.d.ts +10 -0
- package/dist/surveys/components/IntroScreen.js +78 -0
- package/dist/surveys/components/IntroScreen.mjs +40 -0
- package/dist/surveys/components/PostHogLogo.d.ts +5 -0
- package/dist/surveys/components/PostHogLogo.js +54 -0
- package/dist/surveys/components/PostHogLogo.mjs +16 -0
- package/dist/surveys/components/QuestionHeader.d.ts +10 -0
- package/dist/surveys/components/QuestionHeader.js +82 -0
- package/dist/surveys/components/QuestionHeader.mjs +41 -0
- package/dist/surveys/components/QuestionTypes.d.ts +31 -0
- package/dist/surveys/components/QuestionTypes.js +519 -0
- package/dist/surveys/components/QuestionTypes.mjs +469 -0
- package/dist/surveys/icons.d.ts +12 -0
- package/dist/surveys/icons.js +212 -0
- package/dist/surveys/icons.mjs +147 -0
- package/dist/surveys/survey-branching.d.ts +12 -0
- package/dist/surveys/survey-branching.js +101 -0
- package/dist/surveys/survey-branching.mjs +60 -0
- package/dist/surveys/survey-styles.d.ts +1 -0
- package/dist/surveys/survey-styles.js +40 -0
- package/dist/surveys/survey-styles.mjs +2 -0
- package/dist/surveys/survey-translations.d.ts +22 -0
- package/dist/surveys/survey-translations.js +68 -0
- package/dist/surveys/survey-translations.mjs +27 -0
- package/dist/surveys/survey-url-prefill.d.ts +36 -0
- package/dist/surveys/survey-url-prefill.js +162 -0
- package/dist/surveys/survey-url-prefill.mjs +118 -0
- package/dist/surveys/surveys-extension-utils.d.ts +133 -0
- package/dist/surveys/surveys-extension-utils.js +739 -0
- package/dist/surveys/surveys-extension-utils.mjs +608 -0
- package/dist/surveys-config.d.ts +60 -0
- package/dist/surveys-config.js +68 -0
- package/dist/surveys-config.mjs +9 -0
- package/dist/surveys-renderer.d.ts +248 -0
- package/dist/surveys-renderer.js +1299 -0
- package/dist/surveys-renderer.mjs +1230 -0
- package/dist/surveys.d.ts +117 -0
- package/dist/surveys.js +566 -0
- package/dist/surveys.mjs +495 -0
- package/dist/types/surveys.d.ts +83 -86
- package/dist/types/surveys.js +1 -127
- package/dist/types/surveys.mjs +1 -76
- package/dist/utils/autocapture-utils.js +8 -9
- package/dist/utils/autocapture-utils.mjs +8 -9
- package/dist/utils/matcher-utils.d.ts +1 -1
- package/dist/utils/matcher-utils.js +13 -10
- package/dist/utils/matcher-utils.mjs +10 -7
- package/dist/utils/survey-utils.d.ts +16 -0
- package/dist/utils/survey-utils.js +121 -0
- package/dist/utils/survey-utils.mjs +38 -0
- package/dist/utils/url-targeting-utils.d.ts +3 -1
- package/dist/utils/url-targeting-utils.js +1 -2
- package/dist/utils/url-targeting-utils.mjs +1 -2
- package/dist/utils/uuidv7.js +4 -4
- package/dist/utils/uuidv7.mjs +4 -4
- package/package.json +96 -2
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
LinkQuestion: ()=>LinkQuestion,
|
|
32
|
+
MultipleChoiceQuestion: ()=>MultipleChoiceQuestion,
|
|
33
|
+
OpenTextQuestion: ()=>OpenTextQuestion,
|
|
34
|
+
RatingButton: ()=>RatingButton,
|
|
35
|
+
RatingQuestion: ()=>RatingQuestion
|
|
36
|
+
});
|
|
37
|
+
const jsx_runtime_namespaceObject = require("preact/jsx-runtime");
|
|
38
|
+
const external_preact_namespaceObject = require("preact");
|
|
39
|
+
const hooks_namespaceObject = require("preact/hooks");
|
|
40
|
+
const external_survey_constants_js_namespaceObject = require("../../survey-constants.js");
|
|
41
|
+
const core_namespaceObject = require("@posthog/core");
|
|
42
|
+
const surveys_namespaceObject = require("@posthog/core/surveys");
|
|
43
|
+
const external_icons_js_namespaceObject = require("../icons.js");
|
|
44
|
+
const external_surveys_extension_utils_js_namespaceObject = require("../surveys-extension-utils.js");
|
|
45
|
+
const external_BottomSection_js_namespaceObject = require("./BottomSection.js");
|
|
46
|
+
const external_QuestionHeader_js_namespaceObject = require("./QuestionHeader.js");
|
|
47
|
+
const isValidStringArray = (value)=>(0, core_namespaceObject.isArray)(value) && value.every((item)=>(0, core_namespaceObject.isString)(item));
|
|
48
|
+
const initializeSelectedChoices = (initialValue, questionType)=>{
|
|
49
|
+
if ((0, core_namespaceObject.isString)(initialValue)) return initialValue;
|
|
50
|
+
if (isValidStringArray(initialValue)) return initialValue;
|
|
51
|
+
return questionType === external_survey_constants_js_namespaceObject.SurveyQuestionType.SingleChoice ? null : [];
|
|
52
|
+
};
|
|
53
|
+
const initializeOpenEndedState = (initialValue, choices)=>{
|
|
54
|
+
if ((0, core_namespaceObject.isString)(initialValue) && !choices.includes(initialValue)) return {
|
|
55
|
+
isSelected: true,
|
|
56
|
+
inputValue: initialValue
|
|
57
|
+
};
|
|
58
|
+
if (isValidStringArray(initialValue)) {
|
|
59
|
+
const openEndedValue = initialValue.find((choice)=>!choices.includes(choice));
|
|
60
|
+
if (openEndedValue) return {
|
|
61
|
+
isSelected: true,
|
|
62
|
+
inputValue: openEndedValue
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
isSelected: false,
|
|
67
|
+
inputValue: ''
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
function OpenTextQuestion({ question, forceDisableHtml, appearance, onSubmit, onPreviewSubmit, displayQuestionIndex, initialValue, canGoBack, onBack }) {
|
|
71
|
+
const { isPreviewMode } = (0, external_surveys_extension_utils_js_namespaceObject.useSurveyContext)();
|
|
72
|
+
const inputRef = (0, hooks_namespaceObject.useRef)(null);
|
|
73
|
+
const [text, setText] = (0, hooks_namespaceObject.useState)(()=>{
|
|
74
|
+
if ((0, core_namespaceObject.isString)(initialValue)) return initialValue;
|
|
75
|
+
return '';
|
|
76
|
+
});
|
|
77
|
+
const disableAutofocus = appearance?.disableAutofocus;
|
|
78
|
+
(0, hooks_namespaceObject.useEffect)(()=>{
|
|
79
|
+
if (disableAutofocus) return;
|
|
80
|
+
setTimeout(()=>{
|
|
81
|
+
if (!isPreviewMode) inputRef.current?.focus();
|
|
82
|
+
}, 100);
|
|
83
|
+
}, [
|
|
84
|
+
isPreviewMode,
|
|
85
|
+
disableAutofocus
|
|
86
|
+
]);
|
|
87
|
+
const htmlFor = `surveyQuestion${displayQuestionIndex}`;
|
|
88
|
+
const validationError = (0, hooks_namespaceObject.useMemo)(()=>(0, surveys_namespaceObject.getValidationError)(text, question.validation, question.optional), [
|
|
89
|
+
text,
|
|
90
|
+
question.validation,
|
|
91
|
+
question.optional
|
|
92
|
+
]);
|
|
93
|
+
const minLength = (0, surveys_namespaceObject.getLengthFromRules)(question.validation, core_namespaceObject.SurveyValidationType.MinLength);
|
|
94
|
+
const maxLength = (0, surveys_namespaceObject.getLengthFromRules)(question.validation, core_namespaceObject.SurveyValidationType.MaxLength);
|
|
95
|
+
const requirementsHint = (0, hooks_namespaceObject.useMemo)(()=>(0, surveys_namespaceObject.getRequirementsHint)(minLength, maxLength), [
|
|
96
|
+
minLength,
|
|
97
|
+
maxLength
|
|
98
|
+
]);
|
|
99
|
+
const handleSubmit = ()=>{
|
|
100
|
+
if (validationError) return;
|
|
101
|
+
onSubmit(text.trim());
|
|
102
|
+
};
|
|
103
|
+
const handlePreviewSubmit = ()=>{
|
|
104
|
+
if (validationError) return;
|
|
105
|
+
onPreviewSubmit(text.trim());
|
|
106
|
+
};
|
|
107
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_preact_namespaceObject.Fragment, {
|
|
108
|
+
children: [
|
|
109
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
110
|
+
className: "question-container",
|
|
111
|
+
children: [
|
|
112
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_QuestionHeader_js_namespaceObject.QuestionHeader, {
|
|
113
|
+
question: question,
|
|
114
|
+
forceDisableHtml: forceDisableHtml,
|
|
115
|
+
htmlFor: htmlFor
|
|
116
|
+
}),
|
|
117
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("textarea", {
|
|
118
|
+
ref: inputRef,
|
|
119
|
+
id: htmlFor,
|
|
120
|
+
rows: 4,
|
|
121
|
+
placeholder: appearance?.placeholder,
|
|
122
|
+
minLength: minLength,
|
|
123
|
+
maxLength: maxLength,
|
|
124
|
+
onInput: (e)=>{
|
|
125
|
+
setText(e.currentTarget.value);
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
},
|
|
128
|
+
onKeyDown: (e)=>{
|
|
129
|
+
e.stopPropagation();
|
|
130
|
+
if ('Enter' === e.key && (e.metaKey || e.ctrlKey) && !validationError) {
|
|
131
|
+
e.preventDefault();
|
|
132
|
+
isPreviewMode ? handlePreviewSubmit() : handleSubmit();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
value: text
|
|
136
|
+
}),
|
|
137
|
+
requirementsHint && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
138
|
+
className: "validation-hint",
|
|
139
|
+
children: requirementsHint
|
|
140
|
+
})
|
|
141
|
+
]
|
|
142
|
+
}),
|
|
143
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_BottomSection_js_namespaceObject.BottomSection, {
|
|
144
|
+
text: question.buttonText || 'Submit',
|
|
145
|
+
submitDisabled: !!validationError,
|
|
146
|
+
appearance: appearance,
|
|
147
|
+
onSubmit: handleSubmit,
|
|
148
|
+
onPreviewSubmit: handlePreviewSubmit,
|
|
149
|
+
canGoBack: canGoBack,
|
|
150
|
+
onBack: onBack
|
|
151
|
+
})
|
|
152
|
+
]
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
function LinkQuestion({ question, forceDisableHtml, appearance, onSubmit, onPreviewSubmit, canGoBack, onBack }) {
|
|
156
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_preact_namespaceObject.Fragment, {
|
|
157
|
+
children: [
|
|
158
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
159
|
+
className: "question-container",
|
|
160
|
+
children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_QuestionHeader_js_namespaceObject.QuestionHeader, {
|
|
161
|
+
question: question,
|
|
162
|
+
forceDisableHtml: forceDisableHtml
|
|
163
|
+
})
|
|
164
|
+
}),
|
|
165
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_BottomSection_js_namespaceObject.BottomSection, {
|
|
166
|
+
text: question.buttonText || 'Submit',
|
|
167
|
+
submitDisabled: false,
|
|
168
|
+
link: question.link,
|
|
169
|
+
appearance: appearance,
|
|
170
|
+
onSubmit: ()=>onSubmit('link clicked'),
|
|
171
|
+
onPreviewSubmit: ()=>onPreviewSubmit('link clicked'),
|
|
172
|
+
canGoBack: canGoBack,
|
|
173
|
+
onBack: onBack
|
|
174
|
+
})
|
|
175
|
+
]
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
function RatingQuestion({ question, forceDisableHtml, displayQuestionIndex, appearance, onSubmit, onPreviewSubmit, initialValue, canGoBack, onBack }) {
|
|
179
|
+
const scale = question.scale;
|
|
180
|
+
const starting = 10 === question.scale ? 0 : 1;
|
|
181
|
+
const [rating, setRating] = (0, hooks_namespaceObject.useState)(()=>{
|
|
182
|
+
if ((0, core_namespaceObject.isNumber)(initialValue)) return initialValue;
|
|
183
|
+
if ((0, core_namespaceObject.isArray)(initialValue) && initialValue.length > 0 && (0, core_namespaceObject.isNumber)(parseInt(initialValue[0]))) return parseInt(initialValue[0]);
|
|
184
|
+
if ((0, core_namespaceObject.isString)(initialValue) && (0, core_namespaceObject.isNumber)(parseInt(initialValue))) return parseInt(initialValue);
|
|
185
|
+
return null;
|
|
186
|
+
});
|
|
187
|
+
const isThumbSurvey = 'emoji' === question.display && 2 === question.scale;
|
|
188
|
+
const { isPreviewMode } = (0, external_surveys_extension_utils_js_namespaceObject.useSurveyContext)();
|
|
189
|
+
const handleSubmit = (num)=>{
|
|
190
|
+
if (isPreviewMode) return onPreviewSubmit(num);
|
|
191
|
+
return onSubmit(num);
|
|
192
|
+
};
|
|
193
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_preact_namespaceObject.Fragment, {
|
|
194
|
+
children: [
|
|
195
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
196
|
+
className: "question-container",
|
|
197
|
+
children: [
|
|
198
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_QuestionHeader_js_namespaceObject.QuestionHeader, {
|
|
199
|
+
question: question,
|
|
200
|
+
forceDisableHtml: forceDisableHtml
|
|
201
|
+
}),
|
|
202
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
203
|
+
className: "rating-section",
|
|
204
|
+
children: [
|
|
205
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
206
|
+
className: "rating-options",
|
|
207
|
+
children: [
|
|
208
|
+
'emoji' === question.display && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
209
|
+
className: `rating-options-emoji${isThumbSurvey ? ' rating-options-emoji-2' : ''}`,
|
|
210
|
+
children: emojiScaleLists[question.scale]?.map((emoji, idx)=>{
|
|
211
|
+
const active = idx + 1 === rating;
|
|
212
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
|
|
213
|
+
"aria-label": `Rate ${idx + 1}`,
|
|
214
|
+
className: `ratings-emoji question-${displayQuestionIndex}-rating-${idx} ${active ? 'rating-active' : ''}`,
|
|
215
|
+
value: idx + 1,
|
|
216
|
+
type: "button",
|
|
217
|
+
onClick: ()=>{
|
|
218
|
+
const response = idx + 1;
|
|
219
|
+
setRating(response);
|
|
220
|
+
if (question.skipSubmitButton) handleSubmit(response);
|
|
221
|
+
},
|
|
222
|
+
children: emoji
|
|
223
|
+
}, idx);
|
|
224
|
+
})
|
|
225
|
+
}),
|
|
226
|
+
'number' === question.display && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
227
|
+
className: "rating-options-number",
|
|
228
|
+
style: {
|
|
229
|
+
gridTemplateColumns: `repeat(${scale - starting + 1}, minmax(0, 1fr))`
|
|
230
|
+
},
|
|
231
|
+
children: getScaleNumbers(question.scale).map((number, idx)=>{
|
|
232
|
+
const active = rating === number;
|
|
233
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(RatingButton, {
|
|
234
|
+
displayQuestionIndex: displayQuestionIndex,
|
|
235
|
+
active: active,
|
|
236
|
+
appearance: appearance,
|
|
237
|
+
num: number,
|
|
238
|
+
setActiveNumber: (response)=>{
|
|
239
|
+
setRating(response);
|
|
240
|
+
if (question.skipSubmitButton) handleSubmit(response);
|
|
241
|
+
}
|
|
242
|
+
}, idx);
|
|
243
|
+
})
|
|
244
|
+
})
|
|
245
|
+
]
|
|
246
|
+
}),
|
|
247
|
+
!isThumbSurvey && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
248
|
+
className: "rating-text",
|
|
249
|
+
children: [
|
|
250
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
251
|
+
children: question.lowerBoundLabel
|
|
252
|
+
}),
|
|
253
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
|
|
254
|
+
children: question.upperBoundLabel
|
|
255
|
+
})
|
|
256
|
+
]
|
|
257
|
+
})
|
|
258
|
+
]
|
|
259
|
+
})
|
|
260
|
+
]
|
|
261
|
+
}),
|
|
262
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_BottomSection_js_namespaceObject.BottomSection, {
|
|
263
|
+
text: question.buttonText || appearance?.submitButtonText || 'Submit',
|
|
264
|
+
submitDisabled: (0, core_namespaceObject.isNull)(rating) && !question.optional,
|
|
265
|
+
appearance: appearance,
|
|
266
|
+
onSubmit: ()=>onSubmit(rating),
|
|
267
|
+
onPreviewSubmit: ()=>onPreviewSubmit(rating),
|
|
268
|
+
skipSubmitButton: question.skipSubmitButton,
|
|
269
|
+
canGoBack: canGoBack,
|
|
270
|
+
onBack: onBack
|
|
271
|
+
})
|
|
272
|
+
]
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
function RatingButton({ num, active, displayQuestionIndex, setActiveNumber }) {
|
|
276
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
|
|
277
|
+
"aria-label": `Rate ${num}`,
|
|
278
|
+
className: `ratings-number question-${displayQuestionIndex}-rating-${num} ${active ? 'rating-active' : ''}`,
|
|
279
|
+
type: "button",
|
|
280
|
+
onClick: ()=>{
|
|
281
|
+
setActiveNumber(num);
|
|
282
|
+
},
|
|
283
|
+
children: num
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
function MultipleChoiceQuestion({ question, forceDisableHtml, displayQuestionIndex, appearance, onSubmit, onPreviewSubmit, initialValue, canGoBack, onBack }) {
|
|
287
|
+
const openChoiceInputRef = (0, hooks_namespaceObject.useRef)(null);
|
|
288
|
+
const choices = (0, hooks_namespaceObject.useMemo)(()=>(0, external_surveys_extension_utils_js_namespaceObject.getDisplayOrderChoices)(question), [
|
|
289
|
+
question
|
|
290
|
+
]);
|
|
291
|
+
const [selectedChoices, setSelectedChoices] = (0, hooks_namespaceObject.useState)(()=>initializeSelectedChoices(initialValue, question.type));
|
|
292
|
+
const [openEndedState, setOpenEndedState] = (0, hooks_namespaceObject.useState)(()=>initializeOpenEndedState(initialValue, choices));
|
|
293
|
+
const { isPreviewMode } = (0, external_surveys_extension_utils_js_namespaceObject.useSurveyContext)();
|
|
294
|
+
const isSingleChoiceQuestion = question.type === external_survey_constants_js_namespaceObject.SurveyQuestionType.SingleChoice;
|
|
295
|
+
const isMultipleChoiceQuestion = question.type === external_survey_constants_js_namespaceObject.SurveyQuestionType.MultipleChoice;
|
|
296
|
+
const shouldSkipSubmit = question.skipSubmitButton && isSingleChoiceQuestion && !question.hasOpenChoice;
|
|
297
|
+
const handleChoiceChange = (val, isOpenChoice)=>{
|
|
298
|
+
if (isOpenChoice) {
|
|
299
|
+
const newOpenSelected = !openEndedState.isSelected;
|
|
300
|
+
setOpenEndedState((prev)=>({
|
|
301
|
+
...prev,
|
|
302
|
+
isSelected: newOpenSelected,
|
|
303
|
+
inputValue: newOpenSelected ? prev.inputValue : ''
|
|
304
|
+
}));
|
|
305
|
+
if (isSingleChoiceQuestion) setSelectedChoices('');
|
|
306
|
+
if (newOpenSelected) setTimeout(()=>openChoiceInputRef.current?.focus(), 75);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
if (isSingleChoiceQuestion) {
|
|
310
|
+
setSelectedChoices(val);
|
|
311
|
+
setOpenEndedState((prev)=>({
|
|
312
|
+
...prev,
|
|
313
|
+
isSelected: false,
|
|
314
|
+
inputValue: ''
|
|
315
|
+
}));
|
|
316
|
+
if (shouldSkipSubmit) {
|
|
317
|
+
onSubmit(val);
|
|
318
|
+
if (isPreviewMode) onPreviewSubmit(val);
|
|
319
|
+
}
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (isMultipleChoiceQuestion && (0, core_namespaceObject.isArray)(selectedChoices)) selectedChoices.includes(val) ? setSelectedChoices(selectedChoices.filter((choice)=>choice !== val)) : setSelectedChoices([
|
|
323
|
+
...selectedChoices,
|
|
324
|
+
val
|
|
325
|
+
]);
|
|
326
|
+
};
|
|
327
|
+
const handleOpenEndedInputChange = (e)=>{
|
|
328
|
+
e.stopPropagation();
|
|
329
|
+
const newValue = e.currentTarget.value;
|
|
330
|
+
setOpenEndedState((prev)=>({
|
|
331
|
+
...prev,
|
|
332
|
+
inputValue: newValue
|
|
333
|
+
}));
|
|
334
|
+
if (isSingleChoiceQuestion) setSelectedChoices(newValue);
|
|
335
|
+
};
|
|
336
|
+
const handleOpenEndedKeyDown = (e)=>{
|
|
337
|
+
e.stopPropagation();
|
|
338
|
+
if ('Enter' === e.key && !isSubmitDisabled()) {
|
|
339
|
+
e.preventDefault();
|
|
340
|
+
handleSubmit();
|
|
341
|
+
}
|
|
342
|
+
if ('Escape' === e.key) {
|
|
343
|
+
e.preventDefault();
|
|
344
|
+
setOpenEndedState((prev)=>({
|
|
345
|
+
...prev,
|
|
346
|
+
isSelected: false,
|
|
347
|
+
inputValue: ''
|
|
348
|
+
}));
|
|
349
|
+
if (isSingleChoiceQuestion) setSelectedChoices(null);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
const isSubmitDisabled = ()=>{
|
|
353
|
+
if (question.optional) return false;
|
|
354
|
+
if ((0, core_namespaceObject.isNull)(selectedChoices)) return true;
|
|
355
|
+
if ((0, core_namespaceObject.isArray)(selectedChoices)) {
|
|
356
|
+
if (!openEndedState.isSelected && 0 === selectedChoices.length) return true;
|
|
357
|
+
}
|
|
358
|
+
if (openEndedState.isSelected && '' === openEndedState.inputValue.trim()) return true;
|
|
359
|
+
return false;
|
|
360
|
+
};
|
|
361
|
+
const handleSubmit = ()=>{
|
|
362
|
+
if (openEndedState.isSelected && isMultipleChoiceQuestion) {
|
|
363
|
+
if ((0, core_namespaceObject.isArray)(selectedChoices)) isPreviewMode ? onPreviewSubmit([
|
|
364
|
+
...selectedChoices,
|
|
365
|
+
openEndedState.inputValue
|
|
366
|
+
]) : onSubmit([
|
|
367
|
+
...selectedChoices,
|
|
368
|
+
openEndedState.inputValue
|
|
369
|
+
]);
|
|
370
|
+
} else isPreviewMode ? onPreviewSubmit(selectedChoices) : onSubmit(selectedChoices);
|
|
371
|
+
};
|
|
372
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_preact_namespaceObject.Fragment, {
|
|
373
|
+
children: [
|
|
374
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
375
|
+
className: "question-container",
|
|
376
|
+
children: [
|
|
377
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_QuestionHeader_js_namespaceObject.QuestionHeader, {
|
|
378
|
+
question: question,
|
|
379
|
+
forceDisableHtml: forceDisableHtml
|
|
380
|
+
}),
|
|
381
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("fieldset", {
|
|
382
|
+
className: "multiple-choice-options limit-height",
|
|
383
|
+
children: [
|
|
384
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("legend", {
|
|
385
|
+
className: "sr-only",
|
|
386
|
+
children: isMultipleChoiceQuestion ? ' Select all that apply' : ' Select one'
|
|
387
|
+
}),
|
|
388
|
+
choices.map((choice, idx)=>{
|
|
389
|
+
const isOpenChoice = !!question.hasOpenChoice && idx === question.choices.length - 1;
|
|
390
|
+
const inputId = `surveyQuestion${displayQuestionIndex}Choice${idx}`;
|
|
391
|
+
const openInputId = `${inputId}Open`;
|
|
392
|
+
const isChecked = isOpenChoice ? openEndedState.isSelected : isSingleChoiceQuestion ? selectedChoices === choice : (0, core_namespaceObject.isArray)(selectedChoices) && selectedChoices.includes(choice);
|
|
393
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("label", {
|
|
394
|
+
className: isOpenChoice ? 'choice-option-open' : '',
|
|
395
|
+
children: [
|
|
396
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
|
|
397
|
+
className: "response-choice",
|
|
398
|
+
children: [
|
|
399
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
|
|
400
|
+
type: isSingleChoiceQuestion ? 'radio' : 'checkbox',
|
|
401
|
+
name: inputId,
|
|
402
|
+
checked: isChecked,
|
|
403
|
+
onChange: ()=>handleChoiceChange(choice, isOpenChoice),
|
|
404
|
+
id: inputId,
|
|
405
|
+
"aria-controls": openInputId
|
|
406
|
+
}),
|
|
407
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
|
|
408
|
+
children: isOpenChoice ? `${choice}:` : choice
|
|
409
|
+
})
|
|
410
|
+
]
|
|
411
|
+
}),
|
|
412
|
+
isOpenChoice && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("input", {
|
|
413
|
+
type: "text",
|
|
414
|
+
ref: openChoiceInputRef,
|
|
415
|
+
id: openInputId,
|
|
416
|
+
name: `question${displayQuestionIndex}Open`,
|
|
417
|
+
value: openEndedState.inputValue,
|
|
418
|
+
onKeyDown: handleOpenEndedKeyDown,
|
|
419
|
+
onInput: handleOpenEndedInputChange,
|
|
420
|
+
onClick: (e)=>{
|
|
421
|
+
if (!openEndedState.isSelected) handleChoiceChange(choice, true);
|
|
422
|
+
e.stopPropagation();
|
|
423
|
+
},
|
|
424
|
+
"aria-label": `${choice} - please specify`
|
|
425
|
+
})
|
|
426
|
+
]
|
|
427
|
+
}, idx);
|
|
428
|
+
})
|
|
429
|
+
]
|
|
430
|
+
})
|
|
431
|
+
]
|
|
432
|
+
}),
|
|
433
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_BottomSection_js_namespaceObject.BottomSection, {
|
|
434
|
+
text: question.buttonText || 'Submit',
|
|
435
|
+
submitDisabled: isSubmitDisabled(),
|
|
436
|
+
appearance: appearance,
|
|
437
|
+
onSubmit: handleSubmit,
|
|
438
|
+
onPreviewSubmit: handleSubmit,
|
|
439
|
+
skipSubmitButton: shouldSkipSubmit,
|
|
440
|
+
canGoBack: canGoBack,
|
|
441
|
+
onBack: onBack
|
|
442
|
+
})
|
|
443
|
+
]
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const fiveScaleNumbers = [
|
|
447
|
+
1,
|
|
448
|
+
2,
|
|
449
|
+
3,
|
|
450
|
+
4,
|
|
451
|
+
5
|
|
452
|
+
];
|
|
453
|
+
const sevenScaleNumbers = [
|
|
454
|
+
1,
|
|
455
|
+
2,
|
|
456
|
+
3,
|
|
457
|
+
4,
|
|
458
|
+
5,
|
|
459
|
+
6,
|
|
460
|
+
7
|
|
461
|
+
];
|
|
462
|
+
const tenScaleNumbers = [
|
|
463
|
+
0,
|
|
464
|
+
1,
|
|
465
|
+
2,
|
|
466
|
+
3,
|
|
467
|
+
4,
|
|
468
|
+
5,
|
|
469
|
+
6,
|
|
470
|
+
7,
|
|
471
|
+
8,
|
|
472
|
+
9,
|
|
473
|
+
10
|
|
474
|
+
];
|
|
475
|
+
const emojiScaleLists = {
|
|
476
|
+
2: [
|
|
477
|
+
external_icons_js_namespaceObject.thumbsUpEmoji,
|
|
478
|
+
external_icons_js_namespaceObject.thumbsDownEmoji
|
|
479
|
+
],
|
|
480
|
+
3: [
|
|
481
|
+
external_icons_js_namespaceObject.dissatisfiedEmoji,
|
|
482
|
+
external_icons_js_namespaceObject.neutralEmoji,
|
|
483
|
+
external_icons_js_namespaceObject.satisfiedEmoji
|
|
484
|
+
],
|
|
485
|
+
5: [
|
|
486
|
+
external_icons_js_namespaceObject.veryDissatisfiedEmoji,
|
|
487
|
+
external_icons_js_namespaceObject.dissatisfiedEmoji,
|
|
488
|
+
external_icons_js_namespaceObject.neutralEmoji,
|
|
489
|
+
external_icons_js_namespaceObject.satisfiedEmoji,
|
|
490
|
+
external_icons_js_namespaceObject.verySatisfiedEmoji
|
|
491
|
+
]
|
|
492
|
+
};
|
|
493
|
+
function getScaleNumbers(scale) {
|
|
494
|
+
switch(scale){
|
|
495
|
+
case 5:
|
|
496
|
+
return fiveScaleNumbers;
|
|
497
|
+
case 7:
|
|
498
|
+
return sevenScaleNumbers;
|
|
499
|
+
case 10:
|
|
500
|
+
return tenScaleNumbers;
|
|
501
|
+
default:
|
|
502
|
+
return fiveScaleNumbers;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
exports.LinkQuestion = __webpack_exports__.LinkQuestion;
|
|
506
|
+
exports.MultipleChoiceQuestion = __webpack_exports__.MultipleChoiceQuestion;
|
|
507
|
+
exports.OpenTextQuestion = __webpack_exports__.OpenTextQuestion;
|
|
508
|
+
exports.RatingButton = __webpack_exports__.RatingButton;
|
|
509
|
+
exports.RatingQuestion = __webpack_exports__.RatingQuestion;
|
|
510
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
511
|
+
"LinkQuestion",
|
|
512
|
+
"MultipleChoiceQuestion",
|
|
513
|
+
"OpenTextQuestion",
|
|
514
|
+
"RatingButton",
|
|
515
|
+
"RatingQuestion"
|
|
516
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
517
|
+
Object.defineProperty(exports, '__esModule', {
|
|
518
|
+
value: true
|
|
519
|
+
});
|