uiik 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/draggable.d.ts CHANGED
@@ -2,7 +2,7 @@ import { DraggableOptions, Uii } from "./types";
2
2
  export declare class Draggable extends Uii {
3
3
  #private;
4
4
  constructor(els: string | HTMLElement | Array<string | HTMLElement> | NodeListOf<Element>, opts?: DraggableOptions);
5
- bindEvent(bindTarget: Element, opts: DraggableOptions, handleMap: WeakMap<Element, Element>): void;
5
+ bindEvent(bindTarget: Element): void;
6
6
  onOptionChanged(opts: Record<string, any>): void;
7
7
  }
8
8
  export declare function newDraggable(els: string | HTMLElement | Array<string | HTMLElement> | NodeListOf<Element>, opts?: DraggableOptions): Draggable;
package/index.esm.js CHANGED
@@ -1,16 +1,16 @@
1
1
  /**
2
- * uiik v1.4.0
2
+ * uiik v1.4.2
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
- * c) 2021-2025 @holyhigh2 may be freely distributed under the MIT license
5
+ * c) 2021-2026 @holyhigh2 may be freely distributed under the MIT license
6
6
  */
7
7
  import { find, map, toArray, each, reject, includes, some, flatMap, size } from 'myfx/collection';
8
8
  import { isDefined, isNumber, isNaN, isString, isArrayLike, isElement, isEmpty, isBlank, isArray, isFunction, isBoolean, isUndefined } from 'myfx/is';
9
- import { get, assign, merge } from 'myfx/object';
10
- import { isElement as isElement$1, filter, last } from 'myfx';
9
+ import { get, assign, set, merge } from 'myfx/object';
10
+ import { closest } from 'myfx/tree';
11
+ import { isElement as isElement$1, filter, isCustomElement, last } from 'myfx';
11
12
  import { compact, findIndex } from 'myfx/array';
12
13
  import { split, test } from 'myfx/string';
13
- import { closest } from 'myfx/tree';
14
14
  import { alphaId } from 'myfx/utils';
15
15
 
16
16
  /******************************************************************************
@@ -497,12 +497,17 @@ function isVisible(el) {
497
497
  }
498
498
 
499
499
  var _Uii_listeners;
500
+ const UII_KEY = '__uii_target_';
501
+ const UII_MAP = {};
502
+ let UiiSn = 0;
500
503
  class Uii {
501
504
  constructor(ele, opts) {
505
+ var _a;
502
506
  this.enabled = true;
503
507
  _Uii_listeners.set(this, []);
504
508
  this.opts = opts || {};
505
509
  this.opts.mouseButton = this.opts.mouseButton || 'left';
510
+ this.opts.eventCapture = (_a = this.opts.eventCapture) !== null && _a !== void 0 ? _a : true;
506
511
  if (isArrayLike(ele) && !isString(ele)) {
507
512
  this.ele = map(ele, (el) => {
508
513
  let e = isString(el) ? document.querySelector(el) : el;
@@ -526,6 +531,9 @@ class Uii {
526
531
  ? toArray(el)
527
532
  : [el];
528
533
  }
534
+ let uid = UiiSn++ + '';
535
+ UII_MAP[uid] = this;
536
+ this._bindUiik(uid);
529
537
  }
530
538
  destroy() {
531
539
  each(__classPrivateFieldGet(this, _Uii_listeners, "f"), (ev) => {
@@ -533,12 +541,13 @@ class Uii {
533
541
  });
534
542
  __classPrivateFieldSet(this, _Uii_listeners, [], "f");
535
543
  }
536
- addPointerDown(el, pointerDown, opts) {
544
+ addPointerDown(el, pointerDown) {
537
545
  const onPointerDown = pointerDown;
538
- const threshold = opts.threshold || 0;
539
- const toLockPage = opts.lockPage || false;
540
546
  const uiiOptions = this.opts;
547
+ let threshold = 0;
548
+ let toLockPage = true;
541
549
  this.registerEvent(el, "mousedown", (e) => {
550
+ var _a;
542
551
  if (uiiOptions.mouseButton) {
543
552
  switch (uiiOptions.mouseButton) {
544
553
  case "left":
@@ -590,6 +599,12 @@ class Uii {
590
599
  e.preventDefault();
591
600
  return false;
592
601
  }
602
+ let target = closest(t, (node) => node && get(node, UII_KEY), "parentElement");
603
+ if (target) {
604
+ let uiiInstance = UII_MAP[get(target, UII_KEY)];
605
+ threshold = uiiInstance.opts.threshold || 0;
606
+ toLockPage = (_a = uiiInstance.opts.lockPage) !== null && _a !== void 0 ? _a : true;
607
+ }
593
608
  let matrixInfo = getMatrixInfo(el, true);
594
609
  const pointerMove = (ev) => {
595
610
  const offX = (ev.clientX - originPosX) / matrixInfo.scale;
@@ -640,7 +655,7 @@ class Uii {
640
655
  window.addEventListener("blur", pointerEnd);
641
656
  e.preventDefault();
642
657
  return false;
643
- }, true);
658
+ }, this.opts.eventCapture);
644
659
  }
645
660
  registerEvent(el, event, hook, useCapture = false) {
646
661
  const wrapper = ((ev) => {
@@ -671,6 +686,11 @@ class Uii {
671
686
  this.opts[name] = value;
672
687
  this.onOptionChanged(this.opts);
673
688
  }
689
+ _bindUiik(uid) {
690
+ each(this.ele, el => {
691
+ set(el, UII_KEY, uid);
692
+ });
693
+ }
674
694
  onOptionChanged(opts) { }
675
695
  }
676
696
  _Uii_listeners = new WeakMap();
@@ -737,7 +757,8 @@ class Splittable extends Uii {
737
757
  }
738
758
  else {
739
759
  each(handleDoms, (h, i) => {
740
- const isRoot = h.parentNode.classList.contains(CLASS_SPLITTABLE);
760
+ var _a;
761
+ const isRoot = (_a = h.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains(CLASS_SPLITTABLE);
741
762
  let dom1, dom2;
742
763
  if (isRoot) {
743
764
  dom1 = h.previousElementSibling;
@@ -773,7 +794,7 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
773
794
  const child = container.children[0];
774
795
  let lastY = child.offsetTop;
775
796
  let lastH = child.offsetHeight;
776
- each(container.children, c => {
797
+ each(container.children, (c) => {
777
798
  if (c.offsetTop > lastH + lastY) {
778
799
  dir = 'v';
779
800
  return false;
@@ -966,9 +987,6 @@ _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Sp
966
987
  }
967
988
  onEnd && onEnd({ size1: originSize, size2: originSize1 }, ev);
968
989
  });
969
- }, {
970
- threshold: THRESHOLD,
971
- lockPage: true
972
990
  });
973
991
  };
974
992
  function newSplittable(container, opts) {
@@ -1505,9 +1523,6 @@ class Resizable extends Uii {
1505
1523
  }
1506
1524
  }
1507
1525
  });
1508
- }, {
1509
- threshold: THRESHOLD,
1510
- lockPage: true,
1511
1526
  });
1512
1527
  }
1513
1528
  initHandle(panel) {
@@ -1576,12 +1591,16 @@ function newResizable(els, opts) {
1576
1591
  return new Resizable(els, opts);
1577
1592
  }
1578
1593
 
1579
- var _Draggable_instances, _Draggable_handleMap, _Draggable_container, _Draggable_initStyle;
1594
+ var _Draggable_instances, _Draggable_container, _Draggable_initHandle, _Draggable_initStyle;
1580
1595
  const DRAGGER_GROUPS = {};
1581
1596
  const CLASS_DRAGGABLE = "uii-draggable";
1582
1597
  const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
1583
1598
  const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
1584
1599
  const CLASS_DRAGGABLE_GHOST = "uii-draggable-ghost";
1600
+ const HANDLE_MAP = new WeakMap();
1601
+ const OPTION_MAP = new WeakMap();
1602
+ const BINDED_CONTAINER = new WeakSet();
1603
+ const WATCH_MAP = {};
1585
1604
  class Draggable extends Uii {
1586
1605
  constructor(els, opts) {
1587
1606
  super(els, assign({
@@ -1598,17 +1617,9 @@ class Draggable extends Uii {
1598
1617
  self: false,
1599
1618
  }, opts));
1600
1619
  _Draggable_instances.add(this);
1601
- _Draggable_handleMap.set(this, new WeakMap());
1602
1620
  _Draggable_container.set(this, null);
1603
1621
  if (this.opts.handle) {
1604
- each(this.ele, (el) => {
1605
- const h = el.querySelector(this.opts.handle);
1606
- if (!h) {
1607
- console.error('No handle found "' + this.opts.handle + '"');
1608
- return false;
1609
- }
1610
- __classPrivateFieldGet(this, _Draggable_handleMap, "f").set(el, h);
1611
- });
1622
+ __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initHandle).call(this, this.ele);
1612
1623
  }
1613
1624
  this.onOptionChanged(this.opts);
1614
1625
  if (this.opts.group) {
@@ -1637,15 +1648,20 @@ class Draggable extends Uii {
1637
1648
  else {
1638
1649
  con = isEmpty(this.ele) ? null : this.ele[0].parentElement;
1639
1650
  }
1640
- this.bindEvent(con || document.body, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1651
+ let bindTarget = con || document.body;
1652
+ if (BINDED_CONTAINER.has(bindTarget))
1653
+ return;
1654
+ WATCH_MAP[this.eleString] = this;
1655
+ this.bindEvent(bindTarget);
1656
+ BINDED_CONTAINER.add(bindTarget);
1641
1657
  }
1642
1658
  else {
1643
1659
  each(this.ele, (el) => {
1644
- this.bindEvent(el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1660
+ this.bindEvent(el);
1645
1661
  });
1646
1662
  }
1647
1663
  }
1648
- bindEvent(bindTarget, opts, handleMap) {
1664
+ bindEvent(bindTarget) {
1649
1665
  const container = __classPrivateFieldGet(this, _Draggable_container, "f");
1650
1666
  let draggableList = this.ele;
1651
1667
  const eleString = this.eleString;
@@ -1655,23 +1671,37 @@ class Draggable extends Uii {
1655
1671
  let t = ev.target;
1656
1672
  if (!t)
1657
1673
  return true;
1658
- if (opts.watch && eleString) {
1659
- draggableList = bindTarget.querySelectorAll(eleString);
1660
- initStyle(draggableList);
1674
+ let opts = {};
1675
+ let findRs = closest(t, (node) => node && get(node, UII_KEY), "parentElement");
1676
+ if (!findRs || isEmpty(OPTION_MAP.get(findRs))) {
1677
+ let toBreak = true;
1678
+ each(WATCH_MAP, (v, k) => {
1679
+ draggableList = bindTarget.querySelectorAll(eleString);
1680
+ if (!isEmpty(draggableList) && (findRs = closest(t, (node) => includes(draggableList, node), "parentNode"))) {
1681
+ initStyle(draggableList);
1682
+ opts = v.opts;
1683
+ __classPrivateFieldGet(v, _Draggable_instances, "m", _Draggable_initHandle).call(v, draggableList);
1684
+ toBreak = false;
1685
+ return false;
1686
+ }
1687
+ });
1688
+ if (toBreak)
1689
+ return true;
1661
1690
  }
1662
- let findRs = closest(t, (node) => includes(draggableList, node), "parentNode");
1663
- if (!findRs)
1664
- return true;
1665
1691
  const dragDom = findRs;
1666
- let handle = handleMap.get(dragDom);
1667
- if (handle && !handle.contains(t)) {
1692
+ let handle = HANDLE_MAP.get(dragDom);
1693
+ if (handle && !isCustomElement(t) && !handle.contains(t)) {
1668
1694
  return true;
1669
1695
  }
1696
+ if (isEmpty(opts))
1697
+ opts = OPTION_MAP.get(dragDom);
1698
+ if (!opts || isEmpty(opts))
1699
+ return true;
1670
1700
  if (opts.self && dragDom !== t)
1671
1701
  return true;
1672
1702
  const onPointerDown = opts.onPointerDown;
1673
1703
  if (onPointerDown &&
1674
- onPointerDown({ draggable: dragDom }, ev) === false)
1704
+ onPointerDown({ draggable: dragDom, handle }, ev) === false)
1675
1705
  return true;
1676
1706
  const filter = opts.filter;
1677
1707
  if (filter) {
@@ -2012,7 +2042,7 @@ class Draggable extends Uii {
2012
2042
  let moveToGhost = true;
2013
2043
  if (onEnd) {
2014
2044
  moveToGhost =
2015
- onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) ===
2045
+ onEnd({ draggable: dragDom, x: endX, y: endY, transform, ghost: ghostNode }, ev) ===
2016
2046
  false
2017
2047
  ? false
2018
2048
  : true;
@@ -2029,13 +2059,19 @@ class Draggable extends Uii {
2029
2059
  if (ghost) {
2030
2060
  (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
2031
2061
  if (moveToGhost !== false) {
2032
- wrapper(dragDom, opts.useTransform).moveTo(transform.x, transform.y);
2062
+ let transf = wrapper(dragDom, opts.useTransform);
2063
+ if (direction === "v") {
2064
+ transf.moveToY(endY);
2065
+ }
2066
+ else if (direction === "h") {
2067
+ transf.moveToX(endX);
2068
+ }
2069
+ else {
2070
+ transf.moveTo(endX, endY);
2071
+ }
2033
2072
  }
2034
2073
  }
2035
2074
  });
2036
- }, {
2037
- threshold: this.opts.threshold || 0,
2038
- lockPage: true,
2039
2075
  });
2040
2076
  }
2041
2077
  onOptionChanged(opts) {
@@ -2056,12 +2092,31 @@ class Draggable extends Uii {
2056
2092
  }
2057
2093
  }
2058
2094
  }
2059
- _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Draggable_instances = new WeakSet(), _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
2095
+ _Draggable_container = new WeakMap(), _Draggable_instances = new WeakSet(), _Draggable_initHandle = function _Draggable_initHandle(ele) {
2096
+ each(ele, (el) => {
2097
+ if (HANDLE_MAP.has(el))
2098
+ return;
2099
+ let h;
2100
+ if (isString(this.opts.handle)) {
2101
+ h = el.querySelector(this.opts.handle);
2102
+ if (!h) {
2103
+ console.error('No handle found "' + this.opts.handle + '"');
2104
+ return false;
2105
+ }
2106
+ }
2107
+ else if (isElement(this.opts.handle)) {
2108
+ h = this.opts.handle;
2109
+ }
2110
+ HANDLE_MAP.set(el, h);
2111
+ });
2112
+ }, _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
2060
2113
  each(draggableList, (el) => {
2114
+ if (OPTION_MAP.has(el))
2115
+ return;
2061
2116
  if (isDefined(this.opts.type))
2062
2117
  el.dataset.dropType = this.opts.type;
2063
2118
  el.classList.toggle(CLASS_DRAGGABLE, true);
2064
- const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
2119
+ const ee = HANDLE_MAP.get(el) || el;
2065
2120
  ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
2066
2121
  if (!isUndefined(this.opts.cursor)) {
2067
2122
  el.style.cursor = this.opts.cursor.default || "move";
@@ -2070,6 +2125,7 @@ _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Dra
2070
2125
  el.dataset.cursorActive = this.opts.cursor.active || "move";
2071
2126
  }
2072
2127
  }
2128
+ OPTION_MAP.set(el, this.opts);
2073
2129
  });
2074
2130
  };
2075
2131
  function newDraggable(els, opts) {
@@ -2298,9 +2354,6 @@ function bindHandle(uiik, handle, el, opts) {
2298
2354
  el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
2299
2355
  onEnd && onEnd({ deg }, ev);
2300
2356
  });
2301
- }, {
2302
- threshold: THRESHOLD,
2303
- lockPage: true,
2304
2357
  });
2305
2358
  }
2306
2359
  function newRotatable(els, opts) {
@@ -2601,9 +2654,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
2601
2654
  if (onEnd)
2602
2655
  onEnd({ selection, selectable: con }, ev);
2603
2656
  });
2604
- }, {
2605
- threshold: THRESHOLD,
2606
- lockPage: true
2607
2657
  });
2608
2658
  };
2609
2659
  function newSelectable(container, opts) {
@@ -3000,7 +3050,7 @@ function newSortable(container, opts) {
3000
3050
  return new Sortable(container, opts);
3001
3051
  }
3002
3052
 
3003
- var version = "1.4.0";
3053
+ var version = "1.4.2";
3004
3054
  var repository = {
3005
3055
  type: "git",
3006
3056
  url: "https://github.com/holyhigh2/uiik"
@@ -3033,4 +3083,4 @@ var index = {
3033
3083
  newSortable
3034
3084
  };
3035
3085
 
3036
- export { CollisionDetector, DRAGGING_RULE, Draggable, Droppable, EDGE_THRESHOLD, ONE_ANG, ONE_RAD, Resizable, Rotatable, Selectable, Sortable, Splittable, THRESHOLD, Uii, UiiTransform, VERSION, calcVertex, index as default, getBox, getCenterXy, getCenterXySVG, getMatrixInfo, getPointInContainer, getPointOffset, getRectCenter, getRectInContainer, getStyleSize, getStyleXy, getTranslate, getVertex, isSVGEl, isVisible, lockPage, moveBy, moveTo, newCollisionDetector, newDraggable, newDroppable, newResizable, newRotatable, newSelectable, newSortable, newSplittable, normalizeVector, parseOxy, restoreCursor, rotateTo, saveCursor, setCursor, transformMoveTo, unlockPage, wrapper };
3086
+ export { CollisionDetector, DRAGGING_RULE, Draggable, Droppable, EDGE_THRESHOLD, ONE_ANG, ONE_RAD, Resizable, Rotatable, Selectable, Sortable, Splittable, THRESHOLD, UII_KEY, Uii, UiiTransform, VERSION, calcVertex, index as default, getBox, getCenterXy, getCenterXySVG, getMatrixInfo, getPointInContainer, getPointOffset, getRectCenter, getRectInContainer, getStyleSize, getStyleXy, getTranslate, getVertex, isSVGEl, isVisible, lockPage, moveBy, moveTo, newCollisionDetector, newDraggable, newDroppable, newResizable, newRotatable, newSelectable, newSortable, newSplittable, normalizeVector, parseOxy, restoreCursor, rotateTo, saveCursor, setCursor, transformMoveTo, unlockPage, wrapper };
package/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * uiik v1.4.0
2
+ * uiik v1.4.2
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
- * c) 2021-2025 @holyhigh2 may be freely distributed under the MIT license
5
+ * c) 2021-2026 @holyhigh2 may be freely distributed under the MIT license
6
6
  */
7
7
  (function (global, factory) {
8
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/collection'), require('myfx/is'), require('myfx/object'), require('myfx'), require('myfx/array'), require('myfx/string'), require('myfx/tree'), require('myfx/utils')) :
9
- typeof define === 'function' && define.amd ? define(['exports', 'myfx/collection', 'myfx/is', 'myfx/object', 'myfx', 'myfx/array', 'myfx/string', 'myfx/tree', 'myfx/utils'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.collection, global.is, global.object, global.myfx, global.array, global.string, global.tree, global.utils));
11
- })(this, (function (exports, collection, is, object, myfx, array, string, tree, utils) { 'use strict';
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/collection'), require('myfx/is'), require('myfx/object'), require('myfx/tree'), require('myfx'), require('myfx/array'), require('myfx/string'), require('myfx/utils')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', 'myfx/collection', 'myfx/is', 'myfx/object', 'myfx/tree', 'myfx', 'myfx/array', 'myfx/string', 'myfx/utils'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.collection, global.is, global.object, global.tree, global.myfx, global.array, global.string, global.utils));
11
+ })(this, (function (exports, collection, is, object, tree, myfx, array, string, utils) { 'use strict';
12
12
 
13
13
  /******************************************************************************
14
14
  Copyright (c) Microsoft Corporation.
@@ -494,12 +494,17 @@
494
494
  }
495
495
 
496
496
  var _Uii_listeners;
497
+ const UII_KEY = '__uii_target_';
498
+ const UII_MAP = {};
499
+ let UiiSn = 0;
497
500
  class Uii {
498
501
  constructor(ele, opts) {
502
+ var _a;
499
503
  this.enabled = true;
500
504
  _Uii_listeners.set(this, []);
501
505
  this.opts = opts || {};
502
506
  this.opts.mouseButton = this.opts.mouseButton || 'left';
507
+ this.opts.eventCapture = (_a = this.opts.eventCapture) !== null && _a !== void 0 ? _a : true;
503
508
  if (is.isArrayLike(ele) && !is.isString(ele)) {
504
509
  this.ele = collection.map(ele, (el) => {
505
510
  let e = is.isString(el) ? document.querySelector(el) : el;
@@ -523,6 +528,9 @@
523
528
  ? collection.toArray(el)
524
529
  : [el];
525
530
  }
531
+ let uid = UiiSn++ + '';
532
+ UII_MAP[uid] = this;
533
+ this._bindUiik(uid);
526
534
  }
527
535
  destroy() {
528
536
  collection.each(__classPrivateFieldGet(this, _Uii_listeners, "f"), (ev) => {
@@ -530,12 +538,13 @@
530
538
  });
531
539
  __classPrivateFieldSet(this, _Uii_listeners, [], "f");
532
540
  }
533
- addPointerDown(el, pointerDown, opts) {
541
+ addPointerDown(el, pointerDown) {
534
542
  const onPointerDown = pointerDown;
535
- const threshold = opts.threshold || 0;
536
- const toLockPage = opts.lockPage || false;
537
543
  const uiiOptions = this.opts;
544
+ let threshold = 0;
545
+ let toLockPage = true;
538
546
  this.registerEvent(el, "mousedown", (e) => {
547
+ var _a;
539
548
  if (uiiOptions.mouseButton) {
540
549
  switch (uiiOptions.mouseButton) {
541
550
  case "left":
@@ -587,6 +596,12 @@
587
596
  e.preventDefault();
588
597
  return false;
589
598
  }
599
+ let target = tree.closest(t, (node) => node && object.get(node, UII_KEY), "parentElement");
600
+ if (target) {
601
+ let uiiInstance = UII_MAP[object.get(target, UII_KEY)];
602
+ threshold = uiiInstance.opts.threshold || 0;
603
+ toLockPage = (_a = uiiInstance.opts.lockPage) !== null && _a !== void 0 ? _a : true;
604
+ }
590
605
  let matrixInfo = getMatrixInfo(el, true);
591
606
  const pointerMove = (ev) => {
592
607
  const offX = (ev.clientX - originPosX) / matrixInfo.scale;
@@ -637,7 +652,7 @@
637
652
  window.addEventListener("blur", pointerEnd);
638
653
  e.preventDefault();
639
654
  return false;
640
- }, true);
655
+ }, this.opts.eventCapture);
641
656
  }
642
657
  registerEvent(el, event, hook, useCapture = false) {
643
658
  const wrapper = ((ev) => {
@@ -668,6 +683,11 @@
668
683
  this.opts[name] = value;
669
684
  this.onOptionChanged(this.opts);
670
685
  }
686
+ _bindUiik(uid) {
687
+ collection.each(this.ele, el => {
688
+ object.set(el, UII_KEY, uid);
689
+ });
690
+ }
671
691
  onOptionChanged(opts) { }
672
692
  }
673
693
  _Uii_listeners = new WeakMap();
@@ -734,7 +754,8 @@
734
754
  }
735
755
  else {
736
756
  collection.each(handleDoms, (h, i) => {
737
- const isRoot = h.parentNode.classList.contains(CLASS_SPLITTABLE);
757
+ var _a;
758
+ const isRoot = (_a = h.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains(CLASS_SPLITTABLE);
738
759
  let dom1, dom2;
739
760
  if (isRoot) {
740
761
  dom1 = h.previousElementSibling;
@@ -770,7 +791,7 @@
770
791
  const child = container.children[0];
771
792
  let lastY = child.offsetTop;
772
793
  let lastH = child.offsetHeight;
773
- collection.each(container.children, c => {
794
+ collection.each(container.children, (c) => {
774
795
  if (c.offsetTop > lastH + lastY) {
775
796
  dir = 'v';
776
797
  return false;
@@ -963,9 +984,6 @@
963
984
  }
964
985
  onEnd && onEnd({ size1: originSize, size2: originSize1 }, ev);
965
986
  });
966
- }, {
967
- threshold: THRESHOLD,
968
- lockPage: true
969
987
  });
970
988
  };
971
989
  function newSplittable(container, opts) {
@@ -1502,9 +1520,6 @@
1502
1520
  }
1503
1521
  }
1504
1522
  });
1505
- }, {
1506
- threshold: THRESHOLD,
1507
- lockPage: true,
1508
1523
  });
1509
1524
  }
1510
1525
  initHandle(panel) {
@@ -1573,12 +1588,16 @@
1573
1588
  return new Resizable(els, opts);
1574
1589
  }
1575
1590
 
1576
- var _Draggable_instances, _Draggable_handleMap, _Draggable_container, _Draggable_initStyle;
1591
+ var _Draggable_instances, _Draggable_container, _Draggable_initHandle, _Draggable_initStyle;
1577
1592
  const DRAGGER_GROUPS = {};
1578
1593
  const CLASS_DRAGGABLE = "uii-draggable";
1579
1594
  const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
1580
1595
  const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
1581
1596
  const CLASS_DRAGGABLE_GHOST = "uii-draggable-ghost";
1597
+ const HANDLE_MAP = new WeakMap();
1598
+ const OPTION_MAP = new WeakMap();
1599
+ const BINDED_CONTAINER = new WeakSet();
1600
+ const WATCH_MAP = {};
1582
1601
  class Draggable extends Uii {
1583
1602
  constructor(els, opts) {
1584
1603
  super(els, object.assign({
@@ -1595,17 +1614,9 @@
1595
1614
  self: false,
1596
1615
  }, opts));
1597
1616
  _Draggable_instances.add(this);
1598
- _Draggable_handleMap.set(this, new WeakMap());
1599
1617
  _Draggable_container.set(this, null);
1600
1618
  if (this.opts.handle) {
1601
- collection.each(this.ele, (el) => {
1602
- const h = el.querySelector(this.opts.handle);
1603
- if (!h) {
1604
- console.error('No handle found "' + this.opts.handle + '"');
1605
- return false;
1606
- }
1607
- __classPrivateFieldGet(this, _Draggable_handleMap, "f").set(el, h);
1608
- });
1619
+ __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initHandle).call(this, this.ele);
1609
1620
  }
1610
1621
  this.onOptionChanged(this.opts);
1611
1622
  if (this.opts.group) {
@@ -1634,15 +1645,20 @@
1634
1645
  else {
1635
1646
  con = is.isEmpty(this.ele) ? null : this.ele[0].parentElement;
1636
1647
  }
1637
- this.bindEvent(con || document.body, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1648
+ let bindTarget = con || document.body;
1649
+ if (BINDED_CONTAINER.has(bindTarget))
1650
+ return;
1651
+ WATCH_MAP[this.eleString] = this;
1652
+ this.bindEvent(bindTarget);
1653
+ BINDED_CONTAINER.add(bindTarget);
1638
1654
  }
1639
1655
  else {
1640
1656
  collection.each(this.ele, (el) => {
1641
- this.bindEvent(el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1657
+ this.bindEvent(el);
1642
1658
  });
1643
1659
  }
1644
1660
  }
1645
- bindEvent(bindTarget, opts, handleMap) {
1661
+ bindEvent(bindTarget) {
1646
1662
  const container = __classPrivateFieldGet(this, _Draggable_container, "f");
1647
1663
  let draggableList = this.ele;
1648
1664
  const eleString = this.eleString;
@@ -1652,23 +1668,37 @@
1652
1668
  let t = ev.target;
1653
1669
  if (!t)
1654
1670
  return true;
1655
- if (opts.watch && eleString) {
1656
- draggableList = bindTarget.querySelectorAll(eleString);
1657
- initStyle(draggableList);
1671
+ let opts = {};
1672
+ let findRs = tree.closest(t, (node) => node && object.get(node, UII_KEY), "parentElement");
1673
+ if (!findRs || is.isEmpty(OPTION_MAP.get(findRs))) {
1674
+ let toBreak = true;
1675
+ collection.each(WATCH_MAP, (v, k) => {
1676
+ draggableList = bindTarget.querySelectorAll(eleString);
1677
+ if (!is.isEmpty(draggableList) && (findRs = tree.closest(t, (node) => collection.includes(draggableList, node), "parentNode"))) {
1678
+ initStyle(draggableList);
1679
+ opts = v.opts;
1680
+ __classPrivateFieldGet(v, _Draggable_instances, "m", _Draggable_initHandle).call(v, draggableList);
1681
+ toBreak = false;
1682
+ return false;
1683
+ }
1684
+ });
1685
+ if (toBreak)
1686
+ return true;
1658
1687
  }
1659
- let findRs = tree.closest(t, (node) => collection.includes(draggableList, node), "parentNode");
1660
- if (!findRs)
1661
- return true;
1662
1688
  const dragDom = findRs;
1663
- let handle = handleMap.get(dragDom);
1664
- if (handle && !handle.contains(t)) {
1689
+ let handle = HANDLE_MAP.get(dragDom);
1690
+ if (handle && !myfx.isCustomElement(t) && !handle.contains(t)) {
1665
1691
  return true;
1666
1692
  }
1693
+ if (is.isEmpty(opts))
1694
+ opts = OPTION_MAP.get(dragDom);
1695
+ if (!opts || is.isEmpty(opts))
1696
+ return true;
1667
1697
  if (opts.self && dragDom !== t)
1668
1698
  return true;
1669
1699
  const onPointerDown = opts.onPointerDown;
1670
1700
  if (onPointerDown &&
1671
- onPointerDown({ draggable: dragDom }, ev) === false)
1701
+ onPointerDown({ draggable: dragDom, handle }, ev) === false)
1672
1702
  return true;
1673
1703
  const filter = opts.filter;
1674
1704
  if (filter) {
@@ -2009,7 +2039,7 @@
2009
2039
  let moveToGhost = true;
2010
2040
  if (onEnd) {
2011
2041
  moveToGhost =
2012
- onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) ===
2042
+ onEnd({ draggable: dragDom, x: endX, y: endY, transform, ghost: ghostNode }, ev) ===
2013
2043
  false
2014
2044
  ? false
2015
2045
  : true;
@@ -2026,13 +2056,19 @@
2026
2056
  if (ghost) {
2027
2057
  (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
2028
2058
  if (moveToGhost !== false) {
2029
- wrapper(dragDom, opts.useTransform).moveTo(transform.x, transform.y);
2059
+ let transf = wrapper(dragDom, opts.useTransform);
2060
+ if (direction === "v") {
2061
+ transf.moveToY(endY);
2062
+ }
2063
+ else if (direction === "h") {
2064
+ transf.moveToX(endX);
2065
+ }
2066
+ else {
2067
+ transf.moveTo(endX, endY);
2068
+ }
2030
2069
  }
2031
2070
  }
2032
2071
  });
2033
- }, {
2034
- threshold: this.opts.threshold || 0,
2035
- lockPage: true,
2036
2072
  });
2037
2073
  }
2038
2074
  onOptionChanged(opts) {
@@ -2053,12 +2089,31 @@
2053
2089
  }
2054
2090
  }
2055
2091
  }
2056
- _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Draggable_instances = new WeakSet(), _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
2092
+ _Draggable_container = new WeakMap(), _Draggable_instances = new WeakSet(), _Draggable_initHandle = function _Draggable_initHandle(ele) {
2093
+ collection.each(ele, (el) => {
2094
+ if (HANDLE_MAP.has(el))
2095
+ return;
2096
+ let h;
2097
+ if (is.isString(this.opts.handle)) {
2098
+ h = el.querySelector(this.opts.handle);
2099
+ if (!h) {
2100
+ console.error('No handle found "' + this.opts.handle + '"');
2101
+ return false;
2102
+ }
2103
+ }
2104
+ else if (is.isElement(this.opts.handle)) {
2105
+ h = this.opts.handle;
2106
+ }
2107
+ HANDLE_MAP.set(el, h);
2108
+ });
2109
+ }, _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
2057
2110
  collection.each(draggableList, (el) => {
2111
+ if (OPTION_MAP.has(el))
2112
+ return;
2058
2113
  if (is.isDefined(this.opts.type))
2059
2114
  el.dataset.dropType = this.opts.type;
2060
2115
  el.classList.toggle(CLASS_DRAGGABLE, true);
2061
- const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
2116
+ const ee = HANDLE_MAP.get(el) || el;
2062
2117
  ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
2063
2118
  if (!is.isUndefined(this.opts.cursor)) {
2064
2119
  el.style.cursor = this.opts.cursor.default || "move";
@@ -2067,6 +2122,7 @@
2067
2122
  el.dataset.cursorActive = this.opts.cursor.active || "move";
2068
2123
  }
2069
2124
  }
2125
+ OPTION_MAP.set(el, this.opts);
2070
2126
  });
2071
2127
  };
2072
2128
  function newDraggable(els, opts) {
@@ -2295,9 +2351,6 @@
2295
2351
  el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
2296
2352
  onEnd && onEnd({ deg }, ev);
2297
2353
  });
2298
- }, {
2299
- threshold: THRESHOLD,
2300
- lockPage: true,
2301
2354
  });
2302
2355
  }
2303
2356
  function newRotatable(els, opts) {
@@ -2598,9 +2651,6 @@
2598
2651
  if (onEnd)
2599
2652
  onEnd({ selection, selectable: con }, ev);
2600
2653
  });
2601
- }, {
2602
- threshold: THRESHOLD,
2603
- lockPage: true
2604
2654
  });
2605
2655
  };
2606
2656
  function newSelectable(container, opts) {
@@ -2997,7 +3047,7 @@
2997
3047
  return new Sortable(container, opts);
2998
3048
  }
2999
3049
 
3000
- var version = "1.4.0";
3050
+ var version = "1.4.2";
3001
3051
  var repository = {
3002
3052
  type: "git",
3003
3053
  url: "https://github.com/holyhigh2/uiik"
@@ -3043,6 +3093,7 @@
3043
3093
  exports.Sortable = Sortable;
3044
3094
  exports.Splittable = Splittable;
3045
3095
  exports.THRESHOLD = THRESHOLD;
3096
+ exports.UII_KEY = UII_KEY;
3046
3097
  exports.Uii = Uii;
3047
3098
  exports.UiiTransform = UiiTransform;
3048
3099
  exports.VERSION = VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uiik",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
@@ -32,7 +32,7 @@
32
32
  "doc": "npx typedoc"
33
33
  },
34
34
  "dependencies": {
35
- "myfx": ">=1.1.0"
35
+ "myfx": ">=1.14.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@babel/core": "^7.12.3",
package/types.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { UiiTransform } from "./transform";
2
+ export declare const UII_KEY = "__uii_target_";
2
3
  export declare abstract class Uii {
3
4
  #private;
4
5
  protected ele: Array<HTMLElement>;
@@ -7,10 +8,7 @@ export declare abstract class Uii {
7
8
  protected eleString: string;
8
9
  constructor(ele: string | Element | NodeList | HTMLCollection | Array<string | Element>, opts?: Record<string, any>);
9
10
  destroy(): void;
10
- addPointerDown(el: Element, pointerDown: (args: Record<string, any>) => void | boolean, opts: {
11
- threshold?: number;
12
- lockPage?: boolean;
13
- }): void;
11
+ addPointerDown(el: Element, pointerDown: (args: Record<string, any>) => void | boolean): void;
14
12
  registerEvent(el: Element, event: string, hook: Function, useCapture?: boolean): void;
15
13
  disable(): void;
16
14
  enable(): void;
@@ -18,6 +16,7 @@ export declare abstract class Uii {
18
16
  getOption(name: string): any;
19
17
  setOptions(options?: Record<string, any>): void;
20
18
  setOption(name: string, value: any): void;
19
+ protected _bindUiik(uid: string): void;
21
20
  protected onOptionChanged(opts?: Record<string, any>): void;
22
21
  }
23
22
  export type ResizableOptions = {
@@ -29,6 +28,7 @@ export type ResizableOptions = {
29
28
  ghostClass?: string;
30
29
  ox?: number | string;
31
30
  oy?: number | string;
31
+ eventCapture?: boolean;
32
32
  onPointerDown?: (event: MouseEvent) => boolean;
33
33
  onStart?: (data: {
34
34
  w: number;
@@ -71,6 +71,7 @@ export type SplittableOptions = {
71
71
  ghostClass?: string;
72
72
  ghostTo?: string | HTMLElement;
73
73
  handle?: string | HTMLElement | HTMLElement[];
74
+ eventCapture?: boolean;
74
75
  onStart?: (data: {
75
76
  size1: number;
76
77
  size2: number;
@@ -99,7 +100,7 @@ export type DraggableOptions = {
99
100
  containment?: boolean | HTMLElement | string;
100
101
  watch?: boolean | string;
101
102
  threshold?: number;
102
- handle?: string;
103
+ handle?: string | HTMLElement | SVGGraphicsElement;
103
104
  filter?: string;
104
105
  droppable?: (() => NodeList | HTMLCollection | HTMLElement[]) | string | HTMLElement | HTMLElement[];
105
106
  ghost?: ((panel: HTMLElement | SVGGraphicsElement) => HTMLElement | SVGGraphicsElement) | boolean;
@@ -122,8 +123,10 @@ export type DraggableOptions = {
122
123
  };
123
124
  grid?: number | number[];
124
125
  type?: string;
126
+ eventCapture?: boolean;
125
127
  onPointerDown?: (data: {
126
128
  draggable: HTMLElement | SVGGraphicsElement;
129
+ handle: HTMLElement | SVGGraphicsElement;
127
130
  }, event: MouseEvent) => boolean;
128
131
  onStart?: (data: {
129
132
  draggable: HTMLElement | SVGGraphicsElement;
@@ -144,6 +147,7 @@ export type DraggableOptions = {
144
147
  x: number;
145
148
  y: number;
146
149
  transform: UiiTransform;
150
+ ghost: HTMLElement | SVGGraphicsElement;
147
151
  }, event: MouseEvent) => boolean | void;
148
152
  onClone?: (data: {
149
153
  clone: HTMLElement | SVGGraphicsElement;
@@ -162,6 +166,7 @@ export type DroppableOptions = {
162
166
  activeClass?: string;
163
167
  hoverClass?: string;
164
168
  accepts?: ((ele: Array<HTMLElement>, draggable: HTMLElement) => boolean) | string;
169
+ eventCapture?: boolean;
165
170
  onActive?: (data: {
166
171
  draggable: HTMLElement;
167
172
  droppables: Array<HTMLElement>;
@@ -195,6 +200,7 @@ export type RotatableOptions = {
195
200
  ox?: number | string;
196
201
  oy?: number | string;
197
202
  handle?: ((target: HTMLElement | SVGGraphicsElement) => NodeList | HTMLCollection | HTMLElement[] | HTMLElement | SVGGraphicsElement) | string | NodeList | HTMLCollection | HTMLElement[] | HTMLElement | SVGGraphicsElement;
203
+ eventCapture?: boolean;
198
204
  onPointerDown?: (event: MouseEvent) => boolean;
199
205
  onStart?: (data: {
200
206
  deg: number;
@@ -222,6 +228,7 @@ export type SelectableOptions = {
222
228
  scroll?: boolean;
223
229
  scrollSpeed?: number;
224
230
  filter?: ((el: HTMLElement) => boolean) | string;
231
+ eventCapture?: boolean;
225
232
  onPointerDown?: (event: MouseEvent) => boolean;
226
233
  onStart?: (data: {
227
234
  selection: Array<HTMLElement>;
@@ -251,6 +258,7 @@ export type SortableOptions = {
251
258
  };
252
259
  spill?: "remove" | "revert";
253
260
  sort?: boolean;
261
+ eventCapture?: boolean;
254
262
  onActive?: (data: {
255
263
  item: HTMLElement;
256
264
  from: HTMLElement;