Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Feature/drag drop v2 #194

Merged
merged 38 commits into from
Apr 26, 2018
Merged

Feature/drag drop v2 #194

merged 38 commits into from
Apr 26, 2018

Conversation

Mboulianne
Copy link
Contributor

@Mboulianne Mboulianne commented Apr 13, 2018

@ulaval/modul-components

PR Checklist

  • Provide a small description of the changes introduced by this PR
    V2 du drag and drop.

  • Include links to issues
    MODUL-21

  • Include this section in the release notes
    Drag and drop v2

  • Ajout d'une classe m--is-grabbing quand on "grab" un élément draggable.

  • Gestion de l'update dynamiques des propriétés des directives. (:x-y-z="abc")

  • Permettre le scroll sur les entête position: fixed. v-m-draggable-allow-scroll. Fix s'applique seulement si le polyfill est actif.

  • Ne pas permettre la sélection (long touch, double click, etc) sur les éléments draggable ou droppable.

  • Gestion du ghost image (sauf sur edge)

  • Ajout de quelques tests pour les bouts les plus simples. (à suivre)

  • Assurer que les transition-group fonctionnent

  • Beaucoup de fix pour bug de compatibilité cross-browser

  • Other info
    Début d'une doc pour confluence pour aider les devs à débuter l'intégration.
    Doc Sortable/Droppable/Sortable

-Fix some flickers issues in sortable (again!)
-Remove the possibility to select text in the draggable / droppable container.
Fix insert parameter in droppable directive bind
Rework droppable binding.
Rework sortable binding.
Fix undefined accepted actions on sortable
First work on sortable insertion behavior
@Mboulianne
Copy link
Contributor Author

Je submit la PR.. mais je dois encore terminer 1 truc ou 2 lundi.

Je submit tout suite qu'on puisse la regarder pour éventuellement release mercredi

add event.stopPropagation where events are handled by custom code.
Add m--is-grabbing class for desktop
Support is limited.. will fully work on edge but will only partially work fir all other browsers
…rify if the element has a vue instance. If it does, emit the event through the $emit service. Else, use native element.dispatchEvent
fix droppable leave on firefox.
… everything is detached when the binding of each direction = false
…he element after a drop if the drop wasn't accepted.
element[constructorFunction.defaultMountPoint] = plugin;
return plugin;
} else {
return new NullObjectMElementPlugin(options);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si le plugin est finalement pas mount pour une raison quelconque, je retourne un null object pour avoir à fairep lein de if (pluginExist) partout dans le code. C'tait trop tannant

if (this.options.canDrag === undefined) { this.options.canDrag = true; }
if (this.options.canDrag) {
mount(() => {
this.element.classList.add(MDraggableClassNames.Draggable);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

le mount permet au attach de décider, selon une condition, si on veut ou pas associer la logique de directive à l'élément.

Mounted = 'mounted',
UnMounted = 'unmounted'
}
export abstract class MElementPlugin<OptionsType> implements IMElementPlugin<OptionsType> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai jamais expliqué pk j'ai eu à faire ça mais voilà =>
Avec le drag and drop je dois être capable de gérer les 2 situations suivantes =>
1- pouvoir drag / drop / sort en associant une directive à l'élément

2- je dois aussi être en mesure de "composer" dynamiquement le comportement d'une directive. Pour éviter la duplication de code, fallait donc que j'extract la logique des directives sortable / droppable afin de pouvoir les composer dans sortable :)

getInsertPosition(event: MDropEvent): MSortInsertPositions;
}

export class MSortableDefaultInsertionMarkerBehavior implements MSortableInsertionMarkerBehavior {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permet de définir le comportement de sort before / after. On pourrait ensuite imaginer qu'un component implémente un interface semblable et laisser le component dicter le comportement du "insert" (before, on, after)

this.showPlaceHolder();
element.insertAdjacentElement(insertPosition, this.placeHolderElement);
private getInsertionMarkerBehavior(): MSortableInsertionMarkerBehavior {
/*const droppable: MDroppable = MDroppable.currentHoverDroppable as MDroppable;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sera commenté out dasns une prochaine itération

import { DirectiveOptions, VNodeDirective, VNode, PluginObject } from 'vue';
import { REMOVE_USER_SELECT } from '../directive-names';

export class MRemoveUserSelect extends MElementPlugin<boolean> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directive qui enlève la possibilité au user de
Sélectionner du texte en "draggant" dessus sur desktop.
En double clickant sur desktop.
En faisant un long touch sur mobile

__vue__: any;
}
export const dispatchEvent = (element: HTMLElement, eventName: string, eventData: any): void => {
const vueElement: VueElement = element as VueElement;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ceci est un peu un hack. Mes directives Droppable / Sortables / Draggable doivent pouvoir émettre des events dans le bus de Vue JS si possible. En gros, si on mount la directive sur un component, il est impératif qu'on $emit via l'instance vue.. sinon l'évènement se perd dans le néant.

@@ -0,0 +1,89 @@
import { DRAGGABLE_ALLOW_SCROLL } from '../directive-names';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Permet le scroll natif des browsers sur desktop quand on dragOver sur un élément position: fixed. C'est un peu hacky mais ça règle notre problème pour pas cher.

Copy link
Member

@simardo simardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encore une fois j'ai noté quelques petites choses mineures au niveau syntaze principalement. Honnêtement il y a beaucoup de trop de code pour que je puisse regarder le "mécanique" de tout ça. Éventuellement faudrait prévoir un peu de temps pour que tu présentes tout ça à quelques développeurs, ne serait-ce que pour en faire la maintenance.
Tu rajouteras l'info nécessaire dans la description du PR #194 et on merge!

@@ -1,7 +1,9 @@
export const DRAGGABLE: string = 'm-draggable';
export const DRAGGABLE_ALLOW_SCROLL: string = 'm-draggable-allow-scroll';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mets un suffixe _NAME à tes noms de directives. ça m'avait échappé le premier coup puisque je voyais juste les nouvelles directives dans le file-change-viewer de github.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. J'ai fix TEXTAREA_AUTO_HEIGHT au passage

}
}

export interface IMElementPlugin<OptionsType> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas besoin de préfixer le nom de l'interface avec un "I". Les internets ont déjà explosé à ce sujet :) microsoft/TypeScript-Handbook#121

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas de troubles avec ça!

protected attachedEvents: Map<string, EventListenerOrEventListenerObject[]> = new Map<string, EventListenerOrEventListenerObject[]>();
protected _options: OptionsType;
private readonly _element: HTMLElement;
public get element(): HTMLElement { return this._element; }
private _status: MElementPluginStatus = MElementPluginStatus.UnMounted;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Côté convention, je ne m'y étais pas vraiment attardé, mais je ne crois pas utile de préfixer par un ' _ ' les attributs private. Typiquement, si tu déclares l'attribut privé, le "compilateur" ne te laissera pas y accéder à l'extérieur de la classe. J'ai vu par contre la convention du ' _ ' dans du pur Javascript, puisque tout est accessible de partout. Typescript lui-même va générer des attributs préfixés de ' _ ' lorsqu'il produit le Javascript.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'ai enlevé le status.

Dans les faits j'utilise _someThing quand on cache une propriété derrière un get / set

private myProperty;
public get myProperty() { return this.
.myProperty }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bon point pour le cas du get/set

bind(element: HTMLElement, binding: VNodeDirective, node: VNode): void {
MDOMPlugin.attach(MDraggable, element, extractVnodeAttributes(node));
inserted(element: HTMLElement, binding: VNodeDirective, node: VNode): void {
const test = MDOMPlugin.attach(MDraggable, element, extractVnodeAttributes(binding, node));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

à quoi sert le "test" ici?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

À rien. Oublie

import { MDroppable } from '../droppable/droppable';
import { MElementPlugin, MDOMPlugin, MountFunction, RefreshFunction } from '../domPlugin';
import { getVNodeAttributeValue, dispatchEvent } from '../../utils/vue/directive';
import { MDroppable, MDroppableClassNames } from '../droppable/droppable';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDroppableClassNames ne semble pas utilisé dans la classe

import { MDroppable, MDroppableClassNames } from '../droppable/droppable';
import { clearUserSelection } from '../../utils/selection/selection';
import { MRemoveUserSelect } from '../user-select/remove-user-select';
import { MSortable } from '../sortable/sortable';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MSortable ne semble pas utilisé dans la classe

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mboulianne Installe l'extension typescript hero pour auto nettoyer tes imports au save

Copy link
Contributor Author

@Mboulianne Mboulianne Apr 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je l'avais déjà install.. je l'avais juste pas config comme du monde :(

@simardo simardo merged commit d013a4b into develop Apr 26, 2018
@simardo simardo deleted the feature/drag-drop-v2 branch April 26, 2018 13:18
@simardo simardo added this to the 1.0.0-beta.30 milestone Apr 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants