{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DataKinds #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module IHaskell.Display.Widgets.String.TextArea
(
TextArea
, mkTextArea
) where
import Prelude
import Control.Monad (void)
import Data.Aeson
import Data.IORef (newIORef)
import Data.Vinyl (Rec(..), (<+>))
import IHaskell.Display
import IHaskell.Eval.Widgets
import IHaskell.IPython.Message.UUID as U
import IHaskell.Display.Widgets.Types
import IHaskell.Display.Widgets.Common
import IHaskell.Display.Widgets.Layout.LayoutWidget
import IHaskell.Display.Widgets.Style.DescriptionStyle
type TextArea = IPythonWidget 'TextAreaType
mkTextArea :: IO TextArea
mkTextArea :: IO TextArea
mkTextArea = do
UUID
wid <- IO UUID
U.random
IPythonWidget 'LayoutType
layout <- IO (IPythonWidget 'LayoutType)
mkLayout
DescriptionStyle
dstyle <- IO DescriptionStyle
mkDescriptionStyle
let strAttrs :: Rec Attr StringClass
strAttrs = FieldType 'ViewName
-> FieldType 'ModelName
-> IPythonWidget 'LayoutType
-> StyleWidget
-> Rec Attr StringClass
defaultStringWidget Text
"TextareaView" Text
"TextareaModel" IPythonWidget 'LayoutType
layout forall a b. (a -> b) -> a -> b
$ forall (w :: WidgetType).
RecAll Attr (WidgetFields w) ToPairs =>
IPythonWidget w -> StyleWidget
StyleWidget DescriptionStyle
dstyle
wgtAttrs :: Rec Attr '[ 'Rows, 'Disabled, 'ContinuousUpdate, 'ChangeHandler]
wgtAttrs = (forall {a :: Field}. (a ~ 'Rows) => SField a
Rows forall (f :: Field).
(SingI f, Typeable (FieldType f)) =>
Sing f -> FieldType f -> Attr f
=:: forall a. Maybe a
Nothing)
forall {u} (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& (forall {a :: Field}. (a ~ 'Disabled) => SField a
Disabled forall (f :: Field).
(SingI f, Typeable (FieldType f)) =>
Sing f -> FieldType f -> Attr f
=:: Bool
False)
forall {u} (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& (forall {a :: Field}. (a ~ 'ContinuousUpdate) => SField a
ContinuousUpdate forall (f :: Field).
(SingI f, Typeable (FieldType f)) =>
Sing f -> FieldType f -> Attr f
=:: Bool
True)
forall {u} (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& (forall {a :: Field}. (a ~ 'ChangeHandler) => SField a
ChangeHandler forall (f :: Field).
(SingI f, Typeable (FieldType f)) =>
Sing f -> FieldType f -> Attr f
=:: forall (m :: * -> *) a. Monad m => a -> m a
return ())
forall {u} (a :: u -> *) (r :: u) (rs :: [u]).
a r -> Rec a rs -> Rec a (r : rs)
:& forall {u} (a :: u -> *). Rec a '[]
RNil
widgetState :: WidgetState 'TextAreaType
widgetState = forall (w :: WidgetType).
Rec Attr (WidgetFields w) -> WidgetState w
WidgetState forall a b. (a -> b) -> a -> b
$ Rec
Attr
'[ 'ViewModule, 'ViewModuleVersion, 'ModelModule,
'ModelModuleVersion, 'ModelName, 'ViewName, 'DOMClasses, 'Tooltip,
'Layout, 'DisplayHandler, 'Description, 'Style, 'StringValue,
'Placeholder]
strAttrs forall {k} (f :: k -> *) (as :: [k]) (bs :: [k]).
Rec f as -> Rec f bs -> Rec f (as ++ bs)
<+> Rec Attr '[ 'Rows, 'Disabled, 'ContinuousUpdate, 'ChangeHandler]
wgtAttrs
IORef (WidgetState 'TextAreaType)
stateIO <- forall a. a -> IO (IORef a)
newIORef WidgetState 'TextAreaType
widgetState
let widget :: TextArea
widget = forall (w :: WidgetType).
UUID -> IORef (WidgetState w) -> IPythonWidget w
IPythonWidget UUID
wid IORef (WidgetState 'TextAreaType)
stateIO
forall a. IHaskellWidget a => a -> Value -> IO ()
widgetSendOpen TextArea
widget forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> Value
toJSON WidgetState 'TextAreaType
widgetState
forall (m :: * -> *) a. Monad m => a -> m a
return TextArea
widget
instance IHaskellWidget TextArea where
getCommUUID :: TextArea -> UUID
getCommUUID = forall (w :: WidgetType). IPythonWidget w -> UUID
uuid
comm :: TextArea -> Value -> (Value -> IO ()) -> IO ()
comm TextArea
widget Value
val Value -> IO ()
_ =
case Value -> [Text] -> Maybe Value
nestedObjectLookup Value
val [Text
"state", Text
"value"] of
Just (String Text
value) -> do
forall (f :: * -> *) a. Functor f => f a -> f ()
void forall a b. (a -> b) -> a -> b
$ forall (f :: Field) (w :: WidgetType).
(f ∈ WidgetFields w, IHaskellWidget (IPythonWidget w)) =>
IPythonWidget w -> SField f -> FieldType f -> IO (Attr f)
setField' TextArea
widget forall {a :: Field}. (a ~ 'StringValue) => SField a
StringValue Text
value
forall (w :: WidgetType).
('ChangeHandler ∈ WidgetFields w) =>
IPythonWidget w -> IO ()
triggerChange TextArea
widget
Maybe Value
_ -> forall (f :: * -> *) a. Applicative f => a -> f a
pure ()