From d4f98999cbcc99f9edea362747a0c6a77c692d9a Mon Sep 17 00:00:00 2001 From: abhimanyuaryan <8083613+AbhimanyuAryan@users.noreply.github.com> Date: Fri, 3 Feb 2023 11:20:19 +0530 Subject: [PATCH 1/3] chat component --- src/ChatMessages.jl | 15 +++++++++++++++ src/StippleUI.jl | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 src/ChatMessages.jl diff --git a/src/ChatMessages.jl b/src/ChatMessages.jl new file mode 100644 index 00000000..3ce565d1 --- /dev/null +++ b/src/ChatMessages.jl @@ -0,0 +1,15 @@ +module ChatMessages + +using Genie, Stipple, StippleUI, StippleUI.API +import Genie.Renderer.Html: HTMLString, normal_element, template, register_normal_element + +export chatmessage + +register_normal_element("q__chat__message", context = @__MODULE__) + +function chatmessage(text::Union{Symbol, String} = "", + args...; kwargs...) + q__chat__message(args...; kw([:text => text, kwargs...])...) +end + +end \ No newline at end of file diff --git a/src/StippleUI.jl b/src/StippleUI.jl index 6dfdb386..cd47036a 100644 --- a/src/StippleUI.jl +++ b/src/StippleUI.jl @@ -63,6 +63,7 @@ include("Banners.jl") include("BigNumbers.jl") include("Buttons.jl") include("Cards.jl") +include("ChatMessages.jl") include("Checkboxes.jl") include("Chips.jl") include("DatePickers.jl") @@ -118,6 +119,7 @@ export quasar, quasar_pure, vue, vue_pure, xelem, xelem_pure, @click, csscolors @reexport using .BigNumbers @reexport using .Buttons @reexport using .Cards +@reexport using .ChatMessages @reexport using .Checkboxes @reexport using .Chips @reexport using .DatePickers From fbffc4fe015a88ec29b5b974637177ea467e44dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Fri, 3 Feb 2023 09:08:31 +0100 Subject: [PATCH 2/3] fix handling of string arguments in chatmessage() --- src/ChatMessages.jl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ChatMessages.jl b/src/ChatMessages.jl index 3ce565d1..5b67fc75 100644 --- a/src/ChatMessages.jl +++ b/src/ChatMessages.jl @@ -7,8 +7,15 @@ export chatmessage register_normal_element("q__chat__message", context = @__MODULE__) -function chatmessage(text::Union{Symbol, String} = "", +function chatmessage(text::Union{Symbol, Vector{<:AbstractString}, AbstractString} = "", args...; kwargs...) + text = if text isa Symbol + text + elseif text isa String + Symbol("['$text']") + else + Symbol("['$(join(replace.(text, "'" => "\\'"), "', '"))']") + end q__chat__message(args...; kw([:text => text, kwargs...])...) end From 76a1058c5a067ac0a8e8e7d5c9ac1dc2cb1a220b Mon Sep 17 00:00:00 2001 From: Abhi <8083613+AbhimanyuAryan@users.noreply.github.com> Date: Sat, 4 Feb 2023 19:39:27 +0530 Subject: [PATCH 3/3] adding docs and bindings --- src/API.jl | 4 ++++ src/ChatMessages.jl | 49 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/src/API.jl b/src/API.jl index 598f501d..9a1412d5 100644 --- a/src/API.jl +++ b/src/API.jl @@ -69,6 +69,10 @@ const ATTRIBUTES_MAPPINGS = Dict{String,String}( "hidehint" => "hide-hint", "hideselected" => "hide-selected", "hideuploadbtn" => "hide-upload-btn", + "htmllabel" => "label-html", + "htmlname" => "name-html", + "htmlstamp" => "stamp-html", + "htmltext" => "text-html", "iconcolor" => "icon-color", "iconhalf" => "icon-half", "iconremove" => "icon-remove", diff --git a/src/ChatMessages.jl b/src/ChatMessages.jl index 5b67fc75..1d1f9601 100644 --- a/src/ChatMessages.jl +++ b/src/ChatMessages.jl @@ -7,6 +7,55 @@ export chatmessage register_normal_element("q__chat__message", context = @__MODULE__) +""" + chatmessage(text::Union{Symbol, Vector{<:AbstractString}, AbstractString} = "", args...; kwargs...) + +The `chatmessage` which is really a chat entry that renders the data given by the reactive model + +---------- +# Examples +---------- + +### Model + +```julia-repl +julia> @app begin + @out textmsg1 = ["hey, how are you?"] + @out textmsg2 = "I am good" + @out messages = Dict{Symbol, Any}[] + end +``` + +### View + +```julia-repl +julia> chatmessage("This is static text", name="stella", sent = true) +julia> chatmessage(:textmsg1, name="dave", sent = true) +julia> chatmessage(Symbol("[textmsg2]"), name="stella") +julia> chatmessage(R"message.text", name = R"message.name", sent = R"message.sent", "", @recur("message in messages")) +``` + +----------- +# Arguments +----------- + +1. Behaviour + * `htmllabel::Bool` - Render the label as HTML; This can lead to XSS attacks so make sure that you sanitize the message first + * `htmlname::Bool` - Render the name as HTML; This can lead to XSS attacks so make sure that you sanitize the message first + * `htmlstamp::Bool` - Render the text as HTML; This can lead to XSS attacks so make sure that you sanitize the message first + * `htmltext::Bool` - Render the stamp as HTML; This can lead to XSS attacks so make sure that you sanitize the message first +2. Content + * `send::Bool` - Render as a sent message (so from current user) + * `label::String` - Renders a label header/section only. Example `Friday, 18th` + * `name::String` - Author's name. Example `John Doe`. + * `avatar::String` - URL to the avatar image of the author. Example. `(public folder) src="boy-avatar.png"` | `(assets folder) src="~assets/boy-avatar.png"` | `(relative path format) :src="require('./my_img.jpg')"` | `(URL) src="https://placeimg.com/500/300/nature"` + * `text::Union{AbstractString, Vector{<:AbstractString}}` - Array of strings that are the message body. Strings are not sanitized (see details in docs) + * `stamp::String` - Creation timestamp. Example `13:55` `Yesterday at 13:51` +6. Style + * `bgcolor::String` - Color name (from the Quasar Color Palette) for chat bubble background + * `textcolor::String` - Color name (from the Quasar Color Palette) for chat bubble text + * `size::String` - 1-12 out of 12(same as col-*) +""" function chatmessage(text::Union{Symbol, Vector{<:AbstractString}, AbstractString} = "", args...; kwargs...) text = if text isa Symbol