Setup initial survey plugin draft

This commit is contained in:
bjoluc 2021-10-07 00:11:17 +02:00
parent c671ad717a
commit 347e7f6765
8 changed files with 200 additions and 0 deletions

53
package-lock.json generated
View File

@ -2562,6 +2562,10 @@
"resolved": "packages/plugin-serial-reaction-time-mouse",
"link": true
},
"node_modules/@jspsych/plugin-survey": {
"resolved": "packages/plugin-survey",
"link": true
},
"node_modules/@jspsych/plugin-survey-html-form": {
"resolved": "packages/plugin-survey-html-form",
"link": true
@ -9654,6 +9658,11 @@
"node": ">=6"
}
},
"node_modules/knockout": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/knockout/-/knockout-3.5.1.tgz",
"integrity": "sha512-wRJ9I4az0QcsH7A4v4l0enUpkS++MBx0BnL/68KaLzJg7x1qmbjSlwEoCNol7KTYZ+pmtI7Eh2J0Nu6/2Z5J/Q=="
},
"node_modules/last-run": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/last-run/-/last-run-1.1.1.tgz",
@ -13116,6 +13125,14 @@
"node": ">=8"
}
},
"node_modules/survey-knockout": {
"version": "1.8.70",
"resolved": "https://registry.npmjs.org/survey-knockout/-/survey-knockout-1.8.70.tgz",
"integrity": "sha512-iYfgFpoyYXPHcWxps1Wo2QuUmIJ78FDFkfgowiuJR18T5GPf8vISEq3UGlwoyEda0rm8kPcOySXPRJ+1CsfBsw==",
"dependencies": {
"knockout": "^3.5.1"
}
},
"node_modules/sver-compat": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/sver-compat/-/sver-compat-1.5.0.tgz",
@ -14949,6 +14966,21 @@
"jspsych": ">=7.0.0"
}
},
"packages/plugin-survey": {
"name": "@jspsych/plugin-survey",
"version": "0.1.0",
"license": "MIT",
"dependencies": {
"survey-knockout": "^1.8.70"
},
"devDependencies": {
"@jspsych/config": "^1.0.0",
"@jspsych/test-utils": "^1.0.0"
},
"peerDependencies": {
"jspsych": ">=7.0.0"
}
},
"packages/plugin-survey-html-form": {
"name": "@jspsych/plugin-survey-html-form",
"version": "1.0.0",
@ -17140,6 +17172,14 @@
"@jspsych/test-utils": "^1.0.0"
}
},
"@jspsych/plugin-survey": {
"version": "file:packages/plugin-survey",
"requires": {
"@jspsych/config": "^1.0.0",
"@jspsych/test-utils": "^1.0.0",
"survey-knockout": "*"
}
},
"@jspsych/plugin-survey-html-form": {
"version": "file:packages/plugin-survey-html-form",
"requires": {
@ -22729,6 +22769,11 @@
"resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz",
"integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w=="
},
"knockout": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/knockout/-/knockout-3.5.1.tgz",
"integrity": "sha512-wRJ9I4az0QcsH7A4v4l0enUpkS++MBx0BnL/68KaLzJg7x1qmbjSlwEoCNol7KTYZ+pmtI7Eh2J0Nu6/2Z5J/Q=="
},
"last-run": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/last-run/-/last-run-1.1.1.tgz",
@ -25393,6 +25438,14 @@
}
}
},
"survey-knockout": {
"version": "1.8.70",
"resolved": "https://registry.npmjs.org/survey-knockout/-/survey-knockout-1.8.70.tgz",
"integrity": "sha512-iYfgFpoyYXPHcWxps1Wo2QuUmIJ78FDFkfgowiuJR18T5GPf8vISEq3UGlwoyEda0rm8kPcOySXPRJ+1CsfBsw==",
"requires": {
"knockout": "^3.5.1"
}
},
"sver-compat": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/sver-compat/-/sver-compat-1.5.0.tgz",

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<script src="../jspsych/dist/index.browser.js"></script>
<script src="./dist/index.browser.js"></script>
<link rel="stylesheet" href="../jspsych/css/jspsych.css"></script>
</head>
<body></body>
<script type="text/javascript">
var jsPsych = initJsPsych({
on_finish: function() {
jsPsych.data.displayData();
}
});
jsPsych.run([{
type: jsPsychSurvey,
}]);
</script>
</html>

View File

@ -0,0 +1 @@
module.exports = require("@jspsych/config/jest").makePackageConfig(__dirname);

View File

@ -0,0 +1,46 @@
{
"name": "@jspsych/plugin-survey",
"version": "0.1.0",
"description": "A jsPsych plugin for complex surveys",
"type": "module",
"main": "dist/index.cjs",
"exports": {
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"typings": "dist/index.d.ts",
"unpkg": "dist/index.browser.min.js",
"files": [
"src",
"dist"
],
"source": "src/index.ts",
"scripts": {
"test": "jest",
"test:watch": "npm test -- --watch",
"tsc": "tsc",
"build": "rollup --config",
"build:watch": "npm run build -- --watch"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jspsych/jsPsych.git",
"directory": "packages/plugin-survey"
},
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/jspsych/jsPsych/issues"
},
"homepage": "https://www.jspsych.org/latest/plugins/survey",
"peerDependencies": {
"jspsych": ">=7.0.0"
},
"devDependencies": {
"@jspsych/config": "^1.0.0",
"@jspsych/test-utils": "^1.0.0"
},
"dependencies": {
"survey-knockout": "^1.8.70"
}
}

View File

@ -0,0 +1,3 @@
import { makeRollupConfig } from "@jspsych/config/rollup";
export default makeRollupConfig("jsPsychSurvey");

View File

@ -0,0 +1,15 @@
import { startTimeline } from "@jspsych/test-utils";
import survey from ".";
describe("survey plugin", () => {
test("", async () => {
const { displayElement, expectRunning, getData } = await startTimeline([
{
type: survey,
},
]);
await expectRunning();
});
});

View File

@ -0,0 +1,53 @@
import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
import { StylesManager, Survey } from "survey-knockout";
const info = <const>{
name: "survey",
parameters: {},
};
type Info = typeof info;
/**
* **survey**
*
*
*
* @author
* @see {@link https://www.jspsych.org/plugins/survey/ survey plugin documentation on jspsych.org}
*/
class SurveyPlugin implements JsPsychPlugin<Info> {
static info = info;
constructor(private jsPsych: JsPsych) {}
applyStyles() {
StylesManager.applyTheme("bootstrap");
// https://surveyjs.io/Examples/Library/?id=custom-theme
}
trial(display_element: HTMLElement, trial: TrialType<Info>) {
this.applyStyles();
// https://surveyjs.io/Documentation/Library#survey-objects
const survey = new Survey();
const page = survey.addNewPage("page1");
const question = page.addNewQuestion("text");
question.name = "q1";
question.title = "Question 1";
survey.render(display_element);
const startTime = performance.now();
survey.onComplete.add((sender) => {
// display_element.innerHTML = "";
this.jsPsych.finishTrial({
rt: Math.round(performance.now() - startTime),
response: sender.data,
});
});
}
}
export default SurveyPlugin;

View File

@ -0,0 +1,7 @@
{
"extends": "@jspsych/config/tsconfig.core.json",
"compilerOptions": {
"baseUrl": "."
},
"include": ["src"]
}