@turbowarp/types 0.0.2 → 0.0.4

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.
@@ -0,0 +1,612 @@
1
+ // Type definitions for scratch-gui redux state and events
2
+ // Project: https://github.com/LLK/scratch-gui
3
+
4
+ /// <reference path="./react.d.ts" />
5
+ /// <reference path="./immutable.d.ts" />
6
+ /// <reference path="./scratch-paint.ts" />
7
+ /// <reference path="./scratch-vm.d.ts" />
8
+
9
+ declare namespace ScratchGUI {
10
+ interface ReduxState extends ScratchPaint.ReduxState {
11
+ scratchGui: ScratchGUIState;
12
+ locales: LocaleState;
13
+ session: SessionState;
14
+ }
15
+ type ReduxEvent = ScratchGUIEvent | LocaleEvent | ScratchPaint.ReduxEvent;
16
+
17
+ const enum AlertType {
18
+ Standard = 'STANDARD',
19
+ Extension = 'EXTENSION',
20
+ Inline = 'INLINE'
21
+ }
22
+
23
+ const enum AlertLevel {
24
+ Success = 'success',
25
+ Info = 'info',
26
+ Warning = 'warn'
27
+ }
28
+
29
+ const enum Alert {
30
+ CreateSuccess = 'createSuccess',
31
+ CreateCopySuccess = 'createCopySuccess',
32
+ CreateRemixSuccess = 'createRemixSuccess',
33
+ Creating = 'creating',
34
+ CreatingCopy = 'creatingCopy',
35
+ CreatingRemix = 'creatingRemix',
36
+ CreatingError = 'creatingError',
37
+ SavingError = 'savingError',
38
+ SaveSuccess = 'saveSuccess',
39
+ Saving = 'saving',
40
+ CloudInfo = 'cloudInfo',
41
+ ImportingAsset = 'importingAsset'
42
+ }
43
+
44
+ // Not going to bother listing all of the IDs here.
45
+ type Deck = string;
46
+
47
+ const enum DragType {
48
+ Costume = 'COSTUME',
49
+ Sound = 'SOUND',
50
+ Sprite = 'SPRITE'
51
+ }
52
+
53
+ type DragPayload = VM.Costume | VM.Sound;
54
+
55
+ const enum StageDisplaySize {
56
+ Large = 'large',
57
+ Small = 'small',
58
+ LargeConstrained = 'largeConstrained'
59
+ }
60
+
61
+ const enum Menu {
62
+ About = 'aboutMenu',
63
+ Account = 'accountMenu',
64
+ File = 'fileMenu',
65
+ Edit = 'editMenu',
66
+ Language = 'languageMenu',
67
+ Login = 'loginMenu'
68
+ }
69
+
70
+ const enum Modal {
71
+ BackdropLibrary = 'backdropLibrary',
72
+ CostumeLibrary = 'costumeLibrary',
73
+ ExtensionLibrary = 'extensionLibrary',
74
+ LoadingProject = 'loadingProject',
75
+ Telemetry = 'telemetryModal',
76
+ SoundLibrary = 'soundLibrary',
77
+ SpriteLibrary = 'spriteLibrary',
78
+ SoundRecorder = 'soundRecorder',
79
+ Connection = 'connectionModal',
80
+ TipsLibrary = 'tipsLibrary'
81
+ }
82
+
83
+ type ProjectData = string | Uint8Array;
84
+
85
+ const enum LoadingState {
86
+ NotLoaded = 'NOT_LOADED',
87
+ Error = 'ERROR',
88
+ AutoUpdating = 'AUTO_UPDATING',
89
+ CreatingCopy = 'CREATING_COPY',
90
+ CreatingNew = 'CREATING_NEW',
91
+ FetchingNewDefault = 'FETCHING_NEW_DEFAULT',
92
+ FetchingWithID= 'FETCHING_WITH_ID',
93
+ LoadingVMFIleUpload = 'LOADING_VM_FILE_UPLOAD',
94
+ LoadingVMNewDefault = 'LOADING_VM_NEW_DEFAULT',
95
+ LoadingVMWithID = 'LOADING_VM_WITH_ID',
96
+ ManualUpdating = 'MANUAL_UPDATING',
97
+ Remixing = 'REMIXING',
98
+ ShowingWithID = 'SHOWING_WITH_ID',
99
+ ShowingWithoutID = 'SHOWING_WITHOUT_ID',
100
+ UpdatingBeforeCopy = 'UPDATING_BEFORE_COPY',
101
+ UpdatingBeforeNew = 'UPDATING_BEFORE_NEW'
102
+ }
103
+
104
+ const enum DeletedItemType {
105
+ Costume = 'Costume',
106
+ Sound = 'Sound',
107
+ Sprite = 'Sprite'
108
+ }
109
+
110
+ const enum ActiveTabIndex {
111
+ Blocks = 0,
112
+ Costumes = 1,
113
+ Sounds = 2
114
+ }
115
+
116
+ interface ScratchGUIState {
117
+ alerts: {
118
+ visible: boolean;
119
+ alertsList: Array<{
120
+ alertType: AlertType;
121
+ level: AlertLevel;
122
+ alertId?: Alert;
123
+ extensionId?: string;
124
+ content?: React.Element;
125
+ message?: string;
126
+ iconURL?: string;
127
+ iconSpinner?: boolean;
128
+ closeButton?: boolean;
129
+ showReconnect?: boolean;
130
+ showDownload?: boolean;
131
+ showSaveNow?: boolean;
132
+ }>;
133
+ };
134
+
135
+ assetDrag: {
136
+ dragging: boolean;
137
+ currentOffset: {
138
+ x: number;
139
+ y: number;
140
+ } | null;
141
+ img: string | null;
142
+ index?: number;
143
+ dragType?: DragType;
144
+ payload?: DragPayload;
145
+ };
146
+
147
+ blockDrag: boolean;
148
+
149
+ cards: {
150
+ visible: boolean;
151
+ content: Record<Deck, unknown>;
152
+ activeDeckId: Deck | null;
153
+ step: number;
154
+ x: number;
155
+ y: number;
156
+ expanded: boolean;
157
+ dragging: boolean;
158
+ };
159
+
160
+ colorPicker: {
161
+ active: boolean;
162
+ callback(color: string): void;
163
+ };
164
+
165
+ connectionModal: {
166
+ extensionId: string | null;
167
+ };
168
+
169
+ customProcedures: {
170
+ active: boolean;
171
+ mutator: Element | null;
172
+ callback: ((mutation: Element) => void) | null;
173
+ };
174
+
175
+ editorTab: {
176
+ activeTabIndex: ActiveTabIndex;
177
+ };
178
+
179
+ mode: {
180
+ showBranding: boolean;
181
+ isFullScreen: boolean;
182
+ isPlayerOnly: boolean;
183
+ hasEverEnteredEditor: boolean;
184
+ };
185
+
186
+ hoveredTarget: {
187
+ sprite: string | null;
188
+ receivedBlocks: boolean;
189
+ };
190
+
191
+ stageSize: {
192
+ /**
193
+ * Will only be large or small. Large constrained is determined elsewhere.
194
+ */
195
+ stageSize: StageDisplaySize;
196
+ };
197
+
198
+ menus: Record<Menu, boolean>;
199
+
200
+ micIndicator: boolean;
201
+
202
+ modals: Record<Modal, boolean>;
203
+
204
+ monitors: OrderedMap;
205
+
206
+ monitorLayout: {
207
+ monitors: Record<string, {
208
+ upperStart: {
209
+ x: number;
210
+ y: number;
211
+ };
212
+ lowerEnd: {
213
+ x: number;
214
+ y: number;
215
+ };
216
+ }>;
217
+ savedMonitorPositions: Record<string, {
218
+ x: number;
219
+ y: number
220
+ }>;
221
+ };
222
+
223
+ projectChanged: boolean;
224
+
225
+ projectState: {
226
+ error: null | unknown;
227
+ projectData: ProjectData | null;
228
+ projectId: string;
229
+ loadingState: LoadingState;
230
+ };
231
+
232
+ projectTitle: string;
233
+
234
+ fontsLoaded: boolean;
235
+
236
+ restoreDeletion: {
237
+ restoreFun: null | (() => void);
238
+ deletedItem: DeletedItemType | '';
239
+ };
240
+
241
+ targets: {
242
+ sprites: Record<string, VM.RenderedTarget & {
243
+ order: number;
244
+ }>;
245
+ stage: VM.RenderedTarget | {};
246
+ editingTarget?: string | null;
247
+ highlightedTargetId: string | null;
248
+ highlightedTargetTime: number | null;
249
+ };
250
+
251
+ timeout: {
252
+ autoSaveTimeoutId: number | null;
253
+ };
254
+
255
+ toolbox: {
256
+ toolboxXML: string;
257
+ };
258
+
259
+ vm: VM;
260
+
261
+ vmStatus: {
262
+ running: boolean;
263
+ started: boolean;
264
+ turbo: boolean;
265
+ };
266
+
267
+ workspaceMetrics: {
268
+ targets: Record<string, {
269
+ scale: number;
270
+ scrollX: number;
271
+ scrollY: number;
272
+ }>;
273
+ };
274
+ }
275
+
276
+ type ScratchGUIEvent =
277
+ {
278
+ type: 'scratch-gui/alerts/SHOW_ALERT';
279
+ alertId: string;
280
+ } |
281
+ {
282
+ type: 'scratch-gui/alerts/SHOW_EXTENSION_ALERT';
283
+ data: {
284
+ message: string;
285
+ extensionId: string;
286
+ }
287
+ } |
288
+ {
289
+ type: 'scratch-gui/alerts/CLOSE_ALERT';
290
+ index: number;
291
+ } |
292
+ {
293
+ type: 'scratch-gui/alerts/CLOSE_ALERT_WITH_ID';
294
+ alertId: string;
295
+ } |
296
+ {
297
+ type: 'scratch-gui/alerts/CLOSE_ALERTS_WITH_ID';
298
+ alertId: string;
299
+ } |
300
+ {
301
+ type: 'scratch-gui/asset-drag/DRAG_UPDATE';
302
+ state: Partial<ScratchGUIState['assetDrag']>;
303
+ } |
304
+ {
305
+ type: 'scratch-gui/block-drag/BLOCK_DRAG_UPDATE';
306
+ areBlocksOverGui: boolean;
307
+ } |
308
+ {
309
+ type: 'scratch-gui/cards/CLOSE_CARDS';
310
+ } |
311
+ {
312
+ type: 'scratch-gui/cards/SHRINK_EXPAND_CARDS';
313
+ } |
314
+ {
315
+ type: 'scratch-gui/cards/VIEW_CARDS';
316
+ } |
317
+ {
318
+ type: 'scratch-gui/cards/ACTIVATE_DECK';
319
+ activeDeckId: Deck;
320
+ } |
321
+ {
322
+ type: 'scratch-gui/cards/NEXT_STEP';
323
+ } |
324
+ {
325
+ type: 'scratch-gui/cards/PREV_STEP';
326
+ } |
327
+ {
328
+ type: 'scratch-gui/cards/DRAG_CARD';
329
+ x: number;
330
+ y: number;
331
+ } |
332
+ {
333
+ type: 'scratch-gui/cards/START_DRAG';
334
+ } |
335
+ {
336
+ type: 'scratch-gui/cards/END_DRAG';
337
+ } |
338
+ {
339
+ type: 'scratch-gui/color-picker/ACTIVATE_COLOR_PICKER';
340
+ callback: ScratchGUIState['colorPicker']['callback'];
341
+ } |
342
+ {
343
+ type: 'scratch-gui/color-picker/DEACTIVATE_COLOR_PICKER';
344
+ color: string;
345
+ } |
346
+ {
347
+ type: 'scratch-gui/color-picker/SET_CALLBACK';
348
+ callback: ScratchGUIState['colorPicker']['callback'];
349
+ } |
350
+ {
351
+ type: 'scratch-gui/connection-modal/setId';
352
+ extensionId: string | null;
353
+ } |
354
+ {
355
+ type: 'scratch-gui/custom-procedures/ACTIVATE_CUSTOM_PROCEDURES';
356
+ mutator: Element;
357
+ callback(mutation: Element): void;
358
+ } |
359
+ {
360
+ type: 'scratch-gui/custom-procedures/DEACTIVATE_CUSTOM_PROCEDURES';
361
+ mutator: Element | null;
362
+ } |
363
+ {
364
+ // Technically exists but unused by scratch-gui
365
+ type: 'scratch-gui/custom-procedures/SET_CALLBACK';
366
+ callback(mutation: Element): void;
367
+ } |
368
+ {
369
+ type: 'scratch-gui/navigation/ACTIVATE_TAB';
370
+ activeTabIndex: ActiveTabIndex;
371
+ } |
372
+ {
373
+ type: 'fontsLoaded/SET_FONTS_LOADED';
374
+ loaded: boolean;
375
+ } |
376
+ {
377
+ type: 'scratch-gui/hovered-target/SET_HOVERED_SPRITE';
378
+ spriteId: string | null;
379
+ } |
380
+ {
381
+ type: 'scratch-gui/hovered-target/SET_RECEIVED_BLOCKS';
382
+ receivedBlocks: boolean;
383
+ } |
384
+ {
385
+ type: 'scratch-gui/menus/OPEN_MENU';
386
+ menu: Menu;
387
+ } |
388
+ {
389
+ type: 'scratch-gui/menus/CLOSE_MENU';
390
+ menu: Menu;
391
+ } |
392
+ {
393
+ type: 'scratch-gui/mic-indicator/UPDATE';
394
+ visible: boolean;
395
+ } |
396
+ {
397
+ type: 'scratch-gui/modals/OPEN_MODAL';
398
+ modal: Modal;
399
+ } |
400
+ {
401
+ type: 'scratch-gui/modals/CLOSE_MODAL';
402
+ modal: Modal;
403
+ } |
404
+ {
405
+ type: 'scratch-gui/mode/SET_FULL_SCREEN';
406
+ isFullScreen: boolean;
407
+ } |
408
+ {
409
+ type: 'scratch-gui/mode/SET_PLAYER';
410
+ isPlayerOnly: boolean;
411
+ } |
412
+ {
413
+ type: 'scratch-gui/monitors/ADD_MONITOR_RECT';
414
+ monitorId: string;
415
+ upperStart: {
416
+ x: number;
417
+ y: number;
418
+ };
419
+ lowerEnd: {
420
+ x: number;
421
+ y: number;
422
+ };
423
+ savePosition: boolean;
424
+ } |
425
+ {
426
+ type: 'scratch-gui/monitors/MOVE_MONITOR_RECT';
427
+ monitorId: string;
428
+ newX: number;
429
+ newY: number;
430
+ } |
431
+ {
432
+ type: 'scratch-gui/monitors/RESIZE_MONITOR_RECT';
433
+ monitorId: string;
434
+ newWidth: number;
435
+ newHeight: number;
436
+ } |
437
+ {
438
+ type: 'scratch-gui/monitors/REMOVE_MONITOR_RECT';
439
+ monitorId: string;
440
+ } |
441
+ {
442
+ type: 'scratch-gui/monitors/RESET_MONITOR_LAYOUT';
443
+ } |
444
+ {
445
+ type: 'scratch-gui/monitors/UPDATE_MONITORS';
446
+ monitors: OrderedMap;
447
+ } |
448
+ {
449
+ type: 'scratch-gui/project-changed/SET_PROJECT_CHANGED';
450
+ changed: boolean;
451
+ } |
452
+ {
453
+ type: 'scratch-gui/project-state/DONE_CREATING_COPY';
454
+ projectId: string;
455
+ } |
456
+ {
457
+ type: 'scratch-gui/project-state/DONE_CREATING_NEW';
458
+ projectId: string;
459
+ } |
460
+ {
461
+ type: 'scratch-gui/project-state/DONE_FETCHING_DEFAULT';
462
+ projectData: ProjectData;
463
+ } |
464
+ {
465
+ type: 'scratch-gui/project-state/DONE_FETCHING_WITH_ID';
466
+ projectData: ProjectData;
467
+ } |
468
+ {
469
+ type: 'scratch-gui/project-state/DONE_LOADING_VM_TO_SAVE';
470
+ } |
471
+ {
472
+ type: 'scratch-gui/project-state/DONE_LOADING_VM_WITH_ID';
473
+ } |
474
+ {
475
+ type: 'scratch-gui/project-state/DONE_LOADING_VM_WITHOUT_ID';
476
+ } |
477
+ {
478
+ type: 'scratch-gui/project-state/DONE_REMIXING';
479
+ projectId: string;
480
+ } |
481
+ {
482
+ type: 'scratch-gui/project-state/DONE_UPDATING';
483
+ } |
484
+ {
485
+ type: 'scratch-gui/project-state/DONE_UPDATING_BEFORE_COPY';
486
+ } |
487
+ {
488
+ type: 'scratch-gui/project-state/DONE_UPDATING_BEFORE_NEW';
489
+ } |
490
+ {
491
+ type: 'scratch-gui/project-state/RETURN_TO_SHOWING';
492
+ } |
493
+ {
494
+ type: 'scratch-gui/project-state/SET_PROJECT_ID';
495
+ projectId: string;
496
+ } |
497
+ {
498
+ type: 'scratch-gui/project-state/START_AUTO_UPDATING';
499
+ } |
500
+ {
501
+ type: 'scratch-gui/project-state/START_CREATING_NEW';
502
+ } |
503
+ {
504
+ type: 'scratch-gui/project-state/START_ERROR';
505
+ error: unknown;
506
+ } |
507
+ {
508
+ type: 'scratch-gui/project-state/START_FETCHING_NEW';
509
+ } |
510
+ {
511
+ type: 'scratch-gui/project-state/START_LOADING_VM_FILE_UPLOAD';
512
+ } |
513
+ {
514
+ type: 'scratch-gui/project-state/START_MANUAL_UPDATING';
515
+ } |
516
+ {
517
+ type: 'scratch-gui/project-state/START_REMIXING';
518
+ } |
519
+ {
520
+ type: 'scratch-gui/project-state/START_UPDATING_BEFORE_CREATING_COPY';
521
+ } |
522
+ {
523
+ type: 'scratch-gui/project-state/START_UPDATING_BEFORE_CREATING_NEW';
524
+ } |
525
+ {
526
+ type: 'projectTitle/SET_PROJECT_TITLE';
527
+ title: string;
528
+ } |
529
+ {
530
+ type: 'scratch-gui/restore-deletion/RESTORE_UPDATE';
531
+ state: ScratchGUIState['restoreDeletion']
532
+ } |
533
+ {
534
+ type: 'scratch-gui/StageSize/SET_STAGE_SIZE';
535
+ /**
536
+ * Should only be large or small.
537
+ */
538
+ stageSize: StageDisplaySize;
539
+ } |
540
+ {
541
+ type: 'scratch-gui/targets/UPDATE_TARGET_LIST';
542
+ targets: VM.RenderedTarget[];
543
+ editingTarget: string | null;
544
+ } |
545
+ {
546
+ type: 'scratch-gui/targets/HIGHLIGHT_TARGET';
547
+ targetId: string;
548
+ /**
549
+ * Set to Date.now()
550
+ */
551
+ updateTime: number;
552
+ } |
553
+ {
554
+ type: 'timeout/SET_AUTOSAVE_TIMEOUT_ID';
555
+ id: number | null;
556
+ } |
557
+ {
558
+ type: 'scratch-gui/toolbox/UPDATE_TOOLBOX';
559
+ toolboxXML: string;
560
+ } |
561
+ {
562
+ type: 'scratch-gui/vm-status/SET_RUNNING_STATE';
563
+ running: boolean;
564
+ } |
565
+ {
566
+ type: 'scratch-gui/vm-status/SET_TURBO_STATE';
567
+ turbo: boolean;
568
+ } |
569
+ {
570
+ type: 'scratch-gui/vm-status/SET_STARTED_STATE';
571
+ started: boolean;
572
+ } |
573
+ {
574
+ // Technically exists but unused by scratch-gui.
575
+ // Probably doesn't work properly.
576
+ type: 'scratch-gui/vm/SET_VM';
577
+ vm: VM;
578
+ } |
579
+ {
580
+ type: 'scratch-gui/workspace-metrics/UPDATE_METRICS';
581
+ targetID: string;
582
+ scrollX: number;
583
+ scrollY: number;
584
+ scale: number;
585
+ };
586
+
587
+ interface LocaleState {
588
+ isRtl: boolean;
589
+ locale: string;
590
+ messages: Record<string, string>;
591
+ messagesByLocale: Record<string, Record<string, string>>;
592
+ }
593
+
594
+ type LocaleEvent =
595
+ {
596
+ type: 'scratch-gui/locales/UPDATE_LOCALES';
597
+ messagesByLocale: LocaleState['messagesByLocale'];
598
+ } |
599
+ {
600
+ type: 'scratch-gui/locales/SELECT_LOCALE';
601
+ locale: string;
602
+ };
603
+
604
+ interface SessionState {
605
+ // TODO: Move to scratch-www?
606
+ session?: {
607
+ user?: {
608
+ username?: string;
609
+ };
610
+ };
611
+ }
612
+ }