jspsych-tangram 0.0.16 → 0.0.18
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 +23 -5
- package/dist/construct/index.browser.js.map +1 -1
- package/dist/construct/index.browser.min.js +8 -8
- package/dist/construct/index.browser.min.js.map +1 -1
- package/dist/construct/index.cjs +23 -5
- package/dist/construct/index.cjs.map +1 -1
- package/dist/construct/index.js +23 -5
- package/dist/construct/index.js.map +1 -1
- package/dist/grid/index.browser.js +17855 -0
- package/dist/grid/index.browser.js.map +1 -0
- package/dist/grid/index.browser.min.js +47 -0
- package/dist/grid/index.browser.min.js.map +1 -0
- package/dist/grid/index.cjs +547 -0
- package/dist/grid/index.cjs.map +1 -0
- package/dist/grid/index.d.ts +174 -0
- package/dist/grid/index.js +545 -0
- package/dist/grid/index.js.map +1 -0
- package/dist/index.cjs +548 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +187 -16
- package/dist/index.js +549 -15
- package/dist/index.js.map +1 -1
- package/dist/prep/index.browser.js +23 -5
- package/dist/prep/index.browser.js.map +1 -1
- package/dist/prep/index.browser.min.js +6 -6
- package/dist/prep/index.browser.min.js.map +1 -1
- package/dist/prep/index.cjs +23 -5
- package/dist/prep/index.cjs.map +1 -1
- package/dist/prep/index.js +23 -5
- package/dist/prep/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/components/board/GameBoard.tsx +12 -0
- package/src/core/io/InteractionTracker.ts +19 -7
- package/src/core/io/data-tracking.ts +5 -0
- package/src/index.ts +2 -1
- package/src/plugins/tangram-grid/GridApp.tsx +522 -0
- package/src/plugins/tangram-grid/index.ts +154 -0
- package/tangram-construct.min.js +8 -8
- package/tangram-prep.min.js +6 -6
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from "jspsych";
|
|
2
|
+
import { startGridTrial, StartGridTrialParams } from "./GridApp";
|
|
3
|
+
|
|
4
|
+
const info = {
|
|
5
|
+
name: "tangram-grid",
|
|
6
|
+
version: "1.0.0",
|
|
7
|
+
parameters: {
|
|
8
|
+
/** Array of tangram specifications to display in the grid */
|
|
9
|
+
tangrams: {
|
|
10
|
+
type: ParameterType.COMPLEX,
|
|
11
|
+
default: undefined,
|
|
12
|
+
description: "Array of TangramSpec objects to display in the grid"
|
|
13
|
+
},
|
|
14
|
+
/** Number of rows in the grid */
|
|
15
|
+
n_rows: {
|
|
16
|
+
type: ParameterType.INT,
|
|
17
|
+
default: 1,
|
|
18
|
+
description: "Number of rows in the tangram grid"
|
|
19
|
+
},
|
|
20
|
+
/** Number of columns in the grid */
|
|
21
|
+
n_cols: {
|
|
22
|
+
type: ParameterType.INT,
|
|
23
|
+
default: 1,
|
|
24
|
+
description: "Number of columns in the tangram grid"
|
|
25
|
+
},
|
|
26
|
+
/** Prompt text displayed above the text input */
|
|
27
|
+
prompt_text: {
|
|
28
|
+
type: ParameterType.STRING,
|
|
29
|
+
default: "",
|
|
30
|
+
description: "Text displayed above the text input field"
|
|
31
|
+
},
|
|
32
|
+
/** Label for the submit button */
|
|
33
|
+
button_text: {
|
|
34
|
+
type: ParameterType.STRING,
|
|
35
|
+
default: "Submit",
|
|
36
|
+
description: "Text displayed on the submit button"
|
|
37
|
+
},
|
|
38
|
+
/** Whether to show tangrams decomposed into primitives */
|
|
39
|
+
show_tangram_decomposition: {
|
|
40
|
+
type: ParameterType.BOOL,
|
|
41
|
+
default: false,
|
|
42
|
+
description:
|
|
43
|
+
"Whether to show tangrams decomposed into individual primitives"
|
|
44
|
+
},
|
|
45
|
+
/** Whether to use distinct colors for each primitive type */
|
|
46
|
+
use_primitive_colors: {
|
|
47
|
+
type: ParameterType.BOOL,
|
|
48
|
+
default: false,
|
|
49
|
+
description:
|
|
50
|
+
"Whether each primitive shape type should have its own distinct color"
|
|
51
|
+
},
|
|
52
|
+
/** Indices mapping primitives to colors */
|
|
53
|
+
primitive_color_indices: {
|
|
54
|
+
type: ParameterType.OBJECT,
|
|
55
|
+
default: [0, 1, 2, 3, 4],
|
|
56
|
+
description:
|
|
57
|
+
"Array of 5 integers indexing into primitiveColors array, mapping " +
|
|
58
|
+
"[square, smalltriangle, parallelogram, medtriangle, largetriangle] " +
|
|
59
|
+
"to colors"
|
|
60
|
+
},
|
|
61
|
+
/** Callback fired when trial ends */
|
|
62
|
+
onTrialEnd: {
|
|
63
|
+
type: ParameterType.FUNCTION,
|
|
64
|
+
default: undefined,
|
|
65
|
+
description: "Callback when trial completes with full data"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
data: {
|
|
69
|
+
/** The text response entered by the participant */
|
|
70
|
+
response: {
|
|
71
|
+
type: ParameterType.STRING,
|
|
72
|
+
description: "The text response entered by the participant"
|
|
73
|
+
},
|
|
74
|
+
/** Reaction time from trial start to submit button click */
|
|
75
|
+
rt: {
|
|
76
|
+
type: ParameterType.INT,
|
|
77
|
+
description: "Time in milliseconds from trial start to submit"
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
citations: ""
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type Info = typeof info;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* **tangram-grid**
|
|
87
|
+
*
|
|
88
|
+
* A jsPsych plugin that displays a grid of tangrams with a text input field
|
|
89
|
+
* and submit button for collecting free-text responses.
|
|
90
|
+
*
|
|
91
|
+
* @author Sean Paul Anderson & Justin Yang
|
|
92
|
+
* @see {@link https://github.com/cogtoolslab/tangram_construction.git}
|
|
93
|
+
*/
|
|
94
|
+
class TangramGridPlugin implements JsPsychPlugin<Info> {
|
|
95
|
+
static info = info;
|
|
96
|
+
|
|
97
|
+
constructor(private jsPsych: JsPsych) {}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Launches the trial by invoking startGridTrial with the display element,
|
|
101
|
+
* parameters, and jsPsych instance.
|
|
102
|
+
*
|
|
103
|
+
* REQUIRES: display_element is a valid HTMLElement, trial contains valid
|
|
104
|
+
* parameters
|
|
105
|
+
* MODIFIES: display_element (renders React component)
|
|
106
|
+
* EFFECTS: Starts the grid trial and handles cleanup on completion
|
|
107
|
+
*/
|
|
108
|
+
trial(display_element: HTMLElement, trial: TrialType<Info>) {
|
|
109
|
+
// Wrap onTrialEnd to handle React cleanup and jsPsych trial completion
|
|
110
|
+
const wrappedOnTrialEnd = (data: any) => {
|
|
111
|
+
// Call user-provided callback if exists
|
|
112
|
+
if (trial.onTrialEnd) {
|
|
113
|
+
trial.onTrialEnd(data);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Clean up React first (before clearing DOM)
|
|
117
|
+
const reactContext = (display_element as any).__reactContext;
|
|
118
|
+
if (reactContext?.root) {
|
|
119
|
+
reactContext.root.unmount();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Clear display after React cleanup
|
|
123
|
+
display_element.innerHTML = "";
|
|
124
|
+
|
|
125
|
+
// Finish jsPsych trial with data
|
|
126
|
+
this.jsPsych.finishTrial(data);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Create parameter object for wrapper
|
|
130
|
+
const params: StartGridTrialParams = {
|
|
131
|
+
tangrams: trial.tangrams,
|
|
132
|
+
n_rows: trial.n_rows,
|
|
133
|
+
n_cols: trial.n_cols,
|
|
134
|
+
prompt_text: trial.prompt_text,
|
|
135
|
+
button_text: trial.button_text,
|
|
136
|
+
show_tangram_decomposition: trial.show_tangram_decomposition,
|
|
137
|
+
usePrimitiveColors: trial.use_primitive_colors,
|
|
138
|
+
primitiveColorIndices: trial.primitive_color_indices,
|
|
139
|
+
onTrialEnd: wrappedOnTrialEnd
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Use React wrapper to start the trial
|
|
143
|
+
const { root, display_element: element, jsPsych } = startGridTrial(
|
|
144
|
+
display_element,
|
|
145
|
+
params,
|
|
146
|
+
this.jsPsych
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
// Store React context for cleanup
|
|
150
|
+
(element as any).__reactContext = { root, jsPsych };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export default TangramGridPlugin;
|