|
12 | 12 | } |
13 | 13 |
|
14 | 14 | export interface EditorState { |
| 15 | + workspace: Blockly.WorkspaceSvg |
| 16 | + canvas: HTMLCanvasElement |
15 | 17 | editorModalKind?: "variable" | "projectSettings" | "editorSettings" | null, |
16 | 18 | save: { |
17 | 19 | unsavedChanges: boolean, |
|
48 | 50 | }) |
49 | 51 |
|
50 | 52 | let editorState: EditorState = $state({ |
| 53 | + workspace: null, |
| 54 | + canvas: null, |
51 | 55 | editorModalKind: null, |
52 | 56 | save: null |
53 | 57 | }) |
54 | 58 |
|
55 | 59 | registerContinuousToolbox(); |
56 | 60 | |
57 | 61 | let blocklyDiv: HTMLDivElement | null = null; |
58 | | - let workspace: Blockly.WorkspaceSvg | null = null; |
59 | 62 |
|
60 | 63 | onMount(() => { |
61 | 64 | if (!blocklyDiv) return; |
62 | 65 |
|
63 | 66 | const toolboxElement = document.createElement("xml"); |
64 | 67 | toolboxElement.innerHTML = toolbox; |
65 | 68 |
|
66 | | - workspace = Blockly.inject(blocklyDiv, { |
| 69 | + editorState.workspace = Blockly.inject(blocklyDiv, { |
67 | 70 | toolbox: toolboxElement, |
68 | 71 | collapse: true, |
69 | 72 | comments: true, |
|
282 | 285 | </block> |
283 | 286 | ` |
284 | 287 |
|
285 | | - Blockly.Xml.domToWorkspace(defaultWorkspaceElement, workspace) |
| 288 | + Blockly.Xml.domToWorkspace(defaultWorkspaceElement, editorState.workspace) |
286 | 289 |
|
287 | | - workspace.addChangeListener(Blockly.Events.disableOrphans); |
| 290 | + editorState.workspace.addChangeListener(Blockly.Events.disableOrphans); |
288 | 291 |
|
289 | 292 | const listener = (e: Blockly.Events.Abstract) => { |
290 | 293 | if ( |
291 | 294 | e.isUiEvent || |
292 | 295 | e.type === Blockly.Events.FINISHED_LOADING || |
293 | | - workspace?.isDragging() |
| 296 | + editorState.workspace?.isDragging() |
294 | 297 | ) |
295 | 298 | return; |
296 | | - Compiler.compile(workspace!); |
| 299 | + Compiler.compile(editorState.workspace!); |
297 | 300 | if (editorState.save) { |
298 | 301 | editorState.save.unsavedChanges = true |
299 | 302 | } |
300 | 303 | }; |
301 | 304 |
|
302 | | - workspace.addChangeListener(listener); |
| 305 | + editorState.workspace.addChangeListener(listener); |
303 | 306 |
|
304 | 307 | onDestroy(() => { |
305 | | - workspace?.removeChangeListener(listener); |
306 | | - workspace?.dispose(); |
307 | | - workspace = null; |
| 308 | + editorState.workspace?.removeChangeListener(listener); |
| 309 | + editorState.workspace?.removeChangeListener(Blockly.Events.disableOrphans); |
| 310 | + editorState.workspace?.dispose(); |
| 311 | + editorState.workspace = null; |
308 | 312 | }); |
309 | 313 | }); |
310 | 314 | </script> |
|
317 | 321 | <div id="pageContainer"> |
318 | 322 | <div bind:this={blocklyDiv} id="blocklyDiv"></div> |
319 | 323 | <RaymarcherPreview |
320 | | - size={projectSettings.size} |
321 | | - previewSize={savedEditorState.preview.size} |
| 324 | + {editorState} |
| 325 | + {projectSettings} |
| 326 | + {savedEditorState} |
322 | 327 | /> |
323 | 328 | </div> |
324 | 329 | {#if editorState.editorModalKind === "variable"} |
325 | 330 | <EditorModalVariable |
326 | | - title="Create a Variable" |
327 | | - acceptText="Create" |
328 | | - cancelText="Cancel" |
| 331 | + title="Create a Variable" |
| 332 | + acceptText="Create" |
| 333 | + cancelText="Cancel" |
329 | 334 | ></EditorModalVariable> |
| 335 | + {:else if editorState.editorModalKind === "editorSettings"} |
| 336 | + <EditorModal |
| 337 | + title="Editor Settings" |
| 338 | + acceptText="Accept" |
| 339 | + cancelText="Cancel" |
| 340 | + onAccept={() => {}} |
| 341 | + onCancel={() => {editorState.editorModalKind = null}} |
| 342 | + ></EditorModal> |
| 343 | + {:else if editorState.editorModalKind === "projectSettings"} |
| 344 | + <EditorModal |
| 345 | + title="Project Settings" |
| 346 | + acceptText="Accept" |
| 347 | + cancelText="Cancel" |
| 348 | + onAccept={() => {}} |
| 349 | + onCancel={() => {editorState.editorModalKind = null}} |
| 350 | + ></EditorModal> |
330 | 351 | {/if} |
331 | 352 | </div> |
332 | 353 | <AlphaWarning /> |
|
0 commit comments