@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.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: object) => void;
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 interface ComponentTrial {
21
- name: string;
22
- type: string;
23
- props?: Record<string, any> | ((store: Store, data: TrialData[]) => Record<string, any>);
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?: React.ReactNode;
89
+ content?: default_2.ReactNode;
29
90
  buttonText?: string;
30
- } & BaseComponentProps): JSX_2.Element;
91
+ delayMs?: number;
92
+ } & BaseComponentProps): JSX_2.Element | null;
31
93
 
32
- export declare function ExitFullscreen({ next }: BaseComponentProps): JSX_2.Element;
33
-
34
- export declare function Experiment({ timeline, config, components, questions, }: {
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 type ExperimentTrial = MarkerTrial | IfGotoTrial | UpdateStoreTrial | IfBlockTrial | WhileBlockTrial | ComponentTrial;
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: 'base64' | 'utf8';
117
+ encoding?: 'base64' | 'utf8';
55
118
  }
56
119
 
57
- export declare function getParam<T extends ParamType>(name: string, defaultValue: ParamValue<T> | undefined, type?: T): ParamValue<T> | undefined;
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 IfBlockTrial {
62
- type: 'IF_BLOCK' | string;
63
- cond: (store: Store, data: TrialData[]) => boolean;
64
- timeline: ExperimentTrial[];
124
+ declare interface IfBlockItem {
125
+ type: 'IF_BLOCK';
126
+ cond: ConditionalFunction;
127
+ timeline: TimelineItem[];
65
128
  }
66
129
 
67
- declare interface IfGotoTrial {
68
- type: 'IF_GOTO' | string;
69
- cond: (store: Store, data: TrialData[]) => boolean;
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 interface MarkerTrial {
76
- type: 'MARKER' | string;
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 | undefined : T extends 'boolean' ? boolean | undefined : T extends 'array' | 'json' ? any | undefined : string | undefined;
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, // user defined function
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
- export declare function RequestFilePermission({ next }: BaseComponentProps): JSX_2.Element;
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 shuffle(array: any[]): any[];
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 function Text_2({ content, buttonText, className, next, animate, }: {
124
- content: React.ReactNode;
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
- }): JSX_2.Element;
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
- data: any;
258
+ responseData: any;
139
259
  start: number;
140
260
  end: number;
141
261
  duration: number;
142
262
  }
143
263
 
144
- declare interface UpdateStoreTrial {
145
- type: 'UPDATE_STORE' | string;
146
- fun: (store: Store, data: TrialData[]) => Store;
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 WhileBlockTrial {
158
- type: 'WHILE_BLOCK' | string;
159
- cond: (store: Store, data: TrialData[]) => boolean;
160
- timeline: ExperimentTrial[];
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
+ }
@@ -1,19 +1,29 @@
1
- import { a, c as i, d as r, e as t, M as n, f as l, P as o, Q as P, R as c, T as f, U as m, g as p, h as u, i as x, n as E, s as d } from "./mod-Dqf5zajq.js";
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
- a as EnterFullscreen,
4
- i as ExitFullscreen,
5
- r as Experiment,
6
- t as ExperimentProvider,
7
- n as MicCheck,
8
- l as PlainInput,
9
- o as ProlificEnding,
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
- c as RequestFilePermission,
12
- f as Text,
13
- m as Upload,
14
- p as getParam,
15
- u as getPlatform,
16
- x as isDesktop,
17
- E as now,
18
- d as shuffle
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
  };