open Js_of_ocaml open Brr module PM = Prosemirror let prosemirror id content = begin match (Jv.is_none id), (Jv.is_none content) with | false, false -> let module PM = Prosemirror in let pm = PM.v () in let schema = (PM.SchemaBasic.schema pm) in let schema = Footnotes.footnote_schema pm schema in let specs = PM.Model.schema_spec (PM.SchemaList.add_list_nodes pm (schema##.spec##.nodes) (Jstr.v "paragraph block*") (Some (Jstr.v "block"))) (Some schema##.spec##.marks) None in let mySchema = PM.Model.schema pm specs in (* Create the initial state *) let state = Storage.load pm mySchema content in let props = PM.View.direct_editor_props () in props##.state := state; (* Each time the state is update, handle the copy *) props##.dispatchTransaction := Js.wrap_meth_callback @@ (fun view tr -> let state = view##.state##apply tr in view##updateState state ); let view' = (Footnotes.footnote_view pm) in let nodes = PM.O.init [| ("footnote", view') |] in props##.nodeViews := nodes; let view = PM.View.editor_view pm (Jv.Id.of_jv id) props in (* Attach an event on focus out *) let _ = Brr_note.Evr.on_el (Ev.focusout) (fun _ -> Storage.save view) (Jv.Id.of_jv id) in () | _, _ -> Console.(error [str "No element with id '%s' '%s' found"; id ; content]) end let () = let open Jv in let editor = obj [| "attach_prosemirror", (repr prosemirror) |] in set global "editor" editor