diff --git a/bower.json b/bower.json index dd3de45..5ed565b 100644 --- a/bower.json +++ b/bower.json @@ -18,8 +18,12 @@ "package.json" ], "dependencies": { - "purescript-prelude": "^3.0.0", - "purescript-dom": "^4.2.0", - "purescript-css": "^3.0.0" + "purescript-prelude": "^4.1.0", + "purescript-web-dom": "^1.0.0", + "purescript-css": "^4.0.0" + }, + "devDependencies": { + "purescript-web-html": "^1.2.0", + "purescript-web-events": "^1.0.1" } } diff --git a/example/src/Main.purs b/example/src/Main.purs index f572d7e..91bbddc 100644 --- a/example/src/Main.purs +++ b/example/src/Main.purs @@ -4,47 +4,45 @@ import Prelude import CSS (Selector, fromString) import Clipboard as C -import Control.Monad.Eff (Eff) -import DOM (DOM) -import DOM.Event.EventTarget (addEventListener, eventListener) -import DOM.HTML (window) -import DOM.HTML.Event.EventTypes (load) -import DOM.HTML.Types (windowToEventTarget, htmlDocumentToDocument) -import DOM.HTML.Window (document) -import DOM.Node.Element (getAttribute) -import DOM.Node.NonElementParentNode (getElementById) -import DOM.Node.Types (Element, ElementId(ElementId), documentToNonElementParentNode) import Data.Maybe (fromJust, fromMaybe) -import Data.Newtype (wrap) +import Effect (Effect) import Partial.Unsafe (unsafePartial) - -onLoad :: forall eff. (Eff (dom :: DOM | eff) Unit) -> Eff (dom :: DOM | eff) Unit -onLoad action - = addEventListener load (eventListener (const action)) false - <<< windowToEventTarget - =<< window - -stringFromAttr :: forall eff. String -> Element -> Eff (dom :: DOM | eff) String -stringFromAttr attr el = fromMaybe "" <$> getAttribute attr el - -testElement :: forall eff. Element -> Eff (dom :: DOM | eff) Unit +import Web.DOM.Element (Element) +import Web.DOM.Element as Element +import Web.DOM.NonElementParentNode (getElementById) +import Web.Event.EventTarget (addEventListener, eventListener) +import Web.HTML (window) +import Web.HTML.Event.EventTypes (load) +import Web.HTML.HTMLDocument as HTMLDocument +import Web.HTML.Window as Window + +onLoad :: Effect Unit -> Effect Unit --forall eff. (Eff (dom :: DOM | eff) Unit) -> Eff (dom :: DOM | eff) Unit +onLoad action = do + listener <- eventListener $ const action + win <- map Window.toEventTarget window + addEventListener load listener false win + +stringFromAttr :: String -> Element -> Effect String +stringFromAttr attr el = fromMaybe "" <$> Element.getAttribute attr el + +testElement :: Element -> Effect Unit testElement el = void $ C.fromElement el $ stringFromAttr "data-copy-text" el -testSelector :: forall eff. Selector -> Eff (dom :: DOM | eff) Unit +testSelector :: Selector -> Effect Unit testSelector sel = void $ C.fromCSSSelector sel $ stringFromAttr "data-copy-text" -testInputSelector :: forall eff. Eff (dom :: DOM | eff) Unit +testInputSelector :: Effect Unit testInputSelector = do - doc <- documentToNonElementParentNode <<< htmlDocumentToDocument <$> (document =<< window) - let getInput = unsafePartial fromJust <$> getElementById (wrap "input-selector") doc - button <- unsafePartial fromJust <$> getElementById (wrap "input-button-selector") doc + doc <- HTMLDocument.toNonElementParentNode <$> (Window.document =<< window) + let getInput = unsafePartial fromJust <$> getElementById "input-selector" doc + button <- unsafePartial fromJust <$> getElementById "input-button-selector" doc void $ C.fromElementWithTarget button getInput -main :: forall eff. Eff (dom :: DOM | eff) Unit +main :: Effect Unit main = onLoad do win <- window - doc <- documentToNonElementParentNode <<< htmlDocumentToDocument <$> document win - element <- getElementById (ElementId "test-element") doc + doc <- HTMLDocument.toNonElementParentNode <$> Window.document win + element <- getElementById "test-element" doc fromMaybe (pure unit) $ testElement <$> element testSelector $ fromString ".test-selector" testInputSelector diff --git a/package.json b/package.json index 5db504a..6a89747 100644 --- a/package.json +++ b/package.json @@ -1,16 +1,16 @@ { "private": true, "scripts": { - "clean": "rimraf output && rimraf .pulp-cache", - "build": "eslint src && pulp build -- --censor-lib --strict", - "test": "pulp build -I example/src -- --censor-lib --strict", - "build-example": "pulp browserify -I example/src --to example/example.js" - }, + "clean": "rimraf output && rimraf .pulp-cache", + "build": "eslint src && pulp build -- --censor-lib --strict", + "test": "pulp build -I example/src -- --censor-lib --strict", + "build-example": "pulp browserify -I example/src --to example/example.js" + }, "devDependencies": { "eslint": "^3.19.0", - "pulp": "^11.0.0", - "purescript": "^0.11.4", - "purescript-psa": "^0.5.1", + "pulp": "^12.2.0", + "purescript": "^0.12.0", + "purescript-psa": "^0.6.0", "rimraf": "^2.6.1" }, "dependencies": { diff --git a/src/Clipboard.purs b/src/Clipboard.purs index 233f34d..d0d6835 100644 --- a/src/Clipboard.purs +++ b/src/Clipboard.purs @@ -8,41 +8,35 @@ module Clipboard import Prelude -import Control.Monad.Eff (Eff) -import DOM (DOM) +import Effect (Effect) import CSS (Selector, selector) -import DOM.Node.Types (Element) +import Web.DOM.Element (Element) foreign import data Clipboard :: Type foreign import fromElement - :: forall eff - . Element - -> Eff (dom :: DOM | eff) String - -> Eff (dom :: DOM | eff) Clipboard + :: Element + -> Effect String + -> Effect Clipboard fromCSSSelector - :: forall eff - . Selector - -> (Element -> Eff (dom :: DOM | eff) String) - -> Eff (dom :: DOM | eff) Clipboard + :: Selector + -> (Element -> Effect String) + -> Effect Clipboard fromCSSSelector = selector >>> fromStringSelector foreign import fromStringSelector - :: forall eff - . String - -> (Element -> Eff (dom :: DOM | eff) String) - -> Eff (dom :: DOM | eff) Clipboard + :: String + -> (Element -> Effect String) + -> Effect Clipboard -- | Registers a click handler on an Event, which triggers the passed `Eff` and -- | copies the text inside the returned element to the clipboard. foreign import fromElementWithTarget - :: forall eff - . Element - -> Eff (dom :: DOM | eff) Element - -> Eff (dom :: DOM | eff) Clipboard + :: Element + -> Effect Element + -> Effect Clipboard foreign import destroy - :: forall eff - . Clipboard - -> Eff (dom :: DOM | eff) Unit + :: Clipboard + -> Effect Unit