@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
@@ -1,12 +1,31 @@
1
1
  import React, { useState, useRef, useEffect, forwardRef, useImperativeHandle } from 'react';
2
- import { HiMicrophone, HiStop, HiTrash, HiPause } from 'react-icons/hi2';
3
- import { useTheme, t } from '../utils/theme';
4
- import { useAudioDeviceId } from '../utils/audiodevice';
5
-
6
- interface RecordingData {
7
- blob: Blob;
8
- url: string;
9
- timestamp: string;
2
+ import { MicrophoneIcon, PauseIcon, StopIcon, TrashIcon } from './icons';
3
+ import { useTheme, t } from '../runner/theme';
4
+ import { useAudioDeviceId } from '../runner/contexts';
5
+
6
+ // An analyser of the stream's sound, with room for its samples, and a function that stops it
7
+ function analyse(stream: MediaStream) {
8
+ const AudioContextClass = window.AudioContext ?? (window as any).webkitAudioContext;
9
+ const audioContext = new AudioContextClass();
10
+ const analyser = audioContext.createAnalyser();
11
+ analyser.fftSize = 2048;
12
+ const source = audioContext.createMediaStreamSource(stream);
13
+ source.connect(analyser);
14
+ const close = () => {
15
+ source.disconnect();
16
+ audioContext.close();
17
+ };
18
+ return { analyser, samples: new Uint8Array(analyser.fftSize), close };
19
+ }
20
+
21
+ // The loudness of the samples, which are centered at 128
22
+ function rms(samples: Uint8Array): number {
23
+ let sumOfSquares = 0;
24
+ for (const sample of samples) {
25
+ const normalized = (sample - 128) / 128;
26
+ sumOfSquares += normalized * normalized;
27
+ }
28
+ return Math.sqrt(sumOfSquares / samples.length);
10
29
  }
11
30
 
12
31
  const AudioVisualizer: React.FC<{ stream: MediaStream; isDark: boolean }> = ({ stream, isDark }) => {
@@ -15,18 +34,10 @@ const AudioVisualizer: React.FC<{ stream: MediaStream; isDark: boolean }> = ({ s
15
34
 
16
35
  useEffect(() => {
17
36
  if (!stream || !canvasRef.current) return;
18
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
19
- //@ts-ignore
20
- const audioContext = new (window.AudioContext || window.webkitAudioContext)();
21
- const analyser = audioContext.createAnalyser();
22
- const source = audioContext.createMediaStreamSource(stream);
23
-
24
- analyser.fftSize = 2048;
25
- source.connect(analyser);
26
-
27
37
  const canvas = canvasRef.current;
28
38
  const ctx = canvas.getContext('2d', { alpha: false });
29
39
  if (!ctx) return;
40
+ const { analyser, samples, close } = analyse(stream);
30
41
 
31
42
  const dpr = window.devicePixelRatio || 1;
32
43
  const rect = canvas.getBoundingClientRect();
@@ -36,7 +47,6 @@ const AudioVisualizer: React.FC<{ stream: MediaStream; isDark: boolean }> = ({ s
36
47
  canvas.style.width = `${rect.width}px`;
37
48
  canvas.style.height = `${rect.height}px`;
38
49
 
39
- const timeData = new Uint8Array(analyser.fftSize);
40
50
  const bgColor = isDark ? '#374151' : '#ffffff';
41
51
  const activeColor = isDark ? '#ffffff' : '#000000';
42
52
  const dimColor = isDark ? '#4B5563' : '#E5E7EB';
@@ -49,15 +59,8 @@ const AudioVisualizer: React.FC<{ stream: MediaStream; isDark: boolean }> = ({ s
49
59
 
50
60
  const draw = () => {
51
61
  animationRef.current = requestAnimationFrame(draw);
52
- analyser.getByteTimeDomainData(timeData);
53
-
54
- // Compute RMS volume from time-domain samples (centered at 128)
55
- let sumOfSquares = 0;
56
- for (let i = 0; i < timeData.length; i++) {
57
- const normalized = (timeData[i] - 128) / 128;
58
- sumOfSquares += normalized * normalized;
59
- }
60
- const volumeLevel = Math.min(1, Math.sqrt(sumOfSquares / timeData.length) * 5);
62
+ analyser.getByteTimeDomainData(samples);
63
+ const volumeLevel = Math.min(1, rms(samples) * 5);
61
64
  smoothedLevel += (volumeLevel - smoothedLevel) * 0.3;
62
65
 
63
66
  ctx.fillStyle = bgColor;
@@ -74,8 +77,7 @@ const AudioVisualizer: React.FC<{ stream: MediaStream; isDark: boolean }> = ({ s
74
77
 
75
78
  return () => {
76
79
  if (animationRef.current) cancelAnimationFrame(animationRef.current);
77
- source.disconnect();
78
- audioContext.close();
80
+ close();
79
81
  };
80
82
  }, [stream, isDark]);
81
83
 
@@ -89,12 +91,11 @@ const AudioVisualizer: React.FC<{ stream: MediaStream; isDark: boolean }> = ({ s
89
91
  );
90
92
  };
91
93
 
92
- export interface VoiceRecorderHandle {
94
+ export interface RecorderHandle {
93
95
  stop: () => void;
94
96
  }
95
97
 
96
- export interface VoiceRecorderProps {
97
- question?: { value: RecordingData | null };
98
+ interface RecorderProps {
98
99
  handleSaveVoiceData: (data: object) => void;
99
100
  handleDiscardVoiceData: () => void;
100
101
  deviceId?: string;
@@ -104,19 +105,17 @@ export interface VoiceRecorderProps {
104
105
  /** Show a discard button while recording to delete and start over. */
105
106
  showDiscard?: boolean;
106
107
  /** Label for the post-recording discard button. */
107
- discardLabel?: string;
108
- /** If set, show a "speak up" banner after this many seconds of continuous silence. Disabled when undefined. */
109
- silenceWarningSec?: number;
108
+ discardButtonText?: string;
109
+ /** If set, show a "speak up" banner after this many milliseconds of continuous silence. Disabled when undefined. */
110
+ silenceWarningMs?: number;
110
111
  /** Text shown in the silence banner. */
111
- silenceWarningText?: string;
112
+ silenceWarningContent?: React.ReactNode;
112
113
  onRecordingStart?: () => void;
113
114
  onPause?: (duration: number) => void;
114
115
  onResume?: () => void;
115
116
  }
116
117
 
117
- export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>(({
118
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
119
- question: _question,
118
+ export const Recorder = forwardRef<RecorderHandle, RecorderProps>(({
120
119
  handleSaveVoiceData,
121
120
  handleDiscardVoiceData,
122
121
  deviceId,
@@ -124,9 +123,9 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
124
123
  showStop = true,
125
124
  showVisualizer = true,
126
125
  showDiscard = true,
127
- discardLabel = 'New Recording',
128
- silenceWarningSec,
129
- silenceWarningText = 'We can\'t hear you — please speak up',
126
+ discardButtonText = 'New Recording',
127
+ silenceWarningMs,
128
+ silenceWarningContent = "We can't hear you — please speak up",
130
129
  onRecordingStart,
131
130
  onPause,
132
131
  onResume,
@@ -156,7 +155,9 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
156
155
  const recorder = mediaRecorderRef.current;
157
156
  if (recorder && (recorder.state === 'recording' || recorder.state === 'paused')) {
158
157
  recorder.stop();
159
- recorder.stream.getTracks().forEach((track) => track.stop());
158
+ recorder.stream.getTracks().forEach((track) => {
159
+ track.stop();
160
+ });
160
161
  setIsRecording(false);
161
162
  setIsPaused(false);
162
163
  clearTimer();
@@ -166,32 +167,20 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
166
167
  useImperativeHandle(ref, () => ({ stop: stopRecording }));
167
168
 
168
169
  // Silence detection: analyze the mic stream every 100ms; trigger banner when
169
- // RMS stays below threshold for silenceWarningSec seconds continuously.
170
+ // RMS stays below threshold for silenceWarningMs continuously.
170
171
  useEffect(() => {
171
- if (!audioStream || !silenceWarningSec || isPaused) {
172
+ if (!audioStream || !silenceWarningMs || isPaused) {
172
173
  setShowSilenceBanner(false);
173
174
  return;
174
175
  }
175
- const AudioCtx = (window.AudioContext || (window as any).webkitAudioContext);
176
- const audioCtx = new AudioCtx();
177
- const analyser = audioCtx.createAnalyser();
178
- analyser.fftSize = 2048;
179
- const source = audioCtx.createMediaStreamSource(audioStream);
180
- source.connect(analyser);
181
- const timeData = new Uint8Array(analyser.fftSize);
176
+ const { analyser, samples, close } = analyse(audioStream);
182
177
 
183
178
  let silenceMs = 0;
184
179
  const tick = setInterval(() => {
185
- analyser.getByteTimeDomainData(timeData);
186
- let sum = 0;
187
- for (let i = 0; i < timeData.length; i++) {
188
- const n = (timeData[i] - 128) / 128;
189
- sum += n * n;
190
- }
191
- const rms = Math.sqrt(sum / timeData.length);
192
- if (rms < 0.02) {
180
+ analyser.getByteTimeDomainData(samples);
181
+ if (rms(samples) < 0.02) {
193
182
  silenceMs += 100;
194
- if (silenceMs >= silenceWarningSec * 1000) setShowSilenceBanner(true);
183
+ if (silenceMs >= silenceWarningMs) setShowSilenceBanner(true);
195
184
  } else {
196
185
  silenceMs = 0;
197
186
  setShowSilenceBanner(false);
@@ -200,11 +189,10 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
200
189
 
201
190
  return () => {
202
191
  clearInterval(tick);
203
- source.disconnect();
204
- audioCtx.close();
192
+ close();
205
193
  setShowSilenceBanner(false);
206
194
  };
207
- }, [audioStream, silenceWarningSec, isPaused]);
195
+ }, [audioStream, silenceWarningMs, isPaused]);
208
196
 
209
197
  const startRecording = async () => {
210
198
  try {
@@ -266,26 +254,24 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
266
254
  };
267
255
 
268
256
  const saveRecording = async (blob: Blob, url: string) => {
269
- if (blob && url) {
270
- const base64Data = await new Promise<string>((resolve) => {
271
- const reader = new FileReader();
272
- reader.onloadend = () => {
273
- const base64 = reader.result?.toString().split(',')[1] || '';
274
- resolve(base64);
275
- };
276
- reader.readAsDataURL(blob);
277
- });
278
-
279
- handleSaveVoiceData({
280
- blob: blob,
281
- // dont change this type, since the upload function depends on it while looking for audio
282
- type: 'audiorecording',
283
- url: url,
284
- data64: base64Data,
285
- timestamp: new Date().toISOString(),
286
- recordingDuration: durationRef.current,
287
- });
288
- }
257
+ const base64Data = await new Promise<string>((resolve) => {
258
+ const reader = new FileReader();
259
+ reader.onloadend = () => {
260
+ const base64 = reader.result?.toString().split(',')[1] || '';
261
+ resolve(base64);
262
+ };
263
+ reader.readAsDataURL(blob);
264
+ });
265
+
266
+ handleSaveVoiceData({
267
+ blob: blob,
268
+ // dont change this type, since the upload function depends on it while looking for audio
269
+ type: 'audiorecording',
270
+ url: url,
271
+ data64: base64Data,
272
+ timestamp: new Date().toISOString(),
273
+ recordingDurationMs: durationRef.current,
274
+ });
289
275
  };
290
276
 
291
277
  const discardWhileRecording = () => {
@@ -295,7 +281,9 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
295
281
  chunksRef.current = [];
296
282
  recorder.onstop = null;
297
283
  recorder.stop();
298
- recorder.stream.getTracks().forEach((track) => track.stop());
284
+ recorder.stream.getTracks().forEach((track) => {
285
+ track.stop();
286
+ });
299
287
  }
300
288
  setIsRecording(false);
301
289
  setIsPaused(false);
@@ -319,7 +307,7 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
319
307
  <div className='flex flex-col items-center space-y-4 p-4 px-8'>
320
308
  {showSilenceBanner && (
321
309
  <div className='fixed top-0 left-0 right-0 z-40 bg-yellow-300 text-black text-center py-3 px-4 border-b-2 border-black font-semibold shadow-[0px_2px_0px_rgba(0,0,0,1)]'>
322
- {silenceWarningText}
310
+ {silenceWarningContent}
323
311
  </div>
324
312
  )}
325
313
  {/* Start button */}
@@ -329,7 +317,7 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
329
317
  className={`${btnBase} ${th.buttonBg}`}
330
318
  aria-label='Start Recording'
331
319
  >
332
- <HiMicrophone className={`w-6 h-6 ${th.buttonText}`} />
320
+ <MicrophoneIcon className={`w-6 h-6 ${th.buttonText}`} />
333
321
  </button>
334
322
  )}
335
323
 
@@ -343,9 +331,9 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
343
331
  aria-label={isPaused ? 'Resume Recording' : 'Pause Recording'}
344
332
  >
345
333
  {isPaused ? (
346
- <HiMicrophone className={`w-6 h-6 ${th.buttonText}`} />
334
+ <MicrophoneIcon className={`w-6 h-6 ${th.buttonText}`} />
347
335
  ) : (
348
- <HiPause className={`w-6 h-6 ${th.buttonText}`} />
336
+ <PauseIcon className={`w-6 h-6 ${th.buttonText}`} />
349
337
  )}
350
338
  </button>
351
339
  )}
@@ -355,7 +343,7 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
355
343
  className={`${btnBase} bg-red-500 text-white`}
356
344
  aria-label='Stop Recording'
357
345
  >
358
- <HiStop className='w-6 h-6' />
346
+ <StopIcon className='w-6 h-6' />
359
347
  </button>
360
348
  )}
361
349
  {showDiscard && isPaused && (
@@ -364,7 +352,7 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
364
352
  className={`${btnBase} ${th.buttonBg}`}
365
353
  aria-label='Discard Recording'
366
354
  >
367
- <HiTrash className={`w-6 h-6 ${th.buttonText}`} />
355
+ <TrashIcon className={`w-6 h-6 ${th.buttonText}`} />
368
356
  </button>
369
357
  )}
370
358
  </div>
@@ -399,8 +387,8 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
399
387
  onClick={discardRecording}
400
388
  className={`border-2 ${th.buttonBorder} ${th.buttonShadow} hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-none cursor-pointer flex items-center space-x-2 px-4 py-2 ${th.text} rounded-xl transition-colors duration-200`}
401
389
  >
402
- <HiTrash className='w-4 h-4' />
403
- <span>{discardLabel}</span>
390
+ <TrashIcon className='w-4 h-4' />
391
+ <span>{discardButtonText}</span>
404
392
  </button>
405
393
  </div>
406
394
  </div>
@@ -409,16 +397,3 @@ export const VoiceRecorder = forwardRef<VoiceRecorderHandle, VoiceRecorderProps>
409
397
  );
410
398
  });
411
399
 
412
-
413
- export default function VoicerecorderQuestionComponent({
414
- setValue,
415
- }: {
416
- setValue: (data: object | null) => void;
417
- }) {
418
- return (
419
- <VoiceRecorder
420
- handleSaveVoiceData={(data) => setValue(data)}
421
- handleDiscardVoiceData={() => setValue(null)}
422
- />
423
- );
424
- }
@@ -0,0 +1,63 @@
1
+ import { BaseComponentProps } from '../core/component';
2
+ import { type ReactNode, useEffect, useState } from 'react';
3
+ import { noopSimulate } from '../core/simulation';
4
+ import { defineComponent } from '../core/component';
5
+ import { getNative } from '../core/platform';
6
+ import { t, useTheme } from '../runner/theme';
7
+
8
+ function RequestFilePermission({
9
+ next,
10
+ content = (
11
+ <>
12
+ <p>Storage permission is required to save your data.</p>
13
+ <p>Please grant permission when prompted.</p>
14
+ <p>If there is no popup, go to "Settings" {">"} "Apps" {">"} "Name of the App" {">"} "Permissions" {">"} "Storage" {">"} "Allow"</p>
15
+ </>
16
+ ),
17
+ buttonText = 'Try Again',
18
+ }: BaseComponentProps & {
19
+ /** Shown when the app may not save files. */
20
+ content?: ReactNode;
21
+ buttonText?: string;
22
+ }) {
23
+ const [checking, setChecking] = useState(true);
24
+ const th = t(useTheme());
25
+
26
+ useEffect(() => {
27
+ if (!checking) return;
28
+
29
+ const checkPermission = async () => {
30
+ const native = getNative();
31
+ if (!native || (await native.canWriteFiles())) {
32
+ next({});
33
+ } else {
34
+ setChecking(false);
35
+ }
36
+ };
37
+
38
+ checkPermission();
39
+ }, [next, checking]);
40
+
41
+ if (checking) {
42
+ return null;
43
+ }
44
+
45
+ return (
46
+ <div className="flex flex-col items-center justify-center gap-4 p-6 text-xl mt-16 px-10">
47
+ {content}
48
+ <button
49
+ onClick={() => setChecking(true)}
50
+ className={`mt-8 ${th.button}`}
51
+ >
52
+ {buttonText}
53
+ </button>
54
+ </div>
55
+ );
56
+ }
57
+
58
+ export default defineComponent({
59
+ name: 'RequestFilePermission',
60
+ component: RequestFilePermission,
61
+ csv: null,
62
+ simulate: noopSimulate,
63
+ });