<commit_before>module Internal.Menu.Implementation exposing
    ( anchorCorner
    , anchorMargin
    , attach
    , bottomEndCorner
    , bottomLeftCorner
    , bottomRightCorner
    , bottomStartCorner
    , connect
    , Corner
    , divider
    , index
    , Item
    , li
    , Margin
    , menu
    , Menu
    , onSelect
    , Property
    , quickOpen
    , react
    , subs
    , subscriptions
    , topEndCorner
    , topLeftCorner
    , topRightCorner
    , topStartCorner
    , ul
    , update
    , view
    )

import DOM
import Html.Attributes as Html
import Html.Events as Html
import Html exposing (Html, text)
import Json.Decode as Json exposing (Decoder)
import Internal.Component as Component exposing (Indexed, Index)
import Internal.Dispatch.Internal as Dispatch
import Internal.GlobalEvents as GlobalEvents
import Internal.Helpers as Helpers
import Internal.List.Implementation as Lists
import Internal.Menu.Model exposing (Model, defaultModel, Msg(..), KeyCode, Key, Meta, Geometry, defaultGeometry, Viewport)
import Internal.Msg
import Internal.Options as Options exposing (cs, css, styled, when)
import Mouse
import Time


subscriptions : Model -> Sub (Msg m)
subscriptions model =
    -- Note: Clicking to open a Menu immediately triggers a click on document.
    -- To prevent the Menu from closing immediately, we ignore Document clicks
    -- in the first animation frame after Open by watching model.geometry.
    if model.open && (model.geometry /= Nothing) then
      Mouse.clicks (\ _ -> DocumentClick)
    else
      Sub.none


type alias Item m =
    { options : List (Lists.Property m)
    , childs : List (Html m)
    , divider : Bool
    }


li : List (Lists.Property m) -> List (Html m) -> Item m
li options childs =
    { options = options, childs = childs, divider = False }



divider : List (Lists.Property m) -> List (Html m) -> Item m
divider options childs =
    { options = options, childs = childs, divider = True }


type alias Menu m =
    { options: List (Lists.Property m)
    , items : List (Item m)
    }


ul : List (Lists.Property m) -> List (Item m) -> Menu m
ul options items =
    { options = options, items = items }


attach : (Internal.Msg.Msg m -> m) -> Index -> Options.Property c m
attach lift idx =
    Options.onClick (lift (Internal.Msg.MenuMsg idx Toggle))


connect : (Internal.Menu.Model.Msg m -> m) -> Options.Property c m
connect lift =
    Options.onClick (lift Toggle)


update : (Msg msg -> msg) -> Msg msg -> Model -> ( Maybe Model, Cmd msg )
update lift msg model =
    case msg of

        NoOp ->
            ( Nothing, Cmd.none )

        Toggle ->
            update lift (if model.open then Close else Open) model

        Open ->
            let
                quickOpen =
                    Maybe.withDefault False model.quickOpen
            in
            if not model.open then
                (
                  Just
                  { model
                    | open = True
                    , animating = True
                    , geometry = Nothing
                  }
                ,
                  if not quickOpen then
                      Helpers.delayedCmd (120*Time.millisecond) (lift AnimationEnd)
                  else
                      Helpers.cmd (lift AnimationEnd)
                )
            else
                ( Nothing, Cmd.none )

        Close ->
            let
                quickOpen =
                    Maybe.withDefault False model.quickOpen
            in
            if model.open then
                (
                  Just
                  { model
                    | open = False
                    , animating = True
                    , quickOpen = Nothing
                    , focusedItemAtIndex = Nothing
                  }
                ,
                  if not quickOpen then
                      Helpers.delayedCmd (70*Time.millisecond) (lift AnimationEnd)
                  else
                      Helpers.cmd (lift AnimationEnd)
                )
            else
                ( Nothing, Cmd.none )

        CloseDelayed ->
            ( Nothing, Helpers.delayedCmd (50*Time.millisecond) (lift Close) )

        Init { quickOpen, index } geometry ->
            ( Just
              { model
                | geometry = Just geometry
                , quickOpen = Just quickOpen
                , focusedItemAtIndex = Debug.log "index" index
              }
            ,
              Cmd.none
            )
<commit_msg>Remove Debug.log from Internal.Menu.Implementation<commit_after>module Internal.Menu.Implementation exposing
    ( anchorCorner
    , anchorMargin
    , attach
    , bottomEndCorner
    , bottomLeftCorner
    , bottomRightCorner
    , bottomStartCorner
    , connect
    , Corner
    , divider
    , index
    , Item
    , li
    , Margin
    , menu
    , Menu
    , onSelect
    , Property
    , quickOpen
    , react
    , subs
    , subscriptions
    , topEndCorner
    , topLeftCorner
    , topRightCorner
    , topStartCorner
    , ul
    , update
    , view
    )

import DOM
import Html.Attributes as Html
import Html.Events as Html
import Html exposing (Html, text)
import Json.Decode as Json exposing (Decoder)
import Internal.Component as Component exposing (Indexed, Index)
import Internal.Dispatch.Internal as Dispatch
import Internal.GlobalEvents as GlobalEvents
import Internal.Helpers as Helpers
import Internal.List.Implementation as Lists
import Internal.Menu.Model exposing (Model, defaultModel, Msg(..), KeyCode, Key, Meta, Geometry, defaultGeometry, Viewport)
import Internal.Msg
import Internal.Options as Options exposing (cs, css, styled, when)
import Mouse
import Time


subscriptions : Model -> Sub (Msg m)
subscriptions model =
    -- Note: Clicking to open a Menu immediately triggers a click on document.
    -- To prevent the Menu from closing immediately, we ignore Document clicks
    -- in the first animation frame after Open by watching model.geometry.
    if model.open && (model.geometry /= Nothing) then
      Mouse.clicks (\ _ -> DocumentClick)
    else
      Sub.none


type alias Item m =
    { options : List (Lists.Property m)
    , childs : List (Html m)
    , divider : Bool
    }


li : List (Lists.Property m) -> List (Html m) -> Item m
li options childs =
    { options = options, childs = childs, divider = False }



divider : List (Lists.Property m) -> List (Html m) -> Item m
divider options childs =
    { options = options, childs = childs, divider = True }


type alias Menu m =
    { options: List (Lists.Property m)
    , items : List (Item m)
    }


ul : List (Lists.Property m) -> List (Item m) -> Menu m
ul options items =
    { options = options, items = items }


attach : (Internal.Msg.Msg m -> m) -> Index -> Options.Property c m
attach lift idx =
    Options.onClick (lift (Internal.Msg.MenuMsg idx Toggle))


connect : (Internal.Menu.Model.Msg m -> m) -> Options.Property c m
connect lift =
    Options.onClick (lift Toggle)


update : (Msg msg -> msg) -> Msg msg -> Model -> ( Maybe Model, Cmd msg )
update lift msg model =
    case msg of

        NoOp ->
            ( Nothing, Cmd.none )

        Toggle ->
            update lift (if model.open then Close else Open) model

        Open ->
            let
                quickOpen =
                    Maybe.withDefault False model.quickOpen
            in
            if not model.open then
                (
                  Just
                  { model
                    | open = True
                    , animating = True
                    , geometry = Nothing
                  }
                ,
                  if not quickOpen then
                      Helpers.delayedCmd (120*Time.millisecond) (lift AnimationEnd)
                  else
                      Helpers.cmd (lift AnimationEnd)
                )
            else
                ( Nothing, Cmd.none )

        Close ->
            let
                quickOpen =
                    Maybe.withDefault False model.quickOpen
            in
            if model.open then
                (
                  Just
                  { model
                    | open = False
                    , animating = True
                    , quickOpen = Nothing
                    , focusedItemAtIndex = Nothing
                  }
                ,
                  if not quickOpen then
                      Helpers.delayedCmd (70*Time.millisecond) (lift AnimationEnd)
                  else
                      Helpers.cmd (lift AnimationEnd)
                )
            else
                ( Nothing, Cmd.none )

        CloseDelayed ->
            ( Nothing, Helpers.delayedCmd (50*Time.millisecond) (lift Close) )

        Init { quickOpen, index } geometry ->
            ( Just
              { model
                | geometry = Just geometry
                , quickOpen = Just quickOpen
                , focusedItemAtIndex = index
              }
            ,
              Cmd.none
            )

{'fraction_non_alphanumeric': 0.07571888531142444, 'fraction_numerical': 0.001554346619296103, 'mean_word_length': 1.5460712266817411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7133234', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2276, 'n_words': 763}