uiik 1.3.0-beta.2 → 1.3.0-beta.4

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/CHANGELOG.md CHANGED
@@ -7,7 +7,12 @@
7
7
  ### 新增
8
8
  - handle 属性变更,支持更多类型
9
9
  - onPointerDown 事件,可用于阻止后续逻辑
10
- - draggable watch参数,可用于dom变动自动检测
10
+ - Draggable watch参数,可用于dom变动自动检测
11
+ - Draggable self参数,仅自身元素响应时触发
12
+ - Droppable watch参数,可用于dom变动自动检测
13
+ - Uiik mouseButton参数,可指定鼠标响应按钮
14
+ ### 修复
15
+ - Droppable 元素同时为Draggable时会自己触发Droppable事件
11
16
 
12
17
  ## [1.2.0] - 2023/9/3
13
18
  ### Add
package/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * uiik v1.3.0-beta.2
2
+ * uiik v1.3.0-beta.4
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2023 @holyhigh2 may be freely distributed under the MIT license
@@ -9,6 +9,7 @@ import { find, map, toArray, each, reject, includes, some, flatMap, size } from
9
9
  import { get, assign, merge } from 'myfx/object';
10
10
  import { split, test } from 'myfx/string';
11
11
  import { compact, findIndex } from 'myfx/array';
12
+ import { closest } from 'myfx/tree';
12
13
  import { alphaId } from 'myfx/utils';
13
14
 
14
15
  /******************************************************************************
@@ -284,41 +285,59 @@ function getStyleSize(el, cStyle) {
284
285
  const h = parseFloat(cStyle.height);
285
286
  return { w, h };
286
287
  }
287
- const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<x>[\d.-]+)\s*,\s*(?<y>[\d.-]+)\s*\)/;
288
- function getMatrixInfo(elCStyle) {
289
- let a = 1, b = 0, x = 0, y = 0;
290
- let e = undefined, f = undefined;
291
- if (elCStyle instanceof SVGGraphicsElement) {
292
- const transMatrix = elCStyle.transform.animVal[0];
293
- if (transMatrix) {
294
- e = transMatrix.matrix.e;
295
- f = transMatrix.matrix.f;
288
+ const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<e>[\d.-]+)\s*,\s*(?<f>[\d.-]+)\s*\)/;
289
+ function getMatrixInfo(el, recur = false) {
290
+ const rs = _getMatrixInfo(el);
291
+ if (recur) {
292
+ let p = el.parentElement;
293
+ while (p && p.tagName !== "BODY") {
294
+ let prs = _getMatrixInfo(p);
295
+ rs.scale *= prs.scale;
296
+ p = p.parentElement;
296
297
  }
297
- elCStyle = window.getComputedStyle(elCStyle);
298
298
  }
299
- else {
300
- if (elCStyle instanceof HTMLElement) {
301
- elCStyle = window.getComputedStyle(elCStyle);
302
- }
303
- }
304
- const matched = elCStyle.transform.match(EXP_MATRIX);
305
- if (matched && matched.groups) {
306
- a = parseFloat(matched.groups.a);
307
- b = parseFloat(matched.groups.b);
308
- parseFloat(matched.groups.c);
309
- parseFloat(matched.groups.d);
310
- x = parseFloat(matched.groups.x);
311
- y = parseFloat(matched.groups.y);
299
+ return rs;
300
+ }
301
+ function _getMatrixInfo(el) {
302
+ const rs = { scale: 1, angle: 0, x: 0, y: 0 };
303
+ let a = 1, b = 0;
304
+ let elCStyle;
305
+ if (el instanceof SVGGraphicsElement || el instanceof HTMLElement) {
306
+ elCStyle = window.getComputedStyle(el);
312
307
  }
313
- if (e && f) {
314
- x = e;
315
- y = f;
308
+ let matrix = _getMatrix(elCStyle.transform);
309
+ if (matrix) {
310
+ a = matrix.a;
311
+ b = matrix.b;
312
+ matrix.c;
313
+ matrix.d;
314
+ rs.x = matrix.e;
315
+ rs.y = matrix.f;
316
316
  }
317
- const rs = { scale: 1, angle: 0, x, y };
318
317
  rs.scale = Math.sqrt(a * a + b * b);
319
318
  rs.angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
320
319
  return rs;
321
320
  }
321
+ function _getMatrix(transform) {
322
+ let matrix = null;
323
+ if (window.WebKitCSSMatrix) {
324
+ matrix = new WebKitCSSMatrix(transform);
325
+ }
326
+ else {
327
+ const matched = transform.match(EXP_MATRIX);
328
+ if (matched && matched.groups) {
329
+ matrix = {
330
+ a: parseFloat(matched.groups.a),
331
+ b: parseFloat(matched.groups.b),
332
+ c: parseFloat(matched.groups.c),
333
+ d: parseFloat(matched.groups.d),
334
+ e: parseFloat(matched.groups.e),
335
+ f: parseFloat(matched.groups.f),
336
+ };
337
+ }
338
+ }
339
+ return matrix;
340
+ }
322
341
  function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
323
342
  if (!elRect) {
324
343
  elRect = el.getBoundingClientRect();
@@ -327,7 +346,7 @@ function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
327
346
  elCStyle = window.getComputedStyle(el);
328
347
  }
329
348
  if (!matrixInfo) {
330
- matrixInfo = getMatrixInfo(elCStyle);
349
+ matrixInfo = getMatrixInfo(el, true);
331
350
  }
332
351
  const scale = matrixInfo.scale;
333
352
  let x = event.clientX -
@@ -344,7 +363,7 @@ function getRectInContainer(el, container) {
344
363
  const elRect = el.getBoundingClientRect();
345
364
  const containerRect = container.getBoundingClientRect();
346
365
  const elCStyle = window.getComputedStyle(container);
347
- const matrixInfo = getMatrixInfo(elCStyle);
366
+ const matrixInfo = getMatrixInfo(container);
348
367
  const scale = matrixInfo.scale;
349
368
  let x = elRect.x -
350
369
  containerRect.x -
@@ -389,7 +408,7 @@ function getVertex(el, ox, oy) {
389
408
  const h = parseFloat(cStyle.height);
390
409
  const { originX, originY } = parseOxy(ox, oy, w, h);
391
410
  const { x, y, sx, sy } = el instanceof SVGGraphicsElement ? getCenterXySVG(el, originX, originY) : getCenterXy(el);
392
- const { angle } = getMatrixInfo(cStyle);
411
+ const { angle } = getMatrixInfo(el);
393
412
  return calcVertex(w, h, x, y, sx, sy, angle * ONE_ANG);
394
413
  }
395
414
  function calcVertex(w, h, cx, cy, sx, sy, radian) {
@@ -430,6 +449,7 @@ class Uii {
430
449
  this.enabled = true;
431
450
  _Uii_listeners.set(this, []);
432
451
  this.opts = opts || {};
452
+ this.opts.mouseButton = this.opts.mouseButton || 'left';
433
453
  if (isArrayLike(ele) && !isString(ele)) {
434
454
  this.ele = map(ele, (el) => {
435
455
  let e = isString(el) ? document.querySelector(el) : el;
@@ -449,7 +469,9 @@ class Uii {
449
469
  console.error('Invalid element "' + ele + '"');
450
470
  return;
451
471
  }
452
- this.ele = isArrayLike(el) ? toArray(el) : [el];
472
+ this.ele = isArrayLike(el)
473
+ ? toArray(el)
474
+ : [el];
453
475
  }
454
476
  }
455
477
  destroy() {
@@ -463,11 +485,23 @@ class Uii {
463
485
  const threshold = opts.threshold || 0;
464
486
  const toLockPage = opts.lockPage || false;
465
487
  const uiiOptions = this.opts;
466
- this.registerEvent(el, 'mousedown', (e) => {
488
+ this.registerEvent(el, "mousedown", (e) => {
489
+ if (uiiOptions.mouseButton) {
490
+ switch (uiiOptions.mouseButton) {
491
+ case "left":
492
+ if (e.button != 0)
493
+ return;
494
+ break;
495
+ case "right":
496
+ if (e.button != 2)
497
+ return;
498
+ break;
499
+ }
500
+ }
467
501
  let t = e.target;
468
502
  if (!t)
469
503
  return;
470
- const hasCursor = !isEmpty(get(uiiOptions, 'cursor.active'));
504
+ const hasCursor = !isEmpty(get(uiiOptions, "cursor.active"));
471
505
  const currentStyle = el.style;
472
506
  const currentCStyle = window.getComputedStyle(el);
473
507
  const currentRect = el.getBoundingClientRect();
@@ -481,12 +515,23 @@ class Uii {
481
515
  let onPointerMove;
482
516
  let onPointerEnd;
483
517
  const toBreak = !!onPointerDown({
484
- onPointerMove: (pm) => { onPointerMove = pm; },
485
- onPointerStart: (ps) => { onPointerStart = ps; },
486
- onPointerEnd: (pe) => { onPointerEnd = pe; },
518
+ onPointerMove: (pm) => {
519
+ onPointerMove = pm;
520
+ },
521
+ onPointerStart: (ps) => {
522
+ onPointerStart = ps;
523
+ },
524
+ onPointerEnd: (pe) => {
525
+ onPointerEnd = pe;
526
+ },
487
527
  ev: e,
488
- pointX: e.clientX, pointY: e.clientY, target: t,
489
- currentTarget: el, currentStyle, currentCStyle, currentRect
528
+ pointX: e.clientX,
529
+ pointY: e.clientY,
530
+ target: t,
531
+ currentTarget: el,
532
+ currentStyle,
533
+ currentCStyle,
534
+ currentRect,
490
535
  });
491
536
  if (toBreak) {
492
537
  e.preventDefault();
@@ -511,12 +556,21 @@ class Uii {
511
556
  return false;
512
557
  }
513
558
  }
514
- onPointerMove && onPointerMove({ ev, pointX: ev.clientX, pointY: ev.clientY, offX, offY, currentStyle, currentCStyle });
559
+ onPointerMove &&
560
+ onPointerMove({
561
+ ev,
562
+ pointX: ev.clientX,
563
+ pointY: ev.clientY,
564
+ offX,
565
+ offY,
566
+ currentStyle,
567
+ currentCStyle,
568
+ });
515
569
  };
516
570
  const pointerEnd = (ev) => {
517
- document.removeEventListener('mousemove', pointerMove, false);
518
- document.removeEventListener('mouseup', pointerEnd, false);
519
- window.removeEventListener('blur', pointerEnd, false);
571
+ document.removeEventListener("mousemove", pointerMove, false);
572
+ document.removeEventListener("mouseup", pointerEnd, false);
573
+ window.removeEventListener("blur", pointerEnd, false);
520
574
  if (dragging) {
521
575
  if (toLockPage) {
522
576
  unlockPage();
@@ -1174,7 +1228,6 @@ class Resizable extends Uii {
1174
1228
  break;
1175
1229
  }
1176
1230
  if (changeW) {
1177
- console.log(minWidth, 'xxxxxx', w);
1178
1231
  if (minWidth && w < minWidth)
1179
1232
  w = minWidth;
1180
1233
  if (maxWidth && w > maxWidth)
@@ -1348,7 +1401,8 @@ class Draggable extends Uii {
1348
1401
  scroll: true,
1349
1402
  snapOptions: {
1350
1403
  tolerance: 10,
1351
- }
1404
+ },
1405
+ self: false
1352
1406
  }, opts));
1353
1407
  _Draggable_instances.add(this);
1354
1408
  _Draggable_handleMap.set(this, new WeakMap());
@@ -1412,7 +1466,7 @@ class Draggable extends Uii {
1412
1466
  draggableList = bindTarget.querySelectorAll(eleString);
1413
1467
  initStyle(draggableList);
1414
1468
  }
1415
- let findRs = find(draggableList, el => el.contains(t));
1469
+ let findRs = closest(t, node => includes(draggableList, node), 'parentNode');
1416
1470
  if (!findRs)
1417
1471
  return true;
1418
1472
  const dragDom = findRs;
@@ -1420,6 +1474,8 @@ class Draggable extends Uii {
1420
1474
  if (handle && !handle.contains(t)) {
1421
1475
  return true;
1422
1476
  }
1477
+ if (opts.self && dragDom !== t)
1478
+ return true;
1423
1479
  const onPointerDown = opts.onPointerDown;
1424
1480
  if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
1425
1481
  return true;
@@ -1434,11 +1490,8 @@ class Draggable extends Uii {
1434
1490
  const offsetXy = getPointInContainer(ev, dragDom);
1435
1491
  let offsetPointX = offsetXy.x;
1436
1492
  let offsetPointY = offsetXy.y;
1437
- const matrixInfo = getMatrixInfo(dragDom);
1493
+ const matrixInfo = getMatrixInfo(dragDom, true);
1438
1494
  const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1439
- const matrixInfoParent = getMatrixInfo(offsetParent);
1440
- offsetPointX = offsetPointX / (matrixInfo.scale * matrixInfoParent.scale);
1441
- offsetPointY = offsetPointY / (matrixInfo.scale * matrixInfoParent.scale);
1442
1495
  if (matrixInfo.angle != 0) {
1443
1496
  offsetPointX = currentXy.x - matrixInfo.x;
1444
1497
  offsetPointY = currentXy.y - matrixInfo.y;
@@ -1799,7 +1852,9 @@ const Droppables = [];
1799
1852
  const CLASS_DROPPABLE = "uii-droppable";
1800
1853
  class Droppable extends Uii {
1801
1854
  constructor(el, opts) {
1802
- super(el, assign({}, opts));
1855
+ super(el, assign({
1856
+ watch: true
1857
+ }, opts));
1803
1858
  _Droppable_active.set(this, void 0);
1804
1859
  Droppables.push(this);
1805
1860
  }
@@ -1807,6 +1862,8 @@ class Droppable extends Uii {
1807
1862
  this.registerEvent(droppable, "mouseenter", (e) => {
1808
1863
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1809
1864
  return;
1865
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1866
+ return;
1810
1867
  if (opts.hoverClass) {
1811
1868
  each(split(opts.hoverClass, ' '), cls => {
1812
1869
  droppable.classList.toggle(cls, true);
@@ -1820,6 +1877,8 @@ class Droppable extends Uii {
1820
1877
  this.registerEvent(droppable, "mouseleave", (e) => {
1821
1878
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1822
1879
  return;
1880
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1881
+ return;
1823
1882
  if (opts.hoverClass) {
1824
1883
  each(split(opts.hoverClass, ' '), cls => {
1825
1884
  droppable.classList.toggle(cls, false);
@@ -1833,11 +1892,15 @@ class Droppable extends Uii {
1833
1892
  this.registerEvent(droppable, "mousemove", (e) => {
1834
1893
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1835
1894
  return;
1895
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1896
+ return;
1836
1897
  opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1837
1898
  });
1838
1899
  this.registerEvent(droppable, "mouseup", (e) => {
1839
1900
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1840
1901
  return;
1902
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1903
+ return;
1841
1904
  if (opts.hoverClass) {
1842
1905
  each(split(opts.hoverClass, ' '), cls => {
1843
1906
  droppable.classList.toggle(cls, false);
@@ -1849,6 +1912,10 @@ class Droppable extends Uii {
1849
1912
  active(target) {
1850
1913
  let valid = true;
1851
1914
  const opts = this.opts;
1915
+ if (opts.watch && this.eleString) {
1916
+ let nodes = document.querySelectorAll(this.eleString);
1917
+ this.ele = toArray(nodes);
1918
+ }
1852
1919
  if (isString(opts.accepts)) {
1853
1920
  valid = !!target.dataset.dropType && test(opts.accepts, target.dataset.dropType);
1854
1921
  }
@@ -2175,7 +2242,7 @@ _Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap()
2175
2242
  if (onPointerDown && onPointerDown(ev) === false)
2176
2243
  return true;
2177
2244
  let originPos = "";
2178
- let matrixInfo = getMatrixInfo(currentCStyle);
2245
+ let matrixInfo = getMatrixInfo(currentTarget);
2179
2246
  const startxy = getPointInContainer(ev, con, currentRect, currentCStyle, matrixInfo);
2180
2247
  let hitPosX = startxy.x;
2181
2248
  let hitPosY = startxy.y;
@@ -2703,7 +2770,7 @@ function newSortable(container, opts) {
2703
2770
  return new Sortable(container, opts);
2704
2771
  }
2705
2772
 
2706
- var version = "1.3.0-beta.2";
2773
+ var version = "1.3.0-beta.4";
2707
2774
  var repository = {
2708
2775
  type: "git",
2709
2776
  url: "https://github.com/holyhigh2/uiik"
package/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * uiik v1.3.0-beta.2
2
+ * uiik v1.3.0-beta.4
3
3
  * A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.
4
4
  * https://github.com/holyhigh2/uiik
5
5
  * c) 2021-2023 @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/is'), require('myfx/collection'), require('myfx/object'), require('myfx/string'), require('myfx/array'), require('myfx/utils')) :
9
- typeof define === 'function' && define.amd ? define(['exports', 'myfx/is', 'myfx/collection', 'myfx/object', 'myfx/string', 'myfx/array', 'myfx/utils'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.is, global.collection, global.object, global.string, global.array, global.utils));
11
- })(this, (function (exports, is, collection, object, string, array, utils) { 'use strict';
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('myfx/is'), require('myfx/collection'), require('myfx/object'), require('myfx/string'), require('myfx/array'), require('myfx/tree'), require('myfx/utils')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', 'myfx/is', 'myfx/collection', 'myfx/object', 'myfx/string', 'myfx/array', 'myfx/tree', 'myfx/utils'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.uiik = {}, global.is, global.collection, global.object, global.string, global.array, global.tree, global.utils));
11
+ })(this, (function (exports, is, collection, object, string, array, tree, utils) { 'use strict';
12
12
 
13
13
  /******************************************************************************
14
14
  Copyright (c) Microsoft Corporation.
@@ -283,41 +283,59 @@
283
283
  const h = parseFloat(cStyle.height);
284
284
  return { w, h };
285
285
  }
286
- const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<x>[\d.-]+)\s*,\s*(?<y>[\d.-]+)\s*\)/;
287
- function getMatrixInfo(elCStyle) {
288
- let a = 1, b = 0, x = 0, y = 0;
289
- let e = undefined, f = undefined;
290
- if (elCStyle instanceof SVGGraphicsElement) {
291
- const transMatrix = elCStyle.transform.animVal[0];
292
- if (transMatrix) {
293
- e = transMatrix.matrix.e;
294
- f = transMatrix.matrix.f;
286
+ const EXP_MATRIX = /matrix\((?<a>[\d.-]+)\s*,\s*(?<b>[\d.-]+)\s*,\s*(?<c>[\d.-]+)\s*,\s*(?<d>[\d.-]+)\s*,\s*(?<e>[\d.-]+)\s*,\s*(?<f>[\d.-]+)\s*\)/;
287
+ function getMatrixInfo(el, recur = false) {
288
+ const rs = _getMatrixInfo(el);
289
+ if (recur) {
290
+ let p = el.parentElement;
291
+ while (p && p.tagName !== "BODY") {
292
+ let prs = _getMatrixInfo(p);
293
+ rs.scale *= prs.scale;
294
+ p = p.parentElement;
295
295
  }
296
- elCStyle = window.getComputedStyle(elCStyle);
297
296
  }
298
- else {
299
- if (elCStyle instanceof HTMLElement) {
300
- elCStyle = window.getComputedStyle(elCStyle);
301
- }
302
- }
303
- const matched = elCStyle.transform.match(EXP_MATRIX);
304
- if (matched && matched.groups) {
305
- a = parseFloat(matched.groups.a);
306
- b = parseFloat(matched.groups.b);
307
- parseFloat(matched.groups.c);
308
- parseFloat(matched.groups.d);
309
- x = parseFloat(matched.groups.x);
310
- y = parseFloat(matched.groups.y);
297
+ return rs;
298
+ }
299
+ function _getMatrixInfo(el) {
300
+ const rs = { scale: 1, angle: 0, x: 0, y: 0 };
301
+ let a = 1, b = 0;
302
+ let elCStyle;
303
+ if (el instanceof SVGGraphicsElement || el instanceof HTMLElement) {
304
+ elCStyle = window.getComputedStyle(el);
311
305
  }
312
- if (e && f) {
313
- x = e;
314
- y = f;
306
+ let matrix = _getMatrix(elCStyle.transform);
307
+ if (matrix) {
308
+ a = matrix.a;
309
+ b = matrix.b;
310
+ matrix.c;
311
+ matrix.d;
312
+ rs.x = matrix.e;
313
+ rs.y = matrix.f;
315
314
  }
316
- const rs = { scale: 1, angle: 0, x, y };
317
315
  rs.scale = Math.sqrt(a * a + b * b);
318
316
  rs.angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
319
317
  return rs;
320
318
  }
319
+ function _getMatrix(transform) {
320
+ let matrix = null;
321
+ if (window.WebKitCSSMatrix) {
322
+ matrix = new WebKitCSSMatrix(transform);
323
+ }
324
+ else {
325
+ const matched = transform.match(EXP_MATRIX);
326
+ if (matched && matched.groups) {
327
+ matrix = {
328
+ a: parseFloat(matched.groups.a),
329
+ b: parseFloat(matched.groups.b),
330
+ c: parseFloat(matched.groups.c),
331
+ d: parseFloat(matched.groups.d),
332
+ e: parseFloat(matched.groups.e),
333
+ f: parseFloat(matched.groups.f),
334
+ };
335
+ }
336
+ }
337
+ return matrix;
338
+ }
321
339
  function getPointInContainer(event, el, elRect, elCStyle, matrixInfo) {
322
340
  if (!elRect) {
323
341
  elRect = el.getBoundingClientRect();
@@ -326,7 +344,7 @@
326
344
  elCStyle = window.getComputedStyle(el);
327
345
  }
328
346
  if (!matrixInfo) {
329
- matrixInfo = getMatrixInfo(elCStyle);
347
+ matrixInfo = getMatrixInfo(el, true);
330
348
  }
331
349
  const scale = matrixInfo.scale;
332
350
  let x = event.clientX -
@@ -343,7 +361,7 @@
343
361
  const elRect = el.getBoundingClientRect();
344
362
  const containerRect = container.getBoundingClientRect();
345
363
  const elCStyle = window.getComputedStyle(container);
346
- const matrixInfo = getMatrixInfo(elCStyle);
364
+ const matrixInfo = getMatrixInfo(container);
347
365
  const scale = matrixInfo.scale;
348
366
  let x = elRect.x -
349
367
  containerRect.x -
@@ -388,7 +406,7 @@
388
406
  const h = parseFloat(cStyle.height);
389
407
  const { originX, originY } = parseOxy(ox, oy, w, h);
390
408
  const { x, y, sx, sy } = el instanceof SVGGraphicsElement ? getCenterXySVG(el, originX, originY) : getCenterXy(el);
391
- const { angle } = getMatrixInfo(cStyle);
409
+ const { angle } = getMatrixInfo(el);
392
410
  return calcVertex(w, h, x, y, sx, sy, angle * ONE_ANG);
393
411
  }
394
412
  function calcVertex(w, h, cx, cy, sx, sy, radian) {
@@ -429,6 +447,7 @@
429
447
  this.enabled = true;
430
448
  _Uii_listeners.set(this, []);
431
449
  this.opts = opts || {};
450
+ this.opts.mouseButton = this.opts.mouseButton || 'left';
432
451
  if (is.isArrayLike(ele) && !is.isString(ele)) {
433
452
  this.ele = collection.map(ele, (el) => {
434
453
  let e = is.isString(el) ? document.querySelector(el) : el;
@@ -448,7 +467,9 @@
448
467
  console.error('Invalid element "' + ele + '"');
449
468
  return;
450
469
  }
451
- this.ele = is.isArrayLike(el) ? collection.toArray(el) : [el];
470
+ this.ele = is.isArrayLike(el)
471
+ ? collection.toArray(el)
472
+ : [el];
452
473
  }
453
474
  }
454
475
  destroy() {
@@ -462,11 +483,23 @@
462
483
  const threshold = opts.threshold || 0;
463
484
  const toLockPage = opts.lockPage || false;
464
485
  const uiiOptions = this.opts;
465
- this.registerEvent(el, 'mousedown', (e) => {
486
+ this.registerEvent(el, "mousedown", (e) => {
487
+ if (uiiOptions.mouseButton) {
488
+ switch (uiiOptions.mouseButton) {
489
+ case "left":
490
+ if (e.button != 0)
491
+ return;
492
+ break;
493
+ case "right":
494
+ if (e.button != 2)
495
+ return;
496
+ break;
497
+ }
498
+ }
466
499
  let t = e.target;
467
500
  if (!t)
468
501
  return;
469
- const hasCursor = !is.isEmpty(object.get(uiiOptions, 'cursor.active'));
502
+ const hasCursor = !is.isEmpty(object.get(uiiOptions, "cursor.active"));
470
503
  const currentStyle = el.style;
471
504
  const currentCStyle = window.getComputedStyle(el);
472
505
  const currentRect = el.getBoundingClientRect();
@@ -480,12 +513,23 @@
480
513
  let onPointerMove;
481
514
  let onPointerEnd;
482
515
  const toBreak = !!onPointerDown({
483
- onPointerMove: (pm) => { onPointerMove = pm; },
484
- onPointerStart: (ps) => { onPointerStart = ps; },
485
- onPointerEnd: (pe) => { onPointerEnd = pe; },
516
+ onPointerMove: (pm) => {
517
+ onPointerMove = pm;
518
+ },
519
+ onPointerStart: (ps) => {
520
+ onPointerStart = ps;
521
+ },
522
+ onPointerEnd: (pe) => {
523
+ onPointerEnd = pe;
524
+ },
486
525
  ev: e,
487
- pointX: e.clientX, pointY: e.clientY, target: t,
488
- currentTarget: el, currentStyle, currentCStyle, currentRect
526
+ pointX: e.clientX,
527
+ pointY: e.clientY,
528
+ target: t,
529
+ currentTarget: el,
530
+ currentStyle,
531
+ currentCStyle,
532
+ currentRect,
489
533
  });
490
534
  if (toBreak) {
491
535
  e.preventDefault();
@@ -510,12 +554,21 @@
510
554
  return false;
511
555
  }
512
556
  }
513
- onPointerMove && onPointerMove({ ev, pointX: ev.clientX, pointY: ev.clientY, offX, offY, currentStyle, currentCStyle });
557
+ onPointerMove &&
558
+ onPointerMove({
559
+ ev,
560
+ pointX: ev.clientX,
561
+ pointY: ev.clientY,
562
+ offX,
563
+ offY,
564
+ currentStyle,
565
+ currentCStyle,
566
+ });
514
567
  };
515
568
  const pointerEnd = (ev) => {
516
- document.removeEventListener('mousemove', pointerMove, false);
517
- document.removeEventListener('mouseup', pointerEnd, false);
518
- window.removeEventListener('blur', pointerEnd, false);
569
+ document.removeEventListener("mousemove", pointerMove, false);
570
+ document.removeEventListener("mouseup", pointerEnd, false);
571
+ window.removeEventListener("blur", pointerEnd, false);
519
572
  if (dragging) {
520
573
  if (toLockPage) {
521
574
  unlockPage();
@@ -1173,7 +1226,6 @@
1173
1226
  break;
1174
1227
  }
1175
1228
  if (changeW) {
1176
- console.log(minWidth, 'xxxxxx', w);
1177
1229
  if (minWidth && w < minWidth)
1178
1230
  w = minWidth;
1179
1231
  if (maxWidth && w > maxWidth)
@@ -1347,7 +1399,8 @@
1347
1399
  scroll: true,
1348
1400
  snapOptions: {
1349
1401
  tolerance: 10,
1350
- }
1402
+ },
1403
+ self: false
1351
1404
  }, opts));
1352
1405
  _Draggable_instances.add(this);
1353
1406
  _Draggable_handleMap.set(this, new WeakMap());
@@ -1411,7 +1464,7 @@
1411
1464
  draggableList = bindTarget.querySelectorAll(eleString);
1412
1465
  initStyle(draggableList);
1413
1466
  }
1414
- let findRs = collection.find(draggableList, el => el.contains(t));
1467
+ let findRs = tree.closest(t, node => collection.includes(draggableList, node), 'parentNode');
1415
1468
  if (!findRs)
1416
1469
  return true;
1417
1470
  const dragDom = findRs;
@@ -1419,6 +1472,8 @@
1419
1472
  if (handle && !handle.contains(t)) {
1420
1473
  return true;
1421
1474
  }
1475
+ if (opts.self && dragDom !== t)
1476
+ return true;
1422
1477
  const onPointerDown = opts.onPointerDown;
1423
1478
  if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
1424
1479
  return true;
@@ -1433,11 +1488,8 @@
1433
1488
  const offsetXy = getPointInContainer(ev, dragDom);
1434
1489
  let offsetPointX = offsetXy.x;
1435
1490
  let offsetPointY = offsetXy.y;
1436
- const matrixInfo = getMatrixInfo(dragDom);
1491
+ const matrixInfo = getMatrixInfo(dragDom, true);
1437
1492
  const currentXy = getPointInContainer(ev, offsetParent, offsetParentRect, offsetParentCStyle);
1438
- const matrixInfoParent = getMatrixInfo(offsetParent);
1439
- offsetPointX = offsetPointX / (matrixInfo.scale * matrixInfoParent.scale);
1440
- offsetPointY = offsetPointY / (matrixInfo.scale * matrixInfoParent.scale);
1441
1493
  if (matrixInfo.angle != 0) {
1442
1494
  offsetPointX = currentXy.x - matrixInfo.x;
1443
1495
  offsetPointY = currentXy.y - matrixInfo.y;
@@ -1798,7 +1850,9 @@
1798
1850
  const CLASS_DROPPABLE = "uii-droppable";
1799
1851
  class Droppable extends Uii {
1800
1852
  constructor(el, opts) {
1801
- super(el, object.assign({}, opts));
1853
+ super(el, object.assign({
1854
+ watch: true
1855
+ }, opts));
1802
1856
  _Droppable_active.set(this, void 0);
1803
1857
  Droppables.push(this);
1804
1858
  }
@@ -1806,6 +1860,8 @@
1806
1860
  this.registerEvent(droppable, "mouseenter", (e) => {
1807
1861
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1808
1862
  return;
1863
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1864
+ return;
1809
1865
  if (opts.hoverClass) {
1810
1866
  collection.each(string.split(opts.hoverClass, ' '), cls => {
1811
1867
  droppable.classList.toggle(cls, true);
@@ -1819,6 +1875,8 @@
1819
1875
  this.registerEvent(droppable, "mouseleave", (e) => {
1820
1876
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1821
1877
  return;
1878
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1879
+ return;
1822
1880
  if (opts.hoverClass) {
1823
1881
  collection.each(string.split(opts.hoverClass, ' '), cls => {
1824
1882
  droppable.classList.toggle(cls, false);
@@ -1832,11 +1890,15 @@
1832
1890
  this.registerEvent(droppable, "mousemove", (e) => {
1833
1891
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1834
1892
  return;
1893
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1894
+ return;
1835
1895
  opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
1836
1896
  });
1837
1897
  this.registerEvent(droppable, "mouseup", (e) => {
1838
1898
  if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
1839
1899
  return;
1900
+ if (__classPrivateFieldGet(this, _Droppable_active, "f") === droppable)
1901
+ return;
1840
1902
  if (opts.hoverClass) {
1841
1903
  collection.each(string.split(opts.hoverClass, ' '), cls => {
1842
1904
  droppable.classList.toggle(cls, false);
@@ -1848,6 +1910,10 @@
1848
1910
  active(target) {
1849
1911
  let valid = true;
1850
1912
  const opts = this.opts;
1913
+ if (opts.watch && this.eleString) {
1914
+ let nodes = document.querySelectorAll(this.eleString);
1915
+ this.ele = collection.toArray(nodes);
1916
+ }
1851
1917
  if (is.isString(opts.accepts)) {
1852
1918
  valid = !!target.dataset.dropType && string.test(opts.accepts, target.dataset.dropType);
1853
1919
  }
@@ -2174,7 +2240,7 @@
2174
2240
  if (onPointerDown && onPointerDown(ev) === false)
2175
2241
  return true;
2176
2242
  let originPos = "";
2177
- let matrixInfo = getMatrixInfo(currentCStyle);
2243
+ let matrixInfo = getMatrixInfo(currentTarget);
2178
2244
  const startxy = getPointInContainer(ev, con, currentRect, currentCStyle, matrixInfo);
2179
2245
  let hitPosX = startxy.x;
2180
2246
  let hitPosY = startxy.y;
@@ -2702,7 +2768,7 @@
2702
2768
  return new Sortable(container, opts);
2703
2769
  }
2704
2770
 
2705
- var version = "1.3.0-beta.2";
2771
+ var version = "1.3.0-beta.4";
2706
2772
  var repository = {
2707
2773
  type: "git",
2708
2774
  url: "https://github.com/holyhigh2/uiik"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uiik",
3
- "version": "1.3.0-beta.2",
3
+ "version": "1.3.0-beta.4",
4
4
  "description": "A UI interactions kit includes draggable, splittable, rotatable, selectable, etc.",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
package/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { UiiTransform } from './transform';
1
+ import { UiiTransform } from "./transform";
2
2
  export declare abstract class Uii {
3
3
  #private;
4
4
  protected ele: Array<HTMLElement>;
@@ -88,6 +88,8 @@ export type SplittableOptions = {
88
88
  }, event: MouseEvent) => void;
89
89
  };
90
90
  export type DraggableOptions = {
91
+ self?: boolean;
92
+ mouseButton?: 'all' | "left" | "right";
91
93
  containment?: boolean | HTMLElement | string;
92
94
  watch?: boolean | string;
93
95
  threshold?: number;
@@ -148,6 +150,7 @@ export type DraggableOptions = {
148
150
  }, event: MouseEvent) => void;
149
151
  };
150
152
  export type DroppableOptions = {
153
+ watch?: boolean;
151
154
  activeClass?: string;
152
155
  hoverClass?: string;
153
156
  accepts?: ((ele: Array<HTMLElement>, draggable: HTMLElement) => boolean) | string;
@@ -235,10 +238,10 @@ export type SortableOptions = {
235
238
  handle?: string;
236
239
  activeClass?: string;
237
240
  move?: {
238
- to?: ((item: HTMLElement, from: HTMLElement) => boolean) | boolean | 'copy';
241
+ to?: ((item: HTMLElement, from: HTMLElement) => boolean) | boolean | "copy";
239
242
  from?: ((item: HTMLElement, from: HTMLElement, to: HTMLElement) => boolean) | boolean;
240
243
  };
241
- spill?: 'remove' | 'revert';
244
+ spill?: "remove" | "revert";
242
245
  sort?: boolean;
243
246
  onActive?: (data: {
244
247
  item: HTMLElement;
package/utils.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare function getStyleSize(el: HTMLElement | SVGGraphicsElement, cStyl
26
26
  w: number;
27
27
  h: number;
28
28
  };
29
- export declare function getMatrixInfo(elCStyle: CSSStyleDeclaration | HTMLElement | SVGGraphicsElement): {
29
+ export declare function getMatrixInfo(el: HTMLElement | SVGGraphicsElement, recur?: boolean): {
30
30
  scale: number;
31
31
  angle: number;
32
32
  x: number;