diff --git a/src/haz3lweb/DocumentationEnv.re b/src/haz3lweb/DocumentationEnv.re index ad3e91cfea..0c9737951c 100644 --- a/src/haz3lweb/DocumentationEnv.re +++ b/src/haz3lweb/DocumentationEnv.re @@ -565,12 +565,10 @@ module F = (DocEnv: ExerciseEnv) => { let stitch_term = ({eds, _}: state): stitched(TermItem.t) => { // let instructor = // stitch3(eds.hidden_tests.tests); - let user_impl_term = { + let user_impl_term = // let your_impl_term = - eds.your_impl |> term_of |> wrap_filter(FilterAction.Step)// let prelude_term = - ; // eds.prelude |> term_of |> wrap_filter(FilterAction.Eval); - // EditorUtil.append_exp(your_impl_term); - }; + eds.your_impl |> term_of |> wrap_filter(FilterAction.Step); + // }; // let test_validation_term = // stitch3(eds.prelude, eds.correct_impl, eds.your_tests.tests); // let user_tests_term = diff --git a/src/haz3lweb/dune b/src/haz3lweb/dune index 5b43be3b9d..6dcaeb3b1d 100644 --- a/src/haz3lweb/dune +++ b/src/haz3lweb/dune @@ -35,8 +35,7 @@ (:standard \ Main) \ Worker - WorkerServer - DocumentationEnv) + WorkerServer) (libraries ezjs_min ezjs_idb diff --git a/src/haz3lweb/view/Page.re b/src/haz3lweb/view/Page.re index 6fea2c2666..bc430c3015 100644 --- a/src/haz3lweb/view/Page.re +++ b/src/haz3lweb/view/Page.re @@ -1,35 +1,27 @@ -open Util; +// open Util; open Js_of_ocaml; open Haz3lcore; open Virtual_dom.Vdom; open Node; -let key_handler = - ( - ~inject: UpdateAction.t => Ui_effect.t(unit), - ~dir: Key.dir, - editor: Editor.t, - evt: Js.t(Dom_html.keyboardEvent), - ) - : Effect.t(unit) => { - open Effect; - let key = Key.mk(dir, evt); - switch (ProjectorView.key_handoff(editor, key)) { - | Some(action) => - Many([Prevent_default, inject(PerformAction(Project(action)))]) - | None => - switch (Keyboard.handle_key_event(key)) { - | None => Ignore - | Some(action) => Many([Prevent_default, inject(action)]) - } - }; -}; +let handlers = (~inject: UpdateAction.t => Ui_effect.t(unit), model) => { + let get_selection = (model: Model.t): string => + model.editors |> Editors.get_editor |> Printer.to_string_selection; + let key_handler = + (~inject, ~dir: Key.dir, evt: Js.t(Dom_html.keyboardEvent)) + : Effect.t(unit) => + Effect.( + switch (Keyboard.handle_key_event(Key.mk(dir, evt))) { + | None => Ignore + | Some(action) => + Many([Prevent_default, Stop_propagation, inject(action)]) + } + ); -let handlers = - (~inject: UpdateAction.t => Ui_effect.t(unit), editor: Editor.t) => { [ - Attr.on_keyup(key_handler(~inject, editor, ~dir=KeyUp)), - Attr.on_keydown(key_handler(~inject, editor, ~dir=KeyDown)), + Attr.on_keypress(_ => Effect.Prevent_default), + Attr.on_keyup(key_handler(~inject, ~dir=KeyUp)), + Attr.on_keydown(key_handler(~inject, ~dir=KeyDown)), /* safety handler in case mousedown overlay doesn't catch it */ Attr.on_mouseup(_ => inject(SetMeta(Mouseup))), Attr.on_blur(_ => { @@ -41,19 +33,23 @@ let handlers = Effect.Ignore; }), Attr.on_copy(_ => { - JsUtil.copy(Printer.to_string_selection(editor)); + JsUtil.copy(get_selection(model)); + // JsUtil.copy(Printer.to_string_selection(editor)); Effect.Ignore; }), Attr.on_cut(_ => { - JsUtil.copy(Printer.to_string_selection(editor)); + JsUtil.copy(get_selection(model)); + // JsUtil.copy(Printer.to_string_selection(editor)); inject(UpdateAction.PerformAction(Destruct(Left))); }), Attr.on_paste(evt => { let pasted_text = Js.to_string(evt##.clipboardData##getData(Js.string("text"))) - |> Util.StringUtil.trim_leading; + |> Str.global_replace(Str.regexp("\n[ ]*"), "\n"); + // |> Util.StringUtil.trim_leading; Dom.preventDefault(evt); - inject(PerformAction(Paste(pasted_text))); + inject(UpdateAction.Paste(pasted_text)); + // inject(PerformAction(Paste(pasted_text))); }), ]; }; @@ -61,114 +57,167 @@ let handlers = let main_view = ( ~inject: UpdateAction.t => Ui_effect.t(unit), - {settings, editors, explainThisModel, results, ui_state, _}: Model.t, + {settings, editors, explainThisModel, results, statics, ui_state, _}: Model.t, ) => { + // {settings, editors, explainThisModel, results, ui_state, _}: Model.t, + let editor = Editors.get_editor(editors); - let cursor_info = - Indicated.ci_of(editor.state.zipper, editor.state.meta.statics.info_map); + let statics = Editors.lookup_statics(~settings, ~statics, editors); + let cursor_info = Indicated.ci_of(editor.state.zipper, statics.info_map); + let top_bar = + div( + ~attr=Attr.id("top-bar"), + NutMenu.view(~inject, ~settings, ~editors) + @ [div(~attr=Attr.id("title"), [text("hazel")])] + @ [EditorModeView.view(~inject, ~settings, ~editors)], + ); + let bottom_bar = CursorInspector.view(~inject, ~settings, cursor_info); + let sidebar = + settings.explainThis.show && settings.core.statics + ? ExplainThis.view( + ~inject, + ~ui_state, + ~settings, + ~explainThisModel, + cursor_info, + ) + : div([]); + // let cursor_info = + // Indicated.ci_of(editor.state.zipper, editor.state.meta.statics.info_map); let highlights = ExplainThis.get_color_map(~settings, ~explainThisModel, cursor_info); - let (editors_view, cursor_info) = + let editors_view = + // let (editors_view, cursor_info) = switch (editors) { | Scratch(idx, _) => let result_key = ScratchSlide.scratch_key(string_of_int(idx)); - let view = - ScratchMode.view( - ~inject, - ~ui_state, - ~settings, - ~highlights, - ~results, - ~result_key, - editor, - ); - (view, cursor_info); + ScratchMode.view( + ~inject, + ~ui_state, + ~settings, + ~highlights, + ~results, + ~result_key, + ~statics, + editor, + ); + // let view = + // ScratchMode.view( + // ~inject, + // ~ui_state, + // ~settings, + // ~highlights, + // ~results, + // ~result_key, + // editor, + // ); + // (view, cursor_info); | Documentation(name, _) => let result_key = ScratchSlide.scratch_key(name); - let view = - ScratchMode.view( + let info = + SlideContent.get_content(editors) + |> Option.map(i => div(~attr=Attr.id("slide"), [i])) + |> Option.to_list; + info + @ ScratchMode.view( + // let view = + // ScratchMode.view( ~inject, ~ui_state, ~settings, ~highlights, ~results, ~result_key, + ~statics, editor, ); - let info = - SlideContent.get_content(editors) - |> Option.map(i => div(~attrs=[Attr.id("slide")], [i])) - |> Option.to_list; - (info @ view, cursor_info); + // let info = + // SlideContent.get_content(editors) + // |> Option.map(i => div(~attrs=[Attr.id("slide")], [i])) + // |> Option.to_list; + // (info @ view, cursor_info); | Exercises(_, _, exercise) => - /* Note the exercises mode uses a seperate path to calculate - * statics and dynamics via stitching together multiple editors */ - let stitched_dynamics = - Exercise.stitch_dynamic( - settings.core, - exercise, - settings.core.dynamics ? Some(results) : None, - ); - let statics = - Exercise.statics_of_stiched_dynamics(exercise, stitched_dynamics); - let cursor_info = - Indicated.ci_of(editor.state.zipper, statics.info_map); - let highlights = - ExplainThis.get_color_map(~settings, ~explainThisModel, cursor_info); - let view = - ExerciseMode.view( - ~inject, - ~ui_state, - ~settings, - ~highlights, - ~stitched_dynamics, - ~exercise, - ); - (view, cursor_info); + ExerciseMode.view( + ~inject, + ~ui_state, + ~settings, + ~highlights, + ~results, + ~exercise, + ) + // /* Note the exercises mode uses a seperate path to calculate + // * statics and dynamics via stitching together multiple editors */ + // let stitched_dynamics = + // Exercise.stitch_dynamic( + // settings.core, + // exercise, + // settings.core.dynamics ? Some(results) : None, + // ); + // let statics = + // Exercise.statics_of_stiched_dynamics(exercise, stitched_dynamics); + // let cursor_info = + // Indicated.ci_of(editor.state.zipper, statics.info_map); + // let highlights = + // ExplainThis.get_color_map(~settings, ~explainThisModel, cursor_info); + // let view = + // ExerciseMode.view( + // ~inject, + // ~ui_state, + // ~settings, + // ~highlights, + // ~stitched_dynamics, + // ~exercise, + // ); + // (view, cursor_info); }; - let top_bar = - div( - ~attrs=[Attr.id("top-bar")], - NutMenu.view(~inject, ~settings, ~editors) - @ [div(~attrs=[Attr.id("title")], [text("hazel")])] - @ [EditorModeView.view(~inject, ~settings, ~editors)], - ); - let bottom_bar = - CursorInspector.view(~inject, ~settings, editor, cursor_info); - let sidebar = - settings.explainThis.show && settings.core.statics - ? ExplainThis.view( - ~inject, - ~ui_state, - ~settings, - ~explainThisModel, - cursor_info, - ) - : div([]); + // let top_bar = + // div( + // ~attrs=[Attr.id("top-bar")], + // NutMenu.view(~inject, ~settings, ~editors) + // @ [div(~attrs=[Attr.id("title")], [text("hazel")])] + // @ [EditorModeView.view(~inject, ~settings, ~editors)], + // ); + // let bottom_bar = + // CursorInspector.view(~inject, ~settings, editor, cursor_info); + // let sidebar = + // settings.explainThis.show && settings.core.statics + // ? ExplainThis.view( + // ~inject, + // ~ui_state, + // ~settings, + // ~explainThisModel, + // cursor_info, + // ) + // : div([]); [ top_bar, div( - ~attrs=[ - Attr.id("main"), - Attr.classes([Settings.show_mode(settings.mode)]), - ], + ~attr= + Attr.many([ + Attr.id("main"), + Attr.classes([Settings.show_mode(settings.mode)]), + ]), + // ~attrs=[ + // Attr.id("main"), + // Attr.classes([Settings.show_mode(settings.mode)]), + // ], editors_view, ), sidebar, bottom_bar, ]; }; - let get_selection = (model: Model.t): string => model.editors |> Editors.get_editor |> Printer.to_string_selection; let view = (~inject: UpdateAction.t => Ui_effect.t(unit), model: Model.t) => div( - ~attrs= - Attr.[ - id("page"), - ...handlers(~inject, Editors.get_editor(model.editors)), - ], + ~attr=Attr.many(Attr.[id("page"), ...handlers(~inject, model)]), + // ~attrs= + // Attr.[ + // id("page"), + // ...handlers(~inject, Editors.get_editor(model.editors)), + // ], [ FontSpecimen.view("font-specimen"), DecUtil.filters, diff --git a/src/haz3lweb/view/ScratchMode.re b/src/haz3lweb/view/ScratchMode.re index 7883a88007..77bc609c4e 100644 --- a/src/haz3lweb/view/ScratchMode.re +++ b/src/haz3lweb/view/ScratchMode.re @@ -1,4 +1,4 @@ -// open Util; +// open Sexplib.Std; open Haz3lcore; type state = (Id.t, Editor.t); @@ -11,6 +11,7 @@ let view = ~highlights, ~results: ModelResults.t, ~result_key, + ~statics as {error_ids, _}: CachedStatics.statics, editor: Editor.t, ) => { let result = ModelResults.lookup(results, result_key); @@ -36,6 +37,7 @@ let view = ~ui_state, ~settings, ~target_id, + ~error_ids, ~test_results, ~footer?, ~highlights,