export function canDrag()

in src/hooks/useDragAndDrop.ts [29:48]


export function canDrag(stepIndex: number, steps: Steps): boolean | null {
  if (stepIndex === 0) return null;
  /**
   * A step heading is draggable if there's _somewhere_ for it to go between the preceeding
   * step and the next step. This means there needs to be two successive actions for the
   * step heading to place itself when dragging.
   *
   * Example:
   * In [a1], [a2], [a3], no steps are draggable, because we can't put the selector "between" these three actions.
   * [a1, a2], [a3], [a4], `stepIndex` 1 is draggable, because it can go "between" `a1` and `a2`
   *
   * The first step is never draggable, because the list must start with a step heading.
   */
  return (
    (steps[stepIndex - 1].actions.length <= 1 &&
      steps[stepIndex].actions.length <= 1 &&
      steps[stepIndex + 1]?.actions &&
      steps[stepIndex + 1].actions.length <= 1) === false
  );
}