@jspsych/plugin-html-keyboard-response 1.1.2 → 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.js CHANGED
@@ -1,170 +1,177 @@
1
1
  import { ParameterType } from 'jspsych';
2
2
 
3
- const info = {
4
- name: "html-keyboard-response",
5
- parameters: {
6
- /**
7
- * The HTML string to be displayed.
8
- */
9
- stimulus: {
10
- type: ParameterType.HTML_STRING,
11
- pretty_name: "Stimulus",
12
- default: undefined,
13
- },
14
- /**
15
- * Array containing the key(s) the subject is allowed to press to respond to the stimulus.
16
- */
17
- choices: {
18
- type: ParameterType.KEYS,
19
- pretty_name: "Choices",
20
- default: "ALL_KEYS",
21
- },
22
- /**
23
- * Any content here will be displayed below the stimulus.
24
- */
25
- prompt: {
26
- type: ParameterType.HTML_STRING,
27
- pretty_name: "Prompt",
28
- default: null,
29
- },
30
- /**
31
- * How long to show the stimulus.
32
- */
33
- stimulus_duration: {
34
- type: ParameterType.INT,
35
- pretty_name: "Stimulus duration",
36
- default: null,
37
- },
38
- /**
39
- * How long to show trial before it ends.
40
- */
41
- trial_duration: {
42
- type: ParameterType.INT,
43
- pretty_name: "Trial duration",
44
- default: null,
45
- },
46
- /**
47
- * If true, trial will end when subject makes a response.
48
- */
49
- response_ends_trial: {
50
- type: ParameterType.BOOL,
51
- pretty_name: "Response ends trial",
52
- default: true,
53
- },
54
- },
55
- };
56
- /**
57
- * **html-keyboard-response**
58
- *
59
- * jsPsych plugin for displaying a stimulus and getting a keyboard response
60
- *
61
- * @author Josh de Leeuw
62
- * @see {@link https://www.jspsych.org/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
63
- */
64
- class HtmlKeyboardResponsePlugin {
65
- constructor(jsPsych) {
66
- this.jsPsych = jsPsych;
67
- }
68
- trial(display_element, trial) {
69
- var new_html = '<div id="jspsych-html-keyboard-response-stimulus">' + trial.stimulus + "</div>";
70
- // add prompt
71
- if (trial.prompt !== null) {
72
- new_html += trial.prompt;
73
- }
74
- // draw
75
- display_element.innerHTML = new_html;
76
- // store response
77
- var response = {
78
- rt: null,
79
- key: null,
80
- };
81
- // function to end trial when it is time
82
- const end_trial = () => {
83
- // kill any remaining setTimeout handlers
84
- this.jsPsych.pluginAPI.clearAllTimeouts();
85
- // kill keyboard listeners
86
- if (typeof keyboardListener !== "undefined") {
87
- this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
88
- }
89
- // gather the data to store for the trial
90
- var trial_data = {
91
- rt: response.rt,
92
- stimulus: trial.stimulus,
93
- response: response.key,
94
- };
95
- // clear the display
96
- display_element.innerHTML = "";
97
- // move on to the next trial
98
- this.jsPsych.finishTrial(trial_data);
99
- };
100
- // function to handle responses by the subject
101
- var after_response = (info) => {
102
- // after a valid response, the stimulus will have the CSS class 'responded'
103
- // which can be used to provide visual feedback that a response was recorded
104
- display_element.querySelector("#jspsych-html-keyboard-response-stimulus").className +=
105
- " responded";
106
- // only record the first response
107
- if (response.key == null) {
108
- response = info;
109
- }
110
- if (trial.response_ends_trial) {
111
- end_trial();
112
- }
113
- };
114
- // start the response listener
115
- if (trial.choices != "NO_KEYS") {
116
- var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({
117
- callback_function: after_response,
118
- valid_responses: trial.choices,
119
- rt_method: "performance",
120
- persist: false,
121
- allow_held_key: false,
122
- });
123
- }
124
- // hide stimulus if stimulus_duration is set
125
- if (trial.stimulus_duration !== null) {
126
- this.jsPsych.pluginAPI.setTimeout(() => {
127
- display_element.querySelector("#jspsych-html-keyboard-response-stimulus").style.visibility = "hidden";
128
- }, trial.stimulus_duration);
129
- }
130
- // end trial if trial_duration is set
131
- if (trial.trial_duration !== null) {
132
- this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
133
- }
134
- }
135
- simulate(trial, simulation_mode, simulation_options, load_callback) {
136
- if (simulation_mode == "data-only") {
137
- load_callback();
138
- this.simulate_data_only(trial, simulation_options);
139
- }
140
- if (simulation_mode == "visual") {
141
- this.simulate_visual(trial, simulation_options, load_callback);
142
- }
143
- }
144
- create_simulation_data(trial, simulation_options) {
145
- const default_data = {
146
- stimulus: trial.stimulus,
147
- rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
148
- response: this.jsPsych.pluginAPI.getValidKey(trial.choices),
149
- };
150
- const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
151
- this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
152
- return data;
153
- }
154
- simulate_data_only(trial, simulation_options) {
155
- const data = this.create_simulation_data(trial, simulation_options);
156
- this.jsPsych.finishTrial(data);
157
- }
158
- simulate_visual(trial, simulation_options, load_callback) {
159
- const data = this.create_simulation_data(trial, simulation_options);
160
- const display_element = this.jsPsych.getDisplayElement();
161
- this.trial(display_element, trial);
162
- load_callback();
163
- if (data.rt !== null) {
164
- this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
165
- }
166
- }
167
- }
3
+ var _package = {
4
+ name: "@jspsych/plugin-html-keyboard-response",
5
+ version: "2.0.0",
6
+ description: "jsPsych plugin for displaying a stimulus and getting a keyboard response",
7
+ type: "module",
8
+ main: "dist/index.cjs",
9
+ exports: {
10
+ import: "./dist/index.js",
11
+ require: "./dist/index.cjs"
12
+ },
13
+ typings: "dist/index.d.ts",
14
+ unpkg: "dist/index.browser.min.js",
15
+ files: [
16
+ "src",
17
+ "dist"
18
+ ],
19
+ source: "src/index.ts",
20
+ scripts: {
21
+ test: "jest",
22
+ "test:watch": "npm test -- --watch",
23
+ tsc: "tsc",
24
+ build: "rollup --config",
25
+ "build:watch": "npm run build -- --watch"
26
+ },
27
+ repository: {
28
+ type: "git",
29
+ url: "git+https://github.com/jspsych/jsPsych.git",
30
+ directory: "packages/plugin-html-keyboard-response"
31
+ },
32
+ author: "Josh de Leeuw",
33
+ license: "MIT",
34
+ bugs: {
35
+ url: "https://github.com/jspsych/jsPsych/issues"
36
+ },
37
+ homepage: "https://www.jspsych.org/latest/plugins/html-keyboard-response",
38
+ peerDependencies: {
39
+ jspsych: ">=7.1.0"
40
+ },
41
+ devDependencies: {
42
+ "@jspsych/config": "^3.0.0",
43
+ "@jspsych/test-utils": "^1.2.0"
44
+ }
45
+ };
46
+
47
+ const info = {
48
+ name: "html-keyboard-response",
49
+ version: _package.version,
50
+ parameters: {
51
+ stimulus: {
52
+ type: ParameterType.HTML_STRING,
53
+ default: void 0
54
+ },
55
+ choices: {
56
+ type: ParameterType.KEYS,
57
+ default: "ALL_KEYS"
58
+ },
59
+ prompt: {
60
+ type: ParameterType.HTML_STRING,
61
+ default: null
62
+ },
63
+ stimulus_duration: {
64
+ type: ParameterType.INT,
65
+ default: null
66
+ },
67
+ trial_duration: {
68
+ type: ParameterType.INT,
69
+ default: null
70
+ },
71
+ response_ends_trial: {
72
+ type: ParameterType.BOOL,
73
+ default: true
74
+ }
75
+ },
76
+ data: {
77
+ response: {
78
+ type: ParameterType.STRING
79
+ },
80
+ rt: {
81
+ type: ParameterType.INT
82
+ },
83
+ stimulus: {
84
+ type: ParameterType.STRING
85
+ }
86
+ }
87
+ };
88
+ class HtmlKeyboardResponsePlugin {
89
+ constructor(jsPsych) {
90
+ this.jsPsych = jsPsych;
91
+ }
92
+ trial(display_element, trial) {
93
+ var new_html = '<div id="jspsych-html-keyboard-response-stimulus">' + trial.stimulus + "</div>";
94
+ if (trial.prompt !== null) {
95
+ new_html += trial.prompt;
96
+ }
97
+ display_element.innerHTML = new_html;
98
+ var response = {
99
+ rt: null,
100
+ key: null
101
+ };
102
+ const end_trial = () => {
103
+ if (typeof keyboardListener !== "undefined") {
104
+ this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
105
+ }
106
+ var trial_data = {
107
+ rt: response.rt,
108
+ stimulus: trial.stimulus,
109
+ response: response.key
110
+ };
111
+ this.jsPsych.finishTrial(trial_data);
112
+ };
113
+ var after_response = (info2) => {
114
+ display_element.querySelector("#jspsych-html-keyboard-response-stimulus").className += " responded";
115
+ if (response.key == null) {
116
+ response = info2;
117
+ }
118
+ if (trial.response_ends_trial) {
119
+ end_trial();
120
+ }
121
+ };
122
+ if (trial.choices != "NO_KEYS") {
123
+ var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({
124
+ callback_function: after_response,
125
+ valid_responses: trial.choices,
126
+ rt_method: "performance",
127
+ persist: false,
128
+ allow_held_key: false
129
+ });
130
+ }
131
+ if (trial.stimulus_duration !== null) {
132
+ this.jsPsych.pluginAPI.setTimeout(() => {
133
+ display_element.querySelector(
134
+ "#jspsych-html-keyboard-response-stimulus"
135
+ ).style.visibility = "hidden";
136
+ }, trial.stimulus_duration);
137
+ }
138
+ if (trial.trial_duration !== null) {
139
+ this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);
140
+ }
141
+ }
142
+ simulate(trial, simulation_mode, simulation_options, load_callback) {
143
+ if (simulation_mode == "data-only") {
144
+ load_callback();
145
+ this.simulate_data_only(trial, simulation_options);
146
+ }
147
+ if (simulation_mode == "visual") {
148
+ this.simulate_visual(trial, simulation_options, load_callback);
149
+ }
150
+ }
151
+ create_simulation_data(trial, simulation_options) {
152
+ const default_data = {
153
+ stimulus: trial.stimulus,
154
+ rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),
155
+ response: this.jsPsych.pluginAPI.getValidKey(trial.choices)
156
+ };
157
+ const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);
158
+ this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);
159
+ return data;
160
+ }
161
+ simulate_data_only(trial, simulation_options) {
162
+ const data = this.create_simulation_data(trial, simulation_options);
163
+ this.jsPsych.finishTrial(data);
164
+ }
165
+ simulate_visual(trial, simulation_options, load_callback) {
166
+ const data = this.create_simulation_data(trial, simulation_options);
167
+ const display_element = this.jsPsych.getDisplayElement();
168
+ this.trial(display_element, trial);
169
+ load_callback();
170
+ if (data.rt !== null) {
171
+ this.jsPsych.pluginAPI.pressKey(data.response, data.rt);
172
+ }
173
+ }
174
+ }
168
175
  HtmlKeyboardResponsePlugin.info = info;
169
176
 
170
177
  export { HtmlKeyboardResponsePlugin as default };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"html-keyboard-response\",\n parameters: {\n /**\n * The HTML string to be displayed.\n */\n stimulus: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Stimulus\",\n default: undefined,\n },\n /**\n * Array containing the key(s) the subject is allowed to press to respond to the stimulus.\n */\n choices: {\n type: ParameterType.KEYS,\n pretty_name: \"Choices\",\n default: \"ALL_KEYS\",\n },\n /**\n * Any content here will be displayed below the stimulus.\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: null,\n },\n /**\n * How long to show the stimulus.\n */\n stimulus_duration: {\n type: ParameterType.INT,\n pretty_name: \"Stimulus duration\",\n default: null,\n },\n /**\n * How long to show trial before it ends.\n */\n trial_duration: {\n type: ParameterType.INT,\n pretty_name: \"Trial duration\",\n default: null,\n },\n /**\n * If true, trial will end when subject makes a response.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n pretty_name: \"Response ends trial\",\n default: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **html-keyboard-response**\n *\n * jsPsych plugin for displaying a stimulus and getting a keyboard response\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}\n */\nclass HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html = '<div id=\"jspsych-html-keyboard-response-stimulus\">' + trial.stimulus + \"</div>\";\n\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill any remaining setTimeout handlers\n this.jsPsych.pluginAPI.clearAllTimeouts();\n\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // clear the display\n display_element.innerHTML = \"\";\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-html-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n };\n\n // start the response listener\n if (trial.choices != \"NO_KEYS\") {\n var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n\n // hide stimulus if stimulus_duration is set\n if (trial.stimulus_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n display_element.querySelector<HTMLElement>(\n \"#jspsych-html-keyboard-response-stimulus\"\n ).style.visibility = \"hidden\";\n }, trial.stimulus_duration);\n }\n\n // end trial if trial_duration is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);\n }\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n }\n}\n\nexport default HtmlKeyboardResponsePlugin;\n"],"names":[],"mappings":";;AAEA,MAAM,IAAI,GAAU;AAClB,IAAA,IAAI,EAAE,wBAAwB;AAC9B,IAAA,UAAU,EAAE;AACV;;AAEG;AACH,QAAA,QAAQ,EAAE;YACR,IAAI,EAAE,aAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,UAAU;AACvB,YAAA,OAAO,EAAE,SAAS;AACnB,SAAA;AACD;;AAEG;AACH,QAAA,OAAO,EAAE;YACP,IAAI,EAAE,aAAa,CAAC,IAAI;AACxB,YAAA,WAAW,EAAE,SAAS;AACtB,YAAA,OAAO,EAAE,UAAU;AACpB,SAAA;AACD;;AAEG;AACH,QAAA,MAAM,EAAE;YACN,IAAI,EAAE,aAAa,CAAC,WAAW;AAC/B,YAAA,WAAW,EAAE,QAAQ;AACrB,YAAA,OAAO,EAAE,IAAI;AACd,SAAA;AACD;;AAEG;AACH,QAAA,iBAAiB,EAAE;YACjB,IAAI,EAAE,aAAa,CAAC,GAAG;AACvB,YAAA,WAAW,EAAE,mBAAmB;AACh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;AAEO,IAAA,eAAe,CAAC,KAAsB,EAAE,kBAAkB,EAAE,aAAyB,EAAA;QAC3F,MAAM,IAAI,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;QAEpE,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;AAEzD,QAAA,IAAI,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;AACnC,QAAA,aAAa,EAAE,CAAC;AAEhB,QAAA,IAAI,IAAI,CAAC,EAAE,KAAK,IAAI,EAAE;AACpB,YAAA,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;AACzD,SAAA;KACF;;AAtIM,0BAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"html-keyboard-response\",\n version: version,\n parameters: {\n /**\n * The string to be displayed.\n */\n stimulus: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /**\n * This array contains the key(s) that the participant is allowed to press in order to respond\n * to the stimulus. Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see\n * {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values this page}\n * and\n * {@link https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/ this page (event.key column)}\n * for more examples. Any key presses that are not listed in the\n * array will be ignored. The default value of `\"ALL_KEYS\"` means that all keys will be accepted as valid responses.\n * Specifying `\"NO_KEYS\"` will mean that no responses are allowed.\n */\n choices: {\n type: ParameterType.KEYS,\n default: \"ALL_KEYS\",\n },\n /**\n * This string can contain HTML markup. Any content here will be displayed below the stimulus.\n * The intention is that it can be used to provide a reminder about the action the participant\n * is supposed to take (e.g., which key to press).\n */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /**\n * How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus\n * will be set to `hidden` after this time has elapsed. If this is null, then the stimulus will\n * remain visible until the trial ends.\n */\n stimulus_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /**\n * How long to wait for the participant to make a response before ending the trial in milliseconds.\n * If the participant fails to make a response before this timer is reached, the participant's response\n * will be recorded as null for the trial and the trial will end. If the value of this parameter is null,\n * then the trial will wait for a response indefinitely.\n */\n trial_duration: {\n type: ParameterType.INT,\n default: null,\n },\n /**\n * If true, then the trial will end whenever the participant makes a response (assuming they make their\n * response before the cutoff specified by the trial_duration parameter). If false, then the trial will\n * continue until the value for trial_duration is reached. You can set this parameter to false to force\n * the participant to view a stimulus for a fixed amount of time, even if they respond before the time is complete.\n */\n response_ends_trial: {\n type: ParameterType.BOOL,\n default: true,\n },\n },\n data: {\n /** Indicates which key the participant pressed. */\n response: {\n type: ParameterType.STRING,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus first appears on the screen until the participant's response. */\n rt: {\n type: ParameterType.INT,\n },\n /** The HTML content that was displayed on the screen. */\n stimulus: {\n type: ParameterType.STRING,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * This plugin displays HTML content and records responses generated with the keyboard.\n * The stimulus can be displayed until a response is given, or for a pre-determined amount of time.\n * The trial can be ended automatically if the participant has failed to respond within a fixed length of time.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}\n */\nclass HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {\n static info = info;\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var new_html = '<div id=\"jspsych-html-keyboard-response-stimulus\">' + trial.stimulus + \"</div>\";\n\n // add prompt\n if (trial.prompt !== null) {\n new_html += trial.prompt;\n }\n\n // draw\n display_element.innerHTML = new_html;\n\n // store response\n var response = {\n rt: null,\n key: null,\n };\n\n // function to end trial when it is time\n const end_trial = () => {\n // kill keyboard listeners\n if (typeof keyboardListener !== \"undefined\") {\n this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);\n }\n\n // gather the data to store for the trial\n var trial_data = {\n rt: response.rt,\n stimulus: trial.stimulus,\n response: response.key,\n };\n\n // move on to the next trial\n this.jsPsych.finishTrial(trial_data);\n };\n\n // function to handle responses by the subject\n var after_response = (info) => {\n // after a valid response, the stimulus will have the CSS class 'responded'\n // which can be used to provide visual feedback that a response was recorded\n display_element.querySelector(\"#jspsych-html-keyboard-response-stimulus\").className +=\n \" responded\";\n\n // only record the first response\n if (response.key == null) {\n response = info;\n }\n\n if (trial.response_ends_trial) {\n end_trial();\n }\n };\n\n // start the response listener\n if (trial.choices != \"NO_KEYS\") {\n var keyboardListener = this.jsPsych.pluginAPI.getKeyboardResponse({\n callback_function: after_response,\n valid_responses: trial.choices,\n rt_method: \"performance\",\n persist: false,\n allow_held_key: false,\n });\n }\n\n // hide stimulus if stimulus_duration is set\n if (trial.stimulus_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(() => {\n display_element.querySelector<HTMLElement>(\n \"#jspsych-html-keyboard-response-stimulus\"\n ).style.visibility = \"hidden\";\n }, trial.stimulus_duration);\n }\n\n // end trial if trial_duration is set\n if (trial.trial_duration !== null) {\n this.jsPsych.pluginAPI.setTimeout(end_trial, trial.trial_duration);\n }\n }\n\n simulate(\n trial: TrialType<Info>,\n simulation_mode,\n simulation_options: any,\n load_callback: () => void\n ) {\n if (simulation_mode == \"data-only\") {\n load_callback();\n this.simulate_data_only(trial, simulation_options);\n }\n if (simulation_mode == \"visual\") {\n this.simulate_visual(trial, simulation_options, load_callback);\n }\n }\n\n private create_simulation_data(trial: TrialType<Info>, simulation_options) {\n const default_data = {\n stimulus: trial.stimulus,\n rt: this.jsPsych.randomization.sampleExGaussian(500, 50, 1 / 150, true),\n response: this.jsPsych.pluginAPI.getValidKey(trial.choices),\n };\n\n const data = this.jsPsych.pluginAPI.mergeSimulationData(default_data, simulation_options);\n\n this.jsPsych.pluginAPI.ensureSimulationDataConsistency(trial, data);\n\n return data;\n }\n\n private simulate_data_only(trial: TrialType<Info>, simulation_options) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n this.jsPsych.finishTrial(data);\n }\n\n private simulate_visual(trial: TrialType<Info>, simulation_options, load_callback: () => void) {\n const data = this.create_simulation_data(trial, simulation_options);\n\n const display_element = this.jsPsych.getDisplayElement();\n\n this.trial(display_element, trial);\n load_callback();\n\n if (data.rt !== null) {\n this.jsPsych.pluginAPI.pressKey(data.response, data.rt);\n }\n }\n}\n\nexport default HtmlKeyboardResponsePlugin;\n"],"names":["version","info"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,wBAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAIV,QAAU,EAAA;AAAA,MACR,MAAM,aAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,KAAA,CAAA;AAAA,KACX;AAAA,IAWA,OAAS,EAAA;AAAA,MACP,MAAM,aAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,UAAA;AAAA,KACX;AAAA,IAMA,MAAQ,EAAA;AAAA,MACN,MAAM,aAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAMA,iBAAmB,EAAA;AAAA,MACjB,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAOA,cAAgB,EAAA;AAAA,MACd,MAAM,aAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAOA,mBAAqB,EAAA;AAA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AAA,eAAA,GAAkB,IAAK,CAAA,OAAA,CAAQ,iBAAkB,EAAA,CAAA;AAEvD,IAAK,IAAA,CAAA,KAAA,CAAM,iBAAiB,KAAK,CAAA,CAAA;AACjC,IAAc,aAAA,EAAA,CAAA;AAEd,IAAI,IAAA,IAAA,CAAK,OAAO,IAAM,EAAA;AACpB,MAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,QAAA,CAAS,IAAK,CAAA,QAAA,EAAU,KAAK,EAAE,CAAA,CAAA;AAAA,KACxD;AAAA,GACF;AACF,CAAA;AAjIM,0BAAA,CACG,IAAO,GAAA,IAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jspsych/plugin-html-keyboard-response",
3
- "version": "1.1.2",
3
+ "version": "2.0.0",
4
4
  "description": "jsPsych plugin for displaying a stimulus and getting a keyboard response",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -37,7 +37,7 @@
37
37
  "jspsych": ">=7.1.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@jspsych/config": "^1.3.0",
41
- "@jspsych/test-utils": "^1.1.2"
40
+ "@jspsych/config": "^3.0.0",
41
+ "@jspsych/test-utils": "^1.2.0"
42
42
  }
43
43
  }
package/src/index.spec.ts CHANGED
@@ -14,7 +14,7 @@ describe("html-keyboard-response", () => {
14
14
  ]);
15
15
 
16
16
  expect(getHTML()).toBe('<div id="jspsych-html-keyboard-response-stimulus">this is html</div>');
17
- pressKey("a");
17
+ await pressKey("a");
18
18
  await expectFinished();
19
19
  });
20
20
 
@@ -30,7 +30,8 @@ describe("html-keyboard-response", () => {
30
30
  '<div id="jspsych-html-keyboard-response-stimulus">this is html</div>'
31
31
  );
32
32
 
33
- pressKey("f");
33
+ await pressKey("f");
34
+ expect(getHTML()).toBe("");
34
35
  await expectFinished();
35
36
  });
36
37
 
@@ -48,7 +49,7 @@ describe("html-keyboard-response", () => {
48
49
  '<div id="jspsych-html-keyboard-response-stimulus">this is html</div><div id="foo">this is a prompt</div>'
49
50
  );
50
51
 
51
- pressKey("f");
52
+ await pressKey("f");
52
53
  await expectFinished();
53
54
  });
54
55
 
@@ -74,7 +75,7 @@ describe("html-keyboard-response", () => {
74
75
  .visibility
75
76
  ).toBe("hidden");
76
77
 
77
- pressKey("f");
78
+ await pressKey("f");
78
79
  await expectFinished();
79
80
  });
80
81
 
@@ -107,7 +108,7 @@ describe("html-keyboard-response", () => {
107
108
  '<div id="jspsych-html-keyboard-response-stimulus">this is html</div>'
108
109
  );
109
110
 
110
- pressKey("f");
111
+ await pressKey("f");
111
112
  await expectFinished();
112
113
  });
113
114
 
@@ -125,7 +126,7 @@ describe("html-keyboard-response", () => {
125
126
  '<div id="jspsych-html-keyboard-response-stimulus">this is html</div>'
126
127
  );
127
128
 
128
- pressKey("f");
129
+ await pressKey("f");
129
130
 
130
131
  expect(document.querySelector("#jspsych-html-keyboard-response-stimulus").className).toBe(
131
132
  " responded"
package/src/index.ts CHANGED
@@ -1,72 +1,99 @@
1
1
  import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
2
2
 
3
+ import { version } from "../package.json";
4
+
3
5
  const info = <const>{
4
6
  name: "html-keyboard-response",
7
+ version: version,
5
8
  parameters: {
6
9
  /**
7
- * The HTML string to be displayed.
10
+ * The string to be displayed.
8
11
  */
9
12
  stimulus: {
10
13
  type: ParameterType.HTML_STRING,
11
- pretty_name: "Stimulus",
12
14
  default: undefined,
13
15
  },
14
16
  /**
15
- * Array containing the key(s) the subject is allowed to press to respond to the stimulus.
17
+ * This array contains the key(s) that the participant is allowed to press in order to respond
18
+ * to the stimulus. Keys should be specified as characters (e.g., `'a'`, `'q'`, `' '`, `'Enter'`, `'ArrowDown'`) - see
19
+ * {@link https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values this page}
20
+ * and
21
+ * {@link https://www.freecodecamp.org/news/javascript-keycode-list-keypress-event-key-codes/ this page (event.key column)}
22
+ * for more examples. Any key presses that are not listed in the
23
+ * array will be ignored. The default value of `"ALL_KEYS"` means that all keys will be accepted as valid responses.
24
+ * Specifying `"NO_KEYS"` will mean that no responses are allowed.
16
25
  */
17
26
  choices: {
18
27
  type: ParameterType.KEYS,
19
- pretty_name: "Choices",
20
28
  default: "ALL_KEYS",
21
29
  },
22
30
  /**
23
- * Any content here will be displayed below the stimulus.
31
+ * This string can contain HTML markup. Any content here will be displayed below the stimulus.
32
+ * The intention is that it can be used to provide a reminder about the action the participant
33
+ * is supposed to take (e.g., which key to press).
24
34
  */
25
35
  prompt: {
26
36
  type: ParameterType.HTML_STRING,
27
- pretty_name: "Prompt",
28
37
  default: null,
29
38
  },
30
39
  /**
31
- * How long to show the stimulus.
40
+ * How long to display the stimulus in milliseconds. The visibility CSS property of the stimulus
41
+ * will be set to `hidden` after this time has elapsed. If this is null, then the stimulus will
42
+ * remain visible until the trial ends.
32
43
  */
33
44
  stimulus_duration: {
34
45
  type: ParameterType.INT,
35
- pretty_name: "Stimulus duration",
36
46
  default: null,
37
47
  },
38
48
  /**
39
- * How long to show trial before it ends.
49
+ * How long to wait for the participant to make a response before ending the trial in milliseconds.
50
+ * If the participant fails to make a response before this timer is reached, the participant's response
51
+ * will be recorded as null for the trial and the trial will end. If the value of this parameter is null,
52
+ * then the trial will wait for a response indefinitely.
40
53
  */
41
54
  trial_duration: {
42
55
  type: ParameterType.INT,
43
- pretty_name: "Trial duration",
44
56
  default: null,
45
57
  },
46
58
  /**
47
- * If true, trial will end when subject makes a response.
59
+ * If true, then the trial will end whenever the participant makes a response (assuming they make their
60
+ * response before the cutoff specified by the trial_duration parameter). If false, then the trial will
61
+ * continue until the value for trial_duration is reached. You can set this parameter to false to force
62
+ * the participant to view a stimulus for a fixed amount of time, even if they respond before the time is complete.
48
63
  */
49
64
  response_ends_trial: {
50
65
  type: ParameterType.BOOL,
51
- pretty_name: "Response ends trial",
52
66
  default: true,
53
67
  },
54
68
  },
69
+ data: {
70
+ /** Indicates which key the participant pressed. */
71
+ response: {
72
+ type: ParameterType.STRING,
73
+ },
74
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the stimulus first appears on the screen until the participant's response. */
75
+ rt: {
76
+ type: ParameterType.INT,
77
+ },
78
+ /** The HTML content that was displayed on the screen. */
79
+ stimulus: {
80
+ type: ParameterType.STRING,
81
+ },
82
+ },
55
83
  };
56
84
 
57
85
  type Info = typeof info;
58
86
 
59
87
  /**
60
- * **html-keyboard-response**
61
- *
62
- * jsPsych plugin for displaying a stimulus and getting a keyboard response
88
+ * This plugin displays HTML content and records responses generated with the keyboard.
89
+ * The stimulus can be displayed until a response is given, or for a pre-determined amount of time.
90
+ * The trial can be ended automatically if the participant has failed to respond within a fixed length of time.
63
91
  *
64
92
  * @author Josh de Leeuw
65
- * @see {@link https://www.jspsych.org/plugins/jspsych-html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
93
+ * @see {@link https://www.jspsych.org/latest/plugins/html-keyboard-response/ html-keyboard-response plugin documentation on jspsych.org}
66
94
  */
67
95
  class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
68
96
  static info = info;
69
-
70
97
  constructor(private jsPsych: JsPsych) {}
71
98
 
72
99
  trial(display_element: HTMLElement, trial: TrialType<Info>) {
@@ -88,9 +115,6 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
88
115
 
89
116
  // function to end trial when it is time
90
117
  const end_trial = () => {
91
- // kill any remaining setTimeout handlers
92
- this.jsPsych.pluginAPI.clearAllTimeouts();
93
-
94
118
  // kill keyboard listeners
95
119
  if (typeof keyboardListener !== "undefined") {
96
120
  this.jsPsych.pluginAPI.cancelKeyboardResponse(keyboardListener);
@@ -103,9 +127,6 @@ class HtmlKeyboardResponsePlugin implements JsPsychPlugin<Info> {
103
127
  response: response.key,
104
128
  };
105
129
 
106
- // clear the display
107
- display_element.innerHTML = "";
108
-
109
130
  // move on to the next trial
110
131
  this.jsPsych.finishTrial(trial_data);
111
132
  };