miso
Copyright(C) 2016-2026 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
MaintainerDavid M. Johnson <code@dmj.io>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Miso.Native.Element.Text.Event

Description

Since: 1.13.0.0

Synopsis

Events

onLayout :: (LayoutEvent -> action) -> Attribute model action Source #

https://lynxjs.org/api/elements/built-in/text.html#layout

The layout event returns the result information after text layout, including the number of lines of the current text, and the start and end positions of the text in each line relative to the entire text.

data Action = HandleLayout LayoutEvent

view :: context -> props -> Model -> View context Action
view _ _ model = text_ [ onLayout HandleLayout ] [ text "hi" ]

update :: Action -> Effect context props Model Action
update (HandleLayout LayoutEvent {..}) = io_ (consoleLog "layout event received")

onLayoutWith :: (LayoutEvent -> DOMRef -> action) -> Attribute model action Source #

Like onLayout, but the handler also receives the target element's DOMRef. Use for main-thread (MTS) handlers that imperatively mutate the element.

onLayoutMain :: (LayoutEvent -> action) -> EventHandler model action Source #

Like onLayout, but dispatched on the Lynx main thread (MTS).

Runs imperatively on the MTS (no VDOM diff). Meant to be used with -XStaticPointers.

data Action = HandleLayout LayoutEvent

view_ [ event (static (onLayoutMain HandleLayout)) ] [ "some view" ]

onLayoutMainWith :: (LayoutEvent -> model -> DOMRef -> action) -> EventHandler model action Source #

Like onLayoutMain, but the handler also receives read-only access to the model and the target element's DOMRef (for imperative MTS mutation).

data Action = HandleLayout LayoutEvent Model DOMRef

view_ [ event (static (onLayoutMainWith HandleLayout)) ] [ "some view" ]

onSelectionChange :: (SelectionChangeEvent -> action) -> Attribute model action Source #

https://lynxjs.org/api/elements/built-in/text.html#selectionchange

This event is triggered whenever the selected text range changes.

data Action = HandleSelectionChange SelectionChangeEvent

view :: context -> props -> Model -> View context Action
view _ _ model = text_ [ onSelectionChange HandleSelectionChange ] [ text "hi" ]

update :: Action -> Effect context props Model Action
update (HandleSelectionChange SelectionChangeEvent {..}) =
  io_ (consoleLog "selection change event received")

onSelectionChangeWith :: (SelectionChangeEvent -> DOMRef -> action) -> Attribute model action Source #

Like onSelectionChange, but the handler also receives the target element's DOMRef. Use for main-thread (MTS) handlers that imperatively mutate the element.

onSelectionChangeMain :: (SelectionChangeEvent -> action) -> EventHandler model action Source #

Like onSelectionChange, but dispatched on the Lynx main thread (MTS).

Runs imperatively on the MTS (no VDOM diff). Meant to be used with -XStaticPointers.

data Action = HandleSelectionChange SelectionChangeEvent

view_ [ event (static (onSelectionChangeMain HandleSelectionChange)) ] [ "some view" ]

onSelectionChangeMainWith :: (SelectionChangeEvent -> model -> DOMRef -> action) -> EventHandler model action Source #

Like onSelectionChangeMain, but the handler also receives read-only access to the model and the target element's DOMRef (for imperative MTS mutation).

data Action = HandleSelectionChange SelectionChangeEvent Model DOMRef

view_ [ event (static (onSelectionChangeMainWith HandleSelectionChange)) ] [ "some view" ]

Types

data LayoutEvent Source #

Payload of a text layout event: how many lines were laid out, per-line detail, and the resulting size.

Since: 1.13.0.0

Instances

Instances details
Show LayoutEvent Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

Eq LayoutEvent Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

data LineInfo Source #

Per-line detail from a text layout event: the character range the line covers and how many characters were ellipsized.

Since: 1.13.0.0

Instances

Instances details
Show LineInfo Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

Eq LineInfo Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

FromJSON LineInfo Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

data Size Source #

The measured width and height of laid-out text content, in px.

Since: 1.13.0.0

Constructors

Size 

Instances

Instances details
Show Size Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

Methods

showsPrec :: Int -> Size -> ShowS #

show :: Size -> String #

showList :: [Size] -> ShowS #

Eq Size Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

Methods

(==) :: Size -> Size -> Bool #

(/=) :: Size -> Size -> Bool #

data SelectionChangeEvent Source #

Payload of a text selection-change event: the start and end offsets of the new selection and the direction it was extended in.

Since: 1.13.0.0

data Direction Source #

The direction a text selection was extended in.

Since: 1.13.0.0

Constructors

Forward 
Backward 

Instances

Instances details
Show Direction Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

Eq Direction Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

FromJSON Direction Source # 
Instance details

Defined in Miso.Native.Element.Text.Event

Decoders

layoutDecoder :: Decoder LayoutEvent Source #

Decoder producing a LayoutEvent from the raw Lynx event payload.

Pass it to on / onMain when writing a handler by hand; the on* helpers in this module already use it.

Since: 1.13.0.0

selectionChangeDecoder :: Decoder SelectionChangeEvent Source #

Decoder producing a SelectionChangeEvent from the raw Lynx event payload.

Pass it to on / onMain when writing a handler by hand; the on* helpers in this module already use it.

Since: 1.13.0.0

Event Map

textEvents :: Events Source #

The Events map for the Lynx text element.

Combine with other element maps using <> and pass the result to native, so the delegator listens for these events.

Since: 1.13.0.0