Skip to content

Commit

Permalink
use quill cursors
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Oct 20, 2024
1 parent 2d86592 commit bc9f325
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions vendor/brr_lwd_ui/bindings/quill/quill.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@ type t = Jv.t
external to_jv : t -> Jv.t = "%identity"

let quill = Global.quill
let cursors = Global.quill_cursors

let register ~path v =
ignore @@ Jv.call quill "register" [| Jv.of_string path; v |]

type config = Jv.t
type theme = Snow | Bubble

let config ?(theme = Snow) () : config =
let config ?(theme = Snow) ?cursors () : config =
let theme = match theme with Snow -> "snow" | Bubble -> "bubble" in
Jv.obj [| ("theme", Jv.of_string theme) |]
let cursors =
match cursors with Some b -> [| ("cursors", Jv.of_bool b) |] | None -> [||]
in
let modules = Jv.obj cursors in
Jv.obj [| ("theme", Jv.of_string theme); ("modules", modules) |]

let make ~container config = Jv.new' quill [| Brr.El.to_jv container; config |]
3 changes: 2 additions & 1 deletion vendor/brr_lwd_ui/bindings/quill/quill.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ type t

val to_jv : t -> Jv.t
val register : path:string -> Jv.t -> unit
val cursors : Jv.t

type config
type theme = Snow | Bubble

val config : ?theme:theme -> unit -> config
val config : ?theme:theme -> ?cursors:bool -> unit -> config
val make : container:Brr.El.t -> config -> t
5 changes: 4 additions & 1 deletion vendor/brr_lwd_ui/examples/yjs/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ open Lwd_infix
let random_state = Random.State.make_self_init ()
let new_uuid_v4 () = Uuidm.v4_gen random_state ()
let yjs_doc = Yjs.Doc.make ()
let _ = Quill.register ~path:"modules/cursors" Quill.cursors

let provider =
Yjs.Webrtc_provider.make ~room_name:"testroom5267564"
Expand Down Expand Up @@ -597,7 +598,9 @@ let render_bool_cell ~src (value : bool Lwd.t) =

let render_richtext_cell ~src:_ (value : Yjs.Text.t) =
let container = El.div [] in
let editor = Quill.(make ~container @@ config ~theme:Bubble ()) in
let editor =
Quill.(make ~container @@ config ~theme:Bubble ~cursors:true ())
in
let _ = (* TODO is there some cleanup to do ? *) Y_quill.make value editor in
let at = Attrs.O.(v (`P (C "cell"))) in
Elwd.div ~at [ `P container ]
Expand Down

0 comments on commit bc9f325

Please sign in to comment.