-
Notifications
You must be signed in to change notification settings - Fork 118
add simple monaco #418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add simple monaco #418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,106 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { proxy } from 'valtio' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const ideState = proxy({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column: 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| language: 'typescript', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| globalThis.ideState = ideState | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type error risk: globalThis augmentation missing for ideState. Assigning globalThis.ideState without a global augmentation will fail type-checking in TS (“Property 'ideState' does not exist on type 'typeof globalThis'”). Apply this diff to add a typed state shape and a safe global augmentation: -import { proxy } from 'valtio'
+import { proxy } from 'valtio'
+
+type IdeState = {
+ id: string
+ contents: string
+ line: number // note: Monaco uses 1-based positions; see comment below
+ column: number // note: Monaco uses 1-based positions; see comment below
+ language: string
+ title: string
+}
-export const ideState = proxy({
+export const ideState = proxy<IdeState>({
id: '',
contents: '',
line: 0,
column: 0,
language: 'typescript',
title: '',
})
-globalThis.ideState = ideState
+declare global {
+ // eslint-disable-next-line no-var
+ var ideState: typeof ideState
+}
+globalThis.ideState = ideState📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const registerIdeChannels = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| registerIdeOpenChannel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| registerIdeSaveChannel() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const registerIdeOpenChannel = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const CHANNEL_NAME = 'minecraft-web-client:ide-open' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const packetStructure = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'container', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'language', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'contents', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'line', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'i32' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'column', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'i32' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'title', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bot._client.registerChannel(CHANNEL_NAME, packetStructure, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bot._client.on(CHANNEL_NAME as any, (data) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { id, language, contents, line, column, title } = data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ideState.contents = contents | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ideState.line = line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ideState.column = column | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ideState.id = id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ideState.language = language || 'typescript' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ideState.title = title | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.debug(`registered custom channel ${CHANNEL_NAME} channel`) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const IDE_SAVE_CHANNEL_NAME = 'minecraft-web-client:ide-save' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const registerIdeSaveChannel = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const packetStructure = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'container', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'contents', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'language', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: ['pstring', { countType: 'i16' }] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'line', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'i32' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'column', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'i32' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bot._client.registerChannel(IDE_SAVE_CHANNEL_NAME, packetStructure, true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const saveIde = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bot._client.writeChannel(IDE_SAVE_CHANNEL_NAME, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: ideState.id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: ideState.contents, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| language: ideState.language, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // todo: reflect updated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| line: ideState.line, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| column: ideState.column, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+97
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Harden saveIde against disconnects and sync cursor position.
-export const saveIde = () => {
- bot._client.writeChannel(IDE_SAVE_CHANNEL_NAME, {
+export const saveIde = () => {
+ // Guard against disconnects
+ // @ts-expect-error: internal client state
+ if (!bot?._client || bot?._client?.ended) return
+ bot._client.writeChannel(IDE_SAVE_CHANNEL_NAME, {
id: ideState.id,
contents: ideState.contents,
language: ideState.language,
- // todo: reflect updated
- line: ideState.line,
- column: ideState.column,
+ // NOTE: keep these updated from the editor and convert to 1-based if needed.
+ line: ideState.line,
+ column: ideState.column,
})
}Follow-ups:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| .monaco-editor-container { | ||
| position: fixed; | ||
| inset: 0; | ||
| z-index: 1000; | ||
| display: flex; | ||
| flex-direction: column; | ||
| justify-content: center; | ||
| align-items: center; | ||
| padding: 16px; | ||
| background-color: rgba(0, 0, 0, 0.5); | ||
| } | ||
|
|
||
| .monaco-editor-title { | ||
| font-size: 20px; | ||
| font-weight: bold; | ||
| color: #fff; | ||
| margin-bottom: 8px; | ||
| } | ||
|
|
||
| .monaco-editor-wrapper { | ||
| position: relative; | ||
| width: 100%; | ||
| height: 100%; | ||
| max-width: 80vw; | ||
| max-height: 80vh; | ||
| border: 3px solid #000; | ||
| background-color: #000; | ||
| padding: 3px; | ||
| box-shadow: inset 0 0 0 1px #fff, inset 0 0 0 2px #000; | ||
| } | ||
|
|
||
| .monaco-editor-close { | ||
| position: fixed; | ||
| top: 16px; | ||
| left: 16px; | ||
| z-index: 1001; | ||
| cursor: pointer; | ||
| padding: 8px; | ||
| } | ||
|
|
||
| @media (max-width: 768px) { | ||
| .monaco-editor-container { | ||
| padding: 0; | ||
| } | ||
| .monaco-editor-wrapper { | ||
| max-width: 100%; | ||
| max-height: 100%; | ||
| border-radius: 0; | ||
| } | ||
| .monaco-editor-close { | ||
| top: 8px; | ||
| left: 8px; | ||
| } | ||
| .monaco-editor-title { | ||
| /* todo: make it work on mobile */ | ||
| display: none; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Missing peer dependency: add "monaco-editor" and verify worker bundling with Rsbuild.
@monaco-editor/react requires monaco-editor as a peer. It's not present in dependencies, which will likely break build/runtime or force a fallback you don't want. Also, Monaco needs its web workers bundled/configured for languages to work under Rsbuild/Rspack.
Apply this diff to add monaco-editor (pin to the peer range of your installed @monaco-editor/react):
"@floating-ui/react": "^0.26.1", + "monaco-editor": "^0.52.0", "@monaco-editor/react": "^4.7.0",Follow-ups:
🏁 Script executed:
Length of output: 411
🌐 Web query:
💡 Result:
The peerDependencies for @monaco-editor/[email protected] are:
If you want, I can show the package.json / package-lock excerpt that contains these entries.
Citations:
Add the missing monaco-editor dependency and verify worker bundling
Your project is currently missing the
monaco-editorpackage, which is a required peer for@monaco-editor/[email protected](it declares) . Omitting it will lead to runtime errors or unintended fallbacks.
Please update your
package.jsonlike so:"@floating-ui/react": "^0.26.1", + "monaco-editor": "^0.52.0", // satisfies >=0.25.0 <1 "@monaco-editor/react": "^4.7.0",Then:
node_modules/@monaco-editor/react/package.jsonand adjust"monaco-editor"’s version if needed (any0.x≥ 0.25 will do).ts.worker.js,editor.worker.js), you’ll need to configure worker rules or use a plugin/override (MonacoEnvironment.getWorkerUrl) to point to the proper URLs.