Improve html tree component

This commit is contained in:
Thelonius Kort
2023-05-03 22:37:43 +02:00
parent 7990b74bf0
commit 8a0e2f22c1
3 changed files with 18 additions and 4 deletions

View File

@ -3,6 +3,7 @@ defmodule OutlookWeb.HtmlTreeComponent do
use Phoenix.Component use Phoenix.Component
# use OutlookWeb, :html # use OutlookWeb, :html
import OutlookWeb.CoreComponents import OutlookWeb.CoreComponents
import OutlookWeb.ViewHelpers
alias Phoenix.LiveView.JS alias Phoenix.LiveView.JS
@ -15,10 +16,14 @@ defmodule OutlookWeb.HtmlTreeComponent do
end end
def attributes(assigns) do def attributes(assigns) do
~H"&nbsp; <%= @name %>=&quot;<%= @value %>&quot;" ~H"&nbsp; <%= @name %>=&quot;<%= elipsed_text(@value, 16) %>&quot;"
end end
def tnode(%{node: %{status: _}} = assigns), do: ~H"<%= String.slice(@node.content, 0..20) %><%= if String.length(@node.content) > 20 do %>...<% end %><br>" def tnode(%{node: %{status: _}} = assigns) do
~H"""
<span title={@node.content} {@node.eph.attributes}><%= elipsed_text(@node.content, 30) %></span><br>
"""
end
def tnode(assigns) when assigns.node.type == :element do def tnode(assigns) when assigns.node.type == :element do
~H""" ~H"""
@ -32,7 +37,7 @@ defmodule OutlookWeb.HtmlTreeComponent do
def tnode(assigns) when assigns.node.type == :text do def tnode(assigns) when assigns.node.type == :text do
~H""" ~H"""
"<%= String.slice(@node.content, 0..35) %><%= if String.length(@node.content) > 35 do %>..."<% end %><br> "<%= elipsed_text(@node.content, 30) %><br>
""" """
end end

View File

@ -45,7 +45,7 @@ defmodule OutlookWeb.ArticleLive.NewComponents do
~H""" ~H"""
<div>Review Translation Units</div> <div>Review Translation Units</div>
<div class="flex gap-4"> <div class="flex gap-4">
<div id="html-tree" class="w-96 overflow-auto whitespace-nowrap"> <div id="html-tree" class="article w-96 overflow-auto whitespace-nowrap">
<.render_tree tree={@raw_internal_tree} ></.render_tree> <.render_tree tree={@raw_internal_tree} ></.render_tree>
</div> </div>
<div id="partition-preview" class="article show-boundary overflow-auto h-full"> <div id="partition-preview" class="article show-boundary overflow-auto h-full">

View File

@ -18,4 +18,13 @@ defmodule OutlookWeb.ViewHelpers do
def strip_links(html) do def strip_links(html) do
raise "Yet to be implemented!" raise "Yet to be implemented!"
end end
def elipsed_text(text, length) do
if String.length(text) < length do
text
else
part_length = (length - 3) / 2 |> trunc()
"#{String.slice(text, 0..part_length)}#{String.slice(text, -part_length..-1)}"
end
end
end end