Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions src/lib/md.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@ fnalias @respo_node.(
h3,
h4,
pre,
li,
text_node
li
)

///|
fnalias @respo.code_fonts
let code_fonts = @respo.code_fonts

///|
fn[T] comp_code_block(
lines : Array[String],
highlighter~ : (String, String) -> String = fn(x, _) -> String { x }
highlighter~ : (String, String) -> String = fn(x, _) -> String { x },
) -> @respo_node.RespoNode[T] {
let lang = lines[0]
let content = lines[1:].to_array().join("\n")
Expand All @@ -43,11 +42,11 @@ fn[T] comp_snippet(
content : String,
class_name? : String,
highliter? : (String, String) -> String,
lang? : String
lang? : String,
) -> @respo_node.RespoNode[T] {
let highliter = highliter.or(fn(content, _) -> String { content })
let highlighted = highliter(content, lang.or("text"))
return div(class_list=[style_snippet, class_name.or("")], [
let highliter = highliter.unwrap_or(fn(content, _) -> String { content })
let highlighted = highliter(content, lang.unwrap_or("text"))
return div(class_list=[style_snippet, class_name.unwrap_or("")], [
pre(class_name=style_code_block, children=[code(inner_text=highlighted)]),
])
}
Expand Down Expand Up @@ -140,30 +139,30 @@ fn[T] comp_link(chunk : String) -> @respo_node.RespoNode[T] {
///|
pub fn[T] comp_md(
text : String,
class_name? : String
class_name? : String,
) -> @respo_node.RespoNode[T] {
div(class_name=class_name.or(""), render_inline(text))
div(class_name=class_name.unwrap_or(""), render_inline(text))
}

///|
pub fn[T] comp_md_block(
text : String,
class_name? : String,
style? : @respo_node.RespoStyle,
highlighter~ : (String, String) -> String = fn(x, _) -> String { x }
highlighter~ : (String, String) -> String = fn(x, _) -> String { x },
) -> @respo_node.RespoNode[T] {
let blocks = split_block(text)
return div(
class_list=[class_name.or(""), "md-block"],
style=style.or(respo_style()),
class_list=[class_name.unwrap_or(""), "md-block"],
style=style.unwrap_or(respo_style()),
blocks
.iter()
.map(fn(block) {
match block {
Text(lines) => comp_text_block(lines.to_array())
Code(lines) => comp_code_block(lines.to_array(), highlighter~)
Table(lines) => comp_table_block(lines.to_array())
_ => div([block.to_string() |> text_node])
Empty => div([])
}
})
.collect(),
Expand All @@ -172,7 +171,7 @@ pub fn[T] comp_md_block(

///|
fn[T] comp_table_block(
lines : Array[Array[String]]
lines : Array[Array[String]],
) -> @respo_node.RespoNode[T] {
let header_line = lines[0]
let mark_line = lines[1]
Expand Down
16 changes: 5 additions & 11 deletions src/lib/regex.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///|
priv extern type JsRegex
#external
priv type JsRegex

///| extract basic information from a regex match result
priv struct MatchResult {
Expand All @@ -11,7 +12,7 @@ priv struct MatchResult {
///|
extern "js" fn JsRegex::js_regex_create(
pattern : String,
flags : String
flags : String,
) -> JsRegex =
#| (pattern, flags) => new RegExp(pattern, flags)

Expand All @@ -24,7 +25,8 @@ extern "js" fn JsRegex::match_str(regex : JsRegex, input : String) -> JsValue =
#| }

///|
priv extern type JsValue
#external
priv type JsValue

///|
extern "js" fn JsValue::is_null(obj : JsValue) -> Bool =
Expand All @@ -34,18 +36,10 @@ extern "js" fn JsValue::is_null(obj : JsValue) -> Bool =
extern "js" fn JsValue::get_length(obj : JsValue) -> UInt =
#| (obj) => obj.length

///|
extern "js" fn JsValue::get_prop(obj : JsValue, p : String) -> JsValue =
#| (obj, p) => obj[p]

///|
extern "js" fn JsValue::reinterpret_as_string(obj : JsValue) -> String =
#| (obj) => obj

///|
extern "js" fn JsValue::reinterpret_as_int(obj : JsValue) -> Int =
#| (obj) => obj

///|
extern "js" fn JsValue::get_index(obj : JsValue, index : UInt) -> JsValue =
#| (obj, index) => obj[index]
Expand Down
8 changes: 4 additions & 4 deletions src/lib/util.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ priv enum Block {
Text(@immut/array.T[String])
Code(@immut/array.T[String])
Table(@immut/array.T[Array[String]])
} derive(Show, Eq)
}

///|
fn split_block(text : String) -> Array[Block] {
Expand All @@ -37,7 +37,7 @@ fn split_block(text : String) -> Array[Block] {
fn split_block_iter(
lines : Array[String],
acc : Array[Block],
buffer : Block
buffer : Block,
) -> Array[Block] {
if lines.is_empty() {
if buffer is Empty {
Expand Down Expand Up @@ -124,7 +124,7 @@ priv enum LineChunk {
Image(String)
Emphasis(String)
Italic(String)
} derive(Show, Eq)
}

///|
fn LineChunk::is_empty(self : LineChunk) -> Bool {
Expand All @@ -149,7 +149,7 @@ fn split_line(line : String) -> Array[LineChunk] {
fn split_line_iter(
acc : Array[LineChunk],
line : String,
mode : LineChunk
mode : LineChunk,
) -> Array[LineChunk] {
if line == "" {
if mode.is_empty() {
Expand Down
30 changes: 19 additions & 11 deletions src/main/container.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ fnalias @respo_node.(
)

///|
fnalias @respo.(
ui_row_middle,
ui_row,
ui_expand,
ui_textarea,
ui_font_code,
ui_input
)
let ui_row_middle = @respo.ui_row_middle

///|
let ui_row = @respo.ui_row

///|
let ui_expand = @respo.ui_expand

///|
let ui_textarea = @respo.ui_textarea

///|
let ui_font_code = @respo.ui_font_code

///|
let ui_input = @respo.ui_input

///|
struct ContainerState {
Expand All @@ -32,7 +40,7 @@ struct ContainerState {

///|
fn[Op : @respo_node.RespoAction] comp_container(
states : RespoStatesTree
states : RespoStatesTree,
) -> @respo_node.RespoNode[Op] {
let cursor = states.path()
let state = (states.cast_branch() : ContainerState)
Expand Down Expand Up @@ -72,7 +80,7 @@ fn[Op : @respo_node.RespoAction] comp_container(
placeholder="text inline",
on_input=fn(e, dispatch) {
if e is Input(value~, ..) {
dispatch.set_state!(cursor, { ..state, text: value })
dispatch.set_state(cursor, { ..state, text: value })
}
},
),
Expand All @@ -97,7 +105,7 @@ fn[Op : @respo_node.RespoAction] comp_container(
),
on_input=fn(e, dispatch) {
if e is Input(value~, ..) {
dispatch.set_state!(cursor, { ..state, draft: value })
dispatch.set_state(cursor, { ..state, draft: value })
}
},
),
Expand Down
8 changes: 4 additions & 4 deletions src/main/main.mbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
///|
fnalias @respo.ui_global
let ui_global = @respo.ui_global

///|
fnalias @respo_node.(div, respo_style)
Expand All @@ -9,8 +9,8 @@ let app_store_key : String = "mbt-workflow"

///|
fn view(
store : Store
) -> @respo_node.RespoNode[ActionOp]!@respo_node.RespoCommonError {
store : Store,
) -> @respo_node.RespoNode[ActionOp] raise @respo_node.RespoCommonError {
if false {
raise @respo_node.RespoCommonError("TODO")
}
Expand All @@ -35,7 +35,7 @@ fn main {
}
app.backup_model_beforeunload()
// @dom_ffi.log("store: " + app.store.val.to_json().stringify(indent=2))
app.render_loop(fn() { view!(app.store.val) }, fn(op) {
app.render_loop(fn() { view(app.store.val) }, fn(op) {
@dom_ffi.log("Action: " + op.to_string())
app.store.val.update(op)
})
Expand Down
5 changes: 0 additions & 5 deletions src/main/store.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,3 @@ fn update(self : Store, op : ActionOp) -> Unit {
StatesChange(states) => self.states.set_in_mut(states)
}
}

///|
impl Show for Store with output(self, logger) -> Unit {
logger.write_string(self.to_json().stringify(indent=2))
}