|
|
|
@ -12,14 +12,16 @@
|
|
|
|
|
{-# LANGUAGE BangPatterns #-}
|
|
|
|
|
{-# LANGUAGE ConstraintKinds #-}
|
|
|
|
|
{-# LANGUAGE ExistentialQuantification #-}
|
|
|
|
|
|
|
|
|
|
module IHaskell.Display.Widgets.Types where
|
|
|
|
|
|
|
|
|
|
-- | This module houses all the type-trickery needed to make widgets happen.
|
|
|
|
|
--
|
|
|
|
|
-- All widgets have a corresponding 'WidgetType', and some fields/attributes/properties as defined by
|
|
|
|
|
-- the 'WidgetFields' type-family.
|
|
|
|
|
-- All widgets have a corresponding 'WidgetType', and some fields/attributes/properties as defined
|
|
|
|
|
-- by the 'WidgetFields' type-family.
|
|
|
|
|
--
|
|
|
|
|
-- Each widget field corresponds to a concrete haskell type, as given by the 'FieldType' type-family.
|
|
|
|
|
-- Each widget field corresponds to a concrete haskell type, as given by the 'FieldType'
|
|
|
|
|
-- type-family.
|
|
|
|
|
--
|
|
|
|
|
-- Vinyl records are used to wrap together widget fields into a single 'WidgetState'.
|
|
|
|
|
--
|
|
|
|
@ -29,28 +31,31 @@ module IHaskell.Display.Widgets.Types where
|
|
|
|
|
-- SViewName :: SField ViewName
|
|
|
|
|
-- @
|
|
|
|
|
--
|
|
|
|
|
-- This allows the user to pass the type 'ViewName' without using Data.Proxy. In essence, a singleton
|
|
|
|
|
-- is the only inhabitant (other than bottom) of a promoted type. Single element set/type == singleton.
|
|
|
|
|
-- This allows the user to pass the type 'ViewName' without using Data.Proxy. In essence, a
|
|
|
|
|
-- singleton is the only inhabitant (other than bottom) of a promoted type. Single element set/type
|
|
|
|
|
-- == singleton.
|
|
|
|
|
--
|
|
|
|
|
-- It also allows the record to wrap values of properties with information about their Field type. A
|
|
|
|
|
-- vinyl record is represented as @Rec f ts@, which means that a record is a list of @f x@, where @x@
|
|
|
|
|
-- is a type present in the type-level list @ts@. Thus a 'WidgetState' is essentially a list of field
|
|
|
|
|
-- properties wrapped together with the corresponding promoted Field type. See ('=::') for more.
|
|
|
|
|
-- vinyl record is represented as @Rec f ts@, which means that a record is a list of @f x@, where
|
|
|
|
|
-- @x@ is a type present in the type-level list @ts@. Thus a 'WidgetState' is essentially a list of
|
|
|
|
|
-- field properties wrapped together with the corresponding promoted Field type. See ('=::') for
|
|
|
|
|
-- more.
|
|
|
|
|
--
|
|
|
|
|
-- The properties function can be used to view all the @Field@s associated with a widget object.
|
|
|
|
|
--
|
|
|
|
|
-- Attributes are represented by the @Attr@ data type, which holds the value of a field, along with
|
|
|
|
|
-- the actual @Field@ object and a function to verify validity of changes to the value.
|
|
|
|
|
--
|
|
|
|
|
-- The IPython widgets expect state updates of the form {"property": value}, where an empty string for
|
|
|
|
|
-- numeric values is ignored by the frontend and the default value is used instead. Some numbers need to
|
|
|
|
|
-- be sent as numbers (represented by @Integer@), whereas some need to be sent as Strings (@StrInt@).
|
|
|
|
|
-- The IPython widgets expect state updates of the form {"property": value}, where an empty string
|
|
|
|
|
-- for numeric values is ignored by the frontend and the default value is used instead. Some numbers
|
|
|
|
|
-- need to be sent as numbers (represented by @Integer@), whereas some need to be sent as Strings
|
|
|
|
|
-- (@StrInt@).
|
|
|
|
|
--
|
|
|
|
|
-- Child widgets are expected to be sent as strings of the form "IPY_MODEL_<uuid>", where @<uuid>@
|
|
|
|
|
-- represents the uuid of the widget's comm.
|
|
|
|
|
--
|
|
|
|
|
-- To know more about the IPython messaging specification (as implemented in this package) take a look
|
|
|
|
|
-- at the supplied MsgSpec.md.
|
|
|
|
|
-- To know more about the IPython messaging specification (as implemented in this package) take a
|
|
|
|
|
-- look at the supplied MsgSpec.md.
|
|
|
|
|
--
|
|
|
|
|
-- Widgets are not able to do console input, the reason for that can also be found in the messaging
|
|
|
|
|
-- specification
|
|
|
|
@ -67,8 +72,8 @@ import Data.Aeson.Types (Pair)
|
|
|
|
|
import Data.IORef (IORef, readIORef, modifyIORef)
|
|
|
|
|
import Data.Text (Text, pack)
|
|
|
|
|
|
|
|
|
|
import Data.Vinyl (Rec (..), (<+>), recordToList, reifyConstraint, rmap, Dict (..))
|
|
|
|
|
import Data.Vinyl.Functor (Compose (..), Const (..))
|
|
|
|
|
import Data.Vinyl (Rec(..), (<+>), recordToList, reifyConstraint, rmap, Dict(..))
|
|
|
|
|
import Data.Vinyl.Functor (Compose(..), Const(..))
|
|
|
|
|
import Data.Vinyl.Lens (rget, rput, type (∈))
|
|
|
|
|
import Data.Vinyl.TypeLevel (RecAll)
|
|
|
|
|
|
|
|
|
@ -76,38 +81,54 @@ import Data.Singletons.Prelude ((:++))
|
|
|
|
|
import Data.Singletons.TH
|
|
|
|
|
|
|
|
|
|
import IHaskell.Eval.Widgets (widgetSendUpdate)
|
|
|
|
|
import IHaskell.Display (Base64, IHaskellWidget (..))
|
|
|
|
|
import IHaskell.Display (Base64, IHaskellWidget(..))
|
|
|
|
|
import IHaskell.IPython.Message.UUID
|
|
|
|
|
|
|
|
|
|
import IHaskell.Display.Widgets.Singletons (Field, SField (..))
|
|
|
|
|
import IHaskell.Display.Widgets.Singletons (Field, SField(..))
|
|
|
|
|
import qualified IHaskell.Display.Widgets.Singletons as S
|
|
|
|
|
import IHaskell.Display.Widgets.Common
|
|
|
|
|
|
|
|
|
|
-- Classes from IPython's widget hierarchy. Defined as such to reduce code duplication.
|
|
|
|
|
type WidgetClass = '[ S.ViewModule, S.ViewName, S.MsgThrottle, S.Version, S.DisplayHandler ]
|
|
|
|
|
type DOMWidgetClass = WidgetClass :++
|
|
|
|
|
'[ S.Visible, S.CSS, S.DOMClasses, S.Width, S.Height, S.Padding, S.Margin, S.Color
|
|
|
|
|
, S.BackgroundColor, S.BorderColor, S.BorderWidth, S.BorderRadius, S.BorderStyle, S.FontStyle
|
|
|
|
|
, S.FontWeight, S.FontSize, S.FontFamily
|
|
|
|
|
]
|
|
|
|
|
type WidgetClass = '[S.ViewModule, S.ViewName, S.MsgThrottle, S.Version,
|
|
|
|
|
S.DisplayHandler]
|
|
|
|
|
|
|
|
|
|
type DOMWidgetClass = WidgetClass :++ '[S.Visible, S.CSS, S.DOMClasses, S.Width, S.Height, S.Padding,
|
|
|
|
|
S.Margin, S.Color, S.BackgroundColor, S.BorderColor, S.BorderWidth,
|
|
|
|
|
S.BorderRadius, S.BorderStyle, S.FontStyle, S.FontWeight,
|
|
|
|
|
S.FontSize, S.FontFamily]
|
|
|
|
|
|
|
|
|
|
type StringClass = DOMWidgetClass :++ '[S.StringValue, S.Disabled, S.Description, S.Placeholder]
|
|
|
|
|
|
|
|
|
|
type BoolClass = DOMWidgetClass :++ '[S.BoolValue, S.Disabled, S.Description, S.ChangeHandler]
|
|
|
|
|
type SelectionClass = DOMWidgetClass :++
|
|
|
|
|
'[S.Options, S.SelectedValue, S.SelectedLabel, S.Disabled, S.Description, S.SelectionHandler]
|
|
|
|
|
type MultipleSelectionClass = DOMWidgetClass :++
|
|
|
|
|
'[S.Options, S.SelectedLabels, S.SelectedValues, S.Disabled, S.Description, S.SelectionHandler]
|
|
|
|
|
|
|
|
|
|
type SelectionClass = DOMWidgetClass :++ '[S.Options, S.SelectedValue, S.SelectedLabel, S.Disabled,
|
|
|
|
|
S.Description, S.SelectionHandler]
|
|
|
|
|
|
|
|
|
|
type MultipleSelectionClass = DOMWidgetClass :++ '[S.Options, S.SelectedLabels, S.SelectedValues, S.Disabled,
|
|
|
|
|
S.Description, S.SelectionHandler]
|
|
|
|
|
|
|
|
|
|
type IntClass = DOMWidgetClass :++ '[S.IntValue, S.Disabled, S.Description, S.ChangeHandler]
|
|
|
|
|
|
|
|
|
|
type BoundedIntClass = IntClass :++ '[S.StepInt, S.MinInt, S.MaxInt]
|
|
|
|
|
|
|
|
|
|
type IntRangeClass = IntClass :++ '[S.IntPairValue, S.LowerInt, S.UpperInt]
|
|
|
|
|
|
|
|
|
|
type BoundedIntRangeClass = IntRangeClass :++ '[S.StepInt, S.MinInt, S.MaxInt]
|
|
|
|
|
|
|
|
|
|
type FloatClass = DOMWidgetClass :++ '[S.FloatValue, S.Disabled, S.Description, S.ChangeHandler]
|
|
|
|
|
|
|
|
|
|
type BoundedFloatClass = FloatClass :++ '[S.StepFloat, S.MinFloat, S.MaxFloat]
|
|
|
|
|
|
|
|
|
|
type FloatRangeClass = FloatClass :++ '[S.FloatPairValue, S.LowerFloat, S.UpperFloat]
|
|
|
|
|
|
|
|
|
|
type BoundedFloatRangeClass = FloatRangeClass :++ '[S.StepFloat, S.MinFloat, S.MaxFloat]
|
|
|
|
|
|
|
|
|
|
type BoxClass = DOMWidgetClass :++ '[S.Children, S.OverflowX, S.OverflowY, S.BoxStyle]
|
|
|
|
|
|
|
|
|
|
type SelectionContainerClass = BoxClass :++ '[S.Titles, S.SelectedIndex, S.ChangeHandler]
|
|
|
|
|
|
|
|
|
|
-- Types associated with Fields.
|
|
|
|
|
|
|
|
|
|
type family FieldType (f :: Field) :: * where
|
|
|
|
|
FieldType S.ViewModule = Text
|
|
|
|
|
FieldType S.ViewName = Text
|
|
|
|
@ -196,14 +217,14 @@ class CustomBounded a where
|
|
|
|
|
-- Set according to what IPython widgets use
|
|
|
|
|
instance CustomBounded StrInt where
|
|
|
|
|
upperBound = 10 ^ 16 - 1
|
|
|
|
|
lowerBound = - (10 ^ 16 - 1)
|
|
|
|
|
lowerBound = -(10 ^ 16 - 1)
|
|
|
|
|
|
|
|
|
|
instance CustomBounded Integer where
|
|
|
|
|
lowerBound = - (10 ^ 16 - 1)
|
|
|
|
|
lowerBound = -(10 ^ 16 - 1)
|
|
|
|
|
upperBound = 10 ^ 16 - 1
|
|
|
|
|
|
|
|
|
|
instance CustomBounded Double where
|
|
|
|
|
lowerBound = - (10 ** 16 - 1)
|
|
|
|
|
lowerBound = -(10 ** 16 - 1)
|
|
|
|
|
upperBound = 10 ** 16 - 1
|
|
|
|
|
|
|
|
|
|
-- Different types of widgets. Every widget in IPython has a corresponding WidgetType
|
|
|
|
@ -237,38 +258,57 @@ data WidgetType = ButtonType
|
|
|
|
|
| TabType
|
|
|
|
|
|
|
|
|
|
-- Fields associated with a widget
|
|
|
|
|
|
|
|
|
|
type family WidgetFields (w :: WidgetType) :: [Field] where
|
|
|
|
|
WidgetFields ButtonType = DOMWidgetClass :++ '[S.Description, S.Tooltip, S.Disabled, S.Icon, S.ButtonStyle, S.ClickHandler]
|
|
|
|
|
WidgetFields ImageType = DOMWidgetClass :++ '[S.ImageFormat, S.B64Value]
|
|
|
|
|
WidgetFields ButtonType =
|
|
|
|
|
DOMWidgetClass :++
|
|
|
|
|
'[S.Description, S.Tooltip, S.Disabled, S.Icon, S.ButtonStyle,
|
|
|
|
|
S.ClickHandler]
|
|
|
|
|
WidgetFields ImageType =
|
|
|
|
|
DOMWidgetClass :++ '[S.ImageFormat, S.B64Value]
|
|
|
|
|
WidgetFields OutputType = DOMWidgetClass
|
|
|
|
|
WidgetFields HTMLType = StringClass
|
|
|
|
|
WidgetFields LatexType = StringClass
|
|
|
|
|
WidgetFields TextType = StringClass :++ '[S.SubmitHandler, S.ChangeHandler]
|
|
|
|
|
WidgetFields TextType =
|
|
|
|
|
StringClass :++ '[S.SubmitHandler, S.ChangeHandler]
|
|
|
|
|
WidgetFields TextAreaType = StringClass :++ '[S.ChangeHandler]
|
|
|
|
|
WidgetFields CheckBoxType = BoolClass
|
|
|
|
|
WidgetFields ToggleButtonType = BoolClass :++ '[S.Tooltip, S.Icon, S.ButtonStyle]
|
|
|
|
|
WidgetFields ToggleButtonType =
|
|
|
|
|
BoolClass :++ '[S.Tooltip, S.Icon, S.ButtonStyle]
|
|
|
|
|
WidgetFields DropdownType = SelectionClass :++ '[S.ButtonStyle]
|
|
|
|
|
WidgetFields RadioButtonsType = SelectionClass
|
|
|
|
|
WidgetFields SelectType = SelectionClass
|
|
|
|
|
WidgetFields ToggleButtonsType = SelectionClass :++ '[S.Tooltips, S.Icons, S.ButtonStyle]
|
|
|
|
|
WidgetFields ToggleButtonsType =
|
|
|
|
|
SelectionClass :++ '[S.Tooltips, S.Icons, S.ButtonStyle]
|
|
|
|
|
WidgetFields SelectMultipleType = MultipleSelectionClass
|
|
|
|
|
WidgetFields IntTextType = IntClass
|
|
|
|
|
WidgetFields BoundedIntTextType = BoundedIntClass
|
|
|
|
|
WidgetFields IntSliderType = BoundedIntClass :++ '[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields IntSliderType =
|
|
|
|
|
BoundedIntClass :++
|
|
|
|
|
'[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields IntProgressType = BoundedIntClass :++ '[S.BarStyle]
|
|
|
|
|
WidgetFields IntRangeSliderType = BoundedIntRangeClass :++ '[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields IntRangeSliderType =
|
|
|
|
|
BoundedIntRangeClass :++
|
|
|
|
|
'[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields FloatTextType = FloatClass
|
|
|
|
|
WidgetFields BoundedFloatTextType = BoundedFloatClass
|
|
|
|
|
WidgetFields FloatSliderType = BoundedFloatClass :++ '[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields FloatProgressType = BoundedFloatClass :++ '[S.BarStyle]
|
|
|
|
|
WidgetFields FloatRangeSliderType = BoundedFloatRangeClass :++ '[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields FloatSliderType =
|
|
|
|
|
BoundedFloatClass :++
|
|
|
|
|
'[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields FloatProgressType =
|
|
|
|
|
BoundedFloatClass :++ '[S.BarStyle]
|
|
|
|
|
WidgetFields FloatRangeSliderType =
|
|
|
|
|
BoundedFloatRangeClass :++
|
|
|
|
|
'[S.Orientation, S.ShowRange, S.ReadOut, S.SliderColor]
|
|
|
|
|
WidgetFields BoxType = BoxClass
|
|
|
|
|
WidgetFields FlexBoxType = BoxClass :++ '[S.Orientation, S.Flex, S.Pack, S.Align]
|
|
|
|
|
WidgetFields FlexBoxType =
|
|
|
|
|
BoxClass :++ '[S.Orientation, S.Flex, S.Pack, S.Align]
|
|
|
|
|
WidgetFields AccordionType = SelectionContainerClass
|
|
|
|
|
WidgetFields TabType = SelectionContainerClass
|
|
|
|
|
|
|
|
|
|
-- Wrapper around a field's value. A dummy value is sent as an empty string to the frontend.
|
|
|
|
|
data AttrVal a = Dummy a | Real a
|
|
|
|
|
data AttrVal a = Dummy a
|
|
|
|
|
| Real a
|
|
|
|
|
|
|
|
|
|
unwrap :: AttrVal a -> a
|
|
|
|
|
unwrap (Dummy x) = x
|
|
|
|
@ -276,13 +316,15 @@ unwrap (Real x) = x
|
|
|
|
|
|
|
|
|
|
-- Wrapper around a field.
|
|
|
|
|
data Attr (f :: Field) =
|
|
|
|
|
Attr { _value :: AttrVal (FieldType f)
|
|
|
|
|
Attr
|
|
|
|
|
{ _value :: AttrVal (FieldType f)
|
|
|
|
|
, _verify :: FieldType f -> IO (FieldType f)
|
|
|
|
|
, _field :: Field
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
instance ToJSON (FieldType f) => ToJSON (Attr f) where
|
|
|
|
|
toJSON attr = case _value attr of
|
|
|
|
|
toJSON attr =
|
|
|
|
|
case _value attr of
|
|
|
|
|
Dummy _ -> ""
|
|
|
|
|
Real x -> toJSON x
|
|
|
|
|
|
|
|
|
@ -291,82 +333,224 @@ class ToPairs a where
|
|
|
|
|
toPairs :: a -> [Pair]
|
|
|
|
|
|
|
|
|
|
-- Attributes that aren't synced with the frontend give [] on toPairs
|
|
|
|
|
instance ToPairs (Attr S.ViewModule) where toPairs x = ["_view_module" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ViewName) where toPairs x = ["_view_name" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.MsgThrottle) where toPairs x = ["msg_throttle" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Version) where toPairs x = ["version" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.DisplayHandler) where toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
instance ToPairs (Attr S.Visible) where toPairs x = ["visible" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.CSS) where toPairs x = ["_css" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.DOMClasses) where toPairs x = ["_dom_classes" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Width) where toPairs x = ["width" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Height) where toPairs x = ["height" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Padding) where toPairs x = ["padding" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Margin) where toPairs x = ["margin" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Color) where toPairs x = ["color" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BackgroundColor) where toPairs x = ["background_color" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BorderColor) where toPairs x = ["border_color" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BorderWidth) where toPairs x = ["border_width" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BorderRadius) where toPairs x = ["border_radius" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BorderStyle) where toPairs x = ["border_style" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.FontStyle) where toPairs x = ["font_style" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.FontWeight) where toPairs x = ["font_weight" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.FontSize) where toPairs x = ["font_size" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.FontFamily) where toPairs x = ["font_family" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Description) where toPairs x = ["description" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ClickHandler) where toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
instance ToPairs (Attr S.SubmitHandler) where toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
instance ToPairs (Attr S.Disabled) where toPairs x = ["disabled" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.StringValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Placeholder) where toPairs x = ["placeholder" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Tooltip) where toPairs x = ["tooltip" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Icon) where toPairs x = ["icon" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ButtonStyle) where toPairs x = ["button_style" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.B64Value) where toPairs x = ["_b64value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ImageFormat) where toPairs x = ["format" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BoolValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.SelectedLabel) where toPairs x = ["selected_label" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.SelectedValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ViewModule) where
|
|
|
|
|
toPairs x = ["_view_module" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ViewName) where
|
|
|
|
|
toPairs x = ["_view_name" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.MsgThrottle) where
|
|
|
|
|
toPairs x = ["msg_throttle" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Version) where
|
|
|
|
|
toPairs x = ["version" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.DisplayHandler) where
|
|
|
|
|
toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Visible) where
|
|
|
|
|
toPairs x = ["visible" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.CSS) where
|
|
|
|
|
toPairs x = ["_css" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.DOMClasses) where
|
|
|
|
|
toPairs x = ["_dom_classes" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Width) where
|
|
|
|
|
toPairs x = ["width" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Height) where
|
|
|
|
|
toPairs x = ["height" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Padding) where
|
|
|
|
|
toPairs x = ["padding" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Margin) where
|
|
|
|
|
toPairs x = ["margin" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Color) where
|
|
|
|
|
toPairs x = ["color" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BackgroundColor) where
|
|
|
|
|
toPairs x = ["background_color" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BorderColor) where
|
|
|
|
|
toPairs x = ["border_color" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BorderWidth) where
|
|
|
|
|
toPairs x = ["border_width" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BorderRadius) where
|
|
|
|
|
toPairs x = ["border_radius" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BorderStyle) where
|
|
|
|
|
toPairs x = ["border_style" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.FontStyle) where
|
|
|
|
|
toPairs x = ["font_style" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.FontWeight) where
|
|
|
|
|
toPairs x = ["font_weight" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.FontSize) where
|
|
|
|
|
toPairs x = ["font_size" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.FontFamily) where
|
|
|
|
|
toPairs x = ["font_family" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Description) where
|
|
|
|
|
toPairs x = ["description" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ClickHandler) where
|
|
|
|
|
toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SubmitHandler) where
|
|
|
|
|
toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Disabled) where
|
|
|
|
|
toPairs x = ["disabled" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.StringValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Placeholder) where
|
|
|
|
|
toPairs x = ["placeholder" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Tooltip) where
|
|
|
|
|
toPairs x = ["tooltip" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Icon) where
|
|
|
|
|
toPairs x = ["icon" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ButtonStyle) where
|
|
|
|
|
toPairs x = ["button_style" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.B64Value) where
|
|
|
|
|
toPairs x = ["_b64value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ImageFormat) where
|
|
|
|
|
toPairs x = ["format" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BoolValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SelectedLabel) where
|
|
|
|
|
toPairs x = ["selected_label" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SelectedValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Options) where
|
|
|
|
|
toPairs x = case _value x of
|
|
|
|
|
toPairs x =
|
|
|
|
|
case _value x of
|
|
|
|
|
Dummy _ -> labels ("" :: Text)
|
|
|
|
|
Real (OptionLabels xs) -> labels xs
|
|
|
|
|
Real (OptionDict xps) -> labels $ map fst xps
|
|
|
|
|
where labels xs = ["_options_labels" .= xs]
|
|
|
|
|
instance ToPairs (Attr S.SelectionHandler) where toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
instance ToPairs (Attr S.Tooltips) where toPairs x = ["tooltips" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Icons) where toPairs x = ["icons" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.SelectedLabels) where toPairs x = ["selected_labels" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.SelectedValues) where toPairs x = ["values" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.IntValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.StepInt) where toPairs x = ["step" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.MinInt) where toPairs x = ["min" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.MaxInt) where toPairs x = ["max" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.IntPairValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.LowerInt) where toPairs x = ["min" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.UpperInt) where toPairs x = ["max" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.FloatValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.StepFloat) where toPairs x = ["step" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.MinFloat) where toPairs x = ["min" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.MaxFloat) where toPairs x = ["max" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.FloatPairValue) where toPairs x = ["value" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.LowerFloat) where toPairs x = ["min" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.UpperFloat) where toPairs x = ["max" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Orientation) where toPairs x = ["orientation" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ShowRange) where toPairs x = ["_range" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ReadOut) where toPairs x = ["readout" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.SliderColor) where toPairs x = ["slider_color" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BarStyle) where toPairs x = ["bar_style" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.ChangeHandler) where toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
instance ToPairs (Attr S.Children) where toPairs x = ["children" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.OverflowX) where toPairs x = ["overflow_x" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.OverflowY) where toPairs x = ["overflow_y" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.BoxStyle) where toPairs x = ["box_style" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Flex) where toPairs x = ["flex" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Pack) where toPairs x = ["pack" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Align) where toPairs x = ["align" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.Titles) where toPairs x = ["_titles" .= toJSON x]
|
|
|
|
|
instance ToPairs (Attr S.SelectedIndex) where toPairs x = ["selected_index" .= toJSON x]
|
|
|
|
|
where
|
|
|
|
|
labels xs = ["_options_labels" .= xs]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SelectionHandler) where
|
|
|
|
|
toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Tooltips) where
|
|
|
|
|
toPairs x = ["tooltips" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Icons) where
|
|
|
|
|
toPairs x = ["icons" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SelectedLabels) where
|
|
|
|
|
toPairs x = ["selected_labels" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SelectedValues) where
|
|
|
|
|
toPairs x = ["values" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.IntValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.StepInt) where
|
|
|
|
|
toPairs x = ["step" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.MinInt) where
|
|
|
|
|
toPairs x = ["min" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.MaxInt) where
|
|
|
|
|
toPairs x = ["max" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.IntPairValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.LowerInt) where
|
|
|
|
|
toPairs x = ["min" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.UpperInt) where
|
|
|
|
|
toPairs x = ["max" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.FloatValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.StepFloat) where
|
|
|
|
|
toPairs x = ["step" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.MinFloat) where
|
|
|
|
|
toPairs x = ["min" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.MaxFloat) where
|
|
|
|
|
toPairs x = ["max" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.FloatPairValue) where
|
|
|
|
|
toPairs x = ["value" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.LowerFloat) where
|
|
|
|
|
toPairs x = ["min" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.UpperFloat) where
|
|
|
|
|
toPairs x = ["max" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Orientation) where
|
|
|
|
|
toPairs x = ["orientation" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ShowRange) where
|
|
|
|
|
toPairs x = ["_range" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ReadOut) where
|
|
|
|
|
toPairs x = ["readout" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SliderColor) where
|
|
|
|
|
toPairs x = ["slider_color" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BarStyle) where
|
|
|
|
|
toPairs x = ["bar_style" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.ChangeHandler) where
|
|
|
|
|
toPairs _ = [] -- Not sent to the frontend
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Children) where
|
|
|
|
|
toPairs x = ["children" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.OverflowX) where
|
|
|
|
|
toPairs x = ["overflow_x" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.OverflowY) where
|
|
|
|
|
toPairs x = ["overflow_y" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.BoxStyle) where
|
|
|
|
|
toPairs x = ["box_style" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Flex) where
|
|
|
|
|
toPairs x = ["flex" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Pack) where
|
|
|
|
|
toPairs x = ["pack" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Align) where
|
|
|
|
|
toPairs x = ["align" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.Titles) where
|
|
|
|
|
toPairs x = ["_titles" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
instance ToPairs (Attr S.SelectedIndex) where
|
|
|
|
|
toPairs x = ["selected_index" .= toJSON x]
|
|
|
|
|
|
|
|
|
|
-- | Store the value for a field, as an object parametrized by the Field. No verification is done
|
|
|
|
|
-- for these values.
|
|
|
|
@ -391,10 +575,15 @@ ranged s range x = Attr x (rangeCheck range) (reflect s)
|
|
|
|
|
-- dummy value if it's equal to zero.
|
|
|
|
|
(=:+) :: (SingI f, Num (FieldType f), CustomBounded (FieldType f), Ord (FieldType f))
|
|
|
|
|
=> Sing f -> FieldType f -> Attr f
|
|
|
|
|
s =:+ val = Attr ((if val == 0 then Dummy else Real) val) (rangeCheck (0, upperBound)) (reflect s)
|
|
|
|
|
s =:+ val = Attr
|
|
|
|
|
((if val == 0
|
|
|
|
|
then Dummy
|
|
|
|
|
else Real)
|
|
|
|
|
val)
|
|
|
|
|
(rangeCheck (0, upperBound))
|
|
|
|
|
(reflect s)
|
|
|
|
|
|
|
|
|
|
-- | Get a field from a singleton
|
|
|
|
|
-- Adapted from: http://stackoverflow.com/a/28033250/2388535
|
|
|
|
|
-- | Get a field from a singleton Adapted from: http://stackoverflow.com/a/28033250/2388535
|
|
|
|
|
reflect :: forall (f :: Field). (SingI f, SingKind ('KProxy :: KProxy Field)) => Sing f -> Field
|
|
|
|
|
reflect = fromSing
|
|
|
|
|
|
|
|
|
@ -410,7 +599,8 @@ defaultWidget viewName = (ViewModule =:: "")
|
|
|
|
|
-- | A record representing an object of the DOMWidget class from IPython
|
|
|
|
|
defaultDOMWidget :: FieldType S.ViewName -> Rec Attr DOMWidgetClass
|
|
|
|
|
defaultDOMWidget viewName = defaultWidget viewName <+> domAttrs
|
|
|
|
|
where domAttrs = (Visible =:: True)
|
|
|
|
|
where
|
|
|
|
|
domAttrs = (Visible =:: True)
|
|
|
|
|
:& (CSS =:: [])
|
|
|
|
|
:& (DOMClasses =:: [])
|
|
|
|
|
:& (Width =:+ 0)
|
|
|
|
@ -432,7 +622,8 @@ defaultDOMWidget viewName = defaultWidget viewName <+> domAttrs
|
|
|
|
|
-- | A record representing a widget of the _String class from IPython
|
|
|
|
|
defaultStringWidget :: FieldType S.ViewName -> Rec Attr StringClass
|
|
|
|
|
defaultStringWidget viewName = defaultDOMWidget viewName <+> strAttrs
|
|
|
|
|
where strAttrs = (StringValue =:: "")
|
|
|
|
|
where
|
|
|
|
|
strAttrs = (StringValue =:: "")
|
|
|
|
|
:& (Disabled =:: False)
|
|
|
|
|
:& (Description =:: "")
|
|
|
|
|
:& (Placeholder =:: "")
|
|
|
|
@ -441,7 +632,8 @@ defaultStringWidget viewName = defaultDOMWidget viewName <+> strAttrs
|
|
|
|
|
-- | A record representing a widget of the _Bool class from IPython
|
|
|
|
|
defaultBoolWidget :: FieldType S.ViewName -> Rec Attr BoolClass
|
|
|
|
|
defaultBoolWidget viewName = defaultDOMWidget viewName <+> boolAttrs
|
|
|
|
|
where boolAttrs = (BoolValue =:: False)
|
|
|
|
|
where
|
|
|
|
|
boolAttrs = (BoolValue =:: False)
|
|
|
|
|
:& (Disabled =:: False)
|
|
|
|
|
:& (Description =:: "")
|
|
|
|
|
:& (ChangeHandler =:: return ())
|
|
|
|
@ -450,7 +642,8 @@ defaultBoolWidget viewName = defaultDOMWidget viewName <+> boolAttrs
|
|
|
|
|
-- | A record representing a widget of the _Selection class from IPython
|
|
|
|
|
defaultSelectionWidget :: FieldType S.ViewName -> Rec Attr SelectionClass
|
|
|
|
|
defaultSelectionWidget viewName = defaultDOMWidget viewName <+> selectionAttrs
|
|
|
|
|
where selectionAttrs = (Options =:: OptionLabels [])
|
|
|
|
|
where
|
|
|
|
|
selectionAttrs = (Options =:: OptionLabels [])
|
|
|
|
|
:& (SelectedValue =:: "")
|
|
|
|
|
:& (SelectedLabel =:: "")
|
|
|
|
|
:& (Disabled =:: False)
|
|
|
|
@ -461,7 +654,8 @@ defaultSelectionWidget viewName = defaultDOMWidget viewName <+> selectionAttrs
|
|
|
|
|
-- | A record representing a widget of the _MultipleSelection class from IPython
|
|
|
|
|
defaultMultipleSelectionWidget :: FieldType S.ViewName -> Rec Attr MultipleSelectionClass
|
|
|
|
|
defaultMultipleSelectionWidget viewName = defaultDOMWidget viewName <+> mulSelAttrs
|
|
|
|
|
where mulSelAttrs = (Options =:: OptionLabels [])
|
|
|
|
|
where
|
|
|
|
|
mulSelAttrs = (Options =:: OptionLabels [])
|
|
|
|
|
:& (SelectedLabels =:: [])
|
|
|
|
|
:& (SelectedValues =:: [])
|
|
|
|
|
:& (Disabled =:: False)
|
|
|
|
@ -472,7 +666,8 @@ defaultMultipleSelectionWidget viewName = defaultDOMWidget viewName <+> mulSelAt
|
|
|
|
|
-- | A record representing a widget of the _Int class from IPython
|
|
|
|
|
defaultIntWidget :: FieldType S.ViewName -> Rec Attr IntClass
|
|
|
|
|
defaultIntWidget viewName = defaultDOMWidget viewName <+> intAttrs
|
|
|
|
|
where intAttrs = (IntValue =:: 0)
|
|
|
|
|
where
|
|
|
|
|
intAttrs = (IntValue =:: 0)
|
|
|
|
|
:& (Disabled =:: False)
|
|
|
|
|
:& (Description =:: "")
|
|
|
|
|
:& (ChangeHandler =:: return ())
|
|
|
|
@ -481,7 +676,8 @@ defaultIntWidget viewName = defaultDOMWidget viewName <+> intAttrs
|
|
|
|
|
-- | A record representing a widget of the _BoundedInt class from IPython
|
|
|
|
|
defaultBoundedIntWidget :: FieldType S.ViewName -> Rec Attr BoundedIntClass
|
|
|
|
|
defaultBoundedIntWidget viewName = defaultIntWidget viewName <+> boundedIntAttrs
|
|
|
|
|
where boundedIntAttrs = (StepInt =:: 1)
|
|
|
|
|
where
|
|
|
|
|
boundedIntAttrs = (StepInt =:: 1)
|
|
|
|
|
:& (MinInt =:: 0)
|
|
|
|
|
:& (MaxInt =:: 100)
|
|
|
|
|
:& RNil
|
|
|
|
@ -489,7 +685,8 @@ defaultBoundedIntWidget viewName = defaultIntWidget viewName <+> boundedIntAttrs
|
|
|
|
|
-- | A record representing a widget of the _BoundedInt class from IPython
|
|
|
|
|
defaultIntRangeWidget :: FieldType S.ViewName -> Rec Attr IntRangeClass
|
|
|
|
|
defaultIntRangeWidget viewName = defaultIntWidget viewName <+> rangeAttrs
|
|
|
|
|
where rangeAttrs = (IntPairValue =:: (25, 75))
|
|
|
|
|
where
|
|
|
|
|
rangeAttrs = (IntPairValue =:: (25, 75))
|
|
|
|
|
:& (LowerInt =:: 0)
|
|
|
|
|
:& (UpperInt =:: 100)
|
|
|
|
|
:& RNil
|
|
|
|
@ -497,7 +694,8 @@ defaultIntRangeWidget viewName = defaultIntWidget viewName <+> rangeAttrs
|
|
|
|
|
-- | A record representing a widget of the _BoundedIntRange class from IPython
|
|
|
|
|
defaultBoundedIntRangeWidget :: FieldType S.ViewName -> Rec Attr BoundedIntRangeClass
|
|
|
|
|
defaultBoundedIntRangeWidget viewName = defaultIntRangeWidget viewName <+> boundedIntRangeAttrs
|
|
|
|
|
where boundedIntRangeAttrs = (StepInt =:+ 1)
|
|
|
|
|
where
|
|
|
|
|
boundedIntRangeAttrs = (StepInt =:+ 1)
|
|
|
|
|
:& (MinInt =:: 0)
|
|
|
|
|
:& (MaxInt =:: 100)
|
|
|
|
|
:& RNil
|
|
|
|
@ -505,7 +703,8 @@ defaultBoundedIntRangeWidget viewName = defaultIntRangeWidget viewName <+> bound
|
|
|
|
|
-- | A record representing a widget of the _Float class from IPython
|
|
|
|
|
defaultFloatWidget :: FieldType S.ViewName -> Rec Attr FloatClass
|
|
|
|
|
defaultFloatWidget viewName = defaultDOMWidget viewName <+> intAttrs
|
|
|
|
|
where intAttrs = (FloatValue =:: 0)
|
|
|
|
|
where
|
|
|
|
|
intAttrs = (FloatValue =:: 0)
|
|
|
|
|
:& (Disabled =:: False)
|
|
|
|
|
:& (Description =:: "")
|
|
|
|
|
:& (ChangeHandler =:: return ())
|
|
|
|
@ -514,7 +713,8 @@ defaultFloatWidget viewName = defaultDOMWidget viewName <+> intAttrs
|
|
|
|
|
-- | A record representing a widget of the _BoundedFloat class from IPython
|
|
|
|
|
defaultBoundedFloatWidget :: FieldType S.ViewName -> Rec Attr BoundedFloatClass
|
|
|
|
|
defaultBoundedFloatWidget viewName = defaultFloatWidget viewName <+> boundedFloatAttrs
|
|
|
|
|
where boundedFloatAttrs = (StepFloat =:+ 1)
|
|
|
|
|
where
|
|
|
|
|
boundedFloatAttrs = (StepFloat =:+ 1)
|
|
|
|
|
:& (MinFloat =:: 0)
|
|
|
|
|
:& (MaxFloat =:: 100)
|
|
|
|
|
:& RNil
|
|
|
|
@ -522,7 +722,8 @@ defaultBoundedFloatWidget viewName = defaultFloatWidget viewName <+> boundedFloa
|
|
|
|
|
-- | A record representing a widget of the _BoundedFloat class from IPython
|
|
|
|
|
defaultFloatRangeWidget :: FieldType S.ViewName -> Rec Attr FloatRangeClass
|
|
|
|
|
defaultFloatRangeWidget viewName = defaultFloatWidget viewName <+> rangeAttrs
|
|
|
|
|
where rangeAttrs = (FloatPairValue =:: (25, 75))
|
|
|
|
|
where
|
|
|
|
|
rangeAttrs = (FloatPairValue =:: (25, 75))
|
|
|
|
|
:& (LowerFloat =:: 0)
|
|
|
|
|
:& (UpperFloat =:: 100)
|
|
|
|
|
:& RNil
|
|
|
|
@ -530,7 +731,8 @@ defaultFloatRangeWidget viewName = defaultFloatWidget viewName <+> rangeAttrs
|
|
|
|
|
-- | A record representing a widget of the _BoundedFloatRange class from IPython
|
|
|
|
|
defaultBoundedFloatRangeWidget :: FieldType S.ViewName -> Rec Attr BoundedFloatRangeClass
|
|
|
|
|
defaultBoundedFloatRangeWidget viewName = defaultFloatRangeWidget viewName <+> boundedFloatRangeAttrs
|
|
|
|
|
where boundedFloatRangeAttrs = (StepFloat =:+ 1)
|
|
|
|
|
where
|
|
|
|
|
boundedFloatRangeAttrs = (StepFloat =:+ 1)
|
|
|
|
|
:& (MinFloat =:: 0)
|
|
|
|
|
:& (MaxFloat =:: 100)
|
|
|
|
|
:& RNil
|
|
|
|
@ -538,7 +740,8 @@ defaultBoundedFloatRangeWidget viewName = defaultFloatRangeWidget viewName <+> b
|
|
|
|
|
-- | A record representing a widget of the _Box class from IPython
|
|
|
|
|
defaultBoxWidget :: FieldType S.ViewName -> Rec Attr BoxClass
|
|
|
|
|
defaultBoxWidget viewName = defaultDOMWidget viewName <+> boxAttrs
|
|
|
|
|
where boxAttrs = (Children =:: [])
|
|
|
|
|
where
|
|
|
|
|
boxAttrs = (Children =:: [])
|
|
|
|
|
:& (OverflowX =:: DefaultOverflow)
|
|
|
|
|
:& (OverflowY =:: DefaultOverflow)
|
|
|
|
|
:& (BoxStyle =:: DefaultBox)
|
|
|
|
@ -547,7 +750,8 @@ defaultBoxWidget viewName = defaultDOMWidget viewName <+> boxAttrs
|
|
|
|
|
-- | A record representing a widget of the _SelectionContainer class from IPython
|
|
|
|
|
defaultSelectionContainerWidget :: FieldType S.ViewName -> Rec Attr SelectionContainerClass
|
|
|
|
|
defaultSelectionContainerWidget viewName = defaultBoxWidget viewName <+> selAttrs
|
|
|
|
|
where selAttrs = (Titles =:: [])
|
|
|
|
|
where
|
|
|
|
|
selAttrs = (Titles =:: [])
|
|
|
|
|
:& (SelectedIndex =:: 0)
|
|
|
|
|
:& (ChangeHandler =:: return ())
|
|
|
|
|
:& RNil
|
|
|
|
@ -560,10 +764,14 @@ instance RecAll Attr (WidgetFields w) ToPairs => ToJSON (WidgetState w) where
|
|
|
|
|
object
|
|
|
|
|
. concat
|
|
|
|
|
. recordToList
|
|
|
|
|
. rmap (\(Compose (Dict x)) -> Const $ toPairs x)
|
|
|
|
|
$ reifyConstraint (Proxy :: Proxy ToPairs) $ _getState record
|
|
|
|
|
. rmap (\(Compose (Dict x)) -> Const $ toPairs x) $ reifyConstraint (Proxy :: Proxy ToPairs) $ _getState
|
|
|
|
|
record
|
|
|
|
|
|
|
|
|
|
data IPythonWidget (w :: WidgetType) = IPythonWidget { uuid :: UUID, state :: IORef (WidgetState w) }
|
|
|
|
|
data IPythonWidget (w :: WidgetType) =
|
|
|
|
|
IPythonWidget
|
|
|
|
|
{ uuid :: UUID
|
|
|
|
|
, state :: IORef (WidgetState w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
-- | Change the value for a field, and notify the frontend about it.
|
|
|
|
|
setField :: (f ∈ WidgetFields w, IHaskellWidget (IPythonWidget w), ToPairs (Attr f))
|
|
|
|
|