From d8fc9d41cf1b3eefb5d5107c7ff91ab00ca48415 Mon Sep 17 00:00:00 2001 From: roovo Date: Thu, 16 Nov 2023 21:00:27 +0000 Subject: [PATCH 01/16] Cleanup: simplify dragged item placement offset calculations --- typescript/view.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/typescript/view.ts b/typescript/view.ts index 00d0f841..a3260007 100644 --- a/typescript/view.ts +++ b/typescript/view.ts @@ -372,17 +372,15 @@ export class CardBoardView extends ItemView { } function dragEvent(dragAction: "move" | "stop", event: MouseEvent) { - const appContainer = document.getElementsByClassName("workspace")[0]; - const tabContainer = document.getElementsByClassName("workspace-tab-container")[1]; - const rightSidebarContainer = document.getElementsByClassName("workspace-tabs")[2]; + const tabHeader = document.getElementsByClassName("workspace-tab-header-container")[1]; + const ribbon = document.getElementsByClassName("workspace-ribbon")[0]; + const leftSplit = document.getElementsByClassName("workspace-split")[0]; - console.log - - if ((appContainer instanceof HTMLElement) && - (tabContainer instanceof HTMLElement) && + if ((ribbon instanceof HTMLElement) && + (leftSplit instanceof HTMLElement) && (draggedElement instanceof HTMLElement)) { - const offsetLeft = appContainer.clientWidth - (tabContainer.clientWidth + rightSidebarContainer.clientWidth); - const offsetTop = appContainer.clientHeight - tabContainer.clientHeight; + const offsetLeft = ribbon.clientWidth + leftSplit.clientWidth; + const offsetTop = tabHeader.clientHeight; const draggedElementRect = draggedElement.getBoundingClientRect(); From 05012ff8e61aabab5f1d675a484df318f932a382 Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 10:54:44 +0000 Subject: [PATCH 02/16] Cleanup: move BeaconPosition decoding into BeaconPosition module --- src/DragAndDrop/BeaconPosition.elm | 28 ++++++++--------------- src/DragAndDrop/DragData.elm | 16 +------------ tests/DragAndDrop/BeaconPositionTests.elm | 7 ++++-- 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src/DragAndDrop/BeaconPosition.elm b/src/DragAndDrop/BeaconPosition.elm index 12ddbdb0..04372b39 100644 --- a/src/DragAndDrop/BeaconPosition.elm +++ b/src/DragAndDrop/BeaconPosition.elm @@ -5,8 +5,8 @@ module DragAndDrop.BeaconPosition exposing , identifier ) -import Json.Decode as JD import Json.Encode as JE +import TsJson.Decode as TsDecode @@ -22,13 +22,12 @@ type BeaconPosition -- ENCODE / DECODE -decoder : JD.Decoder BeaconPosition +decoder : TsDecode.Decoder BeaconPosition decoder = - JD.map2 - Tuple.pair - (JD.field "position" JD.string) - (JD.field "identifier" JD.string) - |> JD.andThen toPosition + TsDecode.oneOf + [ toElmBeacon "after" After TsDecode.string + , toElmBeacon "before" Before TsDecode.string + ] encoder : BeaconPosition -> JE.Value @@ -66,14 +65,7 @@ identifier beaconPosition = -- PRIVATE -toPosition : ( String, String ) -> JD.Decoder BeaconPosition -toPosition ( position, identifier_ ) = - case position of - "before" -> - JD.succeed (Before identifier_) - - "after" -> - JD.succeed (After identifier_) - - _ -> - JD.fail ("Unknown position: " ++ position) +toElmBeacon : String -> (value -> a) -> TsDecode.Decoder value -> TsDecode.Decoder a +toElmBeacon tagName constructor decoder_ = + TsDecode.field "position" (TsDecode.literal constructor (JE.string tagName)) + |> TsDecode.andMap (TsDecode.field "identifier" decoder_) diff --git a/src/DragAndDrop/DragData.elm b/src/DragAndDrop/DragData.elm index e2398a60..8aaa339a 100644 --- a/src/DragAndDrop/DragData.elm +++ b/src/DragAndDrop/DragData.elm @@ -69,27 +69,13 @@ decoder = beaconDataDecoder : TsDecode.Decoder BeaconData beaconDataDecoder = TsDecode.succeed BeaconData - |> TsDecode.andMap (TsDecode.field "beaconPosition" beaconPositionDecoder) + |> TsDecode.andMap (TsDecode.field "beaconPosition" BeaconPosition.decoder) |> TsDecode.andMap (TsDecode.field "rect" Rect.decoder) -beaconPositionDecoder : TsDecode.Decoder BeaconPosition -beaconPositionDecoder = - TsDecode.oneOf - [ toElmBeacon "after" BeaconPosition.After TsDecode.string - , toElmBeacon "before" BeaconPosition.Before TsDecode.string - ] - - dragActionDecoder : TsDecode.Decoder DragAction dragActionDecoder = TsDecode.discriminatedUnion "dragAction" [ ( "move", TsDecode.succeed Move ) , ( "stop", TsDecode.succeed Stop ) ] - - -toElmBeacon : String -> (value -> a) -> TsDecode.Decoder value -> TsDecode.Decoder a -toElmBeacon tagName constructor decoder_ = - TsDecode.field "position" (TsDecode.literal constructor (JE.string tagName)) - |> TsDecode.andMap (TsDecode.field "identifier" decoder_) diff --git a/tests/DragAndDrop/BeaconPositionTests.elm b/tests/DragAndDrop/BeaconPositionTests.elm index 8fd51f90..f40f4790 100644 --- a/tests/DragAndDrop/BeaconPositionTests.elm +++ b/tests/DragAndDrop/BeaconPositionTests.elm @@ -2,6 +2,7 @@ module DragAndDrop.BeaconPositionTests exposing (suite) import DragAndDrop.BeaconPosition as BeaconPosition exposing (BeaconPosition(..)) import Expect +import Helpers.DecodeHelpers as DecodeHelpers import Json.Decode as JD import Json.Encode as JE import Test exposing (..) @@ -22,12 +23,14 @@ decoder = [ test "decodes an After" <| \() -> """{"position":"after","identifier":"some identifier"}""" - |> JD.decodeString BeaconPosition.decoder + |> DecodeHelpers.runDecoder BeaconPosition.decoder + |> .decoded |> Expect.equal (Ok <| After "some identifier") , test "decodes a Before" <| \() -> """{"position":"before","identifier":"some identifier"}""" - |> JD.decodeString BeaconPosition.decoder + |> DecodeHelpers.runDecoder BeaconPosition.decoder + |> .decoded |> Expect.equal (Ok <| Before "some identifier") ] From d44bb5cf121847fe59869acae96aa86bb475fb2d Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 11:01:01 +0000 Subject: [PATCH 03/16] Cleanup: move DragTracker into own module --- TODO.md | 5 + src/DragAndDrop/DragData.elm | 10 -- src/DragAndDrop/DragTracker.elm | 89 ++++++++++++ src/Page/Board.elm | 108 +++++--------- src/Session.elm | 96 ++++++------- tests/DragAndDrop/DragTrackerTests.elm | 191 +++++++++++++++++++++++++ tests/SessionTests.elm | 172 ++++++++++++---------- 7 files changed, 462 insertions(+), 209 deletions(-) create mode 100644 src/DragAndDrop/DragTracker.elm create mode 100644 tests/DragAndDrop/DragTrackerTests.elm diff --git a/TODO.md b/TODO.md index 4249a86f..523540ee 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,8 @@ +- Session.timeWIthZOneIs - WI -> Wi +- Beacon identifier to uniqueId +- am I using DragData.beaconType ?? +- sort out Session function organisation + - enable reorder boards on settings page too - tidy typescript - tidy elm diff --git a/src/DragAndDrop/DragData.elm b/src/DragAndDrop/DragData.elm index 8aaa339a..385d67cb 100644 --- a/src/DragAndDrop/DragData.elm +++ b/src/DragAndDrop/DragData.elm @@ -2,7 +2,6 @@ module DragAndDrop.DragData exposing ( BeaconData , DragAction(..) , DragData - , DragTracker , decoder ) @@ -38,15 +37,6 @@ type alias BeaconData = } -type alias DragTracker = - { nodeId : String - , clientPos : Coords - , offsetPos : Coords - , offset : Coords - , draggedNodeRect : Rect - } - - -- DECODERS diff --git a/src/DragAndDrop/DragTracker.elm b/src/DragAndDrop/DragTracker.elm new file mode 100644 index 00000000..ef6211ec --- /dev/null +++ b/src/DragAndDrop/DragTracker.elm @@ -0,0 +1,89 @@ +module DragAndDrop.DragTracker exposing + ( ClientData + , DragTracker(..) + , init + , isDragging + , moveDragable + , stopTracking + , waitForDrag + ) + +import DragAndDrop.Coords as Coords exposing (Coords) +import DragAndDrop.DragData exposing (DragData) +import DragAndDrop.Rect as Rect exposing (Rect) + + + +-- TYPES + + +type DragTracker + = NotDragging + | Waiting ClientData + | Dragging ClientData DomData + + +type alias ClientData = + { uniqueId : String + , clientPos : Coords + , offsetPos : Coords + } + + +type alias DomData = + { offset : Coords + , draggedNodeStartRect : Rect + } + + +init : DragTracker +init = + NotDragging + + + +-- INFO + + +isDragging : DragTracker -> Bool +isDragging dragTracker = + case dragTracker of + NotDragging -> + False + + Waiting _ -> + False + + Dragging _ _ -> + True + + + +-- STATE TRANSFORMS + + +moveDragable : DragData -> DragTracker -> DragTracker +moveDragable dragData dragTracker = + case dragTracker of + NotDragging -> + dragTracker + + Waiting clientData -> + Dragging + { clientData | clientPos = dragData.cursor } + { offset = dragData.offset, draggedNodeStartRect = dragData.draggedNodeRect } + + Dragging clientData domData -> + Dragging + { clientData | clientPos = dragData.cursor } + { domData | offset = dragData.offset } + + +stopTracking : DragTracker +stopTracking = + NotDragging + + +waitForDrag : ClientData -> DragTracker +waitForDrag clientData = + Waiting clientData diff --git a/src/Page/Board.elm b/src/Page/Board.elm index db3060d9..38bb598e 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -12,7 +12,8 @@ import ColumnNames exposing (ColumnNames) import Date exposing (Date) import DragAndDrop.BeaconPosition as BeaconPosition exposing (BeaconPosition) import DragAndDrop.Coords as Coords -import DragAndDrop.DragData as DragData exposing (DragData, DragTracker) +import DragAndDrop.DragData as DragData exposing (DragData) +import DragAndDrop.DragTracker as DragTracker exposing (DragTracker) import DragAndDrop.Rect as Rect import FeatherIcons import Html exposing (Attribute, Html) @@ -38,7 +39,7 @@ import TimeWithZone exposing (TimeWithZone) type Msg = ElementDragged DragData | SettingsClicked - | TabHeaderMouseDown ( String, DragTracker ) + | TabHeaderMouseDown ( String, DragTracker.ClientData ) | TabSelected Int | TaskItemEditClicked String | TaskItemDeleteClicked String @@ -51,42 +52,16 @@ beaconType = "data-card-board-tag-header-beacon" -updateBoardOrder : DragTracker -> DragData -> Session -> Session -updateBoardOrder { nodeId } { cursor, beacons } session = - case Rect.closestTo cursor beacons of - Nothing -> - session - - Just position -> - Session.moveBoard nodeId position session - - update : Msg -> Session -> ( Session, Cmd Msg, Session.Msg ) update msg session = case msg of ElementDragged dragData -> case dragData.dragAction of DragData.Move -> - case Session.dragStatus session of - Session.NotDragging -> - ( session - , Cmd.none - , Session.NoOp - ) - - Session.Waiting dragTracker -> - ( Session.trackDraggable dragTracker dragData.draggedNodeRect session - , Cmd.none - , Session.NoOp - ) - - Session.Dragging dragTracker -> - ( session - |> updateBoardOrder dragTracker dragData - |> Session.updateDragPositions dragData.cursor dragData.offset - , Cmd.none - , Session.NoOp - ) + ( Session.moveDragable dragData session + , Cmd.none + , Session.NoOp + ) DragData.Stop -> ( Session.stopTrackingDragable session @@ -100,9 +75,9 @@ update msg session = , Session.SettingsClicked ) - TabHeaderMouseDown ( tabId, dragTracker ) -> - ( Session.waitForDrag dragTracker session - , InteropPorts.trackDraggable beaconType dragTracker.clientPos tabId + TabHeaderMouseDown ( domId, clientData ) -> + ( Session.waitForDrag clientData session + , InteropPorts.trackDraggable beaconType clientData.clientPos domId , Session.NoOp ) @@ -207,15 +182,7 @@ view session = isDragging : Bool isDragging = - case Session.dragStatus session of - Session.Dragging _ -> - True - - Session.NotDragging -> - False - - Session.Waiting _ -> - False + Session.isDragging session in Html.div [ attribute "dir" (TextDirection.toString <| Session.textDirection session) @@ -272,12 +239,12 @@ tabHeader isDragging currentBoardIndex tabIndex title = headerClass = tabHeaderClass currentBoardIndex tabIndex - tabId : String - tabId = + domId : String + domId = "card-board-tab:" ++ String.fromInt tabIndex in Html.div - [ id tabId + [ id domId , class ("workspace-tab-header" ++ headerClass) , attributeIf (not isDragging) (attribute "aria-label" title) , attributeIf (not isDragging) (attribute "aria-label-delay" "50") @@ -285,12 +252,11 @@ tabHeader isDragging currentBoardIndex tabIndex title = , onDown (\e -> TabHeaderMouseDown <| - ( tabId - , DragTracker title - (Coords.fromFloatTuple e.clientPos) - (Coords.fromFloatTuple e.offsetPos) - (Coords.fromFloatTuple ( 0, 0 )) - { x = 0, y = 0, width = 0, height = 0 } + ( domId + , { uniqueId = title + , clientPos = Coords.fromFloatTuple e.clientPos + , offsetPos = Coords.fromFloatTuple e.offsetPos + } ) ) ] @@ -307,25 +273,24 @@ tabHeader isDragging currentBoardIndex tabIndex title = selectedTabHeader : Bool -> Int -> String -> Html Msg selectedTabHeader isDragging tabIndex title = let - tabId : String - tabId = + domId : String + domId = "card-board-tab:" ++ String.fromInt tabIndex in Html.div [ class "workspace-tab-header is-active" - , id tabId + , id domId , attributeIf (not isDragging) (attribute "aria-label" title) , attributeIf (not isDragging) (attribute "aria-label-delay" "50") , attributeIf isDragging (style "opacity" "0.0") , onDown (\e -> TabHeaderMouseDown <| - ( tabId - , DragTracker title - (Coords.fromFloatTuple e.clientPos) - (Coords.fromFloatTuple e.offsetPos) - (Coords.fromFloatTuple ( 0, 0 )) - { x = 0, y = 0, width = 0, height = 0 } + ( domId + , { uniqueId = title + , clientPos = Coords.fromFloatTuple e.clientPos + , offsetPos = Coords.fromFloatTuple e.offsetPos + } ) ) ] @@ -341,30 +306,27 @@ selectedTabHeader isDragging tabIndex title = viewDraggedHeader : Session -> Html Msg viewDraggedHeader session = - case Session.dragStatus session of - Session.Dragging dragTracker -> + case Session.dragTracker session of + DragTracker.Dragging clientData domData -> Html.div [ class "workspace-tab-header is-active" , id <| "card-board-tab:being-dragged" , style "position" "fixed" - , style "top" (String.fromFloat (dragTracker.draggedNodeRect.y - dragTracker.offset.y) ++ "px") - , style "left" (String.fromFloat (dragTracker.clientPos.x - dragTracker.offset.x - dragTracker.offsetPos.x) ++ "px") - , style "width" (String.fromFloat dragTracker.draggedNodeRect.width ++ "px") - , style "height" (String.fromFloat dragTracker.draggedNodeRect.height ++ "px") + , style "top" (String.fromFloat (domData.draggedNodeStartRect.y - domData.offset.y) ++ "px") + , style "left" (String.fromFloat (clientData.clientPos.x - domData.offset.x - clientData.offsetPos.x) ++ "px") + , style "width" (String.fromFloat domData.draggedNodeStartRect.width ++ "px") + , style "height" (String.fromFloat domData.draggedNodeStartRect.height ++ "px") , style "cursor" "grabbing" , style "opacity" "0.85" ] [ Html.div [ class "workspace-tab-header-inner" ] [ Html.div [ class "workspace-tab-header-inner-title" ] - [ Html.text <| dragTracker.nodeId ] + [ Html.text <| clientData.uniqueId ] ] ] - Session.Waiting _ -> - empty - - Session.NotDragging -> + _ -> empty diff --git a/src/Session.elm b/src/Session.elm index a3ecf444..6ce388e5 100644 --- a/src/Session.elm +++ b/src/Session.elm @@ -1,6 +1,5 @@ module Session exposing - ( DragStatus(..) - , Msg(..) + ( Msg(..) , Session , addTaskList , boardConfigs @@ -9,14 +8,16 @@ module Session exposing , dataviewTaskCompletion , default , deleteItemsFromFile - , dragStatus + , dragTracker , finishAdding , fromFlags , globalSettings , ignoreFileNameDates , isActiveView + , isDragging , makeActiveView , moveBoard + , moveDragable , replaceTaskItems , settings , stopTrackingDragable @@ -28,10 +29,9 @@ module Session exposing , timeIs , timeWIthZoneIs , timeWithZone - , trackDraggable , uniqueId + , updateBoardOrder , updateColumnCollapse - , updateDragPositions , updatePath , updateSettings , updateTextDirection @@ -45,8 +45,9 @@ import ColumnNames exposing (ColumnNames) import DataviewTaskCompletion exposing (DataviewTaskCompletion) import DragAndDrop.BeaconPosition exposing (BeaconPosition) import DragAndDrop.Coords exposing (Coords) -import DragAndDrop.DragData exposing (DragTracker) -import DragAndDrop.Rect exposing (Rect) +import DragAndDrop.DragData exposing (DragData) +import DragAndDrop.DragTracker as DragTracker exposing (DragTracker) +import DragAndDrop.Rect as Rect exposing (Rect) import GlobalSettings exposing (GlobalSettings) import InteropDefinitions import SafeZipper exposing (SafeZipper) @@ -69,7 +70,7 @@ type Session type alias Config = { dataviewTaskCompletion : DataviewTaskCompletion - , dragStatus : DragStatus + , dragTracker : DragTracker , isActiveView : Bool , settings : Settings , taskList : State TaskList @@ -79,12 +80,6 @@ type alias Config = } -type DragStatus - = NotDragging - | Waiting DragTracker - | Dragging DragTracker - - type Msg = NoOp | SettingsClicked @@ -99,7 +94,7 @@ default : Session default = Session { dataviewTaskCompletion = DataviewTaskCompletion.default - , dragStatus = NotDragging + , dragTracker = DragTracker.init , isActiveView = False , settings = Settings.default , taskList = State.Waiting @@ -116,7 +111,7 @@ fromFlags : InteropDefinitions.Flags -> Session fromFlags flags = Session { dataviewTaskCompletion = flags.dataviewTaskCompletion - , dragStatus = NotDragging + , dragTracker = DragTracker.init , isActiveView = False , settings = flags.settings , taskList = State.Waiting @@ -156,9 +151,9 @@ dataviewTaskCompletion (Session config) = config.dataviewTaskCompletion -dragStatus : Session -> DragStatus -dragStatus (Session config) = - config.dragStatus +dragTracker : Session -> DragTracker +dragTracker (Session config) = + config.dragTracker globalSettings : Session -> GlobalSettings @@ -176,6 +171,11 @@ isActiveView (Session config) = config.isActiveView +isDragging : Session -> Bool +isDragging (Session config) = + DragTracker.isDragging config.dragTracker + + settings : Session -> Settings settings (Session config) = config.settings @@ -251,7 +251,7 @@ moveBoard draggedId beaconPosition (Session config) = stopTrackingDragable : Session -> Session stopTrackingDragable (Session config) = - Session { config | dragStatus = NotDragging } + Session { config | dragTracker = DragTracker.stopTracking } switchToBoardAt : Int -> Session -> Session @@ -269,48 +269,36 @@ timeWIthZoneIs zone time (Session config) = Session { config | timeWithZone = { zone = zone, time = time } } -trackDraggable : DragTracker -> Rect -> Session -> Session -trackDraggable dragTracker draggedNodeRect (Session config) = +moveDragable : DragData -> Session -> Session +moveDragable dragData session = let - newTracker : DragTracker - newTracker = - { dragTracker | draggedNodeRect = draggedNodeRect } + doMove : Session -> Session + doMove (Session config) = + Session { config | dragTracker = DragTracker.moveDragable dragData config.dragTracker } in - Session { config | dragStatus = Dragging newTracker } + session + |> updateBoardOrder dragData + |> doMove -waitForDrag : DragTracker -> Session -> Session -waitForDrag dragTracker (Session config) = - Session { config | dragStatus = Waiting dragTracker } +updateBoardOrder : DragData -> Session -> Session +updateBoardOrder { cursor, beacons } ((Session config) as session) = + case config.dragTracker of + DragTracker.Dragging clientData _ -> + case Rect.closestTo cursor beacons of + Nothing -> + session + Just position -> + moveBoard clientData.uniqueId position session -updateDragPositions : Coords -> Coords -> Session -> Session -updateDragPositions newPosition newOffset ((Session config) as session) = - case config.dragStatus of - NotDragging -> + _ -> session - Waiting dragTracker -> - let - newTracker : DragTracker - newTracker = - { dragTracker - | clientPos = newPosition - , offset = newOffset - } - in - Session { config | dragStatus = Dragging newTracker } - - Dragging dragTracker -> - let - newTracker : DragTracker - newTracker = - { dragTracker - | clientPos = newPosition - , offset = newOffset - } - in - Session { config | dragStatus = Dragging newTracker } + +waitForDrag : DragTracker.ClientData -> Session -> Session +waitForDrag clientData (Session config) = + Session { config | dragTracker = DragTracker.waitForDrag clientData } updateSettings : Settings -> Session -> Session diff --git a/tests/DragAndDrop/DragTrackerTests.elm b/tests/DragAndDrop/DragTrackerTests.elm new file mode 100644 index 00000000..f2fa6fe6 --- /dev/null +++ b/tests/DragAndDrop/DragTrackerTests.elm @@ -0,0 +1,191 @@ +module DragAndDrop.DragTrackerTests exposing (suite) + +import DragAndDrop.DragData as DragData +import DragAndDrop.DragTracker as DragTracker +import Expect +import Test exposing (..) + + +suite : Test +suite = + concat + [ init + , isDragging + , moveDragable + , stopTracking + , waitForDrag + ] + + +init : Test +init = + describe "init" + [ test "is in the NotDragging state" <| + \() -> + DragTracker.init + |> Expect.equal DragTracker.NotDragging + , test "initialises to not dragging" <| + \() -> + DragTracker.init + |> DragTracker.isDragging + |> Expect.equal False + ] + + +isDragging : Test +isDragging = + describe "isDragging" + [ test "is False if in NotDragging state" <| + \() -> + DragTracker.init + |> DragTracker.isDragging + |> Expect.equal False + , test "returns False if it was Waiting" <| + \() -> + DragTracker.waitForDrag + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + |> DragTracker.isDragging + |> Expect.equal False + , test "returns True if Dragging" <| + \() -> + DragTracker.Dragging + { uniqueId = "an id" + , clientPos = { x = 0, y = 0 } + , offsetPos = { x = 1, y = 2 } + } + { offset = { x = 0, y = 0 } + , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + } + |> DragTracker.isDragging + |> Expect.equal True + ] + + +moveDragable : Test +moveDragable = + describe "moveDragable" + [ test "does nothing if in NotDragging state" <| + \() -> + let + dragData = + { beaconType = "" + , dragAction = DragData.Move + , cursor = { x = 0, y = 1 } + , offset = { x = 1, y = 2 } + , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } + , beacons = [] + } + in + DragTracker.init + |> DragTracker.moveDragable dragData + |> Expect.equal DragTracker.NotDragging + , test "moves into the Dragging state if it was Waiting" <| + \() -> + let + dragData = + { beaconType = "" + , dragAction = DragData.Move + , cursor = { x = 1.1, y = 2.2 } + , offset = { x = 1, y = 2 } + , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } + , beacons = [] + } + + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in + DragTracker.waitForDrag clientData + |> DragTracker.moveDragable dragData + |> Expect.equal + (DragTracker.Dragging + { uniqueId = "an id" + , clientPos = { x = 1.1, y = 2.2 } + , offsetPos = { x = 1, y = 2 } + } + { offset = { x = 1, y = 2 } + , draggedNodeStartRect = { x = 2, y = 3, width = 4, height = 5 } + } + ) + , test "updates clientPos and offset if it was already Dragging" <| + \() -> + let + dragData = + { beaconType = "" + , dragAction = DragData.Move + , cursor = { x = 1.1, y = 2.2 } + , offset = { x = 1, y = 2 } + , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } + , beacons = [] + } + + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in + DragTracker.Dragging + { uniqueId = "an id" + , clientPos = { x = 0, y = 0 } + , offsetPos = { x = 1, y = 2 } + } + { offset = { x = 0, y = 0 } + , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + } + |> DragTracker.moveDragable dragData + |> Expect.equal + (DragTracker.Dragging + { uniqueId = "an id" + , clientPos = { x = 1.1, y = 2.2 } + , offsetPos = { x = 1, y = 2 } + } + { offset = { x = 1, y = 2 } + , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + } + ) + ] + + +stopTracking : Test +stopTracking = + describe "stopTracking" + [ test "returns the NotDragging state" <| + \() -> + DragTracker.stopTracking + |> Expect.equal DragTracker.NotDragging + ] + + +waitForDrag : Test +waitForDrag = + describe "waitForDrag" + [ test "is in the waiting state" <| + \() -> + let + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in + DragTracker.waitForDrag clientData + |> Expect.equal (DragTracker.Waiting clientData) + , test "it is not dragging" <| + \() -> + let + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in + DragTracker.waitForDrag clientData + |> DragTracker.isDragging + |> Expect.equal False + ] diff --git a/tests/SessionTests.elm b/tests/SessionTests.elm index 6a0445de..f9dfb610 100644 --- a/tests/SessionTests.elm +++ b/tests/SessionTests.elm @@ -3,6 +3,7 @@ module SessionTests exposing (suite) import BoardConfig import DataviewTaskCompletion import DragAndDrop.DragData as DragData +import DragAndDrop.DragTracker as DragTracker exposing (DragTracker) import Expect import Filter import GlobalSettings @@ -24,11 +25,11 @@ suite = , deleteItemsFromFile , finishAdding , globalSettings + , moveDragable , replaceTaskItems - , trackDragable , stopTrackingDragable , updatePath - , updateDragPositions + , waitForDrag ] @@ -76,11 +77,11 @@ default = Session.default |> Session.isActiveView |> Expect.equal False - , test "has dragStatus of NotDragging" <| + , test "isnt dragging" <| \() -> Session.default - |> Session.dragStatus - |> Expect.equal Session.NotDragging + |> Session.isDragging + |> Expect.equal False , test "has default Settings" <| \() -> Session.default @@ -166,85 +167,82 @@ globalSettings = ] -trackDragable : Test -trackDragable = - describe "trackDragable" - [ test "tracks a TabHeader" <| +waitForDrag : Test +waitForDrag = + describe "waitForDrag" + [ test "puts the dragTracker in Waiting state" <| \() -> + let + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in Session.default - |> Session.trackDraggable - (DragData.DragTracker "3" - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0, width = 0, height = 0 } - ) - { x = 0, y = 0, width = 0, height = 0 } - |> Session.dragStatus - |> Expect.equal - (Session.Dragging <| - DragData.DragTracker "3" - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0, width = 0, height = 0 } - ) + |> Session.waitForDrag clientData + |> Session.dragTracker + |> Expect.equal (DragTracker.Waiting clientData) ] -updateDragPositions : Test -updateDragPositions = - describe "updateDragPositions" - [ test "does nothing if not dragging" <| - \() -> - Session.default - |> Session.updateDragPositions { x = 10, y = 20 } - { x = 100, y = 200 } - |> Session.dragStatus - |> Expect.equal Session.NotDragging - , test "updates the tracked client position if dragging" <| +moveDragable : Test +moveDragable = + describe "moveDragable" + [ test "puts the dragTracker in Dragging state" <| \() -> + let + dragData = + { beaconType = "" + , dragAction = DragData.Move + , cursor = { x = 1.1, y = 2.2 } + , offset = { x = 1, y = 2 } + , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } + , beacons = [] + } + + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in Session.default - |> Session.trackDraggable - (DragData.DragTracker "3" - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0, width = 0, height = 0 } - ) - { x = 0, y = 0, width = 0, height = 0 } - |> Session.updateDragPositions { x = 10, y = 20 } - { x = 100, y = 200 } - |> Session.dragStatus + |> Session.waitForDrag clientData + |> Session.moveDragable dragData + |> Session.dragTracker |> Expect.equal - (Session.Dragging <| - DragData.DragTracker "3" - { x = 10, y = 20 } - { x = 0, y = 0 } - { x = 100, y = 200 } - { x = 0, y = 0, width = 0, height = 0 } + (DragTracker.Dragging + { uniqueId = "an id" + , clientPos = { x = 1.1, y = 2.2 } + , offsetPos = { x = 1, y = 2 } + } + { offset = { x = 1, y = 2 } + , draggedNodeStartRect = { x = 2, y = 3, width = 4, height = 5 } + } ) ] -stopTrackingDragable : Test -stopTrackingDragable = - describe "stopTrackingDragable" - [ test "stops tracking a TabHeader" <| - \() -> - Session.default - |> Session.trackDraggable - (DragData.DragTracker "3" - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0 } - { x = 0, y = 0, width = 0, height = 0 } - ) - { x = 0, y = 0, width = 0, height = 0 } - |> Session.stopTrackingDragable - |> Session.dragStatus - |> Expect.equal Session.NotDragging - ] + +-- stopTrackingDragable : Test +-- stopTrackingDragable = +-- describe "stopTrackingDragable" +-- [ test "stops tracking a TabHeader" <| +-- \() -> +-- Session.default +-- |> Session.trackDraggable +-- (DragTracker "3" +-- { x = 0, y = 0 } +-- { x = 0, y = 0 } +-- { x = 0, y = 0 } +-- { x = 0, y = 0, width = 0, height = 0 } +-- ) +-- { x = 0, y = 0, width = 0, height = 0 } +-- |> Session.stopTrackingDragable +-- |> Session.isDragging +-- |> Expect.equal False +-- ] replaceTaskItems : Test @@ -279,6 +277,36 @@ replaceTaskItems = ] +stopTrackingDragable : Test +stopTrackingDragable = + describe "stopTracking" + [ test "puts the dragTracker in Dragging state" <| + \() -> + let + dragData = + { beaconType = "" + , dragAction = DragData.Move + , cursor = { x = 1.1, y = 2.2 } + , offset = { x = 1, y = 2 } + , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } + , beacons = [] + } + + clientData = + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + in + Session.default + |> Session.waitForDrag clientData + |> Session.moveDragable dragData + |> Session.stopTrackingDragable + |> Session.dragTracker + |> Expect.equal DragTracker.NotDragging + ] + + updatePath : Test updatePath = describe "updatePath" From 2cb7ebf58501a72d74fccfbd868cd5ba6ee507a8 Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 16:56:20 +0000 Subject: [PATCH 04/16] Cleanup: Beacon.identifier -> uniqueId --- TODO.md | 1 - src/DragAndDrop/BeaconPosition.elm | 10 +++--- src/Settings.elm | 6 ++-- tests/DragAndDrop/BeaconPositionTests.elm | 40 +++++++++++------------ tests/DragAndDrop/DragDataTests.elm | 2 +- tests/InteropDefinitionsTests.elm | 2 +- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/TODO.md b/TODO.md index 523540ee..dc556bc1 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,4 @@ - Session.timeWIthZOneIs - WI -> Wi -- Beacon identifier to uniqueId - am I using DragData.beaconType ?? - sort out Session function organisation diff --git a/src/DragAndDrop/BeaconPosition.elm b/src/DragAndDrop/BeaconPosition.elm index 04372b39..c185eb4d 100644 --- a/src/DragAndDrop/BeaconPosition.elm +++ b/src/DragAndDrop/BeaconPosition.elm @@ -2,7 +2,7 @@ module DragAndDrop.BeaconPosition exposing ( BeaconPosition(..) , decoder , encoder - , identifier + , uniqueId ) import Json.Encode as JE @@ -43,7 +43,7 @@ encoder beaconPosition = in JE.object [ ( "position", JE.string positionStr ) - , ( "identifier", JE.string identifierString ) + , ( "uniqueId", JE.string identifierString ) ] @@ -51,8 +51,8 @@ encoder beaconPosition = -- UTILS -identifier : BeaconPosition -> String -identifier beaconPosition = +uniqueId : BeaconPosition -> String +uniqueId beaconPosition = case beaconPosition of Before id -> id @@ -68,4 +68,4 @@ identifier beaconPosition = toElmBeacon : String -> (value -> a) -> TsDecode.Decoder value -> TsDecode.Decoder a toElmBeacon tagName constructor decoder_ = TsDecode.field "position" (TsDecode.literal constructor (JE.string tagName)) - |> TsDecode.andMap (TsDecode.field "identifier" decoder_) + |> TsDecode.andMap (TsDecode.field "uniqueId" decoder_) diff --git a/src/Settings.elm b/src/Settings.elm index 527b63fa..0b37af03 100644 --- a/src/Settings.elm +++ b/src/Settings.elm @@ -108,14 +108,14 @@ mapGlobalSettings fn settings = moveBoard : String -> BeaconPosition -> Settings -> Settings moveBoard draggedId beaconPosition settings = - if BeaconPosition.identifier beaconPosition == draggedId then + if BeaconPosition.uniqueId beaconPosition == draggedId then let boardList : List BoardConfig boardList = boardConfigs settings |> SafeZipper.toList in - case LE.findIndex (\c -> BoardConfig.title c == BeaconPosition.identifier beaconPosition) boardList of + case LE.findIndex (\c -> BoardConfig.title c == BeaconPosition.uniqueId beaconPosition) boardList of Nothing -> settings @@ -144,7 +144,7 @@ moveBoard draggedId beaconPosition settings = insertConfig : BoardConfig -> Result String ( List BoardConfig, Int ) insertConfig foundConfig = - case LE.findIndex (\c -> BoardConfig.title c == BeaconPosition.identifier beaconPosition) afterRemoving of + case LE.findIndex (\c -> BoardConfig.title c == BeaconPosition.uniqueId beaconPosition) afterRemoving of Nothing -> Err "" diff --git a/tests/DragAndDrop/BeaconPositionTests.elm b/tests/DragAndDrop/BeaconPositionTests.elm index f40f4790..e5ea015c 100644 --- a/tests/DragAndDrop/BeaconPositionTests.elm +++ b/tests/DragAndDrop/BeaconPositionTests.elm @@ -13,7 +13,7 @@ suite = concat [ decoder , encoder - , identifier + , uniqueId ] @@ -22,16 +22,16 @@ decoder = describe "decoder" [ test "decodes an After" <| \() -> - """{"position":"after","identifier":"some identifier"}""" + """{"position":"after","uniqueId":"some uniqueId"}""" |> DecodeHelpers.runDecoder BeaconPosition.decoder |> .decoded - |> Expect.equal (Ok <| After "some identifier") + |> Expect.equal (Ok <| After "some uniqueId") , test "decodes a Before" <| \() -> - """{"position":"before","identifier":"some identifier"}""" + """{"position":"before","uniqueId":"some uniqueId"}""" |> DecodeHelpers.runDecoder BeaconPosition.decoder |> .decoded - |> Expect.equal (Ok <| Before "some identifier") + |> Expect.equal (Ok <| Before "some uniqueId") ] @@ -40,30 +40,30 @@ encoder = describe "encoder" [ test "encodes a Before" <| \() -> - Before "some identifier" + Before "some uniqueId" |> BeaconPosition.encoder |> JE.encode 0 - |> Expect.equal """{"position":"before","identifier":"some identifier"}""" + |> Expect.equal """{"position":"before","uniqueId":"some uniqueId"}""" , test "encodes an After" <| \() -> - After "some identifier" + After "some uniqueId" |> BeaconPosition.encoder |> JE.encode 0 - |> Expect.equal """{"position":"after","identifier":"some identifier"}""" + |> Expect.equal """{"position":"after","uniqueId":"some uniqueId"}""" ] -identifier : Test -identifier = - describe "identifier" - [ test "extracts the identifier from a Before" <| +uniqueId : Test +uniqueId = + describe "uniqueId" + [ test "extracts the uniqueId from a Before" <| \() -> - Before "some identifier" - |> BeaconPosition.identifier - |> Expect.equal "some identifier" - , test "extracts the identifier from an After" <| + Before "some uniqueId" + |> BeaconPosition.uniqueId + |> Expect.equal "some uniqueId" + , test "extracts the uniqueId from an After" <| \() -> - After "some identifier" - |> BeaconPosition.identifier - |> Expect.equal "some identifier" + After "some uniqueId" + |> BeaconPosition.uniqueId + |> Expect.equal "some uniqueId" ] diff --git a/tests/DragAndDrop/DragDataTests.elm b/tests/DragAndDrop/DragDataTests.elm index d9ebbebe..8b3444af 100644 --- a/tests/DragAndDrop/DragDataTests.elm +++ b/tests/DragAndDrop/DragDataTests.elm @@ -19,7 +19,7 @@ decoder = describe "decoder" [ test "decodes valid input" <| \() -> - """{"beaconType":"an identifier","dragAction":"move","cursor":{"x":1.1,"y":2.2},"offset":{"x":3.3,"y":4.4},"draggedNodeRect":{"x":1.2,"y":3.4,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"identifier":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}""" + """{"beaconType":"an identifier","dragAction":"move","cursor":{"x":1.1,"y":2.2},"offset":{"x":3.3,"y":4.4},"draggedNodeRect":{"x":1.2,"y":3.4,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"uniqueId":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}""" |> DecodeHelpers.runDecoder DragData.decoder |> .decoded |> Expect.equal diff --git a/tests/InteropDefinitionsTests.elm b/tests/InteropDefinitionsTests.elm index 5345dd26..2ee03558 100644 --- a/tests/InteropDefinitionsTests.elm +++ b/tests/InteropDefinitionsTests.elm @@ -627,7 +627,7 @@ toElmTests = |> Expect.equal (Ok <| InteropDefinitions.ConfigChanged TextDirection.RightToLeft) , test "decodes elementDragged data" <| \() -> - """{"tag":"elementDragged","data":{"beaconType":"some-beacon-id","dragAction":"stop","cursor":{"x":1.23,"y":4.56},"offset":{"x":1.11,"y":2.22},"draggedNodeRect":{"x":1.1,"y":2.2,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"identifier":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}}""" + """{"tag":"elementDragged","data":{"beaconType":"some-beacon-id","dragAction":"stop","cursor":{"x":1.23,"y":4.56},"offset":{"x":1.11,"y":2.22},"draggedNodeRect":{"x":1.1,"y":2.2,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"uniqueId":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}}""" |> DecodeHelpers.runDecoder interop.toElm |> .decoded |> Expect.equal From ae0416f41efeb8759eb546fb0e363585a1fd72d2 Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 16:58:33 +0000 Subject: [PATCH 05/16] Cleanup: fix typo: Session.timeWIthZoneIs -> timeWithZoneIs --- TODO.md | 3 +-- src/Main.elm | 2 +- src/Session.elm | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index dc556bc1..b067b02d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ -- Session.timeWIthZOneIs - WI -> Wi -- am I using DragData.beaconType ?? - sort out Session function organisation +- am I using DragData.beaconType ?? - enable reorder boards on settings page too - tidy typescript diff --git a/src/Main.elm b/src/Main.elm index 02437a98..deb9b777 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -203,7 +203,7 @@ update msg model = ( model, Cmd.none ) ( ReceiveTime ( zone, posix ), _ ) -> - ( mapSession (Session.timeWIthZoneIs zone posix) model + ( mapSession (Session.timeWithZoneIs zone posix) model , Cmd.none ) diff --git a/src/Session.elm b/src/Session.elm index 6ce388e5..e98b854f 100644 --- a/src/Session.elm +++ b/src/Session.elm @@ -27,8 +27,8 @@ module Session exposing , taskList , textDirection , timeIs - , timeWIthZoneIs , timeWithZone + , timeWithZoneIs , uniqueId , updateBoardOrder , updateColumnCollapse @@ -264,8 +264,8 @@ timeIs time (Session config) = Session { config | timeWithZone = TimeWithZone.time time config.timeWithZone } -timeWIthZoneIs : Time.Zone -> Time.Posix -> Session -> Session -timeWIthZoneIs zone time (Session config) = +timeWithZoneIs : Time.Zone -> Time.Posix -> Session -> Session +timeWithZoneIs zone time (Session config) = Session { config | timeWithZone = { zone = zone, time = time } } From 7cecbb923c39e86c722ed561fbc24c15bee2e696 Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 17:03:16 +0000 Subject: [PATCH 06/16] Cleanup: tidy Session function ordering and labelling --- TODO.md | 1 - src/Session.elm | 54 ++++++++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/TODO.md b/TODO.md index b067b02d..92207a0a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,4 +1,3 @@ -- sort out Session function organisation - am I using DragData.beaconType ?? - enable reorder boards on settings page too diff --git a/src/Session.elm b/src/Session.elm index e98b854f..c155b760 100644 --- a/src/Session.elm +++ b/src/Session.elm @@ -125,7 +125,7 @@ fromFlags flags = --- UTILITIES +-- INFO boardConfigs : Session -> SafeZipper BoardConfig @@ -249,6 +249,18 @@ moveBoard draggedId beaconPosition (Session config) = Session { config | settings = Settings.moveBoard draggedId beaconPosition config.settings } +moveDragable : DragData -> Session -> Session +moveDragable dragData session = + let + doMove : Session -> Session + doMove (Session config) = + Session { config | dragTracker = DragTracker.moveDragable dragData config.dragTracker } + in + session + |> updateBoardOrder dragData + |> doMove + + stopTrackingDragable : Session -> Session stopTrackingDragable (Session config) = Session { config | dragTracker = DragTracker.stopTracking } @@ -269,18 +281,6 @@ timeWithZoneIs zone time (Session config) = Session { config | timeWithZone = { zone = zone, time = time } } -moveDragable : DragData -> Session -> Session -moveDragable dragData session = - let - doMove : Session -> Session - doMove (Session config) = - Session { config | dragTracker = DragTracker.moveDragable dragData config.dragTracker } - in - session - |> updateBoardOrder dragData - |> doMove - - updateBoardOrder : DragData -> Session -> Session updateBoardOrder { cursor, beacons } ((Session config) as session) = case config.dragTracker of @@ -296,9 +296,15 @@ updateBoardOrder { cursor, beacons } ((Session config) as session) = session -waitForDrag : DragTracker.ClientData -> Session -> Session -waitForDrag clientData (Session config) = - Session { config | dragTracker = DragTracker.waitForDrag clientData } +updateColumnCollapse : Int -> Bool -> Session -> Session +updateColumnCollapse columnIndex isCollapsed (Session config) = + Session + { config + | settings = + Settings.updateCurrentBoard + (BoardConfig.collapseColumn columnIndex isCollapsed) + config.settings + } updateSettings : Settings -> Session -> Session @@ -311,6 +317,11 @@ updateTextDirection newTextDirection (Session config) = Session { config | textDirection = newTextDirection } +waitForDrag : DragTracker.ClientData -> Session -> Session +waitForDrag clientData (Session config) = + Session { config | dragTracker = DragTracker.waitForDrag clientData } + + -- TASKLIST MANIPULATION @@ -367,17 +378,6 @@ replaceTaskItems filePath updatedList ((Session config) as session) = updateTaskListState (State.Loaded (TaskList.replaceForFile filePath updatedList currentList)) session -updateColumnCollapse : Int -> Bool -> Session -> Session -updateColumnCollapse columnIndex isCollapsed (Session config) = - Session - { config - | settings = - Settings.updateCurrentBoard - (BoardConfig.collapseColumn columnIndex isCollapsed) - config.settings - } - - updatePath : String -> String -> Session -> Session updatePath oldPath newPath (Session config) = let From f8f902837cde1d1ff6f9bbc88f7a67b383c06659 Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 17:11:37 +0000 Subject: [PATCH 07/16] Cleanup: not using DragData.beaconType so remove it --- TODO.md | 2 -- src/DragAndDrop/DragData.elm | 4 +--- tests/DragAndDrop/DragDataTests.elm | 3 +-- tests/DragAndDrop/DragTrackerTests.elm | 9 +++------ tests/InteropDefinitionsTests.elm | 3 +-- tests/SessionTests.elm | 6 ++---- typescript/view.ts | 1 - 7 files changed, 8 insertions(+), 20 deletions(-) diff --git a/TODO.md b/TODO.md index 92207a0a..4249a86f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,3 @@ -- am I using DragData.beaconType ?? - - enable reorder boards on settings page too - tidy typescript - tidy elm diff --git a/src/DragAndDrop/DragData.elm b/src/DragAndDrop/DragData.elm index 385d67cb..d1423532 100644 --- a/src/DragAndDrop/DragData.elm +++ b/src/DragAndDrop/DragData.elm @@ -17,8 +17,7 @@ import TsJson.Decode as TsDecode type alias DragData = - { beaconType : String - , dragAction : DragAction + { dragAction : DragAction , cursor : Coords , offset : Coords , draggedNodeRect : Rect @@ -44,7 +43,6 @@ type alias BeaconData = decoder : TsDecode.Decoder DragData decoder = TsDecode.succeed DragData - |> TsDecode.andMap (TsDecode.field "beaconType" TsDecode.string) |> TsDecode.andMap dragActionDecoder |> TsDecode.andMap (TsDecode.field "cursor" Coords.decoder) |> TsDecode.andMap (TsDecode.field "offset" Coords.decoder) diff --git a/tests/DragAndDrop/DragDataTests.elm b/tests/DragAndDrop/DragDataTests.elm index 8b3444af..c2339720 100644 --- a/tests/DragAndDrop/DragDataTests.elm +++ b/tests/DragAndDrop/DragDataTests.elm @@ -24,8 +24,7 @@ decoder = |> .decoded |> Expect.equal (Ok <| - { beaconType = "an identifier" - , beacons = + { beacons = [ { beaconPosition = BeaconPosition.Before "someId" , rect = { x = 1.1, y = 2.2, width = 3.3, height = 4.4 } } diff --git a/tests/DragAndDrop/DragTrackerTests.elm b/tests/DragAndDrop/DragTrackerTests.elm index f2fa6fe6..c923fadc 100644 --- a/tests/DragAndDrop/DragTrackerTests.elm +++ b/tests/DragAndDrop/DragTrackerTests.elm @@ -71,8 +71,7 @@ moveDragable = \() -> let dragData = - { beaconType = "" - , dragAction = DragData.Move + { dragAction = DragData.Move , cursor = { x = 0, y = 1 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } @@ -86,8 +85,7 @@ moveDragable = \() -> let dragData = - { beaconType = "" - , dragAction = DragData.Move + { dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } @@ -116,8 +114,7 @@ moveDragable = \() -> let dragData = - { beaconType = "" - , dragAction = DragData.Move + { dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } diff --git a/tests/InteropDefinitionsTests.elm b/tests/InteropDefinitionsTests.elm index 2ee03558..e27c755f 100644 --- a/tests/InteropDefinitionsTests.elm +++ b/tests/InteropDefinitionsTests.elm @@ -633,8 +633,7 @@ toElmTests = |> Expect.equal (Ok <| InteropDefinitions.ElementDragged - { beaconType = "some-beacon-id" - , dragAction = DragData.Stop + { dragAction = DragData.Stop , cursor = { x = 1.23, y = 4.56 } , offset = { x = 1.11, y = 2.22 } , draggedNodeRect = { x = 1.1, y = 2.2, width = 3.33, height = 4.44 } diff --git a/tests/SessionTests.elm b/tests/SessionTests.elm index f9dfb610..dbe0fa85 100644 --- a/tests/SessionTests.elm +++ b/tests/SessionTests.elm @@ -193,8 +193,7 @@ moveDragable = \() -> let dragData = - { beaconType = "" - , dragAction = DragData.Move + { dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } @@ -284,8 +283,7 @@ stopTrackingDragable = \() -> let dragData = - { beaconType = "" - , dragAction = DragData.Move + { dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } diff --git a/typescript/view.ts b/typescript/view.ts index a3260007..c94af92a 100644 --- a/typescript/view.ts +++ b/typescript/view.ts @@ -387,7 +387,6 @@ export class CardBoardView extends ItemView { that.elm.ports.interopToElm.send({ tag: "elementDragged", data: { - beaconType: data.beaconType, dragAction: dragAction, cursor: coords(event), offset: { x: offsetLeft, y: offsetTop }, From e314932549993d8857972116a626857836a57ec0 Mon Sep 17 00:00:00 2001 From: roovo Date: Fri, 17 Nov 2023 20:20:31 +0000 Subject: [PATCH 08/16] Cleanup: move board reordering logic to the board page --- src/Page/Board.elm | 19 ++++++++++++++++++- src/Session.elm | 42 +++++++++++++++++------------------------- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/Page/Board.elm b/src/Page/Board.elm index 38bb598e..e704fcf8 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -52,13 +52,30 @@ beaconType = "data-card-board-tag-header-beacon" +updateBoardOrder : DragTracker -> DragData -> Session -> Session +updateBoardOrder dragTracker { cursor, beacons } session = + case dragTracker of + DragTracker.Dragging clientData _ -> + case Rect.closestTo cursor beacons of + Nothing -> + session + + Just position -> + Session.moveBoard clientData.uniqueId position session + + _ -> + session + + update : Msg -> Session -> ( Session, Cmd Msg, Session.Msg ) update msg session = case msg of ElementDragged dragData -> case dragData.dragAction of DragData.Move -> - ( Session.moveDragable dragData session + ( session + |> updateBoardOrder (Session.dragTracker session) dragData + |> Session.moveDragable dragData , Cmd.none , Session.NoOp ) diff --git a/src/Session.elm b/src/Session.elm index c155b760..bb488a80 100644 --- a/src/Session.elm +++ b/src/Session.elm @@ -30,7 +30,6 @@ module Session exposing , timeWithZone , timeWithZoneIs , uniqueId - , updateBoardOrder , updateColumnCollapse , updatePath , updateSettings @@ -250,15 +249,8 @@ moveBoard draggedId beaconPosition (Session config) = moveDragable : DragData -> Session -> Session -moveDragable dragData session = - let - doMove : Session -> Session - doMove (Session config) = - Session { config | dragTracker = DragTracker.moveDragable dragData config.dragTracker } - in - session - |> updateBoardOrder dragData - |> doMove +moveDragable dragData (Session config) = + Session { config | dragTracker = DragTracker.moveDragable dragData config.dragTracker } stopTrackingDragable : Session -> Session @@ -281,21 +273,6 @@ timeWithZoneIs zone time (Session config) = Session { config | timeWithZone = { zone = zone, time = time } } -updateBoardOrder : DragData -> Session -> Session -updateBoardOrder { cursor, beacons } ((Session config) as session) = - case config.dragTracker of - DragTracker.Dragging clientData _ -> - case Rect.closestTo cursor beacons of - Nothing -> - session - - Just position -> - moveBoard clientData.uniqueId position session - - _ -> - session - - updateColumnCollapse : Int -> Bool -> Session -> Session updateColumnCollapse columnIndex isCollapsed (Session config) = Session @@ -396,6 +373,21 @@ updatePath oldPath newPath (Session config) = -- PRIVATE +updateBoardOrder : DragData -> Session -> Session +updateBoardOrder { cursor, beacons } ((Session config) as session) = + case config.dragTracker of + DragTracker.Dragging clientData _ -> + case Rect.closestTo cursor beacons of + Nothing -> + session + + Just position -> + moveBoard clientData.uniqueId position session + + _ -> + session + + updateTaskListState : State TaskList -> Session -> Session updateTaskListState taskListState (Session config) = Session { config | taskList = taskListState } From 4f3b738eda3ab8b314dc05c992fdbf54a2ee73df Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 08:49:18 +0000 Subject: [PATCH 09/16] Cleanup: construct beaconType from a dragType --- src/InteropDefinitions.elm | 6 +++--- src/InteropPorts.elm | 4 ++-- src/Page/Board.elm | 13 +++++++++---- tests/InteropDefinitionsTests.elm | 4 ++-- typescript/view.ts | 7 ++++--- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/InteropDefinitions.elm b/src/InteropDefinitions.elm index 936aa094..119a7e1a 100644 --- a/src/InteropDefinitions.elm +++ b/src/InteropDefinitions.elm @@ -31,7 +31,7 @@ type FromElm | ElmInitialized | OpenTaskSourceFile { filePath : String, lineNumber : Int, originalText : String } | RequestFilterCandidates - | TrackDraggable { beaconType : String, clientPos : Coords, draggableId : String } + | TrackDraggable { dragType : String, clientPos : Coords, draggableId : String } | UpdateTasks { filePath : String, tasks : List { lineNumber : Int, originalText : String, newText : String } } @@ -109,10 +109,10 @@ openTaskSourceFileEncoder = ] -trackDraggableEncoder : TsEncode.Encoder { beaconType : String, clientPos : Coords, draggableId : String } +trackDraggableEncoder : TsEncode.Encoder { dragType : String, clientPos : Coords, draggableId : String } trackDraggableEncoder = TsEncode.object - [ required "beaconType" .beaconType TsEncode.string + [ required "dragType" .dragType TsEncode.string , required "clientPos" .clientPos Coords.encoder , required "draggableId" .draggableId TsEncode.string ] diff --git a/src/InteropPorts.elm b/src/InteropPorts.elm index d4abaeea..a7adb94b 100644 --- a/src/InteropPorts.elm +++ b/src/InteropPorts.elm @@ -102,8 +102,8 @@ rewriteTasks dataviewTaskCompletion taskCompletionFormat timeWithZone filePath t trackDraggable : String -> Coords -> String -> Cmd msg -trackDraggable beaconType clientPos draggableId = - { beaconType = beaconType, clientPos = clientPos, draggableId = draggableId } +trackDraggable dragType clientPos draggableId = + { dragType = dragType, clientPos = clientPos, draggableId = draggableId } |> encodeVariant "trackDraggable" InteropDefinitions.trackDraggableEncoder |> interopFromElm diff --git a/src/Page/Board.elm b/src/Page/Board.elm index e704fcf8..ed0746a6 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -47,9 +47,9 @@ type Msg | ToggleColumnCollapse Int Bool -beaconType : String -beaconType = - "data-card-board-tag-header-beacon" +dragType : String +dragType = + "card-board-tag-header" updateBoardOrder : DragTracker -> DragData -> Session -> Session @@ -94,7 +94,7 @@ update msg session = TabHeaderMouseDown ( domId, clientData ) -> ( Session.waitForDrag clientData session - , InteropPorts.trackDraggable beaconType clientData.clientPos domId + , InteropPorts.trackDraggable dragType clientData.clientPos domId , Session.NoOp ) @@ -347,6 +347,11 @@ viewDraggedHeader session = empty +beaconType : String +beaconType = + "data-" ++ dragType ++ "-beacon" + + beacon : BeaconPosition -> Html Msg beacon beaconPosition = Html.span diff --git a/tests/InteropDefinitionsTests.elm b/tests/InteropDefinitionsTests.elm index e27c755f..5ed960e9 100644 --- a/tests/InteropDefinitionsTests.elm +++ b/tests/InteropDefinitionsTests.elm @@ -589,11 +589,11 @@ fromElmTests = |> Expect.equal """{"tag":"requestFilterCandidates"}""" , test "encodes TrackDraggable data" <| \() -> - { beaconType = "someBeaconId", clientPos = { x = 1.1, y = 2.2 }, draggableId = "id of draggable" } + { dragType = "someDragType", clientPos = { x = 1.1, y = 2.2 }, draggableId = "id of draggable" } |> InteropDefinitions.TrackDraggable |> TsEncode.runExample interop.fromElm |> .output - |> Expect.equal """{"tag":"trackDraggable","data":{"beaconType":"someBeaconId","clientPos":{"x":1.1,"y":2.2},"draggableId":"id of draggable"}}""" + |> Expect.equal """{"tag":"trackDraggable","data":{"dragType":"someDragType","clientPos":{"x":1.1,"y":2.2},"draggableId":"id of draggable"}}""" , test "encodes UpdateTasks data" <| \() -> { filePath = "a path", tasks = [ { lineNumber = 12, originalText = "what was there", newText = "new text" } ] } diff --git a/typescript/view.ts b/typescript/view.ts index c94af92a..1c5ccbe2 100644 --- a/typescript/view.ts +++ b/typescript/view.ts @@ -327,7 +327,7 @@ export class CardBoardView extends ItemView { async handleTrackDraggable( data : { - beaconType: string, + dragType: string, clientPos : { x: number, y: number }, draggableId: string } @@ -337,6 +337,7 @@ export class CardBoardView extends ItemView { const that = this; const draggedElement = document.getElementById(data.draggableId); + const beaconType = "data-" + data.dragType + "-beacon"; document.addEventListener("mousemove", maybeDragMove); document.addEventListener("mouseup", stopAwaitingDrag); @@ -396,7 +397,7 @@ export class CardBoardView extends ItemView { width: draggedElementRect.width, height: draggedElementRect.height }, - beacons: beaconPositions(data.beaconType) + beacons: beaconPositions(beaconType) } }); } @@ -409,7 +410,7 @@ export class CardBoardView extends ItemView { function beaconData(elem: Element) { const boundingRect = elem.getBoundingClientRect(); - const beaconId = elem.getAttribute(data.beaconType); + const beaconId = elem.getAttribute(beaconType); return { beaconPosition: tryParse(beaconId), rect: { From ff44f8b85b5f85362b0fc5c6bdb0db160e5e6466 Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 09:20:00 +0000 Subject: [PATCH 10/16] Cleanup: pass dragType with dragData from typescript --- src/DragAndDrop/DragData.elm | 4 +++- tests/DragAndDrop/DragDataTests.elm | 5 +++-- tests/DragAndDrop/DragTrackerTests.elm | 9 ++++++--- tests/InteropDefinitionsTests.elm | 5 +++-- tests/SessionTests.elm | 6 ++++-- typescript/view.ts | 1 + 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/DragAndDrop/DragData.elm b/src/DragAndDrop/DragData.elm index d1423532..79ce625e 100644 --- a/src/DragAndDrop/DragData.elm +++ b/src/DragAndDrop/DragData.elm @@ -17,7 +17,8 @@ import TsJson.Decode as TsDecode type alias DragData = - { dragAction : DragAction + { dragType : String + , dragAction : DragAction , cursor : Coords , offset : Coords , draggedNodeRect : Rect @@ -43,6 +44,7 @@ type alias BeaconData = decoder : TsDecode.Decoder DragData decoder = TsDecode.succeed DragData + |> TsDecode.andMap (TsDecode.field "dragType" TsDecode.string) |> TsDecode.andMap dragActionDecoder |> TsDecode.andMap (TsDecode.field "cursor" Coords.decoder) |> TsDecode.andMap (TsDecode.field "offset" Coords.decoder) diff --git a/tests/DragAndDrop/DragDataTests.elm b/tests/DragAndDrop/DragDataTests.elm index c2339720..ed359f67 100644 --- a/tests/DragAndDrop/DragDataTests.elm +++ b/tests/DragAndDrop/DragDataTests.elm @@ -19,12 +19,13 @@ decoder = describe "decoder" [ test "decodes valid input" <| \() -> - """{"beaconType":"an identifier","dragAction":"move","cursor":{"x":1.1,"y":2.2},"offset":{"x":3.3,"y":4.4},"draggedNodeRect":{"x":1.2,"y":3.4,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"uniqueId":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}""" + """{"dragType":"aDragType","dragAction":"move","cursor":{"x":1.1,"y":2.2},"offset":{"x":3.3,"y":4.4},"draggedNodeRect":{"x":1.2,"y":3.4,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"uniqueId":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}""" |> DecodeHelpers.runDecoder DragData.decoder |> .decoded |> Expect.equal (Ok <| - { beacons = + { dragType = "aDragType" + , beacons = [ { beaconPosition = BeaconPosition.Before "someId" , rect = { x = 1.1, y = 2.2, width = 3.3, height = 4.4 } } diff --git a/tests/DragAndDrop/DragTrackerTests.elm b/tests/DragAndDrop/DragTrackerTests.elm index c923fadc..0f846a21 100644 --- a/tests/DragAndDrop/DragTrackerTests.elm +++ b/tests/DragAndDrop/DragTrackerTests.elm @@ -71,7 +71,8 @@ moveDragable = \() -> let dragData = - { dragAction = DragData.Move + { dragType = "aDragType" + , dragAction = DragData.Move , cursor = { x = 0, y = 1 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } @@ -85,7 +86,8 @@ moveDragable = \() -> let dragData = - { dragAction = DragData.Move + { dragType = "aDragType" + , dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } @@ -114,7 +116,8 @@ moveDragable = \() -> let dragData = - { dragAction = DragData.Move + { dragType = "aDragType" + , dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } diff --git a/tests/InteropDefinitionsTests.elm b/tests/InteropDefinitionsTests.elm index 5ed960e9..2746bd17 100644 --- a/tests/InteropDefinitionsTests.elm +++ b/tests/InteropDefinitionsTests.elm @@ -627,13 +627,14 @@ toElmTests = |> Expect.equal (Ok <| InteropDefinitions.ConfigChanged TextDirection.RightToLeft) , test "decodes elementDragged data" <| \() -> - """{"tag":"elementDragged","data":{"beaconType":"some-beacon-id","dragAction":"stop","cursor":{"x":1.23,"y":4.56},"offset":{"x":1.11,"y":2.22},"draggedNodeRect":{"x":1.1,"y":2.2,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"uniqueId":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}}""" + """{"tag":"elementDragged","data":{"dragType":"someDragType","dragAction":"stop","cursor":{"x":1.23,"y":4.56},"offset":{"x":1.11,"y":2.22},"draggedNodeRect":{"x":1.1,"y":2.2,"width":3.33,"height":4.44},"beacons":[{"beaconPosition":{"uniqueId":"someId","position":"before"},"rect":{"x":1.1,"y":2.2,"width":3.3,"height":4.4}}]}}""" |> DecodeHelpers.runDecoder interop.toElm |> .decoded |> Expect.equal (Ok <| InteropDefinitions.ElementDragged - { dragAction = DragData.Stop + { dragType = "someDragType" + , dragAction = DragData.Stop , cursor = { x = 1.23, y = 4.56 } , offset = { x = 1.11, y = 2.22 } , draggedNodeRect = { x = 1.1, y = 2.2, width = 3.33, height = 4.44 } diff --git a/tests/SessionTests.elm b/tests/SessionTests.elm index dbe0fa85..a1af3374 100644 --- a/tests/SessionTests.elm +++ b/tests/SessionTests.elm @@ -193,7 +193,8 @@ moveDragable = \() -> let dragData = - { dragAction = DragData.Move + { dragType = "aDragType" + , dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } @@ -283,7 +284,8 @@ stopTrackingDragable = \() -> let dragData = - { dragAction = DragData.Move + { dragType = "aDragType" + , dragAction = DragData.Move , cursor = { x = 1.1, y = 2.2 } , offset = { x = 1, y = 2 } , draggedNodeRect = { x = 2, y = 3, width = 4, height = 5 } diff --git a/typescript/view.ts b/typescript/view.ts index 1c5ccbe2..8f7fb95e 100644 --- a/typescript/view.ts +++ b/typescript/view.ts @@ -388,6 +388,7 @@ export class CardBoardView extends ItemView { that.elm.ports.interopToElm.send({ tag: "elementDragged", data: { + dragType: data.dragType, dragAction: dragAction, cursor: coords(event), offset: { x: offsetLeft, y: offsetTop }, From 6a59df75ea83b41f01748210715dfe45e3c25d78 Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 09:24:09 +0000 Subject: [PATCH 11/16] Cleanup: only act on matching drag moves --- src/Page/Board.elm | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Page/Board.elm b/src/Page/Board.elm index ed0746a6..9c2db334 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -73,12 +73,16 @@ update msg session = ElementDragged dragData -> case dragData.dragAction of DragData.Move -> - ( session - |> updateBoardOrder (Session.dragTracker session) dragData - |> Session.moveDragable dragData - , Cmd.none - , Session.NoOp - ) + if dragData.dragType == dragType then + ( session + |> updateBoardOrder (Session.dragTracker session) dragData + |> Session.moveDragable dragData + , Cmd.none + , Session.NoOp + ) + + else + ( session, Cmd.none, Session.NoOp ) DragData.Stop -> ( Session.stopTrackingDragable session From d791c223163ac3f064654da8fbe32203c0285af2 Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 09:38:36 +0000 Subject: [PATCH 12/16] Cleanup: fix function ordering --- src/Page/Board.elm | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Page/Board.elm b/src/Page/Board.elm index 9c2db334..7327c384 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -52,21 +52,6 @@ dragType = "card-board-tag-header" -updateBoardOrder : DragTracker -> DragData -> Session -> Session -updateBoardOrder dragTracker { cursor, beacons } session = - case dragTracker of - DragTracker.Dragging clientData _ -> - case Rect.closestTo cursor beacons of - Nothing -> - session - - Just position -> - Session.moveBoard clientData.uniqueId position session - - _ -> - session - - update : Msg -> Session -> ( Session, Cmd Msg, Session.Msg ) update msg session = case msg of @@ -168,6 +153,21 @@ cmdIfHasTask id session cmd = |> Maybe.withDefault Cmd.none +updateBoardOrder : DragTracker -> DragData -> Session -> Session +updateBoardOrder dragTracker { cursor, beacons } session = + case dragTracker of + DragTracker.Dragging clientData _ -> + case Rect.closestTo cursor beacons of + Nothing -> + session + + Just position -> + Session.moveBoard clientData.uniqueId position session + + _ -> + session + + -- VIEW From 26efcdfadfb7fe3dc2ae977f05a7aa6c527109bd Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 10:18:53 +0000 Subject: [PATCH 13/16] Cleanup: dragTracker needs to track the dragType --- src/DragAndDrop/DragTracker.elm | 13 ++++++++++--- tests/DragAndDrop/DragTrackerTests.elm | 6 +++++- tests/SessionTests.elm | 22 +--------------------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/DragAndDrop/DragTracker.elm b/src/DragAndDrop/DragTracker.elm index ef6211ec..88f26f3b 100644 --- a/src/DragAndDrop/DragTracker.elm +++ b/src/DragAndDrop/DragTracker.elm @@ -31,7 +31,8 @@ type alias ClientData = type alias DomData = - { offset : Coords + { dragType : String + , offset : Coords , draggedNodeStartRect : Rect } @@ -71,12 +72,18 @@ moveDragable dragData dragTracker = Waiting clientData -> Dragging { clientData | clientPos = dragData.cursor } - { offset = dragData.offset, draggedNodeStartRect = dragData.draggedNodeRect } + { offset = dragData.offset + , draggedNodeStartRect = dragData.draggedNodeRect + , dragType = dragData.dragType + } Dragging clientData domData -> Dragging { clientData | clientPos = dragData.cursor } - { domData | offset = dragData.offset } + { domData + | offset = dragData.offset + , dragType = dragData.dragType + } stopTracking : DragTracker diff --git a/tests/DragAndDrop/DragTrackerTests.elm b/tests/DragAndDrop/DragTrackerTests.elm index 0f846a21..ec67c772 100644 --- a/tests/DragAndDrop/DragTrackerTests.elm +++ b/tests/DragAndDrop/DragTrackerTests.elm @@ -58,6 +58,7 @@ isDragging = } { offset = { x = 0, y = 0 } , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + , dragType = "aDragType" } |> DragTracker.isDragging |> Expect.equal True @@ -110,9 +111,10 @@ moveDragable = } { offset = { x = 1, y = 2 } , draggedNodeStartRect = { x = 2, y = 3, width = 4, height = 5 } + , dragType = "aDragType" } ) - , test "updates clientPos and offset if it was already Dragging" <| + , test "updates clientPos, offset and dragType if it was already Dragging" <| \() -> let dragData = @@ -137,6 +139,7 @@ moveDragable = } { offset = { x = 0, y = 0 } , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + , dragType = "oldDragType" } |> DragTracker.moveDragable dragData |> Expect.equal @@ -147,6 +150,7 @@ moveDragable = } { offset = { x = 1, y = 2 } , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + , dragType = "aDragType" } ) ] diff --git a/tests/SessionTests.elm b/tests/SessionTests.elm index a1af3374..21131867 100644 --- a/tests/SessionTests.elm +++ b/tests/SessionTests.elm @@ -219,32 +219,12 @@ moveDragable = } { offset = { x = 1, y = 2 } , draggedNodeStartRect = { x = 2, y = 3, width = 4, height = 5 } + , dragType = "aDragType" } ) ] - --- stopTrackingDragable : Test --- stopTrackingDragable = --- describe "stopTrackingDragable" --- [ test "stops tracking a TabHeader" <| --- \() -> --- Session.default --- |> Session.trackDraggable --- (DragTracker "3" --- { x = 0, y = 0 } --- { x = 0, y = 0 } --- { x = 0, y = 0 } --- { x = 0, y = 0, width = 0, height = 0 } --- ) --- { x = 0, y = 0, width = 0, height = 0 } --- |> Session.stopTrackingDragable --- |> Session.isDragging --- |> Expect.equal False --- ] - - replaceTaskItems : Test replaceTaskItems = describe "replaceTaskItems" From 9468c298e9f99d89b5f12eda4fafe43ec2fba468 Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 10:29:31 +0000 Subject: [PATCH 14/16] Cleanup: only show dragged elements if dragType matches --- src/DragAndDrop/DragTracker.elm | 14 ++++++++++ src/Page/Board.elm | 8 +++++- tests/DragAndDrop/DragTrackerTests.elm | 36 +++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/DragAndDrop/DragTracker.elm b/src/DragAndDrop/DragTracker.elm index 88f26f3b..69b8c343 100644 --- a/src/DragAndDrop/DragTracker.elm +++ b/src/DragAndDrop/DragTracker.elm @@ -1,6 +1,7 @@ module DragAndDrop.DragTracker exposing ( ClientData , DragTracker(..) + , dragType , init , isDragging , moveDragable @@ -46,6 +47,19 @@ init = -- INFO +dragType : DragTracker -> Maybe String +dragType dragTracker = + case dragTracker of + NotDragging -> + Nothing + + Waiting _ -> + Nothing + + Dragging _ domData -> + Just domData.dragType + + isDragging : DragTracker -> Bool isDragging dragTracker = case dragTracker of diff --git a/src/Page/Board.elm b/src/Page/Board.elm index 7327c384..f9835c10 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -203,7 +203,13 @@ view session = isDragging : Bool isDragging = - Session.isDragging session + Session.isDragging session && draggedType == Just dragType + + draggedType : Maybe String + draggedType = + session + |> Session.dragTracker + |> DragTracker.dragType in Html.div [ attribute "dir" (TextDirection.toString <| Session.textDirection session) diff --git a/tests/DragAndDrop/DragTrackerTests.elm b/tests/DragAndDrop/DragTrackerTests.elm index ec67c772..d950fe4f 100644 --- a/tests/DragAndDrop/DragTrackerTests.elm +++ b/tests/DragAndDrop/DragTrackerTests.elm @@ -9,7 +9,8 @@ import Test exposing (..) suite : Test suite = concat - [ init + [ dragType + , init , isDragging , moveDragable , stopTracking @@ -17,6 +18,39 @@ suite = ] +dragType : Test +dragType = + describe "dragType" + [ test "is Nothingl if in NotDragging state" <| + \() -> + DragTracker.init + |> DragTracker.dragType + |> Expect.equal Nothing + , test "returns Nothingl if it was Waiting" <| + \() -> + DragTracker.waitForDrag + { uniqueId = "an id" + , clientPos = { x = 0, y = 1 } + , offsetPos = { x = 1, y = 2 } + } + |> DragTracker.dragType + |> Expect.equal Nothing + , test "returns Just dragType if Dragging" <| + \() -> + DragTracker.Dragging + { uniqueId = "an id" + , clientPos = { x = 0, y = 0 } + , offsetPos = { x = 1, y = 2 } + } + { offset = { x = 0, y = 0 } + , draggedNodeStartRect = { x = 0, y = 0, width = 0, height = 0 } + , dragType = "aDragType" + } + |> DragTracker.dragType + |> Expect.equal (Just "aDragType") + ] + + init : Test init = describe "init" From 45be11f96ebab196dd7112d44ccef2a41ab72a28 Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 10:42:36 +0000 Subject: [PATCH 15/16] Cleanup: clear tab header aria label when dragging --- src/Page/Board.elm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Page/Board.elm b/src/Page/Board.elm index f9835c10..be35cb09 100644 --- a/src/Page/Board.elm +++ b/src/Page/Board.elm @@ -235,7 +235,7 @@ view session = , Html.div [ class "workspace-tab-header-container-inner" ] (tabHeaders isDragging currentBoardIndex boards - ++ [ viewDraggedHeader session ] + ++ [ viewDraggedHeader isDragging session ] ) , Html.div [ class "card-board-tab-header-spacer" ] @@ -308,6 +308,7 @@ selectedTabHeader isDragging tabIndex title = [ class "workspace-tab-header is-active" , id domId , attributeIf (not isDragging) (attribute "aria-label" title) + , attributeIf isDragging (attribute "aria-label" "") , attributeIf (not isDragging) (attribute "aria-label-delay" "50") , attributeIf isDragging (style "opacity" "0.0") , onDown @@ -331,10 +332,10 @@ selectedTabHeader isDragging tabIndex title = ] -viewDraggedHeader : Session -> Html Msg -viewDraggedHeader session = - case Session.dragTracker session of - DragTracker.Dragging clientData domData -> +viewDraggedHeader : Bool -> Session -> Html Msg +viewDraggedHeader isDragging session = + case ( isDragging, Session.dragTracker session ) of + ( True, DragTracker.Dragging clientData domData ) -> Html.div [ class "workspace-tab-header is-active" , id <| "card-board-tab:being-dragged" From a637cb8e0902979b1e410a71319d589d038abaaf Mon Sep 17 00:00:00 2001 From: roovo Date: Sat, 18 Nov 2023 11:42:52 +0000 Subject: [PATCH 16/16] Cleanup: pass plugin component to renderMarkdown --- typescript/view.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typescript/view.ts b/typescript/view.ts index 8f7fb95e..cbd16e81 100644 --- a/typescript/view.ts +++ b/typescript/view.ts @@ -218,7 +218,7 @@ export class CardBoardView extends ItemView { if (element instanceof HTMLElement) { element.innerHTML = ""; - MarkdownRenderer.renderMarkdown(item.markdown, element, card.filePath, this); + MarkdownRenderer.renderMarkdown(item.markdown, element, card.filePath, that.plugin); const internalLinks = Array.from(element.getElementsByClassName("internal-link"));