-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpxt.ts
More file actions
1179 lines (1040 loc) · 30.9 KB
/
pxt.ts
File metadata and controls
1179 lines (1040 loc) · 30.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* MakeCode/pxt types needed for the iframe messages.
*
* These are substantially derived from the PXT project. The types are hard to use
* directly due to logical splits that make sense for MakeCode internally, but not
* for this interface, and TypeScript features that make them hard to reuse in a
* library context: namespaces and const enums.
*
* We've also extracted interfaces for the request parameters separately from the
* request metadata and corrected some types that don't appear to behave as
* described.
*
* Original is Copyright (c) Microsoft Corporation
* MIT licensed: https://github.com/microsoft/pxt/blob/master/LICENSE
*
* Modifications are Copright (c) Micro:bit Educational Foundation and contributors
* 2024.
*/
/* eslint-disable @typescript-eslint/no-explicit-any */
export interface InstallHeader {
name: string; // script name, should always be in sync with pxt.json name
meta: {
// json script meta data
blocksWidth?: number;
blocksHeight?: number;
versions?: TargetVersions;
};
editor: string; // editor that we're in
board?: string; // name of the package that contains the board.json info
temporary?: boolean; // don't serialize project
// older script might miss this
target: string;
// older scripts might miss this
targetVersion: string;
pubId: string; // for published scripts
pubCurrent: boolean; // is this exactly pubId, or just based on it
pubVersions?: {
id: string;
type: 'snapshot' | 'permalink';
}[];
pubPermalink?: string; // permanent (persistent) share ID
anonymousSharePreference?: boolean; // if true, default to sharing anonymously even when logged in
githubId?: string;
githubTag?: string; // the release tag if any (commit.tag)
githubCurrent?: boolean;
// in progress tutorial if any
tutorial?: TutorialOptions;
// completed tutorial info if any
tutorialCompleted?: {
// id of the tutorial
id: string;
// number of steps completed
steps: number;
};
// workspace guid of the extension under test
extensionUnderTest?: string;
// id of cloud user who created this project
cloudUserId?: string;
isSkillmapProject?: boolean;
}
export interface Header extends InstallHeader {
id: string; // guid (generated by us)
path?: string; // for workspaces that require it
recentUse: number; // seconds since epoch
modificationTime: number; // seconds since epoch
icon?: string; // icon uri
isDeleted: boolean; // mark whether or not a header has been deleted
saveId?: any; // used to determine whether a project has been edited while we're saving to cloud
// For cloud sync (local only metadata)
cloudVersion: string; // The cloud-assigned version number (e.g. etag)
cloudCurrent: boolean; // Has the current version of the project been pushed to cloud
cloudLastSyncTime: number; // seconds since epoch
// Used for Updating projects
backupRef?: string; // guid of backed-up project (present if an update was interrupted)
isBackup?: boolean; // True if this is a backed-up project (for a pending update)
// Other
_rev: string; // used for idb / pouchdb revision tracking
}
export type ScriptText = Record<string, string>;
export interface MakeCodeProject {
header?: Header;
text?: ScriptText;
}
export interface Asset {
name: string;
size: number;
url: string;
}
export type Version = any;
export interface File {
header: Header;
text: ScriptText;
version: Version;
}
export interface EditorMessage {
/**
* Constant identifier
*/
type: 'pxteditor' | 'pxthost' | 'pxtpkgext' | 'pxtsim';
/**
* Original request id
*/
id?: string;
/**
* flag to request response
*/
response?: boolean;
/**
* Frame identifier that can be passed to the iframe by adding the frameId query parameter
*/
frameId?: string;
}
// In practice some use the `resp` and some use sibling fields.
export interface EditorMessageResponse extends EditorMessage {
/**
* Additional response payload provided by the command
*/
resp?: any;
/**
* indicate if operation started or completed successfully
*/
success: boolean;
/**
* Error object if any
*/
error?: any;
}
export interface EditorMessageRequest extends EditorMessage {
/**
* Request action
*/
action:
| 'switchblocks'
| 'switchjavascript'
| 'switchpython'
| 'startsimulator'
| 'restartsimulator'
| 'stopsimulator' // EditorMessageStopRequest
| 'hidesimulator'
| 'showsimulator'
| 'closeflyout'
| 'newproject'
| 'importproject'
| 'importexternalproject'
| 'importtutorial'
| 'openheader'
| 'proxytosim' // EditorMessageSimulatorMessageProxyRequest
| 'undo'
| 'redo'
| 'renderblocks'
| 'renderpython'
| 'renderxml'
| 'renderbyblockid'
| 'setscale'
| 'startactivity'
| 'saveproject'
| 'compile'
| 'unloadproject'
| 'shareproject'
| 'savelocalprojectstocloud'
| 'projectcloudstatus'
| 'requestprojectcloudstatus'
| 'convertcloudprojectstolocal'
| 'setlanguagerestriction'
| 'gettoolboxcategories'
| 'toggletrace' // EditorMessageToggleTraceRequest
| 'showthemepicker'
| 'togglehighcontrast'
| 'sethighcontrast' // EditorMessageSetHighContrastRequest
| 'togglegreenscreen'
| 'togglekeyboardcontrols'
| 'settracestate' //
| 'setsimulatorfullscreen' // EditorMessageSimulatorFullScreenRequest
| 'print' // print code
| 'pair' // pair device
| 'workspacesync' // EditorWorspaceSyncRequest
| 'workspacereset'
| 'workspacesave' // EditorWorkspaceSaveRequest
| 'workspaceloaded'
| 'workspaceevent' // EditorWorspaceEvent
| 'workspacediagnostics' // compilation results
| 'event'
| 'simevent'
| 'info' // return info data`
| 'tutorialevent'
| 'editorcontentloaded'
| 'serviceworkerregistered'
| 'runeval';
}
/**
* Request sent by the editor when a tick/error/expection is registered
*/
export interface EditorMessageEventRequest extends EditorMessageRequest {
action: 'event';
// metric identifier
tick: string;
// error category if any
category?: string;
// error message if any
message?: string;
// custom data
data?: Record<string, string | number>;
}
export type EditorMessageTutorialEventRequest =
| EditorMessageTutorialProgressEventRequest
| EditorMessageTutorialCompletedEventRequest
| EditorMessageTutorialLoadedEventRequest
| EditorMessageTutorialExitEventRequest;
export interface EditorMessageTutorialProgressEventRequest
extends EditorMessageRequest {
action: 'tutorialevent';
tutorialEvent: 'progress';
currentStep: number;
totalSteps: number;
isCompleted: boolean;
tutorialId: string;
projectHeaderId: string;
}
export interface EditorMessageTutorialCompletedEventRequest
extends EditorMessageRequest {
action: 'tutorialevent';
tutorialEvent: 'completed';
tutorialId: string;
projectHeaderId: string;
}
export interface EditorMessageTutorialLoadedEventRequest
extends EditorMessageRequest {
action: 'tutorialevent';
tutorialEvent: 'loaded';
tutorialId: string;
projectHeaderId: string;
}
export interface EditorMessageTutorialExitEventRequest
extends EditorMessageRequest {
action: 'tutorialevent';
tutorialEvent: 'exit';
tutorialId: string;
projectHeaderId: string;
}
export interface EditorMessageStopRequest extends EditorMessageRequest {
action: 'stopsimulator';
/**
* Indicates if simulator iframes should be unloaded or kept hot.
*/
unload?: boolean;
}
export interface EditorMessageNewProjectRequest extends EditorMessageRequest {
action: 'newproject';
/**
* Additional optional to create new project
*/
options?: ProjectCreationOptions;
}
export interface EditorContentLoadedRequest extends EditorMessageRequest {
action: 'editorcontentloaded';
}
export interface EditorMessageSetScaleRequest extends EditorMessageRequest {
action: 'setscale';
scale: number;
}
export interface EditorMessageSimulatorMessageProxyRequest
extends EditorMessageRequest {
action: 'proxytosim';
/**
* Content to send to the simulator
*/
content: any;
}
export interface EditorWorkspaceSyncRequest extends EditorMessageRequest {
/**
* Synching projects from host into
*/
action: 'workspacesync' | 'workspacereset' | 'workspaceloaded';
}
export interface EditorWorkspaceEvent extends EditorMessageRequest {
action: 'workspaceevent';
event: EditorEvent;
}
export interface EditorWorkspaceDiagnostics extends EditorMessageRequest {
action: 'workspacediagnostics';
operation: 'compile' | 'decompile' | 'typecheck';
output: string;
diagnostics: {
code: number;
category: 'error' | 'warning' | 'message';
fileName?: string;
start?: number;
length?: number;
line?: number;
column?: number;
endLine?: number;
endColumn?: number;
}[];
}
// UI properties to sync on load
export interface EditorSyncState {
// (optional) filtering argument
filters?: ProjectFilters;
// (optional) show or hide the search bar
searchBar?: boolean;
}
export interface EditorWorkspaceSyncResponse extends EditorMessageResponse {
/*
* Full list of project, required for init
*/
projects: MakeCodeProject[];
// (optional) filtering argument
editor?: EditorSyncState;
// (optional) controller id, used for determining what the parent controller is
controllerId?: string;
}
export interface EditorWorkspaceSaveRequest extends EditorMessageRequest {
action: 'workspacesave';
/*
* Modified project
*/
project: MakeCodeProject;
}
export interface ImportProjectOptions {
// project to load
project: MakeCodeProject;
// (optional) filtering argument
filters?: ProjectFilters;
searchBar?: boolean;
}
export interface EditorMessageImportProjectRequest
extends EditorMessageRequest,
ImportProjectOptions {
action: 'importproject';
}
export interface ImportExternalProjectOptions {
// project to load
project: MakeCodeProject;
}
export interface EditorMessageImportExternalProjectRequest
extends EditorMessageRequest,
ImportExternalProjectOptions {
action: 'importexternalproject';
}
export interface EditorMessageImportExternalProjectResponse
extends EditorMessageResponse {
action: 'importexternalproject';
resp: {
importUrl: string;
};
}
export interface EditorMessageSaveLocalProjectsToCloud
extends EditorMessageRequest {
action: 'savelocalprojectstocloud';
headerIds: string[];
}
export interface EditorMessageSaveLocalProjectsToCloudResponse
extends EditorMessageResponse {
action: 'savelocalprojectstocloud';
headerIdMap?: Record<string, string>;
}
export interface EditorMessageProjectCloudStatus extends EditorMessageRequest {
action: 'projectcloudstatus';
headerId: string;
status: CloudStatus;
}
export interface EditorMessageRequestProjectCloudStatus
extends EditorMessageRequest {
action: 'requestprojectcloudstatus';
headerIds: string[];
}
export interface EditorMessageConvertCloudProjectsToLocal
extends EditorMessageRequest {
action: 'convertcloudprojectstolocal';
userId: string;
}
export interface EditorMessageImportTutorialRequest
extends EditorMessageRequest {
action: 'importtutorial';
// markdown to load
markdown: string;
}
export interface EditorMessageOpenHeaderRequest extends EditorMessageRequest {
action: 'openheader';
headerId: string;
}
export interface RenderBlocksOptions {
// typescript code to render
ts: string;
// rendering options
snippetMode?: boolean;
layout?: BlockLayout;
}
export interface EditorMessageRenderBlocksRequest
extends EditorMessageRequest,
RenderBlocksOptions {
action: 'renderblocks';
}
export interface RenderXmlOptions {
// xml to render
xml: string;
snippetMode?: boolean;
layout?: BlockLayout;
}
export interface EditorMessageRenderXmlRequest
extends EditorMessageRequest,
RenderXmlOptions {
action: 'renderxml';
}
export interface RenderByBlockIdOptions {
blockId: string;
snippetMode?: boolean;
layout?: BlockLayout;
}
export interface EditorMessageRenderByBlockIdRequest
extends EditorMessageRequest,
RenderByBlockIdOptions {
action: 'renderbyblockid';
}
export interface EditorMessageRenderBlocksResponse {
// Corrected vs pxt
resp: string | undefined;
}
export interface EditorMessageRenderXmlResponse {
// Corrected vs pxt
resp: string | undefined;
}
export interface EditorMessageRenderByBlockIdResponse {
// Corrected vs pxt
resp: string | undefined;
}
export interface EditorMessageRenderPythonRequest extends EditorMessageRequest {
action: 'renderpython';
// typescript code to render
ts: string;
}
export interface EditorMessageRenderPythonResponse {
// Corrected vs `python` in pxt
resp: string;
}
export interface EditorSimulatorEvent extends EditorMessageRequest {
action: 'simevent';
subtype: 'toplevelfinished' | 'started' | 'stopped' | 'resumed';
}
export interface EditorSimulatorStoppedEvent extends EditorSimulatorEvent {
subtype: 'stopped';
exception?: string;
}
export interface EditorMessageToggleTraceRequest extends EditorMessageRequest {
action: 'toggletrace';
// interval speed for the execution trace
intervalSpeed?: number;
}
export interface EditorMessageSetTraceStateRequest
extends EditorMessageRequest {
action: 'settracestate';
enabled: boolean;
// interval speed for the execution trace
intervalSpeed?: number;
}
export interface EditorMessageSetSimulatorFullScreenRequest
extends EditorMessageRequest {
action: 'setsimulatorfullscreen';
enabled: boolean;
}
export interface EditorMessageSetHighContrastRequest
extends EditorMessageRequest {
action: 'sethighcontrast';
on: boolean;
}
export interface StartActivityOptions {
activityType: 'tutorial' | 'example' | 'recipe';
path: string;
title?: string;
previousProjectHeaderId?: string;
carryoverPreviousCode?: boolean;
}
export interface EditorMessageStartActivity
extends EditorMessageRequest,
StartActivityOptions {
action: 'startactivity';
}
export interface InfoMessage {
versions: TargetVersions;
locale: string;
availableLocales?: string[];
keyboardControls: boolean;
}
export interface PackageExtensionData {
ts: string;
json?: any;
}
export interface EditorPkgExtMessageRequest extends EditorMessageRequest {
// extension identifier
package: string;
}
export interface EditorPkgExtMessageResponse extends EditorMessageResponse {
// extension identifier
package: string;
}
export interface EditorSimulatorTickEvent extends EditorMessageEventRequest {
type: 'pxtsim';
}
export interface EditorShareRequest extends EditorMessageRequest {
action: 'shareproject';
headerId: string;
projectName: string;
}
export interface ShareResult {
embed: {
code: string;
editor: string;
simulator: string;
};
qr: string;
url: string;
}
// Supertype and resp type corrected vs pxt
export interface EditorShareResponse extends EditorMessageResponse {
action: 'shareproject';
resp: ShareResult;
}
export interface EditorSetLanguageRestriction extends EditorMessageRequest {
action: 'setlanguagerestriction';
restriction: LanguageRestriction;
}
export interface EditorMessageGetToolboxCategoriesRequest
extends EditorMessageRequest {
action: 'gettoolboxcategories';
advanced?: boolean;
}
export interface EditorMessageServiceWorkerRegisteredRequest
extends EditorMessageRequest {
action: 'serviceworkerregistered';
}
export interface EditorMessageGetToolboxCategoriesResponse {
categories: ToolboxCategoryDefinition[];
}
export interface ProjectTemplate {
id: string;
config: PackageConfig;
files: Record<string, string>;
}
export interface ProjectCreationOptions {
prj?: ProjectTemplate;
name?: string;
documentation?: string;
filesOverride?: Record<string, string>;
filters?: ProjectFilters;
temporary?: boolean;
tutorial?: TutorialOptions;
dependencies?: Record<string, string>;
tsOnly?: boolean; // DEPRECATED: use LanguageRestriction.NoBlocks or LanguageRestriction.JavaScriptOnly instead
languageRestriction?: LanguageRestriction;
preferredEditor?: string; // preferred editor to open, pxt.BLOCKS_PROJECT_NAME, ...
extensionUnderTest?: string; // workspace id of the extension under test
skillmapProject?: boolean;
simTheme?: Partial<PackageConfig>;
firstProject?: boolean;
}
export interface ProjectFilters {
namespaces?: { [index: string]: FilterState };
blocks?: { [index: string]: FilterState };
fns?: { [index: string]: FilterState };
defaultState?: FilterState;
}
export enum FilterState {
Hidden = 0,
Visible = 1,
Disabled = 2,
}
export enum BlockLayout {
None = 0,
Align = 1,
// Shuffle deprecated
Clean = 3,
Flow = 4,
}
export type EditorType = 'blocks' | 'ts';
// Switched from supertype to discriminated union
export type EditorEvent = CreateEvent | UIEvent;
export interface CreateEvent {
type: 'create';
blockId: string;
}
export interface UIEvent {
type: 'ui';
action: 'groupHelpClicked';
data?: Record<string, string>;
}
export interface NativeHostMessage {
name?: string;
download?: string;
save?: string;
cmd?: string;
}
// This is defined with the sim types and copied in here
export interface ImportFileOptions {
filename: string;
parts: (string | ArrayBuffer)[];
}
// This is defined in pxtarget.d.ts as a const enum but is on our interface
export type LanguageRestriction =
| /* Standard */ ''
| 'python-only'
| 'javascript-only'
| 'blocks-only'
| 'no-blocks'
| 'no-python'
| 'no-javascript';
export interface ToolboxCategoryDefinition {
/**
* The display name for the category
*/
name?: string;
/**
* The icon of this category
*/
icon?: string;
/**
* The color of this category
*/
color?: string;
/**
* The weight of the category relative to other categories in the toolbox
*/
weight?: number;
/**
* Whether or not the category should be placed in the advanced category
*/
advanced?: boolean;
/**
* Blocks to appear in the category. Specifying this field will override
* all existing blocks in the category. The ordering of the blocks is
* determined by the ordering of this array.
*/
blocks?: ToolboxBlockDefinition[];
/**
* Ordering of category groups
*/
groups?: string[];
}
export interface ToolboxBlockDefinition {
/**
* Internal id used to refer to this block or snippet, must be unique
*/
name: string;
/**
* Group label used to categorize block. Blocks are arranged with other
* blocks that share the same group.
*/
group?: string;
/**
* Indicates an advanced API. Advanced APIs appear after basic ones in the
* toolbox
*/
advanced?: boolean;
/**
* The weight for the block. Blocks are arranged in order of they appear in the category
* definition's array but the weight can be specified in the case that other APIs are
* dynamically added to the category (eg. loops.forever())
*/
weight?: number;
/**
* Description of code to appear in the hover text
*/
jsDoc?: string;
/**
* TypeScript snippet of code to insert when dragged into editor
*/
snippet?: string;
/**
* Python snippet of code to insert when dragged into editor
*/
pySnippet?: string;
/**
* TypeScript name used for highlighting the snippet, uses name if not defined
*/
snippetName?: string;
/**
* Python name used for highlighting the snippet, uses name if not defined
*/
pySnippetName?: string;
/**
* Display just the snippet and nothing else. Should be set to true for
* language constructs (eg. for-loops) and to false for function
* calls (eg. Math.random())
*/
snippetOnly?: boolean;
/**
* The return type of the block. This is used to determine the shape of the block rendered.
*/
retType?: string;
/**
* The block definition in XML for the blockly toolbox.
*/
blockXml?: string;
/**
* The Blockly block id used to identify this block.
*/
blockId?: string;
}
export type CloudStatus =
| 'none'
| 'synced'
| 'justSynced'
| 'offline'
| 'syncing'
| 'conflict'
| 'localEdits';
export type CodeCardType =
| 'file'
| 'example'
| 'codeExample'
| 'tutorial'
| 'side'
| 'template'
| 'package'
| 'hw'
| 'forumUrl'
| 'forumExample'
| 'sharedExample'
| 'link';
export type CodeCardEditorType = 'blocks' | 'js' | 'py';
export interface DependencyMap<T> {
[index: string]: T;
}
export interface TargetVersions {
target: string;
targetId?: string;
targetWebsite?: string;
pxt?: string;
tag?: string;
branch?: string;
commits?: string; // URL
}
export interface CodeCardAction {
url: string;
editor?: CodeCardEditorType;
cardType?: CodeCardType;
}
/**
* The schema for the pxt.json package files
*/
export interface PackageConfig {
name: string;
version?: string;
// installedVersion?: string; moved to Package class
// url to icon -- support for built-in packages only
icon?: string;
// semver description for support target version
documentation?: string; // doc page to open when loading project, used by sidedocs
targetVersions?: TargetVersions; // versions of the target/pxt the package was compiled against
description?: string;
dependencies: DependencyMap<string>;
license?: string;
authors?: string[];
files: string[];
simFiles?: string[];
testFiles?: string[];
fileDependencies?: DependencyMap<string>; // exclude certain files if dependencies are not fulfilled
preferredEditor?: string; // tsprj, blocksprj, pyprj
languageRestriction?: LanguageRestriction; // language restrictions that have been placed on the package
testDependencies?: Record<string, string>;
cppDependencies?: Record<string, string>;
public?: boolean;
partial?: boolean; // true if project is not compileable on its own (eg base)
binaryonly?: boolean;
platformio?: {
dependencies?: DependencyMap<string>;
};
compileServiceVariant?: string;
palette?: string[];
paletteNames?: string[];
screenSize?: {
width: number;
height: number;
};
yotta?: YottaConfig;
codal?: {
libraries?: string[];
};
npmDependencies?: DependencyMap<string>;
card?: CodeCard;
additionalFilePath?: string;
additionalFilePaths?: string[];
core?: boolean;
// used for sorting for core packages
weight?: number;
gistId?: string;
extension?: PackageExtension; // describe the associated extension if any
isExtension?: boolean; // is this package an extension
dalDTS?: {
corePackage?: string;
includeDirs?: string[];
excludePrefix?: string[];
compileServiceVariant?: string;
};
features?: string[];
hidden?: boolean; // hide package from package selection dialog
searchOnly?: boolean; // do not show by default, only as search result
skipLocalization?: boolean;
snippetBuilders?: SnippetConfig[];
experimentalHw?: boolean;
requiredCategories?: string[]; // ensure that those block categories are visible
supportedTargets?: string[]; // a hint about targets in which this extension is supported
firmwareUrl?: string; // link to documentation page about upgrading firmware
disablesVariants?: string[]; // don't build these variants, when this extension is enabled
utf8?: boolean; // force compilation with UTF8 enabled
disableTargetTemplateFiles?: boolean; // do not override target template files when commiting to github
theme?: string | Record<string, string>;
assetPack?: boolean; // if set to true, only the assets of this project will be imported when added as an extension (no code)
assetPacks?: DependencyMap<boolean>; // a map of dependency id to boolean that indicates which dependencies should be imported as asset packs
}
export interface PackageExtension {
// Namespace to add the button under, defaults to package name
namespace?: string;
// Group to place button in
group?: string;
// Label for the flyout button, defaults to `Editor`
label?: string;
// for new category, category color
color?: string;
// for new category, is category advanced
advanced?: boolean;
// trusted custom editor url, must be register in targetconfig.json under approvedEditorExtensionUrls
url?: string;
// local debugging URL used when served through pxt serve and debugExtensions=1 mode
localUrl?: string;
}
export interface YottaConfig {
dependencies?: DependencyMap<string>;
config?: any;
/**
* Overridable config flags
*/
optionalConfig?: any;
userConfigs?: {
description: string;
config: any;
}[];
/* deprecated */
configIsJustDefaults?: boolean;
/* deprecated */
ignoreConflicts?: boolean;
}
export interface CodeCard {
name?: string;
shortName?: string;
title?: string;
role?: string;
ariaLabel?: string;
label?: string;
labelIcon?: string;
labelClass?: string;
tags?: string[]; // tags shown in home screen, colors specified in theme
tabIndex?: number;
style?: string; // "card" | "item" | undefined;
color?: string; // one of semantic ui colors
description?: string;
extracontent?: string;
blocksXml?: string;
typeScript?: string;
imageUrl?: string;
largeImageUrl?: string;
videoUrl?: string;
youTubeId?: string;
youTubePlaylistId?: string; // playlist this video belongs to
buttonLabel?: string;
actionIcon?: string; // icon to override default icon on the action button
time?: number;
url?: string;
learnMoreUrl?: string;
buyUrl?: string;
feedbackUrl?: string;
responsive?: boolean;
cardType?: CodeCardType;
editor?: CodeCardEditorType;
otherActions?: CodeCardAction[];
directOpen?: boolean; // skip the details view, directly do the card action
projectId?: string; // the project's header ID
header?: string;
tutorialStep?: number;
tutorialLength?: number;