uiik 1.3.7 → 1.4.1

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,17 +1,17 @@
1
1
  /**
2
- * uiik v1.3.7
2
+ * uiik v1.4.1
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2025 @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';
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';
10
12
  import { compact, findIndex } from 'myfx/array';
11
13
  import { split, test } from 'myfx/string';
12
- import { closest } from 'myfx/tree';
13
14
  import { alphaId } from 'myfx/utils';
14
- import { filter, last } from 'myfx';
15
15
 
16
16
  /******************************************************************************
17
17
  Copyright (c) Microsoft Corporation.
@@ -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) {
@@ -978,6 +996,7 @@ function newSplittable(container, opts) {
978
996
  const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
979
997
  const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
980
998
  const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
999
+ const CLASS_RESIZABLE_GHOST = "uii-resizable-ghost";
981
1000
  const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
982
1001
  class Resizable extends Uii {
983
1002
  constructor(els, opts) {
@@ -1110,11 +1129,9 @@ class Resizable extends Uii {
1110
1129
  }
1111
1130
  if (ghostNode) {
1112
1131
  if (ghostClass) {
1113
- ghostNode.className =
1114
- ghostNode.className.replace(ghostClass, "") +
1115
- " " +
1116
- ghostClass;
1132
+ ghostNode.classList.add(ghostClass);
1117
1133
  }
1134
+ ghostNode.classList.toggle(CLASS_RESIZABLE_GHOST, true);
1118
1135
  (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
1119
1136
  transform = wrapper(ghostNode);
1120
1137
  onClone && onClone({ clone: ghostNode }, ev);
@@ -1176,7 +1193,7 @@ class Resizable extends Uii {
1176
1193
  }
1177
1194
  startPointXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle, matrixInfo);
1178
1195
  onStart &&
1179
- onStart.call(uiik, { w: originW, h: originH, transform }, ev);
1196
+ onStart.call(uiik, { w: originW, h: originH, transform, handle, ghost: ghostNode }, ev);
1180
1197
  });
1181
1198
  onPointerMove((args) => {
1182
1199
  const { ev, offX, offY } = args;
@@ -1397,39 +1414,13 @@ class Resizable extends Uii {
1397
1414
  break;
1398
1415
  }
1399
1416
  if (aspectRatio) {
1400
- if (changeW) {
1401
- style.width = w + "px";
1402
- style.height = w / aspectRatio + "px";
1403
- }
1404
1417
  if (changeH && dir !== "sw") {
1405
1418
  if (dir === "nw") {
1406
1419
  y = originY - w / aspectRatio + originH;
1407
1420
  }
1408
- else {
1409
- style.width = h * aspectRatio + "px";
1410
- style.height = h + "px";
1411
- }
1412
1421
  }
1413
1422
  }
1414
- else {
1415
- if (changeW) {
1416
- resize(transform, style, w);
1417
- }
1418
- if (changeH) {
1419
- resize(transform, style, undefined, h);
1420
- }
1421
- }
1422
- if (changeY) {
1423
- transform.moveTo(x, y + sY);
1424
- }
1425
- if (changeX) {
1426
- transform.moveTo(x + sX, y);
1427
- }
1428
- lastX = x;
1429
- lastY = y;
1430
- console.log(lastX, lastY);
1431
- currentW = w;
1432
- currentH = h;
1423
+ let canResize = true;
1433
1424
  if (onResize && onResize.call) {
1434
1425
  onResize.call;
1435
1426
  const panelRect = getRectInContainer(panel, panel.parentElement, matrixInfo);
@@ -1437,7 +1428,7 @@ class Resizable extends Uii {
1437
1428
  let centerY = Math.round(panelRect.y + panelRect.h / 2);
1438
1429
  let sx = Math.round(centerX - originW / 2);
1439
1430
  let sy = Math.round(centerY - originH / 2);
1440
- onResize.call(uiik, {
1431
+ canResize = onResize.call(uiik, {
1441
1432
  w,
1442
1433
  h,
1443
1434
  ow: w - originW,
@@ -1449,20 +1440,68 @@ class Resizable extends Uii {
1449
1440
  sy: sy,
1450
1441
  deg: matrixInfo.angle,
1451
1442
  transform,
1443
+ handle
1452
1444
  }, ev);
1453
1445
  }
1446
+ if (canResize !== false) {
1447
+ if (aspectRatio) {
1448
+ if (changeW) {
1449
+ style.width = w + "px";
1450
+ style.height = w / aspectRatio + "px";
1451
+ }
1452
+ if (changeH && dir !== "sw" && dir !== "nw") {
1453
+ style.width = h * aspectRatio + "px";
1454
+ style.height = h + "px";
1455
+ }
1456
+ }
1457
+ else {
1458
+ if (changeW) {
1459
+ resize(transform, style, w);
1460
+ }
1461
+ if (changeH) {
1462
+ resize(transform, style, undefined, h);
1463
+ }
1464
+ }
1465
+ if (changeY) {
1466
+ transform.moveTo(x, y + sY);
1467
+ }
1468
+ if (changeX) {
1469
+ transform.moveTo(x + sX, y);
1470
+ }
1471
+ }
1472
+ lastX = x;
1473
+ lastY = y;
1474
+ currentW = w;
1475
+ currentH = h;
1454
1476
  });
1455
1477
  onPointerEnd((args) => {
1456
1478
  var _a, _b;
1457
1479
  const { ev } = args;
1480
+ let doDefault = true;
1481
+ handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1482
+ let ghostLeft = '0';
1483
+ let ghostTop = '0';
1484
+ let ghostWidth = '0';
1485
+ let ghostHeight = '0';
1458
1486
  if (ghost && ghostNode) {
1459
- panelStyle.left = ghostNode.style.left;
1460
- panelStyle.top = ghostNode.style.top;
1461
- transform = wrapper(panel);
1462
- transform.moveTo((lastX + sX), (lastY + sY));
1487
+ ghostLeft = ghostNode.style.left;
1488
+ ghostTop = ghostNode.style.top;
1489
+ ghostWidth = ghostNode.style.width;
1490
+ ghostHeight = ghostNode.style.height;
1463
1491
  ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) &&
1464
1492
  ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
1465
- resize(transform, panelStyle, parseFloat(ghostNode.style.width), parseFloat(ghostNode.style.height));
1493
+ }
1494
+ if (onEnd) {
1495
+ doDefault = onEnd.call(uiik, { w: currentW, h: currentH, transform, handle, ghost: ghostNode }, ev);
1496
+ }
1497
+ if (doDefault === false)
1498
+ return;
1499
+ if (ghost && ghostNode) {
1500
+ panelStyle.left = ghostLeft;
1501
+ panelStyle.top = ghostTop;
1502
+ transform = wrapper(panel);
1503
+ transform.moveTo((lastX + sX), (lastY + sY));
1504
+ resize(transform, panelStyle, parseFloat(ghostWidth), parseFloat(ghostHeight));
1466
1505
  }
1467
1506
  if (setOrigin)
1468
1507
  panel.style.transformOrigin = originalTransformOrigin;
@@ -1483,13 +1522,7 @@ class Resizable extends Uii {
1483
1522
  }
1484
1523
  }
1485
1524
  }
1486
- handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1487
- onEnd &&
1488
- onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
1489
1525
  });
1490
- }, {
1491
- threshold: THRESHOLD,
1492
- lockPage: true,
1493
1526
  });
1494
1527
  }
1495
1528
  initHandle(panel) {
@@ -1502,6 +1535,15 @@ class Resizable extends Uii {
1502
1535
  else if (isFunction(handleStr)) {
1503
1536
  handles = handleStr(panel);
1504
1537
  }
1538
+ else if (isElement$1(handleStr)) {
1539
+ handles = [handleStr];
1540
+ }
1541
+ else if (isArrayLike(handleStr)) {
1542
+ let eles = filter(handleStr, h => isElement$1(h));
1543
+ if (eles.length > 0) {
1544
+ handles = eles;
1545
+ }
1546
+ }
1505
1547
  if (!handles) {
1506
1548
  console.error('Can not find handles in "' + panel.outerHTML + '"');
1507
1549
  return;
@@ -1549,12 +1591,16 @@ function newResizable(els, opts) {
1549
1591
  return new Resizable(els, opts);
1550
1592
  }
1551
1593
 
1552
- var _Draggable_instances, _Draggable_handleMap, _Draggable_container, _Draggable_initStyle;
1594
+ var _Draggable_instances, _Draggable_container, _Draggable_initHandle, _Draggable_initStyle;
1553
1595
  const DRAGGER_GROUPS = {};
1554
1596
  const CLASS_DRAGGABLE = "uii-draggable";
1555
1597
  const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
1556
1598
  const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
1557
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 = {};
1558
1604
  class Draggable extends Uii {
1559
1605
  constructor(els, opts) {
1560
1606
  super(els, assign({
@@ -1571,17 +1617,9 @@ class Draggable extends Uii {
1571
1617
  self: false,
1572
1618
  }, opts));
1573
1619
  _Draggable_instances.add(this);
1574
- _Draggable_handleMap.set(this, new WeakMap());
1575
1620
  _Draggable_container.set(this, null);
1576
1621
  if (this.opts.handle) {
1577
- each(this.ele, (el) => {
1578
- const h = el.querySelector(this.opts.handle);
1579
- if (!h) {
1580
- console.error('No handle found "' + this.opts.handle + '"');
1581
- return false;
1582
- }
1583
- __classPrivateFieldGet(this, _Draggable_handleMap, "f").set(el, h);
1584
- });
1622
+ __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initHandle).call(this, this.ele);
1585
1623
  }
1586
1624
  this.onOptionChanged(this.opts);
1587
1625
  if (this.opts.group) {
@@ -1610,15 +1648,20 @@ class Draggable extends Uii {
1610
1648
  else {
1611
1649
  con = isEmpty(this.ele) ? null : this.ele[0].parentElement;
1612
1650
  }
1613
- 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);
1614
1657
  }
1615
1658
  else {
1616
1659
  each(this.ele, (el) => {
1617
- this.bindEvent(el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1660
+ this.bindEvent(el);
1618
1661
  });
1619
1662
  }
1620
1663
  }
1621
- bindEvent(bindTarget, opts, handleMap) {
1664
+ bindEvent(bindTarget) {
1622
1665
  const container = __classPrivateFieldGet(this, _Draggable_container, "f");
1623
1666
  let draggableList = this.ele;
1624
1667
  const eleString = this.eleString;
@@ -1628,23 +1671,37 @@ class Draggable extends Uii {
1628
1671
  let t = ev.target;
1629
1672
  if (!t)
1630
1673
  return true;
1631
- if (opts.watch && eleString) {
1632
- draggableList = bindTarget.querySelectorAll(eleString);
1633
- initStyle(draggableList);
1674
+ let opts = {};
1675
+ let findRs = closest(t, (node) => node && get(node, UII_KEY), "parentElement");
1676
+ if (!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;
1634
1690
  }
1635
- let findRs = closest(t, (node) => includes(draggableList, node), "parentNode");
1636
- if (!findRs)
1637
- return true;
1638
1691
  const dragDom = findRs;
1639
- let handle = handleMap.get(dragDom);
1640
- if (handle && !handle.contains(t)) {
1692
+ let handle = HANDLE_MAP.get(dragDom);
1693
+ if (handle && !isCustomElement(t) && !handle.contains(t)) {
1641
1694
  return true;
1642
1695
  }
1696
+ if (isEmpty(opts))
1697
+ opts = OPTION_MAP.get(dragDom);
1698
+ if (!opts || isEmpty(opts))
1699
+ return true;
1643
1700
  if (opts.self && dragDom !== t)
1644
1701
  return true;
1645
1702
  const onPointerDown = opts.onPointerDown;
1646
1703
  if (onPointerDown &&
1647
- onPointerDown({ draggable: dragDom }, ev) === false)
1704
+ onPointerDown({ draggable: dragDom, handle }, ev) === false)
1648
1705
  return true;
1649
1706
  const filter = opts.filter;
1650
1707
  if (filter) {
@@ -1985,7 +2042,7 @@ class Draggable extends Uii {
1985
2042
  let moveToGhost = true;
1986
2043
  if (onEnd) {
1987
2044
  moveToGhost =
1988
- onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) ===
2045
+ onEnd({ draggable: dragDom, x: endX, y: endY, transform, ghost: ghostNode }, ev) ===
1989
2046
  false
1990
2047
  ? false
1991
2048
  : true;
@@ -2002,13 +2059,19 @@ class Draggable extends Uii {
2002
2059
  if (ghost) {
2003
2060
  (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
2004
2061
  if (moveToGhost !== false) {
2005
- 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
+ }
2006
2072
  }
2007
2073
  }
2008
2074
  });
2009
- }, {
2010
- threshold: this.opts.threshold || 0,
2011
- lockPage: true,
2012
2075
  });
2013
2076
  }
2014
2077
  onOptionChanged(opts) {
@@ -2029,12 +2092,27 @@ class Draggable extends Uii {
2029
2092
  }
2030
2093
  }
2031
2094
  }
2032
- _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
+ let h;
2098
+ if (isString(this.opts.handle)) {
2099
+ h = el.querySelector(this.opts.handle);
2100
+ if (!h) {
2101
+ console.error('No handle found "' + this.opts.handle + '"');
2102
+ return false;
2103
+ }
2104
+ }
2105
+ else if (isElement(this.opts.handle)) {
2106
+ h = this.opts.handle;
2107
+ }
2108
+ HANDLE_MAP.set(el, h);
2109
+ });
2110
+ }, _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
2033
2111
  each(draggableList, (el) => {
2034
2112
  if (isDefined(this.opts.type))
2035
2113
  el.dataset.dropType = this.opts.type;
2036
2114
  el.classList.toggle(CLASS_DRAGGABLE, true);
2037
- const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
2115
+ const ee = HANDLE_MAP.get(el) || el;
2038
2116
  ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
2039
2117
  if (!isUndefined(this.opts.cursor)) {
2040
2118
  el.style.cursor = this.opts.cursor.default || "move";
@@ -2043,6 +2121,7 @@ _Draggable_handleMap = new WeakMap(), _Draggable_container = new WeakMap(), _Dra
2043
2121
  el.dataset.cursorActive = this.opts.cursor.active || "move";
2044
2122
  }
2045
2123
  }
2124
+ OPTION_MAP.set(el, this.opts);
2046
2125
  });
2047
2126
  };
2048
2127
  function newDraggable(els, opts) {
@@ -2271,9 +2350,6 @@ function bindHandle(uiik, handle, el, opts) {
2271
2350
  el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
2272
2351
  onEnd && onEnd({ deg }, ev);
2273
2352
  });
2274
- }, {
2275
- threshold: THRESHOLD,
2276
- lockPage: true,
2277
2353
  });
2278
2354
  }
2279
2355
  function newRotatable(els, opts) {
@@ -2574,9 +2650,6 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
2574
2650
  if (onEnd)
2575
2651
  onEnd({ selection, selectable: con }, ev);
2576
2652
  });
2577
- }, {
2578
- threshold: THRESHOLD,
2579
- lockPage: true
2580
2653
  });
2581
2654
  };
2582
2655
  function newSelectable(container, opts) {
@@ -2973,7 +3046,7 @@ function newSortable(container, opts) {
2973
3046
  return new Sortable(container, opts);
2974
3047
  }
2975
3048
 
2976
- var version = "1.3.7";
3049
+ var version = "1.4.1";
2977
3050
  var repository = {
2978
3051
  type: "git",
2979
3052
  url: "https://github.com/holyhigh2/uiik"
@@ -3006,4 +3079,4 @@ var index = {
3006
3079
  newSortable
3007
3080
  };
3008
3081
 
3009
- 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 };
3082
+ 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.3.7
2
+ * uiik v1.4.1
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2025 @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/array'), require('myfx/string'), require('myfx/tree'), require('myfx/utils'), require('myfx')) :
9
- typeof define === 'function' && define.amd ? define(['exports', 'myfx/collection', 'myfx/is', 'myfx/object', 'myfx/array', 'myfx/string', 'myfx/tree', 'myfx/utils', 'myfx'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.collection, global.is, global.object, global.array, global.string, global.tree, global.utils, global.myfx));
11
- })(this, (function (exports, collection, is, object, array, string, tree, utils, myfx) { '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) {
@@ -975,6 +993,7 @@
975
993
  const CLASS_RESIZABLE_HANDLE = "uii-resizable-handle";
976
994
  const CLASS_RESIZABLE_HANDLE_DIR = "uii-resizable-handle-";
977
995
  const CLASS_RESIZABLE_HANDLE_ACTIVE = "uii-resizable-handle-active";
996
+ const CLASS_RESIZABLE_GHOST = "uii-resizable-ghost";
978
997
  const EXP_DIR = new RegExp(CLASS_RESIZABLE_HANDLE_DIR + "(?<dir>[nesw]+)");
979
998
  class Resizable extends Uii {
980
999
  constructor(els, opts) {
@@ -1107,11 +1126,9 @@
1107
1126
  }
1108
1127
  if (ghostNode) {
1109
1128
  if (ghostClass) {
1110
- ghostNode.className =
1111
- ghostNode.className.replace(ghostClass, "") +
1112
- " " +
1113
- ghostClass;
1129
+ ghostNode.classList.add(ghostClass);
1114
1130
  }
1131
+ ghostNode.classList.toggle(CLASS_RESIZABLE_GHOST, true);
1115
1132
  (_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
1116
1133
  transform = wrapper(ghostNode);
1117
1134
  onClone && onClone({ clone: ghostNode }, ev);
@@ -1173,7 +1190,7 @@
1173
1190
  }
1174
1191
  startPointXy = getPointInContainer(ev, container, offsetParentRect, offsetParentCStyle, matrixInfo);
1175
1192
  onStart &&
1176
- onStart.call(uiik, { w: originW, h: originH, transform }, ev);
1193
+ onStart.call(uiik, { w: originW, h: originH, transform, handle, ghost: ghostNode }, ev);
1177
1194
  });
1178
1195
  onPointerMove((args) => {
1179
1196
  const { ev, offX, offY } = args;
@@ -1394,39 +1411,13 @@
1394
1411
  break;
1395
1412
  }
1396
1413
  if (aspectRatio) {
1397
- if (changeW) {
1398
- style.width = w + "px";
1399
- style.height = w / aspectRatio + "px";
1400
- }
1401
1414
  if (changeH && dir !== "sw") {
1402
1415
  if (dir === "nw") {
1403
1416
  y = originY - w / aspectRatio + originH;
1404
1417
  }
1405
- else {
1406
- style.width = h * aspectRatio + "px";
1407
- style.height = h + "px";
1408
- }
1409
- }
1410
- }
1411
- else {
1412
- if (changeW) {
1413
- resize(transform, style, w);
1414
- }
1415
- if (changeH) {
1416
- resize(transform, style, undefined, h);
1417
1418
  }
1418
1419
  }
1419
- if (changeY) {
1420
- transform.moveTo(x, y + sY);
1421
- }
1422
- if (changeX) {
1423
- transform.moveTo(x + sX, y);
1424
- }
1425
- lastX = x;
1426
- lastY = y;
1427
- console.log(lastX, lastY);
1428
- currentW = w;
1429
- currentH = h;
1420
+ let canResize = true;
1430
1421
  if (onResize && onResize.call) {
1431
1422
  onResize.call;
1432
1423
  const panelRect = getRectInContainer(panel, panel.parentElement, matrixInfo);
@@ -1434,7 +1425,7 @@
1434
1425
  let centerY = Math.round(panelRect.y + panelRect.h / 2);
1435
1426
  let sx = Math.round(centerX - originW / 2);
1436
1427
  let sy = Math.round(centerY - originH / 2);
1437
- onResize.call(uiik, {
1428
+ canResize = onResize.call(uiik, {
1438
1429
  w,
1439
1430
  h,
1440
1431
  ow: w - originW,
@@ -1446,20 +1437,68 @@
1446
1437
  sy: sy,
1447
1438
  deg: matrixInfo.angle,
1448
1439
  transform,
1440
+ handle
1449
1441
  }, ev);
1450
1442
  }
1443
+ if (canResize !== false) {
1444
+ if (aspectRatio) {
1445
+ if (changeW) {
1446
+ style.width = w + "px";
1447
+ style.height = w / aspectRatio + "px";
1448
+ }
1449
+ if (changeH && dir !== "sw" && dir !== "nw") {
1450
+ style.width = h * aspectRatio + "px";
1451
+ style.height = h + "px";
1452
+ }
1453
+ }
1454
+ else {
1455
+ if (changeW) {
1456
+ resize(transform, style, w);
1457
+ }
1458
+ if (changeH) {
1459
+ resize(transform, style, undefined, h);
1460
+ }
1461
+ }
1462
+ if (changeY) {
1463
+ transform.moveTo(x, y + sY);
1464
+ }
1465
+ if (changeX) {
1466
+ transform.moveTo(x + sX, y);
1467
+ }
1468
+ }
1469
+ lastX = x;
1470
+ lastY = y;
1471
+ currentW = w;
1472
+ currentH = h;
1451
1473
  });
1452
1474
  onPointerEnd((args) => {
1453
1475
  var _a, _b;
1454
1476
  const { ev } = args;
1477
+ let doDefault = true;
1478
+ handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1479
+ let ghostLeft = '0';
1480
+ let ghostTop = '0';
1481
+ let ghostWidth = '0';
1482
+ let ghostHeight = '0';
1455
1483
  if (ghost && ghostNode) {
1456
- panelStyle.left = ghostNode.style.left;
1457
- panelStyle.top = ghostNode.style.top;
1458
- transform = wrapper(panel);
1459
- transform.moveTo((lastX + sX), (lastY + sY));
1484
+ ghostLeft = ghostNode.style.left;
1485
+ ghostTop = ghostNode.style.top;
1486
+ ghostWidth = ghostNode.style.width;
1487
+ ghostHeight = ghostNode.style.height;
1460
1488
  ((_a = panel.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) &&
1461
1489
  ((_b = panel.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
1462
- resize(transform, panelStyle, parseFloat(ghostNode.style.width), parseFloat(ghostNode.style.height));
1490
+ }
1491
+ if (onEnd) {
1492
+ doDefault = onEnd.call(uiik, { w: currentW, h: currentH, transform, handle, ghost: ghostNode }, ev);
1493
+ }
1494
+ if (doDefault === false)
1495
+ return;
1496
+ if (ghost && ghostNode) {
1497
+ panelStyle.left = ghostLeft;
1498
+ panelStyle.top = ghostTop;
1499
+ transform = wrapper(panel);
1500
+ transform.moveTo((lastX + sX), (lastY + sY));
1501
+ resize(transform, panelStyle, parseFloat(ghostWidth), parseFloat(ghostHeight));
1463
1502
  }
1464
1503
  if (setOrigin)
1465
1504
  panel.style.transformOrigin = originalTransformOrigin;
@@ -1480,13 +1519,7 @@
1480
1519
  }
1481
1520
  }
1482
1521
  }
1483
- handle.classList.remove(CLASS_RESIZABLE_HANDLE_ACTIVE);
1484
- onEnd &&
1485
- onEnd.call(uiik, { w: currentW, h: currentH, transform }, ev);
1486
1522
  });
1487
- }, {
1488
- threshold: THRESHOLD,
1489
- lockPage: true,
1490
1523
  });
1491
1524
  }
1492
1525
  initHandle(panel) {
@@ -1499,6 +1532,15 @@
1499
1532
  else if (is.isFunction(handleStr)) {
1500
1533
  handles = handleStr(panel);
1501
1534
  }
1535
+ else if (myfx.isElement(handleStr)) {
1536
+ handles = [handleStr];
1537
+ }
1538
+ else if (is.isArrayLike(handleStr)) {
1539
+ let eles = myfx.filter(handleStr, h => myfx.isElement(h));
1540
+ if (eles.length > 0) {
1541
+ handles = eles;
1542
+ }
1543
+ }
1502
1544
  if (!handles) {
1503
1545
  console.error('Can not find handles in "' + panel.outerHTML + '"');
1504
1546
  return;
@@ -1546,12 +1588,16 @@
1546
1588
  return new Resizable(els, opts);
1547
1589
  }
1548
1590
 
1549
- var _Draggable_instances, _Draggable_handleMap, _Draggable_container, _Draggable_initStyle;
1591
+ var _Draggable_instances, _Draggable_container, _Draggable_initHandle, _Draggable_initStyle;
1550
1592
  const DRAGGER_GROUPS = {};
1551
1593
  const CLASS_DRAGGABLE = "uii-draggable";
1552
1594
  const CLASS_DRAGGABLE_HANDLE = "uii-draggable-handle";
1553
1595
  const CLASS_DRAGGABLE_ACTIVE = "uii-draggable-active";
1554
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 = {};
1555
1601
  class Draggable extends Uii {
1556
1602
  constructor(els, opts) {
1557
1603
  super(els, object.assign({
@@ -1568,17 +1614,9 @@
1568
1614
  self: false,
1569
1615
  }, opts));
1570
1616
  _Draggable_instances.add(this);
1571
- _Draggable_handleMap.set(this, new WeakMap());
1572
1617
  _Draggable_container.set(this, null);
1573
1618
  if (this.opts.handle) {
1574
- collection.each(this.ele, (el) => {
1575
- const h = el.querySelector(this.opts.handle);
1576
- if (!h) {
1577
- console.error('No handle found "' + this.opts.handle + '"');
1578
- return false;
1579
- }
1580
- __classPrivateFieldGet(this, _Draggable_handleMap, "f").set(el, h);
1581
- });
1619
+ __classPrivateFieldGet(this, _Draggable_instances, "m", _Draggable_initHandle).call(this, this.ele);
1582
1620
  }
1583
1621
  this.onOptionChanged(this.opts);
1584
1622
  if (this.opts.group) {
@@ -1607,15 +1645,20 @@
1607
1645
  else {
1608
1646
  con = is.isEmpty(this.ele) ? null : this.ele[0].parentElement;
1609
1647
  }
1610
- 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);
1611
1654
  }
1612
1655
  else {
1613
1656
  collection.each(this.ele, (el) => {
1614
- this.bindEvent(el, this.opts, __classPrivateFieldGet(this, _Draggable_handleMap, "f"));
1657
+ this.bindEvent(el);
1615
1658
  });
1616
1659
  }
1617
1660
  }
1618
- bindEvent(bindTarget, opts, handleMap) {
1661
+ bindEvent(bindTarget) {
1619
1662
  const container = __classPrivateFieldGet(this, _Draggable_container, "f");
1620
1663
  let draggableList = this.ele;
1621
1664
  const eleString = this.eleString;
@@ -1625,23 +1668,37 @@
1625
1668
  let t = ev.target;
1626
1669
  if (!t)
1627
1670
  return true;
1628
- if (opts.watch && eleString) {
1629
- draggableList = bindTarget.querySelectorAll(eleString);
1630
- initStyle(draggableList);
1671
+ let opts = {};
1672
+ let findRs = tree.closest(t, (node) => node && object.get(node, UII_KEY), "parentElement");
1673
+ if (!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;
1631
1687
  }
1632
- let findRs = tree.closest(t, (node) => collection.includes(draggableList, node), "parentNode");
1633
- if (!findRs)
1634
- return true;
1635
1688
  const dragDom = findRs;
1636
- let handle = handleMap.get(dragDom);
1637
- if (handle && !handle.contains(t)) {
1689
+ let handle = HANDLE_MAP.get(dragDom);
1690
+ if (handle && !myfx.isCustomElement(t) && !handle.contains(t)) {
1638
1691
  return true;
1639
1692
  }
1693
+ if (is.isEmpty(opts))
1694
+ opts = OPTION_MAP.get(dragDom);
1695
+ if (!opts || is.isEmpty(opts))
1696
+ return true;
1640
1697
  if (opts.self && dragDom !== t)
1641
1698
  return true;
1642
1699
  const onPointerDown = opts.onPointerDown;
1643
1700
  if (onPointerDown &&
1644
- onPointerDown({ draggable: dragDom }, ev) === false)
1701
+ onPointerDown({ draggable: dragDom, handle }, ev) === false)
1645
1702
  return true;
1646
1703
  const filter = opts.filter;
1647
1704
  if (filter) {
@@ -1982,7 +2039,7 @@
1982
2039
  let moveToGhost = true;
1983
2040
  if (onEnd) {
1984
2041
  moveToGhost =
1985
- onEnd({ draggable: dragDom, x: endX, y: endY, transform }, ev) ===
2042
+ onEnd({ draggable: dragDom, x: endX, y: endY, transform, ghost: ghostNode }, ev) ===
1986
2043
  false
1987
2044
  ? false
1988
2045
  : true;
@@ -1999,13 +2056,19 @@
1999
2056
  if (ghost) {
2000
2057
  (_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(ghostNode);
2001
2058
  if (moveToGhost !== false) {
2002
- 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
+ }
2003
2069
  }
2004
2070
  }
2005
2071
  });
2006
- }, {
2007
- threshold: this.opts.threshold || 0,
2008
- lockPage: true,
2009
2072
  });
2010
2073
  }
2011
2074
  onOptionChanged(opts) {
@@ -2026,12 +2089,27 @@
2026
2089
  }
2027
2090
  }
2028
2091
  }
2029
- _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
+ let h;
2095
+ if (is.isString(this.opts.handle)) {
2096
+ h = el.querySelector(this.opts.handle);
2097
+ if (!h) {
2098
+ console.error('No handle found "' + this.opts.handle + '"');
2099
+ return false;
2100
+ }
2101
+ }
2102
+ else if (is.isElement(this.opts.handle)) {
2103
+ h = this.opts.handle;
2104
+ }
2105
+ HANDLE_MAP.set(el, h);
2106
+ });
2107
+ }, _Draggable_initStyle = function _Draggable_initStyle(draggableList) {
2030
2108
  collection.each(draggableList, (el) => {
2031
2109
  if (is.isDefined(this.opts.type))
2032
2110
  el.dataset.dropType = this.opts.type;
2033
2111
  el.classList.toggle(CLASS_DRAGGABLE, true);
2034
- const ee = __classPrivateFieldGet(this, _Draggable_handleMap, "f").get(el) || el;
2112
+ const ee = HANDLE_MAP.get(el) || el;
2035
2113
  ee.classList.toggle(CLASS_DRAGGABLE_HANDLE, true);
2036
2114
  if (!is.isUndefined(this.opts.cursor)) {
2037
2115
  el.style.cursor = this.opts.cursor.default || "move";
@@ -2040,6 +2118,7 @@
2040
2118
  el.dataset.cursorActive = this.opts.cursor.active || "move";
2041
2119
  }
2042
2120
  }
2121
+ OPTION_MAP.set(el, this.opts);
2043
2122
  });
2044
2123
  };
2045
2124
  function newDraggable(els, opts) {
@@ -2268,9 +2347,6 @@
2268
2347
  el.classList.toggle(CLASS_ROTATABLE_ACTIVE, false);
2269
2348
  onEnd && onEnd({ deg }, ev);
2270
2349
  });
2271
- }, {
2272
- threshold: THRESHOLD,
2273
- lockPage: true,
2274
2350
  });
2275
2351
  }
2276
2352
  function newRotatable(els, opts) {
@@ -2571,9 +2647,6 @@
2571
2647
  if (onEnd)
2572
2648
  onEnd({ selection, selectable: con }, ev);
2573
2649
  });
2574
- }, {
2575
- threshold: THRESHOLD,
2576
- lockPage: true
2577
2650
  });
2578
2651
  };
2579
2652
  function newSelectable(container, opts) {
@@ -2970,7 +3043,7 @@
2970
3043
  return new Sortable(container, opts);
2971
3044
  }
2972
3045
 
2973
- var version = "1.3.7";
3046
+ var version = "1.4.1";
2974
3047
  var repository = {
2975
3048
  type: "git",
2976
3049
  url: "https://github.com/holyhigh2/uiik"
@@ -3016,6 +3089,7 @@
3016
3089
  exports.Sortable = Sortable;
3017
3090
  exports.Splittable = Splittable;
3018
3091
  exports.THRESHOLD = THRESHOLD;
3092
+ exports.UII_KEY = UII_KEY;
3019
3093
  exports.Uii = Uii;
3020
3094
  exports.UiiTransform = UiiTransform;
3021
3095
  exports.VERSION = VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uiik",
3
- "version": "1.3.7",
3
+ "version": "1.4.1",
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 = {
@@ -25,15 +24,18 @@ export type ResizableOptions = {
25
24
  minSize?: number | Array<number>;
26
25
  maxSize?: number | Array<number>;
27
26
  aspectRatio?: number;
28
- ghost?: boolean | Function;
27
+ ghost?: ((panel: HTMLElement | SVGGraphicsElement) => HTMLElement | SVGGraphicsElement) | boolean;
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;
35
35
  h: number;
36
36
  transform: UiiTransform;
37
+ handle: HTMLElement | SVGGraphicsElement;
38
+ ghost: HTMLElement | SVGGraphicsElement;
37
39
  }, event: MouseEvent) => void;
38
40
  onResize?: (data: {
39
41
  w: number;
@@ -46,14 +48,17 @@ export type ResizableOptions = {
46
48
  y: number;
47
49
  }>;
48
50
  transform: UiiTransform;
49
- }, event: MouseEvent) => void;
51
+ handle: HTMLElement | SVGGraphicsElement;
52
+ }, event: MouseEvent) => boolean | void;
50
53
  onEnd?: (data: {
51
54
  w: number;
52
55
  h: number;
53
56
  transform: UiiTransform;
54
- }, event: MouseEvent) => void;
57
+ handle: HTMLElement | SVGGraphicsElement;
58
+ ghost: HTMLElement | SVGGraphicsElement;
59
+ }, event: MouseEvent) => boolean | void;
55
60
  onClone?: (data: {
56
- clone: HTMLElement;
61
+ clone: HTMLElement | SVGGraphicsElement;
57
62
  }, event: MouseEvent) => void;
58
63
  };
59
64
  export type SplittableOptions = {
@@ -66,6 +71,7 @@ export type SplittableOptions = {
66
71
  ghostClass?: string;
67
72
  ghostTo?: string | HTMLElement;
68
73
  handle?: string | HTMLElement | HTMLElement[];
74
+ eventCapture?: boolean;
69
75
  onStart?: (data: {
70
76
  size1: number;
71
77
  size2: number;
@@ -94,10 +100,10 @@ export type DraggableOptions = {
94
100
  containment?: boolean | HTMLElement | string;
95
101
  watch?: boolean | string;
96
102
  threshold?: number;
97
- handle?: string;
103
+ handle?: string | HTMLElement | SVGGraphicsElement;
98
104
  filter?: string;
99
105
  droppable?: (() => NodeList | HTMLCollection | HTMLElement[]) | string | HTMLElement | HTMLElement[];
100
- ghost?: ((el: HTMLElement) => HTMLElement) | boolean;
106
+ ghost?: ((panel: HTMLElement | SVGGraphicsElement) => HTMLElement | SVGGraphicsElement) | boolean;
101
107
  ghostClass?: string;
102
108
  ghostTo?: string | HTMLElement;
103
109
  direction?: "v" | "h";
@@ -117,8 +123,10 @@ export type DraggableOptions = {
117
123
  };
118
124
  grid?: number | number[];
119
125
  type?: string;
126
+ eventCapture?: boolean;
120
127
  onPointerDown?: (data: {
121
128
  draggable: HTMLElement | SVGGraphicsElement;
129
+ handle: HTMLElement | SVGGraphicsElement;
122
130
  }, event: MouseEvent) => boolean;
123
131
  onStart?: (data: {
124
132
  draggable: HTMLElement | SVGGraphicsElement;
@@ -139,6 +147,7 @@ export type DraggableOptions = {
139
147
  x: number;
140
148
  y: number;
141
149
  transform: UiiTransform;
150
+ ghost: HTMLElement | SVGGraphicsElement;
142
151
  }, event: MouseEvent) => boolean | void;
143
152
  onClone?: (data: {
144
153
  clone: HTMLElement | SVGGraphicsElement;
@@ -157,6 +166,7 @@ export type DroppableOptions = {
157
166
  activeClass?: string;
158
167
  hoverClass?: string;
159
168
  accepts?: ((ele: Array<HTMLElement>, draggable: HTMLElement) => boolean) | string;
169
+ eventCapture?: boolean;
160
170
  onActive?: (data: {
161
171
  draggable: HTMLElement;
162
172
  droppables: Array<HTMLElement>;
@@ -190,6 +200,7 @@ export type RotatableOptions = {
190
200
  ox?: number | string;
191
201
  oy?: number | string;
192
202
  handle?: ((target: HTMLElement | SVGGraphicsElement) => NodeList | HTMLCollection | HTMLElement[] | HTMLElement | SVGGraphicsElement) | string | NodeList | HTMLCollection | HTMLElement[] | HTMLElement | SVGGraphicsElement;
203
+ eventCapture?: boolean;
193
204
  onPointerDown?: (event: MouseEvent) => boolean;
194
205
  onStart?: (data: {
195
206
  deg: number;
@@ -217,6 +228,7 @@ export type SelectableOptions = {
217
228
  scroll?: boolean;
218
229
  scrollSpeed?: number;
219
230
  filter?: ((el: HTMLElement) => boolean) | string;
231
+ eventCapture?: boolean;
220
232
  onPointerDown?: (event: MouseEvent) => boolean;
221
233
  onStart?: (data: {
222
234
  selection: Array<HTMLElement>;
@@ -246,6 +258,7 @@ export type SortableOptions = {
246
258
  };
247
259
  spill?: "remove" | "revert";
248
260
  sort?: boolean;
261
+ eventCapture?: boolean;
249
262
  onActive?: (data: {
250
263
  item: HTMLElement;
251
264
  from: HTMLElement;