@adriansteffan/reactive 0.0.26 → 0.0.27
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-Dqf5zajq.js → mod-CbGhKi2f.js} +11238 -10012
- package/dist/mod.d.ts +187 -49
- package/dist/reactive.es.js +26 -16
- package/dist/reactive.umd.js +37 -39
- package/dist/style.css +1 -1
- package/dist/{web-CnAMKrLX.js → web-BFGLx41c.js} +1 -1
- package/dist/{web-6wmUWZwq.js → web-DOFokKz7.js} +1 -1
- package/package.json +7 -2
- package/src/components/canvasblock.tsx +519 -0
- package/src/components/checkdevice.tsx +158 -0
- package/src/components/enterfullscreen.tsx +114 -31
- package/src/components/exitfullscreen.tsx +98 -21
- package/src/components/experimentprovider.tsx +34 -20
- package/src/components/experimentrunner.tsx +387 -0
- package/src/components/index.ts +13 -0
- package/src/components/mobilefilepermission.tsx +12 -19
- package/src/components/plaininput.tsx +7 -8
- package/src/components/prolificending.tsx +10 -4
- package/src/components/quest.tsx +27 -31
- package/src/components/settingsscreen.tsx +770 -0
- package/src/components/text.tsx +48 -3
- package/src/components/upload.tsx +218 -47
- package/src/mod.tsx +3 -12
- package/src/types/array.d.ts +6 -0
- package/src/utils/array.ts +79 -0
- package/src/utils/bytecode.ts +178 -0
- package/src/utils/common.ts +170 -39
- package/template/.env.template +2 -1
- package/template/src/{App.tsx → Experiment.tsx} +4 -4
- package/template/src/main.tsx +4 -4
- package/template/tsconfig.json +1 -0
- package/src/components/experiment.tsx +0 -371
package/dist/mod.d.ts
CHANGED
|
@@ -1,14 +1,56 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
|
+
import { default as default_2 } from 'react';
|
|
2
3
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
3
4
|
import { ReactNode } from 'react';
|
|
4
5
|
|
|
5
6
|
export declare interface BaseComponentProps {
|
|
6
|
-
next: (data
|
|
7
|
+
next: (data?: object, actualStartTime?: number, actualStopTime?: number) => void;
|
|
7
8
|
data: TrialData[];
|
|
8
9
|
store?: Store;
|
|
9
10
|
updateStore: (mergeIn: Store) => void;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
declare type BaseTrialData = {
|
|
14
|
+
index: number;
|
|
15
|
+
trialNumber: number;
|
|
16
|
+
start: number;
|
|
17
|
+
end: number;
|
|
18
|
+
duration: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export declare function CanvasBlock({ next, updateStore, timeline, width, height, store, styleCanvas, initCanvas, }: CanvasBlockProps): JSX_2.Element;
|
|
22
|
+
|
|
23
|
+
declare type CanvasBlockProps = {
|
|
24
|
+
timeline: TimelineItem[];
|
|
25
|
+
width?: number | string;
|
|
26
|
+
height?: number | string;
|
|
27
|
+
styleCanvas?: (ctx: CanvasRenderingContext2D, width: number, height: number) => void;
|
|
28
|
+
initCanvas?: (ctx: CanvasRenderingContext2D, width: number, height: number) => void;
|
|
29
|
+
} & BaseComponentProps;
|
|
30
|
+
|
|
31
|
+
export declare function canvasCountdown(seconds: number): {
|
|
32
|
+
draw: (ctx: CanvasRenderingContext2D, w: number, h: number) => void;
|
|
33
|
+
displayDuration: number;
|
|
34
|
+
ignoreData: boolean;
|
|
35
|
+
}[];
|
|
36
|
+
|
|
37
|
+
declare type CanvasResultData = BaseTrialData & {
|
|
38
|
+
metadata?: Record<string, any>;
|
|
39
|
+
key: string | null;
|
|
40
|
+
reactionTime: number | null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export declare function CheckDevice({ check, content, data, store, updateStore, next, }: {
|
|
44
|
+
check: (deviceInfo: DeviceInfo, data: any, store: any) => boolean;
|
|
45
|
+
content?: React.ReactNode;
|
|
46
|
+
} & BaseComponentProps): JSX_2.Element | null;
|
|
47
|
+
|
|
48
|
+
declare type ComponentResultData = BaseTrialData & {
|
|
49
|
+
type: string;
|
|
50
|
+
name: string;
|
|
51
|
+
responseData?: any;
|
|
52
|
+
};
|
|
53
|
+
|
|
12
54
|
declare type ComponentsMap = {
|
|
13
55
|
[key: string]: ComponentType<any>;
|
|
14
56
|
};
|
|
@@ -17,63 +59,86 @@ declare type ComponentsMap_2 = {
|
|
|
17
59
|
[key: string]: ComponentType<any>;
|
|
18
60
|
};
|
|
19
61
|
|
|
20
|
-
declare
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
62
|
+
declare type ConditionalFunction = (data?: RefinedTrialData[], store?: Store_2) => boolean;
|
|
63
|
+
|
|
64
|
+
declare type ControlFlowItem = MarkerItem | IfGotoItem | UpdateStoreItem | IfBlockItem | WhileBlockItem;
|
|
65
|
+
|
|
66
|
+
declare type CSVBuilder = {
|
|
67
|
+
filename?: string;
|
|
68
|
+
trials?: string[];
|
|
69
|
+
fun?: (row: Record<string, any>) => Record<string, any>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
declare interface DeviceInfo {
|
|
73
|
+
windowWidth: number;
|
|
74
|
+
windowHeight: number;
|
|
75
|
+
screenWidth: number;
|
|
76
|
+
screenHeight: number;
|
|
77
|
+
browser: string;
|
|
78
|
+
browserVersion: string;
|
|
79
|
+
isMobile: boolean;
|
|
80
|
+
operatingSystem: string;
|
|
81
|
+
hasWebAudio: boolean;
|
|
82
|
+
hasFullscreen: boolean;
|
|
83
|
+
hasWebcam: boolean;
|
|
84
|
+
hasMicrophone: boolean;
|
|
24
85
|
}
|
|
25
86
|
|
|
26
|
-
export declare function EnterFullscreen({ content, buttonText, next, }: {
|
|
87
|
+
export declare function EnterFullscreen({ content, buttonText, next, data, updateStore, delayMs, }: {
|
|
27
88
|
prolificCode?: string;
|
|
28
|
-
content?:
|
|
89
|
+
content?: default_2.ReactNode;
|
|
29
90
|
buttonText?: string;
|
|
30
|
-
|
|
91
|
+
delayMs?: number;
|
|
92
|
+
} & BaseComponentProps): JSX_2.Element | null;
|
|
31
93
|
|
|
32
|
-
export declare function ExitFullscreen({ next }:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
timeline: ExperimentTrial[];
|
|
36
|
-
config?: ExperimentConfig;
|
|
37
|
-
components?: ComponentsMap_2;
|
|
38
|
-
questions?: ComponentsMap_2;
|
|
39
|
-
}): JSX_2.Element;
|
|
94
|
+
export declare function ExitFullscreen({ next, delayMs, }: {
|
|
95
|
+
delayMs?: number;
|
|
96
|
+
} & BaseComponentProps): null;
|
|
40
97
|
|
|
41
98
|
export declare interface ExperimentConfig {
|
|
42
99
|
showProgressBar: boolean;
|
|
43
100
|
}
|
|
44
101
|
|
|
45
|
-
export declare function ExperimentProvider({ children }: {
|
|
102
|
+
export declare function ExperimentProvider({ children, disableSettings }: {
|
|
46
103
|
children: ReactNode;
|
|
104
|
+
disableSettings?: boolean;
|
|
47
105
|
}): JSX_2.Element;
|
|
48
106
|
|
|
49
|
-
declare
|
|
107
|
+
export declare function ExperimentRunner({ timeline, config, components, questions, }: {
|
|
108
|
+
timeline: TimelineItem[];
|
|
109
|
+
config?: ExperimentConfig;
|
|
110
|
+
components?: ComponentsMap_2;
|
|
111
|
+
questions?: ComponentsMap_2;
|
|
112
|
+
}): JSX_2.Element;
|
|
50
113
|
|
|
51
114
|
export declare interface FileUpload {
|
|
52
115
|
filename: string;
|
|
53
116
|
content: string;
|
|
54
|
-
encoding
|
|
117
|
+
encoding?: 'base64' | 'utf8';
|
|
55
118
|
}
|
|
56
119
|
|
|
57
|
-
export declare function getParam<T extends ParamType>(name: string, defaultValue: ParamValue<T
|
|
120
|
+
export declare function getParam<T extends ParamType>(name: string, defaultValue: ParamValue<T>, type?: T, description?: string): ParamValue<T>;
|
|
58
121
|
|
|
59
122
|
export declare const getPlatform: () => Platform;
|
|
60
123
|
|
|
61
|
-
declare interface
|
|
62
|
-
type: 'IF_BLOCK'
|
|
63
|
-
cond:
|
|
64
|
-
timeline:
|
|
124
|
+
declare interface IfBlockItem {
|
|
125
|
+
type: 'IF_BLOCK';
|
|
126
|
+
cond: ConditionalFunction;
|
|
127
|
+
timeline: TimelineItem[];
|
|
65
128
|
}
|
|
66
129
|
|
|
67
|
-
declare interface
|
|
68
|
-
type: 'IF_GOTO'
|
|
69
|
-
cond:
|
|
130
|
+
declare interface IfGotoItem {
|
|
131
|
+
type: 'IF_GOTO';
|
|
132
|
+
cond: ConditionalFunction;
|
|
70
133
|
marker: string;
|
|
71
134
|
}
|
|
72
135
|
|
|
73
136
|
export declare function isDesktop(): boolean;
|
|
74
137
|
|
|
75
|
-
declare
|
|
76
|
-
|
|
138
|
+
export declare function isFullscreen(): boolean;
|
|
139
|
+
|
|
140
|
+
declare interface MarkerItem {
|
|
141
|
+
type: 'MARKER';
|
|
77
142
|
id: string;
|
|
78
143
|
}
|
|
79
144
|
|
|
@@ -83,12 +148,19 @@ export declare const MicCheck: ({ next }: {
|
|
|
83
148
|
|
|
84
149
|
export declare function now(): number;
|
|
85
150
|
|
|
151
|
+
export declare class Param {
|
|
152
|
+
static getRegistry(): any[];
|
|
153
|
+
static getTimelineRepresentation(): {
|
|
154
|
+
type: string;
|
|
155
|
+
name?: string;
|
|
156
|
+
}[];
|
|
157
|
+
}
|
|
158
|
+
|
|
86
159
|
declare type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'json';
|
|
87
160
|
|
|
88
|
-
declare type ParamValue<T extends ParamType> = T extends 'number' ? number
|
|
161
|
+
declare type ParamValue<T extends ParamType> = T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'array' | 'json' ? any : string;
|
|
89
162
|
|
|
90
|
-
export declare function PlainInput({ content, buttonText, className, next, updateStore, animate, storeupdate,
|
|
91
|
-
placeholder, }: BaseComponentProps & {
|
|
163
|
+
export declare function PlainInput({ content, buttonText, className, next, updateStore, animate, storeupdate, placeholder, }: BaseComponentProps & {
|
|
92
164
|
content: React.ReactNode;
|
|
93
165
|
buttonText?: string;
|
|
94
166
|
onButtonClick?: () => void;
|
|
@@ -102,62 +174,128 @@ export declare function PlainInput({ content, buttonText, className, next, updat
|
|
|
102
174
|
|
|
103
175
|
export declare type Platform = 'desktop' | 'mobile' | 'web';
|
|
104
176
|
|
|
105
|
-
export declare function ProlificEnding({ prolificCode, }: {
|
|
177
|
+
export declare function ProlificEnding({ prolificCode, data, updateStore }: {
|
|
106
178
|
prolificCode?: string;
|
|
107
179
|
} & BaseComponentProps): JSX_2.Element;
|
|
108
180
|
|
|
109
|
-
export declare function Quest({ next, surveyJson, customQuestions }: {
|
|
181
|
+
export declare function Quest({ next, surveyJson, customQuestions, }: {
|
|
110
182
|
next: (data: object) => void;
|
|
111
183
|
surveyJson: object;
|
|
112
184
|
customQuestions?: ComponentsMap;
|
|
113
185
|
}): JSX_2.Element;
|
|
114
186
|
|
|
115
|
-
|
|
187
|
+
declare type RefinedTrialData = ComponentResultData | CanvasResultData;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Registers array methods on the Array prototype.
|
|
191
|
+
* Call this function once to make array methods available globally.
|
|
192
|
+
*
|
|
193
|
+
* Example:
|
|
194
|
+
* ```
|
|
195
|
+
* import { registerArrayExtensions } from '@adriansteffan/reactive/array';
|
|
196
|
+
* registerArrayExtensions();
|
|
197
|
+
*
|
|
198
|
+
* // Now you can use the methods
|
|
199
|
+
* const myArray = [1, 2, 3, 4, 5];
|
|
200
|
+
* myArray.shuffle();
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export declare function registerArrayExtensions(): void;
|
|
204
|
+
|
|
205
|
+
export declare function registerComponentParams(type: string, params: {
|
|
206
|
+
name: string;
|
|
207
|
+
defaultValue: any;
|
|
208
|
+
type: string;
|
|
209
|
+
description?: string;
|
|
210
|
+
}[]): void;
|
|
211
|
+
|
|
212
|
+
export declare function registerExperimentParams(experiment: any[]): void;
|
|
116
213
|
|
|
117
|
-
export declare function
|
|
214
|
+
export declare function RequestFilePermission({ next }: BaseComponentProps): JSX_2.Element | null;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Returns random elements from an array
|
|
218
|
+
* @param array The source array
|
|
219
|
+
* @param n Number of random elements to return (defaults to 1)
|
|
220
|
+
* @returns Array of randomly selected elements
|
|
221
|
+
*/
|
|
222
|
+
export declare function sample<T>(array: T[], n?: number): T[];
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Shuffles array elements using Fisher-Yates algorithm
|
|
226
|
+
* @param array The source array
|
|
227
|
+
* @returns A new shuffled array
|
|
228
|
+
*/
|
|
229
|
+
export declare function shuffle<T>(array: T[]): T[];
|
|
118
230
|
|
|
119
231
|
export declare interface Store {
|
|
120
232
|
[key: string]: any;
|
|
121
233
|
}
|
|
122
234
|
|
|
123
|
-
declare
|
|
124
|
-
|
|
235
|
+
declare type Store_2 = Record<string, any>;
|
|
236
|
+
|
|
237
|
+
declare type StoreUpdateFunction = (data?: RefinedTrialData[], store?: Store_2) => Record<string, any>;
|
|
238
|
+
|
|
239
|
+
export declare function subsetExperimentByParam(experiment: any[]): any[];
|
|
240
|
+
|
|
241
|
+
declare function Text_2({ content, buttonText, className, next, animate, allowedKeys, }: {
|
|
242
|
+
content: default_2.ReactNode;
|
|
125
243
|
buttonText?: string;
|
|
126
244
|
onButtonClick?: () => void;
|
|
127
245
|
className?: string;
|
|
128
|
-
next: (newData: object) => void;
|
|
129
246
|
animate?: boolean;
|
|
130
|
-
|
|
247
|
+
allowedKeys?: string[] | boolean;
|
|
248
|
+
} & BaseComponentProps): JSX_2.Element;
|
|
131
249
|
export { Text_2 as Text }
|
|
132
250
|
|
|
251
|
+
declare type TimelineItem = ControlFlowItem | any;
|
|
252
|
+
|
|
133
253
|
export declare interface TrialData {
|
|
134
254
|
index: number;
|
|
135
255
|
trialNumber: number;
|
|
136
256
|
type: string;
|
|
137
257
|
name: string;
|
|
138
|
-
|
|
258
|
+
responseData: any;
|
|
139
259
|
start: number;
|
|
140
260
|
end: number;
|
|
141
261
|
duration: number;
|
|
142
262
|
}
|
|
143
263
|
|
|
144
|
-
declare interface
|
|
145
|
-
type: 'UPDATE_STORE'
|
|
146
|
-
fun:
|
|
264
|
+
declare interface UpdateStoreItem {
|
|
265
|
+
type: 'UPDATE_STORE';
|
|
266
|
+
fun: StoreUpdateFunction;
|
|
147
267
|
}
|
|
148
268
|
|
|
149
|
-
export declare function Upload({ data, next, store, sessionID, generateFiles, uploadRaw, autoUpload, androidFolderName, }: BaseComponentProps & {
|
|
269
|
+
export declare function Upload({ data, next, store, sessionID, generateFiles, sessionCSVBuilder, trialCSVBuilders, uploadRaw, autoUpload, androidFolderName, }: BaseComponentProps & {
|
|
150
270
|
sessionID?: string | null;
|
|
151
271
|
generateFiles: (sessionID: string, data: TrialData[], store?: Store) => FileUpload[];
|
|
272
|
+
sessionCSVBuilder: CSVBuilder;
|
|
273
|
+
trialCSVBuilders: CSVBuilder[];
|
|
152
274
|
uploadRaw: boolean;
|
|
153
275
|
autoUpload: boolean;
|
|
154
276
|
androidFolderName?: string;
|
|
155
277
|
}): JSX_2.Element;
|
|
156
278
|
|
|
157
|
-
declare interface
|
|
158
|
-
type: 'WHILE_BLOCK'
|
|
159
|
-
cond:
|
|
160
|
-
timeline:
|
|
279
|
+
declare interface WhileBlockItem {
|
|
280
|
+
type: 'WHILE_BLOCK';
|
|
281
|
+
cond: ConditionalFunction;
|
|
282
|
+
timeline: TimelineItem[];
|
|
161
283
|
}
|
|
162
284
|
|
|
163
285
|
export { }
|
|
286
|
+
|
|
287
|
+
declare global {
|
|
288
|
+
interface Array<T> {
|
|
289
|
+
/**
|
|
290
|
+
* Returns random elements from the array
|
|
291
|
+
* @param n Number of random elements to return (defaults to 1)
|
|
292
|
+
* @returns Array of randomly selected elements
|
|
293
|
+
*/
|
|
294
|
+
sample(n?: number): Array<T>;
|
|
295
|
+
/**
|
|
296
|
+
* Shuffles array elements using Fisher-Yates algorithm
|
|
297
|
+
* @returns A new shuffled array
|
|
298
|
+
*/
|
|
299
|
+
shuffle(): Array<T>;
|
|
300
|
+
}
|
|
301
|
+
}
|
package/dist/reactive.es.js
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as e, t as r, m as n, o as t, p as i, q as o, M as l, P as m, k as c, l as p, Q as P, R as u, T as x, U as E, j as g, g as f, d as C, c as d, i as k, n as h, r as v, f as F, e as R, s as q, a as w, h as y } from "./mod-CbGhKi2f.js";
|
|
2
2
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
t as
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
3
|
+
e as CanvasBlock,
|
|
4
|
+
r as CheckDevice,
|
|
5
|
+
n as EnterFullscreen,
|
|
6
|
+
t as ExitFullscreen,
|
|
7
|
+
i as ExperimentProvider,
|
|
8
|
+
o as ExperimentRunner,
|
|
9
|
+
l as MicCheck,
|
|
10
|
+
m as Param,
|
|
11
|
+
c as PlainInput,
|
|
12
|
+
p as ProlificEnding,
|
|
10
13
|
P as Quest,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
u as RequestFilePermission,
|
|
15
|
+
x as Text,
|
|
16
|
+
E as Upload,
|
|
17
|
+
g as canvasCountdown,
|
|
18
|
+
f as getParam,
|
|
19
|
+
C as getPlatform,
|
|
20
|
+
d as isDesktop,
|
|
21
|
+
k as isFullscreen,
|
|
22
|
+
h as now,
|
|
23
|
+
v as registerArrayExtensions,
|
|
24
|
+
F as registerComponentParams,
|
|
25
|
+
R as registerExperimentParams,
|
|
26
|
+
q as sample,
|
|
27
|
+
w as shuffle,
|
|
28
|
+
y as subsetExperimentByParam
|
|
19
29
|
};
|