posthog-js 1.136.4 → 1.136.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.
Files changed (42) hide show
  1. package/dist/array.full.js +2 -2
  2. package/dist/array.full.js.map +1 -1
  3. package/dist/array.js +1 -1
  4. package/dist/array.js.map +1 -1
  5. package/dist/es.js +1 -1
  6. package/dist/es.js.map +1 -1
  7. package/dist/lib/src/extensions/replay/sessionrecording.d.ts +2 -2
  8. package/dist/lib/src/extensions/surveys/components/ConfirmationMessage.d.ts +3 -3
  9. package/dist/lib/src/extensions/surveys/components/QuestionTypes.d.ts +8 -12
  10. package/dist/lib/src/extensions/surveys/surveys-utils.d.ts +3 -3
  11. package/dist/lib/src/extensions/surveys.d.ts +3 -5
  12. package/dist/lib/src/posthog-surveys-types.d.ts +1 -1
  13. package/dist/module.d.ts +3 -3
  14. package/dist/module.js +1 -1
  15. package/dist/module.js.map +1 -1
  16. package/dist/surveys-module-previews.js +1 -1
  17. package/dist/surveys-module-previews.js.map +1 -1
  18. package/dist/surveys.js +1 -1
  19. package/dist/surveys.js.map +1 -1
  20. package/lib/package.json +1 -1
  21. package/lib/src/extensions/replay/sessionrecording.d.ts +2 -2
  22. package/lib/src/extensions/replay/sessionrecording.js +33 -37
  23. package/lib/src/extensions/replay/sessionrecording.js.map +1 -1
  24. package/lib/src/extensions/surveys/components/BottomSection.jsx +3 -3
  25. package/lib/src/extensions/surveys/components/BottomSection.jsx.map +1 -1
  26. package/lib/src/extensions/surveys/components/ConfirmationMessage.d.ts +3 -3
  27. package/lib/src/extensions/surveys/components/ConfirmationMessage.jsx +3 -3
  28. package/lib/src/extensions/surveys/components/ConfirmationMessage.jsx.map +1 -1
  29. package/lib/src/extensions/surveys/components/QuestionHeader.jsx +2 -2
  30. package/lib/src/extensions/surveys/components/QuestionHeader.jsx.map +1 -1
  31. package/lib/src/extensions/surveys/components/QuestionTypes.d.ts +8 -12
  32. package/lib/src/extensions/surveys/components/QuestionTypes.jsx +21 -17
  33. package/lib/src/extensions/surveys/components/QuestionTypes.jsx.map +1 -1
  34. package/lib/src/extensions/surveys/surveys-utils.d.ts +3 -3
  35. package/lib/src/extensions/surveys/surveys-utils.jsx +7 -7
  36. package/lib/src/extensions/surveys/surveys-utils.jsx.map +1 -1
  37. package/lib/src/extensions/surveys.d.ts +3 -5
  38. package/lib/src/extensions/surveys.jsx +104 -68
  39. package/lib/src/extensions/surveys.jsx.map +1 -1
  40. package/lib/src/posthog-surveys-types.d.ts +1 -1
  41. package/lib/src/posthog-surveys-types.js.map +1 -1
  42. package/package.json +1 -1
@@ -24,46 +24,49 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
24
24
  return to.concat(ar || Array.prototype.slice.call(from));
25
25
  };
26
26
  import { SurveyQuestionType, } from '../../../posthog-surveys-types';
27
- import { useRef, useState, useMemo } from 'preact/hooks';
27
+ import { useRef, useState, useMemo, useContext } from 'preact/hooks';
28
28
  import { isNull, isArray } from '../../../utils/type-utils';
29
29
  import { useContrastingTextColor } from '../hooks/useContrastingTextColor';
30
30
  import { checkSVG, dissatisfiedEmoji, neutralEmoji, satisfiedEmoji, veryDissatisfiedEmoji, verySatisfiedEmoji, } from '../icons';
31
- import { defaultSurveyAppearance, getDisplayOrderChoices } from '../surveys-utils';
31
+ import { defaultSurveyAppearance, getDisplayOrderChoices, SurveyContext } from '../surveys-utils';
32
32
  import { BottomSection } from './BottomSection';
33
33
  import { Cancel, QuestionHeader } from './QuestionHeader';
34
34
  export function OpenTextQuestion(_a) {
35
- var question = _a.question, appearance = _a.appearance, onSubmit = _a.onSubmit, closeSurveyPopup = _a.closeSurveyPopup;
35
+ var question = _a.question, appearance = _a.appearance, onSubmit = _a.onSubmit;
36
36
  var textRef = useRef(null);
37
37
  var _b = __read(useState(''), 2), text = _b[0], setText = _b[1];
38
+ var handleCloseSurveyPopup = useContext(SurveyContext).handleCloseSurveyPopup;
38
39
  return (<div className="survey-box" style={{ backgroundColor: appearance.backgroundColor || defaultSurveyAppearance.backgroundColor }} ref={textRef}>
39
- <Cancel onClick={function () { return closeSurveyPopup(); }}/>
40
+ <Cancel onClick={function () { return handleCloseSurveyPopup(); }}/>
40
41
  <QuestionHeader question={question.question} description={question.description} backgroundColor={appearance.backgroundColor}/>
41
42
  <textarea rows={4} placeholder={appearance === null || appearance === void 0 ? void 0 : appearance.placeholder} onInput={function (e) { return setText(e.currentTarget.value); }}/>
42
43
  <BottomSection text={question.buttonText || 'Submit'} submitDisabled={!text && !question.optional} appearance={appearance} onSubmit={function () { return onSubmit(text); }}/>
43
44
  </div>);
44
45
  }
45
46
  export function LinkQuestion(_a) {
46
- var question = _a.question, appearance = _a.appearance, onSubmit = _a.onSubmit, closeSurveyPopup = _a.closeSurveyPopup;
47
+ var question = _a.question, appearance = _a.appearance, onSubmit = _a.onSubmit;
48
+ var handleCloseSurveyPopup = useContext(SurveyContext).handleCloseSurveyPopup;
47
49
  return (<div className="survey-box">
48
- <Cancel onClick={function () { return closeSurveyPopup(); }}/>
50
+ <Cancel onClick={function () { return handleCloseSurveyPopup(); }}/>
49
51
  <QuestionHeader question={question.question} description={question.description}/>
50
52
  <BottomSection text={question.buttonText || 'Submit'} submitDisabled={false} link={question.link} appearance={appearance} onSubmit={function () { return onSubmit('link clicked'); }}/>
51
53
  </div>);
52
54
  }
53
55
  export function RatingQuestion(_a) {
54
- var question = _a.question, questionIndex = _a.questionIndex, appearance = _a.appearance, onSubmit = _a.onSubmit, closeSurveyPopup = _a.closeSurveyPopup;
56
+ var question = _a.question, displayQuestionIndex = _a.displayQuestionIndex, appearance = _a.appearance, onSubmit = _a.onSubmit;
55
57
  var scale = question.scale;
56
58
  var starting = question.scale === 10 ? 0 : 1;
57
59
  var _b = __read(useState(null), 2), rating = _b[0], setRating = _b[1];
60
+ var handleCloseSurveyPopup = useContext(SurveyContext).handleCloseSurveyPopup;
58
61
  return (<div className="survey-box">
59
- <Cancel onClick={function () { return closeSurveyPopup(); }}/>
62
+ <Cancel onClick={function () { return handleCloseSurveyPopup(); }}/>
60
63
  <QuestionHeader question={question.question} description={question.description} backgroundColor={appearance.backgroundColor}/>
61
64
  <div className="rating-section">
62
65
  <div className="rating-options">
63
66
  {question.display === 'emoji' && (<div className="rating-options-emoji">
64
67
  {(question.scale === 3 ? threeScaleEmojis : fiveScaleEmojis).map(function (emoji, idx) {
65
68
  var active = idx + 1 === rating;
66
- return (<button className={"ratings-emoji question-".concat(questionIndex, "-rating-").concat(idx, " ").concat(active ? 'rating-active' : null)} value={idx + 1} key={idx} type="button" onClick={function () {
69
+ return (<button className={"ratings-emoji question-".concat(displayQuestionIndex, "-rating-").concat(idx, " ").concat(active ? 'rating-active' : null)} value={idx + 1} key={idx} type="button" onClick={function () {
67
70
  setRating(idx + 1);
68
71
  }}>
69
72
  {emoji}
@@ -73,7 +76,7 @@ export function RatingQuestion(_a) {
73
76
  {question.display === 'number' && (<div className="rating-options-number" style={{ gridTemplateColumns: "repeat(".concat(scale - starting + 1, ", minmax(0, 1fr))") }}>
74
77
  {(question.scale === 5 ? fiveScaleNumbers : tenScaleNumbers).map(function (number, idx) {
75
78
  var active = rating === number;
76
- return (<RatingButton key={idx} questionIndex={questionIndex} active={active} appearance={appearance} num={number} setActiveNumber={function (num) {
79
+ return (<RatingButton key={idx} displayQuestionIndex={displayQuestionIndex} active={active} appearance={appearance} num={number} setActiveNumber={function (num) {
77
80
  setRating(num);
78
81
  }}/>);
79
82
  })}
@@ -88,9 +91,9 @@ export function RatingQuestion(_a) {
88
91
  </div>);
89
92
  }
90
93
  export function RatingButton(_a) {
91
- var num = _a.num, active = _a.active, questionIndex = _a.questionIndex, appearance = _a.appearance, setActiveNumber = _a.setActiveNumber;
94
+ var num = _a.num, active = _a.active, displayQuestionIndex = _a.displayQuestionIndex, appearance = _a.appearance, setActiveNumber = _a.setActiveNumber;
92
95
  var _b = useContrastingTextColor({ appearance: appearance, defaultTextColor: 'black', forceUpdate: active }), textColor = _b.textColor, ref = _b.ref;
93
- return (<button ref={ref} className={"ratings-number question-".concat(questionIndex, "-rating-").concat(num, " ").concat(active ? 'rating-active' : null)} type="button" onClick={function () {
96
+ return (<button ref={ref} className={"ratings-number question-".concat(displayQuestionIndex, "-rating-").concat(num, " ").concat(active ? 'rating-active' : null)} type="button" onClick={function () {
94
97
  setActiveNumber(num);
95
98
  }} style={{
96
99
  color: textColor,
@@ -101,15 +104,16 @@ export function RatingButton(_a) {
101
104
  </button>);
102
105
  }
103
106
  export function MultipleChoiceQuestion(_a) {
104
- var question = _a.question, questionIndex = _a.questionIndex, appearance = _a.appearance, onSubmit = _a.onSubmit, closeSurveyPopup = _a.closeSurveyPopup;
107
+ var question = _a.question, displayQuestionIndex = _a.displayQuestionIndex, appearance = _a.appearance, onSubmit = _a.onSubmit;
105
108
  var textRef = useRef(null);
106
109
  var choices = useMemo(function () { return getDisplayOrderChoices(question); }, [question]);
107
110
  var _b = __read(useState(question.type === SurveyQuestionType.MultipleChoice ? [] : null), 2), selectedChoices = _b[0], setSelectedChoices = _b[1];
108
111
  var _c = __read(useState(false), 2), openChoiceSelected = _c[0], setOpenChoiceSelected = _c[1];
109
112
  var _d = __read(useState(''), 2), openEndedInput = _d[0], setOpenEndedInput = _d[1];
113
+ var handleCloseSurveyPopup = useContext(SurveyContext).handleCloseSurveyPopup;
110
114
  var inputType = question.type === SurveyQuestionType.SingleChoice ? 'radio' : 'checkbox';
111
115
  return (<div className="survey-box" style={{ backgroundColor: appearance.backgroundColor || defaultSurveyAppearance.backgroundColor }} ref={textRef}>
112
- <Cancel onClick={function () { return closeSurveyPopup(); }}/>
116
+ <Cancel onClick={function () { return handleCloseSurveyPopup(); }}/>
113
117
  <QuestionHeader question={question.question} description={question.description} backgroundColor={appearance.backgroundColor}/>
114
118
  <div className="multiple-choice-options">
115
119
  {/* Remove the last element from the choices, if hasOpenChoice is set */}
@@ -123,7 +127,7 @@ export function MultipleChoiceQuestion(_a) {
123
127
  choiceClass += ' choice-option-open';
124
128
  }
125
129
  return (<div className={choiceClass}>
126
- <input type={inputType} id={"surveyQuestion".concat(questionIndex, "Choice").concat(idx)} name={"question".concat(questionIndex)} value={val} disabled={!val} onInput={function () {
130
+ <input type={inputType} id={"surveyQuestion".concat(displayQuestionIndex, "Choice").concat(idx)} name={"question".concat(displayQuestionIndex)} value={val} disabled={!val} onInput={function () {
127
131
  if (question.hasOpenChoice && idx === question.choices.length - 1) {
128
132
  return setOpenChoiceSelected(!openChoiceSelected);
129
133
  }
@@ -139,10 +143,10 @@ export function MultipleChoiceQuestion(_a) {
139
143
  return setSelectedChoices(__spreadArray(__spreadArray([], __read(selectedChoices), false), [val], false));
140
144
  }
141
145
  }}/>
142
- <label htmlFor={"surveyQuestion".concat(questionIndex, "Choice").concat(idx)} style={{ color: 'black' }}>
146
+ <label htmlFor={"surveyQuestion".concat(displayQuestionIndex, "Choice").concat(idx)} style={{ color: 'black' }}>
143
147
  {question.hasOpenChoice && idx === question.choices.length - 1 ? (<>
144
148
  <span>{option}:</span>
145
- <input type="text" id={"surveyQuestion".concat(questionIndex, "Choice").concat(idx, "Open")} name={"question".concat(questionIndex)} onInput={function (e) {
149
+ <input type="text" id={"surveyQuestion".concat(displayQuestionIndex, "Choice").concat(idx, "Open")} name={"question".concat(displayQuestionIndex)} onInput={function (e) {
146
150
  var userValue = e.currentTarget.value;
147
151
  if (question.type === SurveyQuestionType.SingleChoice) {
148
152
  return setSelectedChoices(userValue);
@@ -1 +1 @@
1
- {"version":3,"file":"QuestionTypes.jsx","sourceRoot":"","sources":["../../../../../src/extensions/surveys/components/QuestionTypes.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAMH,kBAAkB,GACrB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,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AAE,cAAc,CAAC,CAAA;AAC1E,IAAM,eAAe,GAAG,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAA;AACpH,IAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;AACxC,IAAM,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA","sourcesContent":["import {\n BasicSurveyQuestion,\n SurveyAppearance,\n LinkSurveyQuestion,\n RatingSurveyQuestion,\n MultipleSurveyQuestion,\n SurveyQuestionType,\n} from '../../../posthog-surveys-types'\nimport { RefObject } from 'preact'\nimport { useRef, useState, useMemo } from 'preact/hooks'\nimport { isNull, isArray } from '../../../utils/type-utils'\nimport { useContrastingTextColor } from '../hooks/useContrastingTextColor'\nimport {\n checkSVG,\n dissatisfiedEmoji,\n neutralEmoji,\n satisfiedEmoji,\n veryDissatisfiedEmoji,\n verySatisfiedEmoji,\n} from '../icons'\nimport { defaultSurveyAppearance, getDisplayOrderChoices } from '../surveys-utils'\nimport { BottomSection } from './BottomSection'\nimport { Cancel, QuestionHeader } from './QuestionHeader'\n\nexport function OpenTextQuestion({\n question,\n appearance,\n onSubmit,\n closeSurveyPopup,\n}: {\n question: BasicSurveyQuestion\n appearance: SurveyAppearance\n onSubmit: (text: string) => void\n closeSurveyPopup: () => void\n}) {\n const textRef = useRef(null)\n const [text, setText] = useState('')\n\n return (\n <div\n className=\"survey-box\"\n style={{ backgroundColor: appearance.backgroundColor || defaultSurveyAppearance.backgroundColor }}\n ref={textRef}\n >\n <Cancel onClick={() => closeSurveyPopup()} />\n <QuestionHeader\n question={question.question}\n description={question.description}\n backgroundColor={appearance.backgroundColor}\n />\n <textarea rows={4} placeholder={appearance?.placeholder} onInput={(e) => setText(e.currentTarget.value)} />\n <BottomSection\n text={question.buttonText || 'Submit'}\n submitDisabled={!text && !question.optional}\n appearance={appearance}\n onSubmit={() => onSubmit(text)}\n />\n </div>\n )\n}\n\nexport function LinkQuestion({\n question,\n appearance,\n onSubmit,\n closeSurveyPopup,\n}: {\n question: LinkSurveyQuestion\n appearance: SurveyAppearance\n onSubmit: (clicked: string) => void\n closeSurveyPopup: () => void\n}) {\n return (\n <div className=\"survey-box\">\n <Cancel onClick={() => closeSurveyPopup()} />\n <QuestionHeader question={question.question} description={question.description} />\n <BottomSection\n text={question.buttonText || 'Submit'}\n submitDisabled={false}\n link={question.link}\n appearance={appearance}\n onSubmit={() => onSubmit('link clicked')}\n />\n </div>\n )\n}\n\nexport function RatingQuestion({\n question,\n questionIndex,\n appearance,\n onSubmit,\n closeSurveyPopup,\n}: {\n question: RatingSurveyQuestion\n questionIndex: number\n appearance: SurveyAppearance\n onSubmit: (rating: number | null) => void\n closeSurveyPopup: () => void\n}) {\n const scale = question.scale\n const starting = question.scale === 10 ? 0 : 1\n const [rating, setRating] = useState<number | null>(null)\n\n return (\n <div className=\"survey-box\">\n <Cancel onClick={() => closeSurveyPopup()} />\n <QuestionHeader\n question={question.question}\n description={question.description}\n backgroundColor={appearance.backgroundColor}\n />\n <div className=\"rating-section\">\n <div className=\"rating-options\">\n {question.display === 'emoji' && (\n <div className=\"rating-options-emoji\">\n {(question.scale === 3 ? threeScaleEmojis : fiveScaleEmojis).map((emoji, idx) => {\n const active = idx + 1 === rating\n return (\n <button\n className={`ratings-emoji question-${questionIndex}-rating-${idx} ${\n active ? 'rating-active' : null\n }`}\n value={idx + 1}\n key={idx}\n type=\"button\"\n onClick={() => {\n setRating(idx + 1)\n }}\n >\n {emoji}\n </button>\n )\n })}\n </div>\n )}\n {question.display === 'number' && (\n <div\n className=\"rating-options-number\"\n style={{ gridTemplateColumns: `repeat(${scale - starting + 1}, minmax(0, 1fr))` }}\n >\n {(question.scale === 5 ? fiveScaleNumbers : tenScaleNumbers).map((number, idx) => {\n const active = rating === number\n return (\n <RatingButton\n key={idx}\n questionIndex={questionIndex}\n active={active}\n appearance={appearance}\n num={number}\n setActiveNumber={(num) => {\n setRating(num)\n }}\n />\n )\n })}\n </div>\n )}\n </div>\n <div className=\"rating-text\">\n <div>{question.lowerBoundLabel}</div>\n <div>{question.upperBoundLabel}</div>\n </div>\n </div>\n <BottomSection\n text={question.buttonText || appearance?.submitButtonText || 'Submit'}\n submitDisabled={isNull(rating) && !question.optional}\n appearance={appearance}\n onSubmit={() => onSubmit(rating)}\n />\n </div>\n )\n}\n\nexport function RatingButton({\n num,\n active,\n questionIndex,\n appearance,\n setActiveNumber,\n}: {\n num: number\n active: boolean\n questionIndex: number\n appearance: any\n setActiveNumber: (num: number) => void\n}) {\n const { textColor, ref } = useContrastingTextColor({ appearance, defaultTextColor: 'black', forceUpdate: active })\n return (\n <button\n ref={ref as RefObject<HTMLButtonElement>}\n className={`ratings-number question-${questionIndex}-rating-${num} ${active ? 'rating-active' : null}`}\n type=\"button\"\n onClick={() => {\n setActiveNumber(num)\n }}\n style={{\n color: textColor,\n backgroundColor: active ? appearance.ratingButtonActiveColor : appearance.ratingButtonColor,\n borderColor: appearance.borderColor,\n }}\n >\n {num}\n </button>\n )\n}\n\nexport function MultipleChoiceQuestion({\n question,\n questionIndex,\n appearance,\n onSubmit,\n closeSurveyPopup,\n}: {\n question: MultipleSurveyQuestion\n questionIndex: number\n appearance: SurveyAppearance\n onSubmit: (choices: string | string[] | null) => void\n closeSurveyPopup: () => void\n}) {\n const textRef = useRef(null)\n const choices = useMemo(() => getDisplayOrderChoices(question), [question])\n const [selectedChoices, setSelectedChoices] = useState<string | string[] | null>(\n question.type === SurveyQuestionType.MultipleChoice ? [] : null\n )\n const [openChoiceSelected, setOpenChoiceSelected] = useState(false)\n const [openEndedInput, setOpenEndedInput] = useState('')\n\n const inputType = question.type === SurveyQuestionType.SingleChoice ? 'radio' : 'checkbox'\n return (\n <div\n className=\"survey-box\"\n style={{ backgroundColor: appearance.backgroundColor || defaultSurveyAppearance.backgroundColor }}\n ref={textRef}\n >\n <Cancel onClick={() => closeSurveyPopup()} />\n <QuestionHeader\n question={question.question}\n description={question.description}\n backgroundColor={appearance.backgroundColor}\n />\n <div className=\"multiple-choice-options\">\n {/* Remove the last element from the choices, if hasOpenChoice is set */}\n {/* shuffle all other options here if question.shuffleOptions is set */}\n {/* Always ensure that the open ended choice is the last option */}\n {choices.map((choice: string, idx: number) => {\n let choiceClass = 'choice-option'\n const val = choice\n const option = choice\n if (!!question.hasOpenChoice && idx === question.choices.length - 1) {\n choiceClass += ' choice-option-open'\n }\n return (\n <div className={choiceClass}>\n <input\n type={inputType}\n id={`surveyQuestion${questionIndex}Choice${idx}`}\n name={`question${questionIndex}`}\n value={val}\n disabled={!val}\n onInput={() => {\n if (question.hasOpenChoice && idx === question.choices.length - 1) {\n return setOpenChoiceSelected(!openChoiceSelected)\n }\n if (question.type === SurveyQuestionType.SingleChoice) {\n return setSelectedChoices(val)\n }\n if (\n question.type === SurveyQuestionType.MultipleChoice &&\n isArray(selectedChoices)\n ) {\n if (selectedChoices.includes(val)) {\n // filter out values because clicking on a selected choice should deselect it\n return setSelectedChoices(\n selectedChoices.filter((choice) => choice !== val)\n )\n }\n return setSelectedChoices([...selectedChoices, val])\n }\n }}\n />\n <label htmlFor={`surveyQuestion${questionIndex}Choice${idx}`} style={{ color: 'black' }}>\n {question.hasOpenChoice && idx === question.choices.length - 1 ? (\n <>\n <span>{option}:</span>\n <input\n type=\"text\"\n id={`surveyQuestion${questionIndex}Choice${idx}Open`}\n name={`question${questionIndex}`}\n onInput={(e) => {\n const userValue = e.currentTarget.value\n if (question.type === SurveyQuestionType.SingleChoice) {\n return setSelectedChoices(userValue)\n }\n if (\n question.type === SurveyQuestionType.MultipleChoice &&\n isArray(selectedChoices)\n ) {\n return setOpenEndedInput(userValue)\n }\n }}\n />\n </>\n ) : (\n option\n )}\n </label>\n <span className=\"choice-check\" style={{ color: 'black' }}>\n {checkSVG}\n </span>\n </div>\n )\n })}\n </div>\n <BottomSection\n text={question.buttonText || 'Submit'}\n submitDisabled={\n (isNull(selectedChoices) ||\n (isArray(selectedChoices) && !openChoiceSelected && selectedChoices.length === 0) ||\n (isArray(selectedChoices) &&\n openChoiceSelected &&\n !openEndedInput &&\n selectedChoices.length === 0 &&\n !question.optional)) &&\n !question.optional\n }\n appearance={appearance}\n onSubmit={() => {\n if (openChoiceSelected && question.type === SurveyQuestionType.MultipleChoice) {\n if (isArray(selectedChoices)) {\n onSubmit([...selectedChoices, openEndedInput])\n }\n } else {\n onSubmit(selectedChoices)\n }\n }}\n />\n </div>\n )\n}\n\nconst threeScaleEmojis = [dissatisfiedEmoji, neutralEmoji, satisfiedEmoji]\nconst fiveScaleEmojis = [veryDissatisfiedEmoji, dissatisfiedEmoji, neutralEmoji, satisfiedEmoji, verySatisfiedEmoji]\nconst fiveScaleNumbers = [1, 2, 3, 4, 5]\nconst tenScaleNumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n"]}
1
+ {"version":3,"file":"QuestionTypes.jsx","sourceRoot":"","sources":["../../../../../src/extensions/surveys/components/QuestionTypes.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAMH,kBAAkB,GACrB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAA;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EACH,QAAQ,EACR,iBAAiB,EACjB,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,kBAAkB,GACrB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,aAAa,EAAE,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,EAAE,YAAY,EAAE,cAAc,CAAC,CAAA;AAC1E,IAAM,eAAe,GAAG,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,YAAY,EAAE,cAAc,EAAE,kBAAkB,CAAC,CAAA;AACpH,IAAM,gBAAgB,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA;AACxC,IAAM,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAA","sourcesContent":["import {\n BasicSurveyQuestion,\n SurveyAppearance,\n LinkSurveyQuestion,\n RatingSurveyQuestion,\n MultipleSurveyQuestion,\n SurveyQuestionType,\n} from '../../../posthog-surveys-types'\nimport { RefObject } from 'preact'\nimport { useRef, useState, useMemo, useContext } from 'preact/hooks'\nimport { isNull, isArray } from '../../../utils/type-utils'\nimport { useContrastingTextColor } from '../hooks/useContrastingTextColor'\nimport {\n checkSVG,\n dissatisfiedEmoji,\n neutralEmoji,\n satisfiedEmoji,\n veryDissatisfiedEmoji,\n verySatisfiedEmoji,\n} from '../icons'\nimport { defaultSurveyAppearance, getDisplayOrderChoices, SurveyContext } from '../surveys-utils'\nimport { BottomSection } from './BottomSection'\nimport { Cancel, QuestionHeader } from './QuestionHeader'\n\nexport function OpenTextQuestion({\n question,\n appearance,\n onSubmit,\n}: {\n question: BasicSurveyQuestion\n appearance: SurveyAppearance\n onSubmit: (text: string) => void\n}) {\n const textRef = useRef(null)\n const [text, setText] = useState('')\n const { handleCloseSurveyPopup } = useContext(SurveyContext)\n\n return (\n <div\n className=\"survey-box\"\n style={{ backgroundColor: appearance.backgroundColor || defaultSurveyAppearance.backgroundColor }}\n ref={textRef}\n >\n <Cancel onClick={() => handleCloseSurveyPopup()} />\n <QuestionHeader\n question={question.question}\n description={question.description}\n backgroundColor={appearance.backgroundColor}\n />\n <textarea rows={4} placeholder={appearance?.placeholder} onInput={(e) => setText(e.currentTarget.value)} />\n <BottomSection\n text={question.buttonText || 'Submit'}\n submitDisabled={!text && !question.optional}\n appearance={appearance}\n onSubmit={() => onSubmit(text)}\n />\n </div>\n )\n}\n\nexport function LinkQuestion({\n question,\n appearance,\n onSubmit,\n}: {\n question: LinkSurveyQuestion\n appearance: SurveyAppearance\n onSubmit: (clicked: string) => void\n}) {\n const { handleCloseSurveyPopup } = useContext(SurveyContext)\n\n return (\n <div className=\"survey-box\">\n <Cancel onClick={() => handleCloseSurveyPopup()} />\n <QuestionHeader question={question.question} description={question.description} />\n <BottomSection\n text={question.buttonText || 'Submit'}\n submitDisabled={false}\n link={question.link}\n appearance={appearance}\n onSubmit={() => onSubmit('link clicked')}\n />\n </div>\n )\n}\n\nexport function RatingQuestion({\n question,\n displayQuestionIndex,\n appearance,\n onSubmit,\n}: {\n question: RatingSurveyQuestion\n displayQuestionIndex: number\n appearance: SurveyAppearance\n onSubmit: (rating: number | null) => void\n}) {\n const scale = question.scale\n const starting = question.scale === 10 ? 0 : 1\n const [rating, setRating] = useState<number | null>(null)\n const { handleCloseSurveyPopup } = useContext(SurveyContext)\n\n return (\n <div className=\"survey-box\">\n <Cancel onClick={() => handleCloseSurveyPopup()} />\n <QuestionHeader\n question={question.question}\n description={question.description}\n backgroundColor={appearance.backgroundColor}\n />\n <div className=\"rating-section\">\n <div className=\"rating-options\">\n {question.display === 'emoji' && (\n <div className=\"rating-options-emoji\">\n {(question.scale === 3 ? threeScaleEmojis : fiveScaleEmojis).map((emoji, idx) => {\n const active = idx + 1 === rating\n return (\n <button\n className={`ratings-emoji question-${displayQuestionIndex}-rating-${idx} ${\n active ? 'rating-active' : null\n }`}\n value={idx + 1}\n key={idx}\n type=\"button\"\n onClick={() => {\n setRating(idx + 1)\n }}\n >\n {emoji}\n </button>\n )\n })}\n </div>\n )}\n {question.display === 'number' && (\n <div\n className=\"rating-options-number\"\n style={{ gridTemplateColumns: `repeat(${scale - starting + 1}, minmax(0, 1fr))` }}\n >\n {(question.scale === 5 ? fiveScaleNumbers : tenScaleNumbers).map((number, idx) => {\n const active = rating === number\n return (\n <RatingButton\n key={idx}\n displayQuestionIndex={displayQuestionIndex}\n active={active}\n appearance={appearance}\n num={number}\n setActiveNumber={(num) => {\n setRating(num)\n }}\n />\n )\n })}\n </div>\n )}\n </div>\n <div className=\"rating-text\">\n <div>{question.lowerBoundLabel}</div>\n <div>{question.upperBoundLabel}</div>\n </div>\n </div>\n <BottomSection\n text={question.buttonText || appearance?.submitButtonText || 'Submit'}\n submitDisabled={isNull(rating) && !question.optional}\n appearance={appearance}\n onSubmit={() => onSubmit(rating)}\n />\n </div>\n )\n}\n\nexport function RatingButton({\n num,\n active,\n displayQuestionIndex,\n appearance,\n setActiveNumber,\n}: {\n num: number\n active: boolean\n displayQuestionIndex: number\n appearance: any\n setActiveNumber: (num: number) => void\n}) {\n const { textColor, ref } = useContrastingTextColor({ appearance, defaultTextColor: 'black', forceUpdate: active })\n return (\n <button\n ref={ref as RefObject<HTMLButtonElement>}\n className={`ratings-number question-${displayQuestionIndex}-rating-${num} ${\n active ? 'rating-active' : null\n }`}\n type=\"button\"\n onClick={() => {\n setActiveNumber(num)\n }}\n style={{\n color: textColor,\n backgroundColor: active ? appearance.ratingButtonActiveColor : appearance.ratingButtonColor,\n borderColor: appearance.borderColor,\n }}\n >\n {num}\n </button>\n )\n}\n\nexport function MultipleChoiceQuestion({\n question,\n displayQuestionIndex,\n appearance,\n onSubmit,\n}: {\n question: MultipleSurveyQuestion\n displayQuestionIndex: number\n appearance: SurveyAppearance\n onSubmit: (choices: string | string[] | null) => void\n}) {\n const textRef = useRef(null)\n const choices = useMemo(() => getDisplayOrderChoices(question), [question])\n const [selectedChoices, setSelectedChoices] = useState<string | string[] | null>(\n question.type === SurveyQuestionType.MultipleChoice ? [] : null\n )\n const [openChoiceSelected, setOpenChoiceSelected] = useState(false)\n const [openEndedInput, setOpenEndedInput] = useState('')\n const { handleCloseSurveyPopup } = useContext(SurveyContext)\n\n const inputType = question.type === SurveyQuestionType.SingleChoice ? 'radio' : 'checkbox'\n return (\n <div\n className=\"survey-box\"\n style={{ backgroundColor: appearance.backgroundColor || defaultSurveyAppearance.backgroundColor }}\n ref={textRef}\n >\n <Cancel onClick={() => handleCloseSurveyPopup()} />\n <QuestionHeader\n question={question.question}\n description={question.description}\n backgroundColor={appearance.backgroundColor}\n />\n <div className=\"multiple-choice-options\">\n {/* Remove the last element from the choices, if hasOpenChoice is set */}\n {/* shuffle all other options here if question.shuffleOptions is set */}\n {/* Always ensure that the open ended choice is the last option */}\n {choices.map((choice: string, idx: number) => {\n let choiceClass = 'choice-option'\n const val = choice\n const option = choice\n if (!!question.hasOpenChoice && idx === question.choices.length - 1) {\n choiceClass += ' choice-option-open'\n }\n return (\n <div className={choiceClass}>\n <input\n type={inputType}\n id={`surveyQuestion${displayQuestionIndex}Choice${idx}`}\n name={`question${displayQuestionIndex}`}\n value={val}\n disabled={!val}\n onInput={() => {\n if (question.hasOpenChoice && idx === question.choices.length - 1) {\n return setOpenChoiceSelected(!openChoiceSelected)\n }\n if (question.type === SurveyQuestionType.SingleChoice) {\n return setSelectedChoices(val)\n }\n if (\n question.type === SurveyQuestionType.MultipleChoice &&\n isArray(selectedChoices)\n ) {\n if (selectedChoices.includes(val)) {\n // filter out values because clicking on a selected choice should deselect it\n return setSelectedChoices(\n selectedChoices.filter((choice) => choice !== val)\n )\n }\n return setSelectedChoices([...selectedChoices, val])\n }\n }}\n />\n <label\n htmlFor={`surveyQuestion${displayQuestionIndex}Choice${idx}`}\n style={{ color: 'black' }}\n >\n {question.hasOpenChoice && idx === question.choices.length - 1 ? (\n <>\n <span>{option}:</span>\n <input\n type=\"text\"\n id={`surveyQuestion${displayQuestionIndex}Choice${idx}Open`}\n name={`question${displayQuestionIndex}`}\n onInput={(e) => {\n const userValue = e.currentTarget.value\n if (question.type === SurveyQuestionType.SingleChoice) {\n return setSelectedChoices(userValue)\n }\n if (\n question.type === SurveyQuestionType.MultipleChoice &&\n isArray(selectedChoices)\n ) {\n return setOpenEndedInput(userValue)\n }\n }}\n />\n </>\n ) : (\n option\n )}\n </label>\n <span className=\"choice-check\" style={{ color: 'black' }}>\n {checkSVG}\n </span>\n </div>\n )\n })}\n </div>\n <BottomSection\n text={question.buttonText || 'Submit'}\n submitDisabled={\n (isNull(selectedChoices) ||\n (isArray(selectedChoices) && !openChoiceSelected && selectedChoices.length === 0) ||\n (isArray(selectedChoices) &&\n openChoiceSelected &&\n !openEndedInput &&\n selectedChoices.length === 0 &&\n !question.optional)) &&\n !question.optional\n }\n appearance={appearance}\n onSubmit={() => {\n if (openChoiceSelected && question.type === SurveyQuestionType.MultipleChoice) {\n if (isArray(selectedChoices)) {\n onSubmit([...selectedChoices, openEndedInput])\n }\n } else {\n onSubmit(selectedChoices)\n }\n }}\n />\n </div>\n )\n}\n\nconst threeScaleEmojis = [dissatisfiedEmoji, neutralEmoji, satisfiedEmoji]\nconst fiveScaleEmojis = [veryDissatisfiedEmoji, dissatisfiedEmoji, neutralEmoji, satisfiedEmoji, verySatisfiedEmoji]\nconst fiveScaleNumbers = [1, 2, 3, 4, 5]\nconst tenScaleNumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n"]}
@@ -11,7 +11,7 @@ export declare const shuffle: (array: any[]) => any[];
11
11
  export declare const getDisplayOrderChoices: (question: MultipleSurveyQuestion) => string[];
12
12
  export declare const getDisplayOrderQuestions: (survey: Survey) => SurveyQuestion[];
13
13
  export declare const SurveyContext: import("preact").Context<{
14
- readOnly: boolean;
15
- previewQuestionIndex: number;
16
- textColor: string;
14
+ isPreviewMode: boolean;
15
+ previewPageIndex: number | undefined;
16
+ handleCloseSurveyPopup: () => void;
17
17
  }>;
@@ -287,18 +287,18 @@ export var getDisplayOrderChoices = function (question) {
287
287
  return shuffledOptions;
288
288
  };
289
289
  export var getDisplayOrderQuestions = function (survey) {
290
+ // retain the original questionIndex so we can correlate values in the webapp
291
+ survey.questions.forEach(function (question, idx) {
292
+ question.originalQuestionIndex = idx;
293
+ });
290
294
  if (!survey.appearance || !survey.appearance.shuffleQuestions) {
291
295
  return survey.questions;
292
296
  }
293
- // retain the original questionIndex so we can correlate values in the webapp
294
- survey.questions.forEach(function (element, idx) {
295
- element.questionIndex = idx;
296
- });
297
297
  return shuffle(survey.questions);
298
298
  };
299
299
  export var SurveyContext = createContext({
300
- readOnly: false,
301
- previewQuestionIndex: 0,
302
- textColor: 'black',
300
+ isPreviewMode: false,
301
+ previewPageIndex: 0,
302
+ handleCloseSurveyPopup: function () { },
303
303
  });
304
304
  //# sourceMappingURL=surveys-utils.jsx.map
@@ -1 +1 @@
1
- {"version":3,"file":"surveys-utils.jsx","sourceRoot":"","sources":["../../../../src/extensions/surveys/surveys-utils.tsx"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,gGAAgG;AAChG,IAAM,MAAM,GAAG,OAAqC,CAAA;AACpD,IAAM,QAAQ,GAAG,SAAqB,CAAA;AAEtC,MAAM,CAAC,IAAM,KAAK,GAAG,UAAC,UAAmC;IACrD,IAAM,SAAS,GAAG;QACd,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,cAAc;QACrB,MAAM,EAAE,gFAGL;KACN,CAAA;IACD,OAAO,2bASgB,QAAQ,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,KAAI,KAAK,CAAC,yCACzC,QAAQ,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,KAAI,OAAO,CAAC,kDAC5B,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,WAAW,KAAI,SAAS,6FAGxD,SAAS,CAAC,CAAA,UAAU,aAA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AAG;QAClC,OAAO,CAAC,aAAa,GAAG,GAAG,CAAA;IAC/B,CAAC,CAAC,CAAA;IAEF,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,CAAC,IAAM,aAAa,GAAG,aAAa,CAIvC;IACC,QAAQ,EAAE,KAAK;IACf,oBAAoB,EAAE,CAAC;IACvB,SAAS,EAAE,OAAO;CACrB,CAAC,CAAA","sourcesContent":["import { PostHog } from '../../posthog-core'\nimport { Survey, SurveyAppearance, MultipleSurveyQuestion, SurveyQuestion } from '../../posthog-surveys-types'\nimport { window as _window, document as _document } from '../../utils/globals'\nimport { createContext } from 'preact'\n// We cast the types here which is dangerous but protected by the top level generateSurveys call\nconst window = _window as Window & typeof globalThis\nconst document = _document as Document\n\nexport const style = (appearance: SurveyAppearance | null) => {\n const positions = {\n left: 'left: 30px;',\n right: 'right: 30px;',\n center: `\n left: 50%;\n transform: translateX(-50%);\n `,\n }\n return `\n .survey-form {\n position: fixed;\n margin: 0px;\n bottom: 0px;\n color: black;\n font-weight: normal;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n text-align: left;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n border-bottom: 0px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .form-submit[disabled] {\n opacity: 0.6;\n filter: grayscale(50%);\n cursor: not-allowed;\n }\n .survey-form {\n flex-direction: column;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n }\n .survey-form textarea {\n color: #2d2d2d;\n font-size: 14px;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n background: white;\n color: black;\n outline: none;\n padding-left: 10px;\n padding-right: 10px;\n padding-top: 10px;\n border-radius: 6px;\n border-color: ${appearance?.borderColor || '#c9c6c6'};\n margin-top: 14px;\n }\n .form-submit {\n box-sizing: border-box;\n margin: 0;\n font-family: inherit;\n overflow: visible;\n text-transform: none;\n position: relative;\n display: inline-block;\n font-weight: 700;\n white-space: nowrap;\n text-align: center;\n border: 1.5px solid transparent;\n cursor: pointer;\n user-select: none;\n touch-action: manipulation;\n padding: 12px;\n font-size: 14px;\n border-radius: 6px;\n outline: 0;\n background: ${appearance?.submitButtonColor || 'black'} !important;\n text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);\n box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);\n width: 100%;\n }\n .form-cancel {\n float: right;\n border: none;\n background: none;\n cursor: pointer;\n }\n .cancel-btn-wrapper {\n position: absolute;\n width: 35px;\n height: 35px;\n border-radius: 100%;\n top: 0;\n right: 0;\n transform: translate(50%, -50%);\n background: white;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .bolded { font-weight: 600; }\n .buttons {\n display: flex;\n justify-content: center;\n }\n .footer-branding {\n font-size: 11px;\n margin-top: 10px;\n text-align: center;\n display: flex;\n justify-content: center;\n gap: 4px;\n align-items: center;\n font-weight: 500;\n background: ${appearance?.backgroundColor || '#eeeded'};\n text-decoration: none;\n }\n .survey-box {\n padding: 20px 25px 10px;\n display: flex;\n flex-direction: column;\n border-radius: 10px;\n }\n .survey-question {\n font-weight: 500;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .question-textarea-wrapper {\n display: flex;\n flex-direction: column;\n }\n .description {\n font-size: 13px;\n padding-top: 5px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .ratings-number {\n background-color: ${appearance?.ratingButtonColor || 'white'};\n font-size: 16px;\n font-weight: 600;\n padding: 8px 0px;\n border: none;\n }\n .ratings-number:hover {\n cursor: pointer;\n }\n .rating-options {\n margin-top: 14px;\n }\n .rating-options-number {\n display: grid;\n border-radius: 6px;\n overflow: hidden;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number {\n border-right: 1px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number:last-of-type {\n border-right: 0px;\n }\n .rating-options-number .rating-active {\n background: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .rating-options-emoji {\n display: flex;\n justify-content: space-between;\n }\n .ratings-emoji {\n font-size: 16px;\n background-color: transparent;\n border: none;\n padding: 0px;\n }\n .ratings-emoji:hover {\n cursor: pointer;\n }\n .ratings-emoji.rating-active svg {\n fill: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .emoji-svg {\n fill: ${appearance?.ratingButtonColor || '#c9c6c6'};\n }\n .rating-text {\n display: flex;\n flex-direction: row;\n font-size: 11px;\n justify-content: space-between;\n margin-top: 6px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n opacity: .60;\n }\n .multiple-choice-options {\n margin-top: 13px;\n font-size: 14px;\n }\n .multiple-choice-options .choice-option {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 13px;\n cursor: pointer;\n margin-bottom: 5px;\n position: relative;\n }\n .multiple-choice-options > .choice-option:last-of-type {\n margin-bottom: 0px;\n }\n .multiple-choice-options input {\n cursor: pointer;\n position: absolute;\n opacity: 0;\n }\n .choice-check {\n position: absolute;\n right: 10px;\n background: white;\n }\n .choice-check svg {\n display: none;\n }\n .multiple-choice-options .choice-option:hover .choice-check svg {\n display: inline-block;\n opacity: .25;\n }\n .multiple-choice-options input:checked + label + .choice-check svg {\n display: inline-block;\n opacity: 100% !important;\n }\n .multiple-choice-options input:checked + label {\n font-weight: bold;\n border: 1.5px solid rgba(0,0,0);\n }\n .multiple-choice-options input:checked + label input {\n font-weight: bold;\n }\n .multiple-choice-options label {\n width: 100%;\n cursor: pointer;\n padding: 10px;\n border: 1.5px solid rgba(0,0,0,.25);\n border-radius: 4px;\n background: white;\n }\n .multiple-choice-options .choice-option-open label {\n padding-right: 30px;\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n max-width: 100%;\n }\n .multiple-choice-options .choice-option-open label span {\n width: 100%;\n }\n .multiple-choice-options .choice-option-open input:disabled + label {\n opacity: 0.6;\n }\n .multiple-choice-options .choice-option-open label input {\n position: relative;\n opacity: 1;\n flex-grow: 1;\n border: 0;\n outline: 0;\n }\n .thank-you-message {\n position: fixed;\n bottom: 0px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n padding: 20px 25px 10px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n text-align: center;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n min-width: 150px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .thank-you-message-body {\n margin-top: 6px;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-header {\n margin: 10px 0px 0px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-container .form-submit {\n margin-top: 20px;\n margin-bottom: 10px;\n }\n .thank-you-message-countdown {\n margin-left: 6px;\n }\n .bottom-section {\n margin-top: 14px;\n }\n `\n}\n\nfunction nameToHex(name: string) {\n return {\n aliceblue: '#f0f8ff',\n antiquewhite: '#faebd7',\n aqua: '#00ffff',\n aquamarine: '#7fffd4',\n azure: '#f0ffff',\n beige: '#f5f5dc',\n bisque: '#ffe4c4',\n black: '#000000',\n blanchedalmond: '#ffebcd',\n blue: '#0000ff',\n blueviolet: '#8a2be2',\n brown: '#a52a2a',\n burlywood: '#deb887',\n cadetblue: '#5f9ea0',\n chartreuse: '#7fff00',\n chocolate: '#d2691e',\n coral: '#ff7f50',\n cornflowerblue: '#6495ed',\n cornsilk: '#fff8dc',\n crimson: '#dc143c',\n cyan: '#00ffff',\n darkblue: '#00008b',\n darkcyan: '#008b8b',\n darkgoldenrod: '#b8860b',\n darkgray: '#a9a9a9',\n darkgreen: '#006400',\n darkkhaki: '#bdb76b',\n darkmagenta: '#8b008b',\n darkolivegreen: '#556b2f',\n darkorange: '#ff8c00',\n darkorchid: '#9932cc',\n darkred: '#8b0000',\n darksalmon: '#e9967a',\n darkseagreen: '#8fbc8f',\n darkslateblue: '#483d8b',\n darkslategray: '#2f4f4f',\n darkturquoise: '#00ced1',\n darkviolet: '#9400d3',\n deeppink: '#ff1493',\n deepskyblue: '#00bfff',\n dimgray: '#696969',\n dodgerblue: '#1e90ff',\n firebrick: '#b22222',\n floralwhite: '#fffaf0',\n forestgreen: '#228b22',\n fuchsia: '#ff00ff',\n gainsboro: '#dcdcdc',\n ghostwhite: '#f8f8ff',\n gold: '#ffd700',\n goldenrod: '#daa520',\n gray: '#808080',\n green: '#008000',\n greenyellow: '#adff2f',\n honeydew: '#f0fff0',\n hotpink: '#ff69b4',\n 'indianred ': '#cd5c5c',\n indigo: '#4b0082',\n ivory: '#fffff0',\n khaki: '#f0e68c',\n lavender: '#e6e6fa',\n lavenderblush: '#fff0f5',\n lawngreen: '#7cfc00',\n lemonchiffon: '#fffacd',\n lightblue: '#add8e6',\n lightcoral: '#f08080',\n lightcyan: '#e0ffff',\n lightgoldenrodyellow: '#fafad2',\n lightgrey: '#d3d3d3',\n lightgreen: '#90ee90',\n lightpink: '#ffb6c1',\n lightsalmon: '#ffa07a',\n lightseagreen: '#20b2aa',\n lightskyblue: '#87cefa',\n lightslategray: '#778899',\n lightsteelblue: '#b0c4de',\n lightyellow: '#ffffe0',\n lime: '#00ff00',\n limegreen: '#32cd32',\n linen: '#faf0e6',\n magenta: '#ff00ff',\n maroon: '#800000',\n mediumaquamarine: '#66cdaa',\n mediumblue: '#0000cd',\n mediumorchid: '#ba55d3',\n mediumpurple: '#9370d8',\n mediumseagreen: '#3cb371',\n mediumslateblue: '#7b68ee',\n mediumspringgreen: '#00fa9a',\n mediumturquoise: '#48d1cc',\n mediumvioletred: '#c71585',\n midnightblue: '#191970',\n mintcream: '#f5fffa',\n mistyrose: '#ffe4e1',\n moccasin: '#ffe4b5',\n navajowhite: '#ffdead',\n navy: '#000080',\n oldlace: '#fdf5e6',\n olive: '#808000',\n olivedrab: '#6b8e23',\n orange: '#ffa500',\n orangered: '#ff4500',\n orchid: '#da70d6',\n palegoldenrod: '#eee8aa',\n palegreen: '#98fb98',\n paleturquoise: '#afeeee',\n palevioletred: '#d87093',\n papayawhip: '#ffefd5',\n peachpuff: '#ffdab9',\n peru: '#cd853f',\n pink: '#ffc0cb',\n plum: '#dda0dd',\n powderblue: '#b0e0e6',\n purple: '#800080',\n red: '#ff0000',\n rosybrown: '#bc8f8f',\n royalblue: '#4169e1',\n saddlebrown: '#8b4513',\n salmon: '#fa8072',\n sandybrown: '#f4a460',\n seagreen: '#2e8b57',\n seashell: '#fff5ee',\n sienna: '#a0522d',\n silver: '#c0c0c0',\n skyblue: '#87ceeb',\n slateblue: '#6a5acd',\n slategray: '#708090',\n snow: '#fffafa',\n springgreen: '#00ff7f',\n steelblue: '#4682b4',\n tan: '#d2b48c',\n teal: '#008080',\n thistle: '#d8bfd8',\n tomato: '#ff6347',\n turquoise: '#40e0d0',\n violet: '#ee82ee',\n wheat: '#f5deb3',\n white: '#ffffff',\n whitesmoke: '#f5f5f5',\n yellow: '#ffff00',\n yellowgreen: '#9acd32',\n }[name.toLowerCase()]\n}\n\nfunction hex2rgb(c: string) {\n if (c[0] === '#') {\n const hexColor = c.replace(/^#/, '')\n const r = parseInt(hexColor.slice(0, 2), 16)\n const g = parseInt(hexColor.slice(2, 4), 16)\n const b = parseInt(hexColor.slice(4, 6), 16)\n return 'rgb(' + r + ',' + g + ',' + b + ')'\n }\n return 'rgb(255, 255, 255)'\n}\n\nexport function getContrastingTextColor(color: string = defaultBackgroundColor) {\n let rgb\n if (color[0] === '#') {\n rgb = hex2rgb(color)\n }\n if (color.startsWith('rgb')) {\n rgb = color\n }\n // otherwise it's a color name\n const nameColorToHex = nameToHex(color)\n if (nameColorToHex) {\n rgb = hex2rgb(nameColorToHex)\n }\n if (!rgb) {\n return 'black'\n }\n const colorMatch = rgb.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (colorMatch) {\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n }\n return 'black'\n}\nexport function getTextColor(el: HTMLElement) {\n const backgroundColor = window.getComputedStyle(el).backgroundColor\n if (backgroundColor === 'rgba(0, 0, 0, 0)') {\n return 'black'\n }\n const colorMatch = backgroundColor.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (!colorMatch) return 'black'\n\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n}\n\nexport const defaultSurveyAppearance: SurveyAppearance = {\n backgroundColor: '#eeeded',\n submitButtonColor: 'black',\n ratingButtonColor: 'white',\n ratingButtonActiveColor: 'black',\n borderColor: '#c9c6c6',\n placeholder: 'Start typing...',\n whiteLabel: false,\n displayThankYouMessage: true,\n thankYouMessageHeader: 'Thank you for your feedback!',\n position: 'right',\n}\n\nexport const defaultBackgroundColor = '#eeeded'\n\nexport const createShadow = (styleSheet: string, surveyId: string) => {\n const div = document.createElement('div')\n div.className = `PostHogSurvey${surveyId}`\n const shadow = div.attachShadow({ mode: 'open' })\n if (styleSheet) {\n const styleElement = Object.assign(document.createElement('style'), {\n innerText: styleSheet,\n })\n shadow.appendChild(styleElement)\n }\n document.body.appendChild(div)\n return shadow\n}\n\nexport const sendSurveyEvent = (\n responses: Record<string, string | number | string[] | null> = {},\n survey: Survey,\n posthog?: PostHog\n) => {\n if (!posthog) return\n localStorage.setItem(`seenSurvey_${survey.id}`, 'true')\n posthog.capture('survey sent', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n $survey_questions: survey.questions.map((question) => question.question),\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n ...responses,\n $set: {\n [`$survey_responded/${survey.id}`]: true,\n },\n })\n window.dispatchEvent(new Event('PHSurveySent'))\n}\n\n// Use the Fisher-yates algorithm to shuffle this array\n// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\nexport const shuffle = (array: any[]) => {\n return array\n .map((a) => ({ sort: Math.floor(Math.random() * 10), value: a }))\n .sort((a, b) => a.sort - b.sort)\n .map((a) => a.value)\n}\n\nconst reverseIfUnshuffled = (unshuffled: string[], shuffled: string[]): string[] => {\n if (unshuffled.length === shuffled.length && unshuffled.every((val, index) => val === shuffled[index])) {\n return shuffled.reverse()\n }\n\n return shuffled\n}\n\nexport const getDisplayOrderChoices = (question: MultipleSurveyQuestion): string[] => {\n if (!question.shuffleOptions) {\n return question.choices\n }\n\n const displayOrderChoices = question.choices\n let openEndedChoice = ''\n if (question.hasOpenChoice) {\n // if the question has an open-ended choice, its always the last element in the choices array.\n openEndedChoice = displayOrderChoices.pop()!\n }\n\n const shuffledOptions = reverseIfUnshuffled(displayOrderChoices, shuffle(displayOrderChoices))\n\n if (question.hasOpenChoice) {\n question.choices.push(openEndedChoice)\n shuffledOptions.push(openEndedChoice)\n }\n\n return shuffledOptions\n}\n\nexport const getDisplayOrderQuestions = (survey: Survey): SurveyQuestion[] => {\n if (!survey.appearance || !survey.appearance.shuffleQuestions) {\n return survey.questions\n }\n\n // retain the original questionIndex so we can correlate values in the webapp\n survey.questions.forEach((element, idx) => {\n element.questionIndex = idx\n })\n\n return shuffle(survey.questions)\n}\n\nexport const SurveyContext = createContext<{\n readOnly: boolean\n previewQuestionIndex: number\n textColor: string\n}>({\n readOnly: false,\n previewQuestionIndex: 0,\n textColor: 'black',\n})\n"]}
1
+ {"version":3,"file":"surveys-utils.jsx","sourceRoot":"","sources":["../../../../src/extensions/surveys/surveys-utils.tsx"],"names":[],"mappings":";;;;;;;;;;;AAEA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,QAAQ,IAAI,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC9E,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AACtC,gGAAgG;AAChG,IAAM,MAAM,GAAG,OAAqC,CAAA;AACpD,IAAM,QAAQ,GAAG,SAAqB,CAAA;AAEtC,MAAM,CAAC,IAAM,KAAK,GAAG,UAAC,UAAmC;IACrD,IAAM,SAAS,GAAG;QACd,IAAI,EAAE,aAAa;QACnB,KAAK,EAAE,cAAc;QACrB,MAAM,EAAE,gFAGL;KACN,CAAA;IACD,OAAO,2bASgB,QAAQ,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,QAAQ,KAAI,KAAK,CAAC,yCACzC,QAAQ,CAAC,CAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,MAAM,KAAI,OAAO,CAAC,kDAC5B,CAAA,UAAU,aAAV,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;IACxC,CAAC,CAAC,CAAA;IAEF,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,gBAAgB,EAAE;QAC3D,OAAO,MAAM,CAAC,SAAS,CAAA;KAC1B;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAA;AACpC,CAAC,CAAA;AAED,MAAM,CAAC,IAAM,aAAa,GAAG,aAAa,CAIvC;IACC,aAAa,EAAE,KAAK;IACpB,gBAAgB,EAAE,CAAC;IACnB,sBAAsB,EAAE,cAAO,CAAC;CACnC,CAAC,CAAA","sourcesContent":["import { PostHog } from '../../posthog-core'\nimport { Survey, SurveyAppearance, MultipleSurveyQuestion, SurveyQuestion } from '../../posthog-surveys-types'\nimport { window as _window, document as _document } from '../../utils/globals'\nimport { createContext } from 'preact'\n// We cast the types here which is dangerous but protected by the top level generateSurveys call\nconst window = _window as Window & typeof globalThis\nconst document = _document as Document\n\nexport const style = (appearance: SurveyAppearance | null) => {\n const positions = {\n left: 'left: 30px;',\n right: 'right: 30px;',\n center: `\n left: 50%;\n transform: translateX(-50%);\n `,\n }\n return `\n .survey-form {\n position: fixed;\n margin: 0px;\n bottom: 0px;\n color: black;\n font-weight: normal;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n text-align: left;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n border-bottom: 0px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .form-submit[disabled] {\n opacity: 0.6;\n filter: grayscale(50%);\n cursor: not-allowed;\n }\n .survey-form {\n flex-direction: column;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n }\n .survey-form textarea {\n color: #2d2d2d;\n font-size: 14px;\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n background: white;\n color: black;\n outline: none;\n padding-left: 10px;\n padding-right: 10px;\n padding-top: 10px;\n border-radius: 6px;\n border-color: ${appearance?.borderColor || '#c9c6c6'};\n margin-top: 14px;\n }\n .form-submit {\n box-sizing: border-box;\n margin: 0;\n font-family: inherit;\n overflow: visible;\n text-transform: none;\n position: relative;\n display: inline-block;\n font-weight: 700;\n white-space: nowrap;\n text-align: center;\n border: 1.5px solid transparent;\n cursor: pointer;\n user-select: none;\n touch-action: manipulation;\n padding: 12px;\n font-size: 14px;\n border-radius: 6px;\n outline: 0;\n background: ${appearance?.submitButtonColor || 'black'} !important;\n text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);\n box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);\n width: 100%;\n }\n .form-cancel {\n float: right;\n border: none;\n background: none;\n cursor: pointer;\n }\n .cancel-btn-wrapper {\n position: absolute;\n width: 35px;\n height: 35px;\n border-radius: 100%;\n top: 0;\n right: 0;\n transform: translate(50%, -50%);\n background: white;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n display: flex;\n justify-content: center;\n align-items: center;\n }\n .bolded { font-weight: 600; }\n .buttons {\n display: flex;\n justify-content: center;\n }\n .footer-branding {\n font-size: 11px;\n margin-top: 10px;\n text-align: center;\n display: flex;\n justify-content: center;\n gap: 4px;\n align-items: center;\n font-weight: 500;\n background: ${appearance?.backgroundColor || '#eeeded'};\n text-decoration: none;\n }\n .survey-box {\n padding: 20px 25px 10px;\n display: flex;\n flex-direction: column;\n border-radius: 10px;\n }\n .survey-question {\n font-weight: 500;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .question-textarea-wrapper {\n display: flex;\n flex-direction: column;\n }\n .description {\n font-size: 13px;\n padding-top: 5px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .ratings-number {\n background-color: ${appearance?.ratingButtonColor || 'white'};\n font-size: 16px;\n font-weight: 600;\n padding: 8px 0px;\n border: none;\n }\n .ratings-number:hover {\n cursor: pointer;\n }\n .rating-options {\n margin-top: 14px;\n }\n .rating-options-number {\n display: grid;\n border-radius: 6px;\n overflow: hidden;\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number {\n border-right: 1px solid ${appearance?.borderColor || '#c9c6c6'};\n }\n .rating-options-number > .ratings-number:last-of-type {\n border-right: 0px;\n }\n .rating-options-number .rating-active {\n background: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .rating-options-emoji {\n display: flex;\n justify-content: space-between;\n }\n .ratings-emoji {\n font-size: 16px;\n background-color: transparent;\n border: none;\n padding: 0px;\n }\n .ratings-emoji:hover {\n cursor: pointer;\n }\n .ratings-emoji.rating-active svg {\n fill: ${appearance?.ratingButtonActiveColor || 'black'};\n }\n .emoji-svg {\n fill: ${appearance?.ratingButtonColor || '#c9c6c6'};\n }\n .rating-text {\n display: flex;\n flex-direction: row;\n font-size: 11px;\n justify-content: space-between;\n margin-top: 6px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n opacity: .60;\n }\n .multiple-choice-options {\n margin-top: 13px;\n font-size: 14px;\n }\n .multiple-choice-options .choice-option {\n display: flex;\n align-items: center;\n gap: 4px;\n font-size: 13px;\n cursor: pointer;\n margin-bottom: 5px;\n position: relative;\n }\n .multiple-choice-options > .choice-option:last-of-type {\n margin-bottom: 0px;\n }\n .multiple-choice-options input {\n cursor: pointer;\n position: absolute;\n opacity: 0;\n }\n .choice-check {\n position: absolute;\n right: 10px;\n background: white;\n }\n .choice-check svg {\n display: none;\n }\n .multiple-choice-options .choice-option:hover .choice-check svg {\n display: inline-block;\n opacity: .25;\n }\n .multiple-choice-options input:checked + label + .choice-check svg {\n display: inline-block;\n opacity: 100% !important;\n }\n .multiple-choice-options input:checked + label {\n font-weight: bold;\n border: 1.5px solid rgba(0,0,0);\n }\n .multiple-choice-options input:checked + label input {\n font-weight: bold;\n }\n .multiple-choice-options label {\n width: 100%;\n cursor: pointer;\n padding: 10px;\n border: 1.5px solid rgba(0,0,0,.25);\n border-radius: 4px;\n background: white;\n }\n .multiple-choice-options .choice-option-open label {\n padding-right: 30px;\n display: flex;\n flex-wrap: wrap;\n gap: 8px;\n max-width: 100%;\n }\n .multiple-choice-options .choice-option-open label span {\n width: 100%;\n }\n .multiple-choice-options .choice-option-open input:disabled + label {\n opacity: 0.6;\n }\n .multiple-choice-options .choice-option-open label input {\n position: relative;\n opacity: 1;\n flex-grow: 1;\n border: 0;\n outline: 0;\n }\n .thank-you-message {\n position: fixed;\n bottom: 0px;\n z-index: ${parseInt(appearance?.zIndex || '99999')};\n box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);\n font-family: -apple-system, BlinkMacSystemFont, \"Inter\", \"Segoe UI\", \"Roboto\", Helvetica, Arial, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\";\n border-top-left-radius: 10px;\n border-top-right-radius: 10px;\n padding: 20px 25px 10px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n border: 1.5px solid ${appearance?.borderColor || '#c9c6c6'};\n text-align: center;\n max-width: ${parseInt(appearance?.maxWidth || '300')}px;\n min-width: 150px;\n width: 100%;\n ${positions[appearance?.position || 'right'] || 'right: 30px;'}\n }\n .thank-you-message-body {\n margin-top: 6px;\n font-size: 14px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-header {\n margin: 10px 0px 0px;\n background: ${appearance?.backgroundColor || '#eeeded'};\n }\n .thank-you-message-container .form-submit {\n margin-top: 20px;\n margin-bottom: 10px;\n }\n .thank-you-message-countdown {\n margin-left: 6px;\n }\n .bottom-section {\n margin-top: 14px;\n }\n `\n}\n\nfunction nameToHex(name: string) {\n return {\n aliceblue: '#f0f8ff',\n antiquewhite: '#faebd7',\n aqua: '#00ffff',\n aquamarine: '#7fffd4',\n azure: '#f0ffff',\n beige: '#f5f5dc',\n bisque: '#ffe4c4',\n black: '#000000',\n blanchedalmond: '#ffebcd',\n blue: '#0000ff',\n blueviolet: '#8a2be2',\n brown: '#a52a2a',\n burlywood: '#deb887',\n cadetblue: '#5f9ea0',\n chartreuse: '#7fff00',\n chocolate: '#d2691e',\n coral: '#ff7f50',\n cornflowerblue: '#6495ed',\n cornsilk: '#fff8dc',\n crimson: '#dc143c',\n cyan: '#00ffff',\n darkblue: '#00008b',\n darkcyan: '#008b8b',\n darkgoldenrod: '#b8860b',\n darkgray: '#a9a9a9',\n darkgreen: '#006400',\n darkkhaki: '#bdb76b',\n darkmagenta: '#8b008b',\n darkolivegreen: '#556b2f',\n darkorange: '#ff8c00',\n darkorchid: '#9932cc',\n darkred: '#8b0000',\n darksalmon: '#e9967a',\n darkseagreen: '#8fbc8f',\n darkslateblue: '#483d8b',\n darkslategray: '#2f4f4f',\n darkturquoise: '#00ced1',\n darkviolet: '#9400d3',\n deeppink: '#ff1493',\n deepskyblue: '#00bfff',\n dimgray: '#696969',\n dodgerblue: '#1e90ff',\n firebrick: '#b22222',\n floralwhite: '#fffaf0',\n forestgreen: '#228b22',\n fuchsia: '#ff00ff',\n gainsboro: '#dcdcdc',\n ghostwhite: '#f8f8ff',\n gold: '#ffd700',\n goldenrod: '#daa520',\n gray: '#808080',\n green: '#008000',\n greenyellow: '#adff2f',\n honeydew: '#f0fff0',\n hotpink: '#ff69b4',\n 'indianred ': '#cd5c5c',\n indigo: '#4b0082',\n ivory: '#fffff0',\n khaki: '#f0e68c',\n lavender: '#e6e6fa',\n lavenderblush: '#fff0f5',\n lawngreen: '#7cfc00',\n lemonchiffon: '#fffacd',\n lightblue: '#add8e6',\n lightcoral: '#f08080',\n lightcyan: '#e0ffff',\n lightgoldenrodyellow: '#fafad2',\n lightgrey: '#d3d3d3',\n lightgreen: '#90ee90',\n lightpink: '#ffb6c1',\n lightsalmon: '#ffa07a',\n lightseagreen: '#20b2aa',\n lightskyblue: '#87cefa',\n lightslategray: '#778899',\n lightsteelblue: '#b0c4de',\n lightyellow: '#ffffe0',\n lime: '#00ff00',\n limegreen: '#32cd32',\n linen: '#faf0e6',\n magenta: '#ff00ff',\n maroon: '#800000',\n mediumaquamarine: '#66cdaa',\n mediumblue: '#0000cd',\n mediumorchid: '#ba55d3',\n mediumpurple: '#9370d8',\n mediumseagreen: '#3cb371',\n mediumslateblue: '#7b68ee',\n mediumspringgreen: '#00fa9a',\n mediumturquoise: '#48d1cc',\n mediumvioletred: '#c71585',\n midnightblue: '#191970',\n mintcream: '#f5fffa',\n mistyrose: '#ffe4e1',\n moccasin: '#ffe4b5',\n navajowhite: '#ffdead',\n navy: '#000080',\n oldlace: '#fdf5e6',\n olive: '#808000',\n olivedrab: '#6b8e23',\n orange: '#ffa500',\n orangered: '#ff4500',\n orchid: '#da70d6',\n palegoldenrod: '#eee8aa',\n palegreen: '#98fb98',\n paleturquoise: '#afeeee',\n palevioletred: '#d87093',\n papayawhip: '#ffefd5',\n peachpuff: '#ffdab9',\n peru: '#cd853f',\n pink: '#ffc0cb',\n plum: '#dda0dd',\n powderblue: '#b0e0e6',\n purple: '#800080',\n red: '#ff0000',\n rosybrown: '#bc8f8f',\n royalblue: '#4169e1',\n saddlebrown: '#8b4513',\n salmon: '#fa8072',\n sandybrown: '#f4a460',\n seagreen: '#2e8b57',\n seashell: '#fff5ee',\n sienna: '#a0522d',\n silver: '#c0c0c0',\n skyblue: '#87ceeb',\n slateblue: '#6a5acd',\n slategray: '#708090',\n snow: '#fffafa',\n springgreen: '#00ff7f',\n steelblue: '#4682b4',\n tan: '#d2b48c',\n teal: '#008080',\n thistle: '#d8bfd8',\n tomato: '#ff6347',\n turquoise: '#40e0d0',\n violet: '#ee82ee',\n wheat: '#f5deb3',\n white: '#ffffff',\n whitesmoke: '#f5f5f5',\n yellow: '#ffff00',\n yellowgreen: '#9acd32',\n }[name.toLowerCase()]\n}\n\nfunction hex2rgb(c: string) {\n if (c[0] === '#') {\n const hexColor = c.replace(/^#/, '')\n const r = parseInt(hexColor.slice(0, 2), 16)\n const g = parseInt(hexColor.slice(2, 4), 16)\n const b = parseInt(hexColor.slice(4, 6), 16)\n return 'rgb(' + r + ',' + g + ',' + b + ')'\n }\n return 'rgb(255, 255, 255)'\n}\n\nexport function getContrastingTextColor(color: string = defaultBackgroundColor) {\n let rgb\n if (color[0] === '#') {\n rgb = hex2rgb(color)\n }\n if (color.startsWith('rgb')) {\n rgb = color\n }\n // otherwise it's a color name\n const nameColorToHex = nameToHex(color)\n if (nameColorToHex) {\n rgb = hex2rgb(nameColorToHex)\n }\n if (!rgb) {\n return 'black'\n }\n const colorMatch = rgb.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (colorMatch) {\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n }\n return 'black'\n}\nexport function getTextColor(el: HTMLElement) {\n const backgroundColor = window.getComputedStyle(el).backgroundColor\n if (backgroundColor === 'rgba(0, 0, 0, 0)') {\n return 'black'\n }\n const colorMatch = backgroundColor.match(/^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*(\\d+(?:\\.\\d+)?))?\\)$/)\n if (!colorMatch) return 'black'\n\n const r = parseInt(colorMatch[1])\n const g = parseInt(colorMatch[2])\n const b = parseInt(colorMatch[3])\n const hsp = Math.sqrt(0.299 * (r * r) + 0.587 * (g * g) + 0.114 * (b * b))\n return hsp > 127.5 ? 'black' : 'white'\n}\n\nexport const defaultSurveyAppearance: SurveyAppearance = {\n backgroundColor: '#eeeded',\n submitButtonColor: 'black',\n ratingButtonColor: 'white',\n ratingButtonActiveColor: 'black',\n borderColor: '#c9c6c6',\n placeholder: 'Start typing...',\n whiteLabel: false,\n displayThankYouMessage: true,\n thankYouMessageHeader: 'Thank you for your feedback!',\n position: 'right',\n}\n\nexport const defaultBackgroundColor = '#eeeded'\n\nexport const createShadow = (styleSheet: string, surveyId: string) => {\n const div = document.createElement('div')\n div.className = `PostHogSurvey${surveyId}`\n const shadow = div.attachShadow({ mode: 'open' })\n if (styleSheet) {\n const styleElement = Object.assign(document.createElement('style'), {\n innerText: styleSheet,\n })\n shadow.appendChild(styleElement)\n }\n document.body.appendChild(div)\n return shadow\n}\n\nexport const sendSurveyEvent = (\n responses: Record<string, string | number | string[] | null> = {},\n survey: Survey,\n posthog?: PostHog\n) => {\n if (!posthog) return\n localStorage.setItem(`seenSurvey_${survey.id}`, 'true')\n posthog.capture('survey sent', {\n $survey_name: survey.name,\n $survey_id: survey.id,\n $survey_questions: survey.questions.map((question) => question.question),\n sessionRecordingUrl: posthog.get_session_replay_url?.(),\n ...responses,\n $set: {\n [`$survey_responded/${survey.id}`]: true,\n },\n })\n window.dispatchEvent(new Event('PHSurveySent'))\n}\n\n// Use the Fisher-yates algorithm to shuffle this array\n// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\nexport const shuffle = (array: any[]) => {\n return array\n .map((a) => ({ sort: Math.floor(Math.random() * 10), value: a }))\n .sort((a, b) => a.sort - b.sort)\n .map((a) => a.value)\n}\n\nconst reverseIfUnshuffled = (unshuffled: string[], shuffled: string[]): string[] => {\n if (unshuffled.length === shuffled.length && unshuffled.every((val, index) => val === shuffled[index])) {\n return shuffled.reverse()\n }\n\n return shuffled\n}\n\nexport const getDisplayOrderChoices = (question: MultipleSurveyQuestion): string[] => {\n if (!question.shuffleOptions) {\n return question.choices\n }\n\n const displayOrderChoices = question.choices\n let openEndedChoice = ''\n if (question.hasOpenChoice) {\n // if the question has an open-ended choice, its always the last element in the choices array.\n openEndedChoice = displayOrderChoices.pop()!\n }\n\n const shuffledOptions = reverseIfUnshuffled(displayOrderChoices, shuffle(displayOrderChoices))\n\n if (question.hasOpenChoice) {\n question.choices.push(openEndedChoice)\n shuffledOptions.push(openEndedChoice)\n }\n\n return shuffledOptions\n}\n\nexport const getDisplayOrderQuestions = (survey: Survey): SurveyQuestion[] => {\n // retain the original questionIndex so we can correlate values in the webapp\n survey.questions.forEach((question, idx) => {\n question.originalQuestionIndex = idx\n })\n\n if (!survey.appearance || !survey.appearance.shuffleQuestions) {\n return survey.questions\n }\n\n return shuffle(survey.questions)\n}\n\nexport const SurveyContext = createContext<{\n isPreviewMode: boolean\n previewPageIndex: number | undefined\n handleCloseSurveyPopup: () => void\n}>({\n isPreviewMode: false,\n previewPageIndex: 0,\n handleCloseSurveyPopup: () => {},\n})\n"]}
@@ -1,16 +1,14 @@
1
1
  import { PostHog } from '../posthog-core';
2
2
  import { Survey } from '../posthog-surveys-types';
3
3
  export declare const callSurveys: (posthog: PostHog, forceReload?: boolean) => void;
4
- export declare const renderSurveysPreview: (survey: Survey, root: HTMLElement, displayState: 'survey' | 'confirmation', previewQuestionIndex: number) => void;
4
+ export declare const renderSurveysPreview: (survey: Survey, parentElement: HTMLElement, previewPageIndex: number) => void;
5
5
  export declare const renderFeedbackWidgetPreview: (survey: Survey, root: HTMLElement) => void;
6
6
  export declare function generateSurveys(posthog: PostHog): void;
7
- export declare function Surveys({ survey, posthog, readOnly, style, initialDisplayState, previewQuestionIndex, }: {
7
+ export declare function SurveyPopup({ survey, posthog, style, previewPageIndex, }: {
8
8
  survey: Survey;
9
9
  posthog?: PostHog;
10
- readOnly?: boolean;
11
10
  style?: React.CSSProperties;
12
- initialDisplayState?: 'survey' | 'confirmation' | 'closed';
13
- previewQuestionIndex?: number;
11
+ previewPageIndex?: number | undefined;
14
12
  }): JSX.Element;
15
13
  export declare function Questions({ survey, posthog, styleOverrides, }: {
16
14
  survey: Survey;