@adriansteffan/reactive 0.1.32 → 0.1.34
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/dist/{mod-BstzgRJu.js → mod-BpIlYaYt.js} +4439 -4418
- package/dist/mod.d.ts +57 -2
- package/dist/reactive.es.js +57 -55
- package/dist/reactive.umd.js +619 -619
- package/dist/style.css +1 -1
- package/dist/{web-BuhM8wPq.js → web-CFP76jkq.js} +1 -1
- package/dist/{web-DAsCmbYK.js → web-CoJYNnww.js} +1 -1
- package/package.json +1 -1
- package/src/components/quest.tsx +2 -2
- package/src/components/text.tsx +16 -2
- package/src/index.css +4 -0
- package/src/mod.tsx +1 -1
- package/src/utils/common.ts +8 -0
- package/src/utils/theme.ts +32 -23
package/package.json
CHANGED
package/src/components/quest.tsx
CHANGED
|
@@ -138,7 +138,7 @@ function Quest({
|
|
|
138
138
|
...surveyJson,
|
|
139
139
|
css: { ...defaultCss, root: 'sd-root-modern custom-root' },
|
|
140
140
|
});
|
|
141
|
-
survey.applyTheme(theme ?? (contextTheme
|
|
141
|
+
survey.applyTheme(theme ?? (contextTheme.startsWith('dark') ? ContrastDark : ContrastLight));
|
|
142
142
|
|
|
143
143
|
const saveResults = useCallback(
|
|
144
144
|
(sender: any) => {
|
|
@@ -149,7 +149,7 @@ function Quest({
|
|
|
149
149
|
|
|
150
150
|
survey.onComplete.add(saveResults);
|
|
151
151
|
|
|
152
|
-
const useCustomBg = !!containerClass || contextTheme
|
|
152
|
+
const useCustomBg = !!containerClass || contextTheme.startsWith('dark');
|
|
153
153
|
|
|
154
154
|
return (
|
|
155
155
|
<div className={`min-h-screen ${containerClass ?? th.containerBg}`}>
|
package/src/components/text.tsx
CHANGED
|
@@ -8,6 +8,9 @@ import { useTheme, t } from '../utils/theme';
|
|
|
8
8
|
registerFlattener('Text', 'text');
|
|
9
9
|
|
|
10
10
|
registerSimulation('Text', (trialProps, _experimentState, simulators, participant) => {
|
|
11
|
+
if (trialProps.duration != null) {
|
|
12
|
+
return { responseData: {}, participantState: participant, duration: trialProps.duration };
|
|
13
|
+
}
|
|
11
14
|
const result = simulators.respond(trialProps, participant);
|
|
12
15
|
return { responseData: result.value, participantState: result.participantState, duration: result.value.reactionTime };
|
|
13
16
|
}, {
|
|
@@ -26,6 +29,7 @@ function Text({
|
|
|
26
29
|
next,
|
|
27
30
|
animate = false,
|
|
28
31
|
allowedKeys = false,
|
|
32
|
+
duration,
|
|
29
33
|
}: {
|
|
30
34
|
content: React.ReactNode;
|
|
31
35
|
buttonText?: string;
|
|
@@ -35,15 +39,25 @@ function Text({
|
|
|
35
39
|
centered?: boolean;
|
|
36
40
|
animate?: boolean;
|
|
37
41
|
allowedKeys?: string[] | boolean;
|
|
42
|
+
/** Auto-advance after N ms. When set, no button is shown and key presses are ignored. */
|
|
43
|
+
duration?: number;
|
|
38
44
|
} & BaseComponentProps) {
|
|
39
45
|
const th = t(useTheme());
|
|
40
46
|
const startTimeRef = useRef<number>(0);
|
|
47
|
+
const timed = duration != null;
|
|
41
48
|
|
|
42
49
|
useEffect(() => {
|
|
43
50
|
window.scrollTo(0, 0);
|
|
44
51
|
}, []);
|
|
45
52
|
|
|
46
53
|
useEffect(() => {
|
|
54
|
+
if (!timed) return;
|
|
55
|
+
const timer = setTimeout(() => next({}), duration);
|
|
56
|
+
return () => clearTimeout(timer);
|
|
57
|
+
}, [timed, duration, next]);
|
|
58
|
+
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (timed) return;
|
|
47
61
|
startTimeRef.current = now();
|
|
48
62
|
|
|
49
63
|
const handleKeyPress = (event: KeyboardEvent) => {
|
|
@@ -73,7 +87,7 @@ function Text({
|
|
|
73
87
|
window.removeEventListener('keydown', handleKeyPress);
|
|
74
88
|
}
|
|
75
89
|
};
|
|
76
|
-
}, [next, allowedKeys]);
|
|
90
|
+
}, [next, allowedKeys, timed]);
|
|
77
91
|
|
|
78
92
|
const handleClick = () => {
|
|
79
93
|
const clickTime = now();
|
|
@@ -97,7 +111,7 @@ function Text({
|
|
|
97
111
|
{content}
|
|
98
112
|
</article>
|
|
99
113
|
|
|
100
|
-
{buttonText && (
|
|
114
|
+
{!timed && buttonText && (
|
|
101
115
|
<div
|
|
102
116
|
className={`mt-16 flex justify-center ${animate ? 'animate-fade-in opacity-0' : ''}`}
|
|
103
117
|
style={animate ? { animationDelay: '1s' } : {}}
|
package/src/index.css
CHANGED
package/src/mod.tsx
CHANGED
|
@@ -7,7 +7,7 @@ export * from './utils/common';
|
|
|
7
7
|
export * from './utils/simulation';
|
|
8
8
|
export { registerFlattener, arrayFlattener } from './utils/upload';
|
|
9
9
|
export { normal, poisson, uniform, seedDistributions, sobol, halton, sampleParticipants } from './utils/distributions';
|
|
10
|
-
export { useTheme, ThemeContext, THEME, t, DARK_BG_CLASS } from './utils/theme';
|
|
10
|
+
export { useTheme, ThemeContext, THEME, t, DARK_BG_CLASS, DARK_BG_PLAIN_CLASS } from './utils/theme';
|
|
11
11
|
export type { Theme } from './utils/theme';
|
|
12
12
|
export type { DimensionSpec, UniformSpec, NormalSpec, PoissonSpec, SamplingMethod } from './utils/distributions';
|
|
13
13
|
export { simulateDDMTrial, mapDDMChoice } from './utils/ddm';
|
package/src/utils/common.ts
CHANGED
|
@@ -54,6 +54,14 @@ export interface BaseComponentProps {
|
|
|
54
54
|
updateStore: (mergeIn: Store) => void;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
export function selectPrevTrialData(data: any[], type?: string): any | undefined {
|
|
58
|
+
if (!type) return data.at(-1);
|
|
59
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
60
|
+
if (data[i].type === type) return data[i];
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
57
65
|
type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'json';
|
|
58
66
|
|
|
59
67
|
type ParamValue<T extends ParamType> = T extends 'number'
|
package/src/utils/theme.ts
CHANGED
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
2
|
|
|
3
|
-
export type Theme = 'light' | 'dark';
|
|
3
|
+
export type Theme = 'light' | 'dark' | 'dark-plain';
|
|
4
4
|
|
|
5
5
|
export const ThemeContext = createContext<Theme>('light');
|
|
6
6
|
export const useTheme = () => useContext(ThemeContext);
|
|
7
7
|
|
|
8
|
+
const DARK_TOKENS = {
|
|
9
|
+
text: 'text-[#f5f5f5]',
|
|
10
|
+
prose: 'prose-invert',
|
|
11
|
+
proseLink: 'prose-a:text-blue-400',
|
|
12
|
+
buttonBg: 'bg-white',
|
|
13
|
+
buttonText: 'text-black',
|
|
14
|
+
buttonBorder: 'border-black',
|
|
15
|
+
buttonShadow: 'shadow-[2px_2px_0px_rgba(0,0,0,1)]',
|
|
16
|
+
buttonDisabledBg: 'bg-gray-700',
|
|
17
|
+
buttonDisabledText: 'text-gray-500',
|
|
18
|
+
buttonDisabledBorder: 'border-gray-600',
|
|
19
|
+
buttonDisabledShadow: 'shadow-[2px_2px_0px_rgba(75,85,99,1)]',
|
|
20
|
+
error: 'text-red-400',
|
|
21
|
+
focusRing: 'focus:ring-blue-400',
|
|
22
|
+
inputBg: 'bg-gray-700',
|
|
23
|
+
inputBorder: 'border-gray-500',
|
|
24
|
+
inputText: 'text-[#f5f5f5]',
|
|
25
|
+
progressBg: 'bg-gray-700',
|
|
26
|
+
progressStripe1: '#374151',
|
|
27
|
+
progressStripe2: '#4B5563',
|
|
28
|
+
dotActive: '#fff',
|
|
29
|
+
dotInactive: 'rgba(255,255,255,0.3)',
|
|
30
|
+
toastTheme: 'dark' as const,
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
8
33
|
export const THEME = {
|
|
9
34
|
light: {
|
|
10
35
|
containerBg: '',
|
|
@@ -33,32 +58,16 @@ export const THEME = {
|
|
|
33
58
|
},
|
|
34
59
|
dark: {
|
|
35
60
|
containerBg: 'reactive-dark-bg',
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
buttonBorder: 'border-black',
|
|
42
|
-
buttonShadow: 'shadow-[2px_2px_0px_rgba(0,0,0,1)]',
|
|
43
|
-
buttonDisabledBg: 'bg-gray-700',
|
|
44
|
-
buttonDisabledText: 'text-gray-500',
|
|
45
|
-
buttonDisabledBorder: 'border-gray-600',
|
|
46
|
-
buttonDisabledShadow: 'shadow-[2px_2px_0px_rgba(75,85,99,1)]',
|
|
47
|
-
error: 'text-red-400',
|
|
48
|
-
focusRing: 'focus:ring-blue-400',
|
|
49
|
-
inputBg: 'bg-gray-700',
|
|
50
|
-
inputBorder: 'border-gray-500',
|
|
51
|
-
inputText: 'text-[#f5f5f5]',
|
|
52
|
-
progressBg: 'bg-gray-700',
|
|
53
|
-
progressStripe1: '#374151',
|
|
54
|
-
progressStripe2: '#4B5563',
|
|
55
|
-
dotActive: '#fff',
|
|
56
|
-
dotInactive: 'rgba(255,255,255,0.3)',
|
|
57
|
-
toastTheme: 'dark' as const,
|
|
61
|
+
...DARK_TOKENS,
|
|
62
|
+
},
|
|
63
|
+
'dark-plain': {
|
|
64
|
+
containerBg: 'reactive-dark-bg-plain',
|
|
65
|
+
...DARK_TOKENS,
|
|
58
66
|
},
|
|
59
67
|
} as const;
|
|
60
68
|
|
|
61
69
|
export const DARK_BG_CLASS = 'reactive-dark-bg';
|
|
70
|
+
export const DARK_BG_PLAIN_CLASS = 'reactive-dark-bg-plain';
|
|
62
71
|
|
|
63
72
|
export function t(theme: Theme) {
|
|
64
73
|
return THEME[theme];
|