@adriansteffan/reactive 0.0.43 → 0.1.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 (41) hide show
  1. package/.claude/settings.local.json +14 -1
  2. package/README.md +232 -3
  3. package/dist/{mod-D6W3wq3h.js → mod-D9lwPIrH.js} +6739 -6389
  4. package/dist/mod.d.ts +70 -22
  5. package/dist/reactive.es.js +46 -36
  6. package/dist/reactive.umd.js +40 -38
  7. package/dist/style.css +1 -1
  8. package/dist/{web-B1hJOwit.js → web-DUIQX1PV.js} +1 -1
  9. package/dist/{web-BYSmfdtR.js → web-DXP3LAJm.js} +1 -1
  10. package/package.json +1 -1
  11. package/src/components/canvasblock.tsx +125 -74
  12. package/src/components/checkdevice.tsx +18 -0
  13. package/src/components/enterfullscreen.tsx +7 -3
  14. package/src/components/exitfullscreen.tsx +6 -1
  15. package/src/components/experimentprovider.tsx +7 -2
  16. package/src/components/experimentrunner.tsx +85 -58
  17. package/src/components/microphonecheck.tsx +6 -1
  18. package/src/components/mobilefilepermission.tsx +3 -0
  19. package/src/components/plaininput.tsx +20 -0
  20. package/src/components/prolificending.tsx +5 -0
  21. package/src/components/quest.tsx +60 -0
  22. package/src/components/storeui.tsx +18 -11
  23. package/src/components/text.tsx +14 -0
  24. package/src/components/upload.tsx +69 -286
  25. package/src/index.css +0 -20
  26. package/src/mod.tsx +2 -0
  27. package/src/utils/bytecode.ts +61 -9
  28. package/src/utils/common.ts +4 -1
  29. package/src/utils/simulation.ts +269 -0
  30. package/src/utils/upload.ts +201 -0
  31. package/template/README.md +59 -0
  32. package/template/backend/package-lock.json +280 -156
  33. package/template/backend/src/backend.ts +1 -0
  34. package/template/package-lock.json +1693 -771
  35. package/template/package.json +2 -0
  36. package/template/simulate.ts +15 -0
  37. package/template/src/Experiment.tsx +62 -5
  38. package/template/src/main.tsx +1 -1
  39. package/template/tsconfig.json +2 -3
  40. package/tsconfig.json +1 -0
  41. package/vite.config.ts +1 -1
package/dist/mod.d.ts CHANGED
@@ -53,10 +53,17 @@ export declare function chunk<T>(array: T[], n: number): T[][];
53
53
  declare type ComponentResultData = BaseTrialData & {
54
54
  type: string;
55
55
  name: string;
56
+ /** Per-trial override for which CSV file(s) this trial's data goes into. When set on a timeline item, overrides the component type's default from the flattener registry. */
57
+ csv?: string | string[];
56
58
  responseData?: any;
57
59
  metadata?: Record<string, any>;
58
60
  };
59
61
 
62
+ declare interface ComponentSimulation {
63
+ simulate: SimulateFunction;
64
+ defaultSimulators: Record<string, any>;
65
+ }
66
+
60
67
  declare type ComponentsMap = {
61
68
  [key: string]: ComponentType<any>;
62
69
  };
@@ -65,16 +72,10 @@ declare type ComponentsMap_2 = {
65
72
  [key: string]: ComponentType<any>;
66
73
  };
67
74
 
68
- declare type ConditionalFunction = (data?: RefinedTrialData[], store?: Store_2) => boolean;
75
+ declare type ConditionalFunction = (data?: TrialResult[], store?: Store_2) => boolean;
69
76
 
70
77
  declare type ControlFlowItem = MarkerItem | IfGotoItem | UpdateStoreItem | IfBlockItem | WhileBlockItem;
71
78
 
72
- declare type CSVBuilder = {
73
- filename?: string;
74
- trials?: string[];
75
- fun?: (row: Record<string, any>) => Record<string, any>;
76
- };
77
-
78
79
  declare interface DeviceInfo {
79
80
  windowWidth: number;
80
81
  windowHeight: number;
@@ -105,16 +106,18 @@ export declare interface ExperimentConfig {
105
106
  showProgressBar: boolean;
106
107
  }
107
108
 
108
- export declare function ExperimentProvider({ children, disableSettings }: {
109
+ export declare function ExperimentProvider({ children, disableSettings, disableHybridSimulation }: {
109
110
  children: ReactNode;
110
111
  disableSettings?: boolean;
112
+ disableHybridSimulation?: boolean;
111
113
  }): JSX_2.Element;
112
114
 
113
- export declare function ExperimentRunner({ timeline, config, components, questions, }: {
115
+ export declare function ExperimentRunner({ timeline, config, components, questions, hybridParticipant, }: {
114
116
  timeline: TimelineItem[];
115
117
  config?: ExperimentConfig;
116
118
  components?: ComponentsMap_2;
117
119
  questions?: ComponentsMap_2;
120
+ hybridParticipant?: ParticipantState;
118
121
  }): JSX_2.Element;
119
122
 
120
123
  export declare interface FileUpload {
@@ -123,10 +126,16 @@ export declare interface FileUpload {
123
126
  encoding?: 'base64' | 'utf8';
124
127
  }
125
128
 
126
- export declare function getParam<T extends ParamType>(name: string, defaultValue: ParamValue<T>, type?: T, description?: string): ParamValue<T>;
129
+ export declare function getBackendUrl(): string;
130
+
131
+ export declare function getInitialParticipant(): ParticipantState | undefined;
132
+
133
+ export declare function getParam<T extends ParamType>(name: string, defaultValue: ParamValue<T>, type?: T, description?: string, uiDefault?: string): ParamValue<T>;
127
134
 
128
135
  export declare const getPlatform: () => Platform;
129
136
 
137
+ export declare function getSimulation(type: string): ComponentSimulation | undefined;
138
+
130
139
  declare interface IfBlockItem {
131
140
  type: 'IF_BLOCK';
132
141
  cond: ConditionalFunction;
@@ -152,8 +161,12 @@ export declare const MicCheck: ({ next }: {
152
161
  next: (data: object) => void;
153
162
  }) => JSX_2.Element;
154
163
 
164
+ export declare const noopSimulate: SimulateFunction;
165
+
155
166
  export declare function now(): number;
156
167
 
168
+ export declare function orchestrateSimulation(config: RunSimulationConfig, scriptPath: string): Promise<void>;
169
+
157
170
  export declare class Param {
158
171
  static getRegistry(): any[];
159
172
  static getTimelineRepresentation(): {
@@ -166,6 +179,8 @@ declare type ParamType = 'string' | 'number' | 'boolean' | 'array' | 'json';
166
179
 
167
180
  declare type ParamValue<T extends ParamType> = T extends 'number' ? number : T extends 'boolean' ? boolean : T extends 'array' | 'json' ? any : string;
168
181
 
182
+ export declare type ParticipantState = Record<string, any>;
183
+
169
184
  /**
170
185
  * Applies a function to an array
171
186
  */
@@ -195,8 +210,6 @@ export declare function Quest({ next, surveyJson, customQuestions, }: {
195
210
  customQuestions?: ComponentsMap;
196
211
  }): JSX_2.Element;
197
212
 
198
- declare type RefinedTrialData = ComponentResultData | CanvasResultData;
199
-
200
213
  /**
201
214
  * Registers array methods on the Array prototype.
202
215
  * Call this function once to make array methods available globally.
@@ -221,25 +234,60 @@ export declare function registerComponentParams(type: string, params: {
221
234
 
222
235
  export declare function registerExperimentParams(experiment: any[]): void;
223
236
 
237
+ export declare function registerFlattener(type: string, csv: string | null, flatten?: (item: TrialData) => any[]): void;
238
+
239
+ export declare function registerSimulation(type: string, simulate: SimulateFunction, defaultSimulators: Record<string, any>): void;
240
+
224
241
  export declare function RequestFilePermission({ next }: BaseComponentProps): JSX_2.Element | null;
225
242
 
243
+ export declare function resolveSimulation(content: any, data: TrialResult[], store: Store_2): {
244
+ trialProps: any;
245
+ simulateFn: any;
246
+ simulators: any;
247
+ };
248
+
249
+ export declare interface RunSimulationConfig {
250
+ participants: ParticipantState[] | {
251
+ generator: (index: number) => ParticipantState;
252
+ count: number;
253
+ };
254
+ backendPort?: number;
255
+ concurrency?: number;
256
+ }
257
+
226
258
  /**
227
259
  * Returns random elements from an array
228
260
  */
229
261
  export declare function sample<T>(array: T[], n?: number): T[];
230
262
 
263
+ export declare function setBackendUrl(url: string): void;
264
+
231
265
  /**
232
266
  * Shuffles array elements using Fisher-Yates algorithm
233
267
  */
234
268
  export declare function shuffle<T>(array: T[]): T[];
235
269
 
270
+ export declare type SimulateFunction = (trialProps: Record<string, any>, experimentState: {
271
+ data: TrialResult[];
272
+ store: Store_2;
273
+ }, simulators: Record<string, any>, participant: ParticipantState) => SimulatorResult | Promise<SimulatorResult>;
274
+
275
+ export declare function simulateParticipant(timeline: TimelineItem[], participant: ParticipantState): Promise<TrialResult[]>;
276
+
277
+ export declare type SimulatorResult = {
278
+ responseData: any;
279
+ participantState: ParticipantState;
280
+ storeUpdates?: Record<string, any>;
281
+ duration?: number;
282
+ };
283
+
236
284
  export declare interface Store {
237
285
  [key: string]: any;
238
286
  }
239
287
 
240
288
  declare type Store_2 = Record<string, any>;
241
289
 
242
- declare type StoreUpdateFunction = (data?: RefinedTrialData[], store?: Store_2) => Record<string, any>;
290
+ declare type StoreUpdateFunction = (data?: TrialResult[], store?: Store_2) => Record<string, any>;
243
291
 
244
292
  export declare function subsetExperimentByParam(experiment: any[]): any[];
245
293
 
@@ -261,27 +309,27 @@ export declare interface TrialData {
261
309
  trialNumber: number;
262
310
  type: string;
263
311
  name: string;
312
+ /** Populated from the timeline item's csv field. Overrides the component type's default CSV target from the flattener registry. */
313
+ csv?: string | string[];
264
314
  responseData: any;
265
315
  start: number;
266
316
  end: number;
267
317
  duration: number;
268
318
  }
269
319
 
320
+ declare type TrialResult = ComponentResultData | CanvasResultData;
321
+
270
322
  declare interface UpdateStoreItem {
271
323
  type: 'UPDATE_STORE';
272
324
  fun: StoreUpdateFunction;
273
325
  }
274
326
 
275
- export declare function Upload({ data, next, store, sessionID, generateFiles, sessionCSVBuilder, trialCSVBuilder, uploadRaw, autoUpload, androidFolderName, }: BaseComponentProps & {
327
+ export declare function Upload({ data, next, store, sessionID, generateFiles, sessionData, uploadRaw, autoUpload, androidFolderName, }: BaseComponentProps & {
276
328
  sessionID?: string | null;
277
- generateFiles: (sessionID: string, data: TrialData[], store?: Store) => FileUpload[];
278
- sessionCSVBuilder: CSVBuilder;
279
- trialCSVBuilder: {
280
- flatteners: Record<string, ((item: TrialData) => Record<string, any>[] | Record<string, Record<string, any>[]>)>;
281
- builders: CSVBuilder[];
282
- };
283
- uploadRaw: boolean;
284
- autoUpload: boolean;
329
+ generateFiles?: (sessionID: string, data: TrialData[], store?: Store) => FileUpload[];
330
+ sessionData?: Record<string, any>;
331
+ uploadRaw?: boolean;
332
+ autoUpload?: boolean;
285
333
  androidFolderName?: string;
286
334
  }): JSX_2.Element;
287
335
 
@@ -1,42 +1,52 @@
1
- import { H as e, C as n, v as r, o as t, q as i, t as o, u as l, Y as c, z as m, M as p, P as u, l as P, m as x, Q as C, R as E, F as g, T, w as d, U as f, X as k, k as F, c as h, x as v, y as B, g as w, e as y, d as R, i as q, n as D, p as I, r as M, h as Q, f as U, s as b, a as j, j as z, B as A, N as H, L } from "./mod-D6W3wq3h.js";
1
+ import { H as e, C as t, a as i, c as n, d as r, e as o, f as l, Y as m, z as c, M as u, P as p, g as P, h as g, Q as x, R as d, F as k, T as C, i as E, U as F, X as S, j as T, k as f, l as h, m as v, n as B, o as I, p as U, q as w, r as y, s as D, t as R, u as q, v as A, w as M, x as Q, y as Z, A as b, B as j, D as z, G, I as H, J, K, L, N, O, S as V, V as X, Z as Y } from "./mod-D9lwPIrH.js";
2
2
  export {
3
3
  e as Bounce,
4
- n as CanvasBlock,
5
- r as CheckDevice,
6
- t as EnterFullscreen,
7
- i as ExitFullscreen,
4
+ t as CanvasBlock,
5
+ i as CheckDevice,
6
+ n as EnterFullscreen,
7
+ r as ExitFullscreen,
8
8
  o as ExperimentProvider,
9
9
  l as ExperimentRunner,
10
- c as Flip,
11
- m as Icons,
12
- p as MicCheck,
13
- u as Param,
10
+ m as Flip,
11
+ c as Icons,
12
+ u as MicCheck,
13
+ p as Param,
14
14
  P as PlainInput,
15
- x as ProlificEnding,
16
- C as Quest,
17
- E as RequestFilePermission,
18
- g as Slide,
19
- T as Text,
20
- d as ToastContainer,
21
- f as Upload,
22
- k as Zoom,
23
- F as canvasCountdown,
24
- h as chunk,
25
- v as collapseToast,
26
- B as cssTransition,
27
- w as getParam,
28
- y as getPlatform,
29
- R as isDesktop,
30
- q as isFullscreen,
31
- D as now,
32
- I as pipe,
33
- M as registerArrayExtensions,
34
- Q as registerComponentParams,
35
- U as registerExperimentParams,
36
- b as sample,
37
- j as shuffle,
38
- z as subsetExperimentByParam,
39
- A as toast,
40
- H as useToast,
41
- L as useToastContainer
15
+ g as ProlificEnding,
16
+ x as Quest,
17
+ d as RequestFilePermission,
18
+ k as Slide,
19
+ C as Text,
20
+ E as ToastContainer,
21
+ F as Upload,
22
+ S as Zoom,
23
+ T as canvasCountdown,
24
+ f as chunk,
25
+ h as collapseToast,
26
+ v as cssTransition,
27
+ B as getBackendUrl,
28
+ I as getInitialParticipant,
29
+ U as getParam,
30
+ w as getPlatform,
31
+ y as getSimulation,
32
+ D as isDesktop,
33
+ R as isFullscreen,
34
+ q as noopSimulate,
35
+ A as now,
36
+ M as orchestrateSimulation,
37
+ Q as pipe,
38
+ Z as registerArrayExtensions,
39
+ b as registerComponentParams,
40
+ j as registerExperimentParams,
41
+ z as registerFlattener,
42
+ G as registerSimulation,
43
+ H as resolveSimulation,
44
+ J as sample,
45
+ K as setBackendUrl,
46
+ L as shuffle,
47
+ N as simulateParticipant,
48
+ O as subsetExperimentByParam,
49
+ V as toast,
50
+ X as useToast,
51
+ Y as useToastContainer
42
52
  };