Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade deps #8

Merged
merged 5 commits into from
Dec 20, 2024
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,9 +1,9 @@
{
"name": "tiye/respo",
"version": "0.0.17",
"version": "0.0.21",
"deps": {
"tiye/dom-ffi": "0.0.6",
"tiye/cirru-parser": "0.0.7"
"tiye/cirru-parser": "0.0.10"
},
"readme": "README.md",
"repository": "https://github.com/Respo/respo.mbt/",
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.1.0",
"version": "0.0.21",
"main": "index.js",
"repository": "git@github.com:Respo/respo.mbt.git",
"author": "tiye <jiyinyiyong@gmail.com>",
Expand Down
7 changes: 4 additions & 3 deletions src/lib/app.mbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
/// get basic App structure
///| get basic App structure
pub(all) struct RespoApp[Model] {
store : Ref[Model]
storage_key : String
mount_target : @dom_ffi.Node
}

/// backup store to local storage before unload

///| backup store to local storage before unload
pub fn backup_model_beforeunload[Model : ToJson](
self : RespoApp[Model]
) -> Unit {
Expand All @@ -22,6 +21,7 @@ pub fn backup_model_beforeunload[Model : ToJson](
window.set_onbeforeunload(beforeunload)
}

///|
pub fn try_load_storage[Model : @json.FromJson + Default](
key : String
) -> Model {
Expand Down Expand Up @@ -50,6 +50,7 @@ pub fn try_load_storage[Model : @json.FromJson + Default](
}
}

///|
pub fn RespoApp::render_loop[Model, ActionOp](
self : RespoApp[Model],
renderer : () -> @node.RespoNode[ActionOp]!@node.RespoCommonError,
Expand Down
150 changes: 67 additions & 83 deletions src/lib/dialog/alert.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// The options for alert modal.
///| The options for alert modal.
// #[derive(Debug, Clone, Default)]
pub(all) struct AlertOptions {
/// inline style for backdrop
Expand All @@ -11,6 +11,7 @@ pub(all) struct AlertOptions {
button_text : String?
} derive(Default)

///|
fn comp_alert_modal[T](
options : AlertOptions,
show : Bool,
Expand All @@ -24,92 +25,71 @@ fn comp_alert_modal[T](
@node.RespoComponent::named(
"alert-modal",
effects=[
effect_focus_data as @node.RespoEffect,
effect_modal_fade_data as @node.RespoEffect,
effect_focus_data as &@node.RespoEffect,
effect_modal_fade_data as &@node.RespoEffect,
],
div(
style=respo_style(position=Absolute),
[
if show {
div(
class_name=@node.str_spaced(
[@respo.ui_fullscreen, @respo.ui_center, css_backdrop],
),
style=options.backdrop_style,
event={}..set(
Click,
fn(e, _dispatch) {
div(style=respo_style(position=Absolute), [
if show {
div(
class_name=@node.str_spaced([
@respo.ui_fullscreen, @respo.ui_center, css_backdrop,
]),
style=options.backdrop_style,
event={}..set(Click, fn(e, _dispatch) {
match e {
Click(original_event~, ..) => original_event.stop_propagation()
_ => ()
}
}),
[
div(
class_name=@node.str_spaced([
@respo.ui_column, ui_global, css_modal_card,
]),
style=respo_style(line_height=Px(32.0)).merge(options.card_style),
event={}..set(Click, fn(e, _dispatch) {
match e {
Click(original_event~, ..) =>
original_event.stop_propagation()
_ => ()
}
},
}),
[
div([
span(inner_text=options.text.or("Alert!"), []),
space(height=8),
div(class_name=@respo.ui_row_parted, [
span([]),
button(
inner_text=options.button_text.or("Read"),
class_name=str_spaced([ui_button, css_button, button_name]),
event={}..set(Click, fn(_e, dispatch) {
read(dispatch)
close(dispatch)
}),
),
]),
]),
],
),
[
div(
class_name=@node.str_spaced(
[@respo.ui_column, ui_global, css_modal_card],
),
style=respo_style(line_height=Px(32.0)).merge(
options.card_style,
),
event={}..set(
Click,
fn(e, _dispatch) {
match e {
Click(original_event~, ..) =>
original_event.stop_propagation()
_ => ()
}
},
),
[
div(
[
span(inner_text=options.text.or("Alert!"), []),
space(height=8),
div(
class_name=@respo.ui_row_parted,
[
span([]),
button(
inner_text=options.button_text.or("Read"),
class_name=str_spaced(
[ui_button, css_button, button_name],
),
event={}..set(
Click,
fn(_e, dispatch) {
read(dispatch)
close(dispatch)
},
),
),
],
),
],
),
],
),
comp_esc_listener(show, close),
],
)
} else {
span(attrs=respo_attrs()..set("data-name", "placeholder"), [])
},
],
),
comp_esc_listener(show, close),
],
)
} else {
span(attrs=respo_attrs()..set("data-name", "placeholder"), [])
},
]),
).to_node()
}

// #[derive(Debug, Clone, Default, PartialEq, Eq, Deserialize, Serialize, RespoState)]
///|
struct AlertPluginState {
show : Bool
text : String?
} derive(Default, ToJson, @json.FromJson)

/// abstraction for Alert modal, new with `AlertOption`,
///| abstraction for Alert modal, new with `AlertOption`,
/// just displaying a message, you read it, you close it
pub(all) struct AlertPlugin[T] {
state : AlertPluginState
Expand All @@ -120,6 +100,7 @@ pub(all) struct AlertPlugin[T] {
on_read : (@node.DispatchFn[T]) -> Unit
}

///|
pub fn render[T : @node.RespoAction](
self : AlertPlugin[T]
) -> @node.RespoNode[T] {
Expand All @@ -143,10 +124,10 @@ pub fn render[T : @node.RespoAction](
let window = @dom_ffi.window()
// TODO dirty global variable
window.dirty_call_fn(next_task_name)
let ret = dispatch.run_state?(
c,
AlertPluginState::{ show: false, text: st.text },
)
let ret = dispatch.run_state?(c, AlertPluginState::{
show: false,
text: st.text,
})
match ret {
Ok(_) => ()
Err(e) => @dom_ffi.error_log("error: " + e.to_string())
Expand All @@ -157,10 +138,10 @@ pub fn render[T : @node.RespoAction](
fn(dispatch) {
let st = state
let c = cursor.copy()
let ret = dispatch.run_state?(
c,
AlertPluginState::{ show: false, text: st.text },
)
let ret = dispatch.run_state?(c, AlertPluginState::{
show: false,
text: st.text,
})
match ret {
Ok(_) => ()
Err(e) => @dom_ffi.error_log("error: " + e.to_string())
Expand All @@ -172,6 +153,7 @@ pub fn render[T : @node.RespoAction](
)
}

///|
pub fn show[T : @node.RespoAction](
self : AlertPlugin[T],
dispatch : @node.DispatchFn[T],
Expand All @@ -180,20 +162,22 @@ pub fn show[T : @node.RespoAction](
dispatch.run_state!(self.cursor, AlertPluginState::{ show: true, text })
}

///|
pub fn close[T : @node.RespoAction](
self : AlertPlugin[T],
dispatch : @node.DispatchFn[T]
) -> Unit {
let ret = dispatch.run_state?(
self.cursor,
AlertPluginState::{ show: false, text: self.text },
)
let ret = dispatch.run_state?(self.cursor, AlertPluginState::{
show: false,
text: self.text,
})
match ret {
Ok(_) => ()
Err(e) => @dom_ffi.error_log("error: " + e.to_string())
}
}

///|
pub fn AlertPlugin::new[T : @node.RespoAction](
states : @respo.RespoStatesTree,
options : AlertOptions,
Expand Down
Loading
Loading