<commit_before>{-
Copyright 2016 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module SlamData.Workspace.Card.StructureEditor.Column.Component where

import SlamData.Prelude

import Halogen as H
import Halogen.Component.Proxy (proxyQL)
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
import Halogen.Query.HalogenM as HQ

import SlamData.Monad (Slam)
import SlamData.Workspace.Card.StructureEditor.Common (ColumnItem, ColumnPath)
import SlamData.Workspace.Card.StructureEditor.Message (Message)
import SlamData.Workspace.MillerColumns.Column.Component as MCC

type ColumnOptions = MCC.ColumnOptions ColumnItem ColumnPath Message
type ColumnQuery = MCC.Query ColumnItem ColumnPath Message

type Message' = MCC.Message' ColumnItem ColumnPath Message

component
  ∷ ColumnOptions
  → ColumnPath
  → H.Component HH.HTML (MCC.Query' ColumnItem ColumnPath Message) Input Message' Slam
component opts = proxyQL ∘ component' opts

data Query a = Raise Message' a

type Query' = Coproduct ColumnQuery Query

type State = MCC.ColumnWidth × Maybe ColumnItem

type Input = MCC.ColumnWidth × Maybe ColumnItem

type DSL = H.ParentDSL State Query' ColumnQuery Unit Message' Slam
type HTML = H.ParentHTML Query' ColumnQuery Unit Slam

component'
  ∷ ColumnOptions
  → ColumnPath
  → H.Component HH.HTML Query' Input Message' Slam
component' opts path =
  H.parentComponent
    { initialState: id
    , render
    , eval
    , receiver: Just ∘ left ∘ H.action ∘ MCC.HandleInput
    }
  where

  column ∷ H.Component HH.HTML ColumnQuery Input Message' Slam
  column = MCC.component' opts path

  render ∷ State → HTML
  render st =
    HH.div_
      [ HH.div
          [ HP.class_ (HH.ClassName "sd-structure-editor-column") ]
          [ HH.slot unit column st (Just ∘ right ∘ H.action ∘ Raise) ]
      ]

  eval ∷ Query' ~> DSL
  eval = coproduct evalInner evalOuter

  evalInner ∷ ColumnQuery ~> DSL
  evalInner =
    maybe (HQ.halt "Inner component query failed") pure <=< H.query unit

  evalOuter ∷ Query ~> DSL
  evalOuter = case _ of
    Raise msg next → do
      H.raise msg
      pure next
<commit_msg>Fix HTML for structure viewer layout<commit_after>{-
Copyright 2016 SlamData, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-}

module SlamData.Workspace.Card.StructureEditor.Column.Component where

import SlamData.Prelude

import Halogen as H
import Halogen.Component.Proxy (proxyQL)
import Halogen.HTML as HH
import Halogen.HTML.Properties as HP
import Halogen.Query.HalogenM as HQ

import SlamData.Monad (Slam)
import SlamData.Workspace.Card.StructureEditor.Common (ColumnItem, ColumnPath)
import SlamData.Workspace.Card.StructureEditor.Message (Message)
import SlamData.Workspace.MillerColumns.Column.Component as MCC

type ColumnOptions = MCC.ColumnOptions ColumnItem ColumnPath Message
type ColumnQuery = MCC.Query ColumnItem ColumnPath Message

type Message' = MCC.Message' ColumnItem ColumnPath Message

component
  ∷ ColumnOptions
  → ColumnPath
  → H.Component HH.HTML (MCC.Query' ColumnItem ColumnPath Message) Input Message' Slam
component opts = proxyQL ∘ component' opts

data Query a = Raise Message' a

type Query' = Coproduct ColumnQuery Query

type State = MCC.ColumnWidth × Maybe ColumnItem

type Input = MCC.ColumnWidth × Maybe ColumnItem

type DSL = H.ParentDSL State Query' ColumnQuery Unit Message' Slam
type HTML = H.ParentHTML Query' ColumnQuery Unit Slam

component'
  ∷ ColumnOptions
  → ColumnPath
  → H.Component HH.HTML Query' Input Message' Slam
component' opts path =
  H.parentComponent
    { initialState: id
    , render
    , eval
    , receiver: Just ∘ left ∘ H.action ∘ MCC.HandleInput
    }
  where

  column ∷ H.Component HH.HTML ColumnQuery Input Message' Slam
  column = MCC.component' opts path

  render ∷ State → HTML
  render st =
    HH.div
      [ HP.class_ (HH.ClassName "sd-structure-editor-column") ]
      [ HH.slot unit column st (Just ∘ right ∘ H.action ∘ Raise) ]

  eval ∷ Query' ~> DSL
  eval = coproduct evalInner evalOuter

  evalInner ∷ ColumnQuery ~> DSL
  evalInner =
    maybe (HQ.halt "Inner component query failed") pure <=< H.query unit

  evalOuter ∷ Query ~> DSL
  evalOuter = case _ of
    Raise msg next → do
      H.raise msg
      pure next

{'fraction_non_alphanumeric': 0.07130501633672881, 'fraction_numerical': 0.003075148952527388, 'mean_word_length': 3.8818011257035647, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7059383', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1513, 'n_words': 606}