From d19d90fbd7c129da3df62d1b2b55838156943acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 21 Oct 2024 00:23:26 +0200 Subject: [PATCH] Show editor buttons --- vendor/brr_lwd_ui/bindings/quill/quill.ml | 28 ++++++++++++++++++---- vendor/brr_lwd_ui/bindings/quill/quill.mli | 4 +++- vendor/brr_lwd_ui/examples/yjs/main.css | 15 +++++++++++- vendor/brr_lwd_ui/examples/yjs/main.ml | 15 ++++++++---- 4 files changed, 51 insertions(+), 11 deletions(-) diff --git a/vendor/brr_lwd_ui/bindings/quill/quill.ml b/vendor/brr_lwd_ui/bindings/quill/quill.ml index fae4fc3..3922bdd 100644 --- a/vendor/brr_lwd_ui/bindings/quill/quill.ml +++ b/vendor/brr_lwd_ui/bindings/quill/quill.ml @@ -10,13 +10,33 @@ let register ~path v = type config = Jv.t type theme = Snow | Bubble +type tool = Bold | Italic | Underline | Strike | Link -let config ?(theme = Snow) ?cursors () : config = +type toolbar = + | Array of tool list (* TODO groups / type for values Bold | Italic... *) + +let jv_of_tool t = + Jv.of_string + @@ + match t with + | Bold -> "bold" + | Italic -> "italic" + | Underline -> "underline" + | Strike -> "strike" + | Link -> "link" + +let config ?(theme = Snow) ?cursors ?toolbar () : config = let theme = match theme with Snow -> "snow" | Bubble -> "bubble" in - let cursors = - match cursors with Some b -> [| ("cursors", Jv.of_bool b) |] | None -> [||] + let cursors = Option.map (fun b -> ("cursors", Jv.of_bool b)) cursors in + let toolbar = + Option.map + (function Array t -> ("toolbar", Jv.of_list jv_of_tool t)) + toolbar + in + + let modules = + Jv.obj (List.filter_map Fun.id [ cursors; toolbar ] |> Array.of_list) 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 |] diff --git a/vendor/brr_lwd_ui/bindings/quill/quill.mli b/vendor/brr_lwd_ui/bindings/quill/quill.mli index 3a5971f..ec93fee 100644 --- a/vendor/brr_lwd_ui/bindings/quill/quill.mli +++ b/vendor/brr_lwd_ui/bindings/quill/quill.mli @@ -4,8 +4,10 @@ val to_jv : t -> Jv.t val register : path:string -> Jv.t -> unit val cursors : Jv.t +type tool = Bold | Italic | Underline | Strike | Link +type toolbar = Array of tool list type config type theme = Snow | Bubble -val config : ?theme:theme -> ?cursors:bool -> unit -> config +val config : ?theme:theme -> ?cursors:bool -> ?toolbar:toolbar -> unit -> config val make : container:Brr.El.t -> config -> t diff --git a/vendor/brr_lwd_ui/examples/yjs/main.css b/vendor/brr_lwd_ui/examples/yjs/main.css index 2c728df..f9ee0ef 100644 --- a/vendor/brr_lwd_ui/examples/yjs/main.css +++ b/vendor/brr_lwd_ui/examples/yjs/main.css @@ -78,4 +78,17 @@ body { .lwdui-virtual-table-row .ql-container { width: 100%; height: 100%; -} \ No newline at end of file +} + +.lwdui-virtual-table-row .ql-toolbar { + border: 0; + padding: 0; + height: 100%; + + & .ql-formats { + display: flex; + flex-direction: column; + margin-right: 0 + ; + } +} diff --git a/vendor/brr_lwd_ui/examples/yjs/main.ml b/vendor/brr_lwd_ui/examples/yjs/main.ml index 19f8608..05c4294 100644 --- a/vendor/brr_lwd_ui/examples/yjs/main.ml +++ b/vendor/brr_lwd_ui/examples/yjs/main.ml @@ -598,12 +598,17 @@ 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 ~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 ] + (* For Quill's toolbar to show we need to wrap the element in a container + before instantiating the editor. *) + let elt = Elwd.div ~at [ `P container ] in + let _editor = + let open Quill in + let toolbar = Array [ Bold; Italic; Underline ] in + make ~container @@ config ~theme:Snow ~cursors:true ~toolbar () + |> (* TODO is there some cleanup to do ? *) Y_quill.make value + in + elt let table_data_source source_rows (content : row Indexed_table.t) = let reduce_row (row : row) =