Skip to content

Commit b98a3c3

Browse files
committed
core -> jsPsych7 + modernish js
1 parent 2fcdb1a commit b98a3c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+646
-453
lines changed

apps/dev/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"@jspsych/plugin-fullscreen": "^1.1.2",
2020
"@pcllab/plugin-audio-response": "workspace:*",
2121
"@pcllab/plugin-free-recall": "workspace:*",
22+
"@pcllab/plugin-core": "workspace:*",
2223
"jspsych": "^7.3.2"
2324
}
2425
}

apps/dev/src/experiment.ts

+36-19
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,44 @@ import "jspsych/css/jspsych.css";
22
import "./style.css";
33

44
import { initJsPsych } from "jspsych";
5-
import audioResponse from "@pcllab/plugin-audio-response";
6-
import freeRecall from "@pcllab/plugin-free-recall";
5+
import pcllabAudioResponse from "@pcllab/plugin-audio-response";
6+
import pcllabFreeRecall from "@pcllab/plugin-free-recall";
7+
import pcllabCore from "@pcllab/plugin-core";
78

8-
const jsPsych = initJsPsych({ on_finish: () => {
9-
jsPsych.data.get()
10-
} });
9+
const jsPsych = initJsPsych({
10+
on_finish: () => {
11+
jsPsych.data.displayData();
12+
},
13+
});
1114

12-
const start = {
13-
type: freeRecall,
15+
const studyTask = {
16+
type: pcllabCore,
17+
stimuli: [
18+
{
19+
//show the current iteration's cue and target
20+
text: `<div style="text-align: center; font-weight: 400; font-size: 24px">cue -- target</div>`,
21+
},
22+
],
23+
response_count: 0,
24+
isi_time: 500,
25+
cue_count: 0,
26+
maximum_time: 1000 * 5,
1427
};
1528

16-
const trial = {
17-
type: audioResponse,
18-
prompt: "<div>this is the prompt</div>",
19-
stimulus: "./audio.m4a",
20-
button: {
21-
choices: ["one", "two"],
22-
},
23-
keyboard: {},
24-
response_allowed_while_playing: false,
25-
show_repeat_button: true,
26-
};
29+
// const start = {
30+
// type: pcllabFreeRecall,
31+
// };
32+
33+
// const trial = {
34+
// type: pcllabAudioResponse,
35+
// prompt: "<div>this is the prompt</div>",
36+
// stimulus: "./audio.m4a",
37+
// button: {
38+
// choices: ["one", "two"],
39+
// },
40+
// keyboard: {},
41+
// response_allowed_while_playing: false,
42+
// show_repeat_button: true,
43+
// };
2744

28-
jsPsych.run([start, trial]);
45+
jsPsych.run([studyTask]);

package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@
2323
"engines": {
2424
"node": ">=14.0.0"
2525
},
26-
"packageManager": "[email protected]"
26+
"packageManager": "[email protected]",
27+
"pnpm": {
28+
"patchedDependencies": {
29+
30+
31+
}
32+
}
2733
}

packages/plugin-core/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Core
1+
# plugin-core
22

33
This plugin handles most of the core procedures of an experiment. The tasks that tasks that it can do include (but are not limited to) showing instructions, short-answer tasks, cued-recall tasks, ratings tasks, etc.
44

@@ -133,7 +133,7 @@ function list_data(data) {
133133
jsPsych.init({
134134
...
135135
timeline: [{
136-
type: 'pcllab-core',
136+
type: pcllabCore,
137137
...
138138
done_callback: list_data
139139
}]
@@ -155,7 +155,7 @@ The callback `feedback_html` provides a way to show feedback after a screen give
155155
156156
```javascript
157157
const trial = {
158-
type: 'pcllab-core',
158+
type: pcllabCore,
159159
stimuli: [
160160
{
161161
cue: 'Should pineapples be on pizza',
@@ -238,7 +238,7 @@ In this example, need to note how this.instructions is set up (it's calling in i
238238
239239
```javascript
240240
const lookUp = {
241-
type: "pcllab-core",
241+
type: pcllabCore,
242242
stimuli: [this.instructions["look-up"]],
243243
response_count: 0,
244244
show_button: true,
@@ -261,7 +261,7 @@ Also explain how to show individual stimuli
261261
262262
```javascript
263263
const studyItemsTrial = {
264-
type: "pcllab-core",
264+
type: pcllabCore,
265265
stimuli: [
266266
{ response_type: "study_items", cue: "Kirvis", target: "Axe" },
267267
{ response_type: "study_items", cue: "Marco", target: "Polo" },
@@ -278,7 +278,7 @@ Explain how cued recall is done. Word as cue, or a question as cue. Box size dif
278278
279279
```javascript
280280
const cuedRecallTrial = {
281-
type: "pcllab-core",
281+
type: pcllabCore,
282282
stimuli: [
283283
{ response_type: "study_items", cue: "A", target: "Apple" },
284284
{

packages/plugin-core/package.json

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pcllab/plugin-core",
3-
"version": "0.1.0",
3+
"version": "0.0.1",
44
"type": "module",
55
"types": "dist/index.d.ts",
66
"main": "dist/index.js",
@@ -29,14 +29,20 @@
2929
},
3030
"homepage": "https://github.com/PCLLAB/plugins/tree/main/packages/plugin-core#readme",
3131
"devDependencies": {
32+
"@types/jquery": "^3.5.16",
3233
"config": "workspace:*",
3334
"tsconfig": "workspace:*",
3435
"tsup": "^7.1.0"
3536
},
3637
"dependencies": {
37-
"jspsych": "^7.3.3"
38+
"custom-event": "^1.0.1",
39+
"dragula": "^3.7.3",
40+
"jquery": "^3.7.0",
41+
"jspsych": "^7.3.3",
42+
"string-similarity-js": "^2.1.4",
43+
"uuid": "^9.0.0"
3844
},
3945
"publishConfig": {
4046
"access": "public"
4147
}
42-
}
48+
}

packages/plugin-core/src/buttons.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const getButtonColorClass = require("./constants").getButtonColorClass;
2-
class NextButton {
1+
import $ from "jquery";
2+
import { getButtonColorClass } from "./constants";
3+
export class NextButton {
34
constructor(text) {
45
const buttonText = text || "Next";
56

@@ -10,9 +11,7 @@ class NextButton {
1011
}
1112
}
1213

13-
module.exports.NextButton = NextButton;
14-
15-
class IDKButton {
14+
export class IDKButton {
1615
constructor(dataInstance) {
1716
this._data = dataInstance;
1817

@@ -40,9 +39,7 @@ class IDKButton {
4039
}
4140
}
4241

43-
module.exports.IDKButton = IDKButton;
44-
45-
class RepeatButton {
42+
export class RepeatButton {
4643
constructor(dataInstance) {
4744
this._data = dataInstance;
4845

@@ -63,5 +60,3 @@ class RepeatButton {
6360
};
6461
}
6562
}
66-
67-
module.exports.RepeatButton = RepeatButton;

packages/plugin-core/src/constants.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
module.exports.RESPONSE_ALIGNMENT = {
1+
export const RESPONSE_ALIGNMENT = {
22
left: "left",
33
center: "center",
44
right: "right",
55
};
66

7-
module.exports.CUE_ALIGNMENT = {
7+
export const CUE_ALIGNMENT = {
88
horizontal: "horizontal",
99
vertical: "vertical",
1010
};
1111

12-
module.exports.SCORING_STRATEGY = {
12+
export const SCORING_STRATEGY = {
1313
dice: "dice",
1414
exact: "exact",
1515
ultron: "ultron",
1616
};
1717

18-
module.exports.INPUT_SIZE = {
18+
export const INPUT_SIZE = {
1919
small: "small",
2020
medium: "medium",
2121
large: "large",
2222
xlarge: "xlarge",
2323
};
2424

25-
module.exports.RESPONSE_TYPE = {
25+
export const RESPONSE_TYPE = {
2626
input: "input",
2727
horizontal_input: "horizontal_input",
2828
study_items: "study_items",
@@ -35,10 +35,10 @@ module.exports.RESPONSE_TYPE = {
3535

3636
let buttonColorClass = "btn-primary";
3737

38-
module.exports.getButtonColorClass = () => {
38+
export const getButtonColorClass = () => {
3939
return buttonColorClass;
4040
};
4141

42-
module.exports.setButtonColorClass = (newButtonClass) => {
42+
export const setButtonColorClass = (newButtonClass) => {
4343
buttonColorClass = newButtonClass;
4444
};

0 commit comments

Comments
 (0)