@adriansteffan/reactive 0.2.7 → 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 (158) 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 +45 -40
  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/.playwright-mcp/console-2026-09-20T12-17-32-043Z.log +0 -1
  99. package/.playwright-mcp/page-2026-09-20T12-17-32-084Z.yml +0 -10
  100. package/.prettierrc +0 -5
  101. package/Dockerfile +0 -20
  102. package/dist/mod-BTpABl23.js +0 -87435
  103. package/dist/mod.d.ts +0 -947
  104. package/dist/reactive.es.js +0 -87
  105. package/dist/reactive.umd.js +0 -10255
  106. package/dist/style.css +0 -5
  107. package/dist/web-DV4cj_8Q.js +0 -435
  108. package/dist/web-DprbPn6i.js +0 -12
  109. package/planned.md +0 -103
  110. package/postcss.config.js +0 -6
  111. package/raw-loader-hooks.mjs +0 -25
  112. package/raw-loader.mjs +0 -5
  113. package/rdk_doc.md +0 -341
  114. package/src/components/enterfullscreen.tsx +0 -230
  115. package/src/components/exitfullscreen.tsx +0 -113
  116. package/src/components/experimentprovider.tsx +0 -69
  117. package/src/components/experimentrunner.tsx +0 -497
  118. package/src/components/mobilefilepermission.tsx +0 -68
  119. package/src/components/settingsscreen.tsx +0 -770
  120. package/src/types/array.d.ts +0 -6
  121. package/src/utils/audiodevice.ts +0 -4
  122. package/src/utils/bytecode.ts +0 -261
  123. package/src/utils/common.ts +0 -291
  124. package/src/utils/ddm.test.ts +0 -233
  125. package/src/utils/distributions.test.ts +0 -209
  126. package/src/utils/nodecompat.ts +0 -11
  127. package/src/utils/overlays.ts +0 -19
  128. package/src/utils/request.ts +0 -25
  129. package/src/utils/simulation.ts +0 -299
  130. package/src/utils/upload.ts +0 -275
  131. package/src/vite-env.d.ts +0 -1
  132. package/template/.env.template +0 -2
  133. package/template/.eslintrc.cjs +0 -18
  134. package/template/.prettierrc +0 -5
  135. package/template/backend/package-lock.json +0 -2544
  136. package/template/backend/package.json +0 -31
  137. package/template/backend/src/backend.ts +0 -131
  138. package/template/backend/tsconfig.json +0 -110
  139. package/template/capacitor.config.ts +0 -15
  140. package/template/electron/main.js +0 -131
  141. package/template/electron/preload.js +0 -9
  142. package/template/electron.vite.config.js +0 -45
  143. package/template/package-lock.json +0 -12467
  144. package/template/postcss.config.js +0 -5
  145. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Bold.ttf +0 -0
  146. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-BoldItalic.ttf +0 -0
  147. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Italic.ttf +0 -0
  148. package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Regular.ttf +0 -0
  149. package/template/shared.vite.config.js +0 -39
  150. package/template/src/vite-env.d.ts +0 -2
  151. package/template/tsconfig.node.json +0 -12
  152. package/template/vite.config.js +0 -11
  153. package/tsconfig.json +0 -30
  154. package/tsconfig.node.json +0 -12
  155. package/vite.config.ts +0 -39
  156. /package/{template → extras}/transcription/Dockerfile.cpu +0 -0
  157. /package/{template → extras}/transcription/Dockerfile.gpu +0 -0
  158. /package/{template/public/Atkinson_Hyperlegible → src/fonts}/OFL.txt +0 -0
@@ -0,0 +1,517 @@
1
+ import { useMemo, useRef, useState } from 'react';
2
+ import { type Experiment, previewTimeline } from '../core/experiment';
3
+ import type { EntryInfo } from '../core/timeline';
4
+ import {
5
+ libraryParams,
6
+ type ParamSpec,
7
+ paramType,
8
+ parseParam,
9
+ resolveParams,
10
+ urlParams,
11
+ } from '../core/params';
12
+ import { ParamInput, Switch } from './paraminput';
13
+
14
+ // A param the experiment does not declare, which a run only records
15
+ type CustomParam = { name: string; value: string };
16
+
17
+ // How a value appears in a text field
18
+ const asText = (value: unknown) =>
19
+ typeof value === 'object' && value !== null ? JSON.stringify(value) : String(value);
20
+
21
+ // When the entered values do not build a timeline, the library's params are still listed
22
+ function preview(
23
+ experiment: Experiment<any>,
24
+ url: Record<string, unknown>,
25
+ defaults: Record<string, unknown>,
26
+ ) {
27
+ try {
28
+ return { ...previewTimeline(experiment, url, defaults), error: undefined };
29
+ } catch (error) {
30
+ return { entries: [] as EntryInfo[], settings: { General: libraryParams }, problems: [], error: (error as Error).message };
31
+ }
32
+ }
33
+
34
+ // What the checkboxes stand for: trials, and blocks without items. Markers always stay, so that no ifGoto loses its target.
35
+ const leavesOf = (entries: EntryInfo[]): EntryInfo[] =>
36
+ entries.flatMap((entry) => (entry.children ? leavesOf(entry.children) : entry.type === 'marker' ? [] : [entry]));
37
+
38
+ // The rows of the trial list: every entry under the block it sits in, with a line where an else arm starts
39
+ type Row = { entry: EntryInfo; depth: number } | { elseAt: string; depth: number };
40
+ const rowsOf = (entries: EntryInfo[], depth = 0): Row[] =>
41
+ entries.flatMap((entry, i) => [
42
+ ...(entry.arm === 'else' && entries[i - 1]?.arm !== 'else' ? [{ elseAt: entry.position, depth }] : []),
43
+ { entry, depth },
44
+ ...rowsOf(entry.children ?? [], depth + 1),
45
+ ]);
46
+
47
+ function describeParam(name: string, spec: ParamSpec) {
48
+ return {
49
+ name,
50
+ spec,
51
+ type: paramType(spec),
52
+ defaultValue: typeof spec.default === 'function' ? undefined : spec.default,
53
+ computedDefault: typeof spec.default === 'function',
54
+ };
55
+ }
56
+
57
+ type ParamField = ReturnType<typeof describeParam>;
58
+
59
+ export const SettingsScreen = ({ experiment }: { experiment: Experiment<any> }) => {
60
+ // The form starts from the link the page was opened with
61
+ const [initial] = useState(() => {
62
+ const { excludeSubset, ...values } = urlParams();
63
+ // Defaults computed for each participant are drawn once for the preview, and stay out of the link
64
+ const defaults = resolveParams(experiment.params);
65
+ // Without the link's selection every setting of the timeline is listed, so none of them is taken for a custom param
66
+ const opened = preview(experiment, values, defaults);
67
+ const declared = new Set([
68
+ ...Object.keys(experiment.params ?? {}),
69
+ ...Object.values(opened.settings).flatMap((params) => Object.keys(params)),
70
+ ]);
71
+
72
+ const entered: Record<string, string> = {};
73
+ const custom: CustomParam[] = [];
74
+ for (const [name, value] of Object.entries(values)) {
75
+ if (declared.has(name)) entered[name] = asText(value);
76
+ else custom.push({ name, value: asText(value) });
77
+ }
78
+
79
+ // The trials the link leaves out are unchecked, with all those in a block it leaves out
80
+ const excluded = new Set(String(excludeSubset ?? '').split(','));
81
+ const leftOut = (entries: EntryInfo[]): EntryInfo[] =>
82
+ entries.flatMap((entry) =>
83
+ excluded.has(entry.id) || excluded.has(entry.position) ? leavesOf([entry]) : leftOut(entry.children ?? []),
84
+ );
85
+ const toggled: Record<string, boolean> = Object.fromEntries(leftOut(opened.entries).map((leaf) => [leaf.id, false]));
86
+
87
+ return {
88
+ defaults,
89
+ entered,
90
+ custom,
91
+ toggled,
92
+ base64: new URLSearchParams(window.location.search).has('_b'),
93
+ };
94
+ });
95
+
96
+ const [paramValues, setParamValues] = useState<Record<string, string>>(initial.entered);
97
+ const [customParams, setCustomParams] = useState<CustomParam[]>(initial.custom);
98
+ const [copied, setCopied] = useState(false);
99
+ const [useBase64, setUseBase64] = useState(initial.base64);
100
+ // Trials checked or unchecked by hand. The others are checked, so a trial the params add later
101
+ // runs unless someone takes it out.
102
+ const [toggled, setToggled] = useState<Record<string, boolean>>(initial.toggled);
103
+ const runs = (leaf: EntryInfo) => toggled[leaf.id] ?? true;
104
+ const urlInputRef = useRef<HTMLInputElement>(null);
105
+
106
+ // The params build the timeline, and the trials selected in it decide which settings apply
107
+ const current = useMemo(() => {
108
+ const entered = Object.fromEntries(
109
+ Object.entries(paramValues).filter(([, value]) => value !== ''),
110
+ );
111
+ const { entries, error } = preview(experiment, entered, initial.defaults);
112
+ const unchecked = [...new Set(leavesOf(entries).filter((leaf) => !(toggled[leaf.id] ?? true)).map((leaf) => leaf.id))];
113
+ const subset: Record<string, string> = unchecked.length > 0 ? { excludeSubset: unchecked.join(',') } : {};
114
+ const { settings, problems } = preview(experiment, { ...entered, ...subset }, initial.defaults);
115
+ return { entries, error, problems, subset, settings };
116
+ }, [experiment, paramValues, initial.defaults, toggled]);
117
+
118
+ const experimentFields = Object.entries((experiment.params ?? {}) as Record<string, ParamSpec>).map(
119
+ ([name, spec]) => describeParam(name, spec),
120
+ );
121
+
122
+ // Params left to a default computed for each participant, which the preview draws once
123
+ const drawnFields = experimentFields.filter((field) => field.computedDefault && !paramValues[field.name]);
124
+
125
+ const settingGroups = Object.entries(current.settings)
126
+ .map(([title, params]) => ({
127
+ title,
128
+ fields: Object.entries(params).map(([name, spec]) => describeParam(name, spec)),
129
+ }))
130
+ .filter((group) => group.fields.length > 0);
131
+
132
+ const generatedUrl = (() => {
133
+ const values: Record<string, unknown> = {};
134
+ // Settings of components whose trials are not selected stay out of the link
135
+ for (const { name, spec, defaultValue } of [
136
+ ...experimentFields,
137
+ ...settingGroups.flatMap((group) => group.fields),
138
+ ]) {
139
+ const text = paramValues[name];
140
+ // Values equal to the default stay out of the link
141
+ if (
142
+ text === undefined ||
143
+ text === '' ||
144
+ (defaultValue !== undefined && text === asText(defaultValue))
145
+ ) {
146
+ continue;
147
+ }
148
+ let value: unknown = text;
149
+ if (useBase64) {
150
+ try {
151
+ value = parseParam(name, spec, text);
152
+ } catch {
153
+ // The preview reports the invalid value
154
+ }
155
+ }
156
+ values[name] = value;
157
+ }
158
+
159
+ Object.assign(values, current.subset);
160
+
161
+ for (const param of customParams) {
162
+ if (param.name && param.value !== '' && param.name !== 'excludeSubset') {
163
+ values[param.name] = param.value;
164
+ }
165
+ }
166
+
167
+ const query = !Object.keys(values).length
168
+ ? ''
169
+ : useBase64
170
+ ? `?_b=${btoa(JSON.stringify(values))}`
171
+ : `?${new URLSearchParams(Object.entries(values).map(([key, value]) => [key, String(value)]))}`;
172
+ const baseUrl = window.location.pathname.replace(/\/settings$/, '');
173
+ return `${window.location.origin}${baseUrl}${query}`;
174
+ })();
175
+
176
+ const handleCustomParamChange = (index: number, field: keyof CustomParam, value: string) => {
177
+ setCustomParams((prev) => {
178
+ const updated = [...prev];
179
+ updated[index] = {
180
+ ...updated[index],
181
+ [field]: value,
182
+ };
183
+ return updated;
184
+ });
185
+ };
186
+
187
+ const handleCopyUrl = () => {
188
+ if (urlInputRef.current) {
189
+ urlInputRef.current.select();
190
+ document.execCommand('copy');
191
+ setCopied(true);
192
+ setTimeout(() => setCopied(false), 2000);
193
+ }
194
+ };
195
+
196
+ const renderCustomParamInput = (param: CustomParam, index: number) => (
197
+ <div key={index} className='grid grid-cols-12 gap-2 items-center mb-2'>
198
+ <div className='col-span-3'>
199
+ <input
200
+ type='text'
201
+ className='block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm'
202
+ value={param.name}
203
+ onChange={(e) => handleCustomParamChange(index, 'name', e.target.value)}
204
+ placeholder='Parameter name'
205
+ />
206
+ </div>
207
+
208
+ <div className='col-span-8'>
209
+ <ParamInput
210
+ type='string'
211
+ value={param.value}
212
+ onChange={(value) => handleCustomParamChange(index, 'value', value)}
213
+ />
214
+ </div>
215
+
216
+ <div className='col-span-1'>
217
+ <button
218
+ onClick={() => setCustomParams((prev) => prev.filter((_, i) => i !== index))}
219
+ className='inline-flex cursor-pointer items-center justify-center p-2 border border-transparent rounded-md text-red-700 bg-red-100 hover:bg-red-200 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500'
220
+ aria-label='Remove parameter'
221
+ >
222
+ <svg
223
+ xmlns='http://www.w3.org/2000/svg'
224
+ className='h-5 w-5'
225
+ viewBox='0 0 20 20'
226
+ fill='currentColor'
227
+ >
228
+ <path
229
+ fillRule='evenodd'
230
+ d='M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z'
231
+ clipRule='evenodd'
232
+ />
233
+ </svg>
234
+ </button>
235
+ </div>
236
+ </div>
237
+ );
238
+
239
+ const renderParamRow = (param: ParamField) => (
240
+ <li key={param.name} className='px-4 py-4 sm:px-6'>
241
+ <div className='grid grid-cols-3 gap-6'>
242
+ <div className='col-span-2'>
243
+ <div className='flex flex-col h-full'>
244
+ <div className='flex items-center'>
245
+ <label className='text-base font-medium text-gray-900'>{param.name}</label>
246
+ <span className='ml-2 inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-medium bg-gray-100 text-gray-600'>
247
+ {param.type}
248
+ </span>
249
+ </div>
250
+ {param.spec.description && (
251
+ <p className='mt-1 text-sm text-gray-500 flex-grow'>{param.spec.description}</p>
252
+ )}
253
+ {param.defaultValue !== undefined && (
254
+ <p className='mt-auto pt-2 text-xs text-gray-500'>
255
+ Default: <code> {JSON.stringify(param.defaultValue)}</code>
256
+ </p>
257
+ )}
258
+ {param.computedDefault && (
259
+ <p className='mt-auto pt-2 text-xs text-gray-500'>
260
+ Default: computed for each participant
261
+ </p>
262
+ )}
263
+ </div>
264
+ </div>
265
+ <div className='col-span-1 flex items-center'>
266
+ <ParamInput
267
+ type={param.type}
268
+ value={paramValues[param.name] ?? ''}
269
+ onChange={(value) => setParamValues((prev) => ({ ...prev, [param.name]: value }))}
270
+ values={param.spec.values}
271
+ defaultValue={param.defaultValue}
272
+ />
273
+ </div>
274
+ </div>
275
+ </li>
276
+ );
277
+
278
+ return (
279
+ <div className='max-w-4xl mx-auto p-6'>
280
+ <h1 className='text-3xl font-bold mb-4'>Configure a Run</h1>
281
+ <p className='text-gray-700 mb-6'>
282
+ Configure the experiment by setting parameter values below. Fields left empty will be
283
+ assigned their default value. Once configured, you can copy the URL to run the experiment
284
+ with these settings.
285
+ </p>
286
+
287
+ <div className='bg-white shadow overflow-hidden sm:rounded-md mb-8'>
288
+ <div className='px-4 py-5 border-b border-gray-200 sm:px-6'>
289
+ <h2 className='text-lg font-medium text-gray-900'>Experiment Parameters</h2>
290
+ <p className='mt-1 text-sm text-gray-500'>
291
+ The experiment's own parameters.
292
+ </p>
293
+ </div>
294
+ {experimentFields.length === 0 ? (
295
+ <p className='px-4 py-5 sm:px-6 text-sm text-gray-500 italic'>
296
+ This experiment declares no parameters.
297
+ </p>
298
+ ) : (
299
+ <ul className='divide-y divide-gray-200'>{experimentFields.map(renderParamRow)}</ul>
300
+ )}
301
+ </div>
302
+
303
+ {drawnFields.length > 0 && (
304
+ <div className='bg-amber-50 border border-amber-200 text-amber-900 sm:rounded-md p-4 mb-8 text-sm'>
305
+ The settings and trials below are for{' '}
306
+ {drawnFields.map((field, index) => (
307
+ <span key={field.name}>
308
+ {index > 0 && ', '}
309
+ <code>{field.name}</code> = <code>{JSON.stringify(initial.defaults[field.name])}</code>
310
+ </span>
311
+ ))}
312
+ , drawn at random for this page. Each participant gets values of their own, which can build other
313
+ trials; choose a value above to see the trials it builds.
314
+ </div>
315
+ )}
316
+
317
+ {current.error !== undefined && (
318
+ <div className='bg-red-50 border border-red-200 text-red-800 sm:rounded-md p-4 mb-8 text-sm'>
319
+ These parameters do not build a timeline: {current.error}
320
+ </div>
321
+ )}
322
+
323
+ {current.problems.length > 0 && (
324
+ <div className='bg-red-50 border border-red-200 text-red-800 sm:rounded-md p-4 mb-8 text-sm'>
325
+ Participants could not start with this link: {current.problems.join(' ')}
326
+ </div>
327
+ )}
328
+
329
+ <div className='bg-white shadow overflow-hidden sm:rounded-md mb-8'>
330
+ <div className='px-4 py-5 border-b border-gray-200 sm:px-6'>
331
+ <h2 className='text-lg font-medium text-gray-900'>Settings</h2>
332
+ <p className='mt-1 text-sm text-gray-500'>
333
+ General settings, and those of the components in the selected trials.
334
+ </p>
335
+ </div>
336
+ {settingGroups.map((group) => (
337
+ <div key={group.title} className='border-b border-gray-200 last:border-b-0'>
338
+ <h3 className='px-4 pt-4 sm:px-6 text-sm font-semibold text-gray-700'>{group.title}</h3>
339
+ <ul className='divide-y divide-gray-200'>{group.fields.map(renderParamRow)}</ul>
340
+ </div>
341
+ ))}
342
+ </div>
343
+
344
+ <div className='bg-white shadow overflow-hidden sm:rounded-md mb-8'>
345
+ <div className='px-4 py-5 border-b border-gray-200 sm:px-6'>
346
+ <div className='flex justify-between items-center'>
347
+ <div>
348
+ <h2 className='text-lg font-medium text-gray-900'>Custom Parameters</h2>
349
+ <p className='mt-1 text-sm text-gray-500'>
350
+ Add any additional parameters to be stored in the data for this run.
351
+ </p>
352
+ </div>
353
+ <button
354
+ onClick={() => setCustomParams((prev) => [...prev, { name: '', value: '' }])}
355
+ className='inline-flex cursor-pointer items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500'
356
+ >
357
+ <svg
358
+ xmlns='http://www.w3.org/2000/svg'
359
+ className='-ml-1 mr-2 h-5 w-5'
360
+ viewBox='0 0 20 20'
361
+ fill='currentColor'
362
+ >
363
+ <path
364
+ fillRule='evenodd'
365
+ d='M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z'
366
+ clipRule='evenodd'
367
+ />
368
+ </svg>
369
+ Add Parameter
370
+ </button>
371
+ </div>
372
+ </div>
373
+
374
+ <div className='px-4 py-5 sm:px-6'>
375
+ {customParams.length === 0 ? (
376
+ <p className='text-sm text-gray-500 italic'>
377
+ No custom parameters added. Click "Add Parameter" to create one.
378
+ </p>
379
+ ) : (
380
+ <div>
381
+ <div className='grid grid-cols-12 gap-2 mb-2'>
382
+ <div className='col-span-3'>
383
+ <label className='block text-xs font-medium text-gray-500'>PARAMETER NAME</label>
384
+ </div>
385
+ <div className='col-span-8'>
386
+ <label className='block text-xs font-medium text-gray-500'>VALUE</label>
387
+ </div>
388
+ <div className='col-span-1'></div>
389
+ </div>
390
+ {customParams.map(renderCustomParamInput)}
391
+ </div>
392
+ )}
393
+ </div>
394
+ </div>
395
+
396
+ {current.entries.length > 0 && (
397
+ <div className='bg-white shadow overflow-hidden sm:rounded-md mb-8'>
398
+ <div className='px-4 py-5 border-b border-gray-200 sm:px-6'>
399
+ <h2 className='text-lg font-medium text-gray-900'>Trial Selection</h2>
400
+ <p className='mt-1 text-sm text-gray-500'>
401
+ The checked trials run. A trial that other parameter values add runs too.
402
+ </p>
403
+ </div>
404
+
405
+ <div className='px-4 py-5 sm:px-6'>
406
+
407
+ <div className='border border-gray-200 rounded-md overflow-hidden'>
408
+ <ul className='divide-y divide-gray-200'>
409
+ {rowsOf(current.entries).map((row) => {
410
+ const indent = { paddingLeft: `${16 + row.depth * 24}px` };
411
+ if ('elseAt' in row) {
412
+ return (
413
+ <li key={`else-${row.elseAt}`} style={indent} className='py-1 text-xs font-medium text-gray-400'>
414
+ else
415
+ </li>
416
+ );
417
+ }
418
+ const { entry } = row;
419
+ const leaves = leavesOf([entry]);
420
+ const running = leaves.filter(runs).length;
421
+ const label = (
422
+ <>
423
+ <div className='ml-3 w-12 text-xs text-gray-500 font-medium'>#{entry.position}</div>
424
+ <div className='flex-grow'>
425
+ {entry.name ? (
426
+ <span className='font-medium text-gray-900'>{entry.name}</span>
427
+ ) : (
428
+ <span className='font-medium text-gray-500'>{entry.type}</span>
429
+ )}
430
+ </div>
431
+ <span className='ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800'>
432
+ {entry.type}
433
+ </span>
434
+ </>
435
+ );
436
+ // Markers, and blocks that hold nothing else, always stay
437
+ if (leaves.length === 0) {
438
+ return (
439
+ <li key={entry.position} style={indent} className='flex items-center pr-4 py-3 text-gray-500'>
440
+ <div className='h-4 w-4' />
441
+ {label}
442
+ </li>
443
+ );
444
+ }
445
+ // A block's box stands for everything in it
446
+ return (
447
+ <li key={entry.position} className='hover:bg-gray-50'>
448
+ <label style={indent} className='flex items-center pr-4 py-3 cursor-pointer'>
449
+ <input
450
+ type='checkbox'
451
+ className='h-4 w-4 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded cursor-pointer'
452
+ checked={running === leaves.length}
453
+ ref={(input) => {
454
+ if (input) input.indeterminate = running > 0 && running < leaves.length;
455
+ }}
456
+ onChange={() =>
457
+ setToggled((prev) => ({
458
+ ...prev,
459
+ ...Object.fromEntries(leaves.map((leaf) => [leaf.id, running < leaves.length])),
460
+ }))
461
+ }
462
+ />
463
+ {label}
464
+ </label>
465
+ </li>
466
+ );
467
+ })}
468
+ </ul>
469
+ </div>
470
+ </div>
471
+ </div>
472
+ )}
473
+
474
+ <div className='bg-white shadow sm:rounded-md p-6 mb-8'>
475
+ <div className='flex justify-between items-center mb-4'>
476
+ <h2 className='text-lg font-medium'>Generated URL</h2>
477
+ <div className='flex items-center'>
478
+ <Switch on={useBase64} onClick={() => setUseBase64((prev) => !prev)} />
479
+ <span className='ml-2 text-sm text-gray-600'>
480
+ {useBase64 ? 'Base64 Encoded' : 'Plain Parameters'}
481
+ </span>
482
+ </div>
483
+ </div>
484
+ <div className='flex flex-col md:flex-row gap-3'>
485
+ <input
486
+ ref={urlInputRef}
487
+ type='text'
488
+ className='flex-grow px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-blue-500 focus:border-blue-500 sm:text-sm'
489
+ value={generatedUrl}
490
+ readOnly
491
+ />
492
+ <button
493
+ onClick={handleCopyUrl}
494
+ className='inline-flex cursor-pointer justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500'
495
+ >
496
+ {copied ? 'Copied!' : 'Copy URL'}
497
+ </button>
498
+ </div>
499
+ {useBase64 && (
500
+ <p className='mt-4 text-sm text-gray-600'>
501
+ <span className='font-medium'>Note:</span> Base64 encoding combines all parameters into
502
+ a single "_b" parameter, creating shorter URLs that hide parameter details.
503
+ </p>
504
+ )}
505
+ </div>
506
+
507
+ <div className='flex justify-center'>
508
+ <a
509
+ href={generatedUrl}
510
+ className='inline-flex justify-center py-4 px-5 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-green-600 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-green-500'
511
+ >
512
+ Launch Experiment with these Settings
513
+ </a>
514
+ </div>
515
+ </div>
516
+ );
517
+ };
@@ -18,7 +18,6 @@ const DARK_TOKENS = {
18
18
  buttonDisabledBorder: 'border-gray-600',
19
19
  buttonDisabledShadow: 'shadow-[2px_2px_0px_rgba(75,85,99,1)]',
20
20
  error: 'text-red-400',
21
- focusRing: 'focus:ring-blue-400',
22
21
  inputBg: 'bg-gray-700',
23
22
  inputBorder: 'border-gray-500',
24
23
  inputText: 'text-[#f5f5f5]',
@@ -30,7 +29,7 @@ const DARK_TOKENS = {
30
29
  toastTheme: 'dark' as const,
31
30
  } as const;
32
31
 
33
- export const THEME = {
32
+ const THEME = {
34
33
  light: {
35
34
  containerBg: '',
36
35
  text: 'text-black',
@@ -45,7 +44,6 @@ export const THEME = {
45
44
  buttonDisabledBorder: 'border-gray-400',
46
45
  buttonDisabledShadow: 'shadow-[2px_2px_0px_rgba(156,163,175,1)]',
47
46
  error: 'text-red-500',
48
- focusRing: 'focus:ring-blue-500',
49
47
  inputBg: '',
50
48
  inputBorder: 'border-black',
51
49
  inputText: '',
@@ -66,10 +64,13 @@ export const THEME = {
66
64
  },
67
65
  } as const;
68
66
 
69
- export const LIGHT_DOT_BG_CLASS = 'reactive-light-dot-bg';
70
- export const DARK_BG_CLASS = 'reactive-dark-bg';
71
- export const DARK_BG_PLAIN_CLASS = 'reactive-dark-bg-plain';
72
-
73
67
  export function t(theme: Theme) {
74
- return THEME[theme];
68
+ const tokens = THEME[theme];
69
+ return {
70
+ ...tokens,
71
+ /** The button that ends a screen. */
72
+ button: `${tokens.buttonBg} cursor-pointer px-8 py-3 border-2 ${tokens.buttonBorder} font-bold ${tokens.buttonText} text-lg rounded-xl ${tokens.buttonShadow} hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-none`,
73
+ /** A screen's text. */
74
+ article: `prose prose-2xl ${tokens.prose} text-xl ${tokens.proseLink} prose-a:underline prose-h1:text-4xl prose-h1:mb-10 prose-h1:font-bold prose-p:mb-4 prose-strong:font-bold ${tokens.text} leading-relaxed`,
75
+ };
75
76
  }
package/src/server.ts ADDED
@@ -0,0 +1,93 @@
1
+ // The server side of Upload: where a session's files and the recordings uploaded during it are saved
2
+ import fs from 'fs/promises';
3
+ import path from 'path';
4
+
5
+ interface ReceivedFile {
6
+ filename: string;
7
+ content: string; // base64 or text content
8
+ encoding: 'base64' | 'utf8';
9
+ }
10
+
11
+ interface UploadRequest {
12
+ sessionId: string;
13
+ uploadId?: string;
14
+ parentFolder?: string;
15
+ files: ReceivedFile[];
16
+ }
17
+
18
+ // Session ids, folder names and filenames become path segments, so they must not escape the data folder
19
+ function isPlainName(name: unknown): boolean {
20
+ return typeof name === 'string' && name !== '' && name !== '.' && name !== '..' && path.basename(name) === name;
21
+ }
22
+
23
+ function isUploadRequest(data: Partial<UploadRequest> | null): data is UploadRequest {
24
+ return (
25
+ data !== null &&
26
+ isPlainName(data.sessionId) &&
27
+ (data.uploadId === undefined || isPlainName(data.uploadId)) &&
28
+ (data.parentFolder === undefined || isPlainName(data.parentFolder)) &&
29
+ Array.isArray(data.files) &&
30
+ data.files.every(
31
+ (file: Partial<ReceivedFile> | null) =>
32
+ file !== null &&
33
+ isPlainName(file.filename) &&
34
+ typeof file.content === 'string' &&
35
+ (file.encoding === 'base64' || file.encoding === 'utf8'),
36
+ )
37
+ );
38
+ }
39
+
40
+ const exists = (target: string) => fs.access(target).then(() => true, () => false);
41
+
42
+ async function getUniqueDir(parent: string, base: string): Promise<string> {
43
+ let candidate = path.join(parent, base);
44
+ for (let counter = 1; await exists(candidate); counter++) {
45
+ candidate = path.join(parent, `${base}_${counter}`);
46
+ }
47
+ return candidate;
48
+ }
49
+
50
+ async function saveData(req: Request, dataFolder: string): Promise<Response> {
51
+ const data = await req.json().catch(() => null);
52
+ if (!isUploadRequest(data)) {
53
+ return Response.json({ status: 400, message: 'Invalid upload request' }, { status: 400 });
54
+ }
55
+
56
+ try {
57
+ // Recordings uploaded during the session wait in a folder named after its upload id. That folder is
58
+ // the session's own, unless the session has another id or goes into a parent folder; then they move.
59
+ const eagerDir = path.join(dataFolder, data.uploadId ?? data.sessionId);
60
+ let dataDir = eagerDir;
61
+ if (data.uploadId || data.parentFolder) {
62
+ const parentDir = path.join(dataFolder, data.parentFolder ?? '');
63
+ await fs.mkdir(parentDir, { recursive: true });
64
+ dataDir = await getUniqueDir(parentDir, data.sessionId);
65
+ if (await exists(eagerDir)) await fs.rename(eagerDir, dataDir);
66
+ }
67
+
68
+ await fs.mkdir(dataDir, { recursive: true });
69
+
70
+ await Promise.all(
71
+ data.files.map((file) =>
72
+ Bun.write(
73
+ path.join(dataDir, file.filename),
74
+ file.encoding === 'base64' ? Buffer.from(file.content, 'base64') : file.content,
75
+ ),
76
+ ),
77
+ );
78
+
79
+ return Response.json({ status: 200, message: 'Files saved successfully' });
80
+ } catch (error) {
81
+ console.error('Error saving files:', error);
82
+ return Response.json({ status: 500, message: 'Error saving files' }, { status: 500 });
83
+ }
84
+ }
85
+
86
+ /**
87
+ * The route that saves uploaded data in `dataFolder`, one folder per session, inside the folder
88
+ * Upload's `parentFolder` names if it sets one. Mount it in the project's server with
89
+ * `...uploadRoutes(dataFolder)`.
90
+ */
91
+ export function uploadRoutes(dataFolder: string) {
92
+ return { '/backend/data': { POST: (req: Request) => saveData(req, dataFolder) } };
93
+ }
@@ -0,0 +1,3 @@
1
+ // Needs motion: bunx @adriansteffan/reactive add tutorial
2
+ export { Tutorial, useTutorialSlide } from './components/tutorial';
3
+ export type { TutorialProps } from './components/tutorial';