Git Product home page Git Product logo

katavorio's Introduction

NOTE As of May 2022 this project has been archived. No development work has been done for 18 months or so as the drag handling code in jsPlumb has been moved to a module in the 5.x branch.

Katavorio

Katavorio is a lightweight drag/drop handler, supporting containment, multiple element drag, custom css classes, drop filters, drag filters, drag clones, drag handles, constraining movement to a grid, and zooming.

Katavorio does not work "out of the box" - it was developed as part of jsPlumb 1.6.0, to support a "no dependency" version (all previous versions of jsPlumb required either jQuery, MooTools or YUI, to provide a bunch of functionality such as CSS manipulation, getting/setting element positions, supporting drag/drop etc). So, rather than re-write simple methods such as addClass, removeClass, getPosition etc, Katavorio expects those methods to be provided in the constructor's options object.

All is not lost, though, as this project also contains DefaultKatavorioHelper - the set of missing methods.

Installation

npm install katavorio

NOTE: Katavorio does not follow strict semantic versioning. It is not at all recommended that you use wildcards when specifying a dependency on Katavorio.

Dependencies

None

Imports

If you have jsPlumb in your page then you already have Katavorio - it is bundled into jsPlumb. Otherwise you'll need to import two scripts:

node_modules/katavorio/src/default-katavorio-helper.js
node_modules/katavorio/src/katavorio.js

For more information, take a look in the wiki.

Changelog

1.5.1

17 Sep 2020

  • added a test in elementRemoved to check if an element is in fact draggable/droppable before running the code to de-register it.

1.5.0

  • Changed package name to @jsplumb/katavorio

1.4.11

  • support constrain functions in a drag selector

1.4.10

  • support ghost proxy handling by selectors in a drag.

1.4.9

  • return grid position from snap method on draggable.

1.4.8

  • support filter and filterExclude in delegated drag handlers

1.4.7

  • pass current drag element in callback to "should proxy" function. Required when a delegate drag is occurring.

1.4.6

  • pass the return value of a delegate to the code that tests if a drag can begin.

1.4.5

  • fixed an issue with drag stop event for single node drags.

1.4.4

  • support revert function being passed in to constructor.

1.4.3

  • added support for "combinator rooted" queries for delegated drags.

1.4.2

  • added support for provision of ghostProxyParent when using a ghost proxy to drag.

1.4.1

  • add test to ensure event's default not prevented when responding to initial mouse down

1.4.0

  • Add support for multiple selector definitions on a single Drag object, via the new addSelector method. You can make some element draggable and then attach more listeners to that object, rather than having to create a whole new draggable:
let d = katavorioInstance.draggable(someElement, {
  selector:".childSelector",
  start:function(p) { ... },
  etc
});

d.addSelector({
  selector:".someOtherChildSelector",
  start:function(p) { ... },
  etc
});

1.3.0

  • for delegated draggables (ie when you provide a selector in the params), we use the class katavorio-delegated-draggable now, instead of where we previously used the default draggable class of katavorio-draggable. This can also be overridden in the constructor by setting the value of delegatedDraggable.

0.28.0

  • add the ability for a user to specify the parent to use when cloning a node for dragging.

0.26.0

  • added the ability to remove specific drag/drop handlers (previous we could only completely switch off drag/drop)

katavorio's People

Contributors

besslwalker avatar brunorb avatar jordyvandortmont avatar sporritt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

katavorio's Issues

Nested draggables

We need to be able to support "nested" draggables: elements that are draggable in this instance of Katavorio and which manage a set of draggable elements. The exact details are unclear...this issue is a place to gather some thoughts.

There are a couple of things we know already:

  • events from a nested draggable should include information about the nested draggable's parent element
  • we'll probably want enough of an API to move nested elements around between draggable parents
  • the key difference when dragging a nested draggable is that the given getPosition function (which is not a part of Katavorio; you plug it in) needs to be smart enough to report positions relative to the nested draggable's offsetParent. And so it may be the case that the getPosition function needs to be told about the offset parent.

option to disable drag with middlemouseclick?

I would like in jsplumb to be able to disable dragging of elements with the middle mouse button, so that dragging works only with the left button. Would it be possible to have an additional option in katavorio for enabling disabling middle mouse drag, e.g.

k.draggable(someElement, {
middleButtonCanDrag:true
});

Or if there is a better way to achieve this i'm all ears :)

deactivate dragging tempoarily

In some cases it would make sense to disable dragging elements in jsplumb/katavorio temporarily. For example, in jQueryUI dragging can be disabled by using $( ".dragMe" ).draggable("option", "disabled", true ); and re-enabled using $( ".window" ).draggable("option", "disabled", false );
It would be useful to have a similar method in katavorio e.g. katavioInstance.draggable(someElement, {disabled:true})

(in case this is a functionality that would concern jsPlumb rather than katavorio, please drop a line in the comment. In this case, I'll close the requrest and recreate it in the jsPlumb issues)

Wrong order of snapThreshold?

It looks to me that currently snapThreshold is not respected if the grid is set.

In https://github.com/jsplumb/katavorio/blob/master/src/katavorio.js#L251 we see the following lines:

var tx = this.params.grid ? this.params.grid[0] / 2 : snapThreshold ? snapThreshold : DEFAULT_GRID_X / 2

Wouldn't it make more sense to do

var tx = snapThreshold ? snapThreshold : this.params.grid ? this.params.grid[0] / 2 :  DEFAULT_GRID_X / 2

in order to respect the snapThreshold when it is set? Right now there is no way of having a grid of 20px and a snapTheshold of 5px, because it will always take half of the grid size.

support multiple posses per element

currently we support only one. need to support an arbitrary number. each element must be able to assume one of two roles in a posse: either a leader, which, when dragged, causes all the other elements in the posse to drag, or a follower, which drags independently but which is dragged when any leader in the posse is dragged.

Support ranking of droppables

came about as a result of issue #568 in jsPlumb - a connection intended for a Node inside a Group can in some cases end up on the Group, depending on the order in which the two objects are made droppable. Supporting the concept of ranking droppables will allow jsPlumb to always check Nodes before Groups, regardless of the order in which the objects are made droppable.

Droppable doesn't have the right position, when a droppable is inside a draggable

In our application, we have droppables inside draggables :

You can see a demo of the example here :

https://github.com/edi9999/katavorio
selection_022

Active state:
katavario_active

Hover state :

katavario_hover

it seems that the hover state is not triggered correctly.

Is is somehow possible to have droppables inside draggables without any issues ?

The offset is calculated with :

this.getPosition = function (el) {
            return [ el.offsetLeft, el.offsetTop ];
};

which seems to be [0,0] in our case, but the position of the element in the html is not 0,0 (that is the position to the parent element). I guess the getPosition is not correct, am I right ?

Performance Issue with _setDroppablesActive in Katavorio.js

I am using jsPlumb to create 200 to 300 nodes on the canvas. After the initial rendering of nodes and connections, If I try to draw a connection from source to target I see there is a lag in seeing the actual connector move with my mouse pointer.
After doing a bit of digging I found out the lag is happening because of the following : as soon as I select the sourceEndpoint and move my mouse, in katavorio.js "this.moveListener" is called, which calls the this.mark function which in turn calls the _setDroppablesActive which is basically a foreach over all the node elements in my canvas, since I have not defined any scopes.

e.setActive(val) adds a class "jtk-drag-active" to all the node elements in the canvas which is super slow(causes noticeable lag) for anything above 150 + nodes.

Way to disable firing drop event on all intersecting droppables

Hi!

I'm trying to upgrade from jsPlumb 1.5.x to jsPlumb 1.6.4, and I'm getting trouble with multiple connections created per one drag-and-drop operation.

Looks like Katavorio tracks all intersecting droppable endpoints and fires the drop event on all of them, leading to multiple connections created per drop (my endpoints are close to each other). This may make sense in some use cases, but not in mine.

Is there a way to only fire the drop event on the endpoint actually dropped on (the one under the mouse cursor)?

prevent dragStop automate fire click event

as non-delegate-drag.html example:

I have add onClick event:

d.id = "draggable_" + count++;
d.style.left = x + "px";
d.style.top = y + "px";
d.className = 'w';
+ d.addEventListener('click', () => {
+    console.log('clickkkkkk')
+ })
i.className = "inner";
d.appendChild(i);

when I dragStop the node element,click event fired。

So,how can I separate the dragStop event and click event?

Disable hover class activation on more than one target

Currently the code will fire a hover event on more than one target element, but in the event that the user drops, only one element will receive the drop event. So it would seem to make sense to also ensure that only one element's hover class is activated.

The larger question of whether or not multiple drops should be possible (probably) and if so, how would this work through the API, should be handled elsewhere.

establish connection between two HTML elements (DIV tag) using Drag and drop connection feature of jsPlumb

Hello Team.
I am trying to establish connection between two HTML elements (DIV tag) using Drag and drop connection feature of jsPlumb. I am able to establish connection using Programmatic Connection but Not by using Drag & Drop connection feature.
Here is the sample code which i am using it.
function onLoadDesignMode()
{
jsPlumb.bind('ready', function () {
jsPlumb.Defaults.Container = $("#Page");
var exampleGreyEndpointOptions = {
endpoint:"Dot",
paintStyle:{ width:25, height:21, fillStyle:'#00ff00' },
isSource:true,
connectorStyle : { strokeStyle:"#ff00ff" },
isTarget:true
};
jsPlumb.addEndpoint('rect001', {anchor:"BottomCenter" }, exampleGreyEndpointOptions);
jsPlumb.addEndpoint('rect002', {anchor:"TopCenter" }, exampleGreyEndpointOptions);
});
}
By using above code, I am only able to establish End Points but not able to establish connection using Drag & Drop connection feature.
Note: I am using following version of jsPlumb: jquery.jsPlumb-1.5.5.js
I would really appriciate your helping hand.
Thnaks and Regards,
Milind

before drag active selector

would be nice to support checking each potential droppable when drag starts to see if it should be added to the list of active droppables (which is currently computed purely by matching scope with the draggable)

unbind all drag handlers on `reset`

there's a reset method. all it does right now it empty out a bunch of array, not actually removing drag handlers from managed elements. It should - but optionally take a flag to not bother doing all of that, since it could be slow, and people may like to just throw the DOM elements away instead o unbinding everything from them.

abort dragging if left pos is less than zero

I am using jsplumb which is using this plugin for dragging.
I want to abort dragging if let and top are less than zero.
I am doing this but I want to release mouse/abort drag too in if condition so one has to start drag process with mouse again.
how can i do this ? //params.drag.abortDragging();

       jsPlumbInstance.draggable($window, {
          handle: '.drag-handle',
          stop: function () {

          },
          drag: function (params) {
            var _left = params.pos[0];
            var _top = params.pos[1];          
            var _el = $(params.el);
            if (_left < 0) {
              _el.css('left', 0);
               //params.drag.abortDragging(); ??? how ??
            }
            if (_top < 0) {
              _el.css('top', 0);
               //params.drag.abortDragging(); ??? how ??
            }
          }
        });

Behaviour of "stop" Lifecycle Event changed

Hi,
did just spend a lot of time wondering why my code does not work anymore till I realized that the reason was that npm updated jsplumb from 2.7.9 -> 2.8.8 which should normally not break anything. But with that upgrade is now also uses katavorio 1.2.0 instead of 0.9.1 which probably broke stuff after all.
Because before when multiple nodes were in a "DragSelection" it emitted not just multiple "start" and "drag" events (which is still does") it also did emit multiple "stop" ones. That, however, is not the case anymore.

Here the jsfiddles:

[email protected] & [email protected]:
https://jsfiddle.net/u139hytL/3/
Does get correctly emitted 3x

[email protected] & [email protected]:
https://jsfiddle.net/u139hytL/2/
Does just get emitted 1x

Anybody any idea? Thanks!

add support for groups

Need to be able to specify "groups" of nodes - when one is dragged, they all are - a sort of declarative short cut to the concept of multiple node dragging.

Rules

  • any element may belong to only one group at a time. assigning an element to a group will remove it from its current group, if there is one
  • when any element in a group is dragged, all of the elements in the group are dragged with it.
  • groups are created automatically if they do not exist when the first element is added
  • groups can be cleared and/or deleted

We are not talking about nested containers in this issue. That will be covered in a separate issue.

(in all these examples, element means a DOM element or an element ID. groupId means a string.)

  • addToGroup(element, groupId) - creating the named group if it does not yet exist
  • removeFromGroup(element, groupId)
  • clearGroup(groupId)
  • deleteGroup(groupId)
  • listGroup(groupId)
  • combineGroups(group1Id, group2Id) - group2Id will be deleted afterwards and all elements will belong to group1Id

change options

Hallo
is there no way to change options after on runtime ?
I want to change the grid size.

support optional 'container'

the container being the parent element of the draggables.

  • if an element is dragged outside of the container a dragExit event should be fired, and a class should be added to the container (and to the 'outside' element)
  • if an element is dragged outside of the container and dropped, one of three things should happen:
    • if the element is dropped on some other katavorio container, control for the element should be passed to the katavorio instance controlling the given container. this means re-registering all Drags and Drops for the dragged element with the other Katavorio instance.
    • if 'revert' flag (or similar name) is true, the element should revert to its original location before the drag
    • if 'revert' is false and the element is not dropped on some other katavorio container, it should be left where it is.

Some other, slightly more hazy, requirements right now...the above setup works only if the user has set overflow:visible to the container. It is not likely that this will always be the case. In the event that overflow is not set to visible, one of two things could happen:

  • we could clone the current node, append it to the body, and move on. in this case if the element was not dropped on some other katavorio we would have to act as if revert was set to true.
  • we could ask the user for a proxy node to use while dragging outside of the container. The same rule about reverting position would apply.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.