-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Create sub-models for editors
1 parent
f810f62
commit 5fb83bc
Showing
24 changed files
with
1,185 additions
and
991 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
open Haz3lcore; | ||
open Virtual_dom.Vdom; | ||
open Node; | ||
|
||
let narrative_cell = (content: Node.t) => | ||
div( | ||
~attr=Attr.class_("cell"), | ||
[div(~attr=Attr.class_("cell-chapter"), [content])], | ||
); | ||
|
||
let simple_cell_item = (content: list(Node.t)) => | ||
div(~attr=Attr.classes(["cell-item"]), content); | ||
|
||
let caption = (~rest: option(string)=?, bolded: string) => | ||
div( | ||
~attr=Attr.many([Attr.classes(["cell-caption"])]), | ||
[strong([text(bolded)])] @ (rest |> Option.map(text) |> Option.to_list), | ||
); | ||
|
||
let simple_cell_view = (items: list(t)) => | ||
div(~attr=Attr.class_("cell"), items); | ||
|
||
let report_footer_view = content => { | ||
div(~attr=Attr.classes(["cell-item", "cell-report"]), content); | ||
}; | ||
|
||
let test_report_footer_view = (~inject, ~test_results: option(TestResults.t)) => { | ||
report_footer_view([TestView.test_summary(~inject, ~test_results)]); | ||
}; | ||
|
||
let panel = (~classes=[], content, ~footer: option(t)) => { | ||
simple_cell_view( | ||
[div(~attr=Attr.classes(["cell-item", "panel"] @ classes), content)] | ||
@ Option.to_list(footer), | ||
); | ||
}; | ||
|
||
let title_cell = title => { | ||
simple_cell_view([ | ||
div( | ||
~attr=Attr.class_("title-cell"), | ||
[div(~attr=Attr.class_("title-text"), [text(title)])], | ||
), | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
open Haz3lcore; | ||
open Virtual_dom.Vdom; | ||
open Node; | ||
|
||
type model = { | ||
editor: CodeEditor.model, | ||
result: ModelResult.t, | ||
}; | ||
|
||
type action = | ||
| MainEditor(CodeEditor.action) | ||
| ResultAction(CellResult.action); | ||
|
||
let update = ReadOnlyEditor.update; | ||
|
||
let calculate = ReadOnlyEditor.calculate; | ||
|
||
type event = CodeEditor.event; | ||
|
||
let view = | ||
( | ||
~select: Editors.Selection.cell => Ui_effect.t(unit), | ||
~inject, | ||
~inject_global, | ||
~ui_state: Model.ui_state, | ||
~settings: Settings.t, | ||
~highlights: option(ColorSteps.colorMap), | ||
~selected: option(Editors.Selection.cell), | ||
~caption: option(Node.t)=?, | ||
~sort=?, | ||
~result_kind=?, | ||
~locked=false, | ||
model, | ||
) => { | ||
let (footer, overlays) = | ||
CellResult.view( | ||
~signal= | ||
fun | ||
| MakeActive(a) => select(a) | ||
| MouseUp => inject_global(Update.SetMeta(Mouseup)) | ||
| MouseDown => inject_global(Update.SetMeta(Mousedown)), | ||
~inject=a => inject(ResultAction(a)), | ||
~inject_global, | ||
~ui_state, | ||
~settings, | ||
~selected=selected == Some(Result(0)), | ||
~result_kind?, | ||
~locked, | ||
model.result, | ||
); | ||
div( | ||
~attr= | ||
Attr.classes([ | ||
"cell", | ||
Option.is_some(selected) ? "selected" : "deselected", | ||
locked ? "locked" : "unlocked", | ||
]), | ||
Option.to_list(caption) | ||
@ [ | ||
CodeEditor.view( | ||
~signal= | ||
locked | ||
? _ => Ui_effect.Ignore | ||
: fun | ||
| MouseUp => inject_global(Update.SetMeta(Mouseup)) | ||
| MouseDown => inject_global(Update.SetMeta(Mousedown)) | ||
| MakeActive => select(Editors.Selection.MainEditor), | ||
~inject= | ||
locked | ||
? _ => Ui_effect.Ignore | ||
: (action => inject_global(PerformAction(action))), | ||
~ui_state, | ||
~settings, | ||
~selected=selected == Some(MainEditor), | ||
~highlights, | ||
~overlays=overlays(model.editor.editor), | ||
~sort?, | ||
model.editor, | ||
), | ||
] | ||
@ footer, | ||
); | ||
}; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
open Js_of_ocaml; | ||
open Haz3lcore; | ||
open Virtual_dom.Vdom; | ||
type editor_id = string; | ||
|
||
type model = ReadOnlyEditor.model; | ||
|
||
type action = ReadOnlyEditor.action; | ||
|
||
let update = ReadOnlyEditor.update; | ||
|
||
let calculate = ReadOnlyEditor.calculate; | ||
|
||
type event = | ||
| MakeActive | ||
| MouseUp | ||
| MouseDown; | ||
|
||
module View = { | ||
let get_goal = | ||
( | ||
~font_metrics: FontMetrics.t, | ||
text_box: Js.t(Dom_html.element), | ||
e: Js.t(Dom_html.mouseEvent), | ||
) => { | ||
let rect = text_box##getBoundingClientRect; | ||
let goal_x = float_of_int(e##.clientX); | ||
let goal_y = float_of_int(e##.clientY); | ||
Measured.Point.{ | ||
row: Float.to_int((goal_y -. rect##.top) /. font_metrics.row_height), | ||
col: | ||
Float.( | ||
to_int(round((goal_x -. rect##.left) /. font_metrics.col_width)) | ||
), | ||
}; | ||
}; | ||
|
||
let mousedown_overlay = (~signal, ~inject, ~font_metrics) => | ||
Node.div( | ||
~attr= | ||
Attr.many( | ||
Attr.[ | ||
id("mousedown-overlay"), | ||
on_mouseup(_ => signal(MouseUp)), | ||
on_mousemove(e => { | ||
let mouse_handler = | ||
e##.target |> Js.Opt.get(_, _ => failwith("no target")); | ||
let text_box = | ||
JsUtil.get_child_with_class( | ||
mouse_handler##.parentNode | ||
|> Js.Opt.get(_, _ => failwith("")) | ||
|> Js.Unsafe.coerce, | ||
"code-container", | ||
) | ||
|> Option.get; | ||
let goal = get_goal(~font_metrics, text_box, e); | ||
inject(Action.Select(Resize(Goal(Point(goal))))); | ||
}), | ||
], | ||
), | ||
[], | ||
); | ||
|
||
let mousedown_handler = (~signal, ~inject, ~font_metrics, evt) => { | ||
let goal = | ||
get_goal( | ||
~font_metrics, | ||
evt##.currentTarget | ||
|> Js.Opt.get(_, _ => failwith("")) | ||
|> JsUtil.get_child_with_class(_, "code-container") | ||
|> Option.get, | ||
evt, | ||
); | ||
switch (JsUtil.ctrl_held(evt), JsUtil.num_clicks(evt)) { | ||
| (true, _) => | ||
Effect.Many([ | ||
signal(MakeActive), | ||
inject(Action.Move(Goal(Point(goal)))), | ||
inject(Action.Jump(BindingSiteOfIndicatedVar)), | ||
]) | ||
| (false, 1) => | ||
Effect.Many([ | ||
signal(MouseDown), | ||
signal(MakeActive), | ||
inject(Action.Move(Goal(Point(goal)))), | ||
]) | ||
| (false, 2) => inject(Action.Select(Tile(Current))) | ||
| (false, 3 | _) => inject(Action.Select(Smart)) | ||
}; | ||
}; | ||
|
||
let view = | ||
( | ||
~signal: event => Ui_effect.t(unit), | ||
~inject: action => Ui_effect.t(unit), | ||
~ui_state: Model.ui_state, | ||
~settings: Settings.t, | ||
~selected: bool, | ||
~highlights: option(ColorSteps.colorMap), | ||
~overlays: list(Node.t)=[], | ||
~sort=?, | ||
model: model, | ||
) => { | ||
let edit_decos = { | ||
module Deco = | ||
Deco.Deco({ | ||
let editor = model.editor; | ||
let ui_state = ui_state; | ||
}); | ||
Deco.editor(model.editor.state.zipper, model.editor.state.meta.segment) | ||
@ ( | ||
switch (highlights) { | ||
| Some(colorMap) => | ||
Deco.color_highlights(ColorSteps.to_list(colorMap)) | ||
| _ => [] | ||
} | ||
); | ||
}; | ||
let overlays = edit_decos @ overlays; | ||
let code_view = | ||
ReadOnlyEditor.view(~ui_state, ~settings, ~overlays, ~sort?, model); | ||
let mousedown_overlay = | ||
selected && ui_state.mousedown | ||
? [ | ||
mousedown_overlay( | ||
~signal, | ||
~inject, | ||
~font_metrics=ui_state.font_metrics, | ||
), | ||
] | ||
: []; | ||
let on_mousedown = | ||
mousedown_handler( | ||
~signal, | ||
~inject, | ||
~font_metrics=ui_state.font_metrics, | ||
); | ||
Node.div( | ||
~attr= | ||
Attr.many([ | ||
Attr.classes(["cell-item"]), | ||
Attr.on_mousedown(on_mousedown), | ||
]), | ||
mousedown_overlay @ [code_view], | ||
); | ||
}; | ||
}; | ||
|
||
let view = View.view; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
open Virtual_dom.Vdom; | ||
open Util.Result.Syntax; | ||
open Haz3lcore; | ||
|
||
type model = { | ||
// Update: | ||
editor: Editor.t, | ||
// Calculate: | ||
statics: CachedStatics.statics, | ||
}; | ||
|
||
type action = Action.t; | ||
|
||
let update = (~settings, action, model) => { | ||
let+ editor = Perform.go(~settings, action, model.editor); | ||
{editor, statics: model.statics}; | ||
}; | ||
|
||
let calculate = (~settings, ~stitch, {editor, statics} as model) => { | ||
let term = MakeTerm.from_zip_for_sem(editor.state.zipper) |> fst |> stitch; | ||
if (Exp.fast_equal(term, statics.term)) { | ||
model; | ||
} else { | ||
{ | ||
editor, | ||
statics: CachedStatics.statics_of_term(~settings, term, editor), | ||
}; | ||
}; | ||
}; | ||
|
||
// There are no events for a read-only editor | ||
type event; | ||
|
||
// read-only editors cannot be selected | ||
type selection; | ||
|
||
let view = | ||
( | ||
~ui_state: Model.ui_state, | ||
~settings, | ||
~overlays: list(Node.t)=[], | ||
~sort=Sort.root, | ||
model: model, | ||
) => { | ||
let code_text_view = | ||
Code.view( | ||
~sort, | ||
~font_metrics=ui_state.font_metrics, | ||
~settings, | ||
model.editor, | ||
); | ||
let statics_decos = { | ||
module Deco = | ||
Deco.Deco({ | ||
let ui_state = ui_state; | ||
let editor = model.editor; | ||
}); | ||
Deco.statics(model.statics.error_ids); | ||
}; | ||
Node.div( | ||
~attr=Attr.many([Attr.classes(["code-container"])]), | ||
[code_text_view] @ statics_decos @ overlays, | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
open Haz3lcore; | ||
|
||
module Stepped = { | ||
type model = { | ||
editor: ReadOnlyEditor.model, | ||
step: EvaluatorStep.step, | ||
step_id: Id.t, | ||
}; | ||
|
||
type action = ReadOnlyEditor.action; | ||
|
||
type event = ReadOnlyEditor.event; | ||
|
||
type selection = ReadOnlyEditor.selection; | ||
|
||
let view = | ||
(~ui_state: Model.ui_state, ~settings, ~overlays=[], model: model) => { | ||
let overlays = { | ||
module Deco = | ||
Deco.Deco({ | ||
let editor = model.editor.editor; | ||
let ui_state = ui_state; | ||
}); | ||
overlays @ Deco.taken_step(Some(model.step_id)); | ||
}; | ||
ReadOnlyEditor.view(~ui_state, ~settings, ~overlays, model.editor); | ||
}; | ||
}; | ||
|
||
module Steppable = { | ||
type model = { | ||
editor: CodeEditor.model, | ||
next_steps: list(Id.t), | ||
}; | ||
|
||
type action = CodeEditor.action; | ||
|
||
type event = | ||
| TakeStep(int); | ||
|
||
let view = | ||
( | ||
~signal: event => Ui_effect.t(unit), | ||
~ui_state: Model.ui_state, | ||
~settings, | ||
~overlays=[], | ||
model: model, | ||
) => { | ||
let overlays = { | ||
module Deco = | ||
Deco.Deco({ | ||
let editor = model.editor.editor; | ||
let ui_state = ui_state; | ||
}); | ||
overlays | ||
@ Deco.next_steps(model.next_steps, ~inject=x => signal(TakeStep(x))); | ||
}; | ||
ReadOnlyEditor.view(~ui_state, ~settings, ~overlays, model.editor); | ||
}; | ||
}; |