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
4 changes: 2 additions & 2 deletions moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "tiye/respo-markdown",
"version": "0.0.2",
"version": "0.0.3",
"deps": {
"tiye/respo": "0.0.32",
"tiye/respo": "0.0.33",
"tiye/dom-ffi": "0.0.9"
},
"readme": "README.md",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mbt.respo",
"version": "0.0.2",
"version": "0.0.3",
"main": "index.js",
"repository": "[email protected]:Respo/respo-markdown.mbt.git",
"author": "tiye <[email protected]>",
Expand Down
45 changes: 21 additions & 24 deletions src/lib/md.mbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
///|
fnalias @respo_node.(
declare_static_style,
static_style,
respo_style,
blockquote,
create_element,
Expand All @@ -24,7 +24,7 @@ fnalias @respo_node.(
fnalias @respo.code_fonts

///|
fn comp_code_block[T](
fn[T] comp_code_block(
lines : Array[String],
highlighter~ : (String, String) -> String = fn(x, _) -> String { x }
) -> @respo_node.RespoNode[T] {
Expand All @@ -39,7 +39,7 @@ fn comp_code_block[T](
}

///|
fn comp_snippet[T](
fn[T] comp_snippet(
content : String,
class_name? : String,
highliter? : (String, String) -> String,
Expand All @@ -53,7 +53,7 @@ fn comp_snippet[T](
}

///|
let style_snippet : String = declare_static_style([
let style_snippet : String = static_style([
(
"&",
respo_style(
Expand All @@ -68,7 +68,7 @@ let style_snippet : String = declare_static_style([
])

///|
fn comp_image[T](chunk : String) -> @respo_node.RespoNode[T] {
fn[T] comp_image(chunk : String) -> @respo_node.RespoNode[T] {
let useful = chunk.substring(start=2, end=chunk.length() - 1)
let xs = useful.split("](").map(@string.View::to_string).collect()
if xs is [content, url, ..] {
Expand All @@ -81,7 +81,7 @@ fn comp_image[T](chunk : String) -> @respo_node.RespoNode[T] {
}

///|
fn comp_line[T](line : String) -> @respo_node.RespoNode[T] {
fn[T] comp_line(line : String) -> @respo_node.RespoNode[T] {
if line.has_prefix("# ") {
h1(render_inline(line.substring(start=2)))
} else if line.has_prefix("## ") {
Expand Down Expand Up @@ -113,7 +113,7 @@ fn comp_line[T](line : String) -> @respo_node.RespoNode[T] {
}

///|
fn comp_link[T](chunk : String) -> @respo_node.RespoNode[T] {
fn[T] comp_link(chunk : String) -> @respo_node.RespoNode[T] {
let useful = chunk.substring(start=1, end=chunk.length() - 1)
let xs = useful.split("](").map(@string.View::to_string).collect()
if xs is [content, url] {
Expand All @@ -138,15 +138,15 @@ fn comp_link[T](chunk : String) -> @respo_node.RespoNode[T] {
}

///|
pub fn comp_md[T](
pub fn[T] comp_md(
text : String,
class_name? : String
) -> @respo_node.RespoNode[T] {
div(class_name=class_name.or(""), render_inline(text))
}

///|
pub fn comp_md_block[T](
pub fn[T] comp_md_block(
text : String,
class_name? : String,
style? : @respo_node.RespoStyle,
Expand All @@ -171,7 +171,7 @@ pub fn comp_md_block[T](
}

///|
fn comp_table_block[T](
fn[T] comp_table_block(
lines : Array[Array[String]]
) -> @respo_node.RespoNode[T] {
let header_line = lines[0]
Expand Down Expand Up @@ -224,15 +224,15 @@ fn comp_table_block[T](
}

///|
fn comp_text_block[T](lines : Array[String]) -> @respo_node.RespoNode[T] {
fn[T] comp_text_block(lines : Array[String]) -> @respo_node.RespoNode[T] {
return div(
class_name=style_paragraph,
lines.iter().map(fn(line) { comp_line(line) }).collect(),
)
}

///|
fn render_inline[T](text : String) -> Array[@respo_node.RespoNode[T]] {
fn[T] render_inline(text : String) -> Array[@respo_node.RespoNode[T]] {
let els = []
let lines = split_line(text)
for chunk in lines {
Expand All @@ -252,7 +252,7 @@ fn render_inline[T](text : String) -> Array[@respo_node.RespoNode[T]] {
}

///|
let style_blockquote : String = declare_static_style([
let style_blockquote : String = static_style([
(
"&",
respo_style(
Expand All @@ -265,18 +265,18 @@ let style_blockquote : String = declare_static_style([
])

///|
let style_code_block : String = declare_static_style([
let style_code_block : String = static_style([
("&", respo_style(max_width=60 |> Vw)),
])

///|
let style_default_link : String = declare_static_style([
let style_default_link : String = static_style([
("&", respo_style(opacity=0.9, transition_duration=200 |> Ms)),
("&:hover", respo_style(opacity=1, transform=1 |> Scale)),
])

///|
let style_image : String = declare_static_style([
let style_image : String = static_style([
(
"&",
respo_style(
Expand All @@ -288,16 +288,13 @@ let style_image : String = declare_static_style([
),
])

// defstyle style-indent $ {}
// "\"&" $ {} (:white-space :pre) (:float :left)

///|
let style_indent : String = declare_static_style([
let style_indent : String = static_style([
("&", respo_style(white_space="pre", float="left")),
])

///|
let style_inline_code : String = declare_static_style([
let style_inline_code : String = static_style([
(
"&",
respo_style(
Expand All @@ -311,7 +308,7 @@ let style_inline_code : String = declare_static_style([
])

///|
let style_line_list : String = declare_static_style([
let style_line_list : String = static_style([
("&", respo_style(margin_left=12 |> Px)),
(
"&::marker",
Expand All @@ -327,7 +324,7 @@ let style_line_list : String = declare_static_style([
])

///|
let style_md_table : String = declare_static_style([
let style_md_table : String = static_style([
(
"&",
respo_style(border=(1, Solid, Hsl(0, 0, 90)))
Expand Down Expand Up @@ -356,4 +353,4 @@ let style_md_table : String = declare_static_style([
])

///|
let style_paragraph : String = declare_static_style([("&", respo_style())])
let style_paragraph : String = static_style([("&", respo_style())])
22 changes: 8 additions & 14 deletions src/main/container.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ struct ContainerState {
} derive(ToJson, @json.FromJson, Default)

///|
fn comp_container[Op : @respo_node.RespoAction](
fn[Op : @respo_node.RespoAction] comp_container(
states : RespoStatesTree
) -> @respo_node.RespoNode[Op] {
let cursor = states.cursor
let cursor = states.path()
let state = (states.cast_branch() : ContainerState)
div(
class_name=ui_global,
Expand Down Expand Up @@ -70,14 +70,11 @@ fn comp_container[Op : @respo_node.RespoAction](
style=respo_style(width=100 |> Percent),
value=state.text,
placeholder="text inline",
event={}..set(Input, fn(e, dispatch) {
on_input=fn(e, dispatch) {
if e is Input(value~, ..) {
dispatch.set_state!(cursor, ContainerState::{
..state,
text: value,
})
dispatch.set_state!(cursor, { ..state, text: value })
}
}),
},
),
comp_md(state.text),
]),
Expand All @@ -98,14 +95,11 @@ fn comp_container[Op : @respo_node.RespoAction](
width=100 |> Percent,
font_size=13,
),
event={}..set(Input, fn(e, dispatch) {
on_input=fn(e, dispatch) {
if e is Input(value~, ..) {
dispatch.set_state!(cursor, ContainerState::{
..state,
draft: value,
})
dispatch.set_state!(cursor, { ..state, draft: value })
}
}),
},
),
]),
div(class_name=ui_expand, style=respo_style(padding=8 |> Px), [
Expand Down
2 changes: 1 addition & 1 deletion src/main/store.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Show for ActionOp with output(self, logger) -> Unit {
}

///|
fn get_states(self : Store) -> @respo.RespoStatesTree {
fn Store::get_states(self : Store) -> @respo.RespoStatesTree {
self.states
}

Expand Down