@lookit/templates 2.0.0 → 2.1.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/README.md +1 -1
- package/dist/index.browser.js +15 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +17 -14
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +14 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/consentVideoTemplate.ts +2 -0
- package/src/index.ts +8 -1
- package/src/utils.spec.ts +11 -1
- package/src/utils.ts +12 -0
package/dist/index.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var consent_garden = "<h1>\n {{#if header}} {{exp-format header}} {{else}}\n
|
|
|
9
9
|
|
|
10
10
|
var consent_template_5 = "<h1>\n {{t \"consent-template-5.header\"}}:\n {{experiment.name}}\n</h1>\n\n<p>\n {{t\n \"consent-template-5.intro-sentence\"\n name=PIName\n institution=institution\n experiment=experiment.name\n }}\n {{exp-format summary_statement}}\n</p>\n\n<h2>\n {{#if purpose_header}} {{purpose_header}} {{else}}\n {{t \"consent-template-5.purpose-header\"}}\n {{/if}}\n</h2>\n<p>{{exp-format purpose}}</p>\n\n<h2>\n {{#if procedures_header}} {{procedures_header}} {{else}}\n {{t \"consent-template-5.procedures-header\"}}\n {{/if}}\n</h2>\n<p>\n {{t \"consent-template-5.duration-statement\" duration=experiment.duration}}\n {{exp-format procedures}}\n</p>\n\n<h2>\n {{#if participation_header}} {{participation_header}} {{else}}\n {{t \"consent-template-5.participation-header\"}}\n {{/if}}\n</h2>\n<p>\n {{t \"consent-template-5.participation-content\" only_adult=prompt_only_adults}}\n</p>\n\n{{#if voluntary_participation}}\n <p>{{exp-format voluntary_participation}}</p>\n{{/if}}\n{{#if risk_statement}}\n\n <h2>\n {{#if risk_header}} {{risk_header}} {{else}}\n {{t \"consent-template-5.risk-header\"}}\n {{/if}}\n </h2>\n\n <p>{{exp-format risk_statement}}</p>\n{{/if}}\n\n<h2>\n {{#if benefits_header}} {{benefits_header}} {{else}}\n {{t \"consent-template-5.benefits-header\"}}\n {{/if}}\n</h2>\n\n<p>{{exp-format payment}}</p>\n\n<h2>{{t \"consent-template-5.data-collection-header\"}}</h2>\n\n<p>\n {{t \"consent-template-5.data-collection-1\" only_adult=prompt_only_adults}}\n {{t \"consent-template-5.data-collection-2\"}}\n</p>\n\n<p>{{t \"consent-template-5.data-collection-3\"}}</p>\n\n<h2>{{t \"consent-template-5.video-privacy-header\"}}</h2>\n<p>{{t \"consent-template-5.video-privacy-consent\"}}</p>\n\n{{#if private_level_only}}\n <p>\n {{t \"consent-template-5.video-privacy-private-description\"}}\n {{t \"consent-template-5.video-privacy-withdraw-private-only\"}}\n </p>\n{{else}}\n <p>{{t \"consent-template-5.video-privacy-overview\"}}:</p>\n <ul>\n <li>\n \"{{t \"consent-template-5.video-privacy-Private\"}}\":\n {{t \"consent-template-5.video-privacy-private-description\"}}\n </li>\n <li>\n \"{{t \"consent-template-5.video-privacy-Scientific\"}}\":\n {{t \"consent-template-5.video-privacy-scientific-description\"}}\n </li>\n <li>\n \"{{t \"consent-template-5.video-privacy-Publicity\"}}\":\n {{t \"consent-template-5.video-privacy-publicity-description\"}}\n </li>\n </ul>\n <p>{{t \"consent-template-5.video-privacy-withdraw\"}}</p>\n{{/if}}\n{{#if include_databrary}}\n <p>{{{t \"consent-template-5.databrary\"}}}</p>\n{{/if}}\n{{#if additional_video_privacy_statement}}\n <p>{{exp-format additional_video_privacy_statement}}</p>\n{{/if}}\n\n<h2>{{t \"consent-template-5.data-use-researchers-header\"}}</h2>\n<p>\n {{t\n \"consent-template-5.data-use-researchers-content-1\"\n name=PIName\n institution=institution\n }}\n</p>\n<ul>\n <li>{{t \"consent-template-5.data-use-researchers-item-1\"}}</li>\n <li>{{t \"consent-template-5.data-use-researchers-item-2\"}}</li>\n <li>\n {{t\n \"consent-template-5.data-use-researchers-item-3\"\n only_adult=prompt_only_adults\n }}\n </li>\n</ul>\n<p>\n {{t\n \"consent-template-5.data-use-researchers-content-2\"\n only_adult=prompt_only_adults\n }}\n</p>\n{{#if datause}}\n <p>{{exp-format datause}}</p>\n{{/if}}\n\n<h2>{{t \"consent-template-5.data-use-Lookit-header\"}}</h2>\n<p>{{t \"consent-template-5.data-use-Lookit-content\"}}</p>\n\n<h2>{{t \"consent-template-5.publication-header\"}}</h2>\n<p>\n {{t \"consent-template-5.publication-content\" only_adult=prompt_only_adults}}\n</p>\n\n{{#if additional_segments}}\n {{#each additional_segments as |segment|}}\n <h2>{{exp-format segment.title}}</h2>\n <p>{{exp-format segment.text}}</p>\n {{/each}}\n{{/if}}\n\n<h2>{{t \"consent-template-5.research-subject-rights-header\"}}</h2>\n<p>{{{exp-format research_rights_statement}}}</p>\n\n{{#if gdpr}}\n <h2>{{t \"consent-template-5.gdpr-header\"}}</h2>\n <p>\n {{t \"consent-template-5.gdpr-personal\"}}:\n {{exp-format gdpr_personal_data}}.\n {{t \"consent-template-5.gdpr-sensitive\"}}:\n {{exp-format gdpr_sensitive_data}}\n </p>\n <p>{{t \"consent-template-5.gdpr-2\"}}</p>\n{{/if}}\n\n<h2>{{t \"consent-template-5.contact-header\"}}</h2>\n<p>\n {{t\n \"consent-template-5.contact-statement-1\"\n name=PIName\n institution=institution\n contact=PIContact\n only_adult=prompt_only_adults\n omit_injury=omit_injury_phrase\n }}\n</p>\n<p>\n {{t \"consent-template-5.contact-statement-2\" only_adult=prompt_only_adults}}\n</p>";
|
|
11
11
|
|
|
12
|
-
var consentVideoTrialTemplate = "<div id=\"consent-video-trial\">\n <div class=\"left-column\">{{{consent}}}</div>\n <div class=\"right-column\">\n <div id=\"{{video_container_id}}\" class=\"jspsych-content\"></div>\n\n <ol>\n <li>{{t \"exp-lookit-video-consent.consent-step-1\"}}.</li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"record\">\n {{t \"exp-lookit-video-consent.start-consent-recording\"}}...\n </button>\n </li>\n <li>\n {{{t \"exp-lookit-video-consent.read-statement-below\"}}}\n {{t \"exp-lookit-video-consent.signed-alternative\"}}\n\n <div class=\"consent-statement\">\n {{#if consent_statement_text}}\n \"{{consent_statement_text}}\"\n {{else if prompt_only_adults}}\n \"{{t \"exp-lookit-video-consent.prompt-adult-only\"}}\"\n {{else}}\n \"{{t \"exp-lookit-video-consent.prompt\"}}\"\n {{/if}}\n </div>\n\n </li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"stop\" disabled>\n {{t \"exp-lookit-video-consent.stop-recording\"}}\n </button>\n </li>\n <li>\n <button class=\"jspsych-btn\" id=\"play\" disabled>\n {{t \"exp-lookit-video-consent.play-consent-video-button\"}}\n </button>\n {{t \"exp-lookit-video-consent.review-video\"}}\n </li>\n </ol>\n <button id=\"next\" class=\"jspsych-btn\" disabled>Next</button>\n </div>\n\n</div>";
|
|
12
|
+
var consentVideoTrialTemplate = "<div id=\"consent-video-trial\">\n <div class=\"left-column\">{{{consent}}}</div>\n <div class=\"right-column\">\n <div id=\"{{msg_container_id}}\">{{t\n \"exp-lookit-video-consent.Not-recording\"\n }}</div>\n <div id=\"{{video_container_id}}\" class=\"jspsych-content\"></div>\n\n <ol>\n <li>{{t \"exp-lookit-video-consent.consent-step-1\"}}.</li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"record\">\n {{t \"exp-lookit-video-consent.start-consent-recording\"}}...\n </button>\n </li>\n <li>\n {{{t \"exp-lookit-video-consent.read-statement-below\"}}}\n {{t \"exp-lookit-video-consent.signed-alternative\"}}\n\n <div class=\"consent-statement\">\n {{#if consent_statement_text}}\n \"{{consent_statement_text}}\"\n {{else if prompt_only_adults}}\n \"{{t \"exp-lookit-video-consent.prompt-adult-only\"}}\"\n {{else}}\n \"{{t \"exp-lookit-video-consent.prompt\"}}\"\n {{/if}}\n </div>\n\n </li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"stop\" disabled>\n {{t \"exp-lookit-video-consent.stop-recording\"}}\n </button>\n </li>\n <li>\n <button class=\"jspsych-btn\" id=\"play\" disabled>\n {{t \"exp-lookit-video-consent.play-consent-video-button\"}}\n </button>\n {{t \"exp-lookit-video-consent.review-video\"}}\n </li>\n </ol>\n <button id=\"next\" class=\"jspsych-btn\" disabled>Next</button>\n </div>\n\n</div>";
|
|
13
13
|
|
|
14
14
|
class LocaleNotFoundError extends Error {
|
|
15
15
|
constructor(baseName) {
|
|
@@ -89,8 +89,12 @@ Handlebars.registerHelper("t", (context, { hash }) => {
|
|
|
89
89
|
const txt = String(i18next.t(context, hash));
|
|
90
90
|
return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;
|
|
91
91
|
});
|
|
92
|
+
const translateString = (messageIdStr) => {
|
|
93
|
+
return i18next.t(messageIdStr);
|
|
94
|
+
};
|
|
92
95
|
|
|
93
96
|
const video_container_id = "lookit-jspsych-video-container";
|
|
97
|
+
const msg_container_id = "lookit-jspsych-video-msg-container";
|
|
94
98
|
const consentVideo = (trial) => {
|
|
95
99
|
const experiment = window.chs.study.attributes;
|
|
96
100
|
const { PIName, PIContact } = trial;
|
|
@@ -105,7 +109,8 @@ const consentVideo = (trial) => {
|
|
|
105
109
|
return Handlebars.compile(consentVideoTrialTemplate)({
|
|
106
110
|
...trial,
|
|
107
111
|
consent,
|
|
108
|
-
video_container_id
|
|
112
|
+
video_container_id,
|
|
113
|
+
msg_container_id
|
|
109
114
|
});
|
|
110
115
|
};
|
|
111
116
|
const consentDocument = (trial) => {
|
|
@@ -276,7 +281,13 @@ const videoConfig = (trial, html_params) => {
|
|
|
276
281
|
});
|
|
277
282
|
};
|
|
278
283
|
|
|
279
|
-
var index = {
|
|
284
|
+
var index = {
|
|
285
|
+
consentVideo,
|
|
286
|
+
videoConfig,
|
|
287
|
+
uploadingVideo,
|
|
288
|
+
exitSurvey,
|
|
289
|
+
translateString
|
|
290
|
+
};
|
|
280
291
|
|
|
281
292
|
module.exports = index;
|
|
282
293
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/errors.ts","../src/utils.ts","../src/consentVideoTemplate.ts","../src/exitSurveyTemplate.ts","../src/uploadingVideoTemplate.ts","../src/videoConfigTemplate.ts","../src/index.ts"],"sourcesContent":["/** Error thrown when specified language isn't found */\nexport class LocaleNotFoundError extends Error {\n /**\n * This will be thrown when attempting to init i18n\n *\n * @param baseName - Language a2code with region\n */\n public constructor(baseName: string) {\n super(`\"${baseName}\" locale not found.`);\n }\n}\n/** Error thrown when researcher selects template that isn't available. */\nexport class ConsentTemplateNotFound extends Error {\n /**\n * This will let the researcher know that their template isn't found.\n *\n * @param template - Supplied name of consent template.\n */\n public constructor(template: string) {\n super(`Consent template \"${template}\" not found.`);\n }\n}\n","import Handlebars from \"handlebars\";\nimport i18next from \"i18next\";\nimport ICU from \"i18next-icu\";\nimport Yaml from \"js-yaml\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport en_us from \"../i18n/en-us.yaml\";\nimport eu from \"../i18n/eu.yaml\";\nimport fr from \"../i18n/fr.yaml\";\nimport hu from \"../i18n/hu.yaml\";\nimport it from \"../i18n/it.yaml\";\nimport ja from \"../i18n/ja.yaml\";\nimport nl from \"../i18n/nl.yaml\";\nimport pt_br from \"../i18n/pt-br.yaml\";\nimport pt from \"../i18n/pt.yaml\";\nimport { LocaleNotFoundError } from \"./errors\";\n\n/**\n * Pulled from EFP. Function to convert researcher's text to HTML.\n *\n * @param text - Text\n * @returns Formatted string\n */\nexport const expFormat = (text?: string | string[]) => {\n if (!text) {\n return \"\";\n }\n\n if (Array.isArray(text)) {\n text = text.join(\"\\n\\n\");\n }\n\n return text\n .replace(/(\\r\\n|\\n|\\r)/gm, \"<br>\")\n .replace(/\\t/gm, \" \");\n};\n\n/**\n * Get a translation resources from yaml files.\n *\n * @returns Resources for i18next\n */\nconst resources = () => {\n const translations = {\n \"en-us\": en_us,\n eu,\n fr,\n hu,\n it,\n ja,\n nl,\n \"pt-br\": pt_br,\n pt,\n };\n\n return Object.entries(translations).reduce((prev, [locale, translation]) => {\n const lcl = new Intl.Locale(locale);\n return {\n ...prev,\n [lcl.baseName]: {\n translation: Yaml.load(translation) as Record<string, string>,\n },\n };\n }, {});\n};\n\n/**\n * Initialize i18next with parameters from trial.\n *\n * @param trial - Trial data including user supplied parameters.\n */\nexport const setLocale = (trial: TrialType<PluginInfo>) => {\n const lcl = new Intl.Locale(trial.locale);\n\n if (!i18next.hasResourceBundle(lcl.baseName, \"translation\")) {\n throw new LocaleNotFoundError(trial.locale);\n }\n\n if (i18next.language !== lcl.baseName) {\n i18next.changeLanguage(lcl.baseName);\n }\n};\n\n// Initialize translations\ni18next.use(ICU).init({\n debug: process.env.DEBUG === \"true\",\n resources: resources(),\n});\n\n// Setup Handlebars' helpers\nHandlebars.registerHelper(\"exp-format\", (context) => expFormat(context));\nHandlebars.registerHelper(\"t\", (context, { hash }) => {\n const txt = String(i18next.t(context, hash));\n return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;\n});\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport consent_garden from \"../hbs/consent-garden.hbs\";\nimport consent_template_5 from \"../hbs/consent-template-5.hbs\";\nimport consentVideoTrialTemplate from \"../hbs/consent-video-trial.hbs\";\nimport { ConsentTemplateNotFound } from \"./errors\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\nconst video_container_id = \"lookit-jspsych-video-container\";\n\n/**\n * Translate, render, and get consent document HTML.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Consent document HTML\n */\nexport const consentVideo = (trial: TrialType<PluginInfo>) => {\n const experiment = window.chs.study.attributes;\n const { PIName, PIContact } = trial;\n\n setLocale(trial);\n\n const consentDocumentTemplate = consentDocument(trial);\n\n const consent = Handlebars.compile(consentDocumentTemplate)({\n ...trial,\n name: PIName,\n contact: PIContact,\n experiment,\n });\n\n return Handlebars.compile(consentVideoTrialTemplate)({\n ...trial,\n consent,\n video_container_id,\n });\n};\n\n/**\n * Get consent template by name.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Consent template\n */\nconst consentDocument = (trial: TrialType<PluginInfo>) => {\n switch (trial.template) {\n case \"consent-template-5\":\n return consent_template_5;\n case \"consent-garden\":\n return consent_garden;\n default:\n throw new ConsentTemplateNotFound(trial.template);\n }\n};\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport i18next from \"i18next\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\n/**\n * Class to augment and translate the exit survey JSON based on user set\n * parameters.\n */\nclass ExitSurveyJson {\n private names = <const>{\n birthDate: \"birthDate\",\n databraryShare: \"databraryShare\",\n useOfMedia: \"useOfMedia\",\n withdrawal: \"withdrawal\",\n feedback: \"feedback\",\n };\n public survey = {\n pages: [\n {\n elements: [\n {\n description: \"exp-lookit-exit-survey.why-birthdate\",\n inputType: \"date\",\n isRequired: true,\n maxValueExpression: \"today()\",\n name: this.names.birthDate,\n title: \"exp-lookit-exit-survey.confirm-birthdate\",\n type: \"text\",\n },\n {\n description: \"exp-lookit-exit-survey.databrary-info\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.databraryShare,\n title: \"exp-lookit-exit-survey.q-databrary\",\n type: \"boolean\",\n valueFalse: \"no\",\n valueTrue: \"yes\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.private-option-part-1\",\n value: \"private\",\n },\n {\n text: \"exp-lookit-exit-survey.scientific-option\",\n value: \"scientific\",\n },\n {\n text: \"exp-lookit-exit-survey.publicity-option\",\n value: \"public\",\n },\n ],\n description: \"\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.useOfMedia,\n title: \"exp-lookit-exit-survey.acceptable-use-header\",\n type: \"radiogroup\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.withdrawal-details\",\n value: true,\n },\n ],\n defaultValue: [],\n isRequired: false,\n name: this.names.withdrawal,\n title: \"exp-lookit-exit-survey.withdrawal-header\",\n type: \"checkbox\",\n },\n {\n autoGrow: true,\n name: this.names.feedback,\n rows: 3,\n title: \"exp-lookit-exit-survey.feedback-label\",\n type: \"comment\",\n },\n ],\n name: \"page1\",\n },\n ],\n showQuestionNumbers: \"off\",\n };\n\n /**\n * Adjust survey json to meet user's parameters.\n *\n * @param trial - Trial data including user supplied parameters.\n */\n public constructor(private trial: TrialType<PluginInfo>) {\n this.showDatabraryOptions();\n this.additionalVideoPrivacyText();\n this.privateLevelOnly();\n this.translation();\n }\n\n /** Alter survey to show Databrary options. */\n private showDatabraryOptions() {\n if (!this.trial.show_databrary_options) {\n const survey_elements = this.survey.pages[0].elements;\n const databrary_share_element_idx = survey_elements.findIndex(\n (element) => element.name === this.names.databraryShare,\n );\n survey_elements.splice(databrary_share_element_idx, 1);\n }\n }\n\n /** Alter survey to contain additional video privacy text. */\n private additionalVideoPrivacyText() {\n const element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n element &&\n Object.assign(element, {\n description: this.trial.additional_video_privacy_text,\n });\n }\n\n /** Alter survey to only show \"private\" on use of media question. */\n private privateLevelOnly() {\n if (this.trial.private_level_only) {\n const media_use_element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n media_use_element &&\n Object.assign(media_use_element, {\n defaultValue: \"private\",\n description: \"exp-lookit-exit-survey.private-option-part-1\",\n choicesVisibleIf: \"false\", // this must be a string expression\n isRequired: false,\n });\n }\n }\n\n /** Translate the survey text. */\n private translation() {\n const { contact_info, name } = window.chs.study.attributes;\n const view = {\n ...this.trial,\n include_example: this.trial.include_withdrawal_example,\n contact: contact_info,\n name,\n };\n\n this.survey.pages[0].elements.forEach((element) => {\n // Descriptions\n element.description &&\n Object.assign(element, {\n description: i18next.t(element.description, view),\n });\n\n // Titles\n Object.assign(element, { title: i18next.t(element.title, view) });\n\n // Choices\n element.choices &&\n element.choices.forEach((choice) => {\n Object.assign(choice, { text: i18next.t(choice.text, view) });\n });\n });\n }\n}\n\n/**\n * Translate survey text to desired locale.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Survey json\n */\nexport const exitSurvey = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n return new ExitSurveyJson(trial).survey;\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport uploadingVideoTemplate from \"../hbs/uploading-video.hbs\";\nimport { setLocale } from \"./utils\";\n\n/**\n * Get translated template for uploading video message.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Uploading video message HTML\n */\nexport const uploadingVideo = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n\n return Handlebars.compile(uploadingVideoTemplate)({});\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport videoConfigTemplate from \"../hbs/video-config.hbs\";\nimport { setLocale } from \"./utils\";\n\ntype VideoConfigTemplateParams = {\n webcam_container_id: string;\n reload_button_id_cam: string;\n camera_selection_id: string;\n mic_selection_id: string;\n step1_id: string;\n step2_id: string;\n step3_id: string;\n step_complete_class: string;\n reload_button_id_text: string;\n next_button_id: string;\n waiting_for_access_msg_id: string;\n checking_mic_msg_id: string;\n access_problem_msg_id: string;\n setup_problem_msg_id: string;\n chromeInitialPrompt: string;\n chromeAlwaysAllow: string;\n chromePermissions: string;\n firefoxInitialPrompt: string;\n firefoxChooseDevice: string;\n firefoxDevicesBlocked: string;\n checkmarkIcon: string;\n};\n\n/**\n * Get translated template for video config.\n *\n * @param trial - JsPsych trial object containing trial params\n * @param html_params - Additional context variables for the template.\n * @returns Video config HTML\n */\nexport const videoConfig = (\n trial: TrialType<PluginInfo>,\n html_params: VideoConfigTemplateParams,\n) => {\n setLocale(trial);\n\n return Handlebars.compile(videoConfigTemplate)({\n ...trial,\n ...html_params,\n });\n};\n","import { consentVideo } from \"./consentVideoTemplate\";\nimport { exitSurvey } from \"./exitSurveyTemplate\";\nimport { uploadingVideo } from \"./uploadingVideoTemplate\";\nimport { videoConfig } from \"./videoConfigTemplate\";\n\nexport default { consentVideo, videoConfig, uploadingVideo, exitSurvey };\n"],"names":["element"],"mappings":";;;;;;;;;;;;;AACO,MAAM,4BAA4B,KAAM,CAAA;AAAA,EAMtC,YAAY,QAAkB,EAAA;AACnC,IAAA,KAAA,CAAM,IAAI,QAA6B,CAAA,mBAAA,CAAA,CAAA,CAAA;AAAA,GACzC;AACF,CAAA;AAEO,MAAM,gCAAgC,KAAM,CAAA;AAAA,EAM1C,YAAY,QAAkB,EAAA;AACnC,IAAA,KAAA,CAAM,qBAAqB,QAAsB,CAAA,YAAA,CAAA,CAAA,CAAA;AAAA,GACnD;AACF;;;;;;;;;;;;;;;;;;;;ACCa,MAAA,SAAA,GAAY,CAAC,IAA6B,KAAA;AACrD,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAO,OAAA,EAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,KAAA,CAAM,OAAQ,CAAA,IAAI,CAAG,EAAA;AACvB,IAAO,IAAA,GAAA,IAAA,CAAK,KAAK,MAAM,CAAA,CAAA;AAAA,GACzB;AAEA,EAAA,OAAO,KACJ,OAAQ,CAAA,gBAAA,EAAkB,MAAM,CAChC,CAAA,OAAA,CAAQ,QAAQ,0BAA0B,CAAA,CAAA;AAC/C,CAAA,CAAA;AAOA,MAAM,YAAY,MAAM;AACtB,EAAA,MAAM,YAAe,GAAA;AAAA,IACnB,OAAS,EAAA,KAAA;AAAA,IACT,EAAA;AAAA,IACA,EAAA;AAAA,IACA,EAAA;AAAA,I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;ACqBa,MAAA,WAAA,GAAc,CACzB,KAAA,EACA,WACG,KAAA;AACH,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AAEf,EAAO,OAAA,UAAA,CAAW,OAAQ,CAAA,mBAAmB,CAAE,CAAA;AAAA,IAC7C,GAAG,KAAA;AAAA,IACH,GAAG,WAAA;AAAA,GACJ,CAAA,CAAA;AACH,CAAA;;ACzCA,YAAe,EAAE,YAAA,EAAc,WAAa,EAAA,cAAA,EAAgB,UAAW,EAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/errors.ts","../src/utils.ts","../src/consentVideoTemplate.ts","../src/exitSurveyTemplate.ts","../src/uploadingVideoTemplate.ts","../src/videoConfigTemplate.ts","../src/index.ts"],"sourcesContent":["/** Error thrown when specified language isn't found */\nexport class LocaleNotFoundError extends Error {\n /**\n * This will be thrown when attempting to init i18n\n *\n * @param baseName - Language a2code with region\n */\n public constructor(baseName: string) {\n super(`\"${baseName}\" locale not found.`);\n }\n}\n/** Error thrown when researcher selects template that isn't available. */\nexport class ConsentTemplateNotFound extends Error {\n /**\n * This will let the researcher know that their template isn't found.\n *\n * @param template - Supplied name of consent template.\n */\n public constructor(template: string) {\n super(`Consent template \"${template}\" not found.`);\n }\n}\n","import Handlebars from \"handlebars\";\nimport i18next from \"i18next\";\nimport ICU from \"i18next-icu\";\nimport Yaml from \"js-yaml\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport en_us from \"../i18n/en-us.yaml\";\nimport eu from \"../i18n/eu.yaml\";\nimport fr from \"../i18n/fr.yaml\";\nimport hu from \"../i18n/hu.yaml\";\nimport it from \"../i18n/it.yaml\";\nimport ja from \"../i18n/ja.yaml\";\nimport nl from \"../i18n/nl.yaml\";\nimport pt_br from \"../i18n/pt-br.yaml\";\nimport pt from \"../i18n/pt.yaml\";\nimport { LocaleNotFoundError } from \"./errors\";\n\n/**\n * Pulled from EFP. Function to convert researcher's text to HTML.\n *\n * @param text - Text\n * @returns Formatted string\n */\nexport const expFormat = (text?: string | string[]) => {\n if (!text) {\n return \"\";\n }\n\n if (Array.isArray(text)) {\n text = text.join(\"\\n\\n\");\n }\n\n return text\n .replace(/(\\r\\n|\\n|\\r)/gm, \"<br>\")\n .replace(/\\t/gm, \" \");\n};\n\n/**\n * Get a translation resources from yaml files.\n *\n * @returns Resources for i18next\n */\nconst resources = () => {\n const translations = {\n \"en-us\": en_us,\n eu,\n fr,\n hu,\n it,\n ja,\n nl,\n \"pt-br\": pt_br,\n pt,\n };\n\n return Object.entries(translations).reduce((prev, [locale, translation]) => {\n const lcl = new Intl.Locale(locale);\n return {\n ...prev,\n [lcl.baseName]: {\n translation: Yaml.load(translation) as Record<string, string>,\n },\n };\n }, {});\n};\n\n/**\n * Initialize i18next with parameters from trial.\n *\n * @param trial - Trial data including user supplied parameters.\n */\nexport const setLocale = (trial: TrialType<PluginInfo>) => {\n const lcl = new Intl.Locale(trial.locale);\n\n if (!i18next.hasResourceBundle(lcl.baseName, \"translation\")) {\n throw new LocaleNotFoundError(trial.locale);\n }\n\n if (i18next.language !== lcl.baseName) {\n i18next.changeLanguage(lcl.baseName);\n }\n};\n\n// Initialize translations\ni18next.use(ICU).init({\n debug: process.env.DEBUG === \"true\",\n resources: resources(),\n});\n\n// Setup Handlebars' helpers\nHandlebars.registerHelper(\"exp-format\", (context) => expFormat(context));\nHandlebars.registerHelper(\"t\", (context, { hash }) => {\n const txt = String(i18next.t(context, hash));\n return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;\n});\n\n/**\n * Public method for directly translating a string, without a corresponding\n * template.\n *\n * @param messageIdStr - Message ID string to be looked up in the translation\n * files.\n * @returns Translated string\n */\nexport const translateString = (messageIdStr: string) => {\n return i18next.t(messageIdStr);\n};\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport consent_garden from \"../hbs/consent-garden.hbs\";\nimport consent_template_5 from \"../hbs/consent-template-5.hbs\";\nimport consentVideoTrialTemplate from \"../hbs/consent-video-trial.hbs\";\nimport { ConsentTemplateNotFound } from \"./errors\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\nconst video_container_id = \"lookit-jspsych-video-container\";\nconst msg_container_id = \"lookit-jspsych-video-msg-container\";\n\n/**\n * Translate, render, and get consent document HTML.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Consent document HTML\n */\nexport const consentVideo = (trial: TrialType<PluginInfo>) => {\n const experiment = window.chs.study.attributes;\n const { PIName, PIContact } = trial;\n\n setLocale(trial);\n\n const consentDocumentTemplate = consentDocument(trial);\n\n const consent = Handlebars.compile(consentDocumentTemplate)({\n ...trial,\n name: PIName,\n contact: PIContact,\n experiment,\n });\n\n return Handlebars.compile(consentVideoTrialTemplate)({\n ...trial,\n consent,\n video_container_id,\n msg_container_id,\n });\n};\n\n/**\n * Get consent template by name.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Consent template\n */\nconst consentDocument = (trial: TrialType<PluginInfo>) => {\n switch (trial.template) {\n case \"consent-template-5\":\n return consent_template_5;\n case \"consent-garden\":\n return consent_garden;\n default:\n throw new ConsentTemplateNotFound(trial.template);\n }\n};\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport i18next from \"i18next\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\n/**\n * Class to augment and translate the exit survey JSON based on user set\n * parameters.\n */\nclass ExitSurveyJson {\n private names = <const>{\n birthDate: \"birthDate\",\n databraryShare: \"databraryShare\",\n useOfMedia: \"useOfMedia\",\n withdrawal: \"withdrawal\",\n feedback: \"feedback\",\n };\n public survey = {\n pages: [\n {\n elements: [\n {\n description: \"exp-lookit-exit-survey.why-birthdate\",\n inputType: \"date\",\n isRequired: true,\n maxValueExpression: \"today()\",\n name: this.names.birthDate,\n title: \"exp-lookit-exit-survey.confirm-birthdate\",\n type: \"text\",\n },\n {\n description: \"exp-lookit-exit-survey.databrary-info\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.databraryShare,\n title: \"exp-lookit-exit-survey.q-databrary\",\n type: \"boolean\",\n valueFalse: \"no\",\n valueTrue: \"yes\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.private-option-part-1\",\n value: \"private\",\n },\n {\n text: \"exp-lookit-exit-survey.scientific-option\",\n value: \"scientific\",\n },\n {\n text: \"exp-lookit-exit-survey.publicity-option\",\n value: \"public\",\n },\n ],\n description: \"\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.useOfMedia,\n title: \"exp-lookit-exit-survey.acceptable-use-header\",\n type: \"radiogroup\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.withdrawal-details\",\n value: true,\n },\n ],\n defaultValue: [],\n isRequired: false,\n name: this.names.withdrawal,\n title: \"exp-lookit-exit-survey.withdrawal-header\",\n type: \"checkbox\",\n },\n {\n autoGrow: true,\n name: this.names.feedback,\n rows: 3,\n title: \"exp-lookit-exit-survey.feedback-label\",\n type: \"comment\",\n },\n ],\n name: \"page1\",\n },\n ],\n showQuestionNumbers: \"off\",\n };\n\n /**\n * Adjust survey json to meet user's parameters.\n *\n * @param trial - Trial data including user supplied parameters.\n */\n public constructor(private trial: TrialType<PluginInfo>) {\n this.showDatabraryOptions();\n this.additionalVideoPrivacyText();\n this.privateLevelOnly();\n this.translation();\n }\n\n /** Alter survey to show Databrary options. */\n private showDatabraryOptions() {\n if (!this.trial.show_databrary_options) {\n const survey_elements = this.survey.pages[0].elements;\n const databrary_share_element_idx = survey_elements.findIndex(\n (element) => element.name === this.names.databraryShare,\n );\n survey_elements.splice(databrary_share_element_idx, 1);\n }\n }\n\n /** Alter survey to contain additional video privacy text. */\n private additionalVideoPrivacyText() {\n const element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n element &&\n Object.assign(element, {\n description: this.trial.additional_video_privacy_text,\n });\n }\n\n /** Alter survey to only show \"private\" on use of media question. */\n private privateLevelOnly() {\n if (this.trial.private_level_only) {\n const media_use_element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n media_use_element &&\n Object.assign(media_use_element, {\n defaultValue: \"private\",\n description: \"exp-lookit-exit-survey.private-option-part-1\",\n choicesVisibleIf: \"false\", // this must be a string expression\n isRequired: false,\n });\n }\n }\n\n /** Translate the survey text. */\n private translation() {\n const { contact_info, name } = window.chs.study.attributes;\n const view = {\n ...this.trial,\n include_example: this.trial.include_withdrawal_example,\n contact: contact_info,\n name,\n };\n\n this.survey.pages[0].elements.forEach((element) => {\n // Descriptions\n element.description &&\n Object.assign(element, {\n description: i18next.t(element.description, view),\n });\n\n // Titles\n Object.assign(element, { title: i18next.t(element.title, view) });\n\n // Choices\n element.choices &&\n element.choices.forEach((choice) => {\n Object.assign(choice, { text: i18next.t(choice.text, view) });\n });\n });\n }\n}\n\n/**\n * Translate survey text to desired locale.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Survey json\n */\nexport const exitSurvey = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n return new ExitSurveyJson(trial).survey;\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport uploadingVideoTemplate from \"../hbs/uploading-video.hbs\";\nimport { setLocale } from \"./utils\";\n\n/**\n * Get translated template for uploading video message.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Uploading video message HTML\n */\nexport const uploadingVideo = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n\n return Handlebars.compile(uploadingVideoTemplate)({});\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport videoConfigTemplate from \"../hbs/video-config.hbs\";\nimport { setLocale } from \"./utils\";\n\ntype VideoConfigTemplateParams = {\n webcam_container_id: string;\n reload_button_id_cam: string;\n camera_selection_id: string;\n mic_selection_id: string;\n step1_id: string;\n step2_id: string;\n step3_id: string;\n step_complete_class: string;\n reload_button_id_text: string;\n next_button_id: string;\n waiting_for_access_msg_id: string;\n checking_mic_msg_id: string;\n access_problem_msg_id: string;\n setup_problem_msg_id: string;\n chromeInitialPrompt: string;\n chromeAlwaysAllow: string;\n chromePermissions: string;\n firefoxInitialPrompt: string;\n firefoxChooseDevice: string;\n firefoxDevicesBlocked: string;\n checkmarkIcon: string;\n};\n\n/**\n * Get translated template for video config.\n *\n * @param trial - JsPsych trial object containing trial params\n * @param html_params - Additional context variables for the template.\n * @returns Video config HTML\n */\nexport const videoConfig = (\n trial: TrialType<PluginInfo>,\n html_params: VideoConfigTemplateParams,\n) => {\n setLocale(trial);\n\n return Handlebars.compile(videoConfigTemplate)({\n ...trial,\n ...html_params,\n });\n};\n","import { consentVideo } from \"./consentVideoTemplate\";\nimport { exitSurvey } from \"./exitSurveyTemplate\";\nimport { uploadingVideo } from \"./uploadingVideoTemplate\";\nimport { translateString } from \"./utils\";\nimport { videoConfig } from \"./videoConfigTemplate\";\n\nexport default {\n consentVideo,\n videoConfig,\n uploadingVideo,\n exitSurvey,\n translateString,\n};\n"],"names":["element"],"mappings":";;;;;;;;;;;;;AACO,MAAM,4BAA4B,KAAM,CAAA;AAAA,EAMtC,YAAY,QAAkB,EAAA;AACnC,IAAA,KAAA,CAAM,IAAI,QAA6B,CAAA,mBAAA,CAAA,CAAA,CAAA;AAAA,GACzC;AACF,CAAA;AAEO,MAAM,gCAAgC,KAAM,CAAA;AAAA,EAM1C,YAAY,QAAkB,EAAA;AACnC,IAAA,KAAA,CAAM,qBAAqB,QAAsB,CAAA,YAAA,CAAA,CAAA,CAAA;AAAA,GACnD;AACF;;;;;;;;;;;;;;;;;;;;ACCa,MAAA,SAAA,GAAY,CAAC,IAA6B,KAAA;AACrD,EAAA,IAAI,CAAC,IAAM,EAAA;AACT,IAAO,OAAA,EAAA,CAAA;AAAA,GACT;AAEA,EAAI,IAAA,KAA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AAClC,QAAO,MAAA,CAAA,MAAA,CAAO,MAAQ,EAAA,EAAE,IAAM,EAAA,OAAA,CAAQ,EAAE,MAAO,CAAA,IAAA,EAAM,IAAI,CAAA,EAAG,CAAA,CAAA;AAAA,OAC7D,CAAA,CAAA;AAAA,KACJ,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAQa,MAAA,UAAA,GAAa,CAAC,KAAiC,KAAA;AAC1D,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AACf,EAAO,OAAA,IAAI,cAAe,CAAA,KAAK,CAAE,CAAA,MAAA,CAAA;AACnC,CAAA;;;;ACxKa,MAAA,cAAA,GAAiB,CAAC,KAAiC,KAAA;AAC9D,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AAEf,EAAA,OAAO,UAAW,CAAA,OAAA,CAAQ,sBAAsB,CAAA,CAAE,EAAE,CAAA,CAAA;AACtD,CAAA;;;;ACqBa,MAAA,WAAA,GAAc,CACzB,KAAA,EACA,WACG,KAAA;AACH,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AAEf,EAAO,OAAA,UAAA,CAAW,OAAQ,CAAA,mBAAmB,CAAE,CAAA;AAAA,IAC7C,GAAG,KAAA;AAAA,IACH,GAAG,WAAA;AAAA,GACJ,CAAA,CAAA;AACH,CAAA;;ACxCA,YAAe;AAAA,EACb,YAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AACF,CAAA;;;;"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ var consent_garden = "<h1>\n {{#if header}} {{exp-format header}} {{else}}\n
|
|
|
7
7
|
|
|
8
8
|
var consent_template_5 = "<h1>\n {{t \"consent-template-5.header\"}}:\n {{experiment.name}}\n</h1>\n\n<p>\n {{t\n \"consent-template-5.intro-sentence\"\n name=PIName\n institution=institution\n experiment=experiment.name\n }}\n {{exp-format summary_statement}}\n</p>\n\n<h2>\n {{#if purpose_header}} {{purpose_header}} {{else}}\n {{t \"consent-template-5.purpose-header\"}}\n {{/if}}\n</h2>\n<p>{{exp-format purpose}}</p>\n\n<h2>\n {{#if procedures_header}} {{procedures_header}} {{else}}\n {{t \"consent-template-5.procedures-header\"}}\n {{/if}}\n</h2>\n<p>\n {{t \"consent-template-5.duration-statement\" duration=experiment.duration}}\n {{exp-format procedures}}\n</p>\n\n<h2>\n {{#if participation_header}} {{participation_header}} {{else}}\n {{t \"consent-template-5.participation-header\"}}\n {{/if}}\n</h2>\n<p>\n {{t \"consent-template-5.participation-content\" only_adult=prompt_only_adults}}\n</p>\n\n{{#if voluntary_participation}}\n <p>{{exp-format voluntary_participation}}</p>\n{{/if}}\n{{#if risk_statement}}\n\n <h2>\n {{#if risk_header}} {{risk_header}} {{else}}\n {{t \"consent-template-5.risk-header\"}}\n {{/if}}\n </h2>\n\n <p>{{exp-format risk_statement}}</p>\n{{/if}}\n\n<h2>\n {{#if benefits_header}} {{benefits_header}} {{else}}\n {{t \"consent-template-5.benefits-header\"}}\n {{/if}}\n</h2>\n\n<p>{{exp-format payment}}</p>\n\n<h2>{{t \"consent-template-5.data-collection-header\"}}</h2>\n\n<p>\n {{t \"consent-template-5.data-collection-1\" only_adult=prompt_only_adults}}\n {{t \"consent-template-5.data-collection-2\"}}\n</p>\n\n<p>{{t \"consent-template-5.data-collection-3\"}}</p>\n\n<h2>{{t \"consent-template-5.video-privacy-header\"}}</h2>\n<p>{{t \"consent-template-5.video-privacy-consent\"}}</p>\n\n{{#if private_level_only}}\n <p>\n {{t \"consent-template-5.video-privacy-private-description\"}}\n {{t \"consent-template-5.video-privacy-withdraw-private-only\"}}\n </p>\n{{else}}\n <p>{{t \"consent-template-5.video-privacy-overview\"}}:</p>\n <ul>\n <li>\n \"{{t \"consent-template-5.video-privacy-Private\"}}\":\n {{t \"consent-template-5.video-privacy-private-description\"}}\n </li>\n <li>\n \"{{t \"consent-template-5.video-privacy-Scientific\"}}\":\n {{t \"consent-template-5.video-privacy-scientific-description\"}}\n </li>\n <li>\n \"{{t \"consent-template-5.video-privacy-Publicity\"}}\":\n {{t \"consent-template-5.video-privacy-publicity-description\"}}\n </li>\n </ul>\n <p>{{t \"consent-template-5.video-privacy-withdraw\"}}</p>\n{{/if}}\n{{#if include_databrary}}\n <p>{{{t \"consent-template-5.databrary\"}}}</p>\n{{/if}}\n{{#if additional_video_privacy_statement}}\n <p>{{exp-format additional_video_privacy_statement}}</p>\n{{/if}}\n\n<h2>{{t \"consent-template-5.data-use-researchers-header\"}}</h2>\n<p>\n {{t\n \"consent-template-5.data-use-researchers-content-1\"\n name=PIName\n institution=institution\n }}\n</p>\n<ul>\n <li>{{t \"consent-template-5.data-use-researchers-item-1\"}}</li>\n <li>{{t \"consent-template-5.data-use-researchers-item-2\"}}</li>\n <li>\n {{t\n \"consent-template-5.data-use-researchers-item-3\"\n only_adult=prompt_only_adults\n }}\n </li>\n</ul>\n<p>\n {{t\n \"consent-template-5.data-use-researchers-content-2\"\n only_adult=prompt_only_adults\n }}\n</p>\n{{#if datause}}\n <p>{{exp-format datause}}</p>\n{{/if}}\n\n<h2>{{t \"consent-template-5.data-use-Lookit-header\"}}</h2>\n<p>{{t \"consent-template-5.data-use-Lookit-content\"}}</p>\n\n<h2>{{t \"consent-template-5.publication-header\"}}</h2>\n<p>\n {{t \"consent-template-5.publication-content\" only_adult=prompt_only_adults}}\n</p>\n\n{{#if additional_segments}}\n {{#each additional_segments as |segment|}}\n <h2>{{exp-format segment.title}}</h2>\n <p>{{exp-format segment.text}}</p>\n {{/each}}\n{{/if}}\n\n<h2>{{t \"consent-template-5.research-subject-rights-header\"}}</h2>\n<p>{{{exp-format research_rights_statement}}}</p>\n\n{{#if gdpr}}\n <h2>{{t \"consent-template-5.gdpr-header\"}}</h2>\n <p>\n {{t \"consent-template-5.gdpr-personal\"}}:\n {{exp-format gdpr_personal_data}}.\n {{t \"consent-template-5.gdpr-sensitive\"}}:\n {{exp-format gdpr_sensitive_data}}\n </p>\n <p>{{t \"consent-template-5.gdpr-2\"}}</p>\n{{/if}}\n\n<h2>{{t \"consent-template-5.contact-header\"}}</h2>\n<p>\n {{t\n \"consent-template-5.contact-statement-1\"\n name=PIName\n institution=institution\n contact=PIContact\n only_adult=prompt_only_adults\n omit_injury=omit_injury_phrase\n }}\n</p>\n<p>\n {{t \"consent-template-5.contact-statement-2\" only_adult=prompt_only_adults}}\n</p>";
|
|
9
9
|
|
|
10
|
-
var consentVideoTrialTemplate = "<div id=\"consent-video-trial\">\n <div class=\"left-column\">{{{consent}}}</div>\n <div class=\"right-column\">\n <div id=\"{{video_container_id}}\" class=\"jspsych-content\"></div>\n\n <ol>\n <li>{{t \"exp-lookit-video-consent.consent-step-1\"}}.</li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"record\">\n {{t \"exp-lookit-video-consent.start-consent-recording\"}}...\n </button>\n </li>\n <li>\n {{{t \"exp-lookit-video-consent.read-statement-below\"}}}\n {{t \"exp-lookit-video-consent.signed-alternative\"}}\n\n <div class=\"consent-statement\">\n {{#if consent_statement_text}}\n \"{{consent_statement_text}}\"\n {{else if prompt_only_adults}}\n \"{{t \"exp-lookit-video-consent.prompt-adult-only\"}}\"\n {{else}}\n \"{{t \"exp-lookit-video-consent.prompt\"}}\"\n {{/if}}\n </div>\n\n </li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"stop\" disabled>\n {{t \"exp-lookit-video-consent.stop-recording\"}}\n </button>\n </li>\n <li>\n <button class=\"jspsych-btn\" id=\"play\" disabled>\n {{t \"exp-lookit-video-consent.play-consent-video-button\"}}\n </button>\n {{t \"exp-lookit-video-consent.review-video\"}}\n </li>\n </ol>\n <button id=\"next\" class=\"jspsych-btn\" disabled>Next</button>\n </div>\n\n</div>";
|
|
10
|
+
var consentVideoTrialTemplate = "<div id=\"consent-video-trial\">\n <div class=\"left-column\">{{{consent}}}</div>\n <div class=\"right-column\">\n <div id=\"{{msg_container_id}}\">{{t\n \"exp-lookit-video-consent.Not-recording\"\n }}</div>\n <div id=\"{{video_container_id}}\" class=\"jspsych-content\"></div>\n\n <ol>\n <li>{{t \"exp-lookit-video-consent.consent-step-1\"}}.</li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"record\">\n {{t \"exp-lookit-video-consent.start-consent-recording\"}}...\n </button>\n </li>\n <li>\n {{{t \"exp-lookit-video-consent.read-statement-below\"}}}\n {{t \"exp-lookit-video-consent.signed-alternative\"}}\n\n <div class=\"consent-statement\">\n {{#if consent_statement_text}}\n \"{{consent_statement_text}}\"\n {{else if prompt_only_adults}}\n \"{{t \"exp-lookit-video-consent.prompt-adult-only\"}}\"\n {{else}}\n \"{{t \"exp-lookit-video-consent.prompt\"}}\"\n {{/if}}\n </div>\n\n </li>\n <li>{{t \"exp-lookit-video-consent.click-to\"}}\n <button class=\"jspsych-btn\" id=\"stop\" disabled>\n {{t \"exp-lookit-video-consent.stop-recording\"}}\n </button>\n </li>\n <li>\n <button class=\"jspsych-btn\" id=\"play\" disabled>\n {{t \"exp-lookit-video-consent.play-consent-video-button\"}}\n </button>\n {{t \"exp-lookit-video-consent.review-video\"}}\n </li>\n </ol>\n <button id=\"next\" class=\"jspsych-btn\" disabled>Next</button>\n </div>\n\n</div>";
|
|
11
11
|
|
|
12
12
|
class LocaleNotFoundError extends Error {
|
|
13
13
|
constructor(baseName) {
|
|
@@ -87,8 +87,12 @@ Handlebars.registerHelper("t", (context, { hash }) => {
|
|
|
87
87
|
const txt = String(i18next.t(context, hash));
|
|
88
88
|
return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;
|
|
89
89
|
});
|
|
90
|
+
const translateString = (messageIdStr) => {
|
|
91
|
+
return i18next.t(messageIdStr);
|
|
92
|
+
};
|
|
90
93
|
|
|
91
94
|
const video_container_id = "lookit-jspsych-video-container";
|
|
95
|
+
const msg_container_id = "lookit-jspsych-video-msg-container";
|
|
92
96
|
const consentVideo = (trial) => {
|
|
93
97
|
const experiment = window.chs.study.attributes;
|
|
94
98
|
const { PIName, PIContact } = trial;
|
|
@@ -103,7 +107,8 @@ const consentVideo = (trial) => {
|
|
|
103
107
|
return Handlebars.compile(consentVideoTrialTemplate)({
|
|
104
108
|
...trial,
|
|
105
109
|
consent,
|
|
106
|
-
video_container_id
|
|
110
|
+
video_container_id,
|
|
111
|
+
msg_container_id
|
|
107
112
|
});
|
|
108
113
|
};
|
|
109
114
|
const consentDocument = (trial) => {
|
|
@@ -274,7 +279,13 @@ const videoConfig = (trial, html_params) => {
|
|
|
274
279
|
});
|
|
275
280
|
};
|
|
276
281
|
|
|
277
|
-
var index = {
|
|
282
|
+
var index = {
|
|
283
|
+
consentVideo,
|
|
284
|
+
videoConfig,
|
|
285
|
+
uploadingVideo,
|
|
286
|
+
exitSurvey,
|
|
287
|
+
translateString
|
|
288
|
+
};
|
|
278
289
|
|
|
279
290
|
export { index as default };
|
|
280
291
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/errors.ts","../src/utils.ts","../src/consentVideoTemplate.ts","../src/exitSurveyTemplate.ts","../src/uploadingVideoTemplate.ts","../src/videoConfigTemplate.ts","../src/index.ts"],"sourcesContent":["/** Error thrown when specified language isn't found */\nexport class LocaleNotFoundError extends Error {\n /**\n * This will be thrown when attempting to init i18n\n *\n * @param baseName - Language a2code with region\n */\n public constructor(baseName: string) {\n super(`\"${baseName}\" locale not found.`);\n }\n}\n/** Error thrown when researcher selects template that isn't available. */\nexport class ConsentTemplateNotFound extends Error {\n /**\n * This will let the researcher know that their template isn't found.\n *\n * @param template - Supplied name of consent template.\n */\n public constructor(template: string) {\n super(`Consent template \"${template}\" not found.`);\n }\n}\n","import Handlebars from \"handlebars\";\nimport i18next from \"i18next\";\nimport ICU from \"i18next-icu\";\nimport Yaml from \"js-yaml\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport en_us from \"../i18n/en-us.yaml\";\nimport eu from \"../i18n/eu.yaml\";\nimport fr from \"../i18n/fr.yaml\";\nimport hu from \"../i18n/hu.yaml\";\nimport it from \"../i18n/it.yaml\";\nimport ja from \"../i18n/ja.yaml\";\nimport nl from \"../i18n/nl.yaml\";\nimport pt_br from \"../i18n/pt-br.yaml\";\nimport pt from \"../i18n/pt.yaml\";\nimport { LocaleNotFoundError } from \"./errors\";\n\n/**\n * Pulled from EFP. Function to convert researcher's text to HTML.\n *\n * @param text - Text\n * @returns Formatted string\n */\nexport const expFormat = (text?: string | string[]) => {\n if (!text) {\n return \"\";\n }\n\n if (Array.isArray(text)) {\n text = text.join(\"\\n\\n\");\n }\n\n return text\n .replace(/(\\r\\n|\\n|\\r)/gm, \"<br>\")\n .replace(/\\t/gm, \" \");\n};\n\n/**\n * Get a translation resources from yaml files.\n *\n * @returns Resources for i18next\n */\nconst resources = () => {\n const translations = {\n \"en-us\": en_us,\n eu,\n fr,\n hu,\n it,\n ja,\n nl,\n \"pt-br\": pt_br,\n pt,\n };\n\n return Object.entries(translations).reduce((prev, [locale, translation]) => {\n const lcl = new Intl.Locale(locale);\n return {\n ...prev,\n [lcl.baseName]: {\n translation: Yaml.load(translation) as Record<string, string>,\n },\n };\n }, {});\n};\n\n/**\n * Initialize i18next with parameters from trial.\n *\n * @param trial - Trial data including user supplied parameters.\n */\nexport const setLocale = (trial: TrialType<PluginInfo>) => {\n const lcl = new Intl.Locale(trial.locale);\n\n if (!i18next.hasResourceBundle(lcl.baseName, \"translation\")) {\n throw new LocaleNotFoundError(trial.locale);\n }\n\n if (i18next.language !== lcl.baseName) {\n i18next.changeLanguage(lcl.baseName);\n }\n};\n\n// Initialize translations\ni18next.use(ICU).init({\n debug: process.env.DEBUG === \"true\",\n resources: resources(),\n});\n\n// Setup Handlebars' helpers\nHandlebars.registerHelper(\"exp-format\", (context) => expFormat(context));\nHandlebars.registerHelper(\"t\", (context, { hash }) => {\n const txt = String(i18next.t(context, hash));\n return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;\n});\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport consent_garden from \"../hbs/consent-garden.hbs\";\nimport consent_template_5 from \"../hbs/consent-template-5.hbs\";\nimport consentVideoTrialTemplate from \"../hbs/consent-video-trial.hbs\";\nimport { ConsentTemplateNotFound } from \"./errors\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\nconst video_container_id = \"lookit-jspsych-video-container\";\n\n/**\n * Translate, render, and get consent document HTML.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Consent document HTML\n */\nexport const consentVideo = (trial: TrialType<PluginInfo>) => {\n const experiment = window.chs.study.attributes;\n const { PIName, PIContact } = trial;\n\n setLocale(trial);\n\n const consentDocumentTemplate = consentDocument(trial);\n\n const consent = Handlebars.compile(consentDocumentTemplate)({\n ...trial,\n name: PIName,\n contact: PIContact,\n experiment,\n });\n\n return Handlebars.compile(consentVideoTrialTemplate)({\n ...trial,\n consent,\n video_container_id,\n });\n};\n\n/**\n * Get consent template by name.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Consent template\n */\nconst consentDocument = (trial: TrialType<PluginInfo>) => {\n switch (trial.template) {\n case \"consent-template-5\":\n return consent_template_5;\n case \"consent-garden\":\n return consent_garden;\n default:\n throw new ConsentTemplateNotFound(trial.template);\n }\n};\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport i18next from \"i18next\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\n/**\n * Class to augment and translate the exit survey JSON based on user set\n * parameters.\n */\nclass ExitSurveyJson {\n private names = <const>{\n birthDate: \"birthDate\",\n databraryShare: \"databraryShare\",\n useOfMedia: \"useOfMedia\",\n withdrawal: \"withdrawal\",\n feedback: \"feedback\",\n };\n public survey = {\n pages: [\n {\n elements: [\n {\n description: \"exp-lookit-exit-survey.why-birthdate\",\n inputType: \"date\",\n isRequired: true,\n maxValueExpression: \"today()\",\n name: this.names.birthDate,\n title: \"exp-lookit-exit-survey.confirm-birthdate\",\n type: \"text\",\n },\n {\n description: \"exp-lookit-exit-survey.databrary-info\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.databraryShare,\n title: \"exp-lookit-exit-survey.q-databrary\",\n type: \"boolean\",\n valueFalse: \"no\",\n valueTrue: \"yes\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.private-option-part-1\",\n value: \"private\",\n },\n {\n text: \"exp-lookit-exit-survey.scientific-option\",\n value: \"scientific\",\n },\n {\n text: \"exp-lookit-exit-survey.publicity-option\",\n value: \"public\",\n },\n ],\n description: \"\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.useOfMedia,\n title: \"exp-lookit-exit-survey.acceptable-use-header\",\n type: \"radiogroup\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.withdrawal-details\",\n value: true,\n },\n ],\n defaultValue: [],\n isRequired: false,\n name: this.names.withdrawal,\n title: \"exp-lookit-exit-survey.withdrawal-header\",\n type: \"checkbox\",\n },\n {\n autoGrow: true,\n name: this.names.feedback,\n rows: 3,\n title: \"exp-lookit-exit-survey.feedback-label\",\n type: \"comment\",\n },\n ],\n name: \"page1\",\n },\n ],\n showQuestionNumbers: \"off\",\n };\n\n /**\n * Adjust survey json to meet user's parameters.\n *\n * @param trial - Trial data including user supplied parameters.\n */\n public constructor(private trial: TrialType<PluginInfo>) {\n this.showDatabraryOptions();\n this.additionalVideoPrivacyText();\n this.privateLevelOnly();\n this.translation();\n }\n\n /** Alter survey to show Databrary options. */\n private showDatabraryOptions() {\n if (!this.trial.show_databrary_options) {\n const survey_elements = this.survey.pages[0].elements;\n const databrary_share_element_idx = survey_elements.findIndex(\n (element) => element.name === this.names.databraryShare,\n );\n survey_elements.splice(databrary_share_element_idx, 1);\n }\n }\n\n /** Alter survey to contain additional video privacy text. */\n private additionalVideoPrivacyText() {\n const element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n element &&\n Object.assign(element, {\n description: this.trial.additional_video_privacy_text,\n });\n }\n\n /** Alter survey to only show \"private\" on use of media question. */\n private privateLevelOnly() {\n if (this.trial.private_level_only) {\n const media_use_element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n media_use_element &&\n Object.assign(media_use_element, {\n defaultValue: \"private\",\n description: \"exp-lookit-exit-survey.private-option-part-1\",\n choicesVisibleIf: \"false\", // this must be a string expression\n isRequired: false,\n });\n }\n }\n\n /** Translate the survey text. */\n private translation() {\n const { contact_info, name } = window.chs.study.attributes;\n const view = {\n ...this.trial,\n include_example: this.trial.include_withdrawal_example,\n contact: contact_info,\n name,\n };\n\n this.survey.pages[0].elements.forEach((element) => {\n // Descriptions\n element.description &&\n Object.assign(element, {\n description: i18next.t(element.description, view),\n });\n\n // Titles\n Object.assign(element, { title: i18next.t(element.title, view) });\n\n // Choices\n element.choices &&\n element.choices.forEach((choice) => {\n Object.assign(choice, { text: i18next.t(choice.text, view) });\n });\n });\n }\n}\n\n/**\n * Translate survey text to desired locale.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Survey json\n */\nexport const exitSurvey = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n return new ExitSurveyJson(trial).survey;\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport uploadingVideoTemplate from \"../hbs/uploading-video.hbs\";\nimport { setLocale } from \"./utils\";\n\n/**\n * Get translated template for uploading video message.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Uploading video message HTML\n */\nexport const uploadingVideo = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n\n return Handlebars.compile(uploadingVideoTemplate)({});\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport videoConfigTemplate from \"../hbs/video-config.hbs\";\nimport { setLocale } from \"./utils\";\n\ntype VideoConfigTemplateParams = {\n webcam_container_id: string;\n reload_button_id_cam: string;\n camera_selection_id: string;\n mic_selection_id: string;\n step1_id: string;\n step2_id: string;\n step3_id: string;\n step_complete_class: string;\n reload_button_id_text: string;\n next_button_id: string;\n waiting_for_access_msg_id: string;\n checking_mic_msg_id: string;\n access_problem_msg_id: string;\n setup_problem_msg_id: string;\n chromeInitialPrompt: string;\n chromeAlwaysAllow: string;\n chromePermissions: string;\n firefoxInitialPrompt: string;\n firefoxChooseDevice: string;\n firefoxDevicesBlocked: string;\n checkmarkIcon: string;\n};\n\n/**\n * Get translated template for video config.\n *\n * @param trial - JsPsych trial object containing trial params\n * @param html_params - Additional context variables for the template.\n * @returns Video config HTML\n */\nexport const videoConfig = (\n trial: TrialType<PluginInfo>,\n html_params: VideoConfigTemplateParams,\n) => {\n setLocale(trial);\n\n return Handlebars.compile(videoConfigTemplate)({\n ...trial,\n ...html_params,\n });\n};\n","import { consentVideo } from \"./consentVideoTemplate\";\nimport { exitSurvey } from \"./exitSurveyTemplate\";\nimport { uploadingVideo } from \"./uploadingVideoTemplate\";\nimport { videoConfig } from \"./videoConfigTemplate\";\n\nexport default { consentVideo, videoConfig, uploadingVideo, exitSurvey };\n"],"names":["element"],"mappings":";;;;;;;;;;;AACO,MAAM,4BAA4B,KAAM,CAAA;AAAA,EAMtC,YAAY,QAAkB,EAAA;AACnC,IAAA,KAAA,CAAM,IAAI,QAA6B,CAAA,mBAAA,CAAA,CAAA,CAAA;AAAA,GACzC;AACF,CAAA;AAEO,MAAM,gCAAgC,KAAM,CAAA;AAAA,EAM1C,YAAY,QAAkB,EAAA;AACnC,IAAA,KAAA,CAAM,qBAAqB,QAAsB,CAAA,YAAA,CAAA,CAAA,CAAA;AAAA,GACnD;AACF;;;;;;;;;;;;;;;;;;;;ACCa,MAAA,SAAA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AAM,EAAA,OAAA,CAAQ,EAAE,MAAO,CAAA,IAAA,EAAM,IAAI,CAAA,EAAG,CAAA,CAAA;AAAA,OAC7D,CAAA,CAAA;AAAA,KACJ,CAAA,CAAA;AAAA,GACH;AACF,CAAA;AAQa,MAAA,UAAA,GAAa,CAAC,KAAiC,KAAA;AAC1D,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AACf,EAAO,OAAA,IAAI,cAAe,CAAA,KAAK,CAAE,CAAA,MAAA,CAAA;AACnC,CAAA;;;;ACxKa,MAAA,cAAA,GAAiB,CAAC,KAAiC,KAAA;AAC9D,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AAEf,EAAA,OAAO,UAAW,CAAA,OAAA,CAAQ,sBAAsB,CAAA,CAAE,EAAE,CAAA,CAAA;AACtD,CAAA;;;;ACqBa,MAAA,WAAA,GAAc,CACzB,KAAA,EACA,WACG,KAAA;AACH,EAAA,SAAA,CAAU,KAAK,CAAA,CAAA;AAEf,EAAO,OAAA,UAAA,CAAW,OAAQ,CAAA,mBAAmB,CAAE,CAAA;AAAA,IAC7C,GAAG,KAAA;AAAA,IACH,GAAG,WAAA;AAAA,GACJ,CAAA,CAAA;AACH,CAAA;;ACzCA,YAAe,EAAE,YAAA,EAAc,WAAa,EAAA,cAAA,EAAgB,UAAW,EAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/errors.ts","../src/utils.ts","../src/consentVideoTemplate.ts","../src/exitSurveyTemplate.ts","../src/uploadingVideoTemplate.ts","../src/videoConfigTemplate.ts","../src/index.ts"],"sourcesContent":["/** Error thrown when specified language isn't found */\nexport class LocaleNotFoundError extends Error {\n /**\n * This will be thrown when attempting to init i18n\n *\n * @param baseName - Language a2code with region\n */\n public constructor(baseName: string) {\n super(`\"${baseName}\" locale not found.`);\n }\n}\n/** Error thrown when researcher selects template that isn't available. */\nexport class ConsentTemplateNotFound extends Error {\n /**\n * This will let the researcher know that their template isn't found.\n *\n * @param template - Supplied name of consent template.\n */\n public constructor(template: string) {\n super(`Consent template \"${template}\" not found.`);\n }\n}\n","import Handlebars from \"handlebars\";\nimport i18next from \"i18next\";\nimport ICU from \"i18next-icu\";\nimport Yaml from \"js-yaml\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport en_us from \"../i18n/en-us.yaml\";\nimport eu from \"../i18n/eu.yaml\";\nimport fr from \"../i18n/fr.yaml\";\nimport hu from \"../i18n/hu.yaml\";\nimport it from \"../i18n/it.yaml\";\nimport ja from \"../i18n/ja.yaml\";\nimport nl from \"../i18n/nl.yaml\";\nimport pt_br from \"../i18n/pt-br.yaml\";\nimport pt from \"../i18n/pt.yaml\";\nimport { LocaleNotFoundError } from \"./errors\";\n\n/**\n * Pulled from EFP. Function to convert researcher's text to HTML.\n *\n * @param text - Text\n * @returns Formatted string\n */\nexport const expFormat = (text?: string | string[]) => {\n if (!text) {\n return \"\";\n }\n\n if (Array.isArray(text)) {\n text = text.join(\"\\n\\n\");\n }\n\n return text\n .replace(/(\\r\\n|\\n|\\r)/gm, \"<br>\")\n .replace(/\\t/gm, \" \");\n};\n\n/**\n * Get a translation resources from yaml files.\n *\n * @returns Resources for i18next\n */\nconst resources = () => {\n const translations = {\n \"en-us\": en_us,\n eu,\n fr,\n hu,\n it,\n ja,\n nl,\n \"pt-br\": pt_br,\n pt,\n };\n\n return Object.entries(translations).reduce((prev, [locale, translation]) => {\n const lcl = new Intl.Locale(locale);\n return {\n ...prev,\n [lcl.baseName]: {\n translation: Yaml.load(translation) as Record<string, string>,\n },\n };\n }, {});\n};\n\n/**\n * Initialize i18next with parameters from trial.\n *\n * @param trial - Trial data including user supplied parameters.\n */\nexport const setLocale = (trial: TrialType<PluginInfo>) => {\n const lcl = new Intl.Locale(trial.locale);\n\n if (!i18next.hasResourceBundle(lcl.baseName, \"translation\")) {\n throw new LocaleNotFoundError(trial.locale);\n }\n\n if (i18next.language !== lcl.baseName) {\n i18next.changeLanguage(lcl.baseName);\n }\n};\n\n// Initialize translations\ni18next.use(ICU).init({\n debug: process.env.DEBUG === \"true\",\n resources: resources(),\n});\n\n// Setup Handlebars' helpers\nHandlebars.registerHelper(\"exp-format\", (context) => expFormat(context));\nHandlebars.registerHelper(\"t\", (context, { hash }) => {\n const txt = String(i18next.t(context, hash));\n return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;\n});\n\n/**\n * Public method for directly translating a string, without a corresponding\n * template.\n *\n * @param messageIdStr - Message ID string to be looked up in the translation\n * files.\n * @returns Translated string\n */\nexport const translateString = (messageIdStr: string) => {\n return i18next.t(messageIdStr);\n};\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport consent_garden from \"../hbs/consent-garden.hbs\";\nimport consent_template_5 from \"../hbs/consent-template-5.hbs\";\nimport consentVideoTrialTemplate from \"../hbs/consent-video-trial.hbs\";\nimport { ConsentTemplateNotFound } from \"./errors\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\nconst video_container_id = \"lookit-jspsych-video-container\";\nconst msg_container_id = \"lookit-jspsych-video-msg-container\";\n\n/**\n * Translate, render, and get consent document HTML.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Consent document HTML\n */\nexport const consentVideo = (trial: TrialType<PluginInfo>) => {\n const experiment = window.chs.study.attributes;\n const { PIName, PIContact } = trial;\n\n setLocale(trial);\n\n const consentDocumentTemplate = consentDocument(trial);\n\n const consent = Handlebars.compile(consentDocumentTemplate)({\n ...trial,\n name: PIName,\n contact: PIContact,\n experiment,\n });\n\n return Handlebars.compile(consentVideoTrialTemplate)({\n ...trial,\n consent,\n video_container_id,\n msg_container_id,\n });\n};\n\n/**\n * Get consent template by name.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Consent template\n */\nconst consentDocument = (trial: TrialType<PluginInfo>) => {\n switch (trial.template) {\n case \"consent-template-5\":\n return consent_template_5;\n case \"consent-garden\":\n return consent_garden;\n default:\n throw new ConsentTemplateNotFound(trial.template);\n }\n};\n","import { LookitWindow } from \"@lookit/data/dist/types\";\nimport i18next from \"i18next\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport { setLocale } from \"./utils\";\n\ndeclare const window: LookitWindow;\n\n/**\n * Class to augment and translate the exit survey JSON based on user set\n * parameters.\n */\nclass ExitSurveyJson {\n private names = <const>{\n birthDate: \"birthDate\",\n databraryShare: \"databraryShare\",\n useOfMedia: \"useOfMedia\",\n withdrawal: \"withdrawal\",\n feedback: \"feedback\",\n };\n public survey = {\n pages: [\n {\n elements: [\n {\n description: \"exp-lookit-exit-survey.why-birthdate\",\n inputType: \"date\",\n isRequired: true,\n maxValueExpression: \"today()\",\n name: this.names.birthDate,\n title: \"exp-lookit-exit-survey.confirm-birthdate\",\n type: \"text\",\n },\n {\n description: \"exp-lookit-exit-survey.databrary-info\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.databraryShare,\n title: \"exp-lookit-exit-survey.q-databrary\",\n type: \"boolean\",\n valueFalse: \"no\",\n valueTrue: \"yes\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.private-option-part-1\",\n value: \"private\",\n },\n {\n text: \"exp-lookit-exit-survey.scientific-option\",\n value: \"scientific\",\n },\n {\n text: \"exp-lookit-exit-survey.publicity-option\",\n value: \"public\",\n },\n ],\n description: \"\",\n enableIf: \"({withdrawal} empty) or ({withdrawal.length} = 0)\",\n isRequired: true,\n name: this.names.useOfMedia,\n title: \"exp-lookit-exit-survey.acceptable-use-header\",\n type: \"radiogroup\",\n },\n {\n choices: [\n {\n text: \"exp-lookit-exit-survey.withdrawal-details\",\n value: true,\n },\n ],\n defaultValue: [],\n isRequired: false,\n name: this.names.withdrawal,\n title: \"exp-lookit-exit-survey.withdrawal-header\",\n type: \"checkbox\",\n },\n {\n autoGrow: true,\n name: this.names.feedback,\n rows: 3,\n title: \"exp-lookit-exit-survey.feedback-label\",\n type: \"comment\",\n },\n ],\n name: \"page1\",\n },\n ],\n showQuestionNumbers: \"off\",\n };\n\n /**\n * Adjust survey json to meet user's parameters.\n *\n * @param trial - Trial data including user supplied parameters.\n */\n public constructor(private trial: TrialType<PluginInfo>) {\n this.showDatabraryOptions();\n this.additionalVideoPrivacyText();\n this.privateLevelOnly();\n this.translation();\n }\n\n /** Alter survey to show Databrary options. */\n private showDatabraryOptions() {\n if (!this.trial.show_databrary_options) {\n const survey_elements = this.survey.pages[0].elements;\n const databrary_share_element_idx = survey_elements.findIndex(\n (element) => element.name === this.names.databraryShare,\n );\n survey_elements.splice(databrary_share_element_idx, 1);\n }\n }\n\n /** Alter survey to contain additional video privacy text. */\n private additionalVideoPrivacyText() {\n const element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n element &&\n Object.assign(element, {\n description: this.trial.additional_video_privacy_text,\n });\n }\n\n /** Alter survey to only show \"private\" on use of media question. */\n private privateLevelOnly() {\n if (this.trial.private_level_only) {\n const media_use_element = this.survey.pages[0].elements.find(\n (element) => element.name === this.names.useOfMedia,\n );\n media_use_element &&\n Object.assign(media_use_element, {\n defaultValue: \"private\",\n description: \"exp-lookit-exit-survey.private-option-part-1\",\n choicesVisibleIf: \"false\", // this must be a string expression\n isRequired: false,\n });\n }\n }\n\n /** Translate the survey text. */\n private translation() {\n const { contact_info, name } = window.chs.study.attributes;\n const view = {\n ...this.trial,\n include_example: this.trial.include_withdrawal_example,\n contact: contact_info,\n name,\n };\n\n this.survey.pages[0].elements.forEach((element) => {\n // Descriptions\n element.description &&\n Object.assign(element, {\n description: i18next.t(element.description, view),\n });\n\n // Titles\n Object.assign(element, { title: i18next.t(element.title, view) });\n\n // Choices\n element.choices &&\n element.choices.forEach((choice) => {\n Object.assign(choice, { text: i18next.t(choice.text, view) });\n });\n });\n }\n}\n\n/**\n * Translate survey text to desired locale.\n *\n * @param trial - Trial data including user supplied parameters.\n * @returns Survey json\n */\nexport const exitSurvey = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n return new ExitSurveyJson(trial).survey;\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport uploadingVideoTemplate from \"../hbs/uploading-video.hbs\";\nimport { setLocale } from \"./utils\";\n\n/**\n * Get translated template for uploading video message.\n *\n * @param trial - JsPsych trial object containing trial params\n * @returns Uploading video message HTML\n */\nexport const uploadingVideo = (trial: TrialType<PluginInfo>) => {\n setLocale(trial);\n\n return Handlebars.compile(uploadingVideoTemplate)({});\n};\n","import Handlebars from \"handlebars\";\nimport { PluginInfo, TrialType } from \"jspsych\";\nimport videoConfigTemplate from \"../hbs/video-config.hbs\";\nimport { setLocale } from \"./utils\";\n\ntype VideoConfigTemplateParams = {\n webcam_container_id: string;\n reload_button_id_cam: string;\n camera_selection_id: string;\n mic_selection_id: string;\n step1_id: string;\n step2_id: string;\n step3_id: string;\n step_complete_class: string;\n reload_button_id_text: string;\n next_button_id: string;\n waiting_for_access_msg_id: string;\n checking_mic_msg_id: string;\n access_problem_msg_id: string;\n setup_problem_msg_id: string;\n chromeInitialPrompt: string;\n chromeAlwaysAllow: string;\n chromePermissions: string;\n firefoxInitialPrompt: string;\n firefoxChooseDevice: string;\n firefoxDevicesBlocked: string;\n checkmarkIcon: string;\n};\n\n/**\n * Get translated template for video config.\n *\n * @param trial - JsPsych trial object containing trial params\n * @param html_params - Additional context variables for the template.\n * @returns Video config HTML\n */\nexport const videoConfig = (\n trial: TrialType<PluginInfo>,\n html_params: VideoConfigTemplateParams,\n) => {\n setLocale(trial);\n\n return Handlebars.compile(videoConfigTemplate)({\n ...trial,\n ...html_params,\n });\n};\n","import { consentVideo } from \"./consentVideoTemplate\";\nimport { exitSurvey } from \"./exitSurveyTemplate\";\nimport { uploadingVideo } from \"./uploadingVideoTemplate\";\nimport { translateString } from \"./utils\";\nimport { videoConfig } from \"./videoConfigTemplate\";\n\nexport default {\n consentVideo,\n videoConfig,\n uploadingVideo,\n exitSurvey,\n translateString,\n};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IAC7C,GAAG,KAAA;AAAA,IACH,GAAG,WAAA;AAAA,GACJ,CAAA,CAAA;AACH,CAAA;;ACxCA,YAAe;AAAA,EACb,YAAA;AAAA,EACA,WAAA;AAAA,EACA,cAAA;AAAA,EACA,UAAA;AAAA,EACA,eAAA;AACF,CAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ import { setLocale } from "./utils";
|
|
|
10
10
|
declare const window: LookitWindow;
|
|
11
11
|
|
|
12
12
|
const video_container_id = "lookit-jspsych-video-container";
|
|
13
|
+
const msg_container_id = "lookit-jspsych-video-msg-container";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Translate, render, and get consent document HTML.
|
|
@@ -36,6 +37,7 @@ export const consentVideo = (trial: TrialType<PluginInfo>) => {
|
|
|
36
37
|
...trial,
|
|
37
38
|
consent,
|
|
38
39
|
video_container_id,
|
|
40
|
+
msg_container_id,
|
|
39
41
|
});
|
|
40
42
|
};
|
|
41
43
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { consentVideo } from "./consentVideoTemplate";
|
|
2
2
|
import { exitSurvey } from "./exitSurveyTemplate";
|
|
3
3
|
import { uploadingVideo } from "./uploadingVideoTemplate";
|
|
4
|
+
import { translateString } from "./utils";
|
|
4
5
|
import { videoConfig } from "./videoConfigTemplate";
|
|
5
6
|
|
|
6
|
-
export default {
|
|
7
|
+
export default {
|
|
8
|
+
consentVideo,
|
|
9
|
+
videoConfig,
|
|
10
|
+
uploadingVideo,
|
|
11
|
+
exitSurvey,
|
|
12
|
+
translateString,
|
|
13
|
+
};
|
package/src/utils.spec.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import i18next from "i18next";
|
|
1
2
|
import { PluginInfo, TrialType } from "jspsych";
|
|
2
3
|
import { LocaleNotFoundError } from "./errors";
|
|
3
|
-
import { expFormat, setLocale } from "./utils";
|
|
4
|
+
import { expFormat, setLocale, translateString } from "./utils";
|
|
4
5
|
|
|
5
6
|
test("expFormat convert written text to format well in HTML", () => {
|
|
6
7
|
expect(expFormat("abcdefg")).toStrictEqual("abcdefg");
|
|
@@ -25,3 +26,12 @@ test("setLocale throw error with non-existing locale", () => {
|
|
|
25
26
|
const trial = { locale: "non-existing" } as unknown as TrialType<PluginInfo>;
|
|
26
27
|
expect(() => setLocale(trial)).toThrow(LocaleNotFoundError);
|
|
27
28
|
});
|
|
29
|
+
|
|
30
|
+
test("translateString translates the string with the appropriate locale", () => {
|
|
31
|
+
const en = new Intl.Locale("en-us");
|
|
32
|
+
i18next.changeLanguage(en.baseName);
|
|
33
|
+
expect(translateString("Continue")).toBe("Continue");
|
|
34
|
+
const fr = new Intl.Locale("fr");
|
|
35
|
+
i18next.changeLanguage(fr.baseName);
|
|
36
|
+
expect(translateString("Continue")).toBe("Continuer");
|
|
37
|
+
});
|
package/src/utils.ts
CHANGED
|
@@ -92,3 +92,15 @@ Handlebars.registerHelper("t", (context, { hash }) => {
|
|
|
92
92
|
const txt = String(i18next.t(context, hash));
|
|
93
93
|
return hash.htmlSafe ? new Handlebars.SafeString(txt) : txt;
|
|
94
94
|
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Public method for directly translating a string, without a corresponding
|
|
98
|
+
* template.
|
|
99
|
+
*
|
|
100
|
+
* @param messageIdStr - Message ID string to be looked up in the translation
|
|
101
|
+
* files.
|
|
102
|
+
* @returns Translated string
|
|
103
|
+
*/
|
|
104
|
+
export const translateString = (messageIdStr: string) => {
|
|
105
|
+
return i18next.t(messageIdStr);
|
|
106
|
+
};
|