@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.
- package/README.md +796 -229
- package/bin/add.js +56 -0
- package/bin/deploy.js +48 -0
- package/bin/download.js +28 -0
- package/bin/ghsetup.js +21 -0
- package/bin/native.js +81 -0
- package/bin/setup.js +11 -17
- package/bin/study-deploy.js +60 -0
- package/bin/undeploy.js +15 -0
- package/extras/transcription/compose.yaml +32 -0
- package/{template → extras}/transcription/transcribe.py +4 -9
- package/package.json +62 -64
- package/src/bun-env.d.ts +1 -0
- package/src/bun-plugin.ts +22 -0
- package/src/components/canvasblock.tsx +209 -537
- package/src/components/checkdevice.tsx +64 -84
- package/src/components/fullscreenblock.tsx +130 -0
- package/src/components/icons.tsx +50 -0
- package/src/components/index.ts +9 -11
- package/src/components/microphonecheck.tsx +76 -38
- package/src/components/plaininput.tsx +48 -41
- package/src/components/prolificending.tsx +64 -28
- package/src/components/quest.tsx +89 -87
- package/src/components/{randomdotkinetogram.tsx → randomdotkinematogram.tsx} +205 -267
- package/src/components/{voicerecorder.tsx → recorder.tsx} +81 -106
- package/src/components/requestfilepermission.tsx +63 -0
- package/src/components/stimulus.tsx +373 -0
- package/src/components/storeui.tsx +94 -148
- package/src/components/text.tsx +61 -59
- package/src/components/tutorial.tsx +45 -47
- package/src/components/upload.tsx +133 -309
- package/src/components/voicerecording.tsx +90 -94
- package/src/core/backend.ts +20 -0
- package/src/core/bytecode.ts +178 -0
- package/src/core/columns.ts +50 -0
- package/src/core/component.ts +238 -0
- package/src/core/development.ts +32 -0
- package/src/core/experiment.ts +263 -0
- package/src/core/files.ts +291 -0
- package/src/core/params.ts +166 -0
- package/src/core/platform.ts +29 -0
- package/src/core/rows.ts +106 -0
- package/src/core/simulation.ts +158 -0
- package/src/core/slides.ts +178 -0
- package/src/core/store.ts +22 -0
- package/src/core/timeline.ts +399 -0
- package/src/fonts/AtkinsonHyperlegible-Bold.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-BoldItalic.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-Italic.woff2 +0 -0
- package/src/fonts/AtkinsonHyperlegible-Regular.woff2 +0 -0
- package/src/index.css +5 -7
- package/src/mod.tsx +31 -17
- package/src/native.ts +127 -0
- package/src/quest.ts +2 -0
- package/src/runner/contexts.ts +35 -0
- package/src/runner/devpanel.tsx +68 -0
- package/src/runner/experimentrunner.tsx +210 -0
- package/src/runner/fullscreenguard.tsx +93 -0
- package/src/runner/paraminput.tsx +86 -0
- package/src/runner/progressbar.tsx +20 -0
- package/src/runner/settingsscreen.tsx +517 -0
- package/src/{utils → runner}/theme.ts +9 -8
- package/src/server.ts +93 -0
- package/src/tutorial.ts +3 -0
- package/src/utils/array.ts +30 -62
- package/src/utils/canvas.ts +66 -0
- package/src/utils/ddm.ts +47 -70
- package/src/utils/distributions.ts +352 -61
- package/src/utils/fullscreen.ts +38 -0
- package/src/utils/ids.ts +11 -0
- package/src/utils/keys.ts +46 -0
- package/src/utils/llm.ts +15 -15
- package/src/utils/time.ts +12 -0
- package/src/utils/tts.ts +24 -24
- package/template/.dockerignore +3 -1
- package/template/.env.example +5 -0
- package/template/.github/workflows/deploy.yml +25 -0
- package/template/.gitignore +14 -0
- package/template/Dockerfile +9 -14
- package/template/README.md +74 -214
- package/template/biome.json +34 -0
- package/template/build.ts +20 -0
- package/template/bunfig.toml +3 -0
- package/template/docker-compose.yaml +4 -33
- package/template/index.html +2 -2
- package/template/package.json +16 -89
- package/template/public/.gitkeep +0 -0
- package/template/server.ts +32 -0
- package/template/simulate.ts +4 -44
- package/template/src/Experiment.tsx +76 -128
- package/template/src/bun-env.d.ts +1 -0
- package/template/src/index.css +1 -9
- package/template/src/main.tsx +25 -10
- package/template/tsconfig.json +4 -6
- package/.claude/settings.local.json +0 -61
- package/.eslintrc.cjs +0 -18
- package/.playwright-mcp/console-2026-04-07T14-22-59-060Z.log +0 -1
- package/.prettierrc +0 -5
- package/Dockerfile +0 -20
- package/dist/mod-HDegGPrf.js +0 -87434
- package/dist/mod.d.ts +0 -946
- package/dist/reactive.es.js +0 -87
- package/dist/reactive.umd.js +0 -10255
- package/dist/style.css +0 -5
- package/dist/web-7BbR1Ad7.js +0 -435
- package/dist/web-CATfZO1Q.js +0 -12
- package/planned.md +0 -103
- package/postcss.config.js +0 -6
- package/raw-loader-hooks.mjs +0 -25
- package/raw-loader.mjs +0 -5
- package/rdk_doc.md +0 -341
- package/src/components/enterfullscreen.tsx +0 -230
- package/src/components/exitfullscreen.tsx +0 -113
- package/src/components/experimentprovider.tsx +0 -69
- package/src/components/experimentrunner.tsx +0 -497
- package/src/components/mobilefilepermission.tsx +0 -68
- package/src/components/settingsscreen.tsx +0 -770
- package/src/types/array.d.ts +0 -6
- package/src/utils/audiodevice.ts +0 -4
- package/src/utils/bytecode.ts +0 -261
- package/src/utils/common.ts +0 -291
- package/src/utils/ddm.test.ts +0 -233
- package/src/utils/distributions.test.ts +0 -209
- package/src/utils/nodecompat.ts +0 -11
- package/src/utils/overlays.ts +0 -19
- package/src/utils/request.ts +0 -25
- package/src/utils/simulation.ts +0 -299
- package/src/utils/upload.ts +0 -275
- package/src/vite-env.d.ts +0 -1
- package/template/.env.template +0 -2
- package/template/.eslintrc.cjs +0 -18
- package/template/.prettierrc +0 -5
- package/template/backend/package-lock.json +0 -2544
- package/template/backend/package.json +0 -31
- package/template/backend/src/backend.ts +0 -131
- package/template/backend/tsconfig.json +0 -110
- package/template/capacitor.config.ts +0 -15
- package/template/electron/main.js +0 -131
- package/template/electron/preload.js +0 -9
- package/template/electron.vite.config.js +0 -45
- package/template/package-lock.json +0 -12467
- package/template/postcss.config.js +0 -5
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Bold.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-BoldItalic.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Italic.ttf +0 -0
- package/template/public/Atkinson_Hyperlegible/AtkinsonHyperlegible-Regular.ttf +0 -0
- package/template/shared.vite.config.js +0 -39
- package/template/src/vite-env.d.ts +0 -2
- package/template/tsconfig.node.json +0 -12
- package/template/vite.config.js +0 -11
- package/tsconfig.json +0 -30
- package/tsconfig.node.json +0 -12
- package/vite.config.ts +0 -39
- /package/{template → extras}/transcription/Dockerfile.cpu +0 -0
- /package/{template → extras}/transcription/Dockerfile.gpu +0 -0
- /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 {
|
|
3
|
-
import { useTheme, t } from '../
|
|
4
|
-
import { useAudioDeviceId } from '../
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
94
|
+
export interface RecorderHandle {
|
|
93
95
|
stop: () => void;
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
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
|
-
|
|
108
|
-
/** If set, show a "speak up" banner after this many
|
|
109
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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) =>
|
|
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
|
|
170
|
+
// RMS stays below threshold for silenceWarningMs continuously.
|
|
170
171
|
useEffect(() => {
|
|
171
|
-
if (!audioStream || !
|
|
172
|
+
if (!audioStream || !silenceWarningMs || isPaused) {
|
|
172
173
|
setShowSilenceBanner(false);
|
|
173
174
|
return;
|
|
174
175
|
}
|
|
175
|
-
const
|
|
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(
|
|
186
|
-
|
|
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 >=
|
|
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
|
-
|
|
204
|
-
audioCtx.close();
|
|
192
|
+
close();
|
|
205
193
|
setShowSilenceBanner(false);
|
|
206
194
|
};
|
|
207
|
-
}, [audioStream,
|
|
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
|
-
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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) =>
|
|
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
|
-
{
|
|
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
|
-
<
|
|
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
|
-
<
|
|
334
|
+
<MicrophoneIcon className={`w-6 h-6 ${th.buttonText}`} />
|
|
347
335
|
) : (
|
|
348
|
-
<
|
|
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
|
-
<
|
|
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
|
-
<
|
|
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
|
-
<
|
|
403
|
-
<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
|
+
});
|