@jspsych/plugin-survey-multi-choice 1.1.3 → 2.0.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n parameters: {\n /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n pretty_name: \"Questions\",\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Prompt\",\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n pretty_name: \"Options\",\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n pretty_name: \"Required\",\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n pretty_name: \"Horizontal\",\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n pretty_name: \"Question Name\",\n default: \"\",\n },\n },\n },\n /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\n pretty_name: \"Randomize Question Order\",\n default: false,\n },\n /** HTML-formatted string to display at top of the page above all of the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n pretty_name: \"Preamble\",\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\n pretty_name: \"Button label\",\n default: \"Continue\",\n },\n /** Setting this to true will enable browser auto-complete or auto-fill for the form. */\n autocomplete: {\n type: ParameterType.BOOL,\n pretty_name: \"Allow autocomplete\",\n default: false,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * jsPsych plugin for presenting multiple choice survey questions\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n display_element.innerHTML = \"\";\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\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 question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\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 const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAEA,MAAM,IAAI,GAAU;AAClB,IAAA,IAAI,EAAE,qBAAqB;AAC3B,IAAA,UAAU,EAAE;;AAEV,QAAA,SAAS,EAAE;YACT,IAAI,EAAEA,qBAAa,CAAC,OAAO;AAC3B,YAAA,KAAK,EAAE,IAAI;AACX,YAAA,WAAW,EAAE,WAAW;AACxB,YAAA,MAAM,EAAE;;AAEN,gBAAA,MAAM,EAAE;oBACN,IAAI,EAAEA,qBAAa,CAAC,WAAW;AAC/B,oBAAA,WAAW,EAAE,QAAQ;AACrB,oBAAA,OAAO,EAAE,SAAS;AACnB,iBAAA;;AAED,gBAAA,OAAO,EAAE;oBACP,IAAI,EAAEA,qBAAa,CAAC,MAAM;AAC1B,oBAAA,WAAW,EAAE,SAAS;AACtB,oBAAA,KAAK,EAAE,IAAI;AACX,oBAAA,OAAO,EAAE,SAAS;AACnB,iBAAA;;AAED,gBAAA,QAAQ,EAAE;oBACR,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,oBAAA,WAAW,EAAE,UAAU;AACvB,oBAAA,OAAO,EAAE,KAAK;AACf,iBAAA;;AAED,gBAAA,UAAU,EAAE;oBACV,IAAI,EAAEA,qBAAa,CAAC,IAAI;AACxB,oBAAA,WAAW,EAAE,YAAY;AACzB,oBAAA,OAAO,EAAE,KAAK;AACf,iBAAA;;AAED,gBAAA,IAAI,EAAE;oBACJ,IAAI,EAAEA,qBAAa,CAAC,MAAM;AAC1B,oBAAA,WAAW,EAAE,eAAe;AAC5B,oBAAA,OAAO,EAA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AC,CAAC;AAC9C,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACvC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAChC,eAAe,CAAC,aAAa,CAC3B,CAAyC,sCAAA,EAAA,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAC9E,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACd,CAAE,CAAA,CACJ,EACD,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC,CAC9C,CAAC;AACH,SAAA;AAED,QAAA,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAChC,eAAe,CAAC,aAAa,CAAC,mCAAmC,CAAC,EAClE,IAAI,CAAC,EAAE,CACR,CAAC;KACH;;AAjOM,uBAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../package.json","../src/index.ts"],"sourcesContent":["{\n \"name\": \"@jspsych/plugin-survey-multi-choice\",\n \"version\": \"2.0.1\",\n \"description\": \"a jspsych plugin for multiple choice survey questions\",\n \"type\": \"module\",\n \"main\": \"dist/index.cjs\",\n \"exports\": {\n \"import\": \"./dist/index.js\",\n \"require\": \"./dist/index.cjs\"\n },\n \"typings\": \"dist/index.d.ts\",\n \"unpkg\": \"dist/index.browser.min.js\",\n \"files\": [\n \"src\",\n \"dist\"\n ],\n \"source\": \"src/index.ts\",\n \"scripts\": {\n \"test\": \"jest\",\n \"test:watch\": \"npm test -- --watch\",\n \"tsc\": \"tsc\",\n \"build\": \"rollup --config\",\n \"build:watch\": \"npm run build -- --watch\"\n },\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/jspsych/jsPsych.git\",\n \"directory\": \"packages/plugin-survey-multi-choice\"\n },\n \"author\": \"Shane Martin\",\n \"license\": \"MIT\",\n \"bugs\": {\n \"url\": \"https://github.com/jspsych/jsPsych/issues\"\n },\n \"homepage\": \"https://www.jspsych.org/latest/plugins/survey-multi-choice\",\n \"peerDependencies\": {\n \"jspsych\": \">=7.1.0\"\n },\n \"devDependencies\": {\n \"@jspsych/config\": \"^3.1.1\",\n \"@jspsych/test-utils\": \"^1.2.0\"\n }\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-multi-choice\",\n version: version,\n parameters: {\n /**\n * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,\n * options, required, and horizontal parameter that will be applied to the question. See examples below for further\n * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be\n * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).\n * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to\n * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates\n * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is\n * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the\n * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing\n * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.\n */\n questions: {\n type: ParameterType.COMPLEX,\n array: true,\n nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of multiple choice options for this question. */\n options: {\n type: ParameterType.STRING,\n array: true,\n default: undefined,\n },\n /** Whether or not a response to this question must be given in order to continue. */\n required: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** If true, then the question will be centered and options will be displayed horizontally. */\n horizontal: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */\n name: {\n type: ParameterType.STRING,\n default: \"\",\n },\n },\n },\n /**\n * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,\n * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.\n */\n randomize_question_order: {\n type: ParameterType.BOOL,\n default: false,\n },\n /** HTML formatted string to display at the top of the page above all the questions. */\n preamble: {\n type: ParameterType.HTML_STRING,\n default: null,\n },\n /** Label of the button. */\n button_label: {\n type: ParameterType.STRING,\n default: \"Continue\",\n },\n /**\n * This determines whether or not all of the input elements on the page should allow autocomplete. Setting\n * this to true will enable autocomplete or auto-fill for the form.\n */\n autocomplete: {\n type: ParameterType.BOOL,\n default: false,\n },\n },\n data: {\n /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n response: {\n type: ParameterType.OBJECT,\n },\n /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */\n rt: {\n type: ParameterType.INT,\n },\n /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */\n question_order: {\n type: ParameterType.INT,\n array: true,\n },\n },\n};\n\ntype Info = typeof info;\n\n/**\n * **survey-multi-choice**\n *\n * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.\n *\n * @author Shane Martin\n * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}\n */\nclass SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n var plugin_id_name = \"jspsych-survey-multi-choice\";\n\n var html = \"\";\n\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-multi-choice-css\">';\n html +=\n \".jspsych-survey-multi-choice-question { margin-top: 2em; margin-bottom: 2em; text-align: left; }\" +\n \".jspsych-survey-multi-choice-text span.required {color: darkred;}\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-text { text-align: center;}\" +\n \".jspsych-survey-multi-choice-option { line-height: 2; }\" +\n \".jspsych-survey-multi-choice-horizontal .jspsych-survey-multi-choice-option { display: inline-block; margin-left: 1em; margin-right: 1em; vertical-align: top;}\" +\n \"label.jspsych-survey-multi-choice-text input[type='radio'] {margin-right: 1em;}\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-multi-choice-preamble\" class=\"jspsych-survey-multi-choice-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n // form element\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-multi-choice-form\">';\n } else {\n html += '<form id=\"jspsych-survey-multi-choice-form\" autocomplete=\"off\">';\n }\n // generate question order. this is randomized here as opposed to randomizing the order of trial.questions\n // so that the data are always associated with the same question regardless of order\n var question_order = [];\n for (var i = 0; i < trial.questions.length; i++) {\n question_order.push(i);\n }\n if (trial.randomize_question_order) {\n question_order = this.jsPsych.randomization.shuffle(question_order);\n }\n\n // add multiple-choice questions\n for (var i = 0; i < trial.questions.length; i++) {\n // get question based on question_order\n var question = trial.questions[question_order[i]];\n var question_id = question_order[i];\n\n // create question container\n var question_classes = [\"jspsych-survey-multi-choice-question\"];\n if (question.horizontal) {\n question_classes.push(\"jspsych-survey-multi-choice-horizontal\");\n }\n\n html +=\n '<div id=\"jspsych-survey-multi-choice-' +\n question_id +\n '\" class=\"' +\n question_classes.join(\" \") +\n '\" data-name=\"' +\n question.name +\n '\">';\n\n // add question text\n html += '<p class=\"jspsych-survey-multi-choice-text survey-multi-choice\">' + question.prompt;\n if (question.required) {\n html += \"<span class='required'>*</span>\";\n }\n html += \"</p>\";\n\n // create option radio buttons\n for (var j = 0; j < question.options.length; j++) {\n // add label and question text\n var option_id_name = \"jspsych-survey-multi-choice-option-\" + question_id + \"-\" + j;\n var input_name = \"jspsych-survey-multi-choice-response-\" + question_id;\n var input_id = \"jspsych-survey-multi-choice-response-\" + question_id + \"-\" + j;\n\n var required_attr = question.required ? \"required\" : \"\";\n\n // add radio button container\n html += '<div id=\"' + option_id_name + '\" class=\"jspsych-survey-multi-choice-option\">';\n html += '<label class=\"jspsych-survey-multi-choice-text\" for=\"' + input_id + '\">';\n html +=\n '<input type=\"radio\" name=\"' +\n input_name +\n '\" id=\"' +\n input_id +\n '\" value=\"' +\n question.options[j] +\n '\" ' +\n required_attr +\n \"></input>\";\n html += question.options[j] + \"</label>\";\n html += \"</div>\";\n }\n\n html += \"</div>\";\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"' +\n plugin_id_name +\n '-next\" class=\"' +\n plugin_id_name +\n ' jspsych-btn\"' +\n (trial.button_label ? ' value=\"' + trial.button_label + '\"' : \"\") +\n \"></input>\";\n html += \"</form>\";\n\n // render\n display_element.innerHTML = html;\n\n document.querySelector(\"form\").addEventListener(\"submit\", (event) => {\n event.preventDefault();\n // measure response time\n var endTime = performance.now();\n var response_time = Math.round(endTime - startTime);\n\n // create object to hold responses\n var question_data = {};\n for (var i = 0; i < trial.questions.length; i++) {\n var match = display_element.querySelector(\"#jspsych-survey-multi-choice-\" + i);\n var id = \"Q\" + i;\n var val: String;\n if (match.querySelector(\"input[type=radio]:checked\") !== null) {\n val = match.querySelector<HTMLInputElement>(\"input[type=radio]:checked\").value;\n } else {\n val = \"\";\n }\n var obje = {};\n var name = id;\n if (match.attributes[\"data-name\"].value !== \"\") {\n name = match.attributes[\"data-name\"].value;\n }\n obje[name] = val;\n Object.assign(question_data, obje);\n }\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\n\n // next trial\n this.jsPsych.finishTrial(trial_data);\n });\n\n var startTime = performance.now();\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 question_data = {};\n let rt = 1000;\n\n for (const q of trial.questions) {\n const name = q.name ? q.name : `Q${trial.questions.indexOf(q)}`;\n question_data[name] = this.jsPsych.randomization.sampleWithoutReplacement(q.options, 1)[0];\n rt += this.jsPsych.randomization.sampleExGaussian(1500, 400, 1 / 200, true);\n }\n\n const default_data = {\n response: question_data,\n rt: rt,\n question_order: trial.randomize_question_order\n ? this.jsPsych.randomization.shuffle([...Array(trial.questions.length).keys()])\n : [...Array(trial.questions.length).keys()],\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 const answers = Object.entries(data.response);\n for (let i = 0; i < answers.length; i++) {\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\n `#jspsych-survey-multi-choice-response-${i}-${trial.questions[i].options.indexOf(\n answers[i][1]\n )}`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-multi-choice-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyMultiChoicePlugin;\n"],"names":["ParameterType","i"],"mappings":";;;;AAEE,IAAW,OAAA,GAAA,OAAA;;ACEb,MAAM,IA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E,IAAK,CAAA,EAAA,GAAK,GAAQ,IAAA,OAAA,CAAQ,UAAW,CAAI,GAAA,CAAA,CAAA;AAAA,OAC7C,CAAA;AAAA,KACF;AAEA,IAAA,IAAA,CAAK,QAAQ,SAAU,CAAA,WAAA;AAAA,MACrB,eAAA,CAAgB,cAAc,mCAAmC,CAAA;AAAA,MACjE,IAAK,CAAA,EAAA;AAAA,KACP,CAAA;AAAA,GACF;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,150 +1,197 @@
1
- import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
1
+ import { JsPsychPlugin, ParameterType, JsPsych, TrialType } from 'jspsych';
2
+
2
3
  declare const info: {
3
4
  readonly name: "survey-multi-choice";
5
+ readonly version: string;
4
6
  readonly parameters: {
5
- /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
7
+ /**
8
+ * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,
9
+ * options, required, and horizontal parameter that will be applied to the question. See examples below for further
10
+ * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be
11
+ * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).
12
+ * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to
13
+ * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates
14
+ * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is
15
+ * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the
16
+ * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing
17
+ * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.
18
+ */
6
19
  readonly questions: {
7
20
  readonly type: ParameterType.COMPLEX;
8
21
  readonly array: true;
9
- readonly pretty_name: "Questions";
10
22
  readonly nested: {
11
23
  /** Question prompt. */
12
24
  readonly prompt: {
13
25
  readonly type: ParameterType.HTML_STRING;
14
- readonly pretty_name: "Prompt";
15
26
  readonly default: any;
16
27
  };
17
28
  /** Array of multiple choice options for this question. */
18
29
  readonly options: {
19
30
  readonly type: ParameterType.STRING;
20
- readonly pretty_name: "Options";
21
31
  readonly array: true;
22
32
  readonly default: any;
23
33
  };
24
34
  /** Whether or not a response to this question must be given in order to continue. */
25
35
  readonly required: {
26
36
  readonly type: ParameterType.BOOL;
27
- readonly pretty_name: "Required";
28
37
  readonly default: false;
29
38
  };
30
39
  /** If true, then the question will be centered and options will be displayed horizontally. */
31
40
  readonly horizontal: {
32
41
  readonly type: ParameterType.BOOL;
33
- readonly pretty_name: "Horizontal";
34
42
  readonly default: false;
35
43
  };
36
44
  /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
37
45
  readonly name: {
38
46
  readonly type: ParameterType.STRING;
39
- readonly pretty_name: "Question Name";
40
47
  readonly default: "";
41
48
  };
42
49
  };
43
50
  };
44
- /** If true, the order of the questions in the 'questions' array will be randomized. */
51
+ /**
52
+ * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,
53
+ * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.
54
+ */
45
55
  readonly randomize_question_order: {
46
56
  readonly type: ParameterType.BOOL;
47
- readonly pretty_name: "Randomize Question Order";
48
57
  readonly default: false;
49
58
  };
50
- /** HTML-formatted string to display at top of the page above all of the questions. */
59
+ /** HTML formatted string to display at the top of the page above all the questions. */
51
60
  readonly preamble: {
52
61
  readonly type: ParameterType.HTML_STRING;
53
- readonly pretty_name: "Preamble";
54
62
  readonly default: any;
55
63
  };
56
- /** Label of the button to submit responses. */
64
+ /** Label of the button. */
57
65
  readonly button_label: {
58
66
  readonly type: ParameterType.STRING;
59
- readonly pretty_name: "Button label";
60
67
  readonly default: "Continue";
61
68
  };
62
- /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
69
+ /**
70
+ * This determines whether or not all of the input elements on the page should allow autocomplete. Setting
71
+ * this to true will enable autocomplete or auto-fill for the form.
72
+ */
63
73
  readonly autocomplete: {
64
74
  readonly type: ParameterType.BOOL;
65
- readonly pretty_name: "Allow autocomplete";
66
75
  readonly default: false;
67
76
  };
68
77
  };
78
+ readonly data: {
79
+ /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
80
+ readonly response: {
81
+ readonly type: ParameterType.OBJECT;
82
+ };
83
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */
84
+ readonly rt: {
85
+ readonly type: ParameterType.INT;
86
+ };
87
+ /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
88
+ readonly question_order: {
89
+ readonly type: ParameterType.INT;
90
+ readonly array: true;
91
+ };
92
+ };
69
93
  };
70
94
  type Info = typeof info;
71
95
  /**
72
96
  * **survey-multi-choice**
73
97
  *
74
- * jsPsych plugin for presenting multiple choice survey questions
98
+ * The survey-multi-choice plugin displays a set of questions with multiple choice response fields. The participant selects a single answer.
75
99
  *
76
100
  * @author Shane Martin
77
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
101
+ * @see {@link https://www.jspsych.org/latest/plugins/survey-multi-choice/ survey-multi-choice plugin documentation on jspsych.org}
78
102
  */
79
103
  declare class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
80
104
  private jsPsych;
81
105
  static info: {
82
106
  readonly name: "survey-multi-choice";
107
+ readonly version: string;
83
108
  readonly parameters: {
84
- /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
109
+ /**
110
+ * An array of objects, each object represents a question that appears on the screen. Each object contains a prompt,
111
+ * options, required, and horizontal parameter that will be applied to the question. See examples below for further
112
+ * clarification.`prompt`: Type string, default value is *undefined*. The string is prompt/question that will be
113
+ * associated with a group of options (radio buttons). All questions will get presented on the same page (trial).
114
+ * `options`: Type array, defualt value is *undefined*. An array of strings. The array contains a set of options to
115
+ * display for an individual question.`required`: Type boolean, default value is null. The boolean value indicates
116
+ * if a question is required('true') or not ('false'), using the HTML5 `required` attribute. If this parameter is
117
+ * undefined, the question will be optional. `horizontal`:Type boolean, default value is false. If true, then the
118
+ * question is centered and the options are displayed horizontally. `name`: Name of the question. Used for storing
119
+ * data. If left undefined then default names (`Q0`, `Q1`, `...`) will be used for the questions.
120
+ */
85
121
  readonly questions: {
86
122
  readonly type: ParameterType.COMPLEX;
87
123
  readonly array: true;
88
- readonly pretty_name: "Questions";
89
124
  readonly nested: {
90
125
  /** Question prompt. */
91
126
  readonly prompt: {
92
127
  readonly type: ParameterType.HTML_STRING;
93
- readonly pretty_name: "Prompt";
94
128
  readonly default: any;
95
129
  };
96
130
  /** Array of multiple choice options for this question. */
97
131
  readonly options: {
98
132
  readonly type: ParameterType.STRING;
99
- readonly pretty_name: "Options";
100
133
  readonly array: true;
101
134
  readonly default: any;
102
135
  };
103
136
  /** Whether or not a response to this question must be given in order to continue. */
104
137
  readonly required: {
105
138
  readonly type: ParameterType.BOOL;
106
- readonly pretty_name: "Required";
107
139
  readonly default: false;
108
140
  };
109
141
  /** If true, then the question will be centered and options will be displayed horizontally. */
110
142
  readonly horizontal: {
111
143
  readonly type: ParameterType.BOOL;
112
- readonly pretty_name: "Horizontal";
113
144
  readonly default: false;
114
145
  };
115
146
  /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
116
147
  readonly name: {
117
148
  readonly type: ParameterType.STRING;
118
- readonly pretty_name: "Question Name";
119
149
  readonly default: "";
120
150
  };
121
151
  };
122
152
  };
123
- /** If true, the order of the questions in the 'questions' array will be randomized. */
153
+ /**
154
+ * If true, the display order of `questions` is randomly determined at the start of the trial. In the data object,
155
+ * `Q0` will still refer to the first question in the array, regardless of where it was presented visually.
156
+ */
124
157
  readonly randomize_question_order: {
125
158
  readonly type: ParameterType.BOOL;
126
- readonly pretty_name: "Randomize Question Order";
127
159
  readonly default: false;
128
160
  };
129
- /** HTML-formatted string to display at top of the page above all of the questions. */
161
+ /** HTML formatted string to display at the top of the page above all the questions. */
130
162
  readonly preamble: {
131
163
  readonly type: ParameterType.HTML_STRING;
132
- readonly pretty_name: "Preamble";
133
164
  readonly default: any;
134
165
  };
135
- /** Label of the button to submit responses. */
166
+ /** Label of the button. */
136
167
  readonly button_label: {
137
168
  readonly type: ParameterType.STRING;
138
- readonly pretty_name: "Button label";
139
169
  readonly default: "Continue";
140
170
  };
141
- /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
171
+ /**
172
+ * This determines whether or not all of the input elements on the page should allow autocomplete. Setting
173
+ * this to true will enable autocomplete or auto-fill for the form.
174
+ */
142
175
  readonly autocomplete: {
143
176
  readonly type: ParameterType.BOOL;
144
- readonly pretty_name: "Allow autocomplete";
145
177
  readonly default: false;
146
178
  };
147
179
  };
180
+ readonly data: {
181
+ /** An object containing the response for each question. The object will have a separate key (variable) for each question, with the first question in the trial being recorded in `Q0`, the second in `Q1`, and so on. The responses are recorded as integers, representing the position selected on the likert scale for that question. If the `name` parameter is defined for the question, then the response object will use the value of `name` as the key for each question. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
182
+ readonly response: {
183
+ readonly type: ParameterType.OBJECT;
184
+ };
185
+ /** The response time in milliseconds for the participant to make a response. The time is measured from when the questions first appear on the screen until the participant's response(s) are submitted. */
186
+ readonly rt: {
187
+ readonly type: ParameterType.INT;
188
+ };
189
+ /** An array with the order of questions. For example `[2,0,1]` would indicate that the first question was `trial.questions[2]` (the third item in the `questions` parameter), the second question was `trial.questions[0]`, and the final question was `trial.questions[1]`. This will be encoded as a JSON string when data is saved using the `.json()` or `.csv()` functions. */
190
+ readonly question_order: {
191
+ readonly type: ParameterType.INT;
192
+ readonly array: true;
193
+ };
194
+ };
148
195
  };
149
196
  constructor(jsPsych: JsPsych);
150
197
  trial(display_element: HTMLElement, trial: TrialType<Info>): void;
@@ -153,4 +200,5 @@ declare class SurveyMultiChoicePlugin implements JsPsychPlugin<Info> {
153
200
  private simulate_data_only;
154
201
  private simulate_visual;
155
202
  }
156
- export default SurveyMultiChoicePlugin;
203
+
204
+ export { SurveyMultiChoicePlugin as default };