Packages

A platform agnostic Elm-like framework (soft-fork of Lustre)

Current section

Files

Jump to
agnostic src agnostic@vdom@vnode.erl
Raw

src/agnostic@vdom@vnode.erl

-module(agnostic@vdom@vnode).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/agnostic/vdom/vnode.gleam").
-export([to_raw_content/1, raw_content_to_string/1, empty_keyed_children/0, fragment/3, element/6, text/2, raw_container/6, raw_node/3, map/2, memo/3, to_keyed/2, to_json/3]).
-export_type([raw_content/0, element/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type raw_content() :: any().
-type element(GSP) :: {fragment,
integer(),
binary(),
list(element(GSP)),
agnostic@internals@mutable_map:mutable_map(binary(), element(GSP))} |
{element,
integer(),
binary(),
binary(),
binary(),
list(agnostic@vdom@vattr:attribute(GSP)),
list(element(GSP)),
agnostic@internals@mutable_map:mutable_map(binary(), element(GSP))} |
{text, integer(), binary(), binary()} |
{raw_container,
integer(),
binary(),
binary(),
binary(),
list(agnostic@vdom@vattr:attribute(GSP)),
raw_content(),
gleam@option:option(fun((raw_content(), raw_content()) -> boolean()))} |
{raw_node,
integer(),
binary(),
raw_content(),
gleam@option:option(fun((raw_content(), raw_content()) -> boolean()))} |
{map,
integer(),
binary(),
fun((gleam@dynamic:dynamic_()) -> gleam@dynamic:dynamic_()),
element(GSP)} |
{memo,
integer(),
binary(),
list(agnostic@internals@ref:ref()),
fun(() -> element(GSP))}.
-file("src/agnostic/vdom/vnode.gleam", 22).
?DOC(" Convert any value to a RawContent. This is the hack that make this work\n").
-spec to_raw_content(any()) -> raw_content().
to_raw_content(Value) ->
gleam@function:identity(Value).
-file("src/agnostic/vdom/vnode.gleam", 28).
?DOC(
" Convert RawContent back to a String. This should only be used when you know\n"
" the content is a String (e.g., in server-side HTML rendering).\n"
).
-spec raw_content_to_string(raw_content()) -> binary().
raw_content_to_string(Content) ->
gleam@function:identity(Content).
-file("src/agnostic/vdom/vnode.gleam", 105).
?DOC(
" Create an empty keyed children map. Used internally when constructing\n"
" elements without keyed children.\n"
).
-spec empty_keyed_children() -> agnostic@internals@mutable_map:mutable_map(binary(), element(any())).
empty_keyed_children() ->
maps:new().
-file("src/agnostic/vdom/vnode.gleam", 111).
-spec fragment(
binary(),
list(element(GTC)),
agnostic@internals@mutable_map:mutable_map(binary(), element(GTC))
) -> element(GTC).
fragment(Key, Children, Keyed_children) ->
{fragment, 0, Key, Children, Keyed_children}.
-file("src/agnostic/vdom/vnode.gleam", 121).
-spec element(
binary(),
binary(),
binary(),
list(agnostic@vdom@vattr:attribute(GTJ)),
list(element(GTJ)),
agnostic@internals@mutable_map:mutable_map(binary(), element(GTJ))
) -> element(GTJ).
element(Key, Namespace, Tag, Attributes, Children, Keyed_children) ->
{element,
1,
Key,
Namespace,
Tag,
agnostic@vdom@vattr:prepare(Attributes),
Children,
Keyed_children}.
-file("src/agnostic/vdom/vnode.gleam", 142).
-spec text(binary(), binary()) -> element(any()).
text(Key, Content) ->
{text, 2, Key, Content}.
-file("src/agnostic/vdom/vnode.gleam", 148).
-spec raw_container(
binary(),
binary(),
binary(),
list(agnostic@vdom@vattr:attribute(GTU)),
GTX,
gleam@option:option(fun((GTX, GTX) -> boolean()))
) -> element(GTU).
raw_container(Key, Namespace, Tag, Attributes, Content, Compare) ->
Raw_compare = gleam@option:map(
Compare,
fun(Cmp) ->
fun(A, B) ->
Cmp(gleam@function:identity(A), gleam@function:identity(B))
end
end
),
{raw_container,
3,
Key,
Namespace,
Tag,
agnostic@vdom@vattr:prepare(Attributes),
gleam@function:identity(Content),
Raw_compare}.
-file("src/agnostic/vdom/vnode.gleam", 176).
-spec raw_node(binary(), GUA, gleam@option:option(fun((GUA, GUA) -> boolean()))) -> element(any()).
raw_node(Key, Content, Compare) ->
Raw_compare = gleam@option:map(
Compare,
fun(Cmp) ->
fun(A, B) ->
Cmp(gleam@function:identity(A), gleam@function:identity(B))
end
end
),
{raw_node, 6, Key, gleam@function:identity(Content), Raw_compare}.
-file("src/agnostic/vdom/vnode.gleam", 196).
-spec map(element(GUE), fun((GUE) -> GUG)) -> element(GUG).
map(Element, Mapper) ->
case Element of
{map, _, _, Child_mapper, _} ->
{map,
4,
erlang:element(3, Element),
fun(Handler) ->
(gleam@function:identity(Mapper))(Child_mapper(Handler))
end,
gleam@function:identity(erlang:element(5, Element))};
_ ->
{map,
4,
erlang:element(3, Element),
gleam@function:identity(Mapper),
gleam@function:identity(Element)}
end.
-file("src/agnostic/vdom/vnode.gleam", 217).
-spec memo(
binary(),
list(agnostic@internals@ref:ref()),
fun(() -> element(GUJ))
) -> element(GUJ).
memo(Key, Dependencies, View) ->
{memo, 5, Key, Dependencies, View}.
-file("src/agnostic/vdom/vnode.gleam", 231).
-spec to_keyed(binary(), element(GUO)) -> element(GUO).
to_keyed(Key, Node) ->
case Node of
{element, _, _, _, _, _, _, _} ->
{element,
erlang:element(2, Node),
Key,
erlang:element(4, Node),
erlang:element(5, Node),
erlang:element(6, Node),
erlang:element(7, Node),
erlang:element(8, Node)};
{text, _, _, _} ->
{text, erlang:element(2, Node), Key, erlang:element(4, Node)};
{raw_container, _, _, _, _, _, _, _} ->
{raw_container,
erlang:element(2, Node),
Key,
erlang:element(4, Node),
erlang:element(5, Node),
erlang:element(6, Node),
erlang:element(7, Node),
erlang:element(8, Node)};
{raw_node, _, _, _, _} ->
{raw_node,
erlang:element(2, Node),
Key,
erlang:element(4, Node),
erlang:element(5, Node)};
{fragment, _, _, _, _} ->
{fragment,
erlang:element(2, Node),
Key,
erlang:element(4, Node),
erlang:element(5, Node)};
{memo, _, _, _, View} ->
{memo,
erlang:element(2, Node),
Key,
erlang:element(4, Node),
fun() -> to_keyed(Key, View()) end};
{map, _, _, _, Child} ->
{map,
erlang:element(2, Node),
Key,
erlang:element(4, Node),
to_keyed(Key, Child)}
end.
-file("src/agnostic/vdom/vnode.gleam", 341).
-spec raw_node_to_json(integer(), binary(), GVX, fun((GVX) -> binary())) -> gleam@json:json().
raw_node_to_json(Kind, Key, Content, Serialize_raw_content) ->
_pipe = agnostic@internals@json_object_builder:tagged(Kind),
_pipe@1 = agnostic@internals@json_object_builder:string(
_pipe,
<<"key"/utf8>>,
Key
),
_pipe@2 = agnostic@internals@json_object_builder:string(
_pipe@1,
<<"content"/utf8>>,
Serialize_raw_content(Content)
),
agnostic@internals@json_object_builder:build(_pipe@2).
-file("src/agnostic/vdom/vnode.gleam", 323).
-spec raw_container_to_json(
integer(),
binary(),
binary(),
binary(),
list(agnostic@vdom@vattr:attribute(any())),
GVS,
fun((GVS) -> binary())
) -> gleam@json:json().
raw_container_to_json(
Kind,
Key,
Namespace,
Tag,
Attributes,
Content,
Serialize_raw_content
) ->
_pipe = agnostic@internals@json_object_builder:tagged(Kind),
_pipe@1 = agnostic@internals@json_object_builder:string(
_pipe,
<<"key"/utf8>>,
Key
),
_pipe@2 = agnostic@internals@json_object_builder:string(
_pipe@1,
<<"namespace"/utf8>>,
Namespace
),
_pipe@3 = agnostic@internals@json_object_builder:string(
_pipe@2,
<<"tag"/utf8>>,
Tag
),
_pipe@4 = agnostic@internals@json_object_builder:list(
_pipe@3,
<<"attributes"/utf8>>,
Attributes,
fun agnostic@vdom@vattr:to_json/1
),
_pipe@5 = agnostic@internals@json_object_builder:string(
_pipe@4,
<<"content"/utf8>>,
Serialize_raw_content(Content)
),
agnostic@internals@json_object_builder:build(_pipe@5).
-file("src/agnostic/vdom/vnode.gleam", 316).
-spec text_to_json(integer(), binary(), binary()) -> gleam@json:json().
text_to_json(Kind, Key, Content) ->
_pipe = agnostic@internals@json_object_builder:tagged(Kind),
_pipe@1 = agnostic@internals@json_object_builder:string(
_pipe,
<<"key"/utf8>>,
Key
),
_pipe@2 = agnostic@internals@json_object_builder:string(
_pipe@1,
<<"content"/utf8>>,
Content
),
agnostic@internals@json_object_builder:build(_pipe@2).
-file("src/agnostic/vdom/vnode.gleam", 348).
-spec memo_to_json(
fun(() -> element(GUR)),
agnostic@internals@mutable_map:mutable_map(fun(() -> element(GUR)), element(GUR)),
fun((raw_content()) -> binary())
) -> gleam@json:json().
memo_to_json(View, Memos, Serialize_raw_content) ->
Child = agnostic@internals@mutable_map:get_or_compute(Memos, View, View),
to_json(Child, Memos, Serialize_raw_content).
-file("src/agnostic/vdom/vnode.gleam", 355).
-spec map_to_json(
integer(),
binary(),
element(GUR),
agnostic@internals@mutable_map:mutable_map(fun(() -> element(GUR)), element(GUR)),
fun((raw_content()) -> binary())
) -> gleam@json:json().
map_to_json(Kind, Key, Child, Memos, Serialize_raw_content) ->
_pipe = agnostic@internals@json_object_builder:tagged(Kind),
_pipe@1 = agnostic@internals@json_object_builder:string(
_pipe,
<<"key"/utf8>>,
Key
),
_pipe@2 = agnostic@internals@json_object_builder:json(
_pipe@1,
<<"child"/utf8>>,
(to_json(Child, Memos, Serialize_raw_content))
),
agnostic@internals@json_object_builder:build(_pipe@2).
-file("src/agnostic/vdom/vnode.gleam", 295).
-spec element_to_json(
integer(),
binary(),
binary(),
binary(),
list(agnostic@vdom@vattr:attribute(GUR)),
list(element(GUR)),
agnostic@internals@mutable_map:mutable_map(fun(() -> element(GUR)), element(GUR)),
fun((raw_content()) -> binary())
) -> gleam@json:json().
element_to_json(
Kind,
Key,
Namespace,
Tag,
Attributes,
Children,
Memos,
Serialize_raw_content
) ->
_pipe = agnostic@internals@json_object_builder:tagged(Kind),
_pipe@1 = agnostic@internals@json_object_builder:string(
_pipe,
<<"key"/utf8>>,
Key
),
_pipe@2 = agnostic@internals@json_object_builder:string(
_pipe@1,
<<"namespace"/utf8>>,
Namespace
),
_pipe@3 = agnostic@internals@json_object_builder:string(
_pipe@2,
<<"tag"/utf8>>,
Tag
),
_pipe@4 = agnostic@internals@json_object_builder:list(
_pipe@3,
<<"attributes"/utf8>>,
Attributes,
fun agnostic@vdom@vattr:to_json/1
),
_pipe@5 = agnostic@internals@json_object_builder:list(
_pipe@4,
<<"children"/utf8>>,
Children,
(fun(_capture) -> to_json(_capture, Memos, Serialize_raw_content) end)
),
agnostic@internals@json_object_builder:build(_pipe@5).
-file("src/agnostic/vdom/vnode.gleam", 286).
-spec fragment_to_json(
integer(),
binary(),
list(element(GUR)),
agnostic@internals@mutable_map:mutable_map(fun(() -> element(GUR)), element(GUR)),
fun((raw_content()) -> binary())
) -> gleam@json:json().
fragment_to_json(Kind, Key, Children, Memos, Serialize_raw_content) ->
_pipe = agnostic@internals@json_object_builder:tagged(Kind),
_pipe@1 = agnostic@internals@json_object_builder:string(
_pipe,
<<"key"/utf8>>,
Key
),
_pipe@2 = agnostic@internals@json_object_builder:list(
_pipe@1,
<<"children"/utf8>>,
Children,
(fun(_capture) -> to_json(_capture, Memos, Serialize_raw_content) end)
),
agnostic@internals@json_object_builder:build(_pipe@2).
-file("src/agnostic/vdom/vnode.gleam", 248).
-spec to_json(
element(GUR),
agnostic@internals@mutable_map:mutable_map(fun(() -> element(GUR)), element(GUR)),
fun((raw_content()) -> binary())
) -> gleam@json:json().
to_json(Node, Memos, Serialize_raw_content) ->
case Node of
{fragment, Kind, Key, Children, _} ->
fragment_to_json(Kind, Key, Children, Memos, Serialize_raw_content);
{element, Kind@1, Key@1, Namespace, Tag, Attributes, Children@1, _} ->
element_to_json(
Kind@1,
Key@1,
Namespace,
Tag,
Attributes,
Children@1,
Memos,
Serialize_raw_content
);
{text, Kind@2, Key@2, Content} ->
text_to_json(Kind@2, Key@2, Content);
{raw_container,
Kind@3,
Key@3,
Namespace@1,
Tag@1,
Attributes@1,
Content@1,
_} ->
raw_container_to_json(
Kind@3,
Key@3,
Namespace@1,
Tag@1,
Attributes@1,
Content@1,
Serialize_raw_content
);
{raw_node, Kind@4, Key@4, Content@2, _} ->
raw_node_to_json(Kind@4, Key@4, Content@2, Serialize_raw_content);
{map, Kind@5, Key@5, _, Child} ->
map_to_json(Kind@5, Key@5, Child, Memos, Serialize_raw_content);
{memo, _, _, _, View} ->
memo_to_json(View, Memos, Serialize_raw_content)
end.