Skip to content

Commit

Permalink
localize prettier to apply only to lines
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriechang committed Dec 6, 2024
1 parent df588e9 commit a28ca04
Show file tree
Hide file tree
Showing 58 changed files with 1,650 additions and 1,594 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
"turbo": "^1.6.3"
},
"prettier": {
"printWidth": 100,
"singleQuote": true
"printWidth": 100
},
"importSort": {
".ts, .js, .mjs, .cjs": {
Expand Down
1 change: 1 addition & 0 deletions packages/config/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const makeConfig = ({
plugins: [
externals(),
modify({
// prettier-ignore
find: /'__CITATIONS__'/g,
replace: JSON.stringify(citationData, null, 2),
}),
Expand Down
39 changes: 20 additions & 19 deletions packages/extension-mouse-tracking/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from 'jspsych';
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from "jspsych";

import { version } from '../package.json';
import { version } from "../package.json";

interface InitializeParameters {
/**
Expand Down Expand Up @@ -31,7 +31,7 @@ interface OnStartParameters {
*/
class MouseTrackingExtension implements JsPsychExtension {
static info: JsPsychExtensionInfo = {
name: 'mouse-tracking',
name: "mouse-tracking",
version: version,
data: {
/**
Expand Down Expand Up @@ -95,6 +95,7 @@ class MouseTrackingExtension implements JsPsychExtension {
},
},
},
// prettier-ignore
citations: '__CITATIONS__',
};

Expand All @@ -121,7 +122,7 @@ class MouseTrackingExtension implements JsPsychExtension {
this.currentTrialTargets = new Map();
this.currentTrialSelectors = params.targets || [];
this.lastSampleTime = null;
this.eventsToTrack = params.events || ['mousemove'];
this.eventsToTrack = params.events || ["mousemove"];

this.domObserver.observe(this.jsPsych.getDisplayElement(), { childList: true });
};
Expand All @@ -131,28 +132,28 @@ class MouseTrackingExtension implements JsPsychExtension {
this.currentTrialStartTime = performance.now();

// start data collection
if (this.eventsToTrack.includes('mousemove')) {
window.addEventListener('mousemove', this.mouseMoveEventHandler);
if (this.eventsToTrack.includes("mousemove")) {
window.addEventListener("mousemove", this.mouseMoveEventHandler);
}
if (this.eventsToTrack.includes('mousedown')) {
window.addEventListener('mousedown', this.mouseDownEventHandler);
if (this.eventsToTrack.includes("mousedown")) {
window.addEventListener("mousedown", this.mouseDownEventHandler);
}
if (this.eventsToTrack.includes('mouseup')) {
window.addEventListener('mouseup', this.mouseUpEventHandler);
if (this.eventsToTrack.includes("mouseup")) {
window.addEventListener("mouseup", this.mouseUpEventHandler);
}
};

on_finish = () => {
this.domObserver.disconnect();

if (this.eventsToTrack.includes('mousemove')) {
window.removeEventListener('mousemove', this.mouseMoveEventHandler);
if (this.eventsToTrack.includes("mousemove")) {
window.removeEventListener("mousemove", this.mouseMoveEventHandler);
}
if (this.eventsToTrack.includes('mousedown')) {
window.removeEventListener('mousedown', this.mouseDownEventHandler);
if (this.eventsToTrack.includes("mousedown")) {
window.removeEventListener("mousedown", this.mouseDownEventHandler);
}
if (this.eventsToTrack.includes('mouseup')) {
window.removeEventListener('mouseup', this.mouseUpEventHandler);
if (this.eventsToTrack.includes("mouseup")) {
window.removeEventListener("mouseup", this.mouseUpEventHandler);
}

return {
Expand All @@ -170,22 +171,22 @@ class MouseTrackingExtension implements JsPsychExtension {
event_time - this.lastSampleTime >= this.minimumSampleTime
) {
this.lastSampleTime = event_time;
this.currentTrialData.push({ x, y, t, event: 'mousemove' });
this.currentTrialData.push({ x, y, t, event: "mousemove" });
}
};

private mouseUpEventHandler = ({ clientX: x, clientY: y }: MouseEvent) => {
const event_time = performance.now();
const t = Math.round(event_time - this.currentTrialStartTime);

this.currentTrialData.push({ x, y, t, event: 'mouseup' });
this.currentTrialData.push({ x, y, t, event: "mouseup" });
};

private mouseDownEventHandler = ({ clientX: x, clientY: y }: MouseEvent) => {
const event_time = performance.now();
const t = Math.round(event_time - this.currentTrialStartTime);

this.currentTrialData.push({ x, y, t, event: 'mousedown' });
this.currentTrialData.push({ x, y, t, event: "mousedown" });
};

private mutationObserverCallback = (mutationsList, observer) => {
Expand Down
19 changes: 10 additions & 9 deletions packages/extension-record-video/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import autoBind from 'auto-bind';
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from 'jspsych';
import autoBind from "auto-bind";
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from "jspsych";

import { version } from '../package.json';
import { version } from "../package.json";

/**
* https://www.jspsych.org/latest/extensions/record-video/
*/
class RecordVideoExtension implements JsPsychExtension {
static info: JsPsychExtensionInfo = {
name: 'record-video',
name: "record-video",
version: version,
data: {
/** [Base 64 encoded](https://developer.mozilla.org/en-US/docs/Glossary/Base64) representation of the video data. */
record_video_data: {
type: ParameterType.STRING,
},
},
// prettier-ignore
citations: '__CITATIONS__',
};

Expand All @@ -40,12 +41,12 @@ class RecordVideoExtension implements JsPsychExtension {

if (!this.recorder) {
console.warn(
'The record-video extension is trying to start but the camera is not initialized. Do you need to run the initialize-camera plugin?'
"The record-video extension is trying to start but the camera is not initialized. Do you need to run the initialize-camera plugin?"
);
return;
}

this.recorder.addEventListener('dataavailable', this.handleOnDataAvailable);
this.recorder.addEventListener("dataavailable", this.handleOnDataAvailable);
};

on_load = () => {
Expand All @@ -69,7 +70,7 @@ class RecordVideoExtension implements JsPsychExtension {

private handleOnDataAvailable(event) {
if (event.data.size > 0) {
console.log('chunks added');
console.log("chunks added");
this.recordedChunks.push(event.data);
if (this.trialComplete) {
this.updateData();
Expand All @@ -82,8 +83,8 @@ class RecordVideoExtension implements JsPsychExtension {
type: this.recorder.mimeType,
});
const reader = new FileReader();
reader.addEventListener('load', () => {
const base64 = (reader.result as string).split(',')[1];
reader.addEventListener("load", () => {
const base64 = (reader.result as string).split(",")[1];
this.currentTrialData.record_video_data = base64;
if (this.onUpdateCallback) {
this.onUpdateCallback();
Expand Down
25 changes: 13 additions & 12 deletions packages/extension-webgazer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from 'jspsych';
import { JsPsych, JsPsychExtension, JsPsychExtensionInfo, ParameterType } from "jspsych";

import { version } from '../package.json';
import { version } from "../package.json";

// we have to add webgazer to the global window object because webgazer attaches itself to
// the window when it loads
Expand Down Expand Up @@ -46,7 +46,7 @@ interface OnStartParameters {
*/
class WebGazerExtension implements JsPsychExtension {
static info: JsPsychExtensionInfo = {
name: 'webgazer',
name: "webgazer",
version: version,
data: {
/** An array of objects containing gaze data for the trial. Each object has an `x`, a `y`, and a `t` property. The `x` and
Expand Down Expand Up @@ -91,6 +91,7 @@ class WebGazerExtension implements JsPsychExtension {
},
},
},
// prettier-ignore
citations: '__CITATIONS__',
};

Expand Down Expand Up @@ -127,13 +128,13 @@ class WebGazerExtension implements JsPsychExtension {
this.domObserver = new MutationObserver(this.mutationObserverCallback);

return new Promise((resolve, reject) => {
if (typeof webgazer === 'undefined') {
if (typeof webgazer === "undefined") {
if (window.webgazer) {
this.webgazer = window.webgazer;
} else {
reject(
new Error(
'Webgazer extension failed to initialize. webgazer.js not loaded. Load webgazer.js before calling initJsPsych()'
"Webgazer extension failed to initialize. webgazer.js not loaded. Load webgazer.js before calling initJsPsych()"
)
);
}
Expand Down Expand Up @@ -219,9 +220,9 @@ class WebGazerExtension implements JsPsychExtension {

start = () => {
return new Promise<void>((resolve, reject) => {
if (typeof this.webgazer == 'undefined') {
if (typeof this.webgazer == "undefined") {
const error =
'Failed to start webgazer. Things to check: Is webgazer.js loaded? Is the webgazer extension included in initJsPsych?';
"Failed to start webgazer. Things to check: Is webgazer.js loaded? Is the webgazer extension included in initJsPsych?";
console.error(error);
reject(error);
}
Expand Down Expand Up @@ -288,8 +289,8 @@ class WebGazerExtension implements JsPsychExtension {
pause = () => {
this.webgazer.pause();
// sometimes gaze dot will show and freeze after pause?
if (document.querySelector('#webgazerGazeDot')) {
document.querySelector<HTMLElement>('#webgazerGazeDot').style.display = 'none';
if (document.querySelector("#webgazerGazeDot")) {
document.querySelector<HTMLElement>("#webgazerGazeDot").style.display = "none";
}
};

Expand All @@ -306,16 +307,16 @@ class WebGazerExtension implements JsPsychExtension {
};

calibratePoint = (x: number, y: number) => {
this.webgazer.recordScreenPosition(x, y, 'click');
this.webgazer.recordScreenPosition(x, y, "click");
};

setRegressionType = (regression_type) => {
var valid_regression_models = ['ridge', 'weightedRidge', 'threadedRidge'];
var valid_regression_models = ["ridge", "weightedRidge", "threadedRidge"];
if (valid_regression_models.includes(regression_type)) {
this.webgazer.setRegression(regression_type);
} else {
console.warn(
'Invalid regression_type parameter for webgazer.setRegressionType. Valid options are ridge, weightedRidge, and threadedRidge.'
"Invalid regression_type parameter for webgazer.setRegressionType. Valid options are ridge, weightedRidge, and threadedRidge."
);
}
};
Expand Down
Loading

0 comments on commit a28ca04

Please sign in to comment.