@jspsych/plugin-survey-likert 1.1.3 → 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.
@@ -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-likert\",\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 likert labels to display for this question. */\n labels: {\n type: ParameterType.STRING,\n array: true,\n pretty_name: \"Labels\",\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 /** 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 /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n pretty_name: \"Scale width\",\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-likert**\n *\n * jsPsych plugin for gathering responses to questions on a likert scale\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/plugins/jspsych-survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\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 for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.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 var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\n\n // save data\n var trial_data = {\n rt: response_time,\n response: question_data,\n question_order: question_order,\n };\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.randomInt(0, q.labels.length - 1);\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 `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":["ParameterType"],"mappings":";;;;AAE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,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;KAChC;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;QAEhB,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,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,6BAA6B,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAa,UAAA,EAAA,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA,EAAA,CAAI,CACzE,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,6BAA6B,CAAC,EAC5D,IAAI,CAAC,EAAE,CACR,CAAC;KACH;;AA9MM,kBAAI,CAAA,IAAA,GAAG,IAAI;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/index.ts"],"sourcesContent":["import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\n\nimport { version } from \"../package.json\";\n\nconst info = <const>{\n name: \"survey-likert\",\n version: version,\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 nested: {\n /** Question prompt. */\n prompt: {\n type: ParameterType.HTML_STRING,\n default: undefined,\n },\n /** Array of likert labels to display for this question. */\n labels: {\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 /** 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 /** If true, the order of the questions in the 'questions' array will be randomized. */\n randomize_question_order: {\n type: ParameterType.BOOL,\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 default: null,\n },\n /** Width of the likert scales in pixels. */\n scale_width: {\n type: ParameterType.INT,\n default: null,\n },\n /** Label of the button to submit responses. */\n button_label: {\n type: ParameterType.STRING,\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 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.COMPLEX,\n nested: {\n identifier: {\n type: ParameterType.STRING,\n },\n response: {\n type:\n ParameterType.STRING |\n ParameterType.INT |\n ParameterType.FLOAT |\n ParameterType.BOOL |\n ParameterType.OBJECT,\n },\n },\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 * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds\n * by selecting a radio button.\n *\n * @author Josh de Leeuw\n * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}\n */\nclass SurveyLikertPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n if (trial.scale_width !== null) {\n var w = trial.scale_width + \"px\";\n } else {\n var w = \"100%\";\n }\n\n var html = \"\";\n // inject CSS for trial\n html += '<style id=\"jspsych-survey-likert-css\">';\n html +=\n \".jspsych-survey-likert-statement { display:block; font-size: 16px; padding-top: 40px; margin-bottom:10px; }\" +\n \".jspsych-survey-likert-opts { list-style:none; width:\" +\n w +\n \"; margin:auto; padding:0 0 35px; display:block; font-size: 14px; line-height:1.1em; }\" +\n \".jspsych-survey-likert-opt-label { line-height: 1.1em; color: #444; }\" +\n \".jspsych-survey-likert-opts:before { content: ''; position:relative; top:11px; /*left:9.5%;*/ display:block; background-color:#efefef; height:4px; width:100%; }\" +\n \".jspsych-survey-likert-opts:last-of-type { border-bottom: 0; }\" +\n \".jspsych-survey-likert-opts li { display:inline-block; /*width:19%;*/ text-align:center; vertical-align: top; }\" +\n \".jspsych-survey-likert-opts li input[type=radio] { display:block; position:relative; top:0; left:50%; margin-left:-6px; }\";\n html += \"</style>\";\n\n // show preamble text\n if (trial.preamble !== null) {\n html +=\n '<div id=\"jspsych-survey-likert-preamble\" class=\"jspsych-survey-likert-preamble\">' +\n trial.preamble +\n \"</div>\";\n }\n\n if (trial.autocomplete) {\n html += '<form id=\"jspsych-survey-likert-form\">';\n } else {\n html += '<form id=\"jspsych-survey-likert-form\" autocomplete=\"off\">';\n }\n\n // add likert scale questions ///\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 for (var i = 0; i < trial.questions.length; i++) {\n var question = trial.questions[question_order[i]];\n // add question\n html += '<label class=\"jspsych-survey-likert-statement\">' + question.prompt + \"</label>\";\n // add options\n var width = 100 / question.labels.length;\n var options_string =\n '<ul class=\"jspsych-survey-likert-opts\" data-name=\"' +\n question.name +\n '\" data-radio-group=\"Q' +\n question_order[i] +\n '\">';\n for (var j = 0; j < question.labels.length; j++) {\n options_string +=\n '<li style=\"width:' +\n width +\n '%\"><label class=\"jspsych-survey-likert-opt-label\"><input type=\"radio\" name=\"Q' +\n question_order[i] +\n '\" value=\"' +\n j +\n '\"';\n if (question.required) {\n options_string += \" required\";\n }\n options_string += \">\" + question.labels[j] + \"</label></li>\";\n }\n options_string += \"</ul>\";\n html += options_string;\n }\n\n // add submit button\n html +=\n '<input type=\"submit\" id=\"jspsych-survey-likert-next\" class=\"jspsych-survey-likert jspsych-btn\" value=\"' +\n trial.button_label +\n '\"></input>';\n\n html += \"</form>\";\n\n display_element.innerHTML = html;\n\n display_element.querySelector(\"#jspsych-survey-likert-form\").addEventListener(\"submit\", (e) => {\n e.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 var matches = display_element.querySelectorAll<HTMLFormElement>(\n \"#jspsych-survey-likert-form .jspsych-survey-likert-opts\"\n );\n for (var index = 0; index < matches.length; index++) {\n var id = matches[index].dataset[\"radioGroup\"];\n var el = display_element.querySelector<HTMLInputElement>(\n 'input[name=\"' + id + '\"]:checked'\n );\n if (el === null) {\n var response: string | number = \"\";\n } else {\n var response: string | number = parseInt(el.value);\n }\n var obje = {};\n if (matches[index].attributes[\"data-name\"].value !== \"\") {\n var name = matches[index].attributes[\"data-name\"].value;\n } else {\n var name = id;\n }\n obje[name] = response;\n Object.assign(question_data, obje);\n }\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.randomInt(0, q.labels.length - 1);\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 `input[type=\"radio\"][name=\"${answers[i][0]}\"][value=\"${answers[i][1]}\"]`\n ),\n ((data.rt - 1000) / answers.length) * (i + 1)\n );\n }\n\n this.jsPsych.pluginAPI.clickTarget(\n display_element.querySelector(\"#jspsych-survey-likert-next\"),\n data.rt\n );\n }\n}\n\nexport default SurveyLikertPlugin;\n"],"names":["version","ParameterType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,MAAM,IAAc,GAAA;AAAA,EAClB,IAAM,EAAA,eAAA;AAAA,WACNA,gBAAA;AAAA,EACA,UAAY,EAAA;AAAA,IAEV,SAAW,EAAA;AAAA,MACT,MAAMC,qBAAc,CAAA,OAAA;AAAA,MACpB,KAAO,EAAA,IAAA;AAAA,MACP,MAAQ,EAAA;AAAA,QAEN,MAAQ,EAAA;AAAA,UACN,MAAMA,qBAAc,CAAA,WAAA;AAAA,UACpB,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,MAAQ,EAAA;AAAA,UACN,MAAMA,qBAAc,CAAA,MAAA;AAAA,UACpB,KAAO,EAAA,IAAA;AAAA,UACP,OAAS,EAAA,KAAA,CAAA;AAAA,SACX;AAAA,QAEA,QAAU,EAAA;AAAA,UACR,MAAMA,qBAAc,CAAA,IAAA;AAAA,UACpB,OAAS,EAAA,KAAA;AAAA,SACX;AAAA,QAEA,IAAM,EAAA;AAAA,UACJ,MAAMA,qBAAc,CAAA,MAAA;AAAA,UACpB,OAAS,EAAA,EAAA;AAAA,SACX;AAAA,OACF;AAAA,KACF;AAAA,IAEA,wBAA0B,EAAA;AAAA,MACxB,MAAMA,qBAAc,CAAA,IAAA;AAAA,MACpB,OAAS,EAAA,KAAA;AAAA,KACX;AAAA,IAEA,QAAU,EAAA;AAAA,MACR,MAAMA,qBAAc,CAAA,WAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAEA,WAAa,EAAA;AAAA,MACX,MAAMA,qBAAc,CAAA,GAAA;AAAA,MACpB,OAAS,EAAA,IAAA;AAAA,KACX;AAAA,IAE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;AAAA,KACP,CAAA;AAAA,GACF;AACF,CAAA;AA9MM,kBAAA,CACG,IAAO,GAAA,IAAA;;;;"}
package/dist/index.d.ts CHANGED
@@ -1,36 +1,33 @@
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-likert";
5
+ readonly version: string;
4
6
  readonly parameters: {
5
7
  /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
6
8
  readonly questions: {
7
9
  readonly type: ParameterType.COMPLEX;
8
10
  readonly array: true;
9
- readonly pretty_name: "Questions";
10
11
  readonly nested: {
11
12
  /** Question prompt. */
12
13
  readonly prompt: {
13
14
  readonly type: ParameterType.HTML_STRING;
14
- readonly pretty_name: "Prompt";
15
15
  readonly default: any;
16
16
  };
17
17
  /** Array of likert labels to display for this question. */
18
18
  readonly labels: {
19
19
  readonly type: ParameterType.STRING;
20
20
  readonly array: true;
21
- readonly pretty_name: "Labels";
22
21
  readonly default: any;
23
22
  };
24
23
  /** Whether or not a response to this question must be given in order to continue. */
25
24
  readonly required: {
26
25
  readonly type: ParameterType.BOOL;
27
- readonly pretty_name: "Required";
28
26
  readonly default: false;
29
27
  };
30
28
  /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
31
29
  readonly name: {
32
30
  readonly type: ParameterType.STRING;
33
- readonly pretty_name: "Question Name";
34
31
  readonly default: "";
35
32
  };
36
33
  };
@@ -38,78 +35,91 @@ declare const info: {
38
35
  /** If true, the order of the questions in the 'questions' array will be randomized. */
39
36
  readonly randomize_question_order: {
40
37
  readonly type: ParameterType.BOOL;
41
- readonly pretty_name: "Randomize Question Order";
42
38
  readonly default: false;
43
39
  };
44
40
  /** HTML-formatted string to display at top of the page above all of the questions. */
45
41
  readonly preamble: {
46
42
  readonly type: ParameterType.HTML_STRING;
47
- readonly pretty_name: "Preamble";
48
43
  readonly default: any;
49
44
  };
50
45
  /** Width of the likert scales in pixels. */
51
46
  readonly scale_width: {
52
47
  readonly type: ParameterType.INT;
53
- readonly pretty_name: "Scale width";
54
48
  readonly default: any;
55
49
  };
56
50
  /** Label of the button to submit responses. */
57
51
  readonly button_label: {
58
52
  readonly type: ParameterType.STRING;
59
- readonly pretty_name: "Button label";
60
53
  readonly default: "Continue";
61
54
  };
62
55
  /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
63
56
  readonly autocomplete: {
64
57
  readonly type: ParameterType.BOOL;
65
- readonly pretty_name: "Allow autocomplete";
66
58
  readonly default: false;
67
59
  };
68
60
  };
61
+ readonly data: {
62
+ /** 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. */
63
+ readonly response: {
64
+ readonly type: ParameterType.COMPLEX;
65
+ readonly nested: {
66
+ readonly identifier: {
67
+ readonly type: ParameterType.STRING;
68
+ };
69
+ readonly response: {
70
+ readonly type: number;
71
+ };
72
+ };
73
+ };
74
+ /** 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. */
75
+ readonly rt: {
76
+ readonly type: ParameterType.INT;
77
+ };
78
+ /** 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. */
79
+ readonly question_order: {
80
+ readonly type: ParameterType.INT;
81
+ readonly array: true;
82
+ };
83
+ };
69
84
  };
70
85
  type Info = typeof info;
71
86
  /**
72
- * **survey-likert**
73
- *
74
- * jsPsych plugin for gathering responses to questions on a likert scale
87
+ * The survey-likert plugin displays a set of questions with Likert scale responses. The participant responds
88
+ * by selecting a radio button.
75
89
  *
76
90
  * @author Josh de Leeuw
77
- * @see {@link https://www.jspsych.org/plugins/jspsych-survey-likert/ survey-likert plugin documentation on jspsych.org}
91
+ * @see {@link https://www.jspsych.org/latest/plugins/survey-likert/ survey-likert plugin documentation on jspsych.org}
78
92
  */
79
93
  declare class SurveyLikertPlugin implements JsPsychPlugin<Info> {
80
94
  private jsPsych;
81
95
  static info: {
82
96
  readonly name: "survey-likert";
97
+ readonly version: string;
83
98
  readonly parameters: {
84
99
  /** Array containing one or more objects with parameters for the question(s) that should be shown on the page. */
85
100
  readonly questions: {
86
101
  readonly type: ParameterType.COMPLEX;
87
102
  readonly array: true;
88
- readonly pretty_name: "Questions";
89
103
  readonly nested: {
90
104
  /** Question prompt. */
91
105
  readonly prompt: {
92
106
  readonly type: ParameterType.HTML_STRING;
93
- readonly pretty_name: "Prompt";
94
107
  readonly default: any;
95
108
  };
96
109
  /** Array of likert labels to display for this question. */
97
110
  readonly labels: {
98
111
  readonly type: ParameterType.STRING;
99
112
  readonly array: true;
100
- readonly pretty_name: "Labels";
101
113
  readonly default: any;
102
114
  };
103
115
  /** Whether or not a response to this question must be given in order to continue. */
104
116
  readonly required: {
105
117
  readonly type: ParameterType.BOOL;
106
- readonly pretty_name: "Required";
107
118
  readonly default: false;
108
119
  };
109
120
  /** Name of the question in the trial data. If no name is given, the questions are named Q0, Q1, etc. */
110
121
  readonly name: {
111
122
  readonly type: ParameterType.STRING;
112
- readonly pretty_name: "Question Name";
113
123
  readonly default: "";
114
124
  };
115
125
  };
@@ -117,34 +127,52 @@ declare class SurveyLikertPlugin implements JsPsychPlugin<Info> {
117
127
  /** If true, the order of the questions in the 'questions' array will be randomized. */
118
128
  readonly randomize_question_order: {
119
129
  readonly type: ParameterType.BOOL;
120
- readonly pretty_name: "Randomize Question Order";
121
130
  readonly default: false;
122
131
  };
123
132
  /** HTML-formatted string to display at top of the page above all of the questions. */
124
133
  readonly preamble: {
125
134
  readonly type: ParameterType.HTML_STRING;
126
- readonly pretty_name: "Preamble";
127
135
  readonly default: any;
128
136
  };
129
137
  /** Width of the likert scales in pixels. */
130
138
  readonly scale_width: {
131
139
  readonly type: ParameterType.INT;
132
- readonly pretty_name: "Scale width";
133
140
  readonly default: any;
134
141
  };
135
142
  /** Label of the button to submit responses. */
136
143
  readonly button_label: {
137
144
  readonly type: ParameterType.STRING;
138
- readonly pretty_name: "Button label";
139
145
  readonly default: "Continue";
140
146
  };
141
147
  /** Setting this to true will enable browser auto-complete or auto-fill for the form. */
142
148
  readonly autocomplete: {
143
149
  readonly type: ParameterType.BOOL;
144
- readonly pretty_name: "Allow autocomplete";
145
150
  readonly default: false;
146
151
  };
147
152
  };
153
+ readonly data: {
154
+ /** 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. */
155
+ readonly response: {
156
+ readonly type: ParameterType.COMPLEX;
157
+ readonly nested: {
158
+ readonly identifier: {
159
+ readonly type: ParameterType.STRING;
160
+ };
161
+ readonly response: {
162
+ readonly type: number;
163
+ };
164
+ };
165
+ };
166
+ /** 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. */
167
+ readonly rt: {
168
+ readonly type: ParameterType.INT;
169
+ };
170
+ /** 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. */
171
+ readonly question_order: {
172
+ readonly type: ParameterType.INT;
173
+ readonly array: true;
174
+ };
175
+ };
148
176
  };
149
177
  constructor(jsPsych: JsPsych);
150
178
  trial(display_element: HTMLElement, trial: TrialType<Info>): void;
@@ -153,4 +181,5 @@ declare class SurveyLikertPlugin implements JsPsychPlugin<Info> {
153
181
  private simulate_data_only;
154
182
  private simulate_visual;
155
183
  }
156
- export default SurveyLikertPlugin;
184
+
185
+ export { SurveyLikertPlugin as default };