posthog-react-native 4.74.1 → 4.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PostHogContext.js +2 -1
- package/dist/PostHogContext.js.map +1 -1
- package/dist/PostHogErrorBoundary.js +2 -1
- package/dist/PostHogErrorBoundary.js.map +1 -1
- package/dist/PostHogMaskView.js +2 -1
- package/dist/PostHogMaskView.js.map +1 -1
- package/dist/PostHogProvider.js +2 -1
- package/dist/PostHogProvider.js.map +1 -1
- package/dist/autocapture.d.ts +1 -1
- package/dist/autocapture.js +2 -1
- package/dist/autocapture.js.map +1 -1
- package/dist/error-tracking/exception-context.js +2 -1
- package/dist/error-tracking/exception-context.js.map +1 -1
- package/dist/error-tracking/index.js +2 -1
- package/dist/error-tracking/index.js.map +1 -1
- package/dist/error-tracking/utils.js +2 -1
- package/dist/error-tracking/utils.js.map +1 -1
- package/dist/frameworks/wix-navigation.js +2 -1
- package/dist/frameworks/wix-navigation.js.map +1 -1
- package/dist/hooks/useFeatureFlag.js +2 -1
- package/dist/hooks/useFeatureFlag.js.map +1 -1
- package/dist/hooks/useFeatureFlagResult.js +2 -1
- package/dist/hooks/useFeatureFlagResult.js.map +1 -1
- package/dist/hooks/useFeatureFlags.js +2 -1
- package/dist/hooks/useFeatureFlags.js.map +1 -1
- package/dist/hooks/useNavigationTracker.js +2 -1
- package/dist/hooks/useNavigationTracker.js.map +1 -1
- package/dist/hooks/usePostHog.js +2 -1
- package/dist/hooks/usePostHog.js.map +1 -1
- package/dist/hooks/utils.js +2 -1
- package/dist/hooks/utils.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/logs-defaults.js +2 -1
- package/dist/logs-defaults.js.map +1 -1
- package/dist/native-deps.js +2 -1
- package/dist/native-deps.js.map +1 -1
- package/dist/optional/OptionalAsyncStorage.js +2 -1
- package/dist/optional/OptionalAsyncStorage.js.map +1 -1
- package/dist/optional/OptionalExpoApplication.js +2 -1
- package/dist/optional/OptionalExpoApplication.js.map +1 -1
- package/dist/optional/OptionalExpoDevice.js +2 -1
- package/dist/optional/OptionalExpoDevice.js.map +1 -1
- package/dist/optional/OptionalExpoFileSystem.js +2 -1
- package/dist/optional/OptionalExpoFileSystem.js.map +1 -1
- package/dist/optional/OptionalExpoFileSystemLegacy.js +2 -1
- package/dist/optional/OptionalExpoFileSystemLegacy.js.map +1 -1
- package/dist/optional/OptionalExpoLocalization.js +2 -1
- package/dist/optional/OptionalExpoLocalization.js.map +1 -1
- package/dist/optional/OptionalExpoUpdates.js +2 -1
- package/dist/optional/OptionalExpoUpdates.js.map +1 -1
- package/dist/optional/OptionalPlugin.js +2 -1
- package/dist/optional/OptionalPlugin.js.map +1 -1
- package/dist/optional/OptionalReactNativeDeviceInfo.js +2 -1
- package/dist/optional/OptionalReactNativeDeviceInfo.js.map +1 -1
- package/dist/optional/OptionalReactNativeLocalize.js +2 -1
- package/dist/optional/OptionalReactNativeLocalize.js.map +1 -1
- package/dist/optional/OptionalReactNativeNavigation.js +2 -1
- package/dist/optional/OptionalReactNativeNavigation.js.map +1 -1
- package/dist/optional/OptionalReactNativeNavigationWix.js +2 -1
- package/dist/optional/OptionalReactNativeNavigationWix.js.map +1 -1
- package/dist/optional/OptionalReactNativeSafeArea.js +2 -1
- package/dist/optional/OptionalReactNativeSafeArea.js.map +1 -1
- package/dist/optional/OptionalReactNativeSvg.js +2 -1
- package/dist/optional/OptionalReactNativeSvg.js.map +1 -1
- package/dist/posthog-rn.js +2 -1
- package/dist/posthog-rn.js.map +1 -1
- package/dist/storage.js +2 -1
- package/dist/storage.js.map +1 -1
- package/dist/surveys/PostHogSurveyProvider.js +2 -1
- package/dist/surveys/PostHogSurveyProvider.js.map +1 -1
- package/dist/surveys/components/BottomSection.js +2 -1
- package/dist/surveys/components/BottomSection.js.map +1 -1
- package/dist/surveys/components/Cancel.js +2 -1
- package/dist/surveys/components/Cancel.js.map +1 -1
- package/dist/surveys/components/ConfirmationMessage.js +2 -1
- package/dist/surveys/components/ConfirmationMessage.js.map +1 -1
- package/dist/surveys/components/IntroMessage.js +2 -1
- package/dist/surveys/components/IntroMessage.js.map +1 -1
- package/dist/surveys/components/QuestionHeader.js +2 -1
- package/dist/surveys/components/QuestionHeader.js.map +1 -1
- package/dist/surveys/components/QuestionTypes.js +2 -1
- package/dist/surveys/components/QuestionTypes.js.map +1 -1
- package/dist/surveys/components/SurveyModal.d.ts +5 -0
- package/dist/surveys/components/SurveyModal.js +2 -1
- package/dist/surveys/components/SurveyModal.js.map +1 -1
- package/dist/surveys/components/Surveys.d.ts +7 -4
- package/dist/surveys/components/Surveys.js +2 -1
- package/dist/surveys/components/Surveys.js.map +1 -1
- package/dist/surveys/getActiveMatchingSurveys.d.ts +1 -1
- package/dist/surveys/getActiveMatchingSurveys.js +2 -1
- package/dist/surveys/getActiveMatchingSurveys.js.map +1 -1
- package/dist/surveys/icons.js +2 -1
- package/dist/surveys/icons.js.map +1 -1
- package/dist/surveys/index.js +2 -1
- package/dist/surveys/index.js.map +1 -1
- package/dist/surveys/safeStyleSheet.js +2 -1
- package/dist/surveys/safeStyleSheet.js.map +1 -1
- package/dist/surveys/survey-progress.d.ts +23 -0
- package/dist/surveys/survey-progress.js +2 -0
- package/dist/surveys/survey-progress.js.map +1 -0
- package/dist/surveys/survey-shuffling.js +2 -1
- package/dist/surveys/survey-shuffling.js.map +1 -1
- package/dist/surveys/survey-translations.js +2 -1
- package/dist/surveys/survey-translations.js.map +1 -1
- package/dist/surveys/surveys-utils.d.ts +1 -1
- package/dist/surveys/surveys-utils.js +2 -1
- package/dist/surveys/surveys-utils.js.map +1 -1
- package/dist/surveys/useActivatedSurveys.js +2 -1
- package/dist/surveys/useActivatedSurveys.js.map +1 -1
- package/dist/surveys/useSurveyStorage.d.ts +3 -1
- package/dist/surveys/useSurveyStorage.js +2 -1
- package/dist/surveys/useSurveyStorage.js.map +1 -1
- package/dist/tooling/expoconfig.js +2 -1
- package/dist/tooling/expoconfig.js.map +1 -1
- package/dist/tooling/metroconfig.js +2 -1
- package/dist/tooling/metroconfig.js.map +1 -1
- package/dist/tooling/posthogMetroSerializer.js +2 -1
- package/dist/tooling/posthogMetroSerializer.js.map +1 -1
- package/dist/tooling/utils.js +2 -1
- package/dist/tooling/utils.js.map +1 -1
- package/dist/tooling/vendor/expo/expoconfig.js +2 -1
- package/dist/tooling/vendor/expo/expoconfig.js.map +1 -1
- package/dist/tooling/vendor/metro/countLines.d.ts +1 -1
- package/dist/tooling/vendor/metro/countLines.js +2 -1
- package/dist/tooling/vendor/metro/countLines.js.map +1 -1
- package/dist/tooling/vendor/metro/utils.js +2 -1
- package/dist/tooling/vendor/metro/utils.js.map +1 -1
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -1
- package/dist/utils.js +2 -1
- package/dist/utils.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +2 -1
- package/dist/version.js.map +1 -1
- package/package.json +6 -5
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createSafeStyleSheet=void 0;var _reactNative=require("react-native");var createSafeStyleSheet=exports.createSafeStyleSheet=function createSafeStyleSheet(styles){try{return typeof(_reactNative.StyleSheet===null||_reactNative.StyleSheet===void 0?void 0:_reactNative.StyleSheet.create)==='function'?_reactNative.StyleSheet.create(styles):styles;}catch(_a){return styles;}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.createSafeStyleSheet=void 0;var _reactNative=require("react-native");var createSafeStyleSheet=exports.createSafeStyleSheet=function createSafeStyleSheet(styles){try{return typeof(_reactNative.StyleSheet===null||_reactNative.StyleSheet===void 0?void 0:_reactNative.StyleSheet.create)==='function'?_reactNative.StyleSheet.create(styles):styles;}catch(_a){return styles;}};
|
|
2
|
+
//# sourceMappingURL=safeStyleSheet.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"safeStyleSheet.js","
|
|
1
|
+
{"version":3,"file":"safeStyleSheet.js","names":["_reactNative","require","createSafeStyleSheet","exports","styles","StyleSheet","create"],"sources":["../../src/surveys/safeStyleSheet.ts"],"sourcesContent":["import { StyleSheet } from 'react-native'\n\n/**\n * `StyleSheet.create` that returns the raw style map when the React Native\n * `StyleSheet` runtime is unavailable (e.g. Jest `testEnvironment: node` without\n * the RN preset), instead of throwing at import.\n * See https://github.com/PostHog/posthog-js/issues/3740.\n */\nexport const createSafeStyleSheet = <T extends StyleSheet.NamedStyles<T>>(styles: T): T => {\n try {\n return typeof StyleSheet?.create === 'function' ? StyleSheet.create(styles) : styles\n } catch {\n return styles\n }\n}\n"],"mappings":"0GAAA,IAAAA,YAAA,CAAAC,OAAA,iBAQO,GAAM,CAAAC,oBAAoB,CAAAC,OAAA,CAAAD,oBAAA,CAAG,QAAvB,CAAAA,oBAAoBA,CAAyCE,MAAS,CAAO,CACxF,GAAI,CACF,MAAO,QAAOC,uBAAU,SAAVA,uBAAU,iBAAVA,uBAAU,CAAEC,MAAM,IAAK,UAAU,CAAGD,uBAAU,CAACC,MAAM,CAACF,MAAM,CAAC,CAAGA,MAAM,CACtF,C,SAAQ,CACN,MAAO,CAAAA,MAAM,CACf,CACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Survey, SurveyResponses } from '@posthog/core';
|
|
2
|
+
import type { PostHog } from '../posthog-rn';
|
|
3
|
+
export type SurveyProgress = {
|
|
4
|
+
submissionId: string;
|
|
5
|
+
questionIndex: number;
|
|
6
|
+
questionOrder: number[];
|
|
7
|
+
responses: SurveyResponses;
|
|
8
|
+
questionSnapshots: Record<string, string>;
|
|
9
|
+
surveyLanguage?: string | null;
|
|
10
|
+
};
|
|
11
|
+
export declare function createSurveyProgress(survey: Survey): SurveyProgress;
|
|
12
|
+
export declare function canCaptureSurvey(posthog: PostHog): boolean;
|
|
13
|
+
export declare function getOtherProjectSurveyProgress(posthog: PostHog): unknown[];
|
|
14
|
+
export declare class SurveyProgressStore {
|
|
15
|
+
private readonly posthog;
|
|
16
|
+
constructor(posthog: PostHog);
|
|
17
|
+
private read;
|
|
18
|
+
private write;
|
|
19
|
+
load(survey: Survey): SurveyProgress | undefined;
|
|
20
|
+
save(survey: Survey, progress: SurveyProgress): void;
|
|
21
|
+
remove(survey: Survey): void;
|
|
22
|
+
reconcile(surveys: Survey[]): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.SurveyProgressStore=void 0;exports.canCaptureSurvey=canCaptureSurvey;exports.createSurveyProgress=createSurveyProgress;exports.getOtherProjectSurveyProgress=getOtherProjectSurveyProgress;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));var _createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof"));var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");var _surveyShuffling=require("./survey-shuffling");function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){(0,_defineProperty2["default"])(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function createSurveyProgress(survey){return{submissionId:(0,_core.uuidv7)(),questionIndex:0,questionOrder:(0,_surveyShuffling.getDisplayOrderQuestions)(survey).map(function(question){return question.originalQuestionIndex;}),responses:{},questionSnapshots:{}};}function questionShape(question){var base={id:question.id,type:question.type,optional:question.optional,branching:question.branching};switch(question.type){case _core.SurveyQuestionType.SingleChoice:case _core.SurveyQuestionType.MultipleChoice:return _objectSpread(_objectSpread({},base),{},{choices:question.choices,hasOpenChoice:question.hasOpenChoice});case _core.SurveyQuestionType.Rating:return _objectSpread(_objectSpread({},base),{},{scale:question.scale,display:question.display});case _core.SurveyQuestionType.Link:return _objectSpread(_objectSpread({},base),{},{link:question.link});default:return base;}}function surveyShape(survey){var _a;return JSON.stringify([survey.current_iteration_start_date,survey.enable_partial_responses,(_a=survey.appearance)===null||_a===void 0?void 0:_a.shuffleQuestions,survey.questions.map(questionShape)]);}var MAX_PROGRESS=20;var MAX_AGE=30*24*60*60*1000;function isRecord(value){return(0,_typeof2["default"])(value)==='object'&&value!==null&&!Array.isArray(value);}function isNonEmptyString(value){return typeof value==='string'&&value.length>0;}function isQuestionIndex(value,count){return typeof value==='number'&&Number.isInteger(value)&&value>=0&&value<count;}function isQuestionOrder(value,count){if(!Array.isArray(value)||value.length!==count||new Set(value).size!==count)return false;return value.every(function(index){return isQuestionIndex(index,count);});}function isResponse(value){if(value===null||typeof value==='string')return true;if(typeof value==='number')return Number.isFinite(value);return Array.isArray(value)&&value.every(function(item){return typeof item==='string';});}function validResponses(value,survey){if(!isRecord(value))return false;var keys=new Set(survey.questions.map(function(question){return(0,_surveys.getSurveyResponseKey)(question.id);}));return Object.entries(value).every(function(_ref){var _ref2=(0,_slicedToArray2["default"])(_ref,2),key=_ref2[0],response=_ref2[1];return keys.has(key)&&isResponse(response);});}function validSnapshots(value,survey){if(!isRecord(value))return false;var ids=new Set(survey.questions.map(function(question){return question.id;}));return Object.entries(value).every(function(_ref3){var _ref4=(0,_slicedToArray2["default"])(_ref3,2),id=_ref4[0],text=_ref4[1];return ids.has(id)&&typeof text==='string';});}function validProgress(value,survey){if(!isRecord(value))return false;var submissionId=value.submissionId,questionIndex=value.questionIndex,questionOrder=value.questionOrder,responses=value.responses,questionSnapshots=value.questionSnapshots,surveyLanguage=value.surveyLanguage;var languageIsValid=surveyLanguage==null||typeof surveyLanguage==='string';return isNonEmptyString(submissionId)&&languageIsValid&&isQuestionIndex(questionIndex,survey.questions.length)&&isQuestionOrder(questionOrder,survey.questions.length)&&validResponses(responses,survey)&&validSnapshots(questionSnapshots,survey);}function isRecent(value){return typeof value==='number'&&value>Date.now()-MAX_AGE&&value<=Date.now();}function isSavedProgress(value,project){if(!isRecord(value))return false;return value.project===project&&typeof value.surveyKey==='string'&&isNonEmptyString(value.shape)&&isRecent(value.updatedAt)&&isRecord(value.progress);}function canCaptureSurvey(posthog){return!posthog.optedOut&&!posthog.isDisabled;}function getOtherProjectSurveyProgress(posthog){var raw=posthog.getPersistedProperty(_core.PostHogPersistedProperty.SurveysInProgress);if(!Array.isArray(raw))return[];var counts=new Map();return raw.filter(function(entry){var _a;if(!isRecord(entry)||!isNonEmptyString(entry.project)||entry.project===posthog.apiKey)return false;if(!isSavedProgress(entry,entry.project))return false;var count=(_a=counts.get(entry.project))!==null&&_a!==void 0?_a:0;if(count>=MAX_PROGRESS)return false;counts.set(entry.project,count+1);return true;});}var SurveyProgressStore=exports.SurveyProgressStore=function(){function SurveyProgressStore(posthog){(0,_classCallCheck2["default"])(this,SurveyProgressStore);this.posthog=posthog;}return(0,_createClass2["default"])(SurveyProgressStore,[{key:"read",value:function read(){var _this=this;var raw=this.posthog.getPersistedProperty(_core.PostHogPersistedProperty.SurveysInProgress);if(!Array.isArray(raw))return[];return raw.filter(function(entry){return isSavedProgress(entry,_this.posthog.apiKey);}).slice(0,MAX_PROGRESS);}},{key:"write",value:function write(entries){this.posthog.setPersistedProperty(_core.PostHogPersistedProperty.SurveysInProgress,[].concat((0,_toConsumableArray2["default"])(entries.slice(0,MAX_PROGRESS)),(0,_toConsumableArray2["default"])(getOtherProjectSurveyProgress(this.posthog))));}},{key:"load",value:function load(survey){var entry=this.read().find(function(entry){return entry.surveyKey===(0,_surveys.getSurveyIterationKey)(survey);});return(entry===null||entry===void 0?void 0:entry.shape)===surveyShape(survey)&&validProgress(entry.progress,survey)?entry.progress:undefined;}},{key:"save",value:function save(survey,progress){var surveyKey=(0,_surveys.getSurveyIterationKey)(survey);this.write([{project:this.posthog.apiKey,surveyKey:surveyKey,shape:surveyShape(survey),updatedAt:Date.now(),progress:progress}].concat((0,_toConsumableArray2["default"])(this.read().filter(function(entry){return entry.surveyKey!==surveyKey;}))));}},{key:"remove",value:function remove(survey){this.write(this.read().filter(function(entry){return entry.surveyKey!==(0,_surveys.getSurveyIterationKey)(survey);}));}},{key:"reconcile",value:function reconcile(surveys){var _this2=this;var validKeys=new Set(surveys.filter(function(survey){return survey.start_date&&!survey.end_date&&_this2.load(survey);}).map(_surveys.getSurveyIterationKey));this.write(this.read().filter(function(entry){return validKeys.has(entry.surveyKey);}));}}]);}();
|
|
2
|
+
//# sourceMappingURL=survey-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"survey-progress.js","names":["_core","require","_surveys","_surveyShuffling","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","createSurveyProgress","survey","submissionId","uuidv7","questionIndex","questionOrder","getDisplayOrderQuestions","map","question","originalQuestionIndex","responses","questionSnapshots","questionShape","base","id","type","optional","branching","SurveyQuestionType","SingleChoice","MultipleChoice","choices","hasOpenChoice","Rating","scale","display","Link","link","surveyShape","JSON","stringify","current_iteration_start_date","enable_partial_responses","_a","appearance","shuffleQuestions","questions","MAX_PROGRESS","MAX_AGE","isRecord","value","_typeof2","Array","isArray","isNonEmptyString","isQuestionIndex","count","Number","isInteger","isQuestionOrder","Set","size","every","index","isResponse","isFinite","item","validResponses","getSurveyResponseKey","entries","_ref","_ref2","_slicedToArray2","key","response","has","validSnapshots","ids","_ref3","_ref4","text","validProgress","surveyLanguage","languageIsValid","isRecent","Date","now","isSavedProgress","project","surveyKey","shape","updatedAt","progress","canCaptureSurvey","posthog","optedOut","isDisabled","getOtherProjectSurveyProgress","raw","getPersistedProperty","PostHogPersistedProperty","SurveysInProgress","counts","Map","entry","apiKey","get","set","SurveyProgressStore","exports","_classCallCheck2","_createClass2","read","_this","slice","write","setPersistedProperty","concat","_toConsumableArray2","load","find","getSurveyIterationKey","undefined","save","remove","reconcile","surveys","_this2","validKeys","start_date","end_date"],"sources":["../../src/surveys/survey-progress.ts"],"sourcesContent":["import {\n PostHogPersistedProperty,\n Survey,\n SurveyQuestion,\n SurveyQuestionType,\n SurveyResponses,\n uuidv7,\n} from '@posthog/core'\nimport { getSurveyIterationKey, getSurveyResponseKey } from '@posthog/core/surveys'\nimport type { PostHog } from '../posthog-rn'\nimport { getDisplayOrderQuestions } from './survey-shuffling'\n\nexport type SurveyProgress = {\n submissionId: string\n questionIndex: number\n questionOrder: number[]\n responses: SurveyResponses\n questionSnapshots: Record<string, string>\n surveyLanguage?: string | null\n}\n\nexport function createSurveyProgress(survey: Survey): SurveyProgress {\n return {\n submissionId: uuidv7(),\n questionIndex: 0,\n questionOrder: getDisplayOrderQuestions(survey).map((question) => question.originalQuestionIndex),\n responses: {},\n questionSnapshots: {},\n }\n}\n\n// Copy changes (including translations) do not invalidate answers. Changes to\n// question identity, response shape or branching must start a new submission.\nfunction questionShape(question: SurveyQuestion): object {\n const base = { id: question.id, type: question.type, optional: question.optional, branching: question.branching }\n switch (question.type) {\n case SurveyQuestionType.SingleChoice:\n case SurveyQuestionType.MultipleChoice:\n return { ...base, choices: question.choices, hasOpenChoice: question.hasOpenChoice }\n case SurveyQuestionType.Rating:\n return { ...base, scale: question.scale, display: question.display }\n case SurveyQuestionType.Link:\n return { ...base, link: question.link }\n default:\n return base\n }\n}\n\nfunction surveyShape(survey: Survey): string {\n return JSON.stringify([\n survey.current_iteration_start_date,\n survey.enable_partial_responses,\n survey.appearance?.shuffleQuestions,\n survey.questions.map(questionShape),\n ])\n}\n\ntype SavedProgress = {\n project: string\n surveyKey: string\n shape: string\n updatedAt: number\n progress: SurveyProgress\n}\n\nconst MAX_PROGRESS = 20\nconst MAX_AGE = 30 * 24 * 60 * 60 * 1000\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.length > 0\n}\n\nfunction isQuestionIndex(value: unknown, count: number): value is number {\n return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value < count\n}\n\nfunction isQuestionOrder(value: unknown, count: number): value is number[] {\n if (!Array.isArray(value) || value.length !== count || new Set(value).size !== count) return false\n return value.every((index) => isQuestionIndex(index, count))\n}\n\nfunction isResponse(value: unknown): boolean {\n if (value === null || typeof value === 'string') return true\n if (typeof value === 'number') return Number.isFinite(value)\n return Array.isArray(value) && value.every((item) => typeof item === 'string')\n}\n\nfunction validResponses(value: unknown, survey: Survey): boolean {\n if (!isRecord(value)) return false\n const keys = new Set(survey.questions.map((question) => getSurveyResponseKey(question.id)))\n return Object.entries(value).every(([key, response]) => keys.has(key) && isResponse(response))\n}\n\nfunction validSnapshots(value: unknown, survey: Survey): boolean {\n if (!isRecord(value)) return false\n const ids = new Set(survey.questions.map((question) => question.id))\n return Object.entries(value).every(([id, text]) => ids.has(id) && typeof text === 'string')\n}\n\nfunction validProgress(value: unknown, survey: Survey): value is SurveyProgress {\n if (!isRecord(value)) return false\n const { submissionId, questionIndex, questionOrder, responses, questionSnapshots, surveyLanguage } = value\n const languageIsValid = surveyLanguage == null || typeof surveyLanguage === 'string'\n return (\n isNonEmptyString(submissionId) &&\n languageIsValid &&\n isQuestionIndex(questionIndex, survey.questions.length) &&\n isQuestionOrder(questionOrder, survey.questions.length) &&\n validResponses(responses, survey) &&\n validSnapshots(questionSnapshots, survey)\n )\n}\n\nfunction isRecent(value: unknown): boolean {\n return typeof value === 'number' && value > Date.now() - MAX_AGE && value <= Date.now()\n}\n\nfunction isSavedProgress(value: unknown, project: string): value is SavedProgress {\n if (!isRecord(value)) return false\n return (\n value.project === project &&\n typeof value.surveyKey === 'string' &&\n isNonEmptyString(value.shape) &&\n isRecent(value.updatedAt) &&\n isRecord(value.progress)\n )\n}\n\nexport function canCaptureSurvey(posthog: PostHog): boolean {\n return !posthog.optedOut && !posthog.isDisabled\n}\n\nexport function getOtherProjectSurveyProgress(posthog: PostHog): unknown[] {\n const raw = posthog.getPersistedProperty<unknown>(PostHogPersistedProperty.SurveysInProgress)\n if (!Array.isArray(raw)) return []\n const counts = new Map<string, number>()\n return raw.filter((entry) => {\n if (!isRecord(entry) || !isNonEmptyString(entry.project) || entry.project === posthog.apiKey) return false\n if (!isSavedProgress(entry, entry.project)) return false\n const count = counts.get(entry.project) ?? 0\n if (count >= MAX_PROGRESS) return false\n counts.set(entry.project, count + 1)\n return true\n })\n}\n\nexport class SurveyProgressStore {\n constructor(private readonly posthog: PostHog) {}\n\n private read(): SavedProgress[] {\n const raw = this.posthog.getPersistedProperty<unknown>(PostHogPersistedProperty.SurveysInProgress)\n if (!Array.isArray(raw)) return []\n return raw\n .filter((entry): entry is SavedProgress => isSavedProgress(entry, this.posthog.apiKey))\n .slice(0, MAX_PROGRESS)\n }\n\n private write(entries: SavedProgress[]): void {\n this.posthog.setPersistedProperty(PostHogPersistedProperty.SurveysInProgress, [\n ...entries.slice(0, MAX_PROGRESS),\n ...getOtherProjectSurveyProgress(this.posthog),\n ])\n }\n\n load(survey: Survey): SurveyProgress | undefined {\n const entry = this.read().find((entry) => entry.surveyKey === getSurveyIterationKey(survey))\n return entry?.shape === surveyShape(survey) && validProgress(entry.progress, survey) ? entry.progress : undefined\n }\n\n save(survey: Survey, progress: SurveyProgress): void {\n const surveyKey = getSurveyIterationKey(survey)\n this.write([\n {\n project: this.posthog.apiKey,\n surveyKey,\n shape: surveyShape(survey),\n updatedAt: Date.now(),\n progress,\n },\n ...this.read().filter((entry) => entry.surveyKey !== surveyKey),\n ])\n }\n\n remove(survey: Survey): void {\n this.write(this.read().filter((entry) => entry.surveyKey !== getSurveyIterationKey(survey)))\n }\n\n reconcile(surveys: Survey[]): void {\n const validKeys = new Set(\n surveys.filter((survey) => survey.start_date && !survey.end_date && this.load(survey)).map(getSurveyIterationKey)\n )\n this.write(this.read().filter((entry) => validKeys.has(entry.surveyKey)))\n }\n}\n"],"mappings":"83BAAA,IAAAA,KAAA,CAAAC,OAAA,kBAQA,IAAAC,QAAA,CAAAD,OAAA,0BAEA,IAAAE,gBAAA,CAAAF,OAAA,uBAA6D,SAAAG,QAAAC,CAAA,CAAAC,CAAA,MAAAC,CAAA,CAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,KAAAG,MAAA,CAAAE,qBAAA,MAAAC,CAAA,CAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,CAAAC,CAAA,IAAAK,CAAA,CAAAA,CAAA,CAAAC,MAAA,UAAAN,CAAA,SAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,CAAAC,CAAA,EAAAQ,UAAA,KAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,CAAAI,CAAA,UAAAJ,CAAA,WAAAU,cAAAZ,CAAA,UAAAC,CAAA,GAAAA,CAAA,CAAAY,SAAA,CAAAC,MAAA,CAAAb,CAAA,QAAAC,CAAA,OAAAW,SAAA,CAAAZ,CAAA,EAAAY,SAAA,CAAAZ,CAAA,IAAAA,CAAA,IAAAF,OAAA,CAAAI,MAAA,CAAAD,CAAA,MAAAa,OAAA,UAAAd,CAAA,KAAAe,gBAAA,aAAAhB,CAAA,CAAAC,CAAA,CAAAC,CAAA,CAAAD,CAAA,MAAAE,MAAA,CAAAc,yBAAA,CAAAd,MAAA,CAAAe,gBAAA,CAAAl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AACwG,KAAK,CAAC,IAAI,CAACH,IAAI,EAAE,CAACnH,MAAM,CAAC,SAAC2G,KAAK,QAAK,CAAAA,KAAK,CAACf,SAAS,GAAK,GAAAgC,8BAAqB,EAAC9G,MAAM,CAAC,GAAC,CAAC,CAC9F,CAAC,GAAA8D,GAAA,aAAAvB,KAAA,CAED,SAAA2E,SAASA,CAACC,OAAiB,MAAAC,MAAA,MACzB,GAAM,CAAAC,SAAS,CAAG,GAAI,CAAApE,GAAG,CACvBkE,OAAO,CAACjI,MAAM,CAAC,SAACc,MAAM,QAAK,CAAAA,MAAM,CAACsH,UAAU,EAAI,CAACtH,MAAM,CAACuH,QAAQ,EAAIH,MAAI,CAACR,IAAI,CAAC5G,MAAM,CAAC,GAAC,CAACM,GAAG,CAACwG,8BAAqB,CAAC,CAClH,CACD,IAAI,CAACN,KAAK,CAAC,IAAI,CAACH,IAAI,EAAE,CAACnH,MAAM,CAAC,SAAC2G,KAAK,QAAK,CAAAwB,SAAS,CAACrD,GAAG,CAAC6B,KAAK,CAACf,SAAS,CAAC,GAAC,CAAC,CAC3E,CAAC","ignoreList":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"getDisplayOrderChoices",{enumerable:true,get:function get(){return _surveys.getDisplayOrderChoices;}});exports.shouldShuffleQuestions=exports.getDisplayOrderQuestions=void 0;Object.defineProperty(exports,"shuffle",{enumerable:true,get:function get(){return _surveys.shuffle;}});var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _surveys=require("@posthog/core/surveys");function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){(0,_defineProperty2["default"])(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}var hasBranching=function hasBranching(survey){return survey.questions.some(function(question){var _a;return!!((_a=question.branching)===null||_a===void 0?void 0:_a.type);});};var shouldShuffleQuestions=exports.shouldShuffleQuestions=function shouldShuffleQuestions(survey){var _a;var partialResponsesEnabled=survey.enable_partial_responses;return!!((_a=survey.appearance)===null||_a===void 0?void 0:_a.shuffleQuestions)&&!partialResponsesEnabled&&!hasBranching(survey);};var reverseIfUnshuffled=function reverseIfUnshuffled(unshuffled,shuffled){if(shuffled.length>1&&unshuffled.every(function(value,index){return value===shuffled[index];})){return shuffled.reverse();}return shuffled;};var getDisplayOrderQuestions=exports.getDisplayOrderQuestions=function getDisplayOrderQuestions(survey){var questions=survey.questions.map(function(question,originalQuestionIndex){return _objectSpread(_objectSpread({},question),{},{originalQuestionIndex:originalQuestionIndex});});if(!shouldShuffleQuestions(survey)){return questions;}return reverseIfUnshuffled(questions,(0,_surveys.shuffle)(questions));};
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"getDisplayOrderChoices",{enumerable:true,get:function get(){return _surveys.getDisplayOrderChoices;}});exports.shouldShuffleQuestions=exports.getDisplayOrderQuestions=void 0;Object.defineProperty(exports,"shuffle",{enumerable:true,get:function get(){return _surveys.shuffle;}});var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _surveys=require("@posthog/core/surveys");function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){(0,_defineProperty2["default"])(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}var hasBranching=function hasBranching(survey){return survey.questions.some(function(question){var _a;return!!((_a=question.branching)===null||_a===void 0?void 0:_a.type);});};var shouldShuffleQuestions=exports.shouldShuffleQuestions=function shouldShuffleQuestions(survey){var _a;var partialResponsesEnabled=survey.enable_partial_responses;return!!((_a=survey.appearance)===null||_a===void 0?void 0:_a.shuffleQuestions)&&!partialResponsesEnabled&&!hasBranching(survey);};var reverseIfUnshuffled=function reverseIfUnshuffled(unshuffled,shuffled){if(shuffled.length>1&&unshuffled.every(function(value,index){return value===shuffled[index];})){return shuffled.reverse();}return shuffled;};var getDisplayOrderQuestions=exports.getDisplayOrderQuestions=function getDisplayOrderQuestions(survey){var questions=survey.questions.map(function(question,originalQuestionIndex){return _objectSpread(_objectSpread({},question),{},{originalQuestionIndex:originalQuestionIndex});});if(!shouldShuffleQuestions(survey)){return questions;}return reverseIfUnshuffled(questions,(0,_surveys.shuffle)(questions));};
|
|
2
|
+
//# sourceMappingURL=survey-shuffling.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"survey-shuffling.js","
|
|
1
|
+
{"version":3,"file":"survey-shuffling.js","names":["_surveys","require","ownKeys","e","r","t","Object","keys","getOwnPropertySymbols","o","filter","getOwnPropertyDescriptor","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty2","getOwnPropertyDescriptors","defineProperties","defineProperty","hasBranching","survey","questions","some","question","_a","branching","type","shouldShuffleQuestions","exports","partialResponsesEnabled","enable_partial_responses","appearance","shuffleQuestions","reverseIfUnshuffled","unshuffled","shuffled","every","value","index","reverse","getDisplayOrderQuestions","map","originalQuestionIndex","shuffle"],"sources":["../../src/surveys/survey-shuffling.ts"],"sourcesContent":["import { shuffle } from '@posthog/core/surveys'\nexport { getDisplayOrderChoices, shuffle } from '@posthog/core/surveys'\nimport { Survey, SurveyQuestion } from '@posthog/core'\n\nconst hasBranching = (survey: Survey): boolean => survey.questions.some((question) => !!question.branching?.type)\n\nexport const shouldShuffleQuestions = (survey: Survey): boolean => {\n const partialResponsesEnabled = survey.enable_partial_responses\n\n return !!survey.appearance?.shuffleQuestions && !partialResponsesEnabled && !hasBranching(survey)\n}\n\nconst reverseIfUnshuffled = <T>(unshuffled: readonly T[], shuffled: T[]): T[] => {\n if (shuffled.length > 1 && unshuffled.every((value, index) => value === shuffled[index])) {\n return shuffled.reverse()\n }\n\n return shuffled\n}\n\nexport const getDisplayOrderQuestions = (survey: Survey): SurveyQuestion[] => {\n const questions = survey.questions.map((question, originalQuestionIndex) => ({\n ...question,\n originalQuestionIndex,\n }))\n\n if (!shouldShuffleQuestions(survey)) {\n return questions\n }\n\n return reverseIfUnshuffled(questions, shuffle(questions))\n}\n"],"mappings":"4iBAAA,IAAAA,QAAA,CAAAC,OAAA,0BAA+C,SAAAC,QAAAC,CAAA,CAAAC,CAAA,MAAAC,CAAA,CAAAC,MAAA,CAAAC,IAAA,CAAAJ,CAAA,KAAAG,MAAA,CAAAE,qBAAA,MAAAC,CAAA,CAAAH,MAAA,CAAAE,qBAAA,CAAAL,CAAA,CAAAC,CAAA,IAAAK,CAAA,CAAAA,CAAA,CAAAC,MAAA,UAAAN,CAAA,SAAAE,MAAA,CAAAK,wBAAA,CAAAR,CAAA,CAAAC,CAAA,EAAAQ,UAAA,KAAAP,CAAA,CAAAQ,IAAA,CAAAC,KAAA,CAAAT,CAAA,CAAAI,CAAA,UAAAJ,CAAA,WAAAU,cAAAZ,CAAA,UAAAC,CAAA,GAAAA,CAAA,CAAAY,SAAA,CAAAC,MAAA,CAAAb,CAAA,QAAAC,CAAA,OAA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EAAIqB,UAAU,CAACE,KAAK,CAAC,SAACC,KAAK,CAAEC,KAAK,QAAK,CAAAD,KAAK,GAAKF,QAAQ,CAACG,KAAK,CAAC,GAAC,CAAE,CACxF,MAAO,CAAAH,QAAQ,CAACI,OAAO,EAAE,CAC3B,CAEA,MAAO,CAAAJ,QAAQ,CACjB,CAAC,CAEM,GAAM,CAAAK,wBAAwB,CAAAZ,OAAA,CAAAY,wBAAA,CAAG,QAA3B,CAAAA,wBAAwBA,CAAIpB,MAAc,CAAsB,CAC3E,GAAM,CAAAC,SAAS,CAAGD,MAAM,CAACC,SAAS,CAACoB,GAAG,CAAC,SAAClB,QAAQ,CAAEmB,qBAAqB,SAAA/B,aAAA,CAAAA,aAAA,IAClEY,QAAQ,MACXmB,qBAAqB,CAArBA,qBAAqB,IACrB,CAAC,CAEH,GAAI,CAACf,sBAAsB,CAACP,MAAM,CAAC,CAAE,CACnC,MAAO,CAAAC,SAAS,CAClB,CAEA,MAAO,CAAAY,mBAAmB,CAACZ,SAAS,CAAE,GAAAsB,gBAAO,EAACtB,SAAS,CAAC,CAAC,CAC3D,CAAC","ignoreList":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.applySurveyTranslationForUser=applySurveyTranslationForUser;exports.detectUserLanguage=detectUserLanguage;var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");var logger=(0,_core.createLogger)('[SurveyTranslations]');function getLogger(instance){return instance.isDebug?logger:undefined;}function detectUserLanguage(instance){return(0,_surveys.detectSurveyLanguage)({overrideLanguage:instance.getSurveyDisplayLanguageOverride(),storedPersonProperties:instance.getPersistedProperty(_core.PostHogPersistedProperty.PersonProperties),locale:instance.getCommonEventProperties().$locale},getLogger(instance));}function applySurveyTranslationForUser(survey,instance){var userLanguage=arguments.length>2&&arguments[2]!==undefined?arguments[2]:detectUserLanguage(instance);var logger=getLogger(instance);if(!userLanguage){logger===null||logger===void 0?void 0:logger.info('No user language detected');return{survey:survey,language:null};}var result=(0,_surveys.applySurveyTranslation)(survey,userLanguage,logger);return{survey:result.survey,language:result.matchedKey};}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.applySurveyTranslationForUser=applySurveyTranslationForUser;exports.detectUserLanguage=detectUserLanguage;var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");var logger=(0,_core.createLogger)('[SurveyTranslations]');function getLogger(instance){return instance.isDebug?logger:undefined;}function detectUserLanguage(instance){return(0,_surveys.detectSurveyLanguage)({overrideLanguage:instance.getSurveyDisplayLanguageOverride(),storedPersonProperties:instance.getPersistedProperty(_core.PostHogPersistedProperty.PersonProperties),locale:instance.getCommonEventProperties().$locale},getLogger(instance));}function applySurveyTranslationForUser(survey,instance){var userLanguage=arguments.length>2&&arguments[2]!==undefined?arguments[2]:detectUserLanguage(instance);var logger=getLogger(instance);if(!userLanguage){logger===null||logger===void 0?void 0:logger.info('No user language detected');return{survey:survey,language:null};}var result=(0,_surveys.applySurveyTranslation)(survey,userLanguage,logger);return{survey:result.survey,language:result.matchedKey};}
|
|
2
|
+
//# sourceMappingURL=survey-translations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"survey-translations.js","
|
|
1
|
+
{"version":3,"file":"survey-translations.js","names":["_core","require","_surveys","logger","createLogger","getLogger","instance","isDebug","undefined","detectUserLanguage","detectSurveyLanguage","overrideLanguage","getSurveyDisplayLanguageOverride","storedPersonProperties","getPersistedProperty","PostHogPersistedProperty","PersonProperties","locale","getCommonEventProperties","$locale","applySurveyTranslationForUser","survey","userLanguage","arguments","length","info","language","result","applySurveyTranslation","matchedKey"],"sources":["../../src/surveys/survey-translations.ts"],"sourcesContent":["import { createLogger, Logger, PostHogPersistedProperty, Survey } from '@posthog/core'\nimport { applySurveyTranslation, detectSurveyLanguage } from '@posthog/core/surveys'\nimport { PostHog } from '../posthog-rn'\n\nconst logger = createLogger('[SurveyTranslations]')\n\nfunction getLogger(instance: PostHog): Logger | undefined {\n return instance.isDebug ? logger : undefined\n}\n\nexport function detectUserLanguage(instance: PostHog): string | null {\n return detectSurveyLanguage(\n {\n overrideLanguage: instance.getSurveyDisplayLanguageOverride(),\n storedPersonProperties: instance.getPersistedProperty(PostHogPersistedProperty.PersonProperties),\n locale: instance.getCommonEventProperties().$locale,\n },\n getLogger(instance)\n )\n}\n\nexport function applySurveyTranslationForUser(\n survey: Survey,\n instance: PostHog,\n userLanguage = detectUserLanguage(instance)\n): { survey: Survey; language: string | null } {\n const logger = getLogger(instance)\n\n if (!userLanguage) {\n logger?.info('No user language detected')\n return { survey, language: null }\n }\n\n const result = applySurveyTranslation(survey, userLanguage, logger)\n\n return {\n survey: result.survey,\n language: result.matchedKey,\n }\n}\n"],"mappings":"wLAAA,IAAAA,KAAA,CAAAC,OAAA,kBACA,IAAAC,QAAA,CAAAD,OAAA,0BAGA,GAAM,CAAAE,MAAM,CAAG,GAAAC,kBAAY,EAAC,sBAAsB,CAAC,CAEnD,QAAS,CAAAC,SAASA,CAACC,QAAiB,EAClC,MAAO,CAAAA,QAAQ,CAACC,OAAO,CAAGJ,MAAM,CAAGK,SAAS,CAC9C,CAEM,QAAU,CAAAC,kBAAkBA,CAACH,QAAiB,EAClD,MAAO,GAAAI,6BAAoB,EACzB,CACEC,gBAAgB,CAAEL,QAAQ,CAACM,gCAAgC,EAAE,CAC7DC,sBAAsB,CAAEP,QAAQ,CAACQ,oBAAoB,CAACC,8BAAwB,CAACC,gBAAgB,CAAC,CAChGC,MAAM,CAAEX,QAAQ,CAACY,wBAAwB,EAAE,CAACC,O,CAC7C,CACDd,SAAS,CAACC,QAAQ,CAAC,CACpB,CACH,CAEM,QAAU,CAAAc,6BAA6BA,CAC3CC,MAAc,CACdf,QAAiB,CAC0B,IAA3C,CAAAgB,YAAY,CAAAC,SAAA,CAAAC,MAAA,IAAAD,SAAA,MAAAf,SAAA,CAAAe,SAAA,IAAGd,kBAAkB,CAACH,QAAQ,CAAC,CAE3C,GAAM,CAAAH,MAAM,CAAGE,SAAS,CAACC,QAAQ,CAAC,CAElC,GAAI,CAACgB,YAAY,CAAE,CACjBnB,MAAM,SAANA,MAAM,iBAANA,MAAM,CAAEsB,IAAI,CAAC,2BAA2B,CAAC,CACzC,MAAO,CAAEJ,MAAM,CAANA,MAAM,CAAEK,QAAQ,CAAE,IAAI,CAAE,CACnC,CAEA,GAAM,CAAAC,MAAM,CAAG,GAAAC,+BAAsB,EAACP,MAAM,CAAEC,YAAY,CAAEnB,MAAM,CAAC,CAEnE,MAAO,CACLkB,MAAM,CAAEM,MAAM,CAACN,MAAM,CACrBK,QAAQ,CAAEC,MAAM,CAACE,U,CAClB,CACH","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ export { isMatchingRegex, matchPropertyFilters, propertyComparisons as surveyVal
|
|
|
10
10
|
* @returns True if the description should be rendered, false otherwise
|
|
11
11
|
*/
|
|
12
12
|
export declare function shouldRenderDescription(description?: string | null, contentType?: SurveyQuestionDescriptionContentType): boolean;
|
|
13
|
-
export declare const defaultBackgroundColor:
|
|
13
|
+
export declare const defaultBackgroundColor: '#eeeded';
|
|
14
14
|
export declare const defaultDescriptionOpacity = 0.8;
|
|
15
15
|
export declare const defaultRatingLabelOpacity = 0.7;
|
|
16
16
|
/**
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.defaultSurveyAppearance=exports.defaultRatingLabelOpacity=exports.defaultDescriptionOpacity=exports.defaultBackgroundColor=exports.closeButtonSize=void 0;exports.getContrastingTextColor=getContrastingTextColor;exports.getDisplayOrderQuestions=void 0;exports.getMaxFontSizeMultiplier=getMaxFontSizeMultiplier;exports.getNextSurveyStep=getNextSurveyStep;Object.defineProperty(exports,"isMatchingRegex",{enumerable:true,get:function get(){return _surveys.isMatchingRegex;}});Object.defineProperty(exports,"matchPropertyFilters",{enumerable:true,get:function get(){return _surveys.matchPropertyFilters;}});exports.resolveSurveyAlignment=resolveSurveyAlignment;exports.shouldRenderDescription=shouldRenderDescription;Object.defineProperty(exports,"surveyValidationMap",{enumerable:true,get:function get(){return _surveys.propertyComparisons;}});var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");function isInteger(value){return typeof value==='number'&&Number.isInteger(value);}function shouldRenderDescription(description,contentType){var effectiveContentType=contentType!==null&&contentType!==void 0?contentType:_core.SurveyQuestionDescriptionContentType.Text;return Boolean(description&&effectiveContentType===_core.SurveyQuestionDescriptionContentType.Text);}var defaultBackgroundColor=exports.defaultBackgroundColor='#eeeded';var defaultDescriptionOpacity=exports.defaultDescriptionOpacity=0.8;var defaultRatingLabelOpacity=exports.defaultRatingLabelOpacity=0.7;var closeButtonSize=exports.closeButtonSize=40;function getMaxFontSizeMultiplier(appearance,role){var configured=appearance.maxFontSizeMultiplier;if(typeof configured==='number'){return configured;}return configured===null||configured===void 0?void 0:configured[role];}var defaultSurveyAppearance=exports.defaultSurveyAppearance={backgroundColor:defaultBackgroundColor,submitButtonColor:'black',submitButtonTextColor:'white',ratingButtonColor:'white',ratingButtonActiveColor:'black',inputBackground:'white',borderColor:'#c9c6c6',displayThankYouMessage:true,thankYouMessageHeader:'Thank you for your feedback!',position:_core.SurveyPosition.Center,submitButtonText:'Submit',autoDisappear:false,thankYouMessageDescription:'',thankYouMessageDescriptionContentType:_core.SurveyQuestionDescriptionContentType.Text,thankYouMessageCloseButtonText:'Close',displayIntroScreen:false,introScreenHeader:'',introScreenDescription:'',introScreenDescriptionContentType:_core.SurveyQuestionDescriptionContentType.Text,introScreenButtonText:'Get started',surveyPopupDelaySeconds:0,allowGoBack:false,backButtonText:'Back'};var KNOWN_SURVEY_POSITIONS=new Set(Object.values(_core.SurveyPosition));var warnedUnknownPositions=new Set();function normalizeSurveyPosition(position){return position.replace(/-/g,'_').replace(/^bottom_/,'');}function resolveSurveyAlignment(position){var resolvedPosition=defaultSurveyAppearance.position;if(position){var normalizedPosition=typeof position==='string'?normalizeSurveyPosition(position):'';if(KNOWN_SURVEY_POSITIONS.has(normalizedPosition)){resolvedPosition=normalizedPosition;}else if(!warnedUnknownPositions.has(normalizedPosition)){warnedUnknownPositions.add(normalizedPosition);console.warn("[PostHog.surveys] Unknown survey position ".concat(JSON.stringify(position)," \u2014 falling back to ").concat(defaultSurveyAppearance.position,". Expected one of: ").concat(Object.values(_core.SurveyPosition).join(', '),"."));}}var isTop=resolvedPosition===_core.SurveyPosition.TopLeft||resolvedPosition===_core.SurveyPosition.TopCenter||resolvedPosition===_core.SurveyPosition.TopRight;var isMiddle=resolvedPosition===_core.SurveyPosition.MiddleLeft||resolvedPosition===_core.SurveyPosition.MiddleCenter||resolvedPosition===_core.SurveyPosition.MiddleRight;var isLeft=resolvedPosition===_core.SurveyPosition.TopLeft||resolvedPosition===_core.SurveyPosition.MiddleLeft||resolvedPosition===_core.SurveyPosition.Left;var isRight=resolvedPosition===_core.SurveyPosition.TopRight||resolvedPosition===_core.SurveyPosition.MiddleRight||resolvedPosition===_core.SurveyPosition.Right;return{vertical:isTop?'flex-start':isMiddle?'center':'flex-end',horizontal:isLeft?'flex-start':isRight?'flex-end':'center'};}var getDisplayOrderQuestions=exports.getDisplayOrderQuestions=function getDisplayOrderQuestions(survey){survey.questions.forEach(function(question,idx){question.originalQuestionIndex=idx;});return survey.questions;};function getRatingBucketForResponseValue(responseValue,scale){if(scale===3){if(responseValue<1||responseValue>3){console.warn('PostHog Debug: Rating response out of range for scale 3:',responseValue);return'neutral';}return responseValue===1?'negative':responseValue===2?'neutral':'positive';}else if(scale===5){if(responseValue<1||responseValue>5){console.warn('PostHog Debug: Rating response out of range for scale 5:',responseValue);return'neutral';}return responseValue<=2?'negative':responseValue===3?'neutral':'positive';}else if(scale===7){if(responseValue<1||responseValue>7){console.warn('PostHog Debug: Rating response out of range for scale 7:',responseValue);return'neutral';}return responseValue<=3?'negative':responseValue===4?'neutral':'positive';}else if(scale===10){if(responseValue<0||responseValue>10){console.warn('PostHog Debug: Rating response out of range for scale 10:',responseValue);return'passives';}return responseValue<=6?'detractors':responseValue<=8?'passives':'promoters';}console.warn('PostHog Debug: Unsupported rating scale:',scale);return'neutral';}function getNextSurveyStep(survey,currentQuestionIndex,response){var _a,_b,_c,_d,_e;var question=survey.questions[currentQuestionIndex];var nextQuestionIndex=currentQuestionIndex+1;if(!((_a=question.branching)===null||_a===void 0?void 0:_a.type)){if(currentQuestionIndex===survey.questions.length-1){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}if(question.branching.type===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}else if(question.branching.type===_core.SurveyQuestionBranchingType.SpecificQuestion){if(isInteger(question.branching.index)){return question.branching.index;}}else if(question.branching.type===_core.SurveyQuestionBranchingType.ResponseBased){if(question.type===_core.SurveyQuestionType.SingleChoice){var selectedChoiceIndex=question.choices.indexOf("".concat(response));if(selectedChoiceIndex===-1&&question.hasOpenChoice){selectedChoiceIndex=question.choices.length-1;}if((_c=(_b=question.branching)===null||_b===void 0?void 0:_b.responseValues)===null||_c===void 0?void 0:_c.hasOwnProperty(selectedChoiceIndex)){var nextStep=question.branching.responseValues[selectedChoiceIndex];if(isInteger(nextStep)){return nextStep;}if(nextStep===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}}else if(question.type===_core.SurveyQuestionType.Rating){if(!isInteger(response)){console.warn('PostHog Debug: Expected integer response for rating question but received:',response);return nextQuestionIndex;}var ratingQuestion=question;var ratingBucket=getRatingBucketForResponseValue(response,ratingQuestion.scale);if((_e=(_d=question.branching)===null||_d===void 0?void 0:_d.responseValues)===null||_e===void 0?void 0:_e.hasOwnProperty(ratingBucket)){var _nextStep=question.branching.responseValues[ratingBucket];if(isInteger(_nextStep)){return _nextStep;}if(_nextStep===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}}return nextQuestionIndex;}console.warn('Falling back to next question index due to unexpected branching type');return nextQuestionIndex;}function getContrastingTextColor(color){var rgb;if(color.startsWith('#')){rgb=hex2rgb(color);}if(color.startsWith('rgb')){rgb=color;}var nameColorToHex=nameToHex(color);if(nameColorToHex){rgb=hex2rgb(nameColorToHex);}if(!rgb){return'black';}var colorMatch=rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);if(colorMatch){var r=parseInt(colorMatch[1],10);var g=parseInt(colorMatch[2],10);var b=parseInt(colorMatch[3],10);var hsp=Math.sqrt(0.299*(r*r)+0.587*(g*g)+0.114*(b*b));return hsp>127.5?'black':'white';}return'black';}function hex2rgb(c){if(c.startsWith('#')){var hexColor=c.replace(/^#/,'');if(/^[0-9A-Fa-f]{3}$/.test(hexColor)){hexColor=hexColor[0]+hexColor[0]+hexColor[1]+hexColor[1]+hexColor[2]+hexColor[2];}if(!/^[0-9A-Fa-f]{6}$/.test(hexColor)){return'rgb(255, 255, 255)';}var r=parseInt(hexColor.slice(0,2),16);var g=parseInt(hexColor.slice(2,4),16);var b=parseInt(hexColor.slice(4,6),16);return"rgb(".concat(r,",").concat(g,",").concat(b,")");}return'rgb(255, 255, 255)';}function nameToHex(name){return{aliceblue:'#f0f8ff',antiquewhite:'#faebd7',aqua:'#00ffff',aquamarine:'#7fffd4',azure:'#f0ffff',beige:'#f5f5dc',bisque:'#ffe4c4',black:'#000000',blanchedalmond:'#ffebcd',blue:'#0000ff',blueviolet:'#8a2be2',brown:'#a52a2a',burlywood:'#deb887',cadetblue:'#5f9ea0',chartreuse:'#7fff00',chocolate:'#d2691e',coral:'#ff7f50',cornflowerblue:'#6495ed',cornsilk:'#fff8dc',crimson:'#dc143c',cyan:'#00ffff',darkblue:'#00008b',darkcyan:'#008b8b',darkgoldenrod:'#b8860b',darkgray:'#a9a9a9',darkgreen:'#006400',darkkhaki:'#bdb76b',darkmagenta:'#8b008b',darkolivegreen:'#556b2f',darkorange:'#ff8c00',darkorchid:'#9932cc',darkred:'#8b0000',darksalmon:'#e9967a',darkseagreen:'#8fbc8f',darkslateblue:'#483d8b',darkslategray:'#2f4f4f',darkturquoise:'#00ced1',darkviolet:'#9400d3',deeppink:'#ff1493',deepskyblue:'#00bfff',dimgray:'#696969',dodgerblue:'#1e90ff',firebrick:'#b22222',floralwhite:'#fffaf0',forestgreen:'#228b22',fuchsia:'#ff00ff',gainsboro:'#dcdcdc',ghostwhite:'#f8f8ff',gold:'#ffd700',goldenrod:'#daa520',gray:'#808080',green:'#008000',greenyellow:'#adff2f',honeydew:'#f0fff0',hotpink:'#ff69b4','indianred ':'#cd5c5c',indigo:'#4b0082',ivory:'#fffff0',khaki:'#f0e68c',lavender:'#e6e6fa',lavenderblush:'#fff0f5',lawngreen:'#7cfc00',lemonchiffon:'#fffacd',lightblue:'#add8e6',lightcoral:'#f08080',lightcyan:'#e0ffff',lightgoldenrodyellow:'#fafad2',lightgrey:'#d3d3d3',lightgreen:'#90ee90',lightpink:'#ffb6c1',lightsalmon:'#ffa07a',lightseagreen:'#20b2aa',lightskyblue:'#87cefa',lightslategray:'#778899',lightsteelblue:'#b0c4de',lightyellow:'#ffffe0',lime:'#00ff00',limegreen:'#32cd32',linen:'#faf0e6',magenta:'#ff00ff',maroon:'#800000',mediumaquamarine:'#66cdaa',mediumblue:'#0000cd',mediumorchid:'#ba55d3',mediumpurple:'#9370d8',mediumseagreen:'#3cb371',mediumslateblue:'#7b68ee',mediumspringgreen:'#00fa9a',mediumturquoise:'#48d1cc',mediumvioletred:'#c71585',midnightblue:'#191970',mintcream:'#f5fffa',mistyrose:'#ffe4e1',moccasin:'#ffe4b5',navajowhite:'#ffdead',navy:'#000080',oldlace:'#fdf5e6',olive:'#808000',olivedrab:'#6b8e23',orange:'#ffa500',orangered:'#ff4500',orchid:'#da70d6',palegoldenrod:'#eee8aa',palegreen:'#98fb98',paleturquoise:'#afeeee',palevioletred:'#d87093',papayawhip:'#ffefd5',peachpuff:'#ffdab9',peru:'#cd853f',pink:'#ffc0cb',plum:'#dda0dd',powderblue:'#b0e0e6',purple:'#800080',red:'#ff0000',rosybrown:'#bc8f8f',royalblue:'#4169e1',saddlebrown:'#8b4513',salmon:'#fa8072',sandybrown:'#f4a460',seagreen:'#2e8b57',seashell:'#fff5ee',sienna:'#a0522d',silver:'#c0c0c0',skyblue:'#87ceeb',slateblue:'#6a5acd',slategray:'#708090',snow:'#fffafa',springgreen:'#00ff7f',steelblue:'#4682b4',tan:'#d2b48c',teal:'#008080',thistle:'#d8bfd8',tomato:'#ff6347',turquoise:'#40e0d0',violet:'#ee82ee',wheat:'#f5deb3',white:'#ffffff',whitesmoke:'#f5f5f5',yellow:'#ffff00',yellowgreen:'#9acd32'}[name.toLowerCase()];}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.defaultSurveyAppearance=exports.defaultRatingLabelOpacity=exports.defaultDescriptionOpacity=exports.defaultBackgroundColor=exports.closeButtonSize=void 0;exports.getContrastingTextColor=getContrastingTextColor;exports.getDisplayOrderQuestions=void 0;exports.getMaxFontSizeMultiplier=getMaxFontSizeMultiplier;exports.getNextSurveyStep=getNextSurveyStep;Object.defineProperty(exports,"isMatchingRegex",{enumerable:true,get:function get(){return _surveys.isMatchingRegex;}});Object.defineProperty(exports,"matchPropertyFilters",{enumerable:true,get:function get(){return _surveys.matchPropertyFilters;}});exports.resolveSurveyAlignment=resolveSurveyAlignment;exports.shouldRenderDescription=shouldRenderDescription;Object.defineProperty(exports,"surveyValidationMap",{enumerable:true,get:function get(){return _surveys.propertyComparisons;}});var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");function isInteger(value){return typeof value==='number'&&Number.isInteger(value);}function shouldRenderDescription(description,contentType){var effectiveContentType=contentType!==null&&contentType!==void 0?contentType:_core.SurveyQuestionDescriptionContentType.Text;return Boolean(description&&effectiveContentType===_core.SurveyQuestionDescriptionContentType.Text);}var defaultBackgroundColor=exports.defaultBackgroundColor='#eeeded';var defaultDescriptionOpacity=exports.defaultDescriptionOpacity=0.8;var defaultRatingLabelOpacity=exports.defaultRatingLabelOpacity=0.7;var closeButtonSize=exports.closeButtonSize=40;function getMaxFontSizeMultiplier(appearance,role){var configured=appearance.maxFontSizeMultiplier;if(typeof configured==='number'){return configured;}return configured===null||configured===void 0?void 0:configured[role];}var defaultSurveyAppearance=exports.defaultSurveyAppearance={backgroundColor:defaultBackgroundColor,submitButtonColor:'black',submitButtonTextColor:'white',ratingButtonColor:'white',ratingButtonActiveColor:'black',inputBackground:'white',borderColor:'#c9c6c6',displayThankYouMessage:true,thankYouMessageHeader:'Thank you for your feedback!',position:_core.SurveyPosition.Center,submitButtonText:'Submit',autoDisappear:false,thankYouMessageDescription:'',thankYouMessageDescriptionContentType:_core.SurveyQuestionDescriptionContentType.Text,thankYouMessageCloseButtonText:'Close',displayIntroScreen:false,introScreenHeader:'',introScreenDescription:'',introScreenDescriptionContentType:_core.SurveyQuestionDescriptionContentType.Text,introScreenButtonText:'Get started',surveyPopupDelaySeconds:0,allowGoBack:false,backButtonText:'Back'};var KNOWN_SURVEY_POSITIONS=new Set(Object.values(_core.SurveyPosition));var warnedUnknownPositions=new Set();function normalizeSurveyPosition(position){return position.replace(/-/g,'_').replace(/^bottom_/,'');}function resolveSurveyAlignment(position){var resolvedPosition=defaultSurveyAppearance.position;if(position){var normalizedPosition=typeof position==='string'?normalizeSurveyPosition(position):'';if(KNOWN_SURVEY_POSITIONS.has(normalizedPosition)){resolvedPosition=normalizedPosition;}else if(!warnedUnknownPositions.has(normalizedPosition)){warnedUnknownPositions.add(normalizedPosition);console.warn("[PostHog.surveys] Unknown survey position ".concat(JSON.stringify(position)," \u2014 falling back to ").concat(defaultSurveyAppearance.position,". Expected one of: ").concat(Object.values(_core.SurveyPosition).join(', '),"."));}}var isTop=resolvedPosition===_core.SurveyPosition.TopLeft||resolvedPosition===_core.SurveyPosition.TopCenter||resolvedPosition===_core.SurveyPosition.TopRight;var isMiddle=resolvedPosition===_core.SurveyPosition.MiddleLeft||resolvedPosition===_core.SurveyPosition.MiddleCenter||resolvedPosition===_core.SurveyPosition.MiddleRight;var isLeft=resolvedPosition===_core.SurveyPosition.TopLeft||resolvedPosition===_core.SurveyPosition.MiddleLeft||resolvedPosition===_core.SurveyPosition.Left;var isRight=resolvedPosition===_core.SurveyPosition.TopRight||resolvedPosition===_core.SurveyPosition.MiddleRight||resolvedPosition===_core.SurveyPosition.Right;return{vertical:isTop?'flex-start':isMiddle?'center':'flex-end',horizontal:isLeft?'flex-start':isRight?'flex-end':'center'};}var getDisplayOrderQuestions=exports.getDisplayOrderQuestions=function getDisplayOrderQuestions(survey){survey.questions.forEach(function(question,idx){question.originalQuestionIndex=idx;});return survey.questions;};function getRatingBucketForResponseValue(responseValue,scale){if(scale===3){if(responseValue<1||responseValue>3){console.warn('PostHog Debug: Rating response out of range for scale 3:',responseValue);return'neutral';}return responseValue===1?'negative':responseValue===2?'neutral':'positive';}else if(scale===5){if(responseValue<1||responseValue>5){console.warn('PostHog Debug: Rating response out of range for scale 5:',responseValue);return'neutral';}return responseValue<=2?'negative':responseValue===3?'neutral':'positive';}else if(scale===7){if(responseValue<1||responseValue>7){console.warn('PostHog Debug: Rating response out of range for scale 7:',responseValue);return'neutral';}return responseValue<=3?'negative':responseValue===4?'neutral':'positive';}else if(scale===10){if(responseValue<0||responseValue>10){console.warn('PostHog Debug: Rating response out of range for scale 10:',responseValue);return'passives';}return responseValue<=6?'detractors':responseValue<=8?'passives':'promoters';}console.warn('PostHog Debug: Unsupported rating scale:',scale);return'neutral';}function getNextSurveyStep(survey,currentQuestionIndex,response){var _a,_b,_c,_d,_e;var question=survey.questions[currentQuestionIndex];var nextQuestionIndex=currentQuestionIndex+1;if(!((_a=question.branching)===null||_a===void 0?void 0:_a.type)){if(currentQuestionIndex===survey.questions.length-1){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}if(question.branching.type===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}else if(question.branching.type===_core.SurveyQuestionBranchingType.SpecificQuestion){if(isInteger(question.branching.index)){return question.branching.index;}}else if(question.branching.type===_core.SurveyQuestionBranchingType.ResponseBased){if(question.type===_core.SurveyQuestionType.SingleChoice){var selectedChoiceIndex=question.choices.indexOf("".concat(response));if(selectedChoiceIndex===-1&&question.hasOpenChoice){selectedChoiceIndex=question.choices.length-1;}if((_c=(_b=question.branching)===null||_b===void 0?void 0:_b.responseValues)===null||_c===void 0?void 0:_c.hasOwnProperty(selectedChoiceIndex)){var nextStep=question.branching.responseValues[selectedChoiceIndex];if(isInteger(nextStep)){return nextStep;}if(nextStep===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}}else if(question.type===_core.SurveyQuestionType.Rating){if(!isInteger(response)){console.warn('PostHog Debug: Expected integer response for rating question but received:',response);return nextQuestionIndex;}var ratingQuestion=question;var ratingBucket=getRatingBucketForResponseValue(response,ratingQuestion.scale);if((_e=(_d=question.branching)===null||_d===void 0?void 0:_d.responseValues)===null||_e===void 0?void 0:_e.hasOwnProperty(ratingBucket)){var _nextStep=question.branching.responseValues[ratingBucket];if(isInteger(_nextStep)){return _nextStep;}if(_nextStep===_core.SurveyQuestionBranchingType.End){return _core.SurveyQuestionBranchingType.End;}return nextQuestionIndex;}}return nextQuestionIndex;}console.warn('Falling back to next question index due to unexpected branching type');return nextQuestionIndex;}function getContrastingTextColor(color){var rgb;if(color.startsWith('#')){rgb=hex2rgb(color);}if(color.startsWith('rgb')){rgb=color;}var nameColorToHex=nameToHex(color);if(nameColorToHex){rgb=hex2rgb(nameColorToHex);}if(!rgb){return'black';}var colorMatch=rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/);if(colorMatch){var r=parseInt(colorMatch[1],10);var g=parseInt(colorMatch[2],10);var b=parseInt(colorMatch[3],10);var hsp=Math.sqrt(0.299*(r*r)+0.587*(g*g)+0.114*(b*b));return hsp>127.5?'black':'white';}return'black';}function hex2rgb(c){if(c.startsWith('#')){var hexColor=c.replace(/^#/,'');if(/^[0-9A-Fa-f]{3}$/.test(hexColor)){hexColor=hexColor[0]+hexColor[0]+hexColor[1]+hexColor[1]+hexColor[2]+hexColor[2];}if(!/^[0-9A-Fa-f]{6}$/.test(hexColor)){return'rgb(255, 255, 255)';}var r=parseInt(hexColor.slice(0,2),16);var g=parseInt(hexColor.slice(2,4),16);var b=parseInt(hexColor.slice(4,6),16);return"rgb(".concat(r,",").concat(g,",").concat(b,")");}return'rgb(255, 255, 255)';}function nameToHex(name){return{aliceblue:'#f0f8ff',antiquewhite:'#faebd7',aqua:'#00ffff',aquamarine:'#7fffd4',azure:'#f0ffff',beige:'#f5f5dc',bisque:'#ffe4c4',black:'#000000',blanchedalmond:'#ffebcd',blue:'#0000ff',blueviolet:'#8a2be2',brown:'#a52a2a',burlywood:'#deb887',cadetblue:'#5f9ea0',chartreuse:'#7fff00',chocolate:'#d2691e',coral:'#ff7f50',cornflowerblue:'#6495ed',cornsilk:'#fff8dc',crimson:'#dc143c',cyan:'#00ffff',darkblue:'#00008b',darkcyan:'#008b8b',darkgoldenrod:'#b8860b',darkgray:'#a9a9a9',darkgreen:'#006400',darkkhaki:'#bdb76b',darkmagenta:'#8b008b',darkolivegreen:'#556b2f',darkorange:'#ff8c00',darkorchid:'#9932cc',darkred:'#8b0000',darksalmon:'#e9967a',darkseagreen:'#8fbc8f',darkslateblue:'#483d8b',darkslategray:'#2f4f4f',darkturquoise:'#00ced1',darkviolet:'#9400d3',deeppink:'#ff1493',deepskyblue:'#00bfff',dimgray:'#696969',dodgerblue:'#1e90ff',firebrick:'#b22222',floralwhite:'#fffaf0',forestgreen:'#228b22',fuchsia:'#ff00ff',gainsboro:'#dcdcdc',ghostwhite:'#f8f8ff',gold:'#ffd700',goldenrod:'#daa520',gray:'#808080',green:'#008000',greenyellow:'#adff2f',honeydew:'#f0fff0',hotpink:'#ff69b4','indianred ':'#cd5c5c',indigo:'#4b0082',ivory:'#fffff0',khaki:'#f0e68c',lavender:'#e6e6fa',lavenderblush:'#fff0f5',lawngreen:'#7cfc00',lemonchiffon:'#fffacd',lightblue:'#add8e6',lightcoral:'#f08080',lightcyan:'#e0ffff',lightgoldenrodyellow:'#fafad2',lightgrey:'#d3d3d3',lightgreen:'#90ee90',lightpink:'#ffb6c1',lightsalmon:'#ffa07a',lightseagreen:'#20b2aa',lightskyblue:'#87cefa',lightslategray:'#778899',lightsteelblue:'#b0c4de',lightyellow:'#ffffe0',lime:'#00ff00',limegreen:'#32cd32',linen:'#faf0e6',magenta:'#ff00ff',maroon:'#800000',mediumaquamarine:'#66cdaa',mediumblue:'#0000cd',mediumorchid:'#ba55d3',mediumpurple:'#9370d8',mediumseagreen:'#3cb371',mediumslateblue:'#7b68ee',mediumspringgreen:'#00fa9a',mediumturquoise:'#48d1cc',mediumvioletred:'#c71585',midnightblue:'#191970',mintcream:'#f5fffa',mistyrose:'#ffe4e1',moccasin:'#ffe4b5',navajowhite:'#ffdead',navy:'#000080',oldlace:'#fdf5e6',olive:'#808000',olivedrab:'#6b8e23',orange:'#ffa500',orangered:'#ff4500',orchid:'#da70d6',palegoldenrod:'#eee8aa',palegreen:'#98fb98',paleturquoise:'#afeeee',palevioletred:'#d87093',papayawhip:'#ffefd5',peachpuff:'#ffdab9',peru:'#cd853f',pink:'#ffc0cb',plum:'#dda0dd',powderblue:'#b0e0e6',purple:'#800080',red:'#ff0000',rosybrown:'#bc8f8f',royalblue:'#4169e1',saddlebrown:'#8b4513',salmon:'#fa8072',sandybrown:'#f4a460',seagreen:'#2e8b57',seashell:'#fff5ee',sienna:'#a0522d',silver:'#c0c0c0',skyblue:'#87ceeb',slateblue:'#6a5acd',slategray:'#708090',snow:'#fffafa',springgreen:'#00ff7f',steelblue:'#4682b4',tan:'#d2b48c',teal:'#008080',thistle:'#d8bfd8',tomato:'#ff6347',turquoise:'#40e0d0',violet:'#ee82ee',wheat:'#f5deb3',white:'#ffffff',whitesmoke:'#f5f5f5',yellow:'#ffff00',yellowgreen:'#9acd32'}[name.toLowerCase()];}
|
|
2
|
+
//# sourceMappingURL=surveys-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"surveys-utils.js","sourceRoot":"","sources":["../../src/surveys/surveys-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,2BAA2B,EAC3B,kBAAkB,EAIlB,cAAc,EACd,oCAAoC,GACrC,MAAM,eAAe,CAAA;AAGtB,OAAO,EACL,eAAe,EACf,oBAAoB,EACpB,mBAAmB,IAAI,mBAAmB,GAC3C,MAAM,uBAAuB,CAAA;AAE9B,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAC7D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACrC,WAA2B,EAC3B,WAAkD;IAElD,MAAM,oBAAoB,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,oCAAoC,CAAC,IAAI,CAAA;IACrF,OAAO,OAAO,CAAC,WAAW,IAAI,oBAAoB,KAAK,oCAAoC,CAAC,IAAI,CAAC,CAAA;AACnG,CAAC;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,SAAkB,CAAA;AACxD,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAA;AAC5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAA;AAE5C;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAA;AAsFjC;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,UAA2D,EAC3D,IAAoB;IAEpB,MAAM,UAAU,GAAG,UAAU,CAAC,qBAAqB,CAAA;IACnD,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,OAAO,UAAU,CAAA;IACnB,CAAC;IACD,OAAO,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAG,IAAI,CAAC,CAAA;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AAS;QACjB,aAAa,EAAE,SAAS;QACxB,SAAS,EAAE,SAAS;QACpB,aAAa,EAAE,SAAS;QACxB,aAAa,EAAE,SAAS;QACxB,UAAU,EAAE,SAAS;QACrB,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,SAAS;QACrB,MAAM,EAAE,SAAS;QACjB,GAAG,EAAE,SAAS;QACd,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,WAAW,EAAE,SAAS;QACtB,MAAM,EAAE,SAAS;QACjB,UAAU,EAAE,SAAS;QACrB,QAAQ,EAAE,SAAS;QACnB,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,SAAS;QACjB,OAAO,EAAE,SAAS;QAClB,SAAS,EAAE,SAAS;QACpB,SAAS,EAAE,SAAS;QACpB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,SAAS;QACtB,SAAS,EAAE,SAAS;QACpB,GAAG,EAAE,SAAS;QACd,IAAI,EAAE,SAAS;QACf,OAAO,EAAE,SAAS;QAClB,MAAM,EAAE,SAAS;QACjB,SAAS,EAAE,SAAS;QACpB,MAAM,EAAE,SAAS;QACjB,KAAK,EAAE,SAAS;QAChB,KAAK,EAAE,SAAS;QAChB,UAAU,EAAE,SAAS;QACrB,MAAM,EAAE,SAAS;QACjB,WAAW,EAAE,SAAS;KACvB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;AACvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"surveys-utils.js","names":["_core","require","_surveys","isInteger","value","Number","shouldRenderDescription","description","contentType","effectiveContentType","SurveyQuestionDescriptionContentType","Text","Boolean","defaultBackgroundColor","exports","defaultDescriptionOpacity","defaultRatingLabelOpacity","closeButtonSize","getMaxFontSizeMultiplier","appearance","role","configured","maxFontSizeMultiplier","defaultSurveyAppearance","backgroundColor","submitButtonColor","submitButtonTextColor","ratingButtonColor","ratingButtonActiveColor","inputBackground","borderColor","displayThankYouMessage","thankYouMessageHeader","position","SurveyPosition","Center","submitButtonText","autoDisappear","thankYouMessageDescription","thankYouMessageDescriptionContentType","thankYouMessageCloseButtonText","displayIntroScreen","introScreenHeader","introScreenDescription","introScreenDescriptionContentType","introScreenButtonText","surveyPopupDelaySeconds","allowGoBack","backButtonText","KNOWN_SURVEY_POSITIONS","Set","Object","values","warnedUnknownPositions","normalizeSurveyPosition","replace","resolveSurveyAlignment","resolvedPosition","normalizedPosition","has","add","console","warn","concat","JSON","stringify","join","isTop","TopLeft","TopCenter","TopRight","isMiddle","MiddleLeft","MiddleCenter","MiddleRight","isLeft","Left","isRight","Right","vertical","horizontal","getDisplayOrderQuestions","survey","questions","forEach","question","idx","originalQuestionIndex","getRatingBucketForResponseValue","responseValue","scale","getNextSurveyStep","currentQuestionIndex","response","nextQuestionIndex","_a","branching","type","length","SurveyQuestionBranchingType","End","SpecificQuestion","index","ResponseBased","SurveyQuestionType","SingleChoice","selectedChoiceIndex","choices","indexOf","hasOpenChoice","_c","_b","responseValues","hasOwnProperty","nextStep","Rating","ratingQuestion","ratingBucket","_e","_d","getContrastingTextColor","color","rgb","startsWith","hex2rgb","nameColorToHex","nameToHex","colorMatch","match","r","parseInt","g","b","hsp","Math","sqrt","c","hexColor","test","slice","name","aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","honeydew","hotpink","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgrey","lightgreen","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen","toLowerCase"],"sources":["../../src/surveys/surveys-utils.ts"],"sourcesContent":["import {\n Survey,\n SurveyQuestion,\n SurveyQuestionBranchingType,\n SurveyQuestionType,\n SurveyRatingDisplay,\n RatingSurveyQuestion,\n SurveyAppearance as CoreSurveyAppearance,\n SurveyPosition,\n SurveyQuestionDescriptionContentType,\n} from '@posthog/core'\n\nexport type { PropertyFilters, PropertyOperator, SurveyEventWithFilters } from '@posthog/core'\nexport {\n isMatchingRegex,\n matchPropertyFilters,\n propertyComparisons as surveyValidationMap,\n} from '@posthog/core/surveys'\n\nfunction isInteger(value: unknown): boolean {\n return typeof value === 'number' && Number.isInteger(value)\n}\n\n/**\n * Utility function to determine if a description should be rendered based on content type\n * Only renders text content, skips HTML content for React Native compatibility\n * Defaults to Text content type when not specified\n * @param description The description text\n * @param contentType The content type (text or html), defaults to Text if not provided\n * @returns True if the description should be rendered, false otherwise\n */\nexport function shouldRenderDescription(\n description?: string | null,\n contentType?: SurveyQuestionDescriptionContentType\n): boolean {\n const effectiveContentType = contentType ?? SurveyQuestionDescriptionContentType.Text\n return Boolean(description && effectiveContentType === SurveyQuestionDescriptionContentType.Text)\n}\n\nexport const defaultBackgroundColor = '#eeeded' as const\nexport const defaultDescriptionOpacity = 0.8\nexport const defaultRatingLabelOpacity = 0.7\n\n/**\n * Side of the circular close button. The button is absolutely positioned in the modal's\n * top-right corner, so the content containers underneath it reserve this much padding on\n * their right edge to keep long text from wrapping into it.\n */\nexport const closeButtonSize = 40\n\n/**\n * The distinct kinds of text a survey renders, each at its own base size. They\n * are separate because one ceiling cannot serve all of them: `question` is an\n * 18pt headline that can wrap freely, while `ratingNumber` sits inside a\n * fixed-width button and has nowhere to grow.\n */\nexport type SurveyTextRole =\n /** The question headline. */\n | 'question'\n /** Body copy under a question, an intro screen, or the thank-you screen. */\n | 'description'\n /** The intro-screen and thank-you-screen headers. */\n | 'header'\n /** A choice label in a single- or multiple-choice question. */\n | 'choice'\n /** Text the user types - the open-text answer and the open-choice field. */\n | 'input'\n /** The submit / next button label. */\n | 'button'\n /** The lower- and upper-bound labels under a rating scale. */\n | 'ratingLabel'\n /** The numeral inside a rating button, which cannot grow past the button. */\n | 'ratingNumber'\n /** The validation hint under an open-text answer. */\n | 'validationHint'\n\n/** React Native survey appearance, including native-only text scaling options. */\nexport interface SurveyAppearance extends CoreSurveyAppearance {\n /**\n * Caps how far survey text may grow under the OS text-size setting, as a\n * multiple of its base size - React Native's `maxFontSizeMultiplier`, applied\n * to every semantic `Text` and `TextInput` the survey renders. Icon-only text\n * fallbacks do not scale because they occupy fixed-size icon boxes.\n *\n * Pass a number to cap every role at once, or an object to cap them\n * separately: a survey headline can usually take more scaling than a numeral\n * inside a rating button, and a host app that already caps its own text by\n * role will want to match those ceilings here.\n *\n * ```ts\n * maxFontSizeMultiplier: 1.6\n * // or\n * maxFontSizeMultiplier: { question: 1.5, description: 1.8, ratingNumber: 1.2 }\n * ```\n *\n * Roles left out of the object are uncapped, as they are today. Use `0` for\n * no maximum, or a value of `1` or greater to set a cap. Other values below\n * `1` (such as `0.8`) do not shrink text and are unsupported by React Native;\n * depending on the platform and version, they may be ignored or rejected.\n *\n * Leave it unset (the default) and survey text scales without a ceiling. That\n * is what the OS asks for, but not always what a fixed-size survey card can\n * hold - at the largest accessibility sizes an unbounded 18pt headline renders\n * roughly one word per line.\n *\n * React Native only inherits this prop through nested `Text`, so a host app\n * cannot apply it from the outside - it has to come in here.\n *\n * @default undefined (no ceiling)\n */\n maxFontSizeMultiplier?: number | Partial<Record<SurveyTextRole, number>>\n}\n\n// textColor and inputTextColor are optional overrides (auto-calculated if not provided)\n// placeholder is optional too: open text questions only show placeholder text when the survey's\n// appearance sets one, so clearing the field in the survey editor clears it here too.\nexport type SurveyAppearanceTheme = Omit<\n Required<SurveyAppearance>,\n | 'widgetSelector'\n | 'widgetType'\n | 'widgetColor'\n | 'widgetLabel'\n | 'shuffleQuestions'\n | 'textColor'\n | 'inputTextColor'\n | 'placeholder'\n | 'maxFontSizeMultiplier'\n> & {\n textColor?: string\n inputTextColor?: string\n placeholder?: string\n maxFontSizeMultiplier?: SurveyAppearance['maxFontSizeMultiplier']\n}\n\n/**\n * The ceiling for one role, from either form of `maxFontSizeMultiplier`.\n *\n * Returns `undefined` when nothing is configured for that role, which is also\n * React Native's \"no ceiling\" - so an unset appearance renders exactly as it\n * did before this option existed.\n */\nexport function getMaxFontSizeMultiplier(\n appearance: Pick<SurveyAppearance, 'maxFontSizeMultiplier'>,\n role: SurveyTextRole\n): number | undefined {\n const configured = appearance.maxFontSizeMultiplier\n if (typeof configured === 'number') {\n return configured\n }\n return configured?.[role]\n}\nexport const defaultSurveyAppearance: SurveyAppearanceTheme = {\n backgroundColor: defaultBackgroundColor,\n submitButtonColor: 'black',\n submitButtonTextColor: 'white',\n ratingButtonColor: 'white',\n ratingButtonActiveColor: 'black',\n inputBackground: 'white',\n borderColor: '#c9c6c6',\n displayThankYouMessage: true,\n thankYouMessageHeader: 'Thank you for your feedback!',\n position: SurveyPosition.Center,\n submitButtonText: 'Submit',\n autoDisappear: false,\n thankYouMessageDescription: '',\n thankYouMessageDescriptionContentType: SurveyQuestionDescriptionContentType.Text,\n thankYouMessageCloseButtonText: 'Close',\n displayIntroScreen: false,\n introScreenHeader: '',\n introScreenDescription: '',\n introScreenDescriptionContentType: SurveyQuestionDescriptionContentType.Text,\n introScreenButtonText: 'Get started',\n surveyPopupDelaySeconds: 0,\n allowGoBack: false,\n backButtonText: 'Back',\n}\n\nexport type SurveyFlexAlign = 'flex-start' | 'center' | 'flex-end'\n\nconst KNOWN_SURVEY_POSITIONS: ReadonlySet<string> = new Set(Object.values(SurveyPosition))\nconst warnedUnknownPositions = new Set<string>()\n\n// Some survey API clients use CSS-style names such as `bottom-right`, while\n// SurveyPosition represents the bottom row as `left`, `center`, and `right`.\nfunction normalizeSurveyPosition(position: string): string {\n return position.replace(/-/g, '_').replace(/^bottom_/, '')\n}\n\n// Mirrors web SDK semantics: `.ph-survey` is bottom-anchored by default and\n// getPopoverPosition only overrides `top` for top_* / middle_* variants. So\n// `left` / `right` / `center` (no prefix) anchor to the bottom edge — they\n// are NOT shorthand for middle.\nexport function resolveSurveyAlignment(position: string | undefined): {\n vertical: SurveyFlexAlign\n horizontal: SurveyFlexAlign\n} {\n let resolvedPosition: SurveyPosition = defaultSurveyAppearance.position\n if (position) {\n const normalizedPosition = typeof position === 'string' ? normalizeSurveyPosition(position) : ''\n if (KNOWN_SURVEY_POSITIONS.has(normalizedPosition)) {\n resolvedPosition = normalizedPosition as SurveyPosition\n } else if (!warnedUnknownPositions.has(normalizedPosition)) {\n warnedUnknownPositions.add(normalizedPosition)\n console.warn(\n `[PostHog.surveys] Unknown survey position ${JSON.stringify(position)} — falling back to ${defaultSurveyAppearance.position}. Expected one of: ${Object.values(SurveyPosition).join(', ')}.`\n )\n }\n }\n const isTop =\n resolvedPosition === SurveyPosition.TopLeft ||\n resolvedPosition === SurveyPosition.TopCenter ||\n resolvedPosition === SurveyPosition.TopRight\n const isMiddle =\n resolvedPosition === SurveyPosition.MiddleLeft ||\n resolvedPosition === SurveyPosition.MiddleCenter ||\n resolvedPosition === SurveyPosition.MiddleRight\n const isLeft =\n resolvedPosition === SurveyPosition.TopLeft ||\n resolvedPosition === SurveyPosition.MiddleLeft ||\n resolvedPosition === SurveyPosition.Left\n const isRight =\n resolvedPosition === SurveyPosition.TopRight ||\n resolvedPosition === SurveyPosition.MiddleRight ||\n resolvedPosition === SurveyPosition.Right\n return {\n vertical: isTop ? 'flex-start' : isMiddle ? 'center' : 'flex-end',\n horizontal: isLeft ? 'flex-start' : isRight ? 'flex-end' : 'center',\n }\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: SurveyQuestion, idx: number) => {\n question.originalQuestionIndex = idx\n })\n\n // TODO: shuffle questions\n return survey.questions\n\n // if (!survey.appearance?.shuffleQuestions) {\n // return survey.questions\n // }\n\n // return reverseIfUnshuffled(survey.questions, shuffle(survey.questions))\n}\n\n/**\n * Use the Fisher-yates algorithm to shuffle this array\n * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\n */\n// export const shuffle = <T>(array: T[]): T[] => {\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\n// const reverseIfUnshuffled = <T>(unshuffled: T[], shuffled: T[]): T[] => {\n// if (unshuffled.length === shuffled.length && unshuffled.every((val, index) => val === shuffled[index])) {\n// return shuffled.reverse()\n// }\n\n// return shuffled\n// }\n\n/**\n * Get the rating bucket for a response value based on the scale\n * @param responseValue The numeric rating value\n * @param scale The scale of the rating (3, 5, 7, or 10)\n * @returns The bucket name for the rating\n */\nfunction getRatingBucketForResponseValue(responseValue: number, scale: number): string {\n if (scale === 3) {\n if (responseValue < 1 || responseValue > 3) {\n console.warn('PostHog Debug: Rating response out of range for scale 3:', responseValue)\n return 'neutral' // Default to neutral for out-of-range values\n }\n\n return responseValue === 1 ? 'negative' : responseValue === 2 ? 'neutral' : 'positive'\n } else if (scale === 5) {\n if (responseValue < 1 || responseValue > 5) {\n console.warn('PostHog Debug: Rating response out of range for scale 5:', responseValue)\n return 'neutral' // Default to neutral for out-of-range values\n }\n\n return responseValue <= 2 ? 'negative' : responseValue === 3 ? 'neutral' : 'positive'\n } else if (scale === 7) {\n if (responseValue < 1 || responseValue > 7) {\n console.warn('PostHog Debug: Rating response out of range for scale 7:', responseValue)\n return 'neutral' // Default to neutral for out-of-range values\n }\n\n return responseValue <= 3 ? 'negative' : responseValue === 4 ? 'neutral' : 'positive'\n } else if (scale === 10) {\n if (responseValue < 0 || responseValue > 10) {\n console.warn('PostHog Debug: Rating response out of range for scale 10:', responseValue)\n return 'passives' // Default to passives for out-of-range values\n }\n\n return responseValue <= 6 ? 'detractors' : responseValue <= 8 ? 'passives' : 'promoters'\n }\n\n console.warn('PostHog Debug: Unsupported rating scale:', scale)\n return 'neutral' // Default fallback for unsupported scales\n}\n\n/**\n * Determines the next question to show based on the survey's branching logic\n * @param survey The survey object\n * @param currentQuestionIndex The current question index\n * @param response The user's response to the current question\n * @returns The index of the next question or SurveyQuestionBranchingType.End if the survey should end\n */\nexport function getNextSurveyStep(\n survey: Survey,\n currentQuestionIndex: number,\n response: string | string[] | number | null\n): number | typeof SurveyQuestionBranchingType.End {\n const question = survey.questions[currentQuestionIndex]\n const nextQuestionIndex = currentQuestionIndex + 1\n\n if (!question.branching?.type) {\n if (currentQuestionIndex === survey.questions.length - 1) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n\n if (question.branching.type === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n } else if (question.branching.type === SurveyQuestionBranchingType.SpecificQuestion) {\n if (isInteger(question.branching.index)) {\n return question.branching.index\n }\n } else if (question.branching.type === SurveyQuestionBranchingType.ResponseBased) {\n // Single choice\n if (question.type === SurveyQuestionType.SingleChoice) {\n // Look up the choiceIndex based on the response\n let selectedChoiceIndex = question.choices.indexOf(`${response}`)\n\n if (selectedChoiceIndex === -1 && question.hasOpenChoice) {\n // if the response is not found in the choices, it must be the open choice,\n // which is always the last choice\n selectedChoiceIndex = question.choices.length - 1\n }\n\n if (question.branching?.responseValues?.hasOwnProperty(selectedChoiceIndex)) {\n const nextStep = question.branching.responseValues[selectedChoiceIndex]\n\n // Specific question\n if (isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n } else if (question.type === SurveyQuestionType.Rating) {\n if (!isInteger(response)) {\n console.warn('PostHog Debug: Expected integer response for rating question but received:', response)\n return nextQuestionIndex // Fail gracefully by continuing to next question\n }\n\n const ratingQuestion = question as RatingSurveyQuestion\n const ratingBucket = getRatingBucketForResponseValue(response as number, ratingQuestion.scale)\n\n if (question.branching?.responseValues?.hasOwnProperty(ratingBucket)) {\n const nextStep = question.branching.responseValues[ratingBucket]\n\n // Specific question\n if (isInteger(nextStep)) {\n return nextStep\n }\n\n if (nextStep === SurveyQuestionBranchingType.End) {\n return SurveyQuestionBranchingType.End\n }\n\n return nextQuestionIndex\n }\n }\n\n return nextQuestionIndex\n }\n\n console.warn('Falling back to next question index due to unexpected branching type')\n return nextQuestionIndex\n}\n\nexport function getContrastingTextColor(color: string): 'black' | 'white' {\n let rgb: string | undefined\n if (color.startsWith('#')) {\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], 10)\n const g = parseInt(colorMatch[2], 10)\n const b = parseInt(colorMatch[3], 10)\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}\n\nfunction hex2rgb(c: string): string {\n if (c.startsWith('#')) {\n let hexColor = c.replace(/^#/, '')\n // Handle 3-character shorthand (e.g., #111 -> #111111, #abc -> #aabbcc)\n if (/^[0-9A-Fa-f]{3}$/.test(hexColor)) {\n hexColor = hexColor[0] + hexColor[0] + hexColor[1] + hexColor[1] + hexColor[2] + hexColor[2]\n }\n if (!/^[0-9A-Fa-f]{6}$/.test(hexColor)) {\n return 'rgb(255, 255, 255)'\n }\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\nfunction nameToHex(name: string): string | undefined {\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"],"mappings":"s5BAAA,IAAAA,KAAA,CAAAC,OAAA,kBAaA,IAAAC,QAAA,CAAAD,OAAA,0BAMA,QAAS,CAAAE,SAASA,CAACC,KAAc,EAC/B,MAAO,OAAO,CAAAA,KAAK,GAAK,QAAQ,EAAIC,MAAM,CAACF,SAAS,CAACC,KAAK,CAAC,CAC7D,CAUM,QAAU,CAAAE,uBAAuBA,CACrCC,WAA2B,CAC3BC,WAAkD,EAElD,GAAM,CAAAC,oBAAoB,CAAGD,WAAW,SAAXA,WAAW,UAAXA,WAAW,CAAIE,0CAAoC,CAACC,IAAI,CACrF,MAAO,CAAAC,OAAO,CAACL,WAAW,EAAIE,oBAAoB,GAAKC,0CAAoC,CAACC,IAAI,CAAC,CACnG,CAEO,GAAM,CAAAE,sBAAsB,CAAAC,OAAA,CAAAD,sBAAA,CAAG,SAAkB,CACjD,GAAM,CAAAE,yBAAyB,CAAAD,OAAA,CAAAC,yBAAA,CAAG,GAAG,CACrC,GAAM,CAAAC,yBAAyB,CAAAF,OAAA,CAAAE,yBAAA,CAAG,GAAG,CAOrC,GAAM,CAAAC,eAAe,CAAAH,O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C,WAAW,CAAE,SAAS,CACtBC,MAAM,CAAE,SAAS,CACjBC,UAAU,CAAE,SAAS,CACrBC,QAAQ,CAAE,SAAS,CACnBC,QAAQ,CAAE,SAAS,CACnBC,MAAM,CAAE,SAAS,CACjBC,MAAM,CAAE,SAAS,CACjBC,OAAO,CAAE,SAAS,CAClBC,SAAS,CAAE,SAAS,CACpBC,SAAS,CAAE,SAAS,CACpBC,IAAI,CAAE,SAAS,CACfC,WAAW,CAAE,SAAS,CACtBC,SAAS,CAAE,SAAS,CACpBC,GAAG,CAAE,SAAS,CACdC,IAAI,CAAE,SAAS,CACfC,OAAO,CAAE,SAAS,CAClBC,MAAM,CAAE,SAAS,CACjBC,SAAS,CAAE,SAAS,CACpBC,MAAM,CAAE,SAAS,CACjBC,KAAK,CAAE,SAAS,CAChBC,KAAK,CAAE,SAAS,CAChBC,UAAU,CAAE,SAAS,CACrBC,MAAM,CAAE,SAAS,CACjBC,WAAW,CAAE,S,CACd,CAAC3I,IAAI,CAAC4I,WAAW,EAAE,CAAC,CACvB","ignoreList":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useActivatedSurveys=useActivatedSurveys;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _surveys=require("@posthog/core/surveys");function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}var SURVEY_SHOWN_EVENT_NAME='survey shown';function useActivatedSurveys(posthog,surveys){var _useState=(0,_react.useState)(new Set()),_useState2=(0,_slicedToArray2["default"])(_useState,2),activatedSurveys=_useState2[0],setActivatedSurveys=_useState2[1];var eventMap=(0,_react.useMemo)(function(){var _a,_b
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useActivatedSurveys=useActivatedSurveys;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=require("react");var _surveys=require("@posthog/core/surveys");function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var _n=0,F=function F(){};return{s:F,n:function n(){return _n>=r.length?{done:!0}:{done:!1,value:r[_n++]};},e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}var SURVEY_SHOWN_EVENT_NAME='survey shown';function useActivatedSurveys(posthog,surveys){var _useState=(0,_react.useState)(new Set()),_useState2=(0,_slicedToArray2["default"])(_useState,2),activatedSurveys=_useState2[0],setActivatedSurveys=_useState2[1];(0,_react.useEffect)(function(){setActivatedSurveys(new Set());return posthog.on('surveysReset',function(){return setActivatedSurveys(new Set());});},[posthog]);var eventMap=(0,_react.useMemo)(function(){var _a,_b;var _c,_d;var newEventMap=new Map();var _iterator=_createForOfIteratorHelper(surveys.filter(_surveys.doesSurveyActivateByEvent)),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var survey=_step.value;var _iterator2=_createForOfIteratorHelper((_c=(_b=(_a=survey.conditions)===null||_a===void 0?void 0:_a.events)===null||_b===void 0?void 0:_b.values)!==null&&_c!==void 0?_c:[]),_step2;try{for(_iterator2.s();!(_step2=_iterator2.n()).done;){var event=_step2.value;var configs=(_d=newEventMap.get(event.name))!==null&&_d!==void 0?_d:[];configs.push({surveyId:survey.id,propertyFilters:event.propertyFilters});newEventMap.set(event.name,configs);}}catch(err){_iterator2.e(err);}finally{_iterator2.f();}}}catch(err){_iterator.e(err);}finally{_iterator.f();}return newEventMap;},[surveys]);(0,_react.useEffect)(function(){if(eventMap.size>0){return posthog.on('capture',function(payload){var _a;var _b;if(eventMap.has(payload.event)){var configs=(_b=eventMap.get(payload.event))!==null&&_b!==void 0?_b:[];var matchingSurveyIds=configs.filter(function(config){return(0,_surveys.matchPropertyFilters)(config.propertyFilters,payload.properties);}).map(function(config){return config.surveyId;});if(matchingSurveyIds.length>0){setActivatedSurveys(function(current){return new Set([].concat((0,_toConsumableArray2["default"])(current),(0,_toConsumableArray2["default"])(matchingSurveyIds)));});}}else if(payload.event===SURVEY_SHOWN_EVENT_NAME){var surveyId=(_a=payload.properties)===null||_a===void 0?void 0:_a.$survey_id;if(surveyId){setActivatedSurveys(function(current){if(!current.has(surveyId)){return current;}var next=new Set(current);next["delete"](surveyId);return next;});}}});}},[eventMap,posthog]);return activatedSurveys;}
|
|
2
|
+
//# sourceMappingURL=useActivatedSurveys.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActivatedSurveys.js","
|
|
1
|
+
{"version":3,"file":"useActivatedSurveys.js","names":["_react","require","_surveys","_createForOfIteratorHelper","r","e","t","Symbol","iterator","Array","isArray","_unsupportedIterableToArray","length","_n","F","s","n","done","value","f","TypeError","o","a","u","call","next","_arrayLikeToArray","toString","slice","constructor","name","from","test","SURVEY_SHOWN_EVENT_NAME","useActivatedSurveys","posthog","surveys","_useState","useState","Set","_useState2","_slicedToArray2","activatedSurveys","setActivatedSurveys","useEffect","on","eventMap","useMemo","newEventMap","Map","_iterator","filter","doesSurveyActivateByEvent","_step","survey","_iterator2","_c","_b","_a","conditions","events","values","_step2","event","configs","_d","get","push","surveyId","id","propertyFilters","set","err","size","payload","has","matchingSurveyIds","config","matchPropertyFilters","properties","map","current","concat","_toConsumableArray2","$survey_id"],"sources":["../../src/surveys/useActivatedSurveys.ts"],"sourcesContent":["import { useEffect, useMemo, useState } from 'react'\n\nimport type { PropertyFilters, Survey } from '@posthog/core'\nimport { doesSurveyActivateByEvent, matchPropertyFilters } from '@posthog/core/surveys'\nimport { PostHog } from '../posthog-rn'\n\nconst SURVEY_SHOWN_EVENT_NAME = 'survey shown'\n\ninterface EventSurveyConfig {\n surveyId: string\n propertyFilters?: PropertyFilters\n}\n\nexport function useActivatedSurveys(posthog: PostHog, surveys: Survey[]): ReadonlySet<string> {\n const [activatedSurveys, setActivatedSurveys] = useState<ReadonlySet<string>>(new Set())\n\n useEffect(() => {\n setActivatedSurveys(new Set())\n return posthog.on('surveysReset', () => setActivatedSurveys(new Set()))\n }, [posthog])\n\n const eventMap = useMemo(() => {\n const newEventMap = new Map<string, EventSurveyConfig[]>()\n for (const survey of surveys.filter(doesSurveyActivateByEvent)) {\n for (const event of survey.conditions?.events?.values ?? []) {\n const configs = newEventMap.get(event.name) ?? []\n configs.push({\n surveyId: survey.id,\n propertyFilters: event.propertyFilters,\n })\n newEventMap.set(event.name, configs)\n }\n }\n return newEventMap\n }, [surveys])\n\n useEffect(() => {\n if (eventMap.size > 0) {\n return posthog.on('capture', (payload: { event: string; properties?: Record<string, unknown> }) => {\n if (eventMap.has(payload.event)) {\n const configs = eventMap.get(payload.event) ?? []\n const matchingSurveyIds = configs\n .filter((config) => matchPropertyFilters(config.propertyFilters, payload.properties))\n .map((config) => config.surveyId)\n\n if (matchingSurveyIds.length > 0) {\n setActivatedSurveys((current) => new Set([...current, ...matchingSurveyIds]))\n }\n } else if (payload.event === SURVEY_SHOWN_EVENT_NAME) {\n const surveyId = payload.properties?.$survey_id as string | undefined\n if (surveyId) {\n setActivatedSurveys((current) => {\n if (!current.has(surveyId)) {\n return current\n }\n const next = new Set(current)\n next.delete(surveyId)\n return next\n })\n }\n }\n })\n }\n }, [eventMap, posthog])\n\n return activatedSurveys\n}\n"],"mappings":"yYAAA,IAAAA,MAAA,CAAAC,OAAA,UAGA,IAAAC,QAAA,CAAAD,OAAA,0BAAuF,SAAAE,2BAAAC,CAAA,CAAAC,CAAA,MAAAC,CAAA,qBAAAC,MAAA,EAAAH,CAAA,CAAAG,MAAA,CAAAC,QAAA,GAAAJ,CAAA,mBAAAE,CAAA,KAAAG,KAAA,CAAAC,OAAA,CAAAN,CAAA,IAAAE,CA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
|
import { SurveyWithIteration } from '@posthog/core/surveys';
|
|
2
|
+
import type { PostHog } from '../posthog-rn';
|
|
2
3
|
type SurveyStorage = {
|
|
4
|
+
isReady: boolean;
|
|
3
5
|
seenSurveys: string[];
|
|
4
6
|
setSeenSurvey: (survey: SurveyWithIteration) => void;
|
|
5
7
|
lastSeenSurveyDate: Date | undefined;
|
|
6
8
|
setLastSeenSurveyDate: (date: Date) => void;
|
|
7
9
|
};
|
|
8
10
|
export declare function updateSeenSurveys(current: string[], survey: SurveyWithIteration): string[];
|
|
9
|
-
export declare function useSurveyStorage(): SurveyStorage;
|
|
11
|
+
export declare function useSurveyStorage(client?: PostHog): SurveyStorage;
|
|
10
12
|
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.updateSeenSurveys=updateSeenSurveys;exports.useSurveyStorage=useSurveyStorage;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");var _react=require("react");var _usePostHog=require("../hooks/usePostHog");var MAX_SEEN_SURVEYS=20;function updateSeenSurveys(current,survey){var surveyKey=(0,_surveys.getSurveyIterationKey)(survey);return[surveyKey].concat((0,_toConsumableArray2["default"])(current.filter(function(key){return!(0,_surveys.isSurveyKeyForSurvey)(key,survey.id);}))).slice(0,MAX_SEEN_SURVEYS);}function useSurveyStorage(){var
|
|
1
|
+
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.updateSeenSurveys=updateSeenSurveys;exports.useSurveyStorage=useSurveyStorage;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));var _core=require("@posthog/core");var _surveys=require("@posthog/core/surveys");var _react=require("react");var _usePostHog=require("../hooks/usePostHog");var MAX_SEEN_SURVEYS=20;function updateSeenSurveys(current,survey){var surveyKey=(0,_surveys.getSurveyIterationKey)(survey);return[surveyKey].concat((0,_toConsumableArray2["default"])(current.filter(function(key){return!(0,_surveys.isSurveyKeyForSurvey)(key,survey.id);}))).slice(0,MAX_SEEN_SURVEYS);}function useSurveyStorage(client){var fromHook=(0,_usePostHog.usePostHog)();var posthogStorage=client!==null&&client!==void 0?client:fromHook;var _useState=(0,_react.useState)(false),_useState2=(0,_slicedToArray2["default"])(_useState,2),isReady=_useState2[0],setIsReady=_useState2[1];var _useState3=(0,_react.useState)(undefined),_useState4=(0,_slicedToArray2["default"])(_useState3,2),lastSeenSurveyDate=_useState4[0],setLastSeenSurveyDate=_useState4[1];var _useState5=(0,_react.useState)([]),_useState6=(0,_slicedToArray2["default"])(_useState5,2),seenSurveys=_useState6[0],setSeenSurveys=_useState6[1];(0,_react.useEffect)(function(){var mounted=true;setIsReady(false);var load=function load(){if(!mounted)return;var lastSeenSurveyDate=posthogStorage.getPersistedProperty(_core.PostHogPersistedProperty.SurveyLastSeenDate);if(typeof lastSeenSurveyDate==='string'){setLastSeenSurveyDate(new Date(lastSeenSurveyDate));}var serialisedSeenSurveys=posthogStorage.getPersistedProperty(_core.PostHogPersistedProperty.SurveysSeen);if(typeof serialisedSeenSurveys==='string'){var parsedSeenSurveys;try{parsedSeenSurveys=JSON.parse(serialisedSeenSurveys);}catch(_a){parsedSeenSurveys=[];}if(Array.isArray(parsedSeenSurveys)){setSeenSurveys(parsedSeenSurveys.filter(function(key){return typeof key==='string';}));}}else{setSeenSurveys([]);}setIsReady(true);};void posthogStorage.ready().then(load);var unsubscribe=posthogStorage.on('surveysReset',function(){void posthogStorage.ready().then(load);});return function(){mounted=false;unsubscribe();};},[posthogStorage]);return{isReady:isReady,seenSurveys:seenSurveys,setSeenSurvey:(0,_react.useCallback)(function(survey){setSeenSurveys(function(current){var newValue=updateSeenSurveys(current,survey);posthogStorage.setPersistedProperty(_core.PostHogPersistedProperty.SurveysSeen,JSON.stringify(newValue));return newValue;});},[posthogStorage]),lastSeenSurveyDate:lastSeenSurveyDate,setLastSeenSurveyDate:(0,_react.useCallback)(function(date){setLastSeenSurveyDate(date);posthogStorage.setPersistedProperty(_core.PostHogPersistedProperty.SurveyLastSeenDate,date.toISOString());},[posthogStorage])};}
|
|
2
|
+
//# sourceMappingURL=useSurveyStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSurveyStorage.js","
|
|
1
|
+
{"version":3,"file":"useSurveyStorage.js","names":["_core","require","_surveys","_react","_usePostHog","MAX_SEEN_SURVEYS","updateSeenSurveys","current","survey","surveyKey","getSurveyIterationKey","concat","_toConsumableArray2","filter","key","isSurveyKeyForSurvey","id","slice","useSurveyStorage","client","fromHook","usePostHog","posthogStorage","_useState","useState","_useState2","_slicedToArray2","isReady","setIsReady","_useState3","undefined","_useState4","lastSeenSurveyDate","setLastSeenSurveyDate","_useState5","_useState6","seenSurveys","setSeenSurveys","useEffect","mounted","load","getPersistedProperty","PostHogPersistedProperty","SurveyLastSeenDate","Date","serialisedSeenSurveys","SurveysSeen","parsedSeenSurveys","JSON","parse","Array","isArray","ready","then","unsubscribe","on","setSeenSurvey","useCallback","newValue","setPersistedProperty","stringify","date","toISOString"],"sources":["../../src/surveys/useSurveyStorage.ts"],"sourcesContent":["import { PostHogPersistedProperty } from '@posthog/core'\nimport { getSurveyIterationKey, isSurveyKeyForSurvey, SurveyWithIteration } from '@posthog/core/surveys'\nimport { useCallback, useEffect, useState } from 'react'\nimport { usePostHog } from '../hooks/usePostHog'\nimport type { PostHog } from '../posthog-rn'\n\ntype SurveyStorage = {\n isReady: boolean\n // Iteration-qualified keys (getSurveyIterationKey) so repeating surveys re-show when a new iteration starts\n seenSurveys: string[]\n setSeenSurvey: (survey: SurveyWithIteration) => void\n lastSeenSurveyDate: Date | undefined\n setLastSeenSurveyDate: (date: Date) => void\n}\n\n// To keep storage bounded, only keep the last 20 seen surveys\nconst MAX_SEEN_SURVEYS = 20\n\n// One slot per survey: stale keys from earlier iterations (or the pre-iteration bare id)\n// can never match again and would otherwise evict other surveys' seen state.\nexport function updateSeenSurveys(current: string[], survey: SurveyWithIteration): string[] {\n const surveyKey = getSurveyIterationKey(survey)\n return [surveyKey, ...current.filter((key) => !isSurveyKeyForSurvey(key, survey.id))].slice(0, MAX_SEEN_SURVEYS)\n}\n\nexport function useSurveyStorage(client?: PostHog): SurveyStorage {\n const fromHook = usePostHog()\n const posthogStorage = client ?? fromHook\n const [isReady, setIsReady] = useState(false)\n const [lastSeenSurveyDate, setLastSeenSurveyDate] = useState<Date | undefined>(undefined)\n const [seenSurveys, setSeenSurveys] = useState<string[]>([])\n\n useEffect(() => {\n let mounted = true\n setIsReady(false)\n const load = () => {\n if (!mounted) return\n const lastSeenSurveyDate = posthogStorage.getPersistedProperty(PostHogPersistedProperty.SurveyLastSeenDate)\n if (typeof lastSeenSurveyDate === 'string') {\n setLastSeenSurveyDate(new Date(lastSeenSurveyDate))\n }\n\n const serialisedSeenSurveys = posthogStorage.getPersistedProperty(PostHogPersistedProperty.SurveysSeen)\n if (typeof serialisedSeenSurveys === 'string') {\n let parsedSeenSurveys: unknown\n try {\n parsedSeenSurveys = JSON.parse(serialisedSeenSurveys)\n } catch {\n parsedSeenSurveys = []\n }\n if (Array.isArray(parsedSeenSurveys)) {\n setSeenSurveys(parsedSeenSurveys.filter((key): key is string => typeof key === 'string'))\n }\n } else {\n setSeenSurveys([])\n }\n setIsReady(true)\n }\n void posthogStorage.ready().then(load)\n const unsubscribe = posthogStorage.on('surveysReset', () => {\n void posthogStorage.ready().then(load)\n })\n return () => {\n mounted = false\n unsubscribe()\n }\n }, [posthogStorage])\n\n return {\n isReady,\n seenSurveys,\n setSeenSurvey: useCallback(\n (survey: SurveyWithIteration) => {\n setSeenSurveys((current) => {\n const newValue = updateSeenSurveys(current, survey)\n posthogStorage.setPersistedProperty(PostHogPersistedProperty.SurveysSeen, JSON.stringify(newValue))\n return newValue\n })\n },\n [posthogStorage]\n ),\n lastSeenSurveyDate,\n setLastSeenSurveyDate: useCallback(\n (date: Date) => {\n setLastSeenSurveyDate(date)\n posthogStorage.setPersistedProperty(PostHogPersistedProperty.SurveyLastSeenDate, date.toISOString())\n },\n [posthogStorage]\n ),\n }\n}\n"],"mappings":"+aAAA,IAAAA,KAAA,CAAAC,OAAA,kBACA,IAAAC,QAAA,CAAAD,OAAA,0BACA,IAAAE,MAAA,CAAAF,OAAA,UACA,IAAAG,WAAA,CAAAH,OAAA,wBAaA,GAAM,CAAAI,gBAAgB,CAAG,EAAE,CAIrB,QAAU,CAAAC,iBAAiBA,CAACC,OAAiB,CAAEC,MAA2B,EAC9E,GAAM,CAAAC,SAAS,CAAG,GAAAC,8BAAqB,EAACF,MAAM,CAAC,CAC/C,MAAO,CAACC,SAAS,EAAAE,MAAA,IAAAC,mBAAA,aAAKL,OAAO,CAACM,MAAM,CAAC,SAACC,GAAG,QAAK,CAAC,GAAAC,6BAAoB,EAACD,GAAG,CAAEN,MAAM,CAACQ,EAAE,CAAC,GAAC,GAAEC,KAAK,CAAC,CAAC,CAAEZ,gBAAgB,CAAC,CAClH,CAEM,QAAU,CAAAa,gBAAgBA,CAACC,MAAgB,EAC/C,GAAM,CAAAC,QAAQ,CAAG,GAAAC,sBAAU,GAAE,CAC7B,GAAM,CAAAC,cAAc,CAAGH,MAAM,SAANA,MAAM,UAANA,MAAM,CAAIC,QAAQ,CACzC,IAAAG,SAAA,CAA8B,GAAAC,eAAQ,EAAC,KAAK,CAAC,CAAAC,UAAA,IAAAC,eAAA,aAAAH,SAAA,IAAtCI,OAAO,CAAAF,UAAA,IAAEG,UAAU,CAAAH,UAAA,IAC1B,IAAAI,UAAA,CAAoD,GAAAL,eAAQ,EAAmBM,SAAS,CAAC,CAAAC,UAAA,IAAAL,eAAA,aAAAG,UAAA,IAAlFG,k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