@adriansteffan/reactive 0.2.6 → 0.5.0

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.
Files changed (156) hide show
  1. package/README.md +796 -229
  2. package/bin/add.js +56 -0
  3. package/bin/deploy.js +48 -0
  4. package/bin/download.js +28 -0
  5. package/bin/ghsetup.js +21 -0
  6. package/bin/native.js +81 -0
  7. package/bin/setup.js +11 -17
  8. package/bin/study-deploy.js +60 -0
  9. package/bin/undeploy.js +15 -0
  10. package/extras/transcription/compose.yaml +32 -0
  11. package/{template → extras}/transcription/transcribe.py +4 -9
  12. package/package.json +62 -64
  13. package/src/bun-env.d.ts +1 -0
  14. package/src/bun-plugin.ts +22 -0
  15. package/src/components/canvasblock.tsx +209 -537
  16. package/src/components/checkdevice.tsx +64 -84
  17. package/src/components/fullscreenblock.tsx +130 -0
  18. package/src/components/icons.tsx +50 -0
  19. package/src/components/index.ts +9 -11
  20. package/src/components/microphonecheck.tsx +76 -38
  21. package/src/components/plaininput.tsx +48 -41
  22. package/src/components/prolificending.tsx +64 -28
  23. package/src/components/quest.tsx +89 -87
  24. package/src/components/{randomdotkinetogram.tsx → randomdotkinematogram.tsx} +205 -267
  25. package/src/components/{voicerecorder.tsx → recorder.tsx} +81 -106
  26. package/src/components/requestfilepermission.tsx +63 -0
  27. package/src/components/stimulus.tsx +373 -0
  28. package/src/components/storeui.tsx +94 -148
  29. package/src/components/text.tsx +61 -59
  30. package/src/components/tutorial.tsx +45 -47
  31. package/src/components/upload.tsx +133 -309
  32. package/src/components/voicerecording.tsx +90 -94
  33. package/src/core/backend.ts +20 -0
  34. package/src/core/bytecode.ts +178 -0
  35. package/src/core/columns.ts +50 -0
  36. package/src/core/component.ts +238 -0
  37. package/src/core/development.ts +32 -0
  38. package/src/core/experiment.ts +263 -0
  39. package/src/core/files.ts +291 -0
  40. package/src/core/params.ts +166 -0
  41. package/src/core/platform.ts +29 -0
  42. package/src/core/rows.ts +106 -0
  43. package/src/core/simulation.ts +158 -0
  44. package/src/core/slides.ts +178 -0
  45. package/src/core/store.ts +22 -0
  46. package/src/core/timeline.ts +399 -0
  47. package/src/fonts/AtkinsonHyperlegible-Bold.woff2 +0 -0
  48. package/src/fonts/AtkinsonHyperlegible-BoldItalic.woff2 +0 -0
  49. package/src/fonts/AtkinsonHyperlegible-Italic.woff2 +0 -0
  50. package/src/fonts/AtkinsonHyperlegible-Regular.woff2 +0 -0
  51. package/src/index.css +5 -7
  52. package/src/mod.tsx +31 -17
  53. package/src/native.ts +127 -0
  54. package/src/quest.ts +2 -0
  55. package/src/runner/contexts.ts +35 -0
  56. package/src/runner/devpanel.tsx +68 -0
  57. package/src/runner/experimentrunner.tsx +210 -0
  58. package/src/runner/fullscreenguard.tsx +93 -0
  59. package/src/runner/paraminput.tsx +86 -0
  60. package/src/runner/progressbar.tsx +20 -0
  61. package/src/runner/settingsscreen.tsx +517 -0
  62. package/src/{utils → runner}/theme.ts +9 -8
  63. package/src/server.ts +93 -0
  64. package/src/tutorial.ts +3 -0
  65. package/src/utils/array.ts +30 -62
  66. package/src/utils/canvas.ts +66 -0
  67. package/src/utils/ddm.ts +47 -70
  68. package/src/utils/distributions.ts +352 -61
  69. package/src/utils/fullscreen.ts +38 -0
  70. package/src/utils/ids.ts +11 -0
  71. package/src/utils/keys.ts +46 -0
  72. package/src/utils/llm.ts +15 -15
  73. package/src/utils/time.ts +12 -0
  74. package/src/utils/tts.ts +24 -24
  75. package/template/.dockerignore +3 -1
  76. package/template/.env.example +5 -0
  77. package/template/.github/workflows/deploy.yml +25 -0
  78. package/template/.gitignore +14 -0
  79. package/template/Dockerfile +9 -14
  80. package/template/README.md +74 -214
  81. package/template/biome.json +34 -0
  82. package/template/build.ts +20 -0
  83. package/template/bunfig.toml +3 -0
  84. package/template/docker-compose.yaml +4 -33
  85. package/template/index.html +2 -2
  86. package/template/package.json +16 -89
  87. package/template/public/.gitkeep +0 -0
  88. package/template/server.ts +32 -0
  89. package/template/simulate.ts +4 -44
  90. package/template/src/Experiment.tsx +76 -128
  91. package/template/src/bun-env.d.ts +1 -0
  92. package/template/src/index.css +1 -9
  93. package/template/src/main.tsx +25 -10
  94. package/template/tsconfig.json +4 -6
  95. package/.claude/settings.local.json +0 -61
  96. package/.eslintrc.cjs +0 -18
  97. package/.playwright-mcp/console-2026-04-07T14-22-59-060Z.log +0 -1
  98. package/.prettierrc +0 -5
  99. package/Dockerfile +0 -20
  100. package/dist/mod-HDegGPrf.js +0 -87434
  101. package/dist/mod.d.ts +0 -946
  102. package/dist/reactive.es.js +0 -87
  103. package/dist/reactive.umd.js +0 -10255
  104. package/dist/style.css +0 -5
  105. package/dist/web-7BbR1Ad7.js +0 -435
  106. package/dist/web-CATfZO1Q.js +0 -12
  107. package/planned.md +0 -103
  108. package/postcss.config.js +0 -6
  109. package/raw-loader-hooks.mjs +0 -25
  110. package/raw-loader.mjs +0 -5
  111. package/rdk_doc.md +0 -341
  112. package/src/components/enterfullscreen.tsx +0 -230
  113. package/src/components/exitfullscreen.tsx +0 -113
  114. package/src/components/experimentprovider.tsx +0 -69
  115. package/src/components/experimentrunner.tsx +0 -497
  116. package/src/components/mobilefilepermission.tsx +0 -68
  117. package/src/components/settingsscreen.tsx +0 -770
  118. package/src/types/array.d.ts +0 -6
  119. package/src/utils/audiodevice.ts +0 -4
  120. package/src/utils/bytecode.ts +0 -261
  121. package/src/utils/common.ts +0 -291
  122. package/src/utils/ddm.test.ts +0 -233
  123. package/src/utils/distributions.test.ts +0 -209
  124. package/src/utils/nodecompat.ts +0 -11
  125. package/src/utils/overlays.ts +0 -19
  126. package/src/utils/request.ts +0 -25
  127. package/src/utils/simulation.ts +0 -299
  128. package/src/utils/upload.ts +0 -275
  129. package/src/vite-env.d.ts +0 -1
  130. package/template/.env.template +0 -2
  131. package/template/.eslintrc.cjs +0 -18
  132. package/template/.prettierrc +0 -5
  133. package/template/backend/package-lock.json +0 -2544
  134. package/template/backend/package.json +0 -31
  135. package/template/backend/src/backend.ts +0 -131
  136. package/template/backend/tsconfig.json +0 -110
  137. package/template/capacitor.config.ts +0 -15
  138. package/template/electron/main.js +0 -131
  139. package/template/electron/preload.js +0 -9
  140. package/template/electron.vite.config.js +0 -45
  141. package/template/package-lock.json +0 -12467
  142. package/template/postcss.config.js +0 -5
  143. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Bold.ttf +0 -0
  144. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-BoldItalic.ttf +0 -0
  145. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Italic.ttf +0 -0
  146. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Regular.ttf +0 -0
  147. package/template/shared.vite.config.js +0 -39
  148. package/template/src/vite-env.d.ts +0 -2
  149. package/template/tsconfig.node.json +0 -12
  150. package/template/vite.config.js +0 -11
  151. package/tsconfig.json +0 -30
  152. package/tsconfig.node.json +0 -12
  153. package/vite.config.ts +0 -39
  154. /package/{template → extras}/transcription/Dockerfile.cpu +0 -0
  155. /package/{template → extras}/transcription/Dockerfile.gpu +0 -0
  156. /package/{template/public/Atkinson_Hyperlegible → src/fonts}/OFL.txt +0 -0
@@ -6,40 +6,11 @@ services:
6
6
  ports:
7
7
  - "8001:8001"
8
8
  volumes:
9
- - ./data:/data
9
+ - ./data:/app/data
10
10
  restart: unless-stopped
11
+ env_file:
12
+ - path: .env.production
13
+ required: false
11
14
  environment:
12
- - NODE_ENV=production
13
15
  - PORT=8001
14
16
 
15
- transcribe:
16
- profiles: ["transcribe"]
17
- build:
18
- context: ./transcription
19
- dockerfile: Dockerfile.cpu
20
- volumes:
21
- - ./data:/data
22
- - model-cache:/root/.cache/huggingface
23
- environment:
24
- - DATA_DIR=/data
25
-
26
- transcribe-gpu:
27
- profiles: ["transcribe-gpu"]
28
- build:
29
- context: ./transcription
30
- dockerfile: Dockerfile.gpu
31
- volumes:
32
- - ./data:/data
33
- - model-cache:/root/.cache/huggingface
34
- environment:
35
- - DATA_DIR=/data
36
- deploy:
37
- resources:
38
- reservations:
39
- devices:
40
- - driver: nvidia
41
- count: 1
42
- capabilities: [gpu]
43
-
44
- volumes:
45
- model-cache:
@@ -4,8 +4,8 @@
4
4
  <meta charset="UTF-8" />
5
5
  <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🟩</text></svg>">
6
6
  <meta name="viewport" content="initial-scale=1, viewport-fit=cover, shrink-to-fit=no, width=device-width, user-scalable=no">
7
-
8
- <link href="./src/index.css" rel="stylesheet">
7
+ <!-- Bun fills in the PUBLIC_ variables that are set. The others are undefined instead of an error, as browsers have no process. -->
8
+ <script>globalThis.process ??= { env: {} };</script>
9
9
  <title>Welcome to our study!</title>
10
10
  </head>
11
11
  <body>
@@ -5,104 +5,31 @@
5
5
  "author": "",
6
6
  "description": "",
7
7
  "type": "module",
8
- "main": "dist-electron/main/index.js",
9
- "build": {
10
- "appId": "",
11
- "productName": "PROJECT_NAME",
12
- "directories": {
13
- "output": "release"
14
- },
15
- "files": [
16
- "dist-electron",
17
- "dist"
18
- ],
19
- "mac": {
20
- "category": "public.app-category.utilities"
21
- },
22
- "win": {
23
- "target": [
24
- {
25
- "target": "nsis",
26
- "arch": [
27
- "x64"
28
- ]
29
- },
30
- {
31
- "target": "portable",
32
- "arch": [
33
- "x64"
34
- ]
35
- }
36
- ]
37
- },
38
- "linux": {
39
- "target": [
40
- "AppImage",
41
- "deb"
42
- ],
43
- "category": "Utility"
44
- }
45
- },
46
8
  "scripts": {
47
- "dev": "vite",
48
- "backend": "npm run dev --prefix backend",
49
- "dev:all": "concurrently -n \"FRONT,BACK\" -c \"blue,green\" \"npm run dev\" \"npm run backend\"",
50
- "simulate": "NODE_OPTIONS='--import tsx/esm --import @adriansteffan/reactive/raw-loader' node simulate.ts",
51
- "transcribe": "docker compose run --rm transcribe",
52
- "transcribe:gpu": "docker compose run --rm transcribe-gpu",
53
- "build": "tsc && vite build",
54
- "test": "vitest --silent=false",
55
- "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
56
- "preview": "vite preview",
57
- "rp-dev-pull": "npm link @adriansteffan/reactive",
58
- "electron:dev": "NODE_ENV=development electron-vite dev",
59
- "electron:build": "vite build && electron-vite build",
60
- "electron:preview": "electron-vite preview",
61
- "package:win": "electron-vite build && electron-builder --win",
62
- "package:mac": "electron-vite build && electron-builder --mac"
9
+ "dev": "bun --hot server.ts --dev",
10
+ "start": "bun server.ts",
11
+ "build": "bun build.ts",
12
+ "build:production": "NODE_ENV=production bun build.ts",
13
+ "deploy": "reactive deploy",
14
+ "download": "reactive download",
15
+ "undeploy": "reactive undeploy",
16
+ "ghsetup": "reactive ghsetup",
17
+ "simulate": "bun simulate.ts",
18
+ "typecheck": "bun check",
19
+ "lint": "biome lint --error-on-warnings"
63
20
  },
64
21
  "dependencies": {
65
22
  "@adriansteffan/reactive": "RP_VERSION",
66
- "@adriansteffan/immersive-mode": "0.0.1",
67
- "@capacitor/android": "^7.0.1",
68
- "@capacitor/core": "^7.0.1",
69
- "@capacitor/filesystem": "^7.0.0",
70
- "@capacitor/ios": "^7.0.1",
71
- "@capacitor/share": "^7.0.0",
72
- "@tanstack/react-query": "^5.61.3",
73
- "@tanstack/react-query-devtools": "^5.61.3",
74
23
  "react": "^18.2.0",
75
- "react-dom": "^18.2.0",
76
- "react-icons": "^5.1.0",
77
- "survey-react-ui": "^1.12.9",
78
- "dotenv": "^16.4.7"
24
+ "react-dom": "^18.2.0"
79
25
  },
80
26
  "devDependencies": {
81
- "@capacitor/cli": "^7.0.1",
82
- "@tailwindcss/postcss": "^4.0.9",
27
+ "@biomejs/biome": "^2.5.15",
83
28
  "@tailwindcss/typography": "^0.5.16",
84
- "@types/howler": "^2.2.11",
85
- "@types/node": "^22.9.2",
29
+ "@types/bun": "^1.4.3",
86
30
  "@types/react": "^18.2.66",
87
31
  "@types/react-dom": "^18.2.22",
88
- "@typescript-eslint/eslint-plugin": "^8.16.0",
89
- "@typescript-eslint/parser": "^8.16.0",
90
- "@vitejs/plugin-react": "^4.2.1",
91
- "concurrently": "^9.1.0",
92
- "tsx": "^4.19.2",
93
- "electron": "^35.0.0",
94
- "electron-builder": "^25.1.8",
95
- "electron-vite": "^3.0.0",
96
- "eslint": "^9.0.0",
97
- "eslint-plugin-react-hooks": "^5.0.0",
98
- "eslint-plugin-react-refresh": "^0.4.14",
99
- "postcss": "^8.4.38",
100
- "prettier": "3.2.5",
101
- "tailwindcss": "^4.0.9",
102
- "typescript": "^5.2.2",
103
- "vite": "^6.2.0",
104
- "vite-plugin-dts": "^4.3.0",
105
- "vite-plugin-top-level-await": "^1.5.0",
106
- "vitest": "^3.0.7"
32
+ "bun-plugin-tailwind": "^0.1.2",
33
+ "tailwindcss": "^4.0.9"
107
34
  }
108
35
  }
File without changes
@@ -0,0 +1,32 @@
1
+ import path from 'path';
2
+ import { uploadRoutes } from '@adriansteffan/reactive/server';
3
+ import index from './index.html';
4
+
5
+ const dataFolder = path.join(import.meta.dir, 'data');
6
+ const publicFolder = path.join(import.meta.dir, 'public');
7
+
8
+ const PORT = Number(process.env.PORT ?? 8001);
9
+
10
+ export const api = {
11
+ ...uploadRoutes(dataFolder),
12
+
13
+ // your routes below this line ------------
14
+
15
+ // ---------
16
+ };
17
+
18
+ if (import.meta.main) {
19
+ const server = Bun.serve({
20
+ port: PORT,
21
+ routes: { ...api, '/': index, '/settings': index },
22
+ // Anything else is served from public/
23
+ async fetch(req) {
24
+ const file = Bun.file(path.join(publicFolder, new URL(req.url).pathname));
25
+ return (await file.exists()) ? new Response(file) : new Response('Not Found', { status: 404 });
26
+ },
27
+ // --dev adds hot reloading and readable errors; without it, the page is built for production
28
+ development: process.argv.includes('--dev'),
29
+ });
30
+
31
+ console.log(`Server running at ${server.url}`);
32
+ }
@@ -1,45 +1,5 @@
1
- import 'dotenv/config';
2
- import { orchestrateSimulation, simulateParticipant, setBackendUrl, seedDistributions } from '@adriansteffan/reactive';
1
+ import { runSimulation } from '@adriansteffan/reactive';
2
+ import { api } from './server';
3
3
 
4
- function extractProps(ExperimentComponent: any) {
5
- // Call the component function directly to get the ExperimentRunner element.
6
- // This is safe because Experiment() just returns JSX — no hooks execute.
7
- const element = ExperimentComponent();
8
- return element.props;
9
- }
10
-
11
- // Each simulated participant runs as a separate subprocess to get fresh module-level
12
- // randomization (e.g., group assignment). The orchestrator spawns workers that re-run
13
- // this script with _REACTIVE_WORKER_INDEX set.
14
- //
15
- // Experiment.tsx is imported dynamically so that seeding happens before module-level
16
- // code runs. If participants is a factory function, it is called with the base seed
17
- // for deterministic generation, then re-seeded per-worker for the simulation.
18
- if (process.env._REACTIVE_WORKER_INDEX) {
19
- const index = parseInt(process.env._REACTIVE_WORKER_INDEX);
20
- const seed = process.env._REACTIVE_SIMULATION_SEED;
21
- if (seed) seedDistributions(parseInt(seed) + index);
22
- setBackendUrl(process.env._REACTIVE_BACKEND_URL!);
23
-
24
- const { default: Experiment } = await import('./src/Experiment');
25
- const { timeline, simulationConfig } = extractProps(Experiment);
26
- const participants = simulationConfig.participants;
27
-
28
- let participant;
29
- if (typeof participants === 'function') {
30
- if (seed) seedDistributions(parseInt(seed));
31
- const allParticipants = participants();
32
- if (seed) seedDistributions(parseInt(seed) + index);
33
- participant = allParticipants[index];
34
- } else if (Array.isArray(participants)) {
35
- participant = participants[index];
36
- } else {
37
- participant = participants.generator(index);
38
- }
39
-
40
- await simulateParticipant(timeline, participant);
41
- } else {
42
- const { default: Experiment } = await import('./src/Experiment');
43
- const { simulationConfig } = extractProps(Experiment);
44
- await orchestrateSimulation(simulationConfig, import.meta.filename);
45
- }
4
+ // Imported through a function, so that the simulation notices random numbers drawn while the experiment loads
5
+ await runSimulation(() => import('./src/Experiment'), api);
@@ -1,13 +1,21 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { useState, useRef } from 'react';
3
- import { ExperimentRunner, BaseComponentProps, ExperimentConfig, registerSimulation, registerFlattener, sampleParticipants, prepareTimeline } from '@adriansteffan/reactive';
4
-
5
-
6
- const config: ExperimentConfig = { showProgressBar: true };
1
+ import { useRef, useState } from 'react';
2
+ import {
3
+ type BaseComponentProps,
4
+ defineComponent,
5
+ defineExperiment,
6
+ PlainInput,
7
+ sampleParticipants,
8
+ Text,
9
+ Upload,
10
+ } from '@adriansteffan/reactive';
7
11
 
8
12
  // --- Custom Components ---
9
13
 
10
- const CustomTrial = ({ next, maxCount }: BaseComponentProps & { maxCount: number }) => {
14
+ // A named function, so that hot reloading keeps the trial's state when this file changes
15
+ function CustomTrialView({
16
+ next,
17
+ maxCount,
18
+ }: BaseComponentProps<{ totalTimeMs: number; clicks: number }> & { maxCount: number }) {
11
19
  const [count, setCount] = useState(0);
12
20
  const startTime = useRef(performance.now());
13
21
 
@@ -17,13 +25,14 @@ const CustomTrial = ({ next, maxCount }: BaseComponentProps & { maxCount: number
17
25
  <strong>Custom Component</strong>
18
26
  </h1>
19
27
  <br />
20
- This is a custom component component. Click the button {maxCount} times to progress
28
+ This is a custom component. Click the button {maxCount} times to progress
21
29
  <br />
22
30
  <button
31
+ type='button'
23
32
  onClick={() => {
24
33
  setCount(count + 1);
25
34
  if (count + 1 === maxCount) {
26
- next({ totalTime: performance.now() - startTime.current, clicks: maxCount });
35
+ next({ totalTimeMs: performance.now() - startTime.current, clicks: maxCount });
27
36
  }
28
37
  }}
29
38
  className='mt-4 px-4 py-2 bg-blue-500 text-white rounded-sm hover:bg-blue-600 transition-colors'
@@ -32,45 +41,49 @@ const CustomTrial = ({ next, maxCount }: BaseComponentProps & { maxCount: number
32
41
  </button>
33
42
  </>
34
43
  );
35
- };
36
-
37
- // Register a flattener to control how this trial's data appears in the CSV.
38
- // 'customtrial' is the default CSV file name — override per-item with the csv field.
39
- registerFlattener('CustomTrial', 'customtrial');
44
+ }
40
45
 
41
- // Register a simulation for the custom trial.
42
- // The decision function determines how fast the participant clicks.
43
- // The simulate function uses the trial logic (clicking maxCount times) to produce response data.
44
- registerSimulation('CustomTrial', (trialProps, _experimentState, simulators, participant) => {
45
- let totalTime = 0;
46
- for (let i = 0; i < (trialProps.maxCount || 1); i++) {
47
- const result = simulators.click(trialProps, participant);
48
- participant = result.participantState;
49
- totalTime += result.value;
50
- }
51
- return { responseData: { totalTime, clicks: trialProps.maxCount }, participantState: participant, duration: totalTime };
52
- }, {
53
- click: (_trialProps: any, participant: any) => ({
54
- value: 200 + Math.random() * 500,
55
- participantState: participant,
56
- }),
46
+ const CustomTrial = defineComponent({
47
+ name: 'CustomTrial',
48
+ component: CustomTrialView,
49
+ // The CSV file this component's data goes into, which a trial can change with .csv()
50
+ csv: 'customtrial',
51
+ // simulate replays the trial, asking the click simulator how fast the participant clicks
52
+ simulate: ({ props, simulators, participant }) => {
53
+ let totalTimeMs = 0;
54
+ for (let i = 0; i < props.maxCount; i++) {
55
+ const result = simulators.click({ props, participant });
56
+ participant = result.participant ?? participant;
57
+ totalTimeMs += result.value;
58
+ }
59
+ return {
60
+ recorded: { totalTimeMs, clicks: props.maxCount },
61
+ participant,
62
+ durationMs: totalTimeMs,
63
+ };
64
+ },
65
+ defaultSimulators: {
66
+ click: () => ({ value: 200 + Math.random() * 500 }),
67
+ },
57
68
  });
58
69
 
59
- const CustomQuestion = () => {
60
- return (
61
- <>
62
- <p>This is a custom question</p>
63
- </>
64
- );
65
- };
66
-
67
- // --- Timeline ---
70
+ // --- Experiment ---
68
71
 
69
- const experiment = prepareTimeline([
70
- {
71
- name: 'introtext',
72
- type: 'Text',
73
- props: {
72
+ export default defineExperiment({
73
+ // Read from the URL (?clicks=3) or set on the settings page at /settings
74
+ params: {
75
+ clicks: { default: 5, description: 'How often the participant needs to click the button' },
76
+ },
77
+ config: { showProgressBar: true },
78
+ simulation: {
79
+ seed: 42,
80
+ createParticipants: () =>
81
+ sampleParticipants('sobol', 10, {
82
+ needForCognition: { distribution: 'normal', mean: 3.5, sd: 0.8 },
83
+ }).map((p) => ({ ...p, nickname: `participant_${p.index}` })),
84
+ },
85
+ timeline: ({ clicks }) => [
86
+ Text.trial('introtext', {
74
87
  buttonText: "Let's Begin",
75
88
  animate: true,
76
89
  content: (
@@ -82,92 +95,27 @@ const experiment = prepareTimeline([
82
95
  This is a basic text component. <br />
83
96
  </>
84
97
  ),
85
- },
86
- },
87
- {
88
- name: 'nickname',
89
- type: 'PlainInput',
90
- props: {
98
+ }),
99
+
100
+ PlainInput.trial('nickname', {
91
101
  content: <p>What is your nickname?</p>,
92
102
  buttonText: 'Submit',
93
103
  placeholder: 'Enter your nickname',
94
- },
95
- simulators: {
96
- respond: (_trialProps: any, participant: any) => ({
97
- value: participant.nickname,
98
- participantState: participant,
99
- }),
100
- },
101
- },
102
- {
103
- name: 'customtrial',
104
- type: 'CustomTrial',
105
- simulate: true,
106
- props: {
107
- maxCount: 5,
108
- },
109
- },
110
- {
111
- name: 'survey',
112
- type: 'Quest',
113
- props: {
114
- surveyJson: {
115
- pages: [
116
- {
117
- elements: [
118
- {
119
- type: 'rating',
120
- name: 'examplequestion',
121
- title: 'We can use all of the surveyjs components in the framework',
122
- isRequired: true,
123
- rateMin: 1,
124
- rateMax: 6,
125
- minRateDescription: 'Not at all',
126
- maxRateDescription: 'Extremely',
127
- },
128
- {
129
- title: 'Cutom Question',
130
- type: 'CustomQuestion',
131
- },
132
- ],
133
- },
134
- ],
135
- },
136
- },
137
- },
138
- {
139
- name: 'upload',
140
- type: 'Upload',
141
- props: {
142
- autoUpload: false,
143
- }
144
- },
145
- {
146
- name: 'finaltext',
147
- type: 'Text',
148
- props: {
149
- content: <>Thank you for participating in our study, you can now close the browser window.</>,
150
- },
151
- },
152
- ]);
104
+ }).simulators({
105
+ respond: ({ participant }) => ({ value: participant.nickname }),
106
+ }),
153
107
 
154
- // --- Simulation config ---
155
- const simulationConfig = {
156
- seed: 42,
157
- participants: () => sampleParticipants('sobol', 10, {
158
- needForCognition: { distribution: 'normal', mean: 3.5, sd: 0.8 },
159
- }).map((p) => ({ ...p, nickname: `participant_${p.index}` })),
160
- };
108
+ CustomTrial.trial('customtrial', { maxCount: clicks }),
161
109
 
162
- export default function Experiment() {
163
- return (
164
- <ExperimentRunner
165
- config={config}
166
- timeline={experiment}
167
- components={{CustomTrial}}
168
- questions={{CustomQuestion}}
169
- hybridParticipant={{ id: 0, nickname: 'test' }}
170
- simulationConfig={simulationConfig}
171
- />
172
- );
173
- }
110
+ Upload.trial('upload'),
111
+
112
+ Text.trial('finaltext', ({ data }) => ({
113
+ content: (
114
+ <>
115
+ Thank you for participating in our study, {PlainInput.getLatest(data, 'nickname').recorded.value}. You can now
116
+ close the browser window.
117
+ </>
118
+ ),
119
+ })),
120
+ ],
121
+ });
@@ -0,0 +1 @@
1
+ declare module "*.css" {}
@@ -1,11 +1,3 @@
1
- @import '@adriansteffan/reactive/style.css';
2
1
  @import 'tailwindcss';
2
+ @import '@adriansteffan/reactive/style.css';
3
3
  @plugin '@tailwindcss/typography';
4
-
5
- @theme {
6
- --font-*: initial;
7
- --font-atkinson: Atkinson Hyperlegible, sans-serif;
8
- }
9
-
10
- @source '../node_modules/@adriansteffan/reactive/dist/**/*.{js,jsx,ts,tsx}';
11
- @source '../node_modules/@adriansteffan/reactive/src/**/*.{js,jsx,ts,tsx}';
@@ -1,13 +1,28 @@
1
1
  import React from "react";
2
2
  import ReactDOM from "react-dom/client";
3
- import Experiment from "./Experiment";
3
+ import experiment from "./Experiment";
4
4
  import "./index.css";
5
- import { ExperimentProvider } from "@adriansteffan/reactive";
6
-
7
- ReactDOM.createRoot(document.getElementById("root")!).render(
8
- <React.StrictMode>
9
- <ExperimentProvider disableSettings={import.meta.env.VITE_DISABLE_SETTINGS} disableHybridSimulation={!!import.meta.env.VITE_DISABLE_HYBRID_SIMULATION}>
10
- <Experiment />
11
- </ExperimentProvider>
12
- </React.StrictMode>
13
- );
5
+ import { ExperimentRunner } from "@adriansteffan/reactive";
6
+
7
+ // Kept across hot reloads, so that an edited experiment re-renders the one that is running.
8
+ // biome-ignore lint/suspicious/noAssignInExpressions: production builds replace this whole expression with the new root
9
+ const root = (import.meta.hot.data.root ??= ReactDOM.createRoot(document.getElementById("root")!));
10
+
11
+ function render(definition: typeof experiment) {
12
+ root.render(
13
+ <React.StrictMode>
14
+ <ExperimentRunner
15
+ experiment={definition}
16
+ disableSettings={process.env.PUBLIC_DISABLE_SETTINGS}
17
+ disableDev={process.env.PUBLIC_DISABLE_DEV}
18
+ />
19
+ </React.StrictMode>
20
+ );
21
+ }
22
+
23
+ render(experiment);
24
+
25
+ // Re-rendering the same runner with the edited experiment keeps the participant's place
26
+ import.meta.hot.accept("./Experiment", (module) => {
27
+ if (module) render(module.default);
28
+ });
@@ -1,15 +1,14 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "noImplicitAny": false,
4
- "target": "ES2020",
5
- "useDefineForClassFields": true,
6
- "lib": ["ES2020", "DOM", "DOM.Iterable"],
4
+ "target": "ES2022",
5
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
6
+ "types": ["bun"],
7
7
  "module": "ESNext",
8
8
  "skipLibCheck": true,
9
9
 
10
10
  /* Bundler mode */
11
11
  "moduleResolution": "bundler",
12
- "allowImportingTsExtensions": true,
13
12
  "resolveJsonModule": true,
14
13
  "isolatedModules": true,
15
14
  "noEmit": true,
@@ -21,6 +20,5 @@
21
20
  "noUnusedParameters": true,
22
21
  "noFallthroughCasesInSwitch": true
23
22
  },
24
- "include": ["src", "elec.js"],
25
- "references": [{ "path": "./tsconfig.node.json" }]
23
+ "include": ["src", "server.ts", "simulate.ts", "build.ts"]
26
24
  }
@@ -1,61 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "mcp__ide__getDiagnostics",
5
- "Bash(npm run:*)",
6
- "WebSearch",
7
- "WebFetch(domain:github.com)",
8
- "WebFetch(domain:surveyjs.io)",
9
- "Read(//Users/adriansteffan/Projects/rtest/**)",
10
- "Bash(npm link:*)",
11
- "Bash(npx tsc:*)",
12
- "Bash(grep:*)",
13
- "Bash(cp:*)",
14
- "Bash(cd:*)",
15
- "mcp__playwright__browser_take_screenshot",
16
- "mcp__playwright__browser_evaluate",
17
- "mcp__playwright__browser_run_code",
18
- "Bash(npm test:*)",
19
- "WebFetch(domain:raw.githubusercontent.com)",
20
- "Bash(ls /Users/adriansteffan/Projects/reactive/README*)",
21
- "Bash(ls /Users/adriansteffan/Projects/reactive/*.md)",
22
- "Bash(npm search:*)",
23
- "Bash(node -e \"const d=require\\('fs'\\).readFileSync\\('/dev/stdin','utf8'\\); const r=JSON.parse\\(d\\); r.slice\\(0,5\\).forEach\\(p => console.log\\(p.name, '-', p.description, '- v'+p.version\\)\\)\")",
24
- "Bash(npm info:*)",
25
- "Bash(node:*)",
26
- "Bash(npm uninstall:*)",
27
- "Bash(curl -s 'https://web.maths.unsw.edu.au/~fkuo/sobol/joe-kuo-old.1111')",
28
- "WebFetch(domain:doi.org)",
29
- "WebFetch(domain:dl.acm.org)",
30
- "WebFetch(domain:web.maths.unsw.edu.au)",
31
- "WebFetch(domain:www.netlib.org)",
32
- "WebFetch(domain:calgo.acm.org)",
33
- "Bash(npx vitest:*)",
34
- "WebFetch(domain:pmc.ncbi.nlm.nih.gov)",
35
- "WebFetch(domain:mollermara.com)",
36
- "WebFetch(domain:www.ejwagenmakers.com)",
37
- "WebFetch(domain:elifesciences.org)",
38
- "WebFetch(domain:www.tqmp.org)",
39
- "WebFetch(domain:pyddm.readthedocs.io)",
40
- "Bash(curl -s https://raw.githubusercontent.com/poldrack/ezdiff/master/ezdiff.py)",
41
- "Bash(curl -s https://raw.githubusercontent.com/poldrack/ezdiff/master/simulate_ddm.py)",
42
- "WebFetch(domain:courses.washington.edu)",
43
- "WebFetch(domain:dominiquemakowski.github.io)",
44
- "WebFetch(domain:itsdfish.github.io)",
45
- "Bash(mkdir -p /tmp/quest-test)",
46
- "mcp__playwright__browser_navigate",
47
- "Bash(kill 59399)",
48
- "Bash(rm -rf /tmp/quest-test)",
49
- "Bash(npm audit:*)",
50
- "Bash(npm view:*)",
51
- "Bash(say -v '?')",
52
- "Read(//Users/adriansteffan/Projects/donkin/dec-from-exp/**)",
53
- "Bash(npx tsx:*)",
54
- "Bash(ls -la data/sim_1775827664642_y5r7bw/audio_*)",
55
- "Bash(rm:*)",
56
- "Bash(ls:*)"
57
- ],
58
- "deny": [],
59
- "ask": []
60
- }
61
- }