From 94b6e2653a69c548ae1e44e10ac50b565bcd2d6e Mon Sep 17 00:00:00 2001 From: tiye Date: Tue, 19 Nov 2024 01:49:17 +0800 Subject: [PATCH] upgrade and fix warnings; tag 0.0.15 --- moon.mod.json | 4 +- src/lib/app.mbt | 2 +- src/lib/dialog/alert.mbt | 8 +- src/lib/dialog/confirm.mbt | 8 +- src/lib/dialog/dialogs.mbt | 2 +- src/lib/dialog/drawer.mbt | 8 +- src/lib/dialog/modal.mbt | 15 +-- src/lib/dialog/prompt.mbt | 12 +- src/lib/node/alias.mbt | 216 ++++++++++++++++++------------------ src/lib/node/component.mbt | 4 +- src/lib/node/css-size.mbt | 2 +- src/lib/node/css.mbt | 198 ++++++++++++++++----------------- src/lib/node/diff.mbt | 32 +++--- src/lib/node/dom-change.mbt | 94 ++++++++-------- src/lib/node/effect.mbt | 4 +- src/lib/node/element.mbt | 50 ++++----- src/lib/node/listener.mbt | 30 ++--- src/lib/node/node.mbt | 6 +- src/lib/node/patch.mbt | 22 ++-- src/lib/node/util.mbt | 2 +- src/lib/states-tree.mbt | 4 +- src/main/counter.mbt | 2 +- src/main/panel.mbt | 2 +- src/main/task.mbt | 2 +- 24 files changed, 365 insertions(+), 364 deletions(-) diff --git a/moon.mod.json b/moon.mod.json index f16ee4c..ae7c582 100644 --- a/moon.mod.json +++ b/moon.mod.json @@ -1,8 +1,8 @@ { "name": "tiye/respo", - "version": "0.0.14", + "version": "0.0.15", "deps": { - "tiye/dom-ffi": "0.0.5", + "tiye/dom-ffi": "0.0.6", "tiye/cirru-parser": "0.0.7" }, "readme": "README.md", diff --git a/src/lib/app.mbt b/src/lib/app.mbt index bdf672d..a40a7d4 100644 --- a/src/lib/app.mbt +++ b/src/lib/app.mbt @@ -1,5 +1,5 @@ /// get basic App structure -pub struct RespoApp[Model] { +pub(all) struct RespoApp[Model] { store : Ref[Model] storage_key : String mount_target : @dom_ffi.Node diff --git a/src/lib/dialog/alert.mbt b/src/lib/dialog/alert.mbt index 35957dc..b03edfd 100644 --- a/src/lib/dialog/alert.mbt +++ b/src/lib/dialog/alert.mbt @@ -1,6 +1,6 @@ /// The options for alert modal. // #[derive(Debug, Clone, Default)] -pub struct AlertOptions { +pub(all) struct AlertOptions { /// inline style for backdrop mut backdrop_style : @node.RespoStyle /// inline style for card @@ -40,7 +40,7 @@ fn comp_alert_modal[T]( Click, fn(e, _dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -58,7 +58,7 @@ fn comp_alert_modal[T]( Click, fn(e, _dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -111,7 +111,7 @@ struct AlertPluginState { /// abstraction for Alert modal, new with `AlertOption`, /// just displaying a message, you read it, you close it -pub struct AlertPlugin[T] { +pub(all) struct AlertPlugin[T] { state : AlertPluginState options : AlertOptions /// tracking content to display diff --git a/src/lib/dialog/confirm.mbt b/src/lib/dialog/confirm.mbt index b6acc2f..b900820 100644 --- a/src/lib/dialog/confirm.mbt +++ b/src/lib/dialog/confirm.mbt @@ -1,7 +1,7 @@ let next_task_name : String = "_RESPO_CONFIRM_NEXT_TASK" /// options for confirm dialog -pub struct ConfirmOptions { +pub(all) struct ConfirmOptions { /// inline style for backdrop backdrop_style : @node.RespoStyle /// inline style for card @@ -43,7 +43,7 @@ fn comp_confirm_modal[T]( Click, fn(e, dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -61,7 +61,7 @@ fn comp_confirm_modal[T]( Click, fn(e, _dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -123,7 +123,7 @@ struct ConfirmPluginState { } derive(Default, ToJson, @json.FromJson) /// Popup a confirmation dialog, confirm to process next task -pub struct ConfirmPlugin[T] { +pub(all) struct ConfirmPlugin[T] { state : ConfirmPluginState options : ConfirmOptions /// tracking content to display diff --git a/src/lib/dialog/dialogs.mbt b/src/lib/dialog/dialogs.mbt index 6a3d9e8..d8dda2d 100644 --- a/src/lib/dialog/dialogs.mbt +++ b/src/lib/dialog/dialogs.mbt @@ -166,7 +166,7 @@ pub fn comp_esc_listener[T]( Keydown, fn(e, dispatch) { match e { - Keyboard(~key, ..) => if key == "Escape" { on_close(dispatch) } + Keyboard(key~, ..) => if key == "Escape" { on_close(dispatch) } _ => () } }, diff --git a/src/lib/dialog/drawer.mbt b/src/lib/dialog/drawer.mbt index ffb8661..cbbba18 100644 --- a/src/lib/dialog/drawer.mbt +++ b/src/lib/dialog/drawer.mbt @@ -1,6 +1,6 @@ /// The options for custom drawer. // #[derive(Debug, Clone, Default)] -pub struct DrawerOptions[T] { +pub(all) struct DrawerOptions[T] { /// inline style for backdrop backdrop_style : @node.RespoStyle /// inline style for card @@ -66,7 +66,7 @@ fn comp_drawer[T]( Click, fn(e, dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -83,7 +83,7 @@ fn comp_drawer[T]( Click, fn(e, _dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -123,7 +123,7 @@ struct DrawerPluginState { /// a drawer that you can render you down card body // #[derive(Debug, Clone)] -pub struct DrawerPlugin[T] { +pub(all) struct DrawerPlugin[T] { state : DrawerPluginState options : DrawerOptions[T] /// tracking content to display diff --git a/src/lib/dialog/modal.mbt b/src/lib/dialog/modal.mbt index d32454c..4f7539a 100644 --- a/src/lib/dialog/modal.mbt +++ b/src/lib/dialog/modal.mbt @@ -1,6 +1,6 @@ /// The options for custom modal. // #[derive(Debug, Clone, Default)] -pub struct ModalOptions[T] { +pub(all) struct ModalOptions[T] { /// inline style for backdrop backdrop_style : @node.RespoStyle /// inline style for card @@ -11,9 +11,10 @@ pub struct ModalOptions[T] { render : ModalRenderer[T] } derive(Default) -pub type ModalRenderer[T] ((@node.DispatchFn[T]) -> Unit!@node.RespoCommonError) -> @node.RespoNode[ - T, -]!@node.RespoCommonError +/// tmp fix since syntax error +typealias Dispatcher[T] = (@node.DispatchFn[T]) -> Unit!@node.RespoCommonError + +pub(all) type ModalRenderer[T] (Dispatcher[T]) -> @node.RespoNode[T]!@node.RespoCommonError pub fn ModalRenderer::default[T]() -> ModalRenderer[T] { fn(_close) { div([]) } @@ -61,7 +62,7 @@ fn comp_modal[T]( Click, fn(e, dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -78,7 +79,7 @@ fn comp_modal[T]( Click, fn(e, _dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -119,7 +120,7 @@ struct ModalPluginState { /// a modal that you can render you down card body // #[derive(Debug, Clone)] -pub struct ModalPlugin[T] { +pub(all) struct ModalPlugin[T] { // where // T: Clone + Debug, state : ModalPluginState diff --git a/src/lib/dialog/prompt.mbt b/src/lib/dialog/prompt.mbt index 398471c..0919b7e 100644 --- a/src/lib/dialog/prompt.mbt +++ b/src/lib/dialog/prompt.mbt @@ -2,7 +2,7 @@ let next_prompt_task_name : String = "_RESPO_PROMPT_NEXT_TASK" /// options for prompt dialog // #[derive(Debug, Clone, Default)] -pub struct PromptOptions { +pub(all) struct PromptOptions { /// inline style for backdrop backdrop_style : @node.RespoStyle /// inline style for card @@ -24,7 +24,7 @@ pub struct PromptOptions { // /// wraps validator function // #[allow(clippy::type_complexity)] // #[derive(Clone)] -pub type PromptValidator (String) -> Result[Unit, String] +pub(all) type PromptValidator (String) -> Result[Unit, String] pub fn to_string(self : PromptValidator) -> String { "(PromptValidator \{self})" @@ -85,7 +85,7 @@ fn comp_prompt_modal[T : @node.RespoAction]( // dispatch.run_state(&cursor, InputState { draft: value, error: None })?; // } match e { - Input(~value, ..) => + Input(value~, ..) => // @dom_ffi.log("input value: " + value.escape()) // @dom_ffi.log("input state: " + s.to_json().stringify(indent=2)) dispatch.run_state!(cursor, InputState::{ draft: value, error: None }) @@ -146,7 +146,7 @@ fn comp_prompt_modal[T : @node.RespoAction]( Click, fn(e, dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -166,7 +166,7 @@ fn comp_prompt_modal[T : @node.RespoAction]( Click, fn(e, _dispatch) { match e { - Click(~original_event, ..) => + Click(original_event~, ..) => original_event.stop_propagation() _ => () } @@ -248,7 +248,7 @@ struct PromptPluginState { /// a dialog for prompt, request for some input, and submit // #[derive(Debug, Clone)] -pub struct PromptPlugin[T] { +pub(all) struct PromptPlugin[T] { states : @respo.RespoStatesTree state : PromptPluginState options : PromptOptions diff --git a/src/lib/node/alias.mbt b/src/lib/node/alias.mbt index 42aab42..c1dc465 100644 --- a/src/lib/node/alias.mbt +++ b/src/lib/node/alias.mbt @@ -3,13 +3,13 @@ ///
element with children. pub fn div[T]( - ~class_name? : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style(), + style~ : RespoStyle = respo_style(), children : Array[RespoNode[T]] ) -> RespoNode[T] { match class_name { @@ -31,13 +31,13 @@ pub fn div[T]( /// create a list of `
` elements with children. `IndexKey` is used in children for quick diffing. pub fn div_listed[T]( - ~class_name? : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style(), + style~ : RespoStyle = respo_style(), children : Array[(RespoIndexKey, RespoNode[T])] ) -> RespoNode[T] { match class_name { @@ -48,14 +48,14 @@ pub fn div_listed[T]( } pub fn span[T]( - ~class_name? : String, - ~inner_text? : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + inner_text? : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style(), + style~ : RespoStyle = respo_style(), children : Array[RespoNode[T]] ) -> RespoNode[T] { match class_name { @@ -80,14 +80,14 @@ pub fn span[T]( } pub fn button[T]( - ~class_name? : String, - ~inner_text : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + inner_text~ : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { match class_name { Some(class_name) => attrs.set("class", class_name) @@ -98,21 +98,21 @@ pub fn button[T]( } pub fn input[T]( - ~class_name? : String, - ~autocomplete? : TextareaElementAutoComplete, - ~autofocus? : Bool, - ~disabled? : Bool, - ~name? : String, - ~placeholder? : String, - ~readonly_? : Bool, - ~spellcheck? : Bool, - ~attrs : Map[String, String] = {}, - ~value : String, - ~event : Map[ + class_name? : String, + autocomplete? : TextareaElementAutoComplete, + autofocus? : Bool, + disabled? : Bool, + name? : String, + placeholder? : String, + readonly_? : Bool, + spellcheck? : Bool, + attrs~ : Map[String, String] = {}, + value~ : String, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { match class_name { Some(class_name) => attrs.set("class", class_name) @@ -161,27 +161,27 @@ pub fn input[T]( Element({ name: "input", attrs, event, style, children: [] }) } -pub enum TextareaElementAutoComplete { +pub(all) enum TextareaElementAutoComplete { On Off } pub fn textarea[T]( - ~class_name? : String, - ~value : String, - ~autocomplete? : TextareaElementAutoComplete, - ~autofocus? : Bool, - ~disabled? : Bool, - ~name? : String, - ~placeholder? : String, - ~readonly_? : Bool, - ~spellcheck? : Bool, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + value~ : String, + autocomplete? : TextareaElementAutoComplete, + autofocus? : Bool, + disabled? : Bool, + name? : String, + placeholder? : String, + readonly_? : Bool, + spellcheck? : Bool, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { match class_name { Some(class_name) => attrs.set("class", class_name) @@ -230,7 +230,7 @@ pub fn textarea[T]( Element({ name: "textarea", attrs, event, style, children: [] }) } -pub enum AnchorElementTarget { +pub(all) enum AnchorElementTarget { Blank Parent Self @@ -249,25 +249,25 @@ pub fn to_string(self : AnchorElementTarget) -> String { /// anchor element /// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a pub fn a[T]( - ~inner_text : String, - ~class_name? : String, + inner_text~ : String, + class_name? : String, /// The URL that the hyperlink points to. /// will override href in attrs. - ~href : String, + href~ : String, /// The value of the download attribute, which will be used when the user triggers a download. /// will override download in attrs. - ~download? : String, + download? : String, /// The target attribute specifies where to open the linked document. /// will override target in attrs. - ~target? : AnchorElementTarget, - ~attrs : Map[String, String] = {}, + target? : AnchorElementTarget, + attrs~ : Map[String, String] = {}, /// mime type of the linked document. - ~type_? : String, - ~event : Map[ + type_? : String, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { attrs.set("href", href) attrs.set("innerText", inner_text) @@ -291,32 +291,32 @@ pub fn a[T]( } pub fn br[T]( - ~attrs : Map[String, String] = {}, - ~event : Map[ + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { Element({ name: "br", attrs, event, style, children: [] }) } -pub enum IframeElementLoading { +pub(all) enum IframeElementLoading { Eager Lazy } pub fn iframe[T]( - ~height? : Int, - ~width? : Int, - ~loading? : IframeElementLoading, - ~src : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + height? : Int, + width? : Int, + loading? : IframeElementLoading, + src~ : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { attrs.set("src", src) match height { @@ -342,14 +342,14 @@ pub fn iframe[T]( } pub fn canvas[T]( - ~height? : Int, - ~width? : Int, - ~attrs : Map[String, String] = {}, - ~event : Map[ + height? : Int, + width? : Int, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { match height { Some(height) => attrs.set("height", height.to_string()) @@ -363,14 +363,14 @@ pub fn canvas[T]( } pub fn code[T]( - ~class_name? : String, - ~inner_text : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + inner_text~ : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { match class_name { Some(class_name) => attrs.set("class", class_name) @@ -381,14 +381,14 @@ pub fn code[T]( } pub fn pre[T]( - ~class_name? : String, - ~inner_text : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + class_name? : String, + inner_text~ : String, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { match class_name { Some(class_name) => attrs.set("class", class_name) @@ -399,10 +399,10 @@ pub fn pre[T]( } pub fn p[T]( - ~class_name? : String, - ~inner_text : String, - ~attrs : Map[String, String] = {}, - ~style : RespoStyle = respo_style(), + class_name? : String, + inner_text~ : String, + attrs~ : Map[String, String] = {}, + style~ : RespoStyle = respo_style(), children : Array[RespoNode[T]] ) -> RespoNode[T] { match class_name { @@ -416,23 +416,23 @@ pub fn p[T]( Element({ name: "p", attrs, event: {}, style, children }) } -pub enum ImgElementLoading { +pub(all) enum ImgElementLoading { Eager Lazy } pub fn img[T]( - ~alt : String, - ~height? : Int, - ~src : String, - ~width? : Int, - ~loading? : ImgElementLoading, - ~attrs : Map[String, String] = {}, - ~event : Map[ + alt~ : String, + height? : Int, + src~ : String, + width? : Int, + loading? : ImgElementLoading, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { attrs.set("alt", alt) attrs.set("src", src) @@ -458,24 +458,24 @@ pub fn img[T]( Element({ name: "img", attrs, event, style, children: [] }) } -pub enum VideoElementPreload { +pub(all) enum VideoElementPreload { Auto Metadata None } pub fn video[T]( - ~height? : Int, - ~width? : Int, - ~src : String, - ~controls? : Bool, - ~preload? : VideoElementPreload, - ~attrs : Map[String, String] = {}, - ~event : Map[ + height? : Int, + width? : Int, + src~ : String, + controls? : Bool, + preload? : VideoElementPreload, + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style() + style~ : RespoStyle = respo_style() ) -> RespoNode[T] { attrs.set("src", src) match height { @@ -508,9 +508,9 @@ pub fn video[T]( /// create a `
` element to render space. pub fn space[T]( - ~width : Int = 1, - ~height : Int = 1, - ~class_name? : String + width~ : Int = 1, + height~ : Int = 1, + class_name? : String ) -> RespoNode[T] { let attrs : Map[String, String] = {} match class_name { @@ -523,7 +523,7 @@ pub fn space[T]( height=Px(height), display=if height > 1 { Block } else { InlineBlock }, ), - ~attrs, + attrs~, [], ) } @@ -531,12 +531,12 @@ pub fn space[T]( /// create element with a custom name pub fn create_element[T]( name : String, - ~attrs : Map[String, String] = {}, - ~event : Map[ + attrs~ : Map[String, String] = {}, + event~ : Map[ RespoEventType, (RespoEvent, DispatchFn[T]) -> Unit!RespoCommonError, ] = {}, - ~style : RespoStyle = respo_style(), + style~ : RespoStyle = respo_style(), children : Array[RespoNode[T]] ) -> RespoNode[T] { Element( diff --git a/src/lib/node/component.mbt b/src/lib/node/component.mbt index df47b99..ed5f6f1 100644 --- a/src/lib/node/component.mbt +++ b/src/lib/node/component.mbt @@ -1,4 +1,4 @@ -pub struct RespoComponent[T] { +pub(all) struct RespoComponent[T] { name : String effects : Array[RespoEffectBox] tree : RespoNode[T] @@ -24,7 +24,7 @@ fn to_string[T](self : RespoComponent[T]) -> String { pub fn RespoComponent::named[T]( name : String, tree : RespoNode[T], - ~effects : Array[RespoEffect] = [] + effects~ : Array[RespoEffect] = [] ) -> RespoComponent[T] { { name, effects: effects.map(fn(x) { x.build_effect() }), tree } } diff --git a/src/lib/node/css-size.mbt b/src/lib/node/css-size.mbt index ff7e6a8..204e37c 100644 --- a/src/lib/node/css-size.mbt +++ b/src/lib/node/css-size.mbt @@ -1,4 +1,4 @@ -pub enum CssSize { +pub(all) enum CssSize { Auto Px(Int) Percent(Int) diff --git a/src/lib/node/css.mbt b/src/lib/node/css.mbt index 5300f5b..7980b1a 100644 --- a/src/lib/node/css.mbt +++ b/src/lib/node/css.mbt @@ -1,4 +1,4 @@ -pub type RespoStyle Array[(String, String)] derive(Eq, Default) +pub(all) type RespoStyle Array[(String, String)] derive(Eq, Default) // is_empty pub fn is_empty(self : RespoStyle) -> Bool { @@ -39,79 +39,79 @@ fn length(self : RespoStyle) -> Int { /// Create a new RespoStyle object pub fn respo_style( // Basic Styling - ~color? : CssColor, - ~background_color? : CssColor, - ~font_size? : UInt, - ~font_family? : String, - ~font_weight? : String, - ~text_align? : CssTextAlign, - ~display? : CssDisplay, - ~margin? : CssSize, - ~padding? : CssSize, - ~border? : CssBorder, - ~width? : CssSize, - ~height? : CssSize, + color? : CssColor, + background_color? : CssColor, + font_size? : UInt, + font_family? : String, + font_weight? : String, + text_align? : CssTextAlign, + display? : CssDisplay, + margin? : CssSize, + padding? : CssSize, + border? : CssBorder, + width? : CssSize, + height? : CssSize, // Layout & Positioning - ~position? : CssPosition, - ~top? : CssSize, - ~right? : CssSize, - ~bottom? : CssSize, - ~left? : CssSize, - ~float? : String, - ~clear? : String, - ~overflow? : CssOverflow, - ~z_index? : Int, - ~flex? : Float, - ~flex_direction? : CssFlexDirection, - ~justify_content? : CssFlexJustifyContent, - ~align_items? : CssFlexAlignItems, - ~align_content? : CssFlexAlignContent, - ~order? : Int, + position? : CssPosition, + top? : CssSize, + right? : CssSize, + bottom? : CssSize, + left? : CssSize, + float? : String, + clear? : String, + overflow? : CssOverflow, + z_index? : Int, + flex? : Float, + flex_direction? : CssFlexDirection, + justify_content? : CssFlexJustifyContent, + align_items? : CssFlexAlignItems, + align_content? : CssFlexAlignContent, + order? : Int, // Text Styling - ~text_decoration? : CssTextDecoration, - ~text_transform? : String, - ~line_height? : CssLineHeight, - ~letter_spacing? : String, - ~white_space? : String, - ~word_break? : CssWordBreak, + text_decoration? : CssTextDecoration, + text_transform? : String, + line_height? : CssLineHeight, + letter_spacing? : String, + white_space? : String, + word_break? : CssWordBreak, // Visual Effects - ~opacity? : Int, - ~visibility? : String, - ~box_shadow? : String, - ~transition? : String, - ~box_sizing? : CssBoxSizing, + opacity? : Int, + visibility? : String, + box_shadow? : String, + transition? : String, + box_sizing? : CssBoxSizing, // more - ~border_radius? : Float, - ~padding_top? : CssSize, - ~padding_bottom? : CssSize, - ~padding_left? : CssSize, - ~padding_right? : CssSize, - ~min_width? : CssSize, - ~max_width? : CssSize, - ~vertical_align? : CssVerticalAlign, - ~border_style? : CssBorderStyle, - ~border_color? : CssColor, - ~border_width? : CssSize, - ~cursor? : CssCursor, - ~transition_duration? : CssDuration, - ~transform? : CssTransform, - ~outline? : CssOutline, - ~user_select? : CssUserSelect, - ~margin_top? : CssSize, - ~margin_bottom? : CssSize, - ~margin_left? : CssSize, - ~margin_right? : CssSize, - ~max_height? : CssSize, - ~transform_property? : Array[String], - ~gap? : CssSize, - ~content? : String, - ~content_visibility? : CssContentVisibility, - ~filter? : CssFilter, - ~object_fit? : CssObjectFit + border_radius? : Float, + padding_top? : CssSize, + padding_bottom? : CssSize, + padding_left? : CssSize, + padding_right? : CssSize, + min_width? : CssSize, + max_width? : CssSize, + vertical_align? : CssVerticalAlign, + border_style? : CssBorderStyle, + border_color? : CssColor, + border_width? : CssSize, + cursor? : CssCursor, + transition_duration? : CssDuration, + transform? : CssTransform, + outline? : CssOutline, + user_select? : CssUserSelect, + margin_top? : CssSize, + margin_bottom? : CssSize, + margin_left? : CssSize, + margin_right? : CssSize, + max_height? : CssSize, + transform_property? : Array[String], + gap? : CssSize, + content? : String, + content_visibility? : CssContentVisibility, + filter? : CssFilter, + object_fit? : CssObjectFit ) -> RespoStyle { let style : Array[(String, String)] = [] match color { @@ -380,7 +380,7 @@ pub fn respo_style( RespoStyle(style) } -pub enum CssOutline { +pub(all) enum CssOutline { None Outline(CssSize, CssBorderStyle, CssColor) } derive(Eq) @@ -393,7 +393,7 @@ pub fn CssOutline::to_string(self : CssOutline) -> String { } } -pub enum CssDuration { +pub(all) enum CssDuration { Ms(Int) S(Float) } @@ -405,7 +405,7 @@ pub fn CssDuration::to_string(self : CssDuration) -> String { } } -pub enum CssUserSelect { +pub(all) enum CssUserSelect { None Text All @@ -421,7 +421,7 @@ pub fn CssUserSelect::to_string(self : CssUserSelect) -> String { } } -pub enum CssPosition { +pub(all) enum CssPosition { Static Relative Absolute @@ -439,7 +439,7 @@ pub fn CssPosition::to_string(self : CssPosition) -> String { } } -pub enum CssColor { +pub(all) enum CssColor { Hsla(UInt, UInt, UInt, Float) Hsl(UInt, UInt, UInt) Hsluva(UInt, UInt, UInt, Float) @@ -483,7 +483,7 @@ pub fn CssColor::to_string(self : CssColor) -> String { } } -pub enum CssLineHeight { +pub(all) enum CssLineHeight { Em(Float) Px(Float) Percent(Float) @@ -499,7 +499,7 @@ pub fn CssLineHeight::to_string(self : CssLineHeight) -> String { } } -pub enum CssWordBreak { +pub(all) enum CssWordBreak { Normal BreakAll KeepAll @@ -515,7 +515,7 @@ pub fn CssWordBreak::to_string(self : CssWordBreak) -> String { } } -pub enum CssDisplay { +pub(all) enum CssDisplay { Block Inline InlineBlock @@ -539,7 +539,7 @@ pub fn CssDisplay::to_string(self : CssDisplay) -> String { } } -pub enum CssFlexWrap { +pub(all) enum CssFlexWrap { Wrap Nowrap WrapReverse @@ -553,7 +553,7 @@ pub fn CssFlexWrap::to_string(self : CssFlexWrap) -> String { } } -pub enum CssFlexDirection { +pub(all) enum CssFlexDirection { Row RowReverse Column @@ -569,7 +569,7 @@ pub fn CssFlexDirection::to_string(self : CssFlexDirection) -> String { } } -pub enum CssVerticalAlign { +pub(all) enum CssVerticalAlign { Top Middle Bottom @@ -583,7 +583,7 @@ pub fn CssVerticalAlign::to_string(self : CssVerticalAlign) -> String { } } -pub enum CssFlexJustifyContent { +pub(all) enum CssFlexJustifyContent { FlexStart FlexEnd Center @@ -603,7 +603,7 @@ pub fn CssFlexJustifyContent::to_string(self : CssFlexJustifyContent) -> String } } -pub enum CssFlexAlignItems { +pub(all) enum CssFlexAlignItems { FlexStart FlexEnd Center @@ -621,7 +621,7 @@ pub fn CssFlexAlignItems::to_string(self : CssFlexAlignItems) -> String { } } -pub enum CssFlexAlignContent { +pub(all) enum CssFlexAlignContent { FlexStart FlexEnd Center @@ -641,7 +641,7 @@ pub fn CssFlexAlignContent::to_string(self : CssFlexAlignContent) -> String { } } -pub enum CssBorderStyle { +pub(all) enum CssBorderStyle { Solid Dashed Dotted @@ -655,7 +655,7 @@ pub fn CssBorderStyle::to_string(self : CssBorderStyle) -> String { } } -pub type CssBorder (Float, CssBorderStyle, CssColor) +pub(all) type CssBorder (Float, CssBorderStyle, CssColor) pub fn to_string(self : CssBorder) -> String { let (width, style, color) = self._ @@ -663,14 +663,14 @@ pub fn to_string(self : CssBorder) -> String { } pub fn CssBorder::new( - ~width : Float = 1.0, - ~style : CssBorderStyle = Solid, - ~color : CssColor = Black + width~ : Float = 1.0, + style~ : CssBorderStyle = Solid, + color~ : CssColor = Black ) -> CssBorder { (width, style, color) } -pub enum CssBackgroundSize { +pub(all) enum CssBackgroundSize { Cover Contain Wh(UInt, UInt) @@ -684,7 +684,7 @@ pub fn CssBackgroundSize::to_string(self : CssBackgroundSize) -> String { } } -pub enum CssOverflow { +pub(all) enum CssOverflow { Visible Hidden Scroll @@ -700,7 +700,7 @@ pub fn CssOverflow::to_string(self : CssOverflow) -> String { } } -pub enum CssTransform { +pub(all) enum CssTransform { Translate(Int, Int) TranslateX(Int) TranslateY(Int) @@ -722,7 +722,7 @@ pub fn CssTransform::to_string(self : CssTransform) -> String { } } -pub enum CssTimingFunction { +pub(all) enum CssTimingFunction { Ease Linear EaseIn @@ -744,7 +744,7 @@ pub fn CssTimingFunction::to_string(self : CssTimingFunction) -> String { } } -pub enum CssTextOverflow { +pub(all) enum CssTextOverflow { Clip Ellipsis } derive(Eq) @@ -756,7 +756,7 @@ pub fn CssTextOverflow::to_string(self : CssTextOverflow) -> String { } } -pub enum CssBoxSizing { +pub(all) enum CssBoxSizing { BorderBox ContentBox } derive(Eq) @@ -768,7 +768,7 @@ pub fn CssBoxSizing::to_string(self : CssBoxSizing) -> String { } } -pub enum CssTextAlign { +pub(all) enum CssTextAlign { Left Right Center @@ -784,7 +784,7 @@ pub fn CssTextAlign::to_string(self : CssTextAlign) -> String { } } -pub enum CssFontWeight { +pub(all) enum CssFontWeight { Normal Bold Bolder @@ -802,7 +802,7 @@ pub fn CssFontWeight::to_string(self : CssFontWeight) -> String { } } -pub enum CssTextDecoration { +pub(all) enum CssTextDecoration { None Underline Overline @@ -818,7 +818,7 @@ pub fn CssTextDecoration::to_string(self : CssTextDecoration) -> String { } } -pub enum CssCursor { +pub(all) enum CssCursor { Auto Default None @@ -898,7 +898,7 @@ pub fn CssCursor::to_string(self : CssCursor) -> String { } } -pub enum CssContentVisibility { +pub(all) enum CssContentVisibility { Visible Hidden Auto @@ -913,7 +913,7 @@ pub fn CssContentVisibility::to_string(self : CssContentVisibility) -> String { } /// https://developer.mozilla.org/en-US/docs/Web/CSS/filter -pub enum CssFilter { +pub(all) enum CssFilter { None Blur(Float) Brightness(Float) @@ -950,7 +950,7 @@ pub fn CssFilter::to_string(self : CssFilter) -> String { } } -pub enum CssObjectFit { +pub(all) enum CssObjectFit { Fill Contain Cover @@ -985,7 +985,7 @@ let class_name_in_tags : @hashset.T[String] = @hashset.new() /// Moonbit version, use [T] for for generics, GC language no need to use to_owned() and & pub fn declare_static_style[U : Show]( rules : Array[(U, RespoStyle)], - ~loc : SourceLoc = _ + loc~ : SourceLoc = _ ) -> String { // @dom_ffi.warn_log("SourceLoc" + loc.to_string()) let gen_name = loc diff --git a/src/lib/node/diff.mbt b/src/lib/node/diff.mbt index 7bb2112..23a8051 100644 --- a/src/lib/node/diff.mbt +++ b/src/lib/node/diff.mbt @@ -27,14 +27,14 @@ pub fn diff_tree[T]( if skipped.size() < effects.length() { changes.val.push( Effect( - ~coord, - ~dom_path, + coord~, + dom_path~, effect_type=BeforeUpdate, skip_indexes=skipped, ), ) changes.val.push( - Effect(~coord, ~dom_path, effect_type=Updated, skip_indexes=skipped), + Effect(coord~, dom_path~, effect_type=Updated, skip_indexes=skipped), ) } } else { @@ -46,7 +46,7 @@ pub fn diff_tree[T]( changes, ) // crate::util::log!("compare elements: {:?} {:?}", new_child, old_child); - changes.val.push(ReplaceElement(~coord, ~dom_path, node=new_child)) + changes.val.push(ReplaceElement(coord~, dom_path~, node=new_child)) collect_effects_outside_in_as!( new_tree, coord, @@ -64,7 +64,7 @@ pub fn diff_tree[T]( BeforeUnmount, changes, ) - changes.val.push(ReplaceElement(~coord, ~dom_path, node=a)) + changes.val.push(ReplaceElement(coord~, dom_path~, node=a)) collect_effects_outside_in_as!( new_tree, coord, @@ -81,7 +81,7 @@ pub fn diff_tree[T]( BeforeUnmount, changes, ) - changes.val.push(ReplaceElement(~coord, ~dom_path, node=a)) + changes.val.push(ReplaceElement(coord~, dom_path~, node=a)) collect_effects_outside_in_as!( new_tree, coord, @@ -107,7 +107,7 @@ pub fn diff_tree[T]( BeforeUnmount, changes, ) - changes.val.push(ReplaceElement(~coord, ~dom_path, node=a)) + changes.val.push(ReplaceElement(coord~, dom_path~, node=a)) collect_effects_outside_in_as!( new_tree, coord, @@ -173,7 +173,7 @@ fn diff_attrs[T]( } } if not(added.is_empty()) || not(removed.is_empty()) { - changes.val.push(ModifyAttrs(~coord, ~dom_path, set=added, unset=removed)) + changes.val.push(ModifyAttrs(coord~, dom_path~, set=added, unset=removed)) } } @@ -208,7 +208,7 @@ fn diff_style[T]( } } if not(added.is_empty()) || not(removed.is_empty()) { - changes.val.push(ModifyStyle(~coord, ~dom_path, set=added, unset=removed)) + changes.val.push(ModifyStyle(coord~, dom_path~, set=added, unset=removed)) } } @@ -228,8 +228,8 @@ fn diff_event[T, U]( if hashset_eq(new_keys, old_keys).not() { changes.val.push( ModifyEvent( - ~coord, - ~dom_path, + coord~, + dom_path~, add=new_keys.difference(old_keys), remove=old_keys.difference(new_keys), ), @@ -253,7 +253,7 @@ fn diff_children[T]( if old_tracking_pointer >= old_children.length() { if not(operations.val.is_empty()) { changes.val.push( - ModifyChildren(~coord, ~dom_path, operations=operations.val), + ModifyChildren(coord~, dom_path~, operations=operations.val), ) } return @@ -378,7 +378,7 @@ pub fn collect_effects_outside_in_as[T]( let { name, effects, tree } = left if not(effects.is_empty()) { changes.val.push( - Effect(~coord, ~dom_path, ~effect_type, skip_indexes=@hashset.new()), + Effect(coord~, dom_path~, effect_type~, skip_indexes=@hashset.new()), ) } let next_coord = coord.copy() @@ -421,7 +421,7 @@ pub fn collect_effects_inside_out_as[T]( ) if not(effects.is_empty()) { changes.val.push( - Effect(~coord, ~dom_path, ~effect_type, skip_indexes=@hashset.new()), + Effect(coord~, dom_path~, effect_type~, skip_indexes=@hashset.new()), ) } } @@ -459,7 +459,7 @@ fn nested_effects_outside_in_as[T]( NestedEffect( nested_coord=coord, nested_dom_path=dom_path, - ~effect_type, + effect_type~, skip_indexes=@hashset.new(), ), ) @@ -505,7 +505,7 @@ fn nested_effects_inside_out_as[T]( NestedEffect( nested_coord=coord, nested_dom_path=dom_path, - ~effect_type, + effect_type~, skip_indexes=@hashset.new(), ), ) diff --git a/src/lib/node/dom-change.mbt b/src/lib/node/dom-change.mbt index a3025f2..2e7c04e 100644 --- a/src/lib/node/dom-change.mbt +++ b/src/lib/node/dom-change.mbt @@ -1,5 +1,5 @@ /// coord of on virtual dom -pub enum RespoCoord { +pub(all) enum RespoCoord { Key(RespoIndexKey) Comp(String) } @@ -21,38 +21,38 @@ pub fn output(self : RespoCoord, logger : Logger) -> Unit { /// Diff/patch for virtual DOM, note that children are not included in this type enum DomChange[T] { ReplaceElement( - ~coord : Array[RespoCoord], - ~dom_path : Array[UInt], - ~node : RespoNode[T] + coord~ : Array[RespoCoord], + dom_path~ : Array[UInt], + node~ : RespoNode[T] ) ModifyChildren( - ~coord : Array[RespoCoord], - ~dom_path : Array[UInt], - ~operations : Array[ChildDomOp[T]] + coord~ : Array[RespoCoord], + dom_path~ : Array[UInt], + operations~ : Array[ChildDomOp[T]] ) ModifyAttrs( - ~coord : Array[RespoCoord], - ~dom_path : Array[UInt], - ~set : Map[String, String], - ~unset : @hashset.T[String] + coord~ : Array[RespoCoord], + dom_path~ : Array[UInt], + set~ : Map[String, String], + unset~ : @hashset.T[String] ) ModifyStyle( - ~coord : Array[RespoCoord], - ~dom_path : Array[UInt], - ~set : Map[String, String], - ~unset : @hashset.T[String] + coord~ : Array[RespoCoord], + dom_path~ : Array[UInt], + set~ : Map[String, String], + unset~ : @hashset.T[String] ) ModifyEvent( - ~coord : Array[RespoCoord], - ~dom_path : Array[UInt], - ~add : @hashset.T[RespoEventType], - ~remove : @hashset.T[RespoEventType] + coord~ : Array[RespoCoord], + dom_path~ : Array[UInt], + add~ : @hashset.T[RespoEventType], + remove~ : @hashset.T[RespoEventType] ) Effect( - ~coord : Array[RespoCoord], - ~dom_path : Array[UInt], - ~effect_type : RespoEffectType, - ~skip_indexes : @hashset.T[Int] + coord~ : Array[RespoCoord], + dom_path~ : Array[UInt], + effect_type~ : RespoEffectType, + skip_indexes~ : @hashset.T[Int] ) } @@ -62,7 +62,7 @@ impl[T] Show for DomChange[T] with output(self, logger) { fn DomChange::to_string[T](self : DomChange[T]) -> String { match self { - ReplaceElement(~coord, ~dom_path, ~node) => + ReplaceElement(coord~, dom_path~, node~) => str_spaced( wrap_parens=true, [ @@ -71,7 +71,7 @@ fn DomChange::to_string[T](self : DomChange[T]) -> String { node.to_string(), ], ) - ModifyChildren(~coord, ~dom_path, ~operations) => + ModifyChildren(coord~, dom_path~, operations~) => str_spaced( wrap_parens=true, [ @@ -80,7 +80,7 @@ fn DomChange::to_string[T](self : DomChange[T]) -> String { operations.to_string(), ], ) - ModifyAttrs(~coord, ~dom_path, ~set, ~unset) => + ModifyAttrs(coord~, dom_path~, set~, unset~) => str_spaced( wrap_parens=true, [ @@ -90,7 +90,7 @@ fn DomChange::to_string[T](self : DomChange[T]) -> String { unset.to_string(), ], ) - ModifyStyle(~coord, ~dom_path, ~set, ~unset) => + ModifyStyle(coord~, dom_path~, set~, unset~) => str_spaced( wrap_parens=true, [ @@ -100,7 +100,7 @@ fn DomChange::to_string[T](self : DomChange[T]) -> String { unset.to_string(), ], ) - ModifyEvent(~coord, ~dom_path, ~add, ~remove) => + ModifyEvent(coord~, dom_path~, add~, remove~) => str_spaced( [ "(ModifyEvent " + coord.to_string(), @@ -109,7 +109,7 @@ fn DomChange::to_string[T](self : DomChange[T]) -> String { remove.to_string() + ")", ], ) - Effect(~coord, ~dom_path, ~effect_type, ~skip_indexes) => + Effect(coord~, dom_path~, effect_type~, skip_indexes~) => str_spaced( wrap_parens=true, [ @@ -124,7 +124,7 @@ fn DomChange::to_string[T](self : DomChange[T]) -> String { pub fn to_cirru[T](self : DomChange[T]) -> @cirru.Cirru { match self { - Effect(~coord, ~dom_path, ~effect_type, ~skip_indexes) => + Effect(coord~, dom_path~, effect_type~, skip_indexes~) => @cirru.List( [ @cirru.Leaf("::effect"), @@ -134,7 +134,7 @@ pub fn to_cirru[T](self : DomChange[T]) -> @cirru.Cirru { indexes_to_cirru(skip_indexes), ], ) - ReplaceElement(~coord, ~dom_path, ~node) => + ReplaceElement(coord~, dom_path~, node~) => @cirru.List( [ @cirru.Leaf("::replace-element"), @@ -143,7 +143,7 @@ pub fn to_cirru[T](self : DomChange[T]) -> @cirru.Cirru { node.to_cirru(), ], ) - ModifyChildren(~coord, ~dom_path, ~operations) => + ModifyChildren(coord~, dom_path~, operations~) => @cirru.List( [ @cirru.Leaf("::modify-children"), @@ -152,7 +152,7 @@ pub fn to_cirru[T](self : DomChange[T]) -> @cirru.Cirru { @cirru.List(operations.map(fn(x) { x.to_cirru() })), ], ) - ModifyAttrs(~coord, ~dom_path, ~set, ~unset) => { + ModifyAttrs(coord~, dom_path~, set~, unset~) => { let set_data : Array[@cirru.Cirru] = [] for pair in set { let (key, value) = pair @@ -171,7 +171,7 @@ pub fn to_cirru[T](self : DomChange[T]) -> @cirru.Cirru { ], ) } - ModifyStyle(~coord, ~dom_path, ~set, ~unset) => { + ModifyStyle(coord~, dom_path~, set~, unset~) => { let set_data : Array[@cirru.Cirru] = [] for pair in set { let (key, value) = pair @@ -190,7 +190,7 @@ pub fn to_cirru[T](self : DomChange[T]) -> @cirru.Cirru { ], ) } - ModifyEvent(~coord, ~dom_path, ~add, ~remove) => { + ModifyEvent(coord~, dom_path~, add~, remove~) => { let add_data : Array[@cirru.Cirru] = [] for event in add { add_data.push(event.to_cirru()) @@ -217,10 +217,10 @@ enum ChildDomOp[T] { Append(RespoIndexKey, RespoNode[T]) Prepend(RespoIndexKey, RespoNode[T]) NestedEffect( - ~nested_coord : Array[RespoCoord], - ~nested_dom_path : Array[UInt], - ~effect_type : RespoEffectType, - ~skip_indexes : @hashset.T[Int] + nested_coord~ : Array[RespoCoord], + nested_dom_path~ : Array[UInt], + effect_type~ : RespoEffectType, + skip_indexes~ : @hashset.T[Int] ) } @@ -243,7 +243,7 @@ fn ChildDomOp::to_string[T](self : ChildDomOp[T]) -> String { str_spaced(["(Append " + key.to_string(), node.to_string() + ")"]) Prepend(key, node) => str_spaced(["(Prepend " + key.to_string(), node.to_string() + ")"]) - NestedEffect(~nested_coord, ~nested_dom_path, ~effect_type, ~skip_indexes) => + NestedEffect(nested_coord~, nested_dom_path~, effect_type~, skip_indexes~) => str_spaced( [ "(NestedEffect " + nested_coord.to_string(), @@ -272,7 +272,7 @@ pub fn to_cirru[T](self : ChildDomOp[T]) -> @cirru.Cirru { @cirru.List([@cirru.Leaf("::append"), key.to_cirru(), node.to_cirru()]) Prepend(key, node) => @cirru.List([@cirru.Leaf("::prepend"), key.to_cirru(), node.to_cirru()]) - NestedEffect(~nested_coord, ~nested_dom_path, ~effect_type, ~skip_indexes) => + NestedEffect(nested_coord~, nested_dom_path~, effect_type~, skip_indexes~) => @cirru.List( [ @cirru.Leaf("::nested-effect"), @@ -287,12 +287,12 @@ pub fn to_cirru[T](self : ChildDomOp[T]) -> @cirru.Cirru { pub fn get_dom_path[T](self : DomChange[T]) -> Array[UInt] { match self { - ReplaceElement(~dom_path, ..) => dom_path - ModifyChildren(~dom_path, ..) => dom_path - ModifyAttrs(~dom_path, ..) => dom_path - ModifyStyle(~dom_path, ..) => dom_path - ModifyEvent(~dom_path, ..) => dom_path - Effect(~dom_path, ..) => dom_path + ReplaceElement(dom_path~, ..) => dom_path + ModifyChildren(dom_path~, ..) => dom_path + ModifyAttrs(dom_path~, ..) => dom_path + ModifyStyle(dom_path~, ..) => dom_path + ModifyEvent(dom_path~, ..) => dom_path + Effect(dom_path~, ..) => dom_path } } diff --git a/src/lib/node/effect.mbt b/src/lib/node/effect.mbt index 8e01b20..81149f2 100644 --- a/src/lib/node/effect.mbt +++ b/src/lib/node/effect.mbt @@ -4,7 +4,7 @@ // // def derive: RespoEffectBox // } -pub struct RespoEffectBox { +pub(all) struct RespoEffectBox { args : Json /// third argument `at_place` is not implemented yet handler : (RespoEffectType, @dom_ffi.Node) -> Unit @@ -57,7 +57,7 @@ pub fn op_equal(self : RespoEffectBox, b : RespoEffectBox) -> Bool { } /// currently only support `Mounted`, `BeforeUpdate`, `Updated`, `BeforeUnmount` -pub enum RespoEffectType { +pub(all) enum RespoEffectType { Mounted BeforeUpdate Updated diff --git a/src/lib/node/element.mbt b/src/lib/node/element.mbt index 4538604..b01a4b2 100644 --- a/src/lib/node/element.mbt +++ b/src/lib/node/element.mbt @@ -1,4 +1,4 @@ -pub type RespoIndexKey String derive(Eq) +pub(all) type RespoIndexKey String derive(Eq) pub fn to_cirru(self : RespoIndexKey) -> @cirru.Cirru { Leaf(self._) @@ -9,7 +9,7 @@ pub fn to_string(self : RespoIndexKey) -> String { } /// internal abstraction for an element -pub struct RespoElement[T] { +pub(all) struct RespoElement[T] { /// tagName name : String attrs : Map[String, String] @@ -71,31 +71,31 @@ pub fn set_attribute[T]( // TODO implement methods for RespoElement pub fn respo_attrs( - ~id? : String, - ~class_name? : String, + id? : String, + class_name? : String, // ~style? : RespoStyle, - ~hidden? : Bool, - ~disabled? : Bool, - ~value? : String, - ~src? : String, - ~href? : String, - ~alt? : String, - ~title? : String, - ~placeholder? : String, + hidden? : Bool, + disabled? : Bool, + value? : String, + src? : String, + href? : String, + alt? : String, + title? : String, + placeholder? : String, /// actually type - ~type_? : String, - ~name? : String, - ~checked? : Bool, - ~selected? : Bool, - ~read_only? : Bool, - ~max_length? : Int, - ~min_length? : Int, - ~tab_index? : Int, - ~content_editable? : Bool, - ~width? : String, - ~height? : String, - ~inner_text? : String, - ~innerHTML? : String + type_? : String, + name? : String, + checked? : Bool, + selected? : Bool, + read_only? : Bool, + max_length? : Int, + min_length? : Int, + tab_index? : Int, + content_editable? : Bool, + width? : String, + height? : String, + inner_text? : String, + innerHTML? : String ) -> Map[String, String] { let result = {} match id { diff --git a/src/lib/node/listener.mbt b/src/lib/node/listener.mbt index 7d0726d..5aa2050 100644 --- a/src/lib/node/listener.mbt +++ b/src/lib/node/listener.mbt @@ -1,21 +1,21 @@ /// wraps some basic event types -pub enum RespoEvent { +pub(all) enum RespoEvent { Click( - ~client_x : Float, - ~client_y : Float, - ~original_event : @dom_ffi.MouseEvent + client_x~ : Float, + client_y~ : Float, + original_event~ : @dom_ffi.MouseEvent ) Keyboard( - ~key : String, - ~key_code : UInt, - ~shift_key : Bool, - ~ctrl_key : Bool, - ~alt_key : Bool, - ~meta_key : Bool, - ~repeat : Bool, - ~original_event : @dom_ffi.KeyboardEvent + key~ : String, + key_code~ : UInt, + shift_key~ : Bool, + ctrl_key~ : Bool, + alt_key~ : Bool, + meta_key~ : Bool, + repeat~ : Bool, + original_event~ : @dom_ffi.KeyboardEvent ) - Input(~value : String, ~original_event : @dom_ffi.InputEvent) + Input(value~ : String, original_event~ : @dom_ffi.InputEvent) Focus(@dom_ffi.FocusEvent) Blur(@dom_ffi.BlurEvent) } @@ -30,13 +30,13 @@ pub fn to_string(self : RespoEvent) -> String { } } -pub struct RespoEventMark { +pub(all) struct RespoEventMark { coord : Array[RespoCoord] name : RespoEventType event_info : RespoEvent } -pub enum RespoEventType { +pub(all) enum RespoEventType { Click DblClick Changle diff --git a/src/lib/node/node.mbt b/src/lib/node/node.mbt index 99eaa12..8d45cb7 100644 --- a/src/lib/node/node.mbt +++ b/src/lib/node/node.mbt @@ -1,4 +1,4 @@ -pub enum RespoNode[T] { +pub(all) enum RespoNode[T] { Component(RespoComponent[T]) Element(RespoElement[T]) } @@ -26,7 +26,7 @@ pub fn to_cirru[T](self : RespoNode[T]) -> @cirru.Cirru { } /// currently it's commonly used for all errors in Respo -pub type! RespoCommonError String +pub(all) type! RespoCommonError String pub fn to_string(self : RespoCommonError) -> String { match self { @@ -156,7 +156,7 @@ pub fn build_dom_tree[T]( } } -pub type DispatchFn[T] (T) -> Unit!RespoCommonError +pub(all) type DispatchFn[T] (T) -> Unit!RespoCommonError pub fn DispatchFn::to_string[T](self : DispatchFn[T]) -> String { "(DispatchFn \{self})" diff --git a/src/lib/node/patch.mbt b/src/lib/node/patch.mbt index d0b9933..eb4b57e 100644 --- a/src/lib/node/patch.mbt +++ b/src/lib/node/patch.mbt @@ -18,7 +18,7 @@ pub fn patch_tree[T]( // handle BeforeUpdate before DOM changes for op in changes { match op { - Effect(~coord, ~effect_type, ~skip_indexes, ..) => + Effect(coord~, effect_type~, skip_indexes~, ..) => if effect_type == BeforeUpdate { let target = find_coord_dom_target!( mount_target.first_child(), @@ -57,7 +57,7 @@ pub fn patch_tree[T]( op.get_dom_path(), ) match op { - ModifyAttrs(~set, ~unset, ..) => { + ModifyAttrs(set~, unset~, ..) => { let el = target.reinterpret_as_element() for pair in set { let (k, v) = pair @@ -109,7 +109,7 @@ pub fn patch_tree[T]( } } } - ModifyStyle(~set, ~unset, ..) => { + ModifyStyle(set~, unset~, ..) => { let style = target.style() for s in unset { style.remove_property(s) @@ -119,7 +119,7 @@ pub fn patch_tree[T]( style.set_property(k, v) } } - ModifyEvent(~add, ~remove, ~coord, ..) => { + ModifyEvent(add~, remove~, coord~, ..) => { let el = target.reinterpret_as_element() for k in add.iter() { attach_event!(el, k, coord, handle_event) @@ -132,13 +132,13 @@ pub fn patch_tree[T]( } } } - ReplaceElement(~node, ~coord, ..) => { + ReplaceElement(node~, coord~, ..) => { let parent = target.parent_element() let new_element = build_dom_tree!(node, coord, handle_event) parent.insert_before(new_element, target) target.remove() } - ModifyChildren(~operations, ~coord, ..) => { + ModifyChildren(operations~, coord~, ..) => { let base_tree = load_coord_target_tree!(tree, coord[:]) let old_base_tree = load_coord_target_tree!(old_tree, coord[:]) for op in operations { @@ -196,10 +196,10 @@ pub fn patch_tree[T]( } } NestedEffect( - ~nested_coord, + nested_coord~, nested_dom_path=nesteed_dom_path, - ~effect_type, - ~skip_indexes + effect_type~, + skip_indexes~ ) => { let target_tree = if effect_type == BeforeUnmount { load_coord_target_tree!(old_base_tree, nested_coord[:]) @@ -224,7 +224,7 @@ pub fn patch_tree[T]( } } } - Effect(~coord, ~effect_type, ~skip_indexes, ..) => { + Effect(coord~, effect_type~, skip_indexes~, ..) => { if effect_type == BeforeUpdate { // should be handled before current pass continue @@ -321,7 +321,7 @@ pub fn attach_event( // TODO Error return } - let wrap_event = RespoEvent::Input(~value, original_event=e) + let wrap_event = RespoEvent::Input(value~, original_event=e) let ret = handle_event?({ coord, name: Input, event_info: wrap_event }) match ret { Ok(_) => () diff --git a/src/lib/node/util.mbt b/src/lib/node/util.mbt index 4cd4161..2b36b6d 100644 --- a/src/lib/node/util.mbt +++ b/src/lib/node/util.mbt @@ -31,7 +31,7 @@ pub fn raf_loop(f : (Float) -> Unit!RespoCommonError) -> Unit { /// convert a list of strings to a single string with spaces between them, /// mainly used for concatenating class names -pub fn str_spaced(~wrap_parens : Bool = false, s : Array[String]) -> String { +pub fn str_spaced(wrap_parens~ : Bool = false, s : Array[String]) -> String { let mut ret = "" for idx, piece in s.iter2() { if idx > 0 { diff --git a/src/lib/states-tree.mbt b/src/lib/states-tree.mbt index 1768f82..a8f8e50 100644 --- a/src/lib/states-tree.mbt +++ b/src/lib/states-tree.mbt @@ -3,7 +3,7 @@ /// Respo maintains states in a tree structure, where the keys are strings, /// each child component "picks" a key to attach its own state to the tree, /// and it dispatches events to global store to update the state. -pub struct RespoStatesTree { +pub(all) struct RespoStatesTree { /// component local data is dynamically typed. we may switch to trait object if supported in the future mut data : @json.JsonValue? // mut backup : @json.JsonValue? @@ -143,7 +143,7 @@ pub fn set_in_mut(self : RespoStatesTree, change : RespoUpdateState) -> Unit { // type RespoStateBranch Json /// framework defined action for updating states branch -pub struct RespoUpdateState { +pub(all) struct RespoUpdateState { /// path to the state cursor : Array[String] /// dyn eq data diff --git a/src/main/counter.mbt b/src/main/counter.mbt index 33f786c..91bcbd5 100644 --- a/src/main/counter.mbt +++ b/src/main/counter.mbt @@ -16,7 +16,7 @@ fn comp_counter( ) -> Unit!@respo_node.RespoCommonError { @dom_ffi.warn_log("inc click: " + e.to_string()) match e { - Click(~original_event, ..) => original_event.prevent_default() + Click(original_event~, ..) => original_event.prevent_default() _ => () } dispatch.run!(Increment) diff --git a/src/main/panel.mbt b/src/main/panel.mbt index 19f0f66..2f1ef32 100644 --- a/src/main/panel.mbt +++ b/src/main/panel.mbt @@ -31,7 +31,7 @@ fn comp_panel( // dispatch.run_state(&cursor, PanelState { content: value })?; // } match e { - Input(~value, ..) => + Input(value~, ..) => dispatch.run!( StatesChange({ cursor, data: Some({ content: value }.to_json()) }), ) diff --git a/src/main/task.mbt b/src/main/task.mbt index 327eeeb..81141df 100644 --- a/src/main/task.mbt +++ b/src/main/task.mbt @@ -38,7 +38,7 @@ fn comp_task( // } match e { - Input(~value, ..) => + Input(value~, ..) => dispatch.run!( StatesChange({ cursor, data: Some({ draft: value }.to_json()) }), )