Current section

Files

Jump to
json_canvas src json_canvas@node.erl
Raw

src/json_canvas@node.erl

-module(json_canvas@node).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([decode_node/1]).
-export_type([file_path/0, sub_path/0, url/0, group_label/0, group_background/0, node_/0]).
-type file_path() :: {file_path, binary()}.
-type sub_path() :: {sub_path, binary()}.
-type url() :: {url, binary()}.
-type group_label() :: {group_label, binary()}.
-type group_background() :: {group_background, binary()}.
-type node_() :: {text_node,
json_canvas@types:node_id(),
integer(),
integer(),
integer(),
integer(),
gleam@option:option(json_canvas@types:color()),
binary()} |
{file_node,
json_canvas@types:node_id(),
integer(),
integer(),
integer(),
integer(),
gleam@option:option(json_canvas@types:color()),
file_path(),
gleam@option:option(sub_path())} |
{link_node,
json_canvas@types:node_id(),
integer(),
integer(),
integer(),
integer(),
gleam@option:option(json_canvas@types:color()),
url()} |
{group_node,
json_canvas@types:node_id(),
integer(),
integer(),
integer(),
integer(),
gleam@option:option(json_canvas@types:color()),
gleam@option:option(group_label()),
gleam@option:option(group_background()),
gleam@option:option(json_canvas@node@group_background_style:group_background_style())}.
-spec decode_node(gleam@dynamic:dynamic_()) -> {ok, node_()} |
{error, list(gleam@dynamic:decode_error())}.
decode_node(Dyn) ->
gleam@result:'try'(
json_canvas@internal@generic_node:decode_node_attrs(Dyn),
fun(Attrs) -> case erlang:element(3, Attrs) of
text_node_type ->
gleam@result:'try'(
(gleam@dynamic:field(
<<"text"/utf8>>,
fun gleam@dynamic:string/1
))(Dyn),
fun(Text) ->
{ok,
{text_node,
erlang:element(2, Attrs),
erlang:element(4, Attrs),
erlang:element(5, Attrs),
erlang:element(6, Attrs),
erlang:element(7, Attrs),
erlang:element(8, Attrs),
Text}}
end
);
file_node_type ->
gleam@result:'try'(
begin
_pipe = Dyn,
(gleam@dynamic:decode2(
fun(Path, Subpath) -> {Path, Subpath} end,
gleam@dynamic:field(
<<"path"/utf8>>,
fun gleam@dynamic:string/1
),
gleam@dynamic:optional_field(
<<"subpath"/utf8>>,
fun gleam@dynamic:string/1
)
))(_pipe)
end,
fun(_use0) ->
{Path@1, Subpath@1} = _use0,
{ok,
{file_node,
erlang:element(2, Attrs),
erlang:element(4, Attrs),
erlang:element(5, Attrs),
erlang:element(6, Attrs),
erlang:element(7, Attrs),
erlang:element(8, Attrs),
{file_path, Path@1},
gleam@option:map(
Subpath@1,
fun(Field@0) -> {sub_path, Field@0} end
)}}
end
);
link_node_type ->
gleam@result:'try'(
(gleam@dynamic:field(
<<"url"/utf8>>,
fun gleam@dynamic:string/1
))(Dyn),
fun(Url) ->
{ok,
{link_node,
erlang:element(2, Attrs),
erlang:element(4, Attrs),
erlang:element(5, Attrs),
erlang:element(6, Attrs),
erlang:element(7, Attrs),
erlang:element(8, Attrs),
{url, Url}}}
end
);
group_node_type ->
gleam@result:'try'(
begin
_pipe@1 = Dyn,
(gleam@dynamic:decode3(
fun(Label, Background, Background_style) ->
{Label, Background, Background_style}
end,
gleam@dynamic:optional_field(
<<"label"/utf8>>,
fun gleam@dynamic:string/1
),
gleam@dynamic:optional_field(
<<"background"/utf8>>,
fun gleam@dynamic:string/1
),
gleam@dynamic:optional_field(
<<"background_style"/utf8>>,
fun json_canvas@node@group_background_style:decode_group_background_style/1
)
))(_pipe@1)
end,
fun(_use0@1) ->
{Label@1, Background@1, Background_style@1} = _use0@1,
{ok,
{group_node,
erlang:element(2, Attrs),
erlang:element(4, Attrs),
erlang:element(5, Attrs),
erlang:element(6, Attrs),
erlang:element(7, Attrs),
erlang:element(8, Attrs),
gleam@option:map(
Label@1,
fun(Field@0) -> {group_label, Field@0} end
),
gleam@option:map(
Background@1,
fun(Field@0) -> {group_background, Field@0} end
),
Background_style@1}}
end
)
end end
).