Skip to content

Commit

Permalink
Editor: disable orphans
Browse files Browse the repository at this point in the history
  • Loading branch information
FilipChalupa committed Jan 12, 2025
1 parent 05facf3 commit 7a18131
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"react-dom": "^18.3.1"
},
"devDependencies": {
"@blockly/disable-top-blocks": "^0.5.12",
"@blockly/theme-dark": "^7.0.10",
"@blockly/theme-modern": "^6.0.10",
"@emotion/react": "^11.14.0",
Expand Down
8 changes: 8 additions & 0 deletions src/BlocklyThemes.d.ts → src/Blockly.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ declare module '@blockly/theme-modern' {
const theme: Blockly.Theme
export = theme
}

declare module '@blockly/disable-top-blocks' {
const X: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
DisableTopBlocks: any
}
export = X
}
7 changes: 7 additions & 0 deletions src/Components/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DisableTopBlocks } from '@blockly/disable-top-blocks'
import DarkTheme from '@blockly/theme-dark'
import ModernTheme from '@blockly/theme-modern'
import * as Blockly from 'blockly/core'
Expand Down Expand Up @@ -104,13 +105,19 @@ export const Editor: FunctionComponent<{
setWorkspace(workspace)
setTheme(workspace)
workspace.addTrashcan() // @TODO: improve styling

workspace.addChangeListener(Blockly.Events.disableOrphans)
new DisableTopBlocks().init()

// Set base XML
Blockly.Events.setRecordUndo(false)
Blockly.Xml.clearWorkspaceAndLoadFromXml(
new window.DOMParser().parseFromString(baseXml, 'text/xml')
.documentElement,
workspace,
)
Blockly.Events.setRecordUndo(true)

if (initialXml) {
Blockly.Xml.clearWorkspaceAndLoadFromXml(
new window.DOMParser().parseFromString(initialXml, 'text/xml')
Expand Down

0 comments on commit 7a18131

Please sign in to comment.