Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
purescript-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Grégoire Locqueville
purescript-gargantext
Commits
bf93eb01
Commit
bf93eb01
authored
Sep 20, 2019
by
James Laver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reactix utils
parent
35e85826
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
8 deletions
+39
-8
ContextMenu.purs
src/Gargantext/Components/ContextMenu/ContextMenu.purs
+1
-4
Reactix.purs
src/Gargantext/Utils/Reactix.purs
+38
-4
No files found.
src/Gargantext/Components/ContextMenu/ContextMenu.purs
View file @
bf93eb01
...
@@ -23,9 +23,6 @@ import Gargantext.Utils.Reactix as R2
...
@@ -23,9 +23,6 @@ import Gargantext.Utils.Reactix as R2
type Props t = ( x :: Number, y :: Number, setMenu :: R2.StateSetter (Maybe t) )
type Props t = ( x :: Number, y :: Number, setMenu :: R2.StateSetter (Maybe t) )
getPortalHost :: R.Hooks DOM.Element
getPortalHost = R.unsafeHooksEffect $ delay unit $ \_ -> pure $ document ... "getElementById" $ ["menu-portal"]
contextMenu :: forall t. Record (Props t) -> Array R.Element -> R.Element
contextMenu :: forall t. Record (Props t) -> Array R.Element -> R.Element
contextMenu = R.createElement contextMenuCpt
contextMenu = R.createElement contextMenuCpt
...
@@ -33,7 +30,7 @@ contextMenuCpt :: forall t. R.Component (Props t)
...
@@ -33,7 +30,7 @@ contextMenuCpt :: forall t. R.Component (Props t)
contextMenuCpt = R.hooksComponent "ContextMenu" cpt
contextMenuCpt = R.hooksComponent "ContextMenu" cpt
where
where
cpt menu children = do
cpt menu children = do
host <- getPortalHost
host <-
R2.
getPortalHost
root <- R.useRef null
root <- R.useRef null
rect /\ setRect <- R.useState $ \_ -> Nothing
rect /\ setRect <- R.useState $ \_ -> Nothing
R.useLayoutEffect1 (R.readRef root) $ do
R.useLayoutEffect1 (R.readRef root) $ do
...
...
src/Gargantext/Utils/Reactix.purs
View file @
bf93eb01
...
@@ -3,6 +3,9 @@ module Gargantext.Utils.Reactix
...
@@ -3,6 +3,9 @@ module Gargantext.Utils.Reactix
import Prelude
import Prelude
import DOM.Simple as DOM
import DOM.Simple.Document (document)
import DOM.Simple.Event as DE
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..))
import Data.Nullable (Nullable, null, toMaybe)
import Data.Nullable (Nullable, null, toMaybe)
import Data.Traversable (traverse_)
import Data.Traversable (traverse_)
...
@@ -13,12 +16,14 @@ import DOM.Simple.Event as DE
...
@@ -13,12 +16,14 @@ import DOM.Simple.Event as DE
import DOM.Simple as DOM
import DOM.Simple as DOM
import Effect (Effect)
import Effect (Effect)
import Effect.Class (liftEffect)
import Effect.Class (liftEffect)
import Effect.Aff (Aff, launchAff, launchAff_, killFiber)
import Effect.Exception (error)
import Effect.Uncurried (EffectFn1, mkEffectFn1)
import Effect.Uncurried (EffectFn1, mkEffectFn1)
import FFI.Simple ((...), defineProperty)
import FFI.Simple ((...), defineProperty
, delay
)
import React (ReactClass, ReactElement, Children, class IsReactElement, class ReactPropFields)
import React (ReactClass, ReactElement, Children, class IsReactElement, class ReactPropFields)
import React as React
import React as React
import Reactix as R
import Reactix as R
import Reactix.DOM.HTML (ElemFactory)
import Reactix.DOM.HTML (ElemFactory
, text
)
import Reactix.React (createDOMElement)
import Reactix.React (createDOMElement)
import Reactix.SyntheticEvent as RE
import Reactix.SyntheticEvent as RE
import Thermite (Spec, simpleSpec, Render, defaultPerformAction)
import Thermite (Spec, simpleSpec, Render, defaultPerformAction)
...
@@ -26,7 +31,7 @@ import Unsafe.Coerce (unsafeCoerce)
...
@@ -26,7 +31,7 @@ import Unsafe.Coerce (unsafeCoerce)
newtype Point = Point { x :: Number, y :: Number }
newtype Point = Point { x :: Number, y :: Number }
type S
tateSetter a = (a -> a
) -> Effect Unit
type S
etter t = (t -> t
) -> Effect Unit
-- | Turns a ReactElement into aReactix Element
-- | Turns a ReactElement into aReactix Element
-- | buff (v.) to polish
-- | buff (v.) to polish
...
@@ -79,6 +84,12 @@ instance isComponentReactClass
...
@@ -79,6 +84,12 @@ instance isComponentReactClass
React.createElement reactClass props children
React.createElement reactClass props children
-}
-}
-- | Turns an aff into a useEffect-compatible Effect (Effect Unit)
affEffect :: forall a. String -> Aff a -> Effect (Effect Unit)
affEffect errmsg aff = do
fiber <- launchAff aff
pure $ launchAff_ $ killFiber (error errmsg) fiber
mousePosition :: RE.SyntheticEvent DE.MouseEvent -> Point
mousePosition :: RE.SyntheticEvent DE.MouseEvent -> Point
mousePosition e = Point { x: RE.clientX e, y: RE.clientY e }
mousePosition e = Point { x: RE.clientX e, y: RE.clientY e }
...
@@ -91,7 +102,6 @@ named = flip $ defineProperty "name"
...
@@ -91,7 +102,6 @@ named = flip $ defineProperty "name"
overState :: forall t. (t -> t) -> R.State t -> Effect Unit
overState :: forall t. (t -> t) -> R.State t -> Effect Unit
overState f (_state /\ setState) = setState f
overState f (_state /\ setState) = setState f
select :: ElemFactory
select :: ElemFactory
select = createDOMElement "select"
select = createDOMElement "select"
...
@@ -129,3 +139,27 @@ readPositionRef :: R.Ref (Nullable DOM.Element) -> Maybe DOM.DOMRect
...
@@ -129,3 +139,27 @@ readPositionRef :: R.Ref (Nullable DOM.Element) -> Maybe DOM.DOMRect
readPositionRef el = do
readPositionRef el = do
let posRef = R.readRef el
let posRef = R.readRef el
Element.boundingRect <$> toMaybe posRef
Element.boundingRect <$> toMaybe posRef
unsafeEventTarget :: forall event. event -> DOM.Element
unsafeEventTarget e = (unsafeCoerce e).target
getElementById :: String -> Effect (Maybe DOM.Element)
getElementById = (flip delay) h
where
h id = pure $ toMaybe $ document ... "getElementById" $ [id]
-- We just assume it works, so make sure it's in the html
getPortalHost :: R.Hooks DOM.Element
getPortalHost = R.unsafeHooksEffect $ delay unit $ \_ -> pure $ document ... "getElementById" $ ["portal"]
useLayoutEffectOnce :: Effect (Effect Unit) -> R.Hooks Unit
useLayoutEffectOnce e = R.unsafeUseLayoutEffect e []
singleParent :: forall props. R.Component props -> Record props -> R.Element -> R.Element
singleParent cpt props child = R.createElement cpt props [ child ]
childless :: forall props. R.Component props -> Record props -> R.Element
childless cpt props = R.createElement cpt props []
showText :: forall s. Show s => s -> R.Element
showText = text <<< show
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment