diff options
author | Joris | 2019-02-02 17:14:33 +0100 |
---|---|---|
committer | Joris | 2019-02-02 17:14:33 +0100 |
commit | 142e0c9fac9896f8cb134fd1e1b010753402e7b8 (patch) | |
tree | 6315c75f5d8a2a0c4f6e6b7251f621fde933ac9f /js/src/EditableNumber.purs | |
parent | fb470f57438047ac8bd635dc485881ebae4ab0ff (diff) |
Make it works and add “galette” recipe
Diffstat (limited to 'js/src/EditableNumber.purs')
-rw-r--r-- | js/src/EditableNumber.purs | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/js/src/EditableNumber.purs b/js/src/EditableNumber.purs index 6a6e3a8..02ffe58 100644 --- a/js/src/EditableNumber.purs +++ b/js/src/EditableNumber.purs @@ -3,18 +3,17 @@ module EditableNumber , set ) where -import Control.Monad.Eff (Eff) import Data.Maybe (Maybe(..)) -import DOM (DOM) -import DOM.HTML (window) as DOM -import DOM.HTML.Types (htmlDocumentToDocument) as DOM -import DOM.HTML.Window (document) as DOM -import DOM.Node.Document (createElement, createTextNode) as DOM -import DOM.Node.Element (setClassName, setAttribute) as DOM -import DOM.Node.Node (textContent) as DOM -import DOM.Node.Types (Element, Node) -import DOM.Node.Types (elementToNode, textToNode) as DOM +import Effect (Effect) import Prelude +import Web.DOM.Document (createElement, createTextNode) as Document +import Web.DOM.Element (setClassName, setAttribute, toNode) as Element +import Web.DOM.Internal.Types (Element, Node) +import Web.DOM.Node (textContent) as Node +import Web.DOM.Text (toNode) as Text +import Web.HTML (window) as HTML +import Web.HTML.HTMLDocument (toDocument) as HTMLDocument +import Web.HTML.Window (document) as Window import Dom (replaceElement, appendNodes) as Dom import Number (format) as Number @@ -26,31 +25,31 @@ type NumberElem = , number :: Number } -set :: forall e. { tag :: String, node :: Node } -> Eff (dom :: DOM | e) (Maybe NumberElem) +set :: { tag :: String, node :: Node } -> Effect (Maybe NumberElem) set { tag, node } = do - content <- DOM.textContent node + content <- Node.textContent node case Parser.textWithNumber content of Just twn -> do textWithNumber <- textWithNumberElem tag twn - Dom.replaceElement node (DOM.elementToNode textWithNumber) + Dom.replaceElement node (Element.toNode textWithNumber) pure (Just { elem: textWithNumber, number: twn.number }) Nothing -> pure Nothing -textWithNumberElem :: forall e. String -> TextWithNumber -> Eff (dom :: DOM | e) Element +textWithNumberElem :: String -> TextWithNumber -> Effect Element textWithNumberElem tag { begin, number, end } = do - document <- DOM.htmlDocumentToDocument <$> (DOM.window >>= DOM.document) - elem <- DOM.createElement tag document - beginNode <- DOM.textToNode <$> DOM.createTextNode begin document + document <- HTMLDocument.toDocument <$> (HTML.window >>= Window.document) + elem <- Document.createElement tag document + beginNode <- Text.toNode <$> Document.createTextNode begin document numberNode <- numberElem number - endNode <- DOM.textToNode <$> DOM.createTextNode end document - Dom.appendNodes (DOM.elementToNode elem) [ beginNode, DOM.elementToNode numberNode, endNode ] + endNode <- Text.toNode <$> Document.createTextNode end document + Dom.appendNodes (Element.toNode elem) [ beginNode, Element.toNode numberNode, endNode ] pure elem -numberElem :: forall e. Number -> Eff (dom :: DOM | e) Element +numberElem :: Number -> Effect Element numberElem number = do - document <- DOM.htmlDocumentToDocument <$> (DOM.window >>= DOM.document) - container <- DOM.createElement "input" document - DOM.setClassName "number" container - DOM.setAttribute "value" (Number.format number) container + document <- HTMLDocument.toDocument <$> (HTML.window >>= Window.document) + container <- Document.createElement "input" document + Element.setClassName "number" container + Element.setAttribute "value" (Number.format number) container pure container |