-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For #6518: templates cursor navigation
- Loading branch information
Erik Bruchez
committed
Nov 11, 2024
1 parent
7608323
commit 34643f6
Showing
6 changed files
with
158 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
form-builder/js/src/main/scala/org/orbeon/builder/FormSettings.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.orbeon.builder | ||
|
||
import org.orbeon.datatypes.Direction | ||
import org.orbeon.web.DomSupport.{DomElemOps, moveIntoViewIfNeeded} | ||
import org.orbeon.xforms.EventListenerSupport | ||
import org.orbeon.xforms.facade.{XBL, XBLCompanion} | ||
import org.scalajs.dom.{KeyboardEvent, html} | ||
|
||
import scala.scalajs.js | ||
|
||
|
||
object FormSettings { | ||
|
||
XBL.declareCompanion("fb|dialog-form-settings", js.constructorOf[ControlSettingsCompanion]) | ||
|
||
private class ControlSettingsCompanion(containerElem: html.Element) extends XBLCompanion { | ||
|
||
private object EventSupport extends EventListenerSupport | ||
|
||
private val KeyMapping = Map( | ||
"ArrowLeft" -> Direction.Left, | ||
"ArrowRight" -> Direction.Right, | ||
"ArrowUp" -> Direction.Up, | ||
"ArrowDown" -> Direction.Down | ||
) | ||
|
||
def dialogOpening(): Unit = { | ||
|
||
val isNew = containerElem.querySelectorOpt(".fb-settings-mode-new").nonEmpty | ||
|
||
def findCardsForDirections: Map[Direction, html.Element] = { | ||
val cards = containerElem.querySelectorAllT(".fb-template-card") | ||
|
||
Some(cards.indexWhere(_.classList.contains("xforms-repeat-selected-item-1"))) | ||
.filter(_ >= 0) | ||
.map { index => | ||
|
||
val lifted = cards.lift | ||
|
||
( | ||
lifted(index - 1).map((Direction.Left : Direction) -> _).toList ::: | ||
lifted(index + 1).map((Direction.Right: Direction) -> _).toList ::: | ||
lifted(index - 4).map((Direction.Up : Direction) -> _).toList ::: | ||
lifted(index + 4).map((Direction.Down : Direction) -> _).toList | ||
).toMap | ||
} | ||
.getOrElse(Map.empty) | ||
} | ||
|
||
if (isNew) | ||
EventSupport.addListener[KeyboardEvent](containerElem, "keydown", e => | ||
KeyMapping.get(e.key).foreach { direction => | ||
findCardsForDirections.get(direction).foreach { card => | ||
moveIntoViewIfNeeded( | ||
containerElem.querySelectorOpt(".fb-template-cards-container").get, | ||
containerElem.querySelectorOpt(".fb-template-cards").get, | ||
card | ||
) | ||
card.click() | ||
} | ||
} | ||
) | ||
} | ||
|
||
def dialogClosing(): Unit = | ||
EventSupport.clearAllListeners() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters