Initial commit

This commit is contained in:
Thomas Forgione 2022-02-04 18:01:04 +01:00
commit a3fb7dd5e4
7 changed files with 17733 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
elm-stuff

28
Makefile Normal file
View File

@ -0,0 +1,28 @@
ifeq ("$(ELM)","")
ELM=elm
endif
ifeq ("$(ELMLIVE)", "")
ELMLIVE=elm-live
endif
ifeq ("$(UGLIFYJS)", "")
UGLIFYJS=uglifyjs
endif
BUILD_DIR=js
dev: js/main.js
release: js/main.min.js
js/main.js: src/**
$(ELM) make src/Main.elm --output $(BUILD_DIR)/main.js
js/main.min.js: js/main.tmp.js
@$(UGLIFYJS) $(BUILD_DIR)/main.tmp.js --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | $(UGLIFYJS) --mangle > $(BUILD_DIR)/main.min.js
js/main.tmp.js: src/**
@$(ELM) make src/Main.elm --optimize --output $(BUILD_DIR)/main.tmp.js
clean:
@rm -rf $(BUILD_DIR)/{main.js,main.min.js}

25
elm.json Normal file
View File

@ -0,0 +1,25 @@
{
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"mdgriffith/elm-ui": "1.1.8"
},
"indirect": {
"elm/json": "1.1.3",
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2"
}
},
"test-dependencies": {
"direct": {},
"indirect": {}
}
}

28
index.html Normal file
View File

@ -0,0 +1,28 @@
<!doctype HTML>
<html>
<head>
<title>elmoji</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="node"></div>
<script src="js/main.js"></script>
<script>
var app = Elm.Main.init({
node: document.getElementById('node')
});
app.ports.copy.subscribe(function(str) {
var el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style = {position: 'absolute', left: '-9999px'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
});
</script>
</body>
</html>

15999
js/main.js Normal file

File diff suppressed because it is too large Load Diff

1525
src/Emoji.elm Normal file

File diff suppressed because it is too large Load Diff

127
src/Main.elm Normal file
View File

@ -0,0 +1,127 @@
port module Main exposing (..)
import Browser
import Element exposing (Element)
import Element.Border as Border
import Element.Input as Input
import Emoji
import Html
import Html.Attributes
main =
Browser.element
{ init = init
, update = update
, subscriptions = \_ -> Sub.none
, view = view
}
-- MODEL --
type alias Model =
{ category : Emoji.Category
}
init : () -> ( Model, Cmd Msg )
init _ =
( { category = Emoji.Recent }, Cmd.none )
type Msg
= CategoryClicked Emoji.Category
| Copy String
-- UPDATE --
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
CategoryClicked category ->
( { model | category = category }, Cmd.none )
Copy c ->
( model, copy c )
-- VIEW --
view : Model -> Html.Html Msg
view model =
Element.layout []
(Element.column [ Element.width (Element.px 512), Element.height (Element.px 512) ]
[ header, panel (Emoji.getEmojis model.category) ]
)
header : Element Msg
header =
Element.row [ Element.width Element.fill, Element.padding 5, Element.spacing 10 ]
(Emoji.categories
|> List.map
(\x ->
Input.button [ Element.padding 5, Border.color (Element.rgb255 0 0 0), Border.width 1, Border.rounded 5 ]
{ label = Element.el [] (emoji (Emoji.categoryEmoji x))
, onPress = Just (CategoryClicked x)
}
)
)
panel : List Emoji.Emoji -> Element Msg
panel em =
em
|> regroup 10
|> List.map (\x -> List.map maybeEmoji x)
|> List.map (Element.row [ Element.width Element.fill ])
|> Element.column [ Element.width (Element.px 512), Element.height (Element.px 512), Element.scrollbarY ]
emoji : Emoji.Emoji -> Element Msg
emoji e =
Input.button [ Element.htmlAttribute (Html.Attributes.title e.name), Element.centerX, Element.centerY ]
{ label = Element.text e.unicode, onPress = Just (Copy e.unicode) }
maybeEmoji : Maybe Emoji.Emoji -> Element Msg
maybeEmoji e =
Element.el [ Element.width Element.fill, Element.padding 10 ] (Maybe.map emoji e |> Maybe.withDefault Element.none)
regroup : Int -> List Emoji.Emoji -> List (List (Maybe Emoji.Emoji))
regroup num input =
List.reverse (regroupAux [] [] num input)
regroupAux : List (List (Maybe Emoji.Emoji)) -> List (Maybe Emoji.Emoji) -> Int -> List Emoji.Emoji -> List (List (Maybe Emoji.Emoji))
regroupAux currentTotal currentPart num input =
case input of
[] ->
if List.length currentPart < num then
regroupAux currentTotal (Nothing :: currentPart) num []
else
List.reverse currentPart :: currentTotal
h :: t ->
if List.length currentPart >= num then
regroupAux (List.reverse currentPart :: currentTotal) [ Just h ] num t
else
regroupAux currentTotal (Just h :: currentPart) num t
-- PORTS --
port copy : String -> Cmd msg