@lookit/templates 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.browser.js +1346 -7555
- package/dist/index.browser.js.map +1 -1
- package/dist/index.browser.min.js +6361 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +239 -24861
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +118 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +239 -24861
- package/dist/index.js.map +1 -1
- package/package.json +13 -6
- package/src/exitSurveyTemplate.ts +180 -0
- package/src/index.spec.ts +56 -1
- package/src/index.ts +4 -1
- package/src/uploadingVideoTemplate.ts +16 -0
- package/src/videoConfigTemplate.ts +47 -0
- package/dist/consentVideoTemplate.d.ts +0 -8
- package/dist/errors.d.ts +0 -18
- package/dist/utils.d.ts +0 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lookit/templates",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "CHS jsPsych trial templates and their translations",
|
|
5
5
|
"homepage": "https://github.com/lookit/lookit-jspsych#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -24,14 +24,21 @@
|
|
|
24
24
|
"dev": "rollup --config rollup.config.dev.mjs --watch",
|
|
25
25
|
"test": "jest --coverage"
|
|
26
26
|
},
|
|
27
|
-
"
|
|
28
|
-
"@jspsych/config": "^2.0.0",
|
|
27
|
+
"dependencies": {
|
|
29
28
|
"handlebars": "^4.7.8",
|
|
29
|
+
"i18next": "^23.16.4",
|
|
30
|
+
"i18next-icu": "^2.3.0",
|
|
31
|
+
"js-yaml": "^4.1.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@jspsych/config": "^3.0.1",
|
|
35
|
+
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
36
|
+
"@types/js-yaml": "^4.0.9",
|
|
30
37
|
"rollup-plugin-dotenv": "^0.5.1",
|
|
31
|
-
"rollup-plugin-
|
|
38
|
+
"rollup-plugin-string": "^3.0.0"
|
|
32
39
|
},
|
|
33
40
|
"peerDependencies": {
|
|
34
|
-
"@lookit/data": "^0.
|
|
35
|
-
"jspsych": "^8.0.
|
|
41
|
+
"@lookit/data": "^0.2.0",
|
|
42
|
+
"jspsych": "^8.0.3"
|
|
36
43
|
}
|
|
37
44
|
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { LookitWindow } from "@lookit/data/dist/types";
|
|
2
|
+
import i18next from "i18next";
|
|
3
|
+
import { PluginInfo, TrialType } from "jspsych";
|
|
4
|
+
import { setLocale } from "./utils";
|
|
5
|
+
|
|
6
|
+
declare const window: LookitWindow;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Class to augment and translate the exit survey JSON based on user set
|
|
10
|
+
* parameters.
|
|
11
|
+
*/
|
|
12
|
+
class ExitSurveyJson {
|
|
13
|
+
private names = <const>{
|
|
14
|
+
birthDate: "birthDate",
|
|
15
|
+
databraryShare: "databraryShare",
|
|
16
|
+
useOfMedia: "useOfMedia",
|
|
17
|
+
withdrawal: "withdrawal",
|
|
18
|
+
feedback: "feedback",
|
|
19
|
+
};
|
|
20
|
+
public survey = {
|
|
21
|
+
pages: [
|
|
22
|
+
{
|
|
23
|
+
elements: [
|
|
24
|
+
{
|
|
25
|
+
description: "exp-lookit-exit-survey.why-birthdate",
|
|
26
|
+
inputType: "date",
|
|
27
|
+
isRequired: true,
|
|
28
|
+
maxValueExpression: "today()",
|
|
29
|
+
name: this.names.birthDate,
|
|
30
|
+
title: "exp-lookit-exit-survey.confirm-birthdate",
|
|
31
|
+
type: "text",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
description: "exp-lookit-exit-survey.databrary-info",
|
|
35
|
+
enableIf: "({withdrawal} empty) or ({withdrawal.length} = 0)",
|
|
36
|
+
isRequired: true,
|
|
37
|
+
name: this.names.databraryShare,
|
|
38
|
+
title: "exp-lookit-exit-survey.q-databrary",
|
|
39
|
+
type: "boolean",
|
|
40
|
+
valueFalse: "no",
|
|
41
|
+
valueTrue: "yes",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
choices: [
|
|
45
|
+
{
|
|
46
|
+
text: "exp-lookit-exit-survey.private-option-part-1",
|
|
47
|
+
value: "private",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
text: "exp-lookit-exit-survey.scientific-option",
|
|
51
|
+
value: "scientific",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
text: "exp-lookit-exit-survey.publicity-option",
|
|
55
|
+
value: "public",
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
description: "",
|
|
59
|
+
enableIf: "({withdrawal} empty) or ({withdrawal.length} = 0)",
|
|
60
|
+
isRequired: true,
|
|
61
|
+
name: this.names.useOfMedia,
|
|
62
|
+
title: "exp-lookit-exit-survey.acceptable-use-header",
|
|
63
|
+
type: "radiogroup",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
choices: [
|
|
67
|
+
{
|
|
68
|
+
text: "exp-lookit-exit-survey.withdrawal-details",
|
|
69
|
+
value: true,
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
defaultValue: [],
|
|
73
|
+
isRequired: false,
|
|
74
|
+
name: this.names.withdrawal,
|
|
75
|
+
title: "exp-lookit-exit-survey.withdrawal-header",
|
|
76
|
+
type: "checkbox",
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
autoGrow: true,
|
|
80
|
+
name: this.names.feedback,
|
|
81
|
+
rows: 3,
|
|
82
|
+
title: "exp-lookit-exit-survey.feedback-label",
|
|
83
|
+
type: "comment",
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
name: "page1",
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
showQuestionNumbers: "off",
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Adjust survey json to meet user's parameters.
|
|
94
|
+
*
|
|
95
|
+
* @param trial - Trial data including user supplied parameters.
|
|
96
|
+
*/
|
|
97
|
+
public constructor(private trial: TrialType<PluginInfo>) {
|
|
98
|
+
this.showDatabraryOptions();
|
|
99
|
+
this.additionalVideoPrivacyText();
|
|
100
|
+
this.privateLevelOnly();
|
|
101
|
+
this.translation();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Alter survey to show Databrary options. */
|
|
105
|
+
private showDatabraryOptions() {
|
|
106
|
+
if (!this.trial.show_databrary_options) {
|
|
107
|
+
const survey_elements = this.survey.pages[0].elements;
|
|
108
|
+
const databrary_share_element_idx = survey_elements.findIndex(
|
|
109
|
+
(element) => element.name === this.names.databraryShare,
|
|
110
|
+
);
|
|
111
|
+
survey_elements.splice(databrary_share_element_idx, 1);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Alter survey to contain additional video privacy text. */
|
|
116
|
+
private additionalVideoPrivacyText() {
|
|
117
|
+
const element = this.survey.pages[0].elements.find(
|
|
118
|
+
(element) => element.name === this.names.useOfMedia,
|
|
119
|
+
);
|
|
120
|
+
element &&
|
|
121
|
+
Object.assign(element, {
|
|
122
|
+
description: this.trial.additional_video_privacy_text,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Alter survey to only show "private" on use of media question. */
|
|
127
|
+
private privateLevelOnly() {
|
|
128
|
+
if (this.trial.private_level_only) {
|
|
129
|
+
const media_use_element = this.survey.pages[0].elements.find(
|
|
130
|
+
(element) => element.name === this.names.useOfMedia,
|
|
131
|
+
);
|
|
132
|
+
media_use_element &&
|
|
133
|
+
Object.assign(media_use_element, {
|
|
134
|
+
defaultValue: "private",
|
|
135
|
+
description: "exp-lookit-exit-survey.private-option-part-1",
|
|
136
|
+
choicesVisibleIf: "false", // this must be a string expression
|
|
137
|
+
isRequired: false,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Translate the survey text. */
|
|
143
|
+
private translation() {
|
|
144
|
+
const { contact_info, name } = window.chs.study.attributes;
|
|
145
|
+
const view = {
|
|
146
|
+
...this.trial,
|
|
147
|
+
include_example: this.trial.include_withdrawal_example,
|
|
148
|
+
contact: contact_info,
|
|
149
|
+
name,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
this.survey.pages[0].elements.forEach((element) => {
|
|
153
|
+
// Descriptions
|
|
154
|
+
element.description &&
|
|
155
|
+
Object.assign(element, {
|
|
156
|
+
description: i18next.t(element.description, view),
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Titles
|
|
160
|
+
Object.assign(element, { title: i18next.t(element.title, view) });
|
|
161
|
+
|
|
162
|
+
// Choices
|
|
163
|
+
element.choices &&
|
|
164
|
+
element.choices.forEach((choice) => {
|
|
165
|
+
Object.assign(choice, { text: i18next.t(choice.text, view) });
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Translate survey text to desired locale.
|
|
173
|
+
*
|
|
174
|
+
* @param trial - Trial data including user supplied parameters.
|
|
175
|
+
* @returns Survey json
|
|
176
|
+
*/
|
|
177
|
+
export const exitSurvey = (trial: TrialType<PluginInfo>) => {
|
|
178
|
+
setLocale(trial);
|
|
179
|
+
return new ExitSurveyJson(trial).survey;
|
|
180
|
+
};
|
package/src/index.spec.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LookitWindow } from "@lookit/data/dist/types";
|
|
2
2
|
import { PluginInfo, TrialType } from "jspsych";
|
|
3
|
+
import { html_params } from "../../record/src/videoConfig";
|
|
3
4
|
import { ConsentTemplateNotFound } from "./errors";
|
|
4
5
|
import chsTemplate from "./index";
|
|
5
6
|
|
|
@@ -11,7 +12,7 @@ declare const window: LookitWindow;
|
|
|
11
12
|
* @param values - Object to replace default trial values
|
|
12
13
|
* @returns Trial object
|
|
13
14
|
*/
|
|
14
|
-
const getTrial = (values: Record<string, string> = {}) => {
|
|
15
|
+
const getTrial = (values: Record<string, string | boolean> = {}) => {
|
|
15
16
|
return {
|
|
16
17
|
locale: "en-us",
|
|
17
18
|
template: "consent-template-5",
|
|
@@ -72,3 +73,57 @@ test("consent garden template", () => {
|
|
|
72
73
|
const trial = getTrial({ template: "consent-garden" });
|
|
73
74
|
expect(chsTemplate.consentVideo(trial)).toContain("Project GARDEN");
|
|
74
75
|
});
|
|
76
|
+
|
|
77
|
+
test("video config template", () => {
|
|
78
|
+
const trial = getTrial();
|
|
79
|
+
|
|
80
|
+
expect(chsTemplate.videoConfig(trial, html_params)).toContain(
|
|
81
|
+
'<div id="lookit-jspsych-video-config">',
|
|
82
|
+
);
|
|
83
|
+
expect(chsTemplate.videoConfig(trial, html_params)).toContain(
|
|
84
|
+
`<h2>Webcam setup</h2>`,
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("video config template in Italian", () => {
|
|
89
|
+
const trial = getTrial({ locale: "it" });
|
|
90
|
+
|
|
91
|
+
expect(chsTemplate.videoConfig(trial, html_params)).toContain(
|
|
92
|
+
'<div id="lookit-jspsych-video-config">',
|
|
93
|
+
);
|
|
94
|
+
expect(chsTemplate.videoConfig(trial, html_params)).toContain(
|
|
95
|
+
`<h2>Configurazione della webcam</h2>`,
|
|
96
|
+
);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("uploading video template", () => {
|
|
100
|
+
const trial = getTrial();
|
|
101
|
+
|
|
102
|
+
expect(chsTemplate.uploadingVideo(trial)).toContain(
|
|
103
|
+
"<div>uploading video, please wait...</div>",
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("uploading video template in Portuguese", () => {
|
|
108
|
+
const trial = getTrial({ locale: "pt" });
|
|
109
|
+
|
|
110
|
+
expect(chsTemplate.uploadingVideo(trial)).toContain(
|
|
111
|
+
"<div>enviando vídeo, por favor, aguarde...</div>",
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("exit survey template", () => {
|
|
116
|
+
const trial = getTrial({ private_level_only: true });
|
|
117
|
+
const survey = chsTemplate.exitSurvey(trial);
|
|
118
|
+
expect(survey.pages[0].elements[0].description).toStrictEqual(
|
|
119
|
+
"We ask again just to check for typos during registration or accidental selection of a different child at the start of the study.",
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("exit survey template in French", () => {
|
|
124
|
+
const trial = getTrial({ locale: "fr" });
|
|
125
|
+
const survey = chsTemplate.exitSurvey(trial);
|
|
126
|
+
expect(survey.pages[0].elements[0].description).toStrictEqual(
|
|
127
|
+
"Nous vous demandons à nouveau en cas d'erreur lors de l'enregistrement ou de sélection par erreur d'un enfant différent au début de l'étude.",
|
|
128
|
+
);
|
|
129
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { consentVideo } from "./consentVideoTemplate";
|
|
2
|
+
import { exitSurvey } from "./exitSurveyTemplate";
|
|
3
|
+
import { uploadingVideo } from "./uploadingVideoTemplate";
|
|
4
|
+
import { videoConfig } from "./videoConfigTemplate";
|
|
2
5
|
|
|
3
|
-
export default { consentVideo };
|
|
6
|
+
export default { consentVideo, videoConfig, uploadingVideo, exitSurvey };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Handlebars from "handlebars";
|
|
2
|
+
import { PluginInfo, TrialType } from "jspsych";
|
|
3
|
+
import uploadingVideoTemplate from "../hbs/uploading-video.hbs";
|
|
4
|
+
import { setLocale } from "./utils";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get translated template for uploading video message.
|
|
8
|
+
*
|
|
9
|
+
* @param trial - JsPsych trial object containing trial params
|
|
10
|
+
* @returns Uploading video message HTML
|
|
11
|
+
*/
|
|
12
|
+
export const uploadingVideo = (trial: TrialType<PluginInfo>) => {
|
|
13
|
+
setLocale(trial);
|
|
14
|
+
|
|
15
|
+
return Handlebars.compile(uploadingVideoTemplate)({});
|
|
16
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Handlebars from "handlebars";
|
|
2
|
+
import { PluginInfo, TrialType } from "jspsych";
|
|
3
|
+
import videoConfigTemplate from "../hbs/video-config.hbs";
|
|
4
|
+
import { setLocale } from "./utils";
|
|
5
|
+
|
|
6
|
+
type VideoConfigTemplateParams = {
|
|
7
|
+
webcam_container_id: string;
|
|
8
|
+
reload_button_id_cam: string;
|
|
9
|
+
camera_selection_id: string;
|
|
10
|
+
mic_selection_id: string;
|
|
11
|
+
step1_id: string;
|
|
12
|
+
step2_id: string;
|
|
13
|
+
step3_id: string;
|
|
14
|
+
step_complete_class: string;
|
|
15
|
+
reload_button_id_text: string;
|
|
16
|
+
next_button_id: string;
|
|
17
|
+
waiting_for_access_msg_id: string;
|
|
18
|
+
checking_mic_msg_id: string;
|
|
19
|
+
access_problem_msg_id: string;
|
|
20
|
+
setup_problem_msg_id: string;
|
|
21
|
+
chromeInitialPrompt: string;
|
|
22
|
+
chromeAlwaysAllow: string;
|
|
23
|
+
chromePermissions: string;
|
|
24
|
+
firefoxInitialPrompt: string;
|
|
25
|
+
firefoxChooseDevice: string;
|
|
26
|
+
firefoxDevicesBlocked: string;
|
|
27
|
+
checkmarkIcon: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Get translated template for video config.
|
|
32
|
+
*
|
|
33
|
+
* @param trial - JsPsych trial object containing trial params
|
|
34
|
+
* @param html_params - Additional context variables for the template.
|
|
35
|
+
* @returns Video config HTML
|
|
36
|
+
*/
|
|
37
|
+
export const videoConfig = (
|
|
38
|
+
trial: TrialType<PluginInfo>,
|
|
39
|
+
html_params: VideoConfigTemplateParams,
|
|
40
|
+
) => {
|
|
41
|
+
setLocale(trial);
|
|
42
|
+
|
|
43
|
+
return Handlebars.compile(videoConfigTemplate)({
|
|
44
|
+
...trial,
|
|
45
|
+
...html_params,
|
|
46
|
+
});
|
|
47
|
+
};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PluginInfo, TrialType } from "jspsych";
|
|
2
|
-
/**
|
|
3
|
-
* Translate, render, and get consent document HTML.
|
|
4
|
-
*
|
|
5
|
-
* @param trial - JsPsych trial object containing trial params
|
|
6
|
-
* @returns Consent document HTML
|
|
7
|
-
*/
|
|
8
|
-
export declare const consentVideo: (trial: TrialType<PluginInfo>) => string;
|
package/dist/errors.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/** Error thrown when specified language isn't found */
|
|
2
|
-
export declare class LocaleNotFoundError extends Error {
|
|
3
|
-
/**
|
|
4
|
-
* This will be thrown when attempting to init i18n
|
|
5
|
-
*
|
|
6
|
-
* @param baseName - Language a2code with region
|
|
7
|
-
*/
|
|
8
|
-
constructor(baseName: string);
|
|
9
|
-
}
|
|
10
|
-
/** Error thrown when researcher selects template that isn't available. */
|
|
11
|
-
export declare class ConsentTemplateNotFound extends Error {
|
|
12
|
-
/**
|
|
13
|
-
* This will let the researcher know that their template isn't found.
|
|
14
|
-
*
|
|
15
|
-
* @param template - Supplied name of consent template.
|
|
16
|
-
*/
|
|
17
|
-
constructor(template: string);
|
|
18
|
-
}
|
package/dist/utils.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { PluginInfo, TrialType } from "jspsych";
|
|
2
|
-
/**
|
|
3
|
-
* Pulled from EFP. Function to convert researcher's text to HTML.
|
|
4
|
-
*
|
|
5
|
-
* @param text - Text
|
|
6
|
-
* @returns Formatted string
|
|
7
|
-
*/
|
|
8
|
-
export declare const expFormat: (text?: string | string[]) => string;
|
|
9
|
-
/**
|
|
10
|
-
* Initialize i18next with parameters from trial.
|
|
11
|
-
*
|
|
12
|
-
* @param trial - Trial data including user supplied parameters.
|
|
13
|
-
*/
|
|
14
|
-
export declare const setLocale: (trial: TrialType<PluginInfo>) => void;
|