Skip to content

Commit

Permalink
fixed previous errors, no substantial chnages
Browse files Browse the repository at this point in the history
  • Loading branch information
reevafaisal committed Aug 8, 2024
1 parent 9c17aeb commit f43be77
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 112 deletions.
8 changes: 3 additions & 5 deletions src/haz3lweb/DocumentationEnv.re
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 1 addition & 2 deletions src/haz3lweb/dune
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
(:standard \ Main)
\
Worker
WorkerServer
DocumentationEnv)
WorkerServer)
(libraries
ezjs_min
ezjs_idb
Expand Down
257 changes: 153 additions & 104 deletions src/haz3lweb/view/Page.re
Original file line number Diff line number Diff line change
@@ -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(_ => {
Expand All @@ -41,134 +33,191 @@ 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)));
}),
];
};

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,
Expand Down
4 changes: 3 additions & 1 deletion src/haz3lweb/view/ScratchMode.re
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// open Util;
// open Sexplib.Std;
open Haz3lcore;

type state = (Id.t, Editor.t);
Expand All @@ -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);
Expand All @@ -36,6 +37,7 @@ let view =
~ui_state,
~settings,
~target_id,
~error_ids,
~test_results,
~footer?,
~highlights,
Expand Down

0 comments on commit f43be77

Please sign in to comment.