mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-24 19:38:24 +00:00
Basic ui for addons
This commit is contained in:
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user