/
Dom.purs
51 lines (35 loc) · 1.61 KB
/
Dom.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
module Sketch.Dom
( getDocuments
, getSelectedDocument
, selectedLayers
, getLayerWithID
, setPropsForLayerID
) where
import Prelude
import Data.Either (Either)
import Data.List.Types (NonEmptyList)
import Effect (Effect)
import Foreign (Foreign, ForeignError)
import Foreign.Class (class Encode, encode)
import Sketch.Types (Document, Layer)
import Sketch.Utils (runExceptDecode)
foreign import _getDocuments :: Effect Foreign
foreign import _getSelectedDocument :: Effect Foreign
foreign import _getSelection :: Effect Foreign
foreign import _getLayerWithID :: String -> Effect Foreign
foreign import _setPropsForLayerID :: String -> Array String -> Foreign -> Effect Unit
-- | A method to help find the first layer in this document which has the given id.
getLayerWithID :: String -> Effect (Either (NonEmptyList ForeignError) Layer)
getLayerWithID = runExceptDecode <<< _getLayerWithID
-- | A method to set value for the path in layer in this document which has the given id.
setPropsForLayerID :: forall a. Encode a => String -> Array String -> a -> Effect Unit
setPropsForLayerID id path val = _setPropsForLayerID id path (encode val)
-- | Access all the open Documents.
getDocuments :: Effect (Either (NonEmptyList ForeignError) (Array Document))
getDocuments = runExceptDecode _getDocuments
-- | Access the selected Document.
getSelectedDocument :: Effect (Either (NonEmptyList ForeignError) Document)
getSelectedDocument = runExceptDecode _getSelectedDocument
-- | Gets selected Layers.
selectedLayers :: Effect (Either (NonEmptyList ForeignError) (Array Layer))
selectedLayers = runExceptDecode _getSelection