aio-class 2.0.3 → 2.0.5
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/index.d.ts +149 -1
- package/index.js +407 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="jquery" />
|
|
2
|
+
/// <reference types="jquery" />
|
|
1
3
|
import { AIOGeo } from 'aio-geo';
|
|
2
4
|
import AIODate from 'aio-date';
|
|
3
5
|
export { AIOGeo, AIODate };
|
|
@@ -76,7 +78,7 @@ export declare const ArrayToObject: <T>(keys: T[], fn: (key: T) => any) => any;
|
|
|
76
78
|
export declare const TextFilter: (p: {
|
|
77
79
|
value: string | number;
|
|
78
80
|
chars?: {
|
|
79
|
-
[key: string]: boolean
|
|
81
|
+
[key: string]: boolean;
|
|
80
82
|
};
|
|
81
83
|
number?: boolean;
|
|
82
84
|
symbol?: boolean;
|
|
@@ -277,3 +279,149 @@ export declare const getGroupedTree: <T>(rows: T[], getGroups: (row: T, level: n
|
|
|
277
279
|
parentRow: any;
|
|
278
280
|
childsField: string;
|
|
279
281
|
}) => any;
|
|
282
|
+
export type I_Swip_mousePosition = {
|
|
283
|
+
x: number;
|
|
284
|
+
y: number;
|
|
285
|
+
xp: number;
|
|
286
|
+
yp: number;
|
|
287
|
+
clientX: number;
|
|
288
|
+
clientY: number;
|
|
289
|
+
centerAngle: number;
|
|
290
|
+
centerDistance: number;
|
|
291
|
+
};
|
|
292
|
+
export type I_Swip_change = {
|
|
293
|
+
x: number;
|
|
294
|
+
y: number;
|
|
295
|
+
dx: number;
|
|
296
|
+
dy: number;
|
|
297
|
+
dist: number;
|
|
298
|
+
angle: number;
|
|
299
|
+
deltaCenterAngle: number;
|
|
300
|
+
dir?: 'h' | 'v';
|
|
301
|
+
};
|
|
302
|
+
export type I_Swip_parameter = {
|
|
303
|
+
change: I_Swip_change;
|
|
304
|
+
mousePosition: I_Swip_mousePosition;
|
|
305
|
+
domLimit: I_Swip_domLimit;
|
|
306
|
+
parentLimit: I_Swip_domLimit;
|
|
307
|
+
event: any;
|
|
308
|
+
selectRect?: I_Swip_selectRect;
|
|
309
|
+
isInSelectRect?: I_Swip_isInSelectRect;
|
|
310
|
+
index: number | false;
|
|
311
|
+
setTemp: (v: any) => void;
|
|
312
|
+
getTemp: () => any;
|
|
313
|
+
};
|
|
314
|
+
type I_Swip_selectRect_config = {
|
|
315
|
+
color?: string;
|
|
316
|
+
enable: () => boolean;
|
|
317
|
+
};
|
|
318
|
+
export type I_Swip = {
|
|
319
|
+
dom: I_Swip_dom;
|
|
320
|
+
parentDom?: I_Swip_dom;
|
|
321
|
+
childIndexAttr?: string;
|
|
322
|
+
onClick?: (p: I_Swip_parameter) => void;
|
|
323
|
+
page?: () => any;
|
|
324
|
+
start?: (p: I_Swip_parameter) => number[] | false | undefined;
|
|
325
|
+
move?: (p: I_Swip_parameter) => void;
|
|
326
|
+
end?: (p: I_Swip_parameter) => void;
|
|
327
|
+
selectRect?: I_Swip_selectRect_config;
|
|
328
|
+
speedX?: number;
|
|
329
|
+
speedY?: number;
|
|
330
|
+
stepX?: number | boolean;
|
|
331
|
+
stepY?: number | boolean;
|
|
332
|
+
reverseY?: boolean;
|
|
333
|
+
reverseX?: boolean;
|
|
334
|
+
minY?: number;
|
|
335
|
+
maxY?: number;
|
|
336
|
+
minX?: number;
|
|
337
|
+
maxX?: number;
|
|
338
|
+
insideX?: boolean;
|
|
339
|
+
insideY?: boolean;
|
|
340
|
+
maxCenterDistance?: number;
|
|
341
|
+
};
|
|
342
|
+
export type I_Swip_domLimit = {
|
|
343
|
+
width: number;
|
|
344
|
+
height: number;
|
|
345
|
+
left: number;
|
|
346
|
+
top: number;
|
|
347
|
+
centerX: number;
|
|
348
|
+
centerY: number;
|
|
349
|
+
right: number;
|
|
350
|
+
bottom: number;
|
|
351
|
+
};
|
|
352
|
+
type I_Swip_isInSelectRect = (x: number, y: number) => boolean;
|
|
353
|
+
type I_Swip_getIsInSelectrect = (selectRect: I_Swip_selectRect) => I_Swip_isInSelectRect;
|
|
354
|
+
export type I_Swip_selectRect = {
|
|
355
|
+
left: number;
|
|
356
|
+
top: number;
|
|
357
|
+
width: number;
|
|
358
|
+
height: number;
|
|
359
|
+
};
|
|
360
|
+
export type I_Swip_tempSelectRect = {
|
|
361
|
+
left: number;
|
|
362
|
+
top: number;
|
|
363
|
+
};
|
|
364
|
+
type I_Swip_dom = HTMLElement | JQuery | {
|
|
365
|
+
current: HTMLElement | null;
|
|
366
|
+
} | string;
|
|
367
|
+
export declare class Swip {
|
|
368
|
+
p: I_Swip;
|
|
369
|
+
geo: AIOGeo;
|
|
370
|
+
defaultLimit: I_Swip_domLimit;
|
|
371
|
+
timeout: any;
|
|
372
|
+
updateDomTimeout: any;
|
|
373
|
+
count: number;
|
|
374
|
+
domLimit: I_Swip_domLimit;
|
|
375
|
+
parentLimit: I_Swip_domLimit;
|
|
376
|
+
dist: number;
|
|
377
|
+
change: I_Swip_change;
|
|
378
|
+
isMoving: boolean;
|
|
379
|
+
centerAngle: number;
|
|
380
|
+
selectRect?: I_Swip_selectRect_config;
|
|
381
|
+
defaultChange: I_Swip_change;
|
|
382
|
+
dx: number;
|
|
383
|
+
dy: number;
|
|
384
|
+
cx: number;
|
|
385
|
+
cy: number;
|
|
386
|
+
index: number | false;
|
|
387
|
+
so: {
|
|
388
|
+
client?: {
|
|
389
|
+
x: number;
|
|
390
|
+
y: number;
|
|
391
|
+
};
|
|
392
|
+
x?: number;
|
|
393
|
+
y?: number;
|
|
394
|
+
sr?: I_Swip_selectRect;
|
|
395
|
+
tsr?: I_Swip_tempSelectRect;
|
|
396
|
+
};
|
|
397
|
+
senseDir: false | 'h' | 'v';
|
|
398
|
+
sentMove?: string;
|
|
399
|
+
boundDom?: HTMLElement;
|
|
400
|
+
domObserver?: MutationObserver;
|
|
401
|
+
dom?: HTMLElement;
|
|
402
|
+
parentDom?: HTMLElement;
|
|
403
|
+
private temp;
|
|
404
|
+
constructor(p: I_Swip);
|
|
405
|
+
setTemp: (temp: any) => any;
|
|
406
|
+
getTemp: () => any;
|
|
407
|
+
updateLimit: () => void;
|
|
408
|
+
updateDom: (tryIndex?: number) => void;
|
|
409
|
+
resolveDom: (dom: I_Swip_dom) => HTMLElement | undefined;
|
|
410
|
+
bind: (dom: HTMLElement) => void;
|
|
411
|
+
unbind: () => void;
|
|
412
|
+
init: () => void;
|
|
413
|
+
getPercentByValue: (value: number, start: number, end: number) => number;
|
|
414
|
+
getPage: () => any;
|
|
415
|
+
getMousePosition: (e: any) => I_Swip_mousePosition;
|
|
416
|
+
getDOMLimit: (type: 'dom' | 'parent') => I_Swip_domLimit;
|
|
417
|
+
changeIsMoving: (moving: boolean) => void;
|
|
418
|
+
updateIndex: (e: any) => void;
|
|
419
|
+
click: (e: any) => void;
|
|
420
|
+
mouseDown: (e: any) => void;
|
|
421
|
+
mouseMove: (e: any) => void;
|
|
422
|
+
mouseUp: (e: any) => void;
|
|
423
|
+
getIsInSelectRect: I_Swip_getIsInSelectrect;
|
|
424
|
+
addSelectRect: (left: number, top: number) => void;
|
|
425
|
+
setSelectRect: (width: number, height: number) => void;
|
|
426
|
+
removeSelectRect: () => void;
|
|
427
|
+
}
|
package/index.js
CHANGED
|
@@ -242,7 +242,7 @@ export const EventHandler = (selector, event, action, type = 'bind') => {
|
|
|
242
242
|
element.addEventListener(fixedEvent, action);
|
|
243
243
|
}
|
|
244
244
|
};
|
|
245
|
-
export const Stall = (
|
|
245
|
+
export const Stall = (stallTime = 3000) => __awaiter(void 0, void 0, void 0, function* () { return yield new Promise(resolve => setTimeout(resolve, stallTime)); });
|
|
246
246
|
export const DetectOS = () => {
|
|
247
247
|
const userAgent = window.navigator.userAgent;
|
|
248
248
|
const platform = window.navigator.platform;
|
|
@@ -2061,3 +2061,409 @@ export const getGroupedTree = (rows, getGroups) => {
|
|
|
2061
2061
|
}
|
|
2062
2062
|
return res;
|
|
2063
2063
|
};
|
|
2064
|
+
export class Swip {
|
|
2065
|
+
constructor(p) {
|
|
2066
|
+
this.geo = new AIOGeo();
|
|
2067
|
+
this.defaultLimit = { width: 0, height: 0, left: 0, top: 0, right: 0, bottom: 0, centerX: 0, centerY: 0 };
|
|
2068
|
+
this.timeout = undefined;
|
|
2069
|
+
this.updateDomTimeout = undefined;
|
|
2070
|
+
this.count = 0;
|
|
2071
|
+
this.domLimit = this.defaultLimit;
|
|
2072
|
+
this.parentLimit = this.defaultLimit;
|
|
2073
|
+
this.dist = 0;
|
|
2074
|
+
this.change = { x: 0, y: 0, dx: 0, dy: 0, dist: 0, angle: 0, deltaCenterAngle: 0 };
|
|
2075
|
+
this.isMoving = false;
|
|
2076
|
+
this.centerAngle = 0;
|
|
2077
|
+
this.defaultChange = { x: 0, y: 0, dx: 0, dy: 0, dist: 0, angle: 0, deltaCenterAngle: 0 };
|
|
2078
|
+
this.dx = 0;
|
|
2079
|
+
this.dy = 0;
|
|
2080
|
+
this.cx = 0;
|
|
2081
|
+
this.cy = 0;
|
|
2082
|
+
this.index = false;
|
|
2083
|
+
this.so = {};
|
|
2084
|
+
this.senseDir = false;
|
|
2085
|
+
this.temp = {};
|
|
2086
|
+
this.setTemp = (temp) => this.temp = JSON.parse(JSON.stringify(temp));
|
|
2087
|
+
this.getTemp = () => this.temp;
|
|
2088
|
+
this.updateLimit = () => {
|
|
2089
|
+
this.domLimit = this.getDOMLimit('dom');
|
|
2090
|
+
this.parentLimit = this.p.parentDom ? this.getDOMLimit('parent') : this.defaultLimit;
|
|
2091
|
+
};
|
|
2092
|
+
this.updateDom = (tryIndex) => {
|
|
2093
|
+
const dom = this.resolveDom(this.p.dom);
|
|
2094
|
+
if (dom) {
|
|
2095
|
+
clearTimeout(this.updateDomTimeout);
|
|
2096
|
+
const parentDom = this.p.parentDom ? this.resolveDom(this.p.parentDom) : undefined;
|
|
2097
|
+
this.dom = dom;
|
|
2098
|
+
this.parentDom = parentDom;
|
|
2099
|
+
this.bind(this.dom);
|
|
2100
|
+
}
|
|
2101
|
+
else if (tryIndex !== undefined && tryIndex < 50) {
|
|
2102
|
+
this.updateDomTimeout = setTimeout(() => this.updateDom(tryIndex + 1), 150);
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
this.resolveDom = (dom) => {
|
|
2106
|
+
if (typeof dom === 'string') {
|
|
2107
|
+
return document.querySelector(dom) || undefined;
|
|
2108
|
+
}
|
|
2109
|
+
if (dom instanceof HTMLElement) {
|
|
2110
|
+
return dom;
|
|
2111
|
+
}
|
|
2112
|
+
return undefined;
|
|
2113
|
+
};
|
|
2114
|
+
this.bind = (dom) => {
|
|
2115
|
+
this.unbind();
|
|
2116
|
+
this.dom = dom;
|
|
2117
|
+
const touch = IsTouch();
|
|
2118
|
+
dom.addEventListener(touch ? 'touchstart' : 'mousedown', this.mouseDown);
|
|
2119
|
+
};
|
|
2120
|
+
this.unbind = () => {
|
|
2121
|
+
if (!this.dom) {
|
|
2122
|
+
return;
|
|
2123
|
+
}
|
|
2124
|
+
const touch = IsTouch();
|
|
2125
|
+
this.dom.removeEventListener(touch ? 'touchstart' : 'mousedown', this.mouseDown);
|
|
2126
|
+
this.dom = undefined;
|
|
2127
|
+
};
|
|
2128
|
+
this.init = () => {
|
|
2129
|
+
this.updateDom(0);
|
|
2130
|
+
};
|
|
2131
|
+
this.getPercentByValue = (value, start, end) => { return 100 * (value - start) / (end - start); };
|
|
2132
|
+
this.getPage = () => {
|
|
2133
|
+
const { page } = this.p;
|
|
2134
|
+
return page ? page() : window;
|
|
2135
|
+
};
|
|
2136
|
+
this.getMousePosition = (e) => {
|
|
2137
|
+
let { left, top, centerX, centerY, width, height } = this.domLimit;
|
|
2138
|
+
const page = this.getPage();
|
|
2139
|
+
const client = GetClient(e);
|
|
2140
|
+
const scrollLeft = page instanceof Window ? window.scrollX : page.scrollLeft;
|
|
2141
|
+
const scrollTop = page instanceof Window ? window.scrollY : page.scrollTop;
|
|
2142
|
+
let x = client.x - left + scrollLeft;
|
|
2143
|
+
let y = client.y - top + scrollTop;
|
|
2144
|
+
const line = [[centerX, centerY], [client.x, client.y]];
|
|
2145
|
+
let centerAngle = this.geo.getAngle(line);
|
|
2146
|
+
const centerDistance = this.geo.getLength(line);
|
|
2147
|
+
if (this.p.maxCenterDistance && centerDistance > this.p.maxCenterDistance) {
|
|
2148
|
+
const center = [width / 2, height / 2];
|
|
2149
|
+
const [newX, newY] = this.geo.getLineBySLA(center, this.p.maxCenterDistance, centerAngle)[1];
|
|
2150
|
+
x = newX;
|
|
2151
|
+
y = newY;
|
|
2152
|
+
}
|
|
2153
|
+
return {
|
|
2154
|
+
clientX: client.x, clientY: client.y, x, y, centerAngle, centerDistance,
|
|
2155
|
+
xp: this.getPercentByValue(x, 0, width), yp: this.getPercentByValue(y, 0, height)
|
|
2156
|
+
};
|
|
2157
|
+
};
|
|
2158
|
+
this.getDOMLimit = (type) => {
|
|
2159
|
+
let dom;
|
|
2160
|
+
if (type === 'parent') {
|
|
2161
|
+
if (!this.p.parentDom) {
|
|
2162
|
+
return this.defaultLimit;
|
|
2163
|
+
}
|
|
2164
|
+
dom = this.resolveDom(this.p.parentDom);
|
|
2165
|
+
}
|
|
2166
|
+
else {
|
|
2167
|
+
dom = this.resolveDom(this.p.dom);
|
|
2168
|
+
}
|
|
2169
|
+
if (!dom) {
|
|
2170
|
+
return this.defaultLimit;
|
|
2171
|
+
}
|
|
2172
|
+
const rect = dom.getBoundingClientRect();
|
|
2173
|
+
return {
|
|
2174
|
+
width: rect.width,
|
|
2175
|
+
height: rect.height,
|
|
2176
|
+
left: rect.left,
|
|
2177
|
+
top: rect.top,
|
|
2178
|
+
centerX: rect.left + rect.width / 2,
|
|
2179
|
+
centerY: rect.top + rect.height / 2,
|
|
2180
|
+
right: rect.right,
|
|
2181
|
+
bottom: rect.bottom
|
|
2182
|
+
};
|
|
2183
|
+
};
|
|
2184
|
+
this.changeIsMoving = (moving) => {
|
|
2185
|
+
this.isMoving = moving;
|
|
2186
|
+
};
|
|
2187
|
+
this.updateIndex = (e) => {
|
|
2188
|
+
var _a;
|
|
2189
|
+
if (!this.p.childIndexAttr) {
|
|
2190
|
+
this.index = false;
|
|
2191
|
+
}
|
|
2192
|
+
else {
|
|
2193
|
+
const target = e.target;
|
|
2194
|
+
if (!(target instanceof Element)) {
|
|
2195
|
+
this.index = false;
|
|
2196
|
+
}
|
|
2197
|
+
const item = target.closest(`[${this.p.childIndexAttr}]`);
|
|
2198
|
+
if (!item || !((_a = this.dom) === null || _a === void 0 ? void 0 : _a.contains(item))) {
|
|
2199
|
+
this.index = false;
|
|
2200
|
+
}
|
|
2201
|
+
else {
|
|
2202
|
+
let index = item.getAttribute(this.p.childIndexAttr);
|
|
2203
|
+
if (index !== null) {
|
|
2204
|
+
this.index = Number(index);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
};
|
|
2209
|
+
this.click = (e) => {
|
|
2210
|
+
if (!this.p.onClick) {
|
|
2211
|
+
return;
|
|
2212
|
+
}
|
|
2213
|
+
this.updateLimit();
|
|
2214
|
+
let mousePosition = this.getMousePosition(e);
|
|
2215
|
+
this.updateIndex(e);
|
|
2216
|
+
let clickParams = {
|
|
2217
|
+
mousePosition, domLimit: this.domLimit, parentLimit: this.parentLimit, event: e,
|
|
2218
|
+
change: this.defaultChange, index: this.index, setTemp: this.setTemp, getTemp: this.getTemp
|
|
2219
|
+
};
|
|
2220
|
+
if (this.p.onClick) {
|
|
2221
|
+
this.p.onClick(clickParams);
|
|
2222
|
+
}
|
|
2223
|
+
};
|
|
2224
|
+
this.mouseDown = (e) => {
|
|
2225
|
+
e.stopPropagation();
|
|
2226
|
+
this.updateIndex(e);
|
|
2227
|
+
this.changeIsMoving(false);
|
|
2228
|
+
this.updateLimit();
|
|
2229
|
+
let mousePosition = this.getMousePosition(e);
|
|
2230
|
+
this.centerAngle = mousePosition.centerAngle;
|
|
2231
|
+
this.cx = mousePosition.clientX;
|
|
2232
|
+
this.cy = mousePosition.clientY;
|
|
2233
|
+
this.so = {
|
|
2234
|
+
client: { x: mousePosition.clientX, y: mousePosition.clientY }
|
|
2235
|
+
};
|
|
2236
|
+
this.addSelectRect(mousePosition.x, mousePosition.y);
|
|
2237
|
+
let startParams = { index: this.index, mousePosition, domLimit: this.domLimit, parentLimit: this.parentLimit, event: e, change: this.defaultChange, setTemp: this.setTemp, getTemp: this.getTemp };
|
|
2238
|
+
let res = (this.p.start || (() => [0, 0]))(startParams);
|
|
2239
|
+
if (res === false) {
|
|
2240
|
+
return;
|
|
2241
|
+
}
|
|
2242
|
+
if (!Array.isArray(res)) {
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2245
|
+
let x = res[0], y = res[1];
|
|
2246
|
+
this.so = Object.assign(Object.assign({}, this.so), { x, y });
|
|
2247
|
+
this.senseDir = false;
|
|
2248
|
+
EventHandler('window', 'mousemove', this.mouseMove);
|
|
2249
|
+
EventHandler('window', 'mouseup', this.mouseUp);
|
|
2250
|
+
};
|
|
2251
|
+
this.mouseMove = (e) => {
|
|
2252
|
+
e.stopPropagation();
|
|
2253
|
+
let { speedX = 1, speedY = 1, stepX = 1, stepY = 1, reverseX, reverseY, insideX, insideY } = this.p;
|
|
2254
|
+
let mousePosition = this.getMousePosition(e), client = GetClient(e);
|
|
2255
|
+
let dx = client.x - this.cx, dy = client.y - this.cy;
|
|
2256
|
+
dx = Math.round(dx * speedX) * (reverseX ? -1 : 1);
|
|
2257
|
+
dy = Math.round(dy * speedY) * (reverseY ? -1 : 1);
|
|
2258
|
+
let deltaCenterAngle = mousePosition.centerAngle - this.centerAngle;
|
|
2259
|
+
//if(deltaCenterAngle < 0){deltaCenterAngle += 360}
|
|
2260
|
+
if (typeof stepX === 'number') {
|
|
2261
|
+
dx = Math.round(dx / stepX) * stepX;
|
|
2262
|
+
}
|
|
2263
|
+
if (typeof stepY === 'number') {
|
|
2264
|
+
dy = Math.round(dy / stepY) * stepY;
|
|
2265
|
+
}
|
|
2266
|
+
if (dx === this.dx && dy === this.dy) {
|
|
2267
|
+
return;
|
|
2268
|
+
}
|
|
2269
|
+
const dist = Math.round(Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)));
|
|
2270
|
+
//if (!this.isMoving) { return }
|
|
2271
|
+
this.changeIsMoving(true);
|
|
2272
|
+
this.dx = dx;
|
|
2273
|
+
this.dy = dy;
|
|
2274
|
+
this.dist = dist;
|
|
2275
|
+
let angle = this.geo.getAngle([[this.cx, this.cy], [client.x, client.y]]);
|
|
2276
|
+
this.setSelectRect(dx, dy);
|
|
2277
|
+
let x = 0, y = 0;
|
|
2278
|
+
if (this.so.x !== undefined && this.so.y !== undefined) {
|
|
2279
|
+
x = this.so.x + dx;
|
|
2280
|
+
y = this.so.y + dy;
|
|
2281
|
+
let { minX, minY, maxX, maxY } = this.p;
|
|
2282
|
+
if (minX !== undefined && x < minX) {
|
|
2283
|
+
x = minX;
|
|
2284
|
+
}
|
|
2285
|
+
if (maxX !== undefined && x > maxX) {
|
|
2286
|
+
x = maxX;
|
|
2287
|
+
}
|
|
2288
|
+
if (minY !== undefined && y < minY) {
|
|
2289
|
+
y = minY;
|
|
2290
|
+
}
|
|
2291
|
+
if (maxY !== undefined && y > maxY) {
|
|
2292
|
+
y = maxY;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
if (stepX === true) {
|
|
2296
|
+
x = Math.round(x / this.domLimit.width) * this.domLimit.width;
|
|
2297
|
+
}
|
|
2298
|
+
if (stepY === true) {
|
|
2299
|
+
y = Math.round(y / this.domLimit.height) * this.domLimit.height;
|
|
2300
|
+
}
|
|
2301
|
+
if (insideX) {
|
|
2302
|
+
if (this.parentLimit) {
|
|
2303
|
+
if (x > this.parentLimit.width - this.domLimit.width) {
|
|
2304
|
+
x = this.parentLimit.width - this.domLimit.width;
|
|
2305
|
+
}
|
|
2306
|
+
if (x < 0) {
|
|
2307
|
+
x = 0;
|
|
2308
|
+
}
|
|
2309
|
+
}
|
|
2310
|
+
else {
|
|
2311
|
+
alert('Swip error => you set insideX prop but missing parent props');
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
if (insideY) {
|
|
2315
|
+
if (this.parentLimit) {
|
|
2316
|
+
if (y > this.parentLimit.height - this.domLimit.height) {
|
|
2317
|
+
y = this.parentLimit.height - this.domLimit.height;
|
|
2318
|
+
}
|
|
2319
|
+
if (y < 0) {
|
|
2320
|
+
y = 0;
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
else {
|
|
2324
|
+
alert('Swip error => you set insideY prop but missing parent props');
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2327
|
+
this.change = { x, y, dx, dy, dist: this.dist, angle, deltaCenterAngle, dir: this.senseDir === false ? undefined : this.senseDir };
|
|
2328
|
+
if (this.senseDir === false) {
|
|
2329
|
+
const dist = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
|
|
2330
|
+
if (dist > 8) {
|
|
2331
|
+
if (Math.abs(dx) > Math.abs(dy)) {
|
|
2332
|
+
this.senseDir = 'h';
|
|
2333
|
+
}
|
|
2334
|
+
else {
|
|
2335
|
+
this.senseDir = 'v';
|
|
2336
|
+
}
|
|
2337
|
+
this.change.dir = this.senseDir;
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
let p = {
|
|
2341
|
+
index: this.index,
|
|
2342
|
+
change: this.change,
|
|
2343
|
+
mousePosition,
|
|
2344
|
+
domLimit: this.domLimit,
|
|
2345
|
+
parentLimit: this.parentLimit,
|
|
2346
|
+
event: e,
|
|
2347
|
+
selectRect: this.so.sr, setTemp: this.setTemp, getTemp: this.getTemp,
|
|
2348
|
+
isInSelectRect: this.getIsInSelectRect(this.so.sr || { left: 0, top: 0, width: 0, height: 0 })
|
|
2349
|
+
};
|
|
2350
|
+
if (this.p.move) {
|
|
2351
|
+
if (!this.sentMove) {
|
|
2352
|
+
this.sentMove = JSON.stringify(this.change);
|
|
2353
|
+
}
|
|
2354
|
+
else if (JSON.stringify(this.change) !== this.sentMove) {
|
|
2355
|
+
this.p.move(p);
|
|
2356
|
+
}
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
this.mouseUp = (e) => {
|
|
2360
|
+
e.stopPropagation();
|
|
2361
|
+
this.senseDir = false;
|
|
2362
|
+
EventHandler('window', 'mousemove', this.mouseMove, 'unbind');
|
|
2363
|
+
EventHandler('window', 'mouseup', this.mouseUp, 'unbind');
|
|
2364
|
+
//chon click bad az mouseUp call mishe mouseUp isMoving ro zoodtar false mikone (pas nemitoone jeloye click bad az harekat ro begire), pas bayad in amal ba yek vaghfe anjam beshe
|
|
2365
|
+
//jeloye clicke bad az harekat ro migirim ta bad az drag kardan function click call nashe
|
|
2366
|
+
let mousePosition = this.getMousePosition(e);
|
|
2367
|
+
this.removeSelectRect();
|
|
2368
|
+
let p = {
|
|
2369
|
+
index: this.index,
|
|
2370
|
+
change: this.change,
|
|
2371
|
+
event: e,
|
|
2372
|
+
domLimit: this.domLimit,
|
|
2373
|
+
parentLimit: this.parentLimit,
|
|
2374
|
+
mousePosition,
|
|
2375
|
+
selectRect: this.so.sr, setTemp: this.setTemp, getTemp: this.getTemp,
|
|
2376
|
+
isInSelectRect: this.getIsInSelectRect(this.so.sr || { left: 0, top: 0, width: 0, height: 0 })
|
|
2377
|
+
};
|
|
2378
|
+
if (this.isMoving) {
|
|
2379
|
+
if (this.p.end) {
|
|
2380
|
+
this.p.end(p);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
else {
|
|
2384
|
+
this.click(e);
|
|
2385
|
+
}
|
|
2386
|
+
this.changeIsMoving(false);
|
|
2387
|
+
};
|
|
2388
|
+
this.getIsInSelectRect = (selectRect) => {
|
|
2389
|
+
let { left, top, width, height } = selectRect;
|
|
2390
|
+
return (x, y) => {
|
|
2391
|
+
if (x < left) {
|
|
2392
|
+
return false;
|
|
2393
|
+
}
|
|
2394
|
+
if (y < top) {
|
|
2395
|
+
return false;
|
|
2396
|
+
}
|
|
2397
|
+
if (x > left + width) {
|
|
2398
|
+
return false;
|
|
2399
|
+
}
|
|
2400
|
+
if (y > top + height) {
|
|
2401
|
+
return false;
|
|
2402
|
+
}
|
|
2403
|
+
return true;
|
|
2404
|
+
};
|
|
2405
|
+
};
|
|
2406
|
+
this.addSelectRect = (left, top) => {
|
|
2407
|
+
if (!this.selectRect || !this.selectRect.enable()) {
|
|
2408
|
+
return;
|
|
2409
|
+
}
|
|
2410
|
+
this.updateDom();
|
|
2411
|
+
if (!this.dom) {
|
|
2412
|
+
return;
|
|
2413
|
+
}
|
|
2414
|
+
const { color } = this.selectRect;
|
|
2415
|
+
this.so.tsr = { left, top };
|
|
2416
|
+
this.removeSelectRect();
|
|
2417
|
+
const rect = document.createElement('div');
|
|
2418
|
+
rect.className = 'swip-select-rect';
|
|
2419
|
+
rect.style.border = `1px dashed ${color}`;
|
|
2420
|
+
rect.style.background = `${color}30`;
|
|
2421
|
+
rect.style.left = `${left}px`;
|
|
2422
|
+
rect.style.top = `${top}px`;
|
|
2423
|
+
rect.style.position = 'absolute';
|
|
2424
|
+
rect.style.width = '0px';
|
|
2425
|
+
rect.style.height = '0px';
|
|
2426
|
+
this.dom.appendChild(rect);
|
|
2427
|
+
};
|
|
2428
|
+
this.setSelectRect = (width, height) => {
|
|
2429
|
+
if (!this.selectRect || !this.selectRect.enable() || !this.dom) {
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2432
|
+
const SR = this.dom.querySelector('.swip-select-rect');
|
|
2433
|
+
if (!SR) {
|
|
2434
|
+
return;
|
|
2435
|
+
}
|
|
2436
|
+
let { tsr = { left: 0, top: 0 } } = this.so || {};
|
|
2437
|
+
let left = tsr.left;
|
|
2438
|
+
let top = tsr.top;
|
|
2439
|
+
if (width < 0) {
|
|
2440
|
+
left += width;
|
|
2441
|
+
width = Math.abs(width);
|
|
2442
|
+
}
|
|
2443
|
+
if (height < 0) {
|
|
2444
|
+
top += height;
|
|
2445
|
+
height = Math.abs(height);
|
|
2446
|
+
}
|
|
2447
|
+
const newSelectRect = { left, top, width, height };
|
|
2448
|
+
this.so.sr = newSelectRect;
|
|
2449
|
+
SR.style.left = `${left}px`;
|
|
2450
|
+
SR.style.top = `${top}px`;
|
|
2451
|
+
SR.style.width = `${width}px`;
|
|
2452
|
+
SR.style.height = `${height}px`;
|
|
2453
|
+
};
|
|
2454
|
+
this.removeSelectRect = () => {
|
|
2455
|
+
if (!this.selectRect || !this.selectRect.enable() || !this.dom) {
|
|
2456
|
+
return;
|
|
2457
|
+
}
|
|
2458
|
+
const selectRect = this.dom.querySelector('.swip-select-rect');
|
|
2459
|
+
selectRect === null || selectRect === void 0 ? void 0 : selectRect.remove();
|
|
2460
|
+
};
|
|
2461
|
+
let { selectRect } = p;
|
|
2462
|
+
if (selectRect) {
|
|
2463
|
+
let { color = '#96a9bc' } = selectRect;
|
|
2464
|
+
this.selectRect = Object.assign(Object.assign({}, selectRect), { color });
|
|
2465
|
+
}
|
|
2466
|
+
this.p = p;
|
|
2467
|
+
this.init();
|
|
2468
|
+
}
|
|
2469
|
+
}
|