jspsych-tangram 0.0.8 → 0.0.10
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/construct/index.browser.js +4572 -3884
- package/dist/construct/index.browser.js.map +1 -1
- package/dist/construct/index.browser.min.js +15 -12
- package/dist/construct/index.browser.min.js.map +1 -1
- package/dist/construct/index.cjs +45 -9
- package/dist/construct/index.cjs.map +1 -1
- package/dist/construct/index.js +45 -9
- package/dist/construct/index.js.map +1 -1
- package/dist/index.cjs +373 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +180 -8
- package/dist/index.js +374 -15
- package/dist/index.js.map +1 -1
- package/dist/nback/index.browser.js +17703 -0
- package/dist/nback/index.browser.js.map +1 -0
- package/dist/nback/index.browser.min.js +42 -0
- package/dist/nback/index.browser.min.js.map +1 -0
- package/dist/nback/index.cjs +395 -0
- package/dist/nback/index.cjs.map +1 -0
- package/dist/nback/index.d.ts +175 -0
- package/dist/nback/index.js +393 -0
- package/dist/nback/index.js.map +1 -0
- package/dist/prep/index.browser.js +4578 -3892
- package/dist/prep/index.browser.js.map +1 -1
- package/dist/prep/index.browser.min.js +16 -13
- package/dist/prep/index.browser.min.js.map +1 -1
- package/dist/prep/index.cjs +46 -12
- package/dist/prep/index.cjs.map +1 -1
- package/dist/prep/index.js +46 -12
- package/dist/prep/index.js.map +1 -1
- package/package.json +9 -3
- package/src/assets/README.md +6 -0
- package/src/assets/images.d.ts +19 -0
- package/src/assets/locked.png +0 -0
- package/src/assets/unlocked.png +0 -0
- package/src/core/components/board/BoardView.tsx +72 -29
- package/src/core/io/InteractionTracker.ts +16 -8
- package/src/core/io/data-tracking.ts +3 -0
- package/src/index.ts +2 -1
- package/src/plugins/tangram-nback/NBackApp.tsx +316 -0
- package/src/plugins/tangram-nback/index.ts +141 -0
- package/tangram-construct.min.js +15 -12
- package/tangram-nback.min.js +42 -0
- package/tangram-prep.min.js +16 -13
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
|
|
2
|
+
import { startNBackTrial, StartNBackTrialParams } from "./NBackApp";
|
|
3
|
+
|
|
4
|
+
const info = {
|
|
5
|
+
name: "tangram-nback",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
parameters: {
|
|
8
|
+
/** Single tangram specification to display */
|
|
9
|
+
tangram: {
|
|
10
|
+
type: ParameterType.COMPLEX,
|
|
11
|
+
default: undefined,
|
|
12
|
+
description: "TangramSpec object defining target shape to display"
|
|
13
|
+
},
|
|
14
|
+
/** Whether this trial is a match (for computing accuracy) */
|
|
15
|
+
isMatch: {
|
|
16
|
+
type: ParameterType.BOOL,
|
|
17
|
+
default: undefined,
|
|
18
|
+
description: "Whether this tangram matches the previous one (optional)"
|
|
19
|
+
},
|
|
20
|
+
/** Whether to show tangram decomposed into individual primitives with borders */
|
|
21
|
+
show_tangram_decomposition: {
|
|
22
|
+
type: ParameterType.BOOL,
|
|
23
|
+
default: false,
|
|
24
|
+
description: "Whether to show tangram decomposed into individual primitives with borders"
|
|
25
|
+
},
|
|
26
|
+
/** HTML content to display above the tangram as instructions */
|
|
27
|
+
instructions: {
|
|
28
|
+
type: ParameterType.STRING,
|
|
29
|
+
default: "",
|
|
30
|
+
description: "HTML content to display above the tangram as instructions"
|
|
31
|
+
},
|
|
32
|
+
/** Text to display on response button */
|
|
33
|
+
button_text: {
|
|
34
|
+
type: ParameterType.STRING,
|
|
35
|
+
default: "Same as previous!",
|
|
36
|
+
description: "Text to display on response button"
|
|
37
|
+
},
|
|
38
|
+
/** Duration to display tangram and accept responses (milliseconds) */
|
|
39
|
+
duration: {
|
|
40
|
+
type: ParameterType.INT,
|
|
41
|
+
default: 3000,
|
|
42
|
+
description: "Duration in milliseconds to display tangram and accept responses"
|
|
43
|
+
},
|
|
44
|
+
/** Callback fired when trial ends */
|
|
45
|
+
onTrialEnd: {
|
|
46
|
+
type: ParameterType.FUNCTION,
|
|
47
|
+
default: undefined,
|
|
48
|
+
description: "Callback when trial completes with full data"
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
data: {
|
|
52
|
+
/** Whether participant clicked the response button before duration expired */
|
|
53
|
+
responded_match: {
|
|
54
|
+
type: ParameterType.BOOL,
|
|
55
|
+
description: "True if participant clicked response button, false otherwise"
|
|
56
|
+
},
|
|
57
|
+
/** Reaction time in milliseconds (NaN if no response or response after duration) */
|
|
58
|
+
rt: {
|
|
59
|
+
type: ParameterType.INT,
|
|
60
|
+
description: "Milliseconds between trial start and button click (NaN if no response or late response)"
|
|
61
|
+
},
|
|
62
|
+
/** Accuracy: 1 if correct, 0 if incorrect, NaN if isMatch not provided */
|
|
63
|
+
accuracy: {
|
|
64
|
+
type: ParameterType.FLOAT,
|
|
65
|
+
description: "1 if response matches isMatch parameter, 0 otherwise (NaN if isMatch not provided)"
|
|
66
|
+
},
|
|
67
|
+
/** Whether response occurred after duration expired */
|
|
68
|
+
responded_after_duration: {
|
|
69
|
+
type: ParameterType.BOOL,
|
|
70
|
+
description: "True if button clicked after duration expired, false otherwise"
|
|
71
|
+
},
|
|
72
|
+
/** Time of late response (NaN if no late response) */
|
|
73
|
+
rt_after_duration: {
|
|
74
|
+
type: ParameterType.INT,
|
|
75
|
+
description: "Milliseconds between trial start and late button click (NaN if no late response)"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
citations: ""
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type Info = typeof info;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* **tangram-nback**
|
|
85
|
+
*
|
|
86
|
+
* A jsPsych plugin for n-back matching trials displaying a single tangram
|
|
87
|
+
* with a response button.
|
|
88
|
+
*
|
|
89
|
+
* @author Justin Yang & Sean Paul Anderson
|
|
90
|
+
* @see {@link https://github.com/cogtoolslab/tangram_construction.git/tree/main/experiments/jspsych-tangram-prep}
|
|
91
|
+
*/
|
|
92
|
+
class TangramNBackPlugin implements JsPsychPlugin<Info> {
|
|
93
|
+
static info = info;
|
|
94
|
+
|
|
95
|
+
constructor(private jsPsych: JsPsych) {}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Launches the trial by invoking startNBackTrial
|
|
99
|
+
* with the display element, parameters, and jsPsych instance.
|
|
100
|
+
*/
|
|
101
|
+
trial(display_element: HTMLElement, trial: TrialType<Info>) {
|
|
102
|
+
// Wrap onTrialEnd to handle React cleanup and jsPsych trial completion
|
|
103
|
+
const wrappedOnTrialEnd = (data: any) => {
|
|
104
|
+
// Call user-provided callback if exists
|
|
105
|
+
if (trial.onTrialEnd) {
|
|
106
|
+
trial.onTrialEnd(data);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Clean up React first (before clearing DOM)
|
|
110
|
+
const reactContext = (display_element as any).__reactContext;
|
|
111
|
+
if (reactContext?.root) {
|
|
112
|
+
reactContext.root.unmount();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Clear display after React cleanup
|
|
116
|
+
display_element.innerHTML = '';
|
|
117
|
+
|
|
118
|
+
// Finish jsPsych trial with data
|
|
119
|
+
this.jsPsych.finishTrial(data);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Create parameter object for wrapper
|
|
123
|
+
const params: StartNBackTrialParams = {
|
|
124
|
+
tangram: trial.tangram,
|
|
125
|
+
isMatch: trial.isMatch,
|
|
126
|
+
show_tangram_decomposition: trial.show_tangram_decomposition,
|
|
127
|
+
instructions: trial.instructions,
|
|
128
|
+
button_text: trial.button_text,
|
|
129
|
+
duration: trial.duration,
|
|
130
|
+
onTrialEnd: wrappedOnTrialEnd
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// Use React wrapper to start the trial
|
|
134
|
+
const { root, display_element: element, jsPsych } = startNBackTrial(display_element, params, this.jsPsych);
|
|
135
|
+
|
|
136
|
+
// Store React context for cleanup
|
|
137
|
+
(element as any).__reactContext = { root, jsPsych };
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default TangramNBackPlugin;
|