@@ -13,7 +13,6 @@ import Data.Nullable as Nullable
13import Data.Symbol (SProxy(..))
13import Data.Symbol (SProxy(..))
14import Data.Traversable (for, sequence)
14import Data.Traversable (for, sequence)
15import Data.Tuple.Nested ((/\), type (/\))
15import Data.Tuple.Nested ((/\), type (/\))
16−import Debug.Trace (spy)
17import Effect (Effect)
16import Effect (Effect)
18import Effect.Class.Console (log)
17import Effect.Class.Console (log)
19import Justifill (justifill)
18import Justifill (justifill)
@@ -88,6 +87,19 @@ swap i j arr = swapped # orDie "Couldn't swap"
88 valueJ <- arr !! j
87 valueJ <- arr !! j
89 pure $ (set (ix i) valueJ <<< set (ix j) valueI) arr
88 pure $ (set (ix i) valueJ <<< set (ix j) valueI) arr
90+regularScale = "scale3d(1.0, 1.0, 1.0)"
92+scaledUp = "scale3d(1.1, 1.1, 1.1)"
99+ , immediate: const true
100+ , transform: "scale3d(1.0,1.0,1.0)"
91springsteen init rectsRef positionsRef arg mx my down springs = do
103springsteen init rectsRef positionsRef arg mx my down springs = do
93 rects <- readRef rectsRef
105 rects <- readRef rectsRef
@@ -96,55 +108,43 @@ springsteen init rectsRef positionsRef arg mx my down springs = do
96 rectDragged = rects !!! (positionsBefore !!! arg)
108 rectDragged = rects !!! (positionsBefore !!! arg)
97 currentPosDragged = rectDragged # translate (mx /\ my)
109 currentPosDragged = rectDragged # translate (mx /\ my)
98 orderedRectsBefore = positionsBefore <#> (rects !!! _)
110 orderedRectsBefore = positionsBefore <#> (rects !!! _)
99− overlapsOtherBefore = orderedRectsBefore # findWithIndex \i rect -> i /= arg && overlaps currentPosDragged rect
111+ overlapsOther = orderedRectsBefore # findWithIndex \i rect -> i /= arg && overlaps currentPosDragged rect
100− case down, overlapsOtherBefore of
112+ case down, overlapsOther of
101 false, Just { index } -> do
113 false, Just { index } -> do
103 newPositions = swap arg index positionsBefore
115 newPositions = swap arg index positionsBefore
104− writeRef positionsRef $ spy "new posis" newPositions
116+ writeRef positionsRef newPositions
105 _, _ -> mempty
117 _, _ -> mempty
106− -- alles gut bis hierher, glaube ich
107 positions <- readRef positionsRef
118 positions <- readRef positionsRef
108 springs.set \i -> do
119 springs.set \i -> do
111− isTheDraggedOne = i == arg
112 originalRect = rects !!! i
121 originalRect = rects !!! i
113− currentRect = rects !!! j
122+ currentRect = rects !!! (positions !!! i)
114 leftOffset = currentRect.left - originalRect.left
123 leftOffset = currentRect.left - originalRect.left
115 topOffset = currentRect.top - originalRect.top
124 topOffset = currentRect.top - originalRect.top
116− case isTheDraggedOne, down, overlapsOtherBefore of
125+ case i == arg, down, overlapsOther of
117 true, true, _ ->
126 true, true, _ ->
118− { x: mx + leftOffset
128+ { x = mx + leftOffset
119− , y: my + topOffset
129+ , y = my + topOffset
120− , zIndex: 1
130+ , zIndex = 1
121− , transform: "scale3d(1.1, 1.1, 1.1)"
131+ , transform = scaledUp
122− , borderRadius: "var(--s-2)"
124− , shadow: 20
132+ , shadow = 20
125− , immediate: \n -> n == "x" || n == "y" || n == "zIndex"
133+ , immediate = \n -> n == "x" || n == "y" || n == "zIndex"
127 false, true, Just { index, value }
135 false, true, Just { index, value }
128 | index == i ->
136 | index == i ->
129− { x: rectDragged.left - currentRect.left + leftOffset
138+ { x = rectDragged.left - currentRect.left + leftOffset
130− , y: rectDragged.top - currentRect.top + topOffset
139+ , y = rectDragged.top - currentRect.top + topOffset
134− , transform: "scale3d(1.0, 1.0, 1.0)"
135− , borderRadius: "var(--s-2)"
136− , immediate: const false
140+ , immediate = const false
138 _, _, _ ->
142 _, _, _ ->
139− { x: leftOffset
144+ { x = leftOffset
140− , y: topOffset
145+ , y = topOffset
143− , borderRadius: "var(--s-2)"
145− , transform: "scale3d(1.0, 1.0, 1.0)"
146− , immediate: const false
146+ , immediate = const false
149makeComponent ∷ Effect (ReactComponent Props)
149makeComponent ∷ Effect (ReactComponent Props)
150makeComponent = do
150makeComponent = do
@@ -152,19 +152,8 @@ makeComponent = do
152 spellComponent <- GrimoireSpell.makeComponent
152 spellComponent <- GrimoireSpell.makeComponent
153 useStyles <- makeStylesJSS styles
153 useStyles <- makeStylesJSS styles
154 component "Grimoire" \(props ∷ Props) -> React.do
154 component "Grimoire" \(props ∷ Props) -> React.do
155− {} <- useStyles (pick props)
155+ classes <- useStyles (pick props)
157− defaultSprings = \_ ->
162− , borderRadius: "var(--s-2)"
164− , immediate: const true
165− , transform: "scale3d(1.0,1.0,1.0)"
167− springs <- useSprings (Array.length props.spells) defaultSprings
156+ springs <- useSprings (Array.length props.spells) (const defaultSprings)
168 nodeRefs ∷ Ref (Array (Nullable (_))) <- useRef (props.spells $> Nullable.null)
157 nodeRefs ∷ Ref (Array (Nullable (_))) <- useRef (props.spells $> Nullable.null)
169 spells /\ updateSpells <- useState props.spells
158 spells /\ updateSpells <- useState props.spells
170 positionsRef <- useRef ([] ∷ _ Int)
159 positionsRef <- useRef ([] ∷ _ Int)
@@ -184,7 +173,7 @@ makeComponent = do
184 writeRef rectsRef rects
173 writeRef rectsRef rects
185 writeRef initialisedRef true
174 writeRef initialisedRef true
186 useLayoutEffect windowSize do
175 useLayoutEffect windowSize do
187− springs.set defaultSprings
176+ springs.set (const defaultSprings)
188 positionsBefore <- readRef positionsRef
177 positionsBefore <- readRef positionsRef
189 when (positionsBefore == []) do
178 when (positionsBefore == []) do
190 log "resetting positions"
179 log "resetting positions"
@@ -204,15 +193,14 @@ makeComponent = do
204 renderSpells =
193 renderSpells =
205 mapWithIndex \i (spell /\ style) ->
194 mapWithIndex \i (spell /\ style) ->
206 animatedDiv
195 animatedDiv
198+ $ Record.insert (SProxy ∷ _ "boxShadow")
207− $ { style: css (Record.insert (SProxy ∷ _ "boxShadow") ((unsafeCoerce (style.shadow ∷ Int)).interpolate (\s -> Interp.i "rgba(0, 0, 0, 0.15) 0px " s "px " (2 * s) "px 0px" ∷ String)) style)
199+ ((unsafeCoerce (style.shadow ∷ Int)).interpolate (\s -> Interp.i "rgba(0, 0, 0, 0.15) 0px " s "px " (2 * s) "px 0px" ∷ String))
201+ , className: classes.container
208 , ref: unsafeCoerce (unsafeUpdateRefs nodeRefs i)
202 , ref: unsafeCoerce (unsafeUpdateRefs nodeRefs i)
211− spellComponent
203+ , children: [ element spellComponent { spell } ]
217 `withDragProps`
205 `withDragProps`
218 bindDragProps i
206 bindDragProps i