You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
10 KiB
12 lines
10 KiB
/*!
|
|
* @antv/g-plugin-dragndrop
|
|
* @description A G plugin for Drag n Drop implemented with PointerEvents
|
|
* @version 2.0.38
|
|
* @date 7/30/2025, 1:35:41 PM
|
|
* @author AntVis
|
|
* @docs https://g.antv.antgroup.com/
|
|
*/
|
|
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],e):e(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.Dragndrop={}),t.window.G)}(this,function(t,e){"use strict";function n(t){return n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},n(t)}function r(t){var e=function(t,e){if("object"!=n(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var o=r.call(t,e||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==n(e)?e:e+""}function o(t,e,n){return(e=r(e))in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function i(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)}return n}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){for(var n=0;e.length>n;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,r(o.key),o)}}function a(t,e,n){return e&&c(t.prototype,e),n&&c(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t){return f=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},f(t)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(p=function(){return!!t})()}function l(t,e){if(e&&("object"==n(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function s(t,e){return s=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},s(t,e)}function d(t,e){this.v=t,this.k=e}function v(t,e,n,r){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}v=function(t,e,n,r){function i(e,n){v(t,e,function(t){return this._invoke(e,n,t)})}e?o?o(t,e,{value:n,enumerable:!r,configurable:!r,writable:!r}):t[e]=n:(i("next",0),i("throw",1),i("return",2))},v(t,e,n,r)}function y(){
|
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
var t,e,n="function"==typeof Symbol?Symbol:{},r=n.iterator||"@@iterator",o=n.toStringTag||"@@toStringTag";function i(n,r,o,i){var a=Object.create((r&&r.prototype instanceof c?r:c).prototype);return v(a,"_invoke",function(n,r,o){var i,c,a,f=0,p=o||[],l=!1,s={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,n){return i=e,c=0,a=t,s.n=n,u}};function d(n,r){for(c=n,a=r,e=0;!l&&f&&!o&&p.length>e;e++){var o,i=p[e],d=s.p,v=i[2];n>3?(o=v===r)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):d>=i[0]&&((o=2>n&&i[1]>d)?(c=0,s.v=r,s.n=i[1]):v>d&&(o=3>n||i[0]>r||r>v)&&(i[4]=n,i[5]=r,s.n=v,c=0))}if(o||n>1)return u;throw l=!0,r}return function(o,p,v){if(f>1)throw TypeError("Generator is already running");for(l&&1===p&&d(p,v),c=p,a=v;(e=2>c?t:a)||!l;){i||(c?3>c?(c>1&&(s.n=-1),d(c,a)):s.n=a:s.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,2>c&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),2>c&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(l=0>s.n)?a:n.call(r,s))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:l}}}(n,o,i),!0),a}var u={};function c(){}function a(){}function f(){}e=Object.getPrototypeOf;var p=[][r]?e(e([][r]())):(v(e={},r,function(){return this}),e),l=f.prototype=c.prototype=Object.create(p);function s(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,v(t,o,"GeneratorFunction")),t.prototype=Object.create(l),t}return a.prototype=f,v(l,"constructor",f),v(f,"constructor",a),a.displayName="GeneratorFunction",v(f,o,"GeneratorFunction"),v(l),v(l,o,"Generator"),v(l,r,function(){return this}),v(l,"toString",function(){return"[object Generator]"}),(y=function(){return{w:i,m:s}})()}function b(t,e){function n(r,o,i,u){try{var c=t[r](o),a=c.value;return a instanceof d?e.resolve(a.v).then(function(t){n("next",t,i,u)},function(t){n("throw",t,i,u)}):e.resolve(a).then(function(t){c.value=t,i(c)},function(t){return n("throw",t,i,u)})}catch(t){u(t)}}var r;this.next||(v(b.prototype),v(b.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),v(this,"_invoke",function(t,o,i){function u(){return new e(function(e,r){n(t,i,e,r)})}return r=r?r.then(u,u):u()},!0)}function g(t,e,n,r,o){return new b(y().w(t,e,n,r),o||Promise)}function h(t,e,n,r,o){var i=g(t,e,n,r,o);return i.next().then(function(t){return t.done?t.value:i.next()})}function m(t){var e=Object(t),n=[];for(var r in e)n.unshift(r);return function t(){for(;n.length;)if((r=n.pop())in e)return t.value=r,t.done=!1,t;return t.done=!0,t}}function O(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}throw new TypeError(n(t)+" is not iterable")}function w(){var t=y(),e=t.m(w),n=(Object.getPrototypeOf?Object.getPrototypeOf(e):e.__proto__).constructor;function r(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===n||"GeneratorFunction"===(e.displayName||e.name))}var o={throw:1,return:2,break:3,continue:3};function i(t){var e,n;return function(r){e||(e={stop:function(){return n(r.a,2)},catch:function(){return r.v},abrupt:function(t,e){return n(r.a,o[t],e)},delegateYield:function(t,o,i){return e.resultName=o,n(r.d,O(t),i)},finish:function(t){return n(r.f,t)}},n=function(t,n,o){r.p=e.prev,r.n=e.next;try{return t(n,o)}finally{e.next=r.n}}),e.resultName&&(e[e.resultName]=r.v,e.resultName=void 0),e.sent=r.v,e.next=r.n;try{return t.call(this,e)}finally{r.p=e.prev,r.n=e.next}}}return(w=function(){return{wrap:function(e,n,r,o){return t.w(i(e),n,r,o&&o.reverse())},isGeneratorFunction:r,mark:t.m,awrap:function(t,e){return new d(t,e)},AsyncIterator:b,async:function(t,e,n,o,u){return(r(e)?g:h)(i(t),e,n,o,u)},keys:m,values:O}})()}function P(t,e,n,r,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void n(t)}c.done?e(a):Promise.resolve(a).then(r,o)}function j(t,e){return Math.sqrt((t[0]-e[0])*(t[0]-e[0])+(t[1]-e[1])*(t[1]-e[1]))}var x=function(){function t(e){u(this,t),this.dragndropPluginOptions=e}return a(t,[{key:"apply",value:function(e){var n=this,r=e.renderingService,o=e.renderingContext.root.ownerDocument,i=o.defaultView,u=function(t){var e=t.target,r=e===o,u=r&&n.dragndropPluginOptions.isDocumentDraggable?o:e.closest&&e.closest("[draggable=true]");if(u){var c=!1,a=t.timeStamp,f=[t.clientX,t.clientY],p=null,l=[t.clientX,t.clientY],s=function(){var t,i=(t=w().mark(function t(i){var s,d,v,y,b,g;return w().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(c){t.next=2;break}if(s=i.timeStamp-a,d=j([i.clientX,i.clientY],f),s>n.dragndropPluginOptions.dragstartTimeThreshold&&d>n.dragndropPluginOptions.dragstartDistanceThreshold){t.next=1;break}return t.abrupt("return");case 1:i.type="dragstart",u.dispatchEvent(i),c=!0;case 2:if(i.type="drag",i.dx=i.clientX-l[0],i.dy=i.clientY-l[1],u.dispatchEvent(i),l=[i.clientX,i.clientY],r){t.next=4;break}return v="pointer"===n.dragndropPluginOptions.overlap?[i.canvasX,i.canvasY]:e.getBounds().center,t.next=3,o.elementsFromPoint(v[0],v[1]);case 3:b=(y=t.sent)[y.indexOf(e)+1],g=(null==b?void 0:b.closest("[droppable=true]"))||(n.dragndropPluginOptions.isDocumentDroppable?o:null),p!==g&&(p&&(i.type="dragleave",i.target=p,p.dispatchEvent(i)),g&&(i.type="dragenter",i.target=g,g.dispatchEvent(i)),(p=g)&&(i.type="dragover",i.target=p,p.dispatchEvent(i)));case 4:case"end":return t.stop()}},t)}),function(){var e=this,n=arguments;return new Promise(function(r,o){var i=t.apply(e,n);function u(t){P(i,r,o,u,c,"next",t)}function c(t){P(i,r,o,u,c,"throw",t)}u(void 0)})});return function(t){return i.apply(this,arguments)}}();i.addEventListener("pointermove",s);var d=function(t){if(c){t.detail={preventClick:!0};var e=t.clone();p&&(e.type="drop",e.target=p,p.dispatchEvent(e)),e.type="dragend",u.dispatchEvent(e),c=!1}i.removeEventListener("pointermove",s)};e.addEventListener("pointerup",d,{once:!0}),e.addEventListener("pointerupoutside",d,{once:!0})}};r.hooks.init.tap(t.tag,function(){i.addEventListener("pointerdown",u)}),r.hooks.destroy.tap(t.tag,function(){i.removeEventListener("pointerdown",u)})}}])}();x.tag="Dragndrop";var E=function(t){function e(){var t,n,r,o,i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return u(this,e),n=this,r=f(r=e),(t=l(n,p()?Reflect.construct(r,o||[],f(n).constructor):r.apply(n,o))).name="dragndrop",t.options=i,t}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&s(t,e)}(e,t),a(e,[{key:"init",value:function(){this.addRenderingPlugin(new x(function(t){for(var e=1;arguments.length>e;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?i(Object(n),!0).forEach(function(e){o(t,e,n[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({overlap:"pointer",isDocumentDraggable:!1,isDocumentDroppable:!1,dragstartDistanceThreshold:0,dragstartTimeThreshold:0},this.options)))}},{key:"destroy",value:function(){this.removeAllRenderingPlugins()}},{key:"setOptions",value:function(t){Object.assign(this.plugins[0].dragndropPluginOptions,t)}}])}(e.AbstractRendererPlugin);t.Plugin=E});
|
|
//# sourceMappingURL=index.umd.min.js.map
|
|
|