-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add binding for Microsoft's Monaco editor
- Loading branch information
Showing
7 changed files
with
131 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Editor : sig | ||
module ITextModel : sig | ||
type t = private Ojs.t | ||
|
||
val id : t -> string | ||
end | ||
|
||
val create_model : value:string -> ?language:string -> unit -> ITextModel.t | ||
[@@js.global "monaco.editor.createModel"] | ||
|
||
module IStandaloneCodeEditor : sig | ||
type t = private Ojs.t | ||
|
||
val set_value : t -> string -> unit [@@js.call] | ||
end | ||
|
||
module IStandaloneEditorConstructionOptions : sig | ||
type t = { model : ITextModel.t; read_only : bool } | ||
end | ||
|
||
val create : | ||
dom_element:React.Dom.domElement -> | ||
?options:IStandaloneEditorConstructionOptions.t -> | ||
unit -> | ||
IStandaloneCodeEditor.t | ||
[@@js.global "monaco.editor.create"] | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
open Batteries; | ||
|
||
module Dom = React.Dom; | ||
module Js = Js_of_ocaml.Js; | ||
|
||
module Editor = Monaco.Editor; | ||
module IStandaloneCodeEditor = Editor.IStandaloneCodeEditor; | ||
|
||
[@react.component] | ||
let make = (~value=?, ~read_only=?) => { | ||
let (value, read_only) = Utils.fix_opt_args2(value, read_only); | ||
let value = Option.default("", value); | ||
let read_only = Option.default(false, read_only); | ||
|
||
let editor = React.useRef(None); | ||
|
||
React.useEffect1( | ||
() => { | ||
editor | ||
|> React.Ref.current | ||
|> Option.may(e => IStandaloneCodeEditor.set_value(e, value)); | ||
None; | ||
}, | ||
[|value|], | ||
); | ||
|
||
let ref = | ||
Dom.Ref.callbackDomRef( | ||
Js.Opt.iter(_, dom_element => | ||
if (editor |> React.Ref.current |> Option.is_none) { | ||
let model = Editor.create_model(~value, ~language="c", ()); | ||
Editor.create(~dom_element, ~options={model, read_only}, ()) | ||
|> Option.some | ||
|> React.Ref.setCurrent(editor); | ||
} | ||
), | ||
); | ||
|
||
<div ref style={Dom.Style.make(~height="600px", ())} />; | ||
}; |
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