Basic ui for addons

This commit is contained in:
eikek
2022-05-08 14:01:41 +02:00
parent 7fdd78ad06
commit 73747c4ea3
33 changed files with 2881 additions and 13 deletions

View File

@ -14,12 +14,42 @@ module Util.List exposing
, findNext
, findPrev
, get
, removeByIndex
, replaceByIndex
, sliding
)
import Html.Attributes exposing (list)
removeByIndex : Int -> List a -> List a
removeByIndex index list =
List.indexedMap
(\idx ->
\e ->
if idx == index then
Nothing
else
Just e
)
list
|> List.filterMap identity
replaceByIndex : Int -> a -> List a -> List a
replaceByIndex index element list =
let
repl idx e =
if idx == index then
element
else
e
in
List.indexedMap repl list
changePosition : Int -> Int -> List a -> List a
changePosition source target list =
let

View File

@ -9,6 +9,7 @@ module Util.String exposing
( appendIfAbsent
, crazyEncode
, ellipsis
, firstSentenceOrMax
, isBlank
, isNothingOrBlank
, underscoreToSpace
@ -16,7 +17,6 @@ module Util.String exposing
)
import Base64
import Html exposing (strong)
crazyEncode : String -> String
@ -45,6 +45,26 @@ ellipsis len str =
String.left (len - 1) str ++ ""
firstSentenceOrMax : Int -> String -> Maybe String
firstSentenceOrMax maxLen str =
let
idx =
String.indexes "." str
|> List.head
|> Maybe.map ((+) 2)
|> Maybe.map (min maxLen)
|> Maybe.withDefault maxLen
len =
String.length str
in
if len <= maxLen then
Nothing
else
Just <| String.left (idx - 1) str ++ ""
withDefault : String -> String -> String
withDefault default str =
if str == "" then