uiik 1.1.0 → 1.3.0-alpha
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 +14 -0
- package/README.md +1 -0
- package/detector.d.ts +0 -19
- package/draggable.d.ts +1 -18
- package/droppable.d.ts +0 -21
- package/index.d.ts +2 -0
- package/index.esm.js +2582 -2
- package/index.js +2625 -2
- package/package.json +4 -7
- package/resizable.d.ts +3 -15
- package/rotatable.d.ts +3 -16
- package/selectable.d.ts +0 -20
- package/sortable.d.ts +0 -24
- package/splittable.d.ts +0 -17
- package/transform.d.ts +19 -0
- package/types.d.ts +39 -307
- package/utils.d.ts +41 -12
- package/detector.js +0 -128
- package/draggable.js +0 -530
- package/droppable.js +0 -160
- package/resizable.js +0 -308
- package/rotatable.js +0 -137
- package/selectable.js +0 -281
- package/sortable.js +0 -441
- package/splittable.js +0 -340
- package/types.js +0 -116
- package/utils.js +0 -58
package/selectable.js
DELETED
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Selectable_instances, _Selectable__detector, _Selectable__lastSelected, _Selectable_bindEvent;
|
|
13
|
-
/* eslint-disable max-len */
|
|
14
|
-
/**
|
|
15
|
-
* selector
|
|
16
|
-
* @author holyhigh2
|
|
17
|
-
*/
|
|
18
|
-
import { each, includes, some } from 'myfx/collection';
|
|
19
|
-
import { assign } from 'myfx/object';
|
|
20
|
-
import { split } from 'myfx/string';
|
|
21
|
-
import { compact } from 'myfx/array';
|
|
22
|
-
import { isFunction } from 'myfx/is';
|
|
23
|
-
import { newCollisionDetector } from "./detector";
|
|
24
|
-
import { Uii } from "./types";
|
|
25
|
-
import { EDGE_THRESHOLD, getOffset } from "./utils";
|
|
26
|
-
const CLASS_SELECTOR = "uii-selector";
|
|
27
|
-
const CLASS_SELECTING = "uii-selecting";
|
|
28
|
-
const CLASS_SELECTED = "uii-selected";
|
|
29
|
-
const THRESHOLD = 2;
|
|
30
|
-
/**
|
|
31
|
-
* 用于表示一个元素选择器的定义
|
|
32
|
-
* > 可用CSS接口
|
|
33
|
-
* - .uii-selector
|
|
34
|
-
* - .uii-selecting
|
|
35
|
-
* - .uii-selected
|
|
36
|
-
* @public
|
|
37
|
-
*/
|
|
38
|
-
export class Selectable extends Uii {
|
|
39
|
-
constructor(container, opts) {
|
|
40
|
-
super(container, assign({
|
|
41
|
-
targets: [],
|
|
42
|
-
scroll: true,
|
|
43
|
-
}, opts));
|
|
44
|
-
_Selectable_instances.add(this);
|
|
45
|
-
_Selectable__detector.set(this, void 0);
|
|
46
|
-
_Selectable__lastSelected.set(this, void 0);
|
|
47
|
-
const domEl = this.ele[0];
|
|
48
|
-
//create selector
|
|
49
|
-
const selector = document.createElement("div");
|
|
50
|
-
selector.className = CLASS_SELECTOR;
|
|
51
|
-
selector.style.cssText = `
|
|
52
|
-
position:absolute;
|
|
53
|
-
left:-9999px;
|
|
54
|
-
`;
|
|
55
|
-
if (this.opts.class) {
|
|
56
|
-
selector.className += " " + this.opts.class;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
selector.style.cssText += "border:1px dashed #000;";
|
|
60
|
-
}
|
|
61
|
-
domEl.appendChild(selector);
|
|
62
|
-
//create detector
|
|
63
|
-
__classPrivateFieldSet(this, _Selectable__detector, newCollisionDetector(selector, this.opts.targets, {
|
|
64
|
-
container: domEl,
|
|
65
|
-
}), "f");
|
|
66
|
-
__classPrivateFieldGet(this, _Selectable_instances, "m", _Selectable_bindEvent).call(this, selector, domEl);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 更新targets
|
|
70
|
-
*/
|
|
71
|
-
updateTargets() {
|
|
72
|
-
__classPrivateFieldGet(this, _Selectable__detector, "f").update();
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/
|
|
77
|
-
onOptionChanged() {
|
|
78
|
-
this.updateTargets();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
_Selectable__detector = new WeakMap(), _Selectable__lastSelected = new WeakMap(), _Selectable_instances = new WeakSet(), _Selectable_bindEvent = function _Selectable_bindEvent(selector, con) {
|
|
82
|
-
const that = this;
|
|
83
|
-
const opts = this.opts;
|
|
84
|
-
this.registerEvent(con, "mousedown", (e) => {
|
|
85
|
-
const t = e.target;
|
|
86
|
-
const onStart = opts.onStart;
|
|
87
|
-
const onSelect = opts.onSelect;
|
|
88
|
-
const onEnd = opts.onEnd;
|
|
89
|
-
const mode = opts.mode || "overlap";
|
|
90
|
-
const scroll = opts.scroll;
|
|
91
|
-
const scrollSpeed = opts.scrollSpeed || 10;
|
|
92
|
-
const filter = opts.filter;
|
|
93
|
-
const selectingClassAry = compact(split(opts.selectingClass, " "));
|
|
94
|
-
const selectedClassAry = compact(split(opts.selectedClass, " "));
|
|
95
|
-
//check filter
|
|
96
|
-
if (filter) {
|
|
97
|
-
if (isFunction(filter)) {
|
|
98
|
-
if (filter(t))
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
else if (some(con.querySelectorAll(filter), (el) => el.contains(t)))
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
let originPos = "";
|
|
105
|
-
//offset
|
|
106
|
-
const rect = con.getBoundingClientRect();
|
|
107
|
-
const conStyle = window.getComputedStyle(con);
|
|
108
|
-
const blw = parseFloat(conStyle.borderLeftWidth);
|
|
109
|
-
const btw = parseFloat(conStyle.borderTopWidth);
|
|
110
|
-
let hitPosX = e.offsetX + con.scrollLeft, hitPosY = e.offsetY + con.scrollTop;
|
|
111
|
-
if (t !== con) {
|
|
112
|
-
const offset = getOffset(t, con);
|
|
113
|
-
const style = window.getComputedStyle(t);
|
|
114
|
-
hitPosX = offset.x + e.offsetX + parseFloat(style.borderLeftWidth);
|
|
115
|
-
hitPosY = offset.y + e.offsetY + parseFloat(style.borderTopWidth);
|
|
116
|
-
}
|
|
117
|
-
const style = selector.style;
|
|
118
|
-
let selection = [];
|
|
119
|
-
let lastSelection = [];
|
|
120
|
-
let x1 = hitPosX, y1 = hitPosY;
|
|
121
|
-
let dragging = false;
|
|
122
|
-
let timer = null;
|
|
123
|
-
let toLeft = false;
|
|
124
|
-
let toTop = false;
|
|
125
|
-
let toRight = false;
|
|
126
|
-
let toBottom = false;
|
|
127
|
-
const dragListener = (ev) => {
|
|
128
|
-
const newX = ev.clientX - rect.x + con.scrollLeft - blw;
|
|
129
|
-
const newY = ev.clientY - rect.y + con.scrollTop - btw;
|
|
130
|
-
const offsetx = newX - hitPosX;
|
|
131
|
-
const offsety = newY - hitPosY;
|
|
132
|
-
if (!dragging) {
|
|
133
|
-
if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
|
|
134
|
-
dragging = true;
|
|
135
|
-
//update targets count & positions
|
|
136
|
-
__classPrivateFieldGet(this, _Selectable__detector, "f").update();
|
|
137
|
-
//detect container position
|
|
138
|
-
const pos = window.getComputedStyle(con).position;
|
|
139
|
-
if (pos === "static") {
|
|
140
|
-
originPos = con.style.position;
|
|
141
|
-
con.style.position = "relative";
|
|
142
|
-
}
|
|
143
|
-
//clear _lastSelected
|
|
144
|
-
each(__classPrivateFieldGet(this, _Selectable__lastSelected, "f"), t => {
|
|
145
|
-
t.classList.toggle(CLASS_SELECTED, false);
|
|
146
|
-
});
|
|
147
|
-
onStart && onStart({ selection: __classPrivateFieldGet(this, _Selectable__lastSelected, "f"), selectable: con }, ev);
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
ev.preventDefault();
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
//edge detect
|
|
155
|
-
if (scroll) {
|
|
156
|
-
const ltX = ev.clientX - rect.x;
|
|
157
|
-
const ltY = ev.clientY - rect.y;
|
|
158
|
-
const rbX = rect.x + rect.width - ev.clientX;
|
|
159
|
-
const rbY = rect.y + rect.height - ev.clientY;
|
|
160
|
-
toLeft = ltX < EDGE_THRESHOLD;
|
|
161
|
-
toTop = ltY < EDGE_THRESHOLD;
|
|
162
|
-
toRight = rbX < EDGE_THRESHOLD;
|
|
163
|
-
toBottom = rbY < EDGE_THRESHOLD;
|
|
164
|
-
if (toLeft || toTop || toRight || toBottom) {
|
|
165
|
-
if (!timer) {
|
|
166
|
-
timer = setInterval(() => {
|
|
167
|
-
if (toLeft) {
|
|
168
|
-
con.scrollLeft -= scrollSpeed;
|
|
169
|
-
}
|
|
170
|
-
else if (toRight) {
|
|
171
|
-
con.scrollLeft += scrollSpeed;
|
|
172
|
-
}
|
|
173
|
-
if (toTop) {
|
|
174
|
-
con.scrollTop -= scrollSpeed;
|
|
175
|
-
}
|
|
176
|
-
else if (toBottom) {
|
|
177
|
-
con.scrollTop += scrollSpeed;
|
|
178
|
-
}
|
|
179
|
-
}, 20);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
if (timer) {
|
|
184
|
-
clearInterval(timer);
|
|
185
|
-
timer = null;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
let x = hitPosX, y = hitPosY, w = Math.abs(offsetx), h = Math.abs(offsety);
|
|
190
|
-
if (offsetx > 0 && offsety > 0) {
|
|
191
|
-
x1 = hitPosX;
|
|
192
|
-
y1 = hitPosY;
|
|
193
|
-
}
|
|
194
|
-
else if (offsetx < 0 && offsety < 0) {
|
|
195
|
-
x = x1 = newX;
|
|
196
|
-
y = y1 = newY;
|
|
197
|
-
}
|
|
198
|
-
else if (offsetx < 0) {
|
|
199
|
-
x = x1 = newX;
|
|
200
|
-
}
|
|
201
|
-
else if (offsety < 0) {
|
|
202
|
-
y = y1 = newY;
|
|
203
|
-
}
|
|
204
|
-
style.left = x + "px";
|
|
205
|
-
style.top = y + "px";
|
|
206
|
-
style.width = w + "px";
|
|
207
|
-
style.height = h + "px";
|
|
208
|
-
//detect collision
|
|
209
|
-
if (mode === "overlap") {
|
|
210
|
-
selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getOverlaps(x1, y1, x1 + w, y1 + h);
|
|
211
|
-
}
|
|
212
|
-
else if (mode === "inclusion") {
|
|
213
|
-
selection = __classPrivateFieldGet(that, _Selectable__detector, "f").getInclusions(x1, y1, x1 + w, y1 + h);
|
|
214
|
-
}
|
|
215
|
-
each(lastSelection, (t) => {
|
|
216
|
-
if (!includes(selection, t)) {
|
|
217
|
-
t.classList.toggle(CLASS_SELECTING, false);
|
|
218
|
-
each(selectingClassAry, (cls) => {
|
|
219
|
-
t.classList.toggle(cls, false);
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
each(selection, (t) => {
|
|
224
|
-
t.classList.toggle(CLASS_SELECTING, true);
|
|
225
|
-
each(selectingClassAry, (cls) => {
|
|
226
|
-
t.classList.toggle(cls, true);
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
const changed = lastSelection.length != selection.length;
|
|
230
|
-
lastSelection = selection;
|
|
231
|
-
if (changed && onSelect)
|
|
232
|
-
onSelect({ selection, selectable: con }, ev);
|
|
233
|
-
ev.preventDefault();
|
|
234
|
-
return false;
|
|
235
|
-
};
|
|
236
|
-
const dragEndListener = (ev) => {
|
|
237
|
-
style.left = "-9999px";
|
|
238
|
-
style.width = style.height = "0px";
|
|
239
|
-
document.removeEventListener("mousemove", dragListener, false);
|
|
240
|
-
document.removeEventListener("mouseup", dragEndListener, false);
|
|
241
|
-
window.removeEventListener("blur", dragEndListener, false);
|
|
242
|
-
if (scroll) {
|
|
243
|
-
if (timer) {
|
|
244
|
-
clearInterval(timer);
|
|
245
|
-
timer = null;
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
//restore container position
|
|
249
|
-
if (originPos) {
|
|
250
|
-
con.style.position = originPos;
|
|
251
|
-
}
|
|
252
|
-
each(selection, (t) => {
|
|
253
|
-
each(selectingClassAry, (cls) => {
|
|
254
|
-
t.classList.toggle(cls, false);
|
|
255
|
-
});
|
|
256
|
-
each(selectedClassAry, (cls) => {
|
|
257
|
-
t.classList.toggle(cls, true);
|
|
258
|
-
});
|
|
259
|
-
t.classList.toggle(CLASS_SELECTING, false);
|
|
260
|
-
t.classList.toggle(CLASS_SELECTED, true);
|
|
261
|
-
});
|
|
262
|
-
__classPrivateFieldSet(this, _Selectable__lastSelected, selection, "f");
|
|
263
|
-
if (dragging && onEnd)
|
|
264
|
-
onEnd({ selection, selectable: con }, ev);
|
|
265
|
-
};
|
|
266
|
-
document.addEventListener("mousemove", dragListener, false);
|
|
267
|
-
document.addEventListener("mouseup", dragEndListener, false);
|
|
268
|
-
window.addEventListener("blur", dragEndListener, false);
|
|
269
|
-
e.preventDefault();
|
|
270
|
-
return false;
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
/**
|
|
274
|
-
* Add a selector into the container
|
|
275
|
-
* @param container css selector or html element
|
|
276
|
-
* @param opts
|
|
277
|
-
* @returns
|
|
278
|
-
*/
|
|
279
|
-
export function newSelectable(container, opts) {
|
|
280
|
-
return new Selectable(container, opts);
|
|
281
|
-
}
|