-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
160 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@quasi-dev/monaco-editor", | ||
"version": "0.0.1", | ||
"type": "module", | ||
"license": "MIT", | ||
"description": "Monaco Editor for Quasi", | ||
"repository": "https://github.com/Quasi-Studio/quasi", | ||
"scripts": { | ||
"check": "tsc --noEmit" | ||
}, | ||
"devDependencies": { | ||
"@refina/tsconfig": "link:..\\..\\..\\refina\\packages\\tsconfig", | ||
"typescript": "^5.0.2", | ||
"vite": "^4.4.8" | ||
}, | ||
"main": "./src/index.ts", | ||
"types": "./src/index.ts", | ||
"files": [ | ||
"src" | ||
], | ||
"exports": { | ||
".": "./src/index.ts" | ||
}, | ||
"dependencies": { | ||
"monaco-editor": "^0.44.0", | ||
"refina": "link:..\\..\\..\\refina\\packages\\core" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as monaco from "monaco-editor"; | ||
import { ComponentContext, D, HTMLElementComponent, TriggerComponent, getD, ref } from "refina"; | ||
import Monaco from "./plugin"; | ||
|
||
@Monaco.triggerComponent("monacoEditor") | ||
export class MonacoEditor extends TriggerComponent<string> { | ||
containerRef = ref<HTMLElementComponent<"div">>(); | ||
// overflowRef = ref<HTMLElementComponent<"div">>(); | ||
editor: monaco.editor.IStandaloneCodeEditor | null = null; | ||
main( | ||
_: ComponentContext<this>, | ||
initialValue: string, | ||
language: string, | ||
options: Omit< | ||
monaco.editor.IStandaloneEditorConstructionOptions, | ||
"value" | "language" | "overflowWidgetsDomNode" | ||
> = {}, | ||
): void { | ||
_.$css`height:100%`; | ||
_.$ref(this.containerRef) && _._div(); | ||
|
||
// _.portal(_ => { | ||
// _.$ref(this.overflowRef) && _._div(); | ||
// }); | ||
|
||
if (_.$updating) { | ||
_.$app.pushHook("afterModifyDOM", () => { | ||
setTimeout(() => { | ||
if (!this.editor) { | ||
const node = this.containerRef.current!.node; | ||
|
||
this.editor = monaco.editor.create(node, { | ||
...options, | ||
value: initialValue, | ||
language, | ||
// overflowWidgetsDomNode: this.overflowRef.current!.node, | ||
}); | ||
|
||
this.editor.getModel()?.onDidChangeContent(ev => { | ||
const newValue = this.editor!.getValue(); | ||
this.$fire(newValue); | ||
}); | ||
|
||
const parent = node.parentElement!; | ||
|
||
window.addEventListener("resize", () => { | ||
// make editor as small as possible | ||
this.editor!.layout({ width: 0, height: 0 }); | ||
|
||
// wait for next frame to ensure last layout finished | ||
window.requestAnimationFrame(() => { | ||
// get the parent dimensions and re-layout the editor | ||
const rect = parent.getBoundingClientRect(); | ||
this.editor!.layout({ width: rect.width, height: rect.height }); | ||
}); | ||
}); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
declare module "refina" { | ||
interface TriggerComponents { | ||
monacoEditor: MonacoEditor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import * as monaco from "monaco-editor"; | ||
export { monaco }; | ||
|
||
import Monaco from "./plugin"; | ||
export default Monaco; | ||
|
||
export * from "./component.r"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { Plugin } from "refina"; | ||
|
||
const Monaco = new Plugin("monaco-editor"); | ||
export default Monaco; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@refina/tsconfig", | ||
"include": ["src"], | ||
"compilerOptions": { | ||
"lib": ["ESNext", "DOM"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.