Current section
Files
Jump to
Current section
Files
src/gbr@ui@core@el.erl
-module(gbr@ui@core@el).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\gbr\\ui\\core\\el.gleam").
-export([id/2, get_id/1, att_key/3, att/2, att_get_key/3, att_any_key/3, att_any/2, class_key/3, class/2, classes_key/3, classes/2, get_classes_key/3, get_classes/2, style_key/3, style/2, attrs_key/2, attrs/1, new/1]).
-export_type([u_i_el/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
"\n"
" Gleam UI super element\n"
"\n"
" ## Motivation\n"
"\n"
" The lustre elements contains the generic event type that difficult to work\n"
" with element in stateless mode.\n"
"\n"
" So, the `gbr/ui/core/el` module has types and functions to work with\n"
" attributes and properties without needs to trait genenric event type.\n"
"\n"
).
-opaque u_i_el() :: {u_i_el,
binary(),
gleam@dict:dict(binary(), list({binary(), boolean()})),
gleam@dict:dict(binary(), list({binary(), binary()})),
gleam@dict:dict(binary(), list({binary(), binary()}))}.
-file("src\\gbr\\ui\\core\\el.gleam", 113).
?DOC(
" Replace id element\n"
"\n"
" - el: Element info\n"
" - id: `lustre.attribute.id`\n"
).
-spec id(u_i_el(), binary()) -> u_i_el().
id(El, Id) ->
{u_i_el,
Id,
erlang:element(3, El),
erlang:element(4, El),
erlang:element(5, El)}.
-file("src\\gbr\\ui\\core\\el.gleam", 117).
-spec get_id(u_i_el()) -> binary().
get_id(El) ->
erlang:element(2, El).
-file("src\\gbr\\ui\\core\\el.gleam", 153).
?DOC(
" Append custom attributes\n"
"\n"
" - el: Element info\n"
" - key: Key identification\n"
" - att: Properties to set in key\n"
).
-spec att_key(u_i_el(), binary(), list({binary(), binary()})) -> u_i_el().
att_key(El, Key, Att) ->
Att_el = begin
_pipe = gleam_stdlib:map_get(
erlang:element(5, El),
erlang:element(2, El)
),
_pipe@1 = gleam@option:from_result(_pipe),
gleam@option:unwrap(_pipe@1, [])
end,
Att@1 = gleam@dict:insert(
erlang:element(5, El),
Key,
lists:append(Att_el, Att)
),
{u_i_el,
erlang:element(2, El),
erlang:element(3, El),
erlang:element(4, El),
Att@1}.
-file("src\\gbr\\ui\\core\\el.gleam", 143).
?DOC(
" Append list of custom attributes\n"
"\n"
" - el: Element info\n"
" - att: Properties to set in key\n"
"\n"
" Uses id like key to set custom attributes to element.\n"
"\n"
" - Equals att_key(el, el.id, value)\n"
).
-spec att(u_i_el(), list({binary(), binary()})) -> u_i_el().
att(El, Att) ->
att_key(El, erlang:element(2, El), Att).
-file("src\\gbr\\ui\\core\\el.gleam", 164).
-spec att_get_key(u_i_el(), binary(), binary()) -> gleam@option:option(binary()).
att_get_key(El, Key, Name) ->
_pipe = gleam_stdlib:map_get(erlang:element(5, El), Key),
_pipe@1 = gleam@option:from_result(_pipe),
_pipe@2 = gleam@option:unwrap(_pipe@1, []),
_pipe@3 = gleam@list:find(
_pipe@2,
fun(Att_el) ->
{Name_el, _} = Att_el,
Name =:= Name_el
end
),
_pipe@4 = gleam@option:from_result(_pipe@3),
gleam@option:map(_pipe@4, fun(Found) -> erlang:element(2, Found) end).
-file("src\\gbr\\ui\\core\\el.gleam", 181).
-spec att_any_key(u_i_el(), binary(), binary()) -> boolean().
att_any_key(El, Key, Name) ->
_pipe = gleam_stdlib:map_get(erlang:element(5, El), Key),
_pipe@1 = gleam@option:from_result(_pipe),
_pipe@2 = gleam@option:unwrap(_pipe@1, []),
gleam@list:any(
_pipe@2,
fun(Att_el) ->
{Name_el, _} = Att_el,
Name =:= Name_el
end
).
-file("src\\gbr\\ui\\core\\el.gleam", 177).
-spec att_any(u_i_el(), binary()) -> boolean().
att_any(El, Name) ->
att_any_key(El, erlang:element(2, El), Name).
-file("src\\gbr\\ui\\core\\el.gleam", 202).
-spec class_key(u_i_el(), binary(), binary()) -> u_i_el().
class_key(El, Key, Class) ->
att_key(El, Key, [{<<"class"/utf8>>, Class}]).
-file("src\\gbr\\ui\\core\\el.gleam", 198).
?DOC(
" Replace class attribute element\n"
"\n"
" Uses id like key to set class attribute\n"
"\n"
" - Equals class_key(el, el.id, value)\n"
).
-spec class(u_i_el(), binary()) -> u_i_el().
class(El, Class) ->
class_key(El, erlang:element(2, El), Class).
-file("src\\gbr\\ui\\core\\el.gleam", 222).
?DOC(
" Append classes attribute element\n"
"\n"
" - el: Element info\n"
" - key: Key identification\n"
" - classes: Properties `lustre.attribute.classes`\n"
).
-spec classes_key(u_i_el(), binary(), list({binary(), boolean()})) -> u_i_el().
classes_key(El, Key, Classes) ->
El_classes = begin
_pipe = gleam_stdlib:map_get(
erlang:element(3, El),
erlang:element(2, El)
),
_pipe@1 = gleam@option:from_result(_pipe),
gleam@option:unwrap(_pipe@1, [])
end,
Classes@1 = gleam@dict:insert(
erlang:element(3, El),
Key,
lists:append(El_classes, Classes)
),
{u_i_el,
erlang:element(2, El),
Classes@1,
erlang:element(4, El),
erlang:element(5, El)}.
-file("src\\gbr\\ui\\core\\el.gleam", 212).
?DOC(
" Append classes attribute element\n"
"\n"
" Uses id like key to set classes attribute\n"
"\n"
" - Equals classes_key(el, el.id, value)\n"
).
-spec classes(u_i_el(), list({binary(), boolean()})) -> u_i_el().
classes(El, Classes) ->
classes_key(El, erlang:element(2, El), Classes).
-file("src\\gbr\\ui\\core\\el.gleam", 237).
-spec get_classes_key(u_i_el(), binary(), binary()) -> gleam@option:option(boolean()).
get_classes_key(El, Key, Name) ->
_pipe = gleam_stdlib:map_get(erlang:element(3, El), Key),
_pipe@1 = gleam@option:from_result(_pipe),
_pipe@2 = gleam@option:unwrap(_pipe@1, []),
_pipe@3 = gleam@list:find(
_pipe@2,
fun(Classes_el) ->
{Name_el, _} = Classes_el,
Name =:= Name_el
end
),
_pipe@4 = gleam@option:from_result(_pipe@3),
gleam@option:map(_pipe@4, fun(Found) -> erlang:element(2, Found) end).
-file("src\\gbr\\ui\\core\\el.gleam", 233).
-spec get_classes(u_i_el(), binary()) -> gleam@option:option(boolean()).
get_classes(El, Name) ->
get_classes_key(El, erlang:element(2, El), Name).
-file("src\\gbr\\ui\\core\\el.gleam", 256).
?DOC(
" Append style attribute element\n"
"\n"
" - el: Element info\n"
" - key: Key identification\n"
" - styles: Properties `lustre.attribute.style`\n"
).
-spec style_key(u_i_el(), binary(), list({binary(), binary()})) -> u_i_el().
style_key(El, Key, Styles) ->
El_styles = begin
_pipe = gleam_stdlib:map_get(
erlang:element(4, El),
erlang:element(2, El)
),
_pipe@1 = gleam@option:from_result(_pipe),
gleam@option:unwrap(_pipe@1, [])
end,
Styles@1 = gleam@dict:insert(
erlang:element(4, El),
Key,
lists:append(El_styles, Styles)
),
{u_i_el,
erlang:element(2, El),
erlang:element(3, El),
Styles@1,
erlang:element(5, El)}.
-file("src\\gbr\\ui\\core\\el.gleam", 273).
?DOC(
" Replace style attribute element\n"
"\n"
" Uses id like key to set style attribute\n"
"\n"
" - Equals style_key(el, el.id, value)\n"
).
-spec style(u_i_el(), list({binary(), binary()})) -> u_i_el().
style(El, Styles) ->
style_key(El, erlang:element(2, El), Styles).
-file("src\\gbr\\ui\\core\\el.gleam", 320).
-spec map_atts(list({binary(), binary()})) -> list(lustre@vdom@vattr:attribute(any())).
map_atts(Att) ->
gleam@list:map(
Att,
fun(_use0) ->
{Name, Value} = _use0,
lustre@attribute:attribute(Name, Value)
end
).
-file("src\\gbr\\ui\\core\\el.gleam", 326).
-spec map_styles(list({binary(), binary()})) -> list(lustre@vdom@vattr:attribute(any())).
map_styles(Styles) ->
gleam@list:map(
Styles,
fun(_use0) ->
{Name, Value} = _use0,
lustre@attribute:style(Name, Value)
end
).
-file("src\\gbr\\ui\\core\\el.gleam", 292).
-spec attrs_key(u_i_el(), binary()) -> list(lustre@vdom@vattr:attribute(any())).
attrs_key(El, Key) ->
{u_i_el, Id, Classes, Styles, Att} = El,
Id@1 = lustre@attribute:id(Id),
Classes@1 = begin
_pipe = gleam_stdlib:map_get(Classes, Key),
_pipe@1 = gleam@option:from_result(_pipe),
_pipe@2 = gleam@option:map(_pipe@1, fun lustre@attribute:classes/1),
gleam@option:unwrap(_pipe@2, lustre@attribute:none())
end,
Styles@1 = begin
_pipe@3 = gleam_stdlib:map_get(Styles, Key),
_pipe@4 = gleam@option:from_result(_pipe@3),
_pipe@5 = gleam@option:map(_pipe@4, fun map_styles/1),
gleam@option:unwrap(_pipe@5, [])
end,
Att@1 = begin
_pipe@6 = gleam_stdlib:map_get(Att, Key),
_pipe@7 = gleam@option:from_result(_pipe@6),
_pipe@8 = gleam@option:map(_pipe@7, fun map_atts/1),
gleam@option:unwrap(_pipe@8, [])
end,
Attrs = lists:append(Att@1, Styles@1),
[Id@1, Classes@1 | Attrs].
-file("src\\gbr\\ui\\core\\el.gleam", 288).
?DOC(
" Convert to `lustre/attribute`s attributes by identification.\n"
"\n"
" - in: Element info to convert\n"
"\n"
" Precedence order attributes:\n"
" - id\n"
" - class\n"
" - classes\n"
" - style\n"
" - others in `att`\n"
).
-spec attrs(u_i_el()) -> list(lustre@vdom@vattr:attribute(any())).
attrs(El) ->
attrs_key(El, erlang:element(2, El)).
-file("src\\gbr\\ui\\core\\el.gleam", 334).
?DOC(" Random identification, avoid conflict.\n").
-spec random_str(binary()) -> binary().
random_str(Id) ->
Random = begin
_pipe = gleam@int:random(1000000),
erlang:integer_to_binary(_pipe)
end,
<<<<<<"gbr-ui-"/utf8, Random/binary>>/binary, "-"/utf8>>/binary, Id/binary>>.
-file("src\\gbr\\ui\\core\\el.gleam", 94).
?DOC(
" New super element with initial class styled\n"
"\n"
" - id: `lustre/attribute.id`\n"
"\n"
" Create dictonary and insert item with id element to represent\n"
" default custom attributes, classes, styles, etc of element.\n"
).
-spec new(binary()) -> u_i_el().
new(Id) ->
Att = begin
_pipe = maps:new(),
gleam@dict:insert(_pipe, Id, [])
end,
Classes = begin
_pipe@1 = maps:new(),
gleam@dict:insert(_pipe@1, Id, [])
end,
Styles = begin
_pipe@2 = maps:new(),
gleam@dict:insert(_pipe@2, Id, [])
end,
{u_i_el, random_str(Id), Classes, Styles, Att}.