diff options
author | Sébastien Dailly <sebastien@chimrod.com> | 2021-02-15 23:03:21 +0100 |
---|---|---|
committer | Sébastien Dailly <sebastien@dailly.me> | 2022-02-07 16:43:33 +0100 |
commit | 274789e733c46e7e20fc1dc918a7251b0206b3d2 (patch) | |
tree | d8f07ef584765dd178cc1c3cfa2ef925ffaa636b /editor/prosemirror | |
parent | e612a344629b999e90089710646e7a0bc68597d2 (diff) |
Working key handler
Diffstat (limited to 'editor/prosemirror')
-rwxr-xr-x | editor/prosemirror/bindings.ml | 9 | ||||
-rwxr-xr-x | editor/prosemirror/prosemirror.ml | 18 | ||||
-rwxr-xr-x | editor/prosemirror/prosemirror.mli | 15 |
3 files changed, 31 insertions, 11 deletions
diff --git a/editor/prosemirror/bindings.ml b/editor/prosemirror/bindings.ml index f6d4223..cb5a47c 100755 --- a/editor/prosemirror/bindings.ml +++ b/editor/prosemirror/bindings.ml @@ -365,6 +365,9 @@ module Transform = struct method replaceRangeWith: int -> int -> Model.node t -> 'this t meth + method setBlockType: + int -> int -> Model.node_type t -> < .. > t -> 'this t meth + end end @@ -650,13 +653,13 @@ module Example = struct Model.schema t prop method menuBar: - bool opt prop + bool t opt prop method floatingMenu: - bool opt prop + bool t opt prop method history: - bool opt prop + bool t opt prop end end diff --git a/editor/prosemirror/prosemirror.ml b/editor/prosemirror/prosemirror.ml index e97fa9b..e2758c7 100755 --- a/editor/prosemirror/prosemirror.ml +++ b/editor/prosemirror/prosemirror.ml @@ -112,6 +112,10 @@ module State = struct include Bindings.State + type dispatch = (transaction Js.t -> unit) + + type command = editor_state Js.t -> dispatch Js.opt -> bool Js.t + let configuration_prop : unit -> configuration_prop Js_of_ocaml.Js.t = fun () -> Js_of_ocaml.Js.Unsafe.obj [||] @@ -176,6 +180,7 @@ module State = struct let state = Jv.get t "state" in Jv.call (Jv.get state "TextSelection") "create" Jv.Id.[|to_jv doc; Jv.of_int number|] |> Jv.Id.of_jv + end (* Editor view *) @@ -249,13 +254,13 @@ module History = struct |> Jv.Id.of_jv let undo - : t -> State.editor_state Js.t -> (State.transaction -> unit) -> bool + : t -> State.command = fun t state fn -> Jv.call (Jv.get t "history") "undo" [|Jv.Id.to_jv state; Jv.repr fn|] |> Jv.Id.of_jv let redo - : t -> State.editor_state Js.t -> (State.transaction -> unit) -> bool + : t -> State.command = fun t state fn -> Jv.call (Jv.get t "history") "redo" [|Jv.Id.to_jv state; Jv.repr fn|] |> Jv.Id.of_jv @@ -264,7 +269,7 @@ end module Keymap = struct let keymap - : t -> (string * (State.editor_state Js.t -> (State.transaction Js.t -> unit) -> bool)) array -> State.plugin Js.t + : t -> (string * State.command) array -> State.plugin Js.t = fun t props -> let props = Jv.obj @@ Array.map (fun (id, f) -> (id, Jv.repr f)) props in Jv.call (Jv.get t "keymap") "keymap" [|props|] @@ -275,11 +280,16 @@ end module Commands = struct let baseKeymap - : t -> (string * (State.editor_state Js.t -> (State.transaction -> unit) -> bool)) array + : t -> (string * State.command) array = fun t -> Jv.get (Jv.get t "commands") "baseKeymap" |> Jv.Id.of_jv + let set_block_type + : t -> Model.node_type Js.t -> < .. > Js.t -> State.command + = fun t node props -> + Jv.call (Jv.get t "commands") "setBlockType" Jv.Id.[| to_jv node ; to_jv props |] + |> Jv.Id.of_jv end (* Example Setup *) diff --git a/editor/prosemirror/prosemirror.mli b/editor/prosemirror/prosemirror.mli index a4c5d35..7a723d3 100755 --- a/editor/prosemirror/prosemirror.mli +++ b/editor/prosemirror/prosemirror.mli @@ -100,6 +100,10 @@ and State : sig val create_text_selection : t -> Model.node Js.t -> int -> text_selection Js.t + type dispatch = (transaction Js.t -> unit) + + type command = editor_state Js.t -> dispatch Js.opt -> bool Js.t + end (* Editor view *) @@ -146,23 +150,26 @@ module History : sig : t -> history_prop Js.t -> State.plugin Js.t val undo - : t -> State.editor_state Js.t -> (State.transaction -> unit) -> bool + : t -> State.command val redo - : t -> State.editor_state Js.t -> (State.transaction -> unit) -> bool + : t -> State.command end module Keymap : sig val keymap - : t -> (string * (State.editor_state Js.t -> (State.transaction Js.t -> unit) -> bool)) array -> State.plugin Js.t + : t -> (string * State.command) array -> State.plugin Js.t end module Commands : sig val baseKeymap - : t -> (string * (State.editor_state Js.t -> (State.transaction -> unit) -> bool)) array + : t -> (string * State.command) array + + val set_block_type + : t -> Model.node_type Js.t -> < .. > Js.t -> State.command end |