Skip to content

Commit cb1af12

Browse files
Update for 0.12
1 parent 5bc290b commit cb1af12

File tree

8 files changed

+148
-167
lines changed

8 files changed

+148
-167
lines changed

bower.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
],
1212
"license": "MIT",
1313
"dependencies": {
14-
"purescript-prelude": "^3.0.0",
15-
"purescript-newtype": "^2.0.0",
16-
"purescript-profunctor-lenses": "^3.2.0",
17-
"purescript-dom": "^4.3.1",
18-
"purescript-symbols": "^3.0.0"
14+
"purescript-prelude": "^4.0.0",
15+
"purescript-newtype": "^3.0.0",
16+
"purescript-profunctor-lenses": "^4.0.0",
17+
"purescript-web-uievents": "^1.0.0"
1918
},
2019
"devDependencies": {
21-
"purescript-psci-support": "^3.0.0",
22-
"purescript-quickcheck": "^4.4.0"
20+
"purescript-psci-support": "^4.0.0",
21+
"purescript-quickcheck": "^5.0.0"
2322
},
2423
"ignore": [
2524
"**/.*",

src/DOM/Util/TextCursor/Element/Type.purs

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/DOM/Util/TextCursor.purs renamed to src/Web/Util/TextCursor.purs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module DOM.Util.TextCursor
1+
module Web.Util.TextCursor
22
( TextCursor(..), Direction(..)
33
, mkTextCursor, genTextCursor
44
, content, length, null, empty, single
@@ -19,7 +19,6 @@ import Data.Lens (Lens', Traversal', over, wander, (.~), (^.))
1919
import Data.Lens.Iso.Newtype (_Newtype)
2020
import Data.Lens.Record (prop)
2121
import Data.Lens.Types (Setter')
22-
import Data.Monoid (class Monoid)
2322
import Data.Newtype (class Newtype)
2423
import Data.String (length, null) as S
2524
import Data.String.Gen (genUnicodeString)
@@ -32,7 +31,7 @@ derive instance eqDirection :: Eq Direction
3231
derive instance ordDirection :: Ord Direction
3332

3433
instance semigroupDirection :: Semigroup Direction where
35-
append None = id
34+
append None = identity
3635
append c = const c
3736
instance monoidDirection :: Monoid Direction where
3837
mempty = None
Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
1-
module DOM.Util.TextCursor.Element
2-
( module DOM.Util.TextCursor.Element.Type
3-
, module DOM.Util.TextCursor.Element.HTML
1+
module Web.Util.TextCursor.Element
2+
( module Web.Util.TextCursor.Element.Type
3+
, module Web.Util.TextCursor.Element.HTML
44
, textCursor, setTextCursor
55
, modifyTextCursor, modifyTextCursorST
66
, focusTextCursor, focusTextCursorById
77
) where
88

99
import Prelude
10-
import Data.Maybe (Maybe(Just))
1110
import Data.String (length, splitAt)
1211
import Data.Lens (Lens', (.~))
13-
import Control.Monad.Eff (Eff)
14-
import Control.Monad.Eff.Class (class MonadEff, liftEff)
12+
import Effect (Effect)
13+
import Effect.Class (class MonadEffect, liftEffect)
1514
import Control.Monad.State.Class (class MonadState, modify)
16-
import DOM (DOM)
17-
import DOM.Node.Types (ElementId)
18-
import DOM.HTML.HTMLElement (focus)
19-
import DOM.Util.TextCursor (TextCursor(..), content)
20-
import DOM.Util.TextCursor.Element.Type
15+
import Web.HTML.HTMLElement (focus)
16+
import Web.Util.TextCursor (TextCursor(..), content)
17+
import Web.Util.TextCursor.Element.Type
2118
( TextCursorElement(..)
22-
, htmlTextCursorElementToHTMLElement
19+
, toHTMLElement
2320
, read, readEventTarget
2421
, validate, validate'
2522
, lookupAndValidate
2623
, lookupValidateAndDo
2724
)
28-
import DOM.Util.TextCursor.Element.HTML
25+
import Web.Util.TextCursor.Element.HTML
2926
( value, setValue
3027
, selectionStart, setSelectionStart
3128
, selectionEnd, setSelectionEnd
3229
, selectionDirection, setSelectionDirection
3330
)
3431

35-
-- | Helper to split a `String` at a specific position without worrying about
36-
-- | `Nothing`.
37-
splitAtRec :: Int -> String -> { before :: String, after :: String }
38-
splitAtRec i s = case splitAt i s of
39-
Just split -> split
40-
_ | i > 0 -> { before: s, after: "" }
41-
| otherwise -> { before: "", after: s }
42-
4332
-- | Get the `TextCursor` from a `TextCursorElement`.
44-
textCursor :: forall eff. TextCursorElement -> Eff ( dom :: DOM | eff ) TextCursor
33+
textCursor :: TextCursorElement -> Effect TextCursor
4534
textCursor element = do
4635
val <- value element
4736
start <- selectionStart element
4837
end <- selectionEnd element
4938
direction <- selectionDirection element
50-
let { before: prior, after } = splitAtRec end val
51-
let { before, after: selected } = splitAtRec start prior
39+
let { before: prior, after } = splitAt end val
40+
let { before, after: selected } = splitAt start prior
5241
pure $ TextCursor
5342
{ before
5443
, selected
@@ -59,7 +48,7 @@ textCursor element = do
5948
-- | Set the `TextCursor` on a `TextCursorElement`. Calls `setValue`,
6049
-- | `setSelectionStart`, `setSelectionEnd`, and `setSelectionDirection` to
6150
-- | ensure a consistent state for the field.
62-
setTextCursor :: forall eff. TextCursor -> TextCursorElement -> Eff ( dom :: DOM | eff ) Unit
51+
setTextCursor :: TextCursor -> TextCursorElement -> Effect Unit
6352
setTextCursor (tc@TextCursor { before, selected, after, direction }) element = do
6453
setValue (content tc) element
6554
let start = length before
@@ -69,31 +58,39 @@ setTextCursor (tc@TextCursor { before, selected, after, direction }) element = d
6958
setSelectionDirection direction element
7059

7160
-- | Modifies the `TextCursor` on an element through the given endomorphism.
72-
modifyTextCursor :: forall eff. (TextCursor -> TextCursor) -> TextCursorElement -> Eff ( dom :: DOM | eff ) Unit
61+
modifyTextCursor :: (TextCursor -> TextCursor) -> TextCursorElement -> Effect Unit
7362
modifyTextCursor f element = do
7463
tc <- f <$> textCursor element
7564
setTextCursor tc element
7665

7766
-- | Modifies the `TextCursor` on an element as well as setting the result in a
7867
-- | State+Eff monad via a lens. Useful for components processing input events!
79-
modifyTextCursorST :: forall eff m s.
68+
modifyTextCursorST :: forall m s.
8069
MonadState s m =>
81-
MonadEff ( dom :: DOM | eff ) m =>
70+
MonadEffect m =>
8271
Lens' s TextCursor ->
8372
(TextCursor -> TextCursor) ->
84-
TextCursorElement -> m Unit
73+
TextCursorElement -> m s
8574
modifyTextCursorST l f element = do
86-
tc <- liftEff $ f <$> textCursor element
87-
liftEff $ setTextCursor tc element
75+
tc <- liftEffect $ f <$> textCursor element
76+
liftEffect $ setTextCursor tc element
8877
modify $ l .~ tc
8978

79+
modifyTextCursorST_ :: forall m s.
80+
MonadState s m =>
81+
MonadEffect m =>
82+
Lens' s TextCursor ->
83+
(TextCursor -> TextCursor) ->
84+
TextCursorElement -> m Unit
85+
modifyTextCursorST_ l f element = void $ modifyTextCursorST l f element
86+
9087
-- | Focuses an element after setting the `TextCursor`.
91-
focusTextCursor :: forall eff. TextCursor -> TextCursorElement -> Eff ( dom :: DOM | eff ) Unit
88+
focusTextCursor :: TextCursor -> TextCursorElement -> Effect Unit
9289
focusTextCursor tc element = do
9390
setTextCursor tc element
94-
focus (htmlTextCursorElementToHTMLElement element)
91+
focus (toHTMLElement element)
9592

9693
-- | Looks up an element by id to focus with a `TextCursor`.
97-
focusTextCursorById :: forall eff. ElementId -> TextCursor -> Eff ( dom :: DOM | eff ) Unit
94+
focusTextCursorById :: String -> TextCursor -> Effect Unit
9895
focusTextCursorById name tc = do
9996
lookupValidateAndDo name (focusTextCursor tc)

src/DOM/Util/TextCursor/Element/HTML.purs renamed to src/Web/Util/TextCursor/Element/HTML.purs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module DOM.Util.TextCursor.Element.HTML
1+
module Web.Util.TextCursor.Element.HTML
22
( value, setValue
33
, selectionStart, setSelectionStart
44
, selectionEnd, setSelectionEnd
@@ -7,18 +7,15 @@ module DOM.Util.TextCursor.Element.HTML
77

88
import Prelude
99

10-
import Control.Monad.Eff (Eff)
11-
import DOM (DOM)
12-
import DOM.HTML.HTMLInputElement as HInput
13-
import DOM.HTML.HTMLTextAreaElement as HTextArea
14-
import DOM.HTML.Types (HTMLInputElement, HTMLTextAreaElement)
15-
import DOM.Util.TextCursor (Direction(..))
16-
import DOM.Util.TextCursor.Element.Type (TextCursorElement(TextArea, Input))
10+
import Effect (Effect)
11+
import Web.HTML.HTMLInputElement as HInput
12+
import Web.HTML.HTMLTextAreaElement as HTextArea
13+
import Web.HTML (HTMLInputElement, HTMLTextAreaElement)
14+
import Web.Util.TextCursor (Direction(..))
15+
import Web.Util.TextCursor.Element.Type (TextCursorElement(TextArea, Input))
1716

18-
type Getter a =
19-
forall eff. TextCursorElement -> Eff ( dom :: DOM | eff ) a
20-
type Setter a =
21-
forall eff. a -> TextCursorElement -> Eff ( dom :: DOM | eff ) Unit
17+
type Getter a = TextCursorElement -> Effect a
18+
type Setter a = a -> TextCursorElement -> Effect Unit
2219

2320
-- | Lift a pair of getters (Input/TextArea).
2421
getter ::

0 commit comments

Comments
 (0)