Skip to content
Permalink
Browse files

WIP: fix keyboard drag issue

  • Loading branch information
kennethanCeyer
kennethanCeyer committed Mar 30, 2018
1 parent e0369b0 commit 8e743cefc20327bc48dbededa0a9331562bd779d
Showing with 115 additions and 70 deletions.
  1. +49 −34 dist/formulize.umd.js
  2. +1 −1 dist/formulize.umd.js.map
  3. +4 −0 dist/ui/ui.manager.d.ts
  4. +61 −35 src/ui/ui.manager.ts

Some generated files are not rendered by default. Learn more.

Large diffs are not rendered by default.

@@ -18,6 +18,10 @@ export declare abstract class UIManager extends UiAnalyzer {
protected selectRange(start: number, end: number): void;
protected removeBefore(): void;
protected removeAfter(): void;
protected dragFirst(): void;
protected dragLast(): void;
protected dragLeft(): void;
protected dragRight(): void;
private moveCursorBefore(elem);
private moveCursorAfter(elem);
protected moveLeftCursor(dragMode?: boolean): void;
@@ -214,6 +214,52 @@ export abstract class UIManager extends UiAnalyzer {
this.triggerUpdate();
}

protected dragFirst(): void {
this.cursor.prevAll().prependTo(this.dragElem);
this.cursor.insertAfter(this.dragElem);
}

protected dragLast(): void {
this.cursor.nextAll().appendTo(this.dragElem);
this.cursor.insertBefore(this.dragElem);
}

protected dragLeft(): void {
if (UIElementHelper.isDrag(this.options.id, this.cursor.prev().get(0))) {
this.dragElem.prev().prependTo(this.dragElem);
this.moveCursorAfter(this.dragElem.get(0));
return;
}

if (UIElementHelper.isDrag(this.options.id, this.cursor.next().get(0))) {
const lastDraggedElem = this.dragElem.children().last();
lastDraggedElem.insertAfter(this.dragElem);

if (!this.dragElem.children().length)
this.removeDrag();

return;
}
}

protected dragRight(): void {
if (UIElementHelper.isDrag(this.options.id, this.cursor.next().get(0))) {
this.dragElem.next().appendTo(this.dragElem);
this.moveCursorBefore(this.dragElem.get(0));
return;
}

if (UIElementHelper.isDrag(this.options.id, this.cursor.prev().get(0))) {
const firstDraggedElem = this.dragElem.children().first();
firstDraggedElem.insertBefore(this.dragElem);

if (!this.dragElem.children().length)
this.removeDrag();

return;
}
}

private moveCursorBefore(elem: HTMLElement) {
if (!$(elem).length)
return;
@@ -231,30 +277,23 @@ export abstract class UIManager extends UiAnalyzer {
protected moveLeftCursor(dragMode: boolean = false): void {
const prevCursorElem = this.cursor.prev();

if (!this.cursor.length || !prevCursorElem.length || !dragMode) {
this.removeDrag();
if (!this.cursor.length || !dragMode) {
this.moveCursorBefore(prevCursorElem.get(0));
this.removeDrag();
return;
}

if (!this.dragElem.length) {
if (!prevCursorElem.length)
return;

const dragElem = $(UIElementHelper.getDragElement(this.options.id));
dragElem.insertBefore(this.cursor);
prevCursorElem.prependTo(this.dragElem);
return;
}

if (prevCursorElem.hasClass(`${this.options.id}-drag`)) {
const draggedUnit = this.dragElem.children();
if (!draggedUnit.length) {
this.dragElem.remove();
return;
}

draggedUnit.last().insertAfter(this.dragElem);
this.moveCursorAfter(this.dragElem.get(0));
return;
}
this.dragLeft();
}

protected moveUpCursor(): void {
@@ -270,31 +309,23 @@ export abstract class UIManager extends UiAnalyzer {
protected moveRightCursor(dragMode: boolean = false): void {
const nextCursorElem = this.cursor.next();

if (!this.cursor.length || !nextCursorElem.length || !dragMode) {
this.removeDrag();
if (!this.cursor.length || !dragMode) {
this.moveCursorAfter(nextCursorElem.get(0));
this.removeDrag();
return;
}

if (!this.dragElem.length) {
const dragElem = $(UIElementHelper.getDragElement(this.options.id));
dragElem.insertBefore(this.cursor);
nextCursorElem.appendTo(this.dragElem);
return;
}

if (nextCursorElem.hasClass(`${this.options.id}-drag`)) {
const draggedUnit = this.dragElem.children();
if (!draggedUnit.length) {
this.dragElem.remove();
if (!nextCursorElem.length)
return;
}

draggedUnit.first().insertBefore(this.dragElem)
this.moveCursorBefore(this.dragElem.get(0));
const dragElem = $(UIElementHelper.getDragElement(this.options.id));
dragElem.insertAfter(this.cursor);
nextCursorElem.appendTo(this.dragElem);
return;
}

this.dragRight();
}

protected moveDownCursor(): void {
@@ -320,10 +351,7 @@ export abstract class UIManager extends UiAnalyzer {
dragElem.insertAfter(this.cursor);
}

this.cursor
.prevAll()
.toArray()
.forEach(elem => $(elem).prependTo(this.dragElem));
this.dragFirst();
}

protected moveLastCursor(dragMode: boolean = false): void {
@@ -339,9 +367,7 @@ export abstract class UIManager extends UiAnalyzer {
dragElem.insertBefore(this.cursor);
}

this.cursor
.nextAll()
.appendTo(this.dragElem);
this.dragLast();
}

public clear() {

0 comments on commit 8e743ce

Please sign in to comment.
You can’t perform that action at this time.