uiik 1.3.0-beta.2 → 1.3.0-beta.3
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 +6 -1
- package/index.esm.js +68 -16
- package/index.js +68 -16
- package/package.json +1 -1
- package/types.d.ts +6 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
### 新增
|
|
8
8
|
- handle 属性变更,支持更多类型
|
|
9
9
|
- onPointerDown 事件,可用于阻止后续逻辑
|
|
10
|
-
-
|
|
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
|
+
* uiik v1.3.0-beta.3
|
|
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
|
|
@@ -430,6 +430,7 @@ class Uii {
|
|
|
430
430
|
this.enabled = true;
|
|
431
431
|
_Uii_listeners.set(this, []);
|
|
432
432
|
this.opts = opts || {};
|
|
433
|
+
this.opts.mouseButton = this.opts.mouseButton || 'left';
|
|
433
434
|
if (isArrayLike(ele) && !isString(ele)) {
|
|
434
435
|
this.ele = map(ele, (el) => {
|
|
435
436
|
let e = isString(el) ? document.querySelector(el) : el;
|
|
@@ -449,7 +450,9 @@ class Uii {
|
|
|
449
450
|
console.error('Invalid element "' + ele + '"');
|
|
450
451
|
return;
|
|
451
452
|
}
|
|
452
|
-
this.ele = isArrayLike(el)
|
|
453
|
+
this.ele = isArrayLike(el)
|
|
454
|
+
? toArray(el)
|
|
455
|
+
: [el];
|
|
453
456
|
}
|
|
454
457
|
}
|
|
455
458
|
destroy() {
|
|
@@ -463,11 +466,23 @@ class Uii {
|
|
|
463
466
|
const threshold = opts.threshold || 0;
|
|
464
467
|
const toLockPage = opts.lockPage || false;
|
|
465
468
|
const uiiOptions = this.opts;
|
|
466
|
-
this.registerEvent(el,
|
|
469
|
+
this.registerEvent(el, "mousedown", (e) => {
|
|
470
|
+
if (uiiOptions.mouseButton) {
|
|
471
|
+
switch (uiiOptions.mouseButton) {
|
|
472
|
+
case "left":
|
|
473
|
+
if (e.button != 0)
|
|
474
|
+
return;
|
|
475
|
+
break;
|
|
476
|
+
case "right":
|
|
477
|
+
if (e.button != 2)
|
|
478
|
+
return;
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
467
482
|
let t = e.target;
|
|
468
483
|
if (!t)
|
|
469
484
|
return;
|
|
470
|
-
const hasCursor = !isEmpty(get(uiiOptions,
|
|
485
|
+
const hasCursor = !isEmpty(get(uiiOptions, "cursor.active"));
|
|
471
486
|
const currentStyle = el.style;
|
|
472
487
|
const currentCStyle = window.getComputedStyle(el);
|
|
473
488
|
const currentRect = el.getBoundingClientRect();
|
|
@@ -481,12 +496,23 @@ class Uii {
|
|
|
481
496
|
let onPointerMove;
|
|
482
497
|
let onPointerEnd;
|
|
483
498
|
const toBreak = !!onPointerDown({
|
|
484
|
-
onPointerMove: (pm) => {
|
|
485
|
-
|
|
486
|
-
|
|
499
|
+
onPointerMove: (pm) => {
|
|
500
|
+
onPointerMove = pm;
|
|
501
|
+
},
|
|
502
|
+
onPointerStart: (ps) => {
|
|
503
|
+
onPointerStart = ps;
|
|
504
|
+
},
|
|
505
|
+
onPointerEnd: (pe) => {
|
|
506
|
+
onPointerEnd = pe;
|
|
507
|
+
},
|
|
487
508
|
ev: e,
|
|
488
|
-
pointX: e.clientX,
|
|
489
|
-
|
|
509
|
+
pointX: e.clientX,
|
|
510
|
+
pointY: e.clientY,
|
|
511
|
+
target: t,
|
|
512
|
+
currentTarget: el,
|
|
513
|
+
currentStyle,
|
|
514
|
+
currentCStyle,
|
|
515
|
+
currentRect,
|
|
490
516
|
});
|
|
491
517
|
if (toBreak) {
|
|
492
518
|
e.preventDefault();
|
|
@@ -511,12 +537,21 @@ class Uii {
|
|
|
511
537
|
return false;
|
|
512
538
|
}
|
|
513
539
|
}
|
|
514
|
-
onPointerMove &&
|
|
540
|
+
onPointerMove &&
|
|
541
|
+
onPointerMove({
|
|
542
|
+
ev,
|
|
543
|
+
pointX: ev.clientX,
|
|
544
|
+
pointY: ev.clientY,
|
|
545
|
+
offX,
|
|
546
|
+
offY,
|
|
547
|
+
currentStyle,
|
|
548
|
+
currentCStyle,
|
|
549
|
+
});
|
|
515
550
|
};
|
|
516
551
|
const pointerEnd = (ev) => {
|
|
517
|
-
document.removeEventListener(
|
|
518
|
-
document.removeEventListener(
|
|
519
|
-
window.removeEventListener(
|
|
552
|
+
document.removeEventListener("mousemove", pointerMove, false);
|
|
553
|
+
document.removeEventListener("mouseup", pointerEnd, false);
|
|
554
|
+
window.removeEventListener("blur", pointerEnd, false);
|
|
520
555
|
if (dragging) {
|
|
521
556
|
if (toLockPage) {
|
|
522
557
|
unlockPage();
|
|
@@ -1348,7 +1383,8 @@ class Draggable extends Uii {
|
|
|
1348
1383
|
scroll: true,
|
|
1349
1384
|
snapOptions: {
|
|
1350
1385
|
tolerance: 10,
|
|
1351
|
-
}
|
|
1386
|
+
},
|
|
1387
|
+
self: true
|
|
1352
1388
|
}, opts));
|
|
1353
1389
|
_Draggable_instances.add(this);
|
|
1354
1390
|
_Draggable_handleMap.set(this, new WeakMap());
|
|
@@ -1420,6 +1456,8 @@ class Draggable extends Uii {
|
|
|
1420
1456
|
if (handle && !handle.contains(t)) {
|
|
1421
1457
|
return true;
|
|
1422
1458
|
}
|
|
1459
|
+
if (opts.self && dragDom !== t)
|
|
1460
|
+
return;
|
|
1423
1461
|
const onPointerDown = opts.onPointerDown;
|
|
1424
1462
|
if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
|
|
1425
1463
|
return true;
|
|
@@ -1799,7 +1837,9 @@ const Droppables = [];
|
|
|
1799
1837
|
const CLASS_DROPPABLE = "uii-droppable";
|
|
1800
1838
|
class Droppable extends Uii {
|
|
1801
1839
|
constructor(el, opts) {
|
|
1802
|
-
super(el, assign({
|
|
1840
|
+
super(el, assign({
|
|
1841
|
+
watch: true
|
|
1842
|
+
}, opts));
|
|
1803
1843
|
_Droppable_active.set(this, void 0);
|
|
1804
1844
|
Droppables.push(this);
|
|
1805
1845
|
}
|
|
@@ -1807,6 +1847,8 @@ class Droppable extends Uii {
|
|
|
1807
1847
|
this.registerEvent(droppable, "mouseenter", (e) => {
|
|
1808
1848
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1809
1849
|
return;
|
|
1850
|
+
if (e.target === droppable)
|
|
1851
|
+
return;
|
|
1810
1852
|
if (opts.hoverClass) {
|
|
1811
1853
|
each(split(opts.hoverClass, ' '), cls => {
|
|
1812
1854
|
droppable.classList.toggle(cls, true);
|
|
@@ -1820,6 +1862,8 @@ class Droppable extends Uii {
|
|
|
1820
1862
|
this.registerEvent(droppable, "mouseleave", (e) => {
|
|
1821
1863
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1822
1864
|
return;
|
|
1865
|
+
if (e.target === droppable)
|
|
1866
|
+
return;
|
|
1823
1867
|
if (opts.hoverClass) {
|
|
1824
1868
|
each(split(opts.hoverClass, ' '), cls => {
|
|
1825
1869
|
droppable.classList.toggle(cls, false);
|
|
@@ -1833,11 +1877,15 @@ class Droppable extends Uii {
|
|
|
1833
1877
|
this.registerEvent(droppable, "mousemove", (e) => {
|
|
1834
1878
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1835
1879
|
return;
|
|
1880
|
+
if (e.target === droppable)
|
|
1881
|
+
return;
|
|
1836
1882
|
opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
|
|
1837
1883
|
});
|
|
1838
1884
|
this.registerEvent(droppable, "mouseup", (e) => {
|
|
1839
1885
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1840
1886
|
return;
|
|
1887
|
+
if (e.target === droppable)
|
|
1888
|
+
return;
|
|
1841
1889
|
if (opts.hoverClass) {
|
|
1842
1890
|
each(split(opts.hoverClass, ' '), cls => {
|
|
1843
1891
|
droppable.classList.toggle(cls, false);
|
|
@@ -1849,6 +1897,10 @@ class Droppable extends Uii {
|
|
|
1849
1897
|
active(target) {
|
|
1850
1898
|
let valid = true;
|
|
1851
1899
|
const opts = this.opts;
|
|
1900
|
+
if (opts.watch && this.eleString) {
|
|
1901
|
+
let nodes = document.querySelectorAll(this.eleString);
|
|
1902
|
+
this.ele = toArray(nodes);
|
|
1903
|
+
}
|
|
1852
1904
|
if (isString(opts.accepts)) {
|
|
1853
1905
|
valid = !!target.dataset.dropType && test(opts.accepts, target.dataset.dropType);
|
|
1854
1906
|
}
|
|
@@ -2703,7 +2755,7 @@ function newSortable(container, opts) {
|
|
|
2703
2755
|
return new Sortable(container, opts);
|
|
2704
2756
|
}
|
|
2705
2757
|
|
|
2706
|
-
var version = "1.3.0-beta.
|
|
2758
|
+
var version = "1.3.0-beta.3";
|
|
2707
2759
|
var repository = {
|
|
2708
2760
|
type: "git",
|
|
2709
2761
|
url: "https://github.com/holyhigh2/uiik"
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* uiik v1.3.0-beta.
|
|
2
|
+
* uiik v1.3.0-beta.3
|
|
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
|
|
@@ -429,6 +429,7 @@
|
|
|
429
429
|
this.enabled = true;
|
|
430
430
|
_Uii_listeners.set(this, []);
|
|
431
431
|
this.opts = opts || {};
|
|
432
|
+
this.opts.mouseButton = this.opts.mouseButton || 'left';
|
|
432
433
|
if (is.isArrayLike(ele) && !is.isString(ele)) {
|
|
433
434
|
this.ele = collection.map(ele, (el) => {
|
|
434
435
|
let e = is.isString(el) ? document.querySelector(el) : el;
|
|
@@ -448,7 +449,9 @@
|
|
|
448
449
|
console.error('Invalid element "' + ele + '"');
|
|
449
450
|
return;
|
|
450
451
|
}
|
|
451
|
-
this.ele = is.isArrayLike(el)
|
|
452
|
+
this.ele = is.isArrayLike(el)
|
|
453
|
+
? collection.toArray(el)
|
|
454
|
+
: [el];
|
|
452
455
|
}
|
|
453
456
|
}
|
|
454
457
|
destroy() {
|
|
@@ -462,11 +465,23 @@
|
|
|
462
465
|
const threshold = opts.threshold || 0;
|
|
463
466
|
const toLockPage = opts.lockPage || false;
|
|
464
467
|
const uiiOptions = this.opts;
|
|
465
|
-
this.registerEvent(el,
|
|
468
|
+
this.registerEvent(el, "mousedown", (e) => {
|
|
469
|
+
if (uiiOptions.mouseButton) {
|
|
470
|
+
switch (uiiOptions.mouseButton) {
|
|
471
|
+
case "left":
|
|
472
|
+
if (e.button != 0)
|
|
473
|
+
return;
|
|
474
|
+
break;
|
|
475
|
+
case "right":
|
|
476
|
+
if (e.button != 2)
|
|
477
|
+
return;
|
|
478
|
+
break;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
466
481
|
let t = e.target;
|
|
467
482
|
if (!t)
|
|
468
483
|
return;
|
|
469
|
-
const hasCursor = !is.isEmpty(object.get(uiiOptions,
|
|
484
|
+
const hasCursor = !is.isEmpty(object.get(uiiOptions, "cursor.active"));
|
|
470
485
|
const currentStyle = el.style;
|
|
471
486
|
const currentCStyle = window.getComputedStyle(el);
|
|
472
487
|
const currentRect = el.getBoundingClientRect();
|
|
@@ -480,12 +495,23 @@
|
|
|
480
495
|
let onPointerMove;
|
|
481
496
|
let onPointerEnd;
|
|
482
497
|
const toBreak = !!onPointerDown({
|
|
483
|
-
onPointerMove: (pm) => {
|
|
484
|
-
|
|
485
|
-
|
|
498
|
+
onPointerMove: (pm) => {
|
|
499
|
+
onPointerMove = pm;
|
|
500
|
+
},
|
|
501
|
+
onPointerStart: (ps) => {
|
|
502
|
+
onPointerStart = ps;
|
|
503
|
+
},
|
|
504
|
+
onPointerEnd: (pe) => {
|
|
505
|
+
onPointerEnd = pe;
|
|
506
|
+
},
|
|
486
507
|
ev: e,
|
|
487
|
-
pointX: e.clientX,
|
|
488
|
-
|
|
508
|
+
pointX: e.clientX,
|
|
509
|
+
pointY: e.clientY,
|
|
510
|
+
target: t,
|
|
511
|
+
currentTarget: el,
|
|
512
|
+
currentStyle,
|
|
513
|
+
currentCStyle,
|
|
514
|
+
currentRect,
|
|
489
515
|
});
|
|
490
516
|
if (toBreak) {
|
|
491
517
|
e.preventDefault();
|
|
@@ -510,12 +536,21 @@
|
|
|
510
536
|
return false;
|
|
511
537
|
}
|
|
512
538
|
}
|
|
513
|
-
onPointerMove &&
|
|
539
|
+
onPointerMove &&
|
|
540
|
+
onPointerMove({
|
|
541
|
+
ev,
|
|
542
|
+
pointX: ev.clientX,
|
|
543
|
+
pointY: ev.clientY,
|
|
544
|
+
offX,
|
|
545
|
+
offY,
|
|
546
|
+
currentStyle,
|
|
547
|
+
currentCStyle,
|
|
548
|
+
});
|
|
514
549
|
};
|
|
515
550
|
const pointerEnd = (ev) => {
|
|
516
|
-
document.removeEventListener(
|
|
517
|
-
document.removeEventListener(
|
|
518
|
-
window.removeEventListener(
|
|
551
|
+
document.removeEventListener("mousemove", pointerMove, false);
|
|
552
|
+
document.removeEventListener("mouseup", pointerEnd, false);
|
|
553
|
+
window.removeEventListener("blur", pointerEnd, false);
|
|
519
554
|
if (dragging) {
|
|
520
555
|
if (toLockPage) {
|
|
521
556
|
unlockPage();
|
|
@@ -1347,7 +1382,8 @@
|
|
|
1347
1382
|
scroll: true,
|
|
1348
1383
|
snapOptions: {
|
|
1349
1384
|
tolerance: 10,
|
|
1350
|
-
}
|
|
1385
|
+
},
|
|
1386
|
+
self: true
|
|
1351
1387
|
}, opts));
|
|
1352
1388
|
_Draggable_instances.add(this);
|
|
1353
1389
|
_Draggable_handleMap.set(this, new WeakMap());
|
|
@@ -1419,6 +1455,8 @@
|
|
|
1419
1455
|
if (handle && !handle.contains(t)) {
|
|
1420
1456
|
return true;
|
|
1421
1457
|
}
|
|
1458
|
+
if (opts.self && dragDom !== t)
|
|
1459
|
+
return;
|
|
1422
1460
|
const onPointerDown = opts.onPointerDown;
|
|
1423
1461
|
if (onPointerDown && onPointerDown({ draggable: dragDom }, ev) === false)
|
|
1424
1462
|
return true;
|
|
@@ -1798,7 +1836,9 @@
|
|
|
1798
1836
|
const CLASS_DROPPABLE = "uii-droppable";
|
|
1799
1837
|
class Droppable extends Uii {
|
|
1800
1838
|
constructor(el, opts) {
|
|
1801
|
-
super(el, object.assign({
|
|
1839
|
+
super(el, object.assign({
|
|
1840
|
+
watch: true
|
|
1841
|
+
}, opts));
|
|
1802
1842
|
_Droppable_active.set(this, void 0);
|
|
1803
1843
|
Droppables.push(this);
|
|
1804
1844
|
}
|
|
@@ -1806,6 +1846,8 @@
|
|
|
1806
1846
|
this.registerEvent(droppable, "mouseenter", (e) => {
|
|
1807
1847
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1808
1848
|
return;
|
|
1849
|
+
if (e.target === droppable)
|
|
1850
|
+
return;
|
|
1809
1851
|
if (opts.hoverClass) {
|
|
1810
1852
|
collection.each(string.split(opts.hoverClass, ' '), cls => {
|
|
1811
1853
|
droppable.classList.toggle(cls, true);
|
|
@@ -1819,6 +1861,8 @@
|
|
|
1819
1861
|
this.registerEvent(droppable, "mouseleave", (e) => {
|
|
1820
1862
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1821
1863
|
return;
|
|
1864
|
+
if (e.target === droppable)
|
|
1865
|
+
return;
|
|
1822
1866
|
if (opts.hoverClass) {
|
|
1823
1867
|
collection.each(string.split(opts.hoverClass, ' '), cls => {
|
|
1824
1868
|
droppable.classList.toggle(cls, false);
|
|
@@ -1832,11 +1876,15 @@
|
|
|
1832
1876
|
this.registerEvent(droppable, "mousemove", (e) => {
|
|
1833
1877
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1834
1878
|
return;
|
|
1879
|
+
if (e.target === droppable)
|
|
1880
|
+
return;
|
|
1835
1881
|
opts.onOver && opts.onOver({ draggable: __classPrivateFieldGet(this, _Droppable_active, "f"), droppable }, e);
|
|
1836
1882
|
});
|
|
1837
1883
|
this.registerEvent(droppable, "mouseup", (e) => {
|
|
1838
1884
|
if (!__classPrivateFieldGet(this, _Droppable_active, "f"))
|
|
1839
1885
|
return;
|
|
1886
|
+
if (e.target === droppable)
|
|
1887
|
+
return;
|
|
1840
1888
|
if (opts.hoverClass) {
|
|
1841
1889
|
collection.each(string.split(opts.hoverClass, ' '), cls => {
|
|
1842
1890
|
droppable.classList.toggle(cls, false);
|
|
@@ -1848,6 +1896,10 @@
|
|
|
1848
1896
|
active(target) {
|
|
1849
1897
|
let valid = true;
|
|
1850
1898
|
const opts = this.opts;
|
|
1899
|
+
if (opts.watch && this.eleString) {
|
|
1900
|
+
let nodes = document.querySelectorAll(this.eleString);
|
|
1901
|
+
this.ele = collection.toArray(nodes);
|
|
1902
|
+
}
|
|
1851
1903
|
if (is.isString(opts.accepts)) {
|
|
1852
1904
|
valid = !!target.dataset.dropType && string.test(opts.accepts, target.dataset.dropType);
|
|
1853
1905
|
}
|
|
@@ -2702,7 +2754,7 @@
|
|
|
2702
2754
|
return new Sortable(container, opts);
|
|
2703
2755
|
}
|
|
2704
2756
|
|
|
2705
|
-
var version = "1.3.0-beta.
|
|
2757
|
+
var version = "1.3.0-beta.3";
|
|
2706
2758
|
var repository = {
|
|
2707
2759
|
type: "git",
|
|
2708
2760
|
url: "https://github.com/holyhigh2/uiik"
|
package/package.json
CHANGED
package/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { UiiTransform } from
|
|
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 |
|
|
241
|
+
to?: ((item: HTMLElement, from: HTMLElement) => boolean) | boolean | "copy";
|
|
239
242
|
from?: ((item: HTMLElement, from: HTMLElement, to: HTMLElement) => boolean) | boolean;
|
|
240
243
|
};
|
|
241
|
-
spill?:
|
|
244
|
+
spill?: "remove" | "revert";
|
|
242
245
|
sort?: boolean;
|
|
243
246
|
onActive?: (data: {
|
|
244
247
|
item: HTMLElement;
|