@microbit/makecode-embed 0.0.0-alpha.2

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 (100) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +43 -0
  3. package/dist/react/MakeCodeBlocksRendering.d.ts +24 -0
  4. package/dist/react/MakeCodeBlocksRendering.js +80 -0
  5. package/dist/react/MakeCodeBlocksRendering.js.map +1 -0
  6. package/dist/react/MakeCodeFrame.d.ts +38 -0
  7. package/dist/react/MakeCodeFrame.js +72 -0
  8. package/dist/react/MakeCodeFrame.js.map +1 -0
  9. package/dist/react/MakeCodeRenderBlocksProvider.d.ts +8 -0
  10. package/dist/react/MakeCodeRenderBlocksProvider.js +14 -0
  11. package/dist/react/MakeCodeRenderBlocksProvider.js.map +1 -0
  12. package/dist/react/index.d.ts +4 -0
  13. package/dist/react/index.js +4 -0
  14. package/dist/react/index.js.map +1 -0
  15. package/dist/react/useMakeCodeRenderBlocks.d.ts +6 -0
  16. package/dist/react/useMakeCodeRenderBlocks.js +16 -0
  17. package/dist/react/useMakeCodeRenderBlocks.js.map +1 -0
  18. package/dist/vanilla/examples.d.ts +3 -0
  19. package/dist/vanilla/examples.js +17 -0
  20. package/dist/vanilla/examples.js.map +1 -0
  21. package/dist/vanilla/index.d.ts +4 -0
  22. package/dist/vanilla/index.js +4 -0
  23. package/dist/vanilla/index.js.map +1 -0
  24. package/dist/vanilla/makecode-frame-driver.d.ts +263 -0
  25. package/dist/vanilla/makecode-frame-driver.js +609 -0
  26. package/dist/vanilla/makecode-frame-driver.js.map +1 -0
  27. package/dist/vanilla/makecode-render-blocks.d.ts +32 -0
  28. package/dist/vanilla/makecode-render-blocks.js +214 -0
  29. package/dist/vanilla/makecode-render-blocks.js.map +1 -0
  30. package/dist/vanilla/pxt.d.ts +875 -0
  31. package/dist/vanilla/pxt.js +33 -0
  32. package/dist/vanilla/pxt.js.map +1 -0
  33. package/package.json +68 -0
  34. package/storybook-static/assets/Color-KGDBMAHA-Dc_5Y-jU.js +1 -0
  35. package/storybook-static/assets/DocsRenderer-PKQXORMH-Cguo1Gle.js +574 -0
  36. package/storybook-static/assets/MakeCodeBlocksRendering.stories-BlUxOnyw.js +464 -0
  37. package/storybook-static/assets/MakeCodeFrame.stories-CLEdpFft.js +47 -0
  38. package/storybook-static/assets/entry-preview-BD3I3EAZ.js +1 -0
  39. package/storybook-static/assets/entry-preview-docs-BZaLlg6H.js +62 -0
  40. package/storybook-static/assets/iframe-BXldcLa5.js +2 -0
  41. package/storybook-static/assets/index-BrV66TDq.js +1 -0
  42. package/storybook-static/assets/index-CCdbwdZP.js +1 -0
  43. package/storybook-static/assets/index-D-8MO0q_.js +1 -0
  44. package/storybook-static/assets/index-DrFu-skq.js +6 -0
  45. package/storybook-static/assets/index-SSXOyoI7.js +9 -0
  46. package/storybook-static/assets/isArray-D0A16MCt.js +8 -0
  47. package/storybook-static/assets/jsx-runtime-DFKZ3ixi.js +9 -0
  48. package/storybook-static/assets/preview-9hFJSo5S.js +20 -0
  49. package/storybook-static/assets/preview-BJPLiuSt.js +1 -0
  50. package/storybook-static/assets/preview-BnWGZYux.js +1 -0
  51. package/storybook-static/assets/preview-BpcF_O6y.js +7 -0
  52. package/storybook-static/assets/preview-BrwKgnKZ.js +2 -0
  53. package/storybook-static/assets/preview-CIRcjyVj.js +1 -0
  54. package/storybook-static/assets/preview-Cdum89jS.js +1 -0
  55. package/storybook-static/assets/preview-Ct5NkTJf.js +1 -0
  56. package/storybook-static/assets/preview-DB9FwMii.js +396 -0
  57. package/storybook-static/assets/preview-gLmJTRpJ.js +28 -0
  58. package/storybook-static/assets/react-18-4p7UWKLl.js +24 -0
  59. package/storybook-static/favicon.svg +1 -0
  60. package/storybook-static/iframe.html +639 -0
  61. package/storybook-static/index.html +181 -0
  62. package/storybook-static/index.json +1 -0
  63. package/storybook-static/nunito-sans-bold-italic.woff2 +0 -0
  64. package/storybook-static/nunito-sans-bold.woff2 +0 -0
  65. package/storybook-static/nunito-sans-italic.woff2 +0 -0
  66. package/storybook-static/nunito-sans-regular.woff2 +0 -0
  67. package/storybook-static/project.json +1 -0
  68. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js +333 -0
  69. package/storybook-static/sb-addons/chromatic-com-storybook-9/manager-bundle.js.LEGAL.txt +40 -0
  70. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js +3 -0
  71. package/storybook-static/sb-addons/essentials-actions-3/manager-bundle.js.LEGAL.txt +0 -0
  72. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js +12 -0
  73. package/storybook-static/sb-addons/essentials-backgrounds-4/manager-bundle.js.LEGAL.txt +0 -0
  74. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js +412 -0
  75. package/storybook-static/sb-addons/essentials-controls-2/manager-bundle.js.LEGAL.txt +0 -0
  76. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js +3 -0
  77. package/storybook-static/sb-addons/essentials-measure-7/manager-bundle.js.LEGAL.txt +0 -0
  78. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js +3 -0
  79. package/storybook-static/sb-addons/essentials-outline-8/manager-bundle.js.LEGAL.txt +0 -0
  80. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js +3 -0
  81. package/storybook-static/sb-addons/essentials-toolbars-6/manager-bundle.js.LEGAL.txt +0 -0
  82. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js +3 -0
  83. package/storybook-static/sb-addons/essentials-viewport-5/manager-bundle.js.LEGAL.txt +0 -0
  84. package/storybook-static/sb-addons/interactions-10/manager-bundle.js +234 -0
  85. package/storybook-static/sb-addons/interactions-10/manager-bundle.js.LEGAL.txt +0 -0
  86. package/storybook-static/sb-addons/links-1/manager-bundle.js +3 -0
  87. package/storybook-static/sb-addons/links-1/manager-bundle.js.LEGAL.txt +0 -0
  88. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js +3 -0
  89. package/storybook-static/sb-addons/storybook-core-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
  90. package/storybook-static/sb-common-assets/favicon.svg +1 -0
  91. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  92. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  93. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  94. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  95. package/storybook-static/sb-manager/globals-module-info.js +995 -0
  96. package/storybook-static/sb-manager/globals-runtime.js +53525 -0
  97. package/storybook-static/sb-manager/globals.js +48 -0
  98. package/storybook-static/sb-manager/runtime.js +11884 -0
  99. package/storybook-static/sb-preview/globals.js +33 -0
  100. package/storybook-static/sb-preview/runtime.js +9485 -0
@@ -0,0 +1,263 @@
1
+ import { EditorContentLoadedRequest, EditorEvent, EditorMessageTutorialEventRequest, EditorWorkspaceSaveRequest, EditorWorkspaceSyncRequest, ImportExternalProjectOptions, ImportFileOptions, ImportProjectOptions, InfoMessage, LanguageRestriction, Project, ProjectCreationOptions, ProjectFilters, RenderBlocksOptions, RenderByBlockIdOptions, RenderXmlOptions, ShareResult, StartActivityOptions, ToolboxCategoryDefinition } from './pxt.js';
2
+ interface EditorShareOptions {
3
+ headerId: string;
4
+ projectName: string;
5
+ }
6
+ export interface Options {
7
+ /**
8
+ * A function that provides the initial set of projects to be used when initialising MakeCode.
9
+ *
10
+ * This will also be used if the iframe reloads itself.
11
+ *
12
+ * The projects will receive updates via `onWorkspaceSave` and should be stored keyed by header
13
+ * id.
14
+ */
15
+ initialProjects: () => Promise<Project[]>;
16
+ /**
17
+ * Set this to a value representing your app.
18
+ */
19
+ controllerId?: string;
20
+ /**
21
+ * Filters affecting the configuration of MakeCode.
22
+ */
23
+ filters?: ProjectFilters;
24
+ /**
25
+ * Whether to show the search bar.
26
+ */
27
+ searchBar?: boolean;
28
+ /**
29
+ * Called when the main editor area is ready (e.g. after a project load).
30
+ */
31
+ onEditorContentLoaded?(event: EditorContentLoadedRequest): void;
32
+ /**
33
+ * This is not typically needed as the driver responds to MakeCode's request to sync using the initialProjects option.
34
+ */
35
+ onWorkspaceSync?(event: EditorWorkspaceSyncRequest): void;
36
+ /**
37
+ * Called when the workspace sync is complete.
38
+ */
39
+ onWorkspaceLoaded?(event: EditorWorkspaceSyncRequest): void;
40
+ /**
41
+ * Implement this to update the data store that `initialProjects` reads from.
42
+ */
43
+ onWorkspaceSave?(event: EditorWorkspaceSaveRequest): void;
44
+ /**
45
+ * This is only called via MakeCode UI, which is not visible in embedded mode.
46
+ *
47
+ * It's intention is to delete all projects/settings.
48
+ */
49
+ onWorkspaceReset?(event: EditorWorkspaceSyncRequest): void;
50
+ /**
51
+ * Editor events including detail on block usage and help interactions.
52
+ */
53
+ onWorkspaceEvent?(event: EditorEvent): void;
54
+ /**
55
+ * Updates as a user progresses through a tutorial.
56
+ */
57
+ onTutorialEvent?(event: EditorMessageTutorialEventRequest): void;
58
+ /**
59
+ * Requests the embedding app handles a download.
60
+ *
61
+ * Applies only with `controller` set to `2`.
62
+ */
63
+ onDownload?: (download: {
64
+ name: string;
65
+ hex: string;
66
+ }) => void;
67
+ /**
68
+ * Requests the embedding app handles a save.
69
+ *
70
+ * Applies only with `controller` set to `2`.
71
+ */
72
+ onSave?: (save: {
73
+ name: string;
74
+ hex: string;
75
+ }) => void;
76
+ /**
77
+ * Requests the embedding app handles a press/tap on the back arrow.
78
+ *
79
+ * Applies only with `controller` set to `2`.
80
+ */
81
+ onBack?: () => void;
82
+ /**
83
+ * Requests the embedding app handles a long press/tap on the back arrow.
84
+ * This is optional.
85
+ *
86
+ * Applies only with `controller` set to `2`.
87
+ */
88
+ onBackLongPress?: () => void;
89
+ }
90
+ /**
91
+ * A driver for MakeCode.
92
+ *
93
+ * This stores state to correlate requests/responses to and from MakeCode.
94
+ */
95
+ export declare class MakeCodeFrameDriver {
96
+ private options;
97
+ private iframe;
98
+ private ready;
99
+ private messageQueue;
100
+ private nextId;
101
+ private pendingResponses;
102
+ private listener;
103
+ constructor(options: Options, iframe: () => HTMLIFrameElement | undefined);
104
+ initialize(): void;
105
+ setOptions(options: Options): void;
106
+ dispose(): void;
107
+ private sendRequest;
108
+ private sendMessage;
109
+ private sendMessageNoReadyCheck;
110
+ private handleWorkspaceSync;
111
+ /**
112
+ * Switch the MakeCode to blocks mode.
113
+ *
114
+ * You can find the current mode in the project.
115
+ */
116
+ switchBlocks(): Promise<void>;
117
+ /**
118
+ * Switch the MakeCode to JavaScript mode.
119
+ *
120
+ * You can find the current mode in the project.
121
+ */
122
+ switchJavascript(): Promise<void>;
123
+ /**
124
+ * Switch the MakeCode to JavaScript mode.
125
+ *
126
+ * You can find the current mode in the project.
127
+ */
128
+ switchPython(): Promise<void>;
129
+ /**
130
+ * Start the simulator.
131
+ */
132
+ startSimulator(): Promise<void>;
133
+ /**
134
+ * Restarts the simulator.
135
+ */
136
+ restartSimulator(): Promise<void>;
137
+ /**
138
+ * Stops the simulator.
139
+ */
140
+ stopSimulator(options?: {
141
+ /**
142
+ * Optionally unload the simulator (removes its UI)
143
+ */
144
+ unload: boolean;
145
+ }): Promise<void>;
146
+ /**
147
+ * Hides the simulator. The user can reverse this via the UI.
148
+ */
149
+ hideSimulator(): Promise<void>;
150
+ /**
151
+ * Show the simulator. The user can reverse this via the UI.
152
+ */
153
+ showSimulator(): Promise<void>;
154
+ /**
155
+ * Closes the toolbox and similar UX.
156
+ */
157
+ closeFlyout(): Promise<void>;
158
+ /**
159
+ * Create a new project.
160
+ */
161
+ newProject(options?: ProjectCreationOptions): Promise<void>;
162
+ /**
163
+ * Import a project.
164
+ *
165
+ * The project needs to have a header.
166
+ * Otherwise consider `newProject`
167
+ */
168
+ importProject(options: ImportProjectOptions): Promise<void>;
169
+ /**
170
+ * Create a URL that can be used to import a project into MakeCode.
171
+ *
172
+ * This can be useful if MakeCode is embedded in one application but you want to be able to export to non-embedded MakeCode.
173
+ *
174
+ * The applications must be part of the same site as the process relies on shared client-side storage.
175
+ *
176
+ * The URL must be used immediately as it won't remain valid if another call is made.
177
+ */
178
+ importExternalProject(options: ImportExternalProjectOptions): Promise<{
179
+ importUrl: string;
180
+ }>;
181
+ /**
182
+ * Import a tutorial from markdown text.
183
+ *
184
+ * See also `startActivity`.
185
+ */
186
+ importTutorial(options: {
187
+ markdown: string;
188
+ }): Promise<void>;
189
+ /**
190
+ * Open a MakeCode project.
191
+ */
192
+ openHeader(headerId: string): Promise<void>;
193
+ /**
194
+ * Undo.
195
+ */
196
+ undo(): Promise<void>;
197
+ /**
198
+ * Redo.
199
+ */
200
+ redo(): Promise<void>;
201
+ renderBlocks(options: RenderBlocksOptions): Promise<string>;
202
+ renderPython(options: {
203
+ ts: string;
204
+ }): Promise<string | undefined>;
205
+ renderXml(options: RenderXmlOptions): Promise<string | undefined>;
206
+ /**
207
+ * Renders an individual block by type (e.g. basic_show_id) to an SVG data URI.
208
+ */
209
+ renderByBlockId(options: RenderByBlockIdOptions): Promise<string | undefined>;
210
+ setScale({ scale }: {
211
+ scale: number;
212
+ }): Promise<void>;
213
+ /**
214
+ * See https://github.com/microsoft/pxt-microbit/issues/5456
215
+ *
216
+ * Tutorial tool sharing link ID from https:*makecode.com/tutorial-tool prefixed with 'S'
217
+ * path: 'S96773-99918-18806-19059',
218
+ *
219
+ * Built-in tutorial
220
+ * path: '/projects/rock-paper-scissors',
221
+ *
222
+ * GitHub repo (no trailing .md, no blob/main cruft, tag versions)
223
+ *
224
+ * You get a series of "tutorialevent" actions tracking load and progress
225
+ * which we'd need to add support for at least to error handle the load.
226
+ */
227
+ startActivity(options: StartActivityOptions): Promise<void>;
228
+ saveProject(): Promise<void>;
229
+ compile(): Promise<void>;
230
+ unloadProject(): Promise<void>;
231
+ shareProject(options: EditorShareOptions): Promise<ShareResult>;
232
+ /**
233
+ * Change the language restriction (e.g. move to just JavaScript).
234
+ */
235
+ setLanguageRestriction(restriction: LanguageRestriction): Promise<void>;
236
+ getToolboxCategories(options?: {
237
+ advanced?: boolean;
238
+ }): Promise<ToolboxCategoryDefinition[]>;
239
+ toggleDebugSloMo(options?: {
240
+ invervalSpeed?: number;
241
+ }): Promise<void>;
242
+ setDebugSlowMo(options: {
243
+ enabled: boolean;
244
+ intervalSpeed?: number;
245
+ }): Promise<void>;
246
+ toggleHighContrast(): Promise<void>;
247
+ setHighContrast(on: boolean): Promise<void>;
248
+ toggleGreenScreen(): Promise<void>;
249
+ setSimulatorFullScreen(enabled: boolean): Promise<void>;
250
+ print(): Promise<void>;
251
+ pair(): Promise<void>;
252
+ info(): Promise<InfoMessage>;
253
+ /**
254
+ * Import a file.
255
+ *
256
+ * This works with hex and mkcd files.
257
+ *
258
+ * TODO: Other types may also be supported.
259
+ */
260
+ importFile(options: ImportFileOptions): void;
261
+ }
262
+ export declare const createMakeCodeURL: (baseUrl: string | undefined, version: string | undefined, lang: string | undefined, controller: number | undefined, queryParams: Record<string, string> | undefined) => string;
263
+ export {};