dragselect 3.0.1 → 3.0.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 +5 -1
- package/dist/DragSelect.d.ts +877 -0
- package/dist/DragSelect.esm.js +2597 -0
- package/dist/DragSelect.js +2605 -0
- package/dist/ds.esm.min.js +1 -0
- package/dist/ds.min.js +1 -0
- package/package.json +9 -1
- package/deployment.md +0 -33
- package/jest-puppeteer.config.js +0 -16
- package/jest.config.js +0 -10
- package/rollup.config.mjs +0 -82
- package/src/DragSelect.ts +0 -425
- package/src/methods/addModificationObservers.ts +0 -51
- package/src/methods/canScroll.ts +0 -19
- package/src/methods/createSelectorAreaElement.ts +0 -8
- package/src/methods/createSelectorElement.ts +0 -13
- package/src/methods/debounce.ts +0 -31
- package/src/methods/ensureArray.ts +0 -13
- package/src/methods/getAllParentNodes.ts +0 -15
- package/src/methods/getAreaRect.ts +0 -27
- package/src/methods/getCurrentScroll.ts +0 -14
- package/src/methods/getDocumentScroll.ts +0 -5
- package/src/methods/getOverflowEdges.ts +0 -27
- package/src/methods/getPointerPos.ts +0 -9
- package/src/methods/getSelectionRect.ts +0 -29
- package/src/methods/getSelectorPosition.ts +0 -74
- package/src/methods/getStylePosition.spec.ts +0 -114
- package/src/methods/getStylePosition.ts +0 -83
- package/src/methods/handleElementPositionAttribute.ts +0 -15
- package/src/methods/handleKeyboardDragPosDifference.ts +0 -35
- package/src/methods/handleSelection.ts +0 -26
- package/src/methods/handleUnSelection.ts +0 -36
- package/src/methods/hydrateSettings.ts +0 -245
- package/src/methods/isCollision.ts +0 -66
- package/src/methods/limitDirection.ts +0 -36
- package/src/methods/moveElement.ts +0 -18
- package/src/methods/scrollElement.ts +0 -26
- package/src/methods/setStylePosition.ts +0 -16
- package/src/methods/subscriberAliases.ts +0 -240
- package/src/methods/updateElementStylePos.ts +0 -7
- package/src/methods/vect2.ts +0 -34
- package/src/modules/Area.ts +0 -169
- package/src/modules/Drag.ts +0 -236
- package/src/modules/DropZone.ts +0 -223
- package/src/modules/DropZones.ts +0 -151
- package/src/modules/Interaction.ts +0 -251
- package/src/modules/PubSub.ts +0 -111
- package/src/modules/SelectableSet.ts +0 -146
- package/src/modules/SelectedSet.ts +0 -92
- package/src/modules/Selection.ts +0 -133
- package/src/modules/Selector.ts +0 -81
- package/src/modules/SelectorArea.ts +0 -161
- package/src/stores/KeyStore.ts +0 -92
- package/src/stores/PointerStore.ts +0 -194
- package/src/stores/ScrollStore.ts +0 -87
- package/src/stores/SettingsStore.ts +0 -88
- package/src/types.ts +0 -158
- package/tsconfig.json +0 -105
|
@@ -0,0 +1,877 @@
|
|
|
1
|
+
type DSDropZone<E extends DSInputElement> = {
|
|
2
|
+
id: string;
|
|
3
|
+
element: E;
|
|
4
|
+
droppables: E[];
|
|
5
|
+
/** items related to the target zone */
|
|
6
|
+
itemsDropped?: E[];
|
|
7
|
+
/** items that are within the targets bounds */
|
|
8
|
+
itemsInside?: E[];
|
|
9
|
+
};
|
|
10
|
+
declare class DropZone<E extends DSInputElement> {
|
|
11
|
+
id: string;
|
|
12
|
+
element: E;
|
|
13
|
+
private _droppables?;
|
|
14
|
+
private _rect?;
|
|
15
|
+
private _observers?;
|
|
16
|
+
private _timeout?;
|
|
17
|
+
private _itemsDropped;
|
|
18
|
+
private _itemsInside?;
|
|
19
|
+
private DS;
|
|
20
|
+
private PS;
|
|
21
|
+
private Settings;
|
|
22
|
+
private isDestroyed;
|
|
23
|
+
private _parentNodes?;
|
|
24
|
+
constructor({ DS, PS, id, element, droppables, }: {
|
|
25
|
+
DS: DragSelect<E>;
|
|
26
|
+
PS: PubSub<E>;
|
|
27
|
+
id: string;
|
|
28
|
+
element: E;
|
|
29
|
+
droppables?: E[];
|
|
30
|
+
});
|
|
31
|
+
private setReadyClasses;
|
|
32
|
+
/** This zone is NOT the target of a drop */
|
|
33
|
+
handleNoDrop: () => void;
|
|
34
|
+
/** This zone IS the target of a drop */
|
|
35
|
+
handleDrop: () => void;
|
|
36
|
+
handleItemsInsideClasses: () => void;
|
|
37
|
+
private start;
|
|
38
|
+
private stop;
|
|
39
|
+
destroy(): void;
|
|
40
|
+
toObject: () => DSDropZone<E>;
|
|
41
|
+
get rect(): DOMRect | undefined;
|
|
42
|
+
get itemsDropped(): E[] | undefined;
|
|
43
|
+
get itemsInside(): E[] | undefined;
|
|
44
|
+
private get parentNodes();
|
|
45
|
+
get droppables(): E[];
|
|
46
|
+
private set droppables(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type DSInteractionPublishEventNames = 'Interaction:init:pre' | 'Interaction:init' | 'Interaction:start:pre' | 'Interaction:start' | 'Interaction:update:pre' | 'Interaction:update' | 'Interaction:end:pre' | 'Interaction:end';
|
|
50
|
+
type DSInteractionPublishEventData = {
|
|
51
|
+
event: InteractionEvent | KeyboardEvent;
|
|
52
|
+
/** Whether the interaction is a drag or a select */
|
|
53
|
+
isDragging: boolean;
|
|
54
|
+
/** Whether or not the drag interaction is via keyboard */
|
|
55
|
+
isDraggingKeyboard?: boolean;
|
|
56
|
+
key?: string;
|
|
57
|
+
scroll_directions?: DSEdges;
|
|
58
|
+
scroll_multiplier?: number;
|
|
59
|
+
};
|
|
60
|
+
type DSInteractionPublish = {
|
|
61
|
+
'Interaction:init:pre': {};
|
|
62
|
+
'Interaction:init': {};
|
|
63
|
+
'Interaction:start:pre': DSInteractionPublishEventData;
|
|
64
|
+
'Interaction:start': DSInteractionPublishEventData;
|
|
65
|
+
'Interaction:update:pre': Partial<DSInteractionPublishEventData>;
|
|
66
|
+
'Interaction:update': Partial<DSInteractionPublishEventData>;
|
|
67
|
+
'Interaction:end:pre': DSInteractionPublishEventData;
|
|
68
|
+
'Interaction:end': DSInteractionPublishEventData;
|
|
69
|
+
};
|
|
70
|
+
type InteractionEvent = MouseEvent | PointerEvent | TouchEvent;
|
|
71
|
+
declare class Interaction<E extends DSInputElement> {
|
|
72
|
+
private isInteracting?;
|
|
73
|
+
isDragging: boolean;
|
|
74
|
+
private DS;
|
|
75
|
+
private PS;
|
|
76
|
+
private Settings;
|
|
77
|
+
constructor({ DS, PS }: {
|
|
78
|
+
DS: DragSelect<E>;
|
|
79
|
+
PS: PubSub<E>;
|
|
80
|
+
});
|
|
81
|
+
init: () => void;
|
|
82
|
+
private _init;
|
|
83
|
+
private _canInteract;
|
|
84
|
+
private start;
|
|
85
|
+
private _start;
|
|
86
|
+
private isDragEvent;
|
|
87
|
+
/**
|
|
88
|
+
* Triggers when a node is actively selected: <button> nodes that are pressed via the keyboard.
|
|
89
|
+
* Making DragSelect accessible for everyone!
|
|
90
|
+
*/
|
|
91
|
+
private onClick;
|
|
92
|
+
stop: (area?: DSArea) => void;
|
|
93
|
+
update: ({ event, scroll_directions, scroll_multiplier, }: {
|
|
94
|
+
event?: InteractionEvent | undefined;
|
|
95
|
+
scroll_directions?: DSEdges | undefined;
|
|
96
|
+
scroll_multiplier?: number | undefined;
|
|
97
|
+
}) => void;
|
|
98
|
+
reset: (event: InteractionEvent) => void;
|
|
99
|
+
_reset: (event: InteractionEvent | KeyboardEvent) => void;
|
|
100
|
+
private setAreaEventListeners;
|
|
101
|
+
private removeAreaEventListeners;
|
|
102
|
+
private setDocEventListeners;
|
|
103
|
+
private removeDocEventListeners;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
type DSPublicPublishEventNames<E extends DSInputElement> = keyof DSPublicPublish<E>;
|
|
107
|
+
type DSPublicPublishAdditionalEventData<E extends DSInputElement> = {
|
|
108
|
+
/** The dropZone element that the element was dropped into (or the mouse is currently hovering over) */
|
|
109
|
+
dropTarget?: DSDropZone<E>;
|
|
110
|
+
/** Selected Elements */
|
|
111
|
+
items: E[];
|
|
112
|
+
/** Whether the user is dragging or selecting */
|
|
113
|
+
isDragging: boolean;
|
|
114
|
+
};
|
|
115
|
+
type SelectionCB<E extends DSInputElement> = DSSelectedPublishEventData<E> & {
|
|
116
|
+
/** Whether the user is dragging or selecting */
|
|
117
|
+
isDragging: boolean;
|
|
118
|
+
};
|
|
119
|
+
type ScrollCB<E extends DSInputElement> = Pick<DSAreaPublishEventData<E>, 'scroll_directions' | 'scroll_multiplier'> & {
|
|
120
|
+
/** Selected Elements */
|
|
121
|
+
items: E[];
|
|
122
|
+
/** Whether the user is dragging or selecting */
|
|
123
|
+
isDragging: boolean;
|
|
124
|
+
};
|
|
125
|
+
type InteractionCB = DSInteractionPublishEventData;
|
|
126
|
+
type InteractionEndCB<E extends DSInputElement> = Partial<DSInteractionPublishEventData> & DSPublicPublishAdditionalEventData<E>;
|
|
127
|
+
type DSPublicPublish<E extends DSInputElement> = {
|
|
128
|
+
preelementselect: SelectionCB<E>;
|
|
129
|
+
elementselect: SelectionCB<E>;
|
|
130
|
+
'DS:select:pre': SelectionCB<E>;
|
|
131
|
+
'DS:select': SelectionCB<E>;
|
|
132
|
+
preelementunselect: SelectionCB<E>;
|
|
133
|
+
elementunselect: SelectionCB<E>;
|
|
134
|
+
'DS:unselect:pre': SelectionCB<E>;
|
|
135
|
+
'DS:unselect': SelectionCB<E>;
|
|
136
|
+
'DS:added:pre': SelectionCB<E>;
|
|
137
|
+
'DS:added': SelectionCB<E>;
|
|
138
|
+
'DS:removed:pre': SelectionCB<E>;
|
|
139
|
+
'DS:removed': SelectionCB<E>;
|
|
140
|
+
preautoscroll: ScrollCB<E>;
|
|
141
|
+
autoscroll: ScrollCB<E>;
|
|
142
|
+
'DS:scroll': ScrollCB<E>;
|
|
143
|
+
'DS:scroll:pre': ScrollCB<E>;
|
|
144
|
+
predragstart: InteractionCB;
|
|
145
|
+
dragstart: InteractionCB;
|
|
146
|
+
'DS:start': InteractionCB;
|
|
147
|
+
'DS:start:pre': InteractionCB;
|
|
148
|
+
predragmove: InteractionCB;
|
|
149
|
+
dragmove: InteractionCB;
|
|
150
|
+
'DS:update': InteractionCB;
|
|
151
|
+
'DS:update:pre': InteractionCB;
|
|
152
|
+
precallback: InteractionEndCB<E>;
|
|
153
|
+
callback: InteractionEndCB<E>;
|
|
154
|
+
'DS:end': InteractionEndCB<E>;
|
|
155
|
+
'DS:end:pre': InteractionEndCB<E>;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
type DSSelectablePublishEventNames = "Selectable:added:pre" | "Selectable:added" | "Selectable:removed" | "Selectable:removed:pre" | "Selectable:click:pre" | "Selectable:click" | "Selectable:pointer:pre" | "Selectable:pointer";
|
|
159
|
+
type DSSelectablePublishEventData<E extends DSInputElement> = {
|
|
160
|
+
/** The items currently selected */
|
|
161
|
+
items: E[];
|
|
162
|
+
/** The item currently selected */
|
|
163
|
+
item: E;
|
|
164
|
+
};
|
|
165
|
+
type DSSelectablePublish<E extends DSInputElement> = {
|
|
166
|
+
"Selectable:added:pre": DSSelectablePublishEventData<E>;
|
|
167
|
+
"Selectable:added": DSSelectablePublishEventData<E>;
|
|
168
|
+
"Selectable:removed:pre": DSSelectablePublishEventData<E>;
|
|
169
|
+
"Selectable:removed": DSSelectablePublishEventData<E>;
|
|
170
|
+
"Selectable:click:pre": {
|
|
171
|
+
event: MouseEvent;
|
|
172
|
+
};
|
|
173
|
+
"Selectable:click": {
|
|
174
|
+
event: MouseEvent;
|
|
175
|
+
};
|
|
176
|
+
"Selectable:pointer:pre": {
|
|
177
|
+
event: InteractionEvent;
|
|
178
|
+
};
|
|
179
|
+
"Selectable:pointer": {
|
|
180
|
+
event: InteractionEvent;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
183
|
+
declare class SelectableSet<E extends DSInputElement> extends Set<E> {
|
|
184
|
+
private _rects?;
|
|
185
|
+
private _timeout?;
|
|
186
|
+
private DS;
|
|
187
|
+
private PS;
|
|
188
|
+
private Settings;
|
|
189
|
+
constructor({ DS, PS }: {
|
|
190
|
+
DS: DragSelect<E>;
|
|
191
|
+
PS: PubSub<E>;
|
|
192
|
+
});
|
|
193
|
+
private init;
|
|
194
|
+
add(element: E): this;
|
|
195
|
+
delete(element: E): boolean;
|
|
196
|
+
clear: () => void;
|
|
197
|
+
private _onClick;
|
|
198
|
+
private _onPointer;
|
|
199
|
+
addAll: (elements: E[]) => void;
|
|
200
|
+
deleteAll: (elements: E[]) => void;
|
|
201
|
+
/**
|
|
202
|
+
* Gets the bounding rect from private memory if available. If not gets it from the DOM.
|
|
203
|
+
* => Does not force rect calculation on all elements
|
|
204
|
+
*/
|
|
205
|
+
getElementRect: (element: E) => DSBoundingRect | DOMRect | undefined;
|
|
206
|
+
get elements(): E[];
|
|
207
|
+
get rects(): Map<E, DSBoundingRect>;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
type DSKeyStorePublishEventNames = "KeyStore:down:pre" | "KeyStore:down" | "KeyStore:up:pre" | "KeyStore:up";
|
|
211
|
+
type DSKeyStorePublishEventData = {
|
|
212
|
+
event: KeyboardEvent;
|
|
213
|
+
/** Pressed key (lowercase) */
|
|
214
|
+
key: string;
|
|
215
|
+
};
|
|
216
|
+
type DSKeyStorePublish = {
|
|
217
|
+
[K in DSKeyStorePublishEventNames]: DSKeyStorePublishEventData;
|
|
218
|
+
};
|
|
219
|
+
declare class KeyStore<E extends DSInputElement> {
|
|
220
|
+
private _currentValues;
|
|
221
|
+
private _keyMapping;
|
|
222
|
+
private DS;
|
|
223
|
+
private PS;
|
|
224
|
+
private settings;
|
|
225
|
+
/**
|
|
226
|
+
* @class KeyStore
|
|
227
|
+
* @constructor KeyStore
|
|
228
|
+
* @ignore
|
|
229
|
+
*/
|
|
230
|
+
constructor({ DS, PS }: {
|
|
231
|
+
DS: DragSelect<E>;
|
|
232
|
+
PS: PubSub<E>;
|
|
233
|
+
});
|
|
234
|
+
private init;
|
|
235
|
+
private keydown;
|
|
236
|
+
private keyup;
|
|
237
|
+
stop: () => void;
|
|
238
|
+
private reset;
|
|
239
|
+
isMultiSelectKeyPressed(event?: KeyboardEvent | MouseEvent | PointerEvent | TouchEvent): boolean;
|
|
240
|
+
get currentValues(): string[];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
type DSPointerStorePublishEventNames = 'PointerStore:updated:pre' | 'PointerStore:updated';
|
|
244
|
+
type DSPointerStorePublishEventData = {
|
|
245
|
+
event: PointerEvent | MouseEvent | TouchEvent;
|
|
246
|
+
};
|
|
247
|
+
type DSPointerStorePublish = {
|
|
248
|
+
[K in DSPointerStorePublishEventNames]: DSPointerStorePublishEventData;
|
|
249
|
+
};
|
|
250
|
+
declare class PointerStore<E extends DSInputElement> {
|
|
251
|
+
private _isMouseInteraction;
|
|
252
|
+
private _initialValArea;
|
|
253
|
+
private _currentValArea;
|
|
254
|
+
private _lastValArea;
|
|
255
|
+
private _initialVal;
|
|
256
|
+
private _currentVal;
|
|
257
|
+
private _lastVal;
|
|
258
|
+
private _lastTouch?;
|
|
259
|
+
private DS;
|
|
260
|
+
private PS;
|
|
261
|
+
private settings;
|
|
262
|
+
constructor({ DS, PS }: {
|
|
263
|
+
DS: DragSelect<E>;
|
|
264
|
+
PS: PubSub<E>;
|
|
265
|
+
});
|
|
266
|
+
private init;
|
|
267
|
+
start(event?: DSEvent): void;
|
|
268
|
+
getPointerPosition: (event?: DSEvent) => Vect2;
|
|
269
|
+
private update;
|
|
270
|
+
stop: () => void;
|
|
271
|
+
private reset;
|
|
272
|
+
private _normalizedEvent;
|
|
273
|
+
/** First recorded pointer position within the area */
|
|
274
|
+
get initialValArea(): Vect2;
|
|
275
|
+
/** Current pointer position within the area */
|
|
276
|
+
get currentValArea(): Vect2;
|
|
277
|
+
/** Last recorded pointer position within the area */
|
|
278
|
+
get lastValArea(): Vect2;
|
|
279
|
+
/** First recorded pointer position */
|
|
280
|
+
get initialVal(): Vect2;
|
|
281
|
+
/** Current pointer position */
|
|
282
|
+
get currentVal(): Vect2;
|
|
283
|
+
/** Last recorded pointer position */
|
|
284
|
+
get lastVal(): Vect2;
|
|
285
|
+
set initialVal(value: Vect2);
|
|
286
|
+
set currentVal(value: Vect2);
|
|
287
|
+
set lastVal(value: Vect2);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type WithPostfix<T, Postfix extends string> = {
|
|
291
|
+
[K in keyof T as K | `${string & K}${Postfix}`]: T[K];
|
|
292
|
+
};
|
|
293
|
+
type DSSettings<E extends DSInputElement> = WithPostfix<Required<Settings<E>>, ':pre'>;
|
|
294
|
+
type DSSettingsPublishEventNames = "Settings:updated:pre" | "Settings:updated" | `Settings:updated:${string}:pre` | `Settings:updated:${string}`;
|
|
295
|
+
type DSSettingsPublishEventData<E extends DSInputElement> = {
|
|
296
|
+
/** whether this is the initial settings call */
|
|
297
|
+
'settings:init': boolean;
|
|
298
|
+
/** the settings being updates/manipulated/passed, holds all settings including the previous value. i.e. updating selectorClass will publish { settings: { ...settings, selectorClass: 'newVal', 'selectorClass:pre': 'oldVal' } } this is a deep cloned copy so manipulating it will have no effect */
|
|
299
|
+
settings: DSSettings<E>;
|
|
300
|
+
/** the new settings that are passed, not available on the initial settings call */
|
|
301
|
+
'settings:new'?: Settings<E>;
|
|
302
|
+
};
|
|
303
|
+
type DSSettingsPublish<E extends DSInputElement> = {
|
|
304
|
+
[K in DSSettingsPublishEventNames]: DSSettingsPublishEventData<E>;
|
|
305
|
+
};
|
|
306
|
+
declare class SettingsStore<E extends DSInputElement> {
|
|
307
|
+
private _settings;
|
|
308
|
+
/**
|
|
309
|
+
* Holds the settings and their previous value `:pre`
|
|
310
|
+
* @example {
|
|
311
|
+
* autoScrollSpeed: 3,
|
|
312
|
+
* 'autoScrollSpeed:pre': 5
|
|
313
|
+
* }
|
|
314
|
+
**/
|
|
315
|
+
s: DSSettings<E>;
|
|
316
|
+
private PS;
|
|
317
|
+
/**
|
|
318
|
+
* @class ScrollStore
|
|
319
|
+
* @constructor ScrollStore
|
|
320
|
+
* @param {{ DS:DragSelect, settings:Settings }} p
|
|
321
|
+
* @ignore
|
|
322
|
+
*/
|
|
323
|
+
constructor({ PS, settings }: {
|
|
324
|
+
PS: PubSub<E>;
|
|
325
|
+
settings: Settings<E>;
|
|
326
|
+
});
|
|
327
|
+
update: ({ settings, init }: {
|
|
328
|
+
settings: Settings<E>;
|
|
329
|
+
init?: boolean | undefined;
|
|
330
|
+
}) => void;
|
|
331
|
+
private _update;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
type Vect2 = {
|
|
335
|
+
x: number;
|
|
336
|
+
y: number;
|
|
337
|
+
};
|
|
338
|
+
type Settings<E extends DSInputElement> = {
|
|
339
|
+
/** area in which you can drag. If not provided it will be the whole document. Default Document */
|
|
340
|
+
area?: HTMLElement | SVGElement | Document;
|
|
341
|
+
/** [=[]] the elements that can be selected. */
|
|
342
|
+
selectables?: E | E[];
|
|
343
|
+
/** [=5] Speed in which the area scrolls while selecting (if available). Unit is pixel per movement. */
|
|
344
|
+
autoScrollSpeed?: number;
|
|
345
|
+
/** [={x:25,y:25}] Tolerance for autoScroll (how close one has to be near an edges for autoScroll to start). */
|
|
346
|
+
overflowTolerance?: Vect2;
|
|
347
|
+
/** [=1] Zoom scale factor (in case of using CSS style transform: scale() which messes with real positions). Unit scale zoom. */
|
|
348
|
+
zoom?: number;
|
|
349
|
+
/** [=false] if set to true, no styles (except for position absolute) will be applied by default */
|
|
350
|
+
customStyles?: boolean;
|
|
351
|
+
/** [=false] Add newly selected elements to the selection instead of replacing them */
|
|
352
|
+
multiSelectMode?: boolean;
|
|
353
|
+
/** [=true] Whether or not to toggle already active elements while multi-selecting */
|
|
354
|
+
multiSelectToggling?: boolean;
|
|
355
|
+
/** [=['Control', 'Shift', 'Meta']] Keys that allows switching to the multi-select mode (see the multiSelectMode option). Any key value is possible ([see MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)). Note that the best support is given for <kbd>Control</kbd>, <kbd>Shift</kbd> and <kbd>Meta</kbd>. Provide an empty array `[]` if you want to turn off the functionality. */
|
|
356
|
+
multiSelectKeys?: DSMultiSelectKeys;
|
|
357
|
+
/** [=HTMLElement] the square that will draw the selection */
|
|
358
|
+
selector?: HTMLElement;
|
|
359
|
+
/** [=0] how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection) */
|
|
360
|
+
selectionThreshold?: number;
|
|
361
|
+
/** [=true] When a user is dragging on an already selected element, the selection is dragged. */
|
|
362
|
+
draggability?: boolean;
|
|
363
|
+
/** [=true] Whether an element is draggable from the start or needs to be selected first */
|
|
364
|
+
immediateDrag?: boolean;
|
|
365
|
+
/** [=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it) */
|
|
366
|
+
keyboardDrag?: boolean;
|
|
367
|
+
/** [={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard. */
|
|
368
|
+
dragKeys?: DSDragKeys;
|
|
369
|
+
/** [=10] The speed at which elements are dragged using the keyboard. In pixels per keydown. */
|
|
370
|
+
keyboardDragSpeed?: number;
|
|
371
|
+
/** [=true] Whether to use hardware accelerated css transforms when dragging or top/left instead */
|
|
372
|
+
useTransform?: boolean;
|
|
373
|
+
/** [=80] Refresh rate on memoization, higher numbers mean better performance but more lag if elements are moving, lower numbers mean less lag but worse performance. If none of your DOMNodes are moving, you can set it to a very high number to increase performance. Value in milliseconds. */
|
|
374
|
+
refreshMemoryRate?: number;
|
|
375
|
+
/** [=[]] one or more drop-elements: where the selectables can be dropped into */
|
|
376
|
+
dropZones?: DSInputDropZone<E>[];
|
|
377
|
+
/** [=1] how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside) */
|
|
378
|
+
dropInsideThreshold?: number;
|
|
379
|
+
/** [=0] how much % of the zone does the pointer has to be in to be considered a target (0 = anywhere in the zone, max: 0.5 = has to point at the center of the zone) */
|
|
380
|
+
dropTargetThreshold?: number;
|
|
381
|
+
/** [=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly. */
|
|
382
|
+
usePointerEvents?: boolean;
|
|
383
|
+
/** [=ds-hover] the class assigned to the mouse hovered items */
|
|
384
|
+
hoverClass?: string;
|
|
385
|
+
/** [=ds-selectable] the class assigned to the elements that can be selected */
|
|
386
|
+
selectableClass?: string;
|
|
387
|
+
/** [=ds-selected] the class assigned to the selected items */
|
|
388
|
+
selectedClass?: string;
|
|
389
|
+
/** [=ds-selector] the class assigned to the square selector helper */
|
|
390
|
+
selectorClass?: string;
|
|
391
|
+
/** [=ds-selector-area] the class assigned to the square in which the selector resides. By default it's invisible */
|
|
392
|
+
selectorAreaClass?: string;
|
|
393
|
+
/** [=ds-dropped-target] on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id} */
|
|
394
|
+
droppedTargetClass?: string;
|
|
395
|
+
/** [=ds-dropped-inside] on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id} */
|
|
396
|
+
droppedInsideClass?: string;
|
|
397
|
+
/** [=ds-droppable] on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id} */
|
|
398
|
+
droppableClass?: string;
|
|
399
|
+
/** [=ds-dropzone] on each dropZone */
|
|
400
|
+
dropZoneClass?: string;
|
|
401
|
+
/** [=ds-dropzone-ready] on corresponding dropZone when element is dragged */
|
|
402
|
+
dropZoneReadyClass?: string;
|
|
403
|
+
/** [=ds-dropzone-target] on dropZone that has elements from any successful target drop */
|
|
404
|
+
dropZoneTargetClass?: string;
|
|
405
|
+
/** [=ds-dropzone-inside] on dropZone that has elements inside after any drop */
|
|
406
|
+
dropZoneInsideClass?: string;
|
|
407
|
+
};
|
|
408
|
+
type DSCallbackObject<E extends DSInputElement> = Readonly<Partial<DSSettingsPublishEventData<E> & DSAreaPublishEventData<E> & DSKeyStorePublishEventData & DSPointerStorePublishEventData & DSInteractionPublishEventData & DSSelectablePublishEventData<E> & DSSelectedPublishEventData<E> & DSPublicPublishAdditionalEventData<E>>>;
|
|
409
|
+
type DSInputDropZone<E extends DSInputElement> = {
|
|
410
|
+
/** can be any unique identifier of type string */
|
|
411
|
+
id: string;
|
|
412
|
+
/** the dropzone itself */
|
|
413
|
+
element: E;
|
|
414
|
+
/** elements that can be dropped into that zone. This is optional, by default it will be all selectables */
|
|
415
|
+
droppables?: E[];
|
|
416
|
+
};
|
|
417
|
+
type DSElementPos = {
|
|
418
|
+
x: number;
|
|
419
|
+
y: number;
|
|
420
|
+
w: number;
|
|
421
|
+
h: number;
|
|
422
|
+
r: number;
|
|
423
|
+
b: number;
|
|
424
|
+
};
|
|
425
|
+
type DSEdges = Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
|
|
426
|
+
type DSEdgesObj = {
|
|
427
|
+
top: number;
|
|
428
|
+
bottom: number;
|
|
429
|
+
left: number;
|
|
430
|
+
right: number;
|
|
431
|
+
};
|
|
432
|
+
/** area within which you can drag */
|
|
433
|
+
type DSArea = HTMLElement | SVGElement | Document;
|
|
434
|
+
/** area in which you can drag */
|
|
435
|
+
type DSSelectorArea = HTMLElement;
|
|
436
|
+
/** elements that can be selected */
|
|
437
|
+
type DSInputElement = HTMLElement | SVGElement;
|
|
438
|
+
/** element that can be selected */
|
|
439
|
+
/** An array of keys that allows switching to the multi-select mode */
|
|
440
|
+
type DSMultiSelectKeys = Array<'Shift' | 'Control' | 'Meta' | string>;
|
|
441
|
+
type DSEvent = KeyboardEvent | MouseEvent | PointerEvent | TouchEvent;
|
|
442
|
+
type DSInternalEventName = DSSettingsPublishEventNames | DSAreaPublishEventNames | DSKeyStorePublishEventNames | DSPointerStorePublishEventNames | DSInteractionPublishEventNames | DSSelectablePublishEventNames | DSSelectedPublishEventNames;
|
|
443
|
+
type DSCallbackName<E extends DSInputElement> = DSPublicPublishEventNames<E> | DSInternalEventName;
|
|
444
|
+
type DSBoundingRectBase = {
|
|
445
|
+
top: number;
|
|
446
|
+
left: number;
|
|
447
|
+
bottom: number;
|
|
448
|
+
right: number;
|
|
449
|
+
};
|
|
450
|
+
interface DSBoundingRect extends DSBoundingRectBase {
|
|
451
|
+
width: number;
|
|
452
|
+
height: number;
|
|
453
|
+
}
|
|
454
|
+
type DSDragKeys = {
|
|
455
|
+
up: Array<string>;
|
|
456
|
+
down: Array<string>;
|
|
457
|
+
left: Array<string>;
|
|
458
|
+
right: Array<string>;
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
type DSSelectedPublishEventNames = "Selected:added:pre" | "Selected:added" | "Selected:removed" | "Selected:removed:pre";
|
|
462
|
+
type DSSelectedPublishEventData<E extends DSInputElement> = {
|
|
463
|
+
items: E[];
|
|
464
|
+
item: E;
|
|
465
|
+
};
|
|
466
|
+
type DSSelectedPublish<E extends DSInputElement> = {
|
|
467
|
+
[K in DSSelectedPublishEventNames]: DSSelectedPublishEventData<E>;
|
|
468
|
+
};
|
|
469
|
+
declare class SelectedSet<E extends DSInputElement> extends Set<E> {
|
|
470
|
+
private _rects?;
|
|
471
|
+
private _timeout?;
|
|
472
|
+
private DS;
|
|
473
|
+
private PS;
|
|
474
|
+
private Settings;
|
|
475
|
+
constructor({ DS, PS }: {
|
|
476
|
+
DS: DragSelect<E>;
|
|
477
|
+
PS: PubSub<E>;
|
|
478
|
+
});
|
|
479
|
+
add(element?: E): this;
|
|
480
|
+
delete(element: E): boolean;
|
|
481
|
+
clear: () => void;
|
|
482
|
+
/** Adds/Removes an element. If it is already selected = remove, if not = add. */
|
|
483
|
+
toggle(element: E): E;
|
|
484
|
+
addAll: (elements: E[]) => void;
|
|
485
|
+
deleteAll: (elements: E[]) => void;
|
|
486
|
+
get elements(): E[];
|
|
487
|
+
get rects(): Map<E, DSBoundingRect>;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
type DSPublishMappings<E extends DSInputElement> = DSSettingsPublish<E> & DSAreaPublish<E> & DSKeyStorePublish & DSPointerStorePublish & DSInteractionPublish & DSSelectablePublish<E> & DSSelectedPublish<E> & DSPublicPublish<E>;
|
|
491
|
+
type DSCallback<T> = (data: T) => any;
|
|
492
|
+
declare class PubSub<E extends DSInputElement> {
|
|
493
|
+
subscribers: {
|
|
494
|
+
[K in keyof DSPublishMappings<E>]?: DSCallback<DSPublishMappings<E>[K]>[];
|
|
495
|
+
};
|
|
496
|
+
DS: DragSelect<E>;
|
|
497
|
+
constructor({ DS }: {
|
|
498
|
+
DS: DragSelect<E>;
|
|
499
|
+
});
|
|
500
|
+
/**
|
|
501
|
+
* Subscribe to an event
|
|
502
|
+
* @returns event id, can be used to unsubscribe more efficiently
|
|
503
|
+
*/
|
|
504
|
+
subscribe: <K extends DSSettingsPublishEventNames | DSKeyStorePublishEventNames | DSPointerStorePublishEventNames | DSSelectedPublishEventNames | keyof DSAreaPublish<E> | keyof DSInteractionPublish | keyof DSSelectablePublish<E> | keyof DSPublicPublish<E>>(eventName: K, callback: DSCallback<DSPublishMappings<E>[K]>) => number;
|
|
505
|
+
/**
|
|
506
|
+
* Removes event subscription
|
|
507
|
+
* @param callback the callback method signature, has to be exactly the same as when subscribing. Consider using "id" instead.
|
|
508
|
+
* @param id event id returned when subscribed (more performant than callback search)
|
|
509
|
+
*/
|
|
510
|
+
unsubscribe: <K extends DSSettingsPublishEventNames | DSKeyStorePublishEventNames | DSPointerStorePublishEventNames | DSSelectedPublishEventNames | keyof DSAreaPublish<E> | keyof DSInteractionPublish | keyof DSSelectablePublish<E> | keyof DSPublicPublish<E>>(eventName: K, callback?: DSCallback<DSPublishMappings<E>[K]> | undefined, id?: number) => void;
|
|
511
|
+
/**
|
|
512
|
+
* Publishes an event to all subscribers
|
|
513
|
+
* @param eventName
|
|
514
|
+
* @param data passed to the subscription method
|
|
515
|
+
*/
|
|
516
|
+
publish: <K extends DSSettingsPublishEventNames | DSKeyStorePublishEventNames | DSPointerStorePublishEventNames | DSSelectedPublishEventNames | keyof DSAreaPublish<E> | keyof DSInteractionPublish | keyof DSSelectablePublish<E> | keyof DSPublicPublish<E>>(eventName: K | K[], data: DSPublishMappings<E>[K]) => void;
|
|
517
|
+
private _publish;
|
|
518
|
+
private _handlePublish;
|
|
519
|
+
_handlePrePublish: <K extends DSSettingsPublishEventNames | DSKeyStorePublishEventNames | DSPointerStorePublishEventNames | DSSelectedPublishEventNames | keyof DSAreaPublish<E> | keyof DSInteractionPublish | keyof DSSelectablePublish<E> | keyof DSPublicPublish<E>>(subscribers: DSCallback<DSPublishMappings<E>[K]>[], data: DSPublishMappings<E>[K]) => void;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
type MutationCallbackEvent = UIEvent | Event | MutationRecord[] | ResizeObserverEntry[];
|
|
523
|
+
|
|
524
|
+
type DSAreaPublishEventNames = 'Area:modified:pre' | 'Area:modified' | 'Area:scroll' | 'Area:scroll:pre';
|
|
525
|
+
type DSAreaPublishEventData<E extends DSInputElement> = {
|
|
526
|
+
/** The single item currently interacted with */
|
|
527
|
+
item: DSArea;
|
|
528
|
+
/** The respective event object */
|
|
529
|
+
event?: MutationCallbackEvent;
|
|
530
|
+
scroll_directions: DSEdges;
|
|
531
|
+
scroll_multiplier: number;
|
|
532
|
+
};
|
|
533
|
+
type DSAreaPublish<E extends DSInputElement> = {
|
|
534
|
+
'Area:modified:pre': Pick<DSAreaPublishEventData<E>, 'event' | 'item'>;
|
|
535
|
+
'Area:modified': Pick<DSAreaPublishEventData<E>, 'event' | 'item'>;
|
|
536
|
+
'Area:scroll:pre': Pick<DSAreaPublishEventData<E>, 'scroll_directions' | 'scroll_multiplier'>;
|
|
537
|
+
'Area:scroll': Pick<DSAreaPublishEventData<E>, 'scroll_directions' | 'scroll_multiplier'>;
|
|
538
|
+
};
|
|
539
|
+
declare class Area<E extends DSInputElement> {
|
|
540
|
+
private DS;
|
|
541
|
+
private PS;
|
|
542
|
+
private Settings;
|
|
543
|
+
private _observers?;
|
|
544
|
+
private _node;
|
|
545
|
+
private _parentNodes?;
|
|
546
|
+
private _computedStyle?;
|
|
547
|
+
private _computedBorder?;
|
|
548
|
+
private _rect?;
|
|
549
|
+
constructor({ DS, PS }: {
|
|
550
|
+
DS: DragSelect<E>;
|
|
551
|
+
PS: PubSub<E>;
|
|
552
|
+
});
|
|
553
|
+
private setArea;
|
|
554
|
+
private init;
|
|
555
|
+
private reset;
|
|
556
|
+
stop: () => void;
|
|
557
|
+
/** Scroll the area in the specified direction */
|
|
558
|
+
scroll: (directions: DSEdges, multiplier: number) => void;
|
|
559
|
+
get HTMLNode(): DSArea;
|
|
560
|
+
/** The computed border from the element (caches result) */
|
|
561
|
+
get computedBorder(): DSEdgesObj;
|
|
562
|
+
/** The computed styles from the element (caches result) */
|
|
563
|
+
private get computedStyle();
|
|
564
|
+
/** The element rect (caches result) (without scrollbar or borders) */
|
|
565
|
+
get rect(): DSBoundingRect;
|
|
566
|
+
private get parentNodes();
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
declare class DropZones<E extends DSInputElement> {
|
|
570
|
+
/** Get the drop zone by the zone element */
|
|
571
|
+
private _zoneByElement;
|
|
572
|
+
/** Get the drop zone by the zone id */
|
|
573
|
+
private _zoneById;
|
|
574
|
+
/** Get the drop zones by one zone item */
|
|
575
|
+
private _zonesByDroppable;
|
|
576
|
+
/** Get the drop zones by one zone item */
|
|
577
|
+
private _zones?;
|
|
578
|
+
private DS;
|
|
579
|
+
private PS;
|
|
580
|
+
private Settings;
|
|
581
|
+
constructor({ DS, PS }: {
|
|
582
|
+
DS: DragSelect<E>;
|
|
583
|
+
PS: PubSub<E>;
|
|
584
|
+
});
|
|
585
|
+
private setDropZones;
|
|
586
|
+
private _handleDrops;
|
|
587
|
+
private _getZoneByElementsFromPoint;
|
|
588
|
+
private stop;
|
|
589
|
+
getItemsDroppedById: (zoneId: string) => void | E[];
|
|
590
|
+
getItemsInsideById: (zoneId: string, addClasses?: boolean) => void | E[];
|
|
591
|
+
private getKeyboardItemCenter;
|
|
592
|
+
/** Returns first DropsZone under current pointer or coordinates if passed */
|
|
593
|
+
getTarget: ({ coordinates, isDraggingKeyboard, event, }: {
|
|
594
|
+
coordinates?: Vect2 | undefined;
|
|
595
|
+
isDraggingKeyboard?: boolean | undefined;
|
|
596
|
+
event?: InteractionEvent | KeyboardEvent | undefined;
|
|
597
|
+
}) => DropZone<E> | undefined;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
declare class ScrollStore<E extends DSInputElement> {
|
|
601
|
+
private _initialVal;
|
|
602
|
+
private _currentVal;
|
|
603
|
+
private _canScroll?;
|
|
604
|
+
private DS;
|
|
605
|
+
private PS;
|
|
606
|
+
private Settings;
|
|
607
|
+
constructor({ DS, PS }: {
|
|
608
|
+
DS: DragSelect<E>;
|
|
609
|
+
PS: PubSub<E>;
|
|
610
|
+
});
|
|
611
|
+
private init;
|
|
612
|
+
private addListeners;
|
|
613
|
+
private removeListeners;
|
|
614
|
+
private start;
|
|
615
|
+
private update;
|
|
616
|
+
stop: () => void;
|
|
617
|
+
private reset;
|
|
618
|
+
get canScroll(): boolean;
|
|
619
|
+
get scrollAmount(): {
|
|
620
|
+
x: number;
|
|
621
|
+
y: number;
|
|
622
|
+
};
|
|
623
|
+
private get initialVal();
|
|
624
|
+
get currentVal(): Vect2;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
declare class Selector<E extends DSInputElement> {
|
|
628
|
+
private _rect?;
|
|
629
|
+
private DS;
|
|
630
|
+
private PS;
|
|
631
|
+
private Settings;
|
|
632
|
+
HTMLNode: HTMLElement;
|
|
633
|
+
constructor({ DS, PS }: {
|
|
634
|
+
DS: DragSelect<E>;
|
|
635
|
+
PS: PubSub<E>;
|
|
636
|
+
});
|
|
637
|
+
private attachSelector;
|
|
638
|
+
private start;
|
|
639
|
+
stop: () => void;
|
|
640
|
+
/** Moves the selection to the correct place */
|
|
641
|
+
private update;
|
|
642
|
+
get rect(): DSBoundingRect | DOMRect;
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
declare class Selection<E extends DSInputElement> {
|
|
646
|
+
private _prevSelectedSet;
|
|
647
|
+
private _boundingRect?;
|
|
648
|
+
private _timeout?;
|
|
649
|
+
private DS;
|
|
650
|
+
private PS;
|
|
651
|
+
private Settings;
|
|
652
|
+
constructor({ DS, PS }: {
|
|
653
|
+
DS: DragSelect<E>;
|
|
654
|
+
PS: PubSub<E>;
|
|
655
|
+
});
|
|
656
|
+
/** Stores the previous selection (solves #9) */
|
|
657
|
+
private _storePrevious;
|
|
658
|
+
private start;
|
|
659
|
+
private update;
|
|
660
|
+
/** Checks if any selectable element is inside selection. */
|
|
661
|
+
private _handleInsideSelection;
|
|
662
|
+
get boundingRect(): DSBoundingRect;
|
|
663
|
+
/**
|
|
664
|
+
* Can be overridden to apply further filtering logic after the items to select are identified but before they actually get selected
|
|
665
|
+
* Is expected to return the select / unselect maps in the same shape as passed in
|
|
666
|
+
*/
|
|
667
|
+
filterSelected: ({ select, unselect, selectorRect, }: {
|
|
668
|
+
select: Map<E, DSBoundingRect>;
|
|
669
|
+
unselect: Map<E, DSBoundingRect>;
|
|
670
|
+
selectorRect: DSBoundingRect;
|
|
671
|
+
}) => {
|
|
672
|
+
select: Map<E, DSBoundingRect>;
|
|
673
|
+
unselect: Map<E, DSBoundingRect>;
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
declare class SelectorArea<E extends DSInputElement> {
|
|
678
|
+
private _scrollInterval?;
|
|
679
|
+
private _rect?;
|
|
680
|
+
private currentEdges;
|
|
681
|
+
private DS;
|
|
682
|
+
private PS;
|
|
683
|
+
private Settings;
|
|
684
|
+
HTMLNode: HTMLElement;
|
|
685
|
+
constructor({ DS, PS }: {
|
|
686
|
+
DS: DragSelect<E>;
|
|
687
|
+
PS: PubSub<E>;
|
|
688
|
+
});
|
|
689
|
+
private init;
|
|
690
|
+
/** Adding / Removing elements to document */
|
|
691
|
+
private applyElements;
|
|
692
|
+
/** Updates the selectorAreas positions to match the areas */
|
|
693
|
+
private updatePos;
|
|
694
|
+
stop: (remove: boolean) => void;
|
|
695
|
+
private startAutoScroll;
|
|
696
|
+
/** Creates an interval that auto-scrolls while the cursor is near the edge */
|
|
697
|
+
private handleAutoScroll;
|
|
698
|
+
private stopAutoScroll;
|
|
699
|
+
/**
|
|
700
|
+
* Checks if the element is either inside the Selector Area (as a reachable child or touching the area)
|
|
701
|
+
* @param elementRect - slight performance improvements when passed
|
|
702
|
+
*/
|
|
703
|
+
isInside: (element: E, elementRect?: DSBoundingRect) => boolean;
|
|
704
|
+
/** checks if the click was triggered on the area. */
|
|
705
|
+
isClicked(event?: DSEvent): boolean;
|
|
706
|
+
get rect(): DSBoundingRect | DOMRect;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
type IsCollision = {
|
|
710
|
+
/**
|
|
711
|
+
* Axis-Aligned Bounding Box Collision Detection.
|
|
712
|
+
* Imagine following Example:
|
|
713
|
+
*
|
|
714
|
+
*
|
|
715
|
+
* b01
|
|
716
|
+
* a01[1]a02
|
|
717
|
+
* b02 b11
|
|
718
|
+
* a11[2]a12
|
|
719
|
+
* b12
|
|
720
|
+
*
|
|
721
|
+
*
|
|
722
|
+
* to check if those two boxes collide we do this AABB calculation:
|
|
723
|
+
* 1. a01 < a12 (left border pos box1 smaller than right border pos box2)
|
|
724
|
+
* 2. a02 > a11 (right border pos box1 larger than left border pos box2)
|
|
725
|
+
* 3. b01 < b12 (top border pos box1 smaller than bottom border pos box2)
|
|
726
|
+
* 4. b02 > b11 (bottom border pos box1 larger than top border pos box2)
|
|
727
|
+
* {@link https://en.wikipedia.org/wiki/Minimum_bounding_box#Axis-aligned_minimum_bounding_box Wikipedia}
|
|
728
|
+
* {@link https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection MDN}
|
|
729
|
+
|
|
730
|
+
* @param percent
|
|
731
|
+
* 1 = the element has to be completely inside the other element
|
|
732
|
+
* 0.8 = the element has to be 80% inside the other element
|
|
733
|
+
* 0.5 = the element has to be 50% inside the other element
|
|
734
|
+
* 0.2 = the element has to be 20% inside the other element
|
|
735
|
+
* 0 = the element only has to touch the other element
|
|
736
|
+
*/
|
|
737
|
+
(el1?: DSBoundingRectBase, el2?: DSBoundingRectBase, percent?: number): boolean;
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
declare class DragSelect<E extends DSInputElement> {
|
|
741
|
+
/** used to skip all current Selection and dragNdrop functionality */
|
|
742
|
+
continue: boolean;
|
|
743
|
+
private PubSub;
|
|
744
|
+
stores: {
|
|
745
|
+
SettingsStore: SettingsStore<E>;
|
|
746
|
+
PointerStore: PointerStore<E>;
|
|
747
|
+
ScrollStore: ScrollStore<E>;
|
|
748
|
+
KeyStore: KeyStore<E>;
|
|
749
|
+
};
|
|
750
|
+
Area: Area<E>;
|
|
751
|
+
Selector: Selector<E>;
|
|
752
|
+
SelectorArea: SelectorArea<E>;
|
|
753
|
+
SelectableSet: SelectableSet<E>;
|
|
754
|
+
SelectedSet: SelectedSet<E>;
|
|
755
|
+
Selection: Selection<E>;
|
|
756
|
+
private Drag;
|
|
757
|
+
DropZones: DropZones<E>;
|
|
758
|
+
Interaction: Interaction<E>;
|
|
759
|
+
stopped: boolean;
|
|
760
|
+
constructor(settings: Settings<E>);
|
|
761
|
+
static isCollision: IsCollision;
|
|
762
|
+
/** Subscribe to events */
|
|
763
|
+
subscribe: <T extends keyof DSPublicPublish<E>>(eventName: T, callback: DSCallback<DSPublishMappings<E>[T]>) => void;
|
|
764
|
+
/** Un-Subscribe from events */
|
|
765
|
+
unsubscribe: <T extends keyof DSPublicPublish<E>>(eventName: T, callback?: DSCallback<DSPublishMappings<E>[T]> | undefined, id?: number) => void;
|
|
766
|
+
/** Publish events */
|
|
767
|
+
publish: <T extends DSCallbackName<E_1>>(eventName: T | T[], data: DSPublishMappings<E>[T]) => void;
|
|
768
|
+
/** Initializes the functionality. Automatically triggered when created. Also, reset the functionality after a teardown */
|
|
769
|
+
start: () => void;
|
|
770
|
+
/**
|
|
771
|
+
* Complete function teardown
|
|
772
|
+
* Will teardown/stop the whole functionality
|
|
773
|
+
* @param remove if elements should be removed.
|
|
774
|
+
* @param fromSelection if elements should also be added/removed to the selection.
|
|
775
|
+
* @param withCallback if elements should also be added/removed to the selection.
|
|
776
|
+
*/
|
|
777
|
+
stop(remove?: boolean, fromSelection?: boolean, withCallback?: boolean): void;
|
|
778
|
+
/**
|
|
779
|
+
* Utility to override DragSelect internal functionality:
|
|
780
|
+
* Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
|
|
781
|
+
* Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
|
|
782
|
+
*/
|
|
783
|
+
break: () => boolean;
|
|
784
|
+
/** Update any setting dynamically */
|
|
785
|
+
setSettings: (settings: Settings<E>) => void;
|
|
786
|
+
/** Returns the current selected nodes */
|
|
787
|
+
getSelection: () => E[];
|
|
788
|
+
/**
|
|
789
|
+
* Adds several elements to the selection list also adds the specific classes and take into account all calculations.
|
|
790
|
+
* Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
|
|
791
|
+
* @param elements one or multiple elements
|
|
792
|
+
* @param triggerCallback if callback should be called
|
|
793
|
+
* @param dontAddToSelectables if element should not be added to the list of selectable elements
|
|
794
|
+
* @return all selected elements
|
|
795
|
+
*/
|
|
796
|
+
addSelection(elements: E | E[], triggerCallback?: boolean, dontAddToSelectables?: boolean): E[];
|
|
797
|
+
/**
|
|
798
|
+
* Removes specific elements from the selection
|
|
799
|
+
* Multiple elements can be given at once, in contrary to unselect
|
|
800
|
+
* @param elements one or multiple elements
|
|
801
|
+
* @param triggerCallback if callback should be called
|
|
802
|
+
* @param removeFromSelectables if element should be removed from the list of selectable elements
|
|
803
|
+
* @return all selected elements
|
|
804
|
+
*/
|
|
805
|
+
removeSelection(elements: E | E[], triggerCallback?: boolean, removeFromSelectables?: boolean): E[];
|
|
806
|
+
/**
|
|
807
|
+
* Toggles specific elements from the selection:
|
|
808
|
+
* If element is not in selection it will be added, if it is already selected, it will be removed.
|
|
809
|
+
* Multiple elements can be given at once.
|
|
810
|
+
* @param elements one or multiple elements
|
|
811
|
+
* @param triggerCallback if callback should be called
|
|
812
|
+
* @param removeFromSelectables if element should not be added/removed to the list of selectable elements accordingly
|
|
813
|
+
* @return all selected elements
|
|
814
|
+
*/
|
|
815
|
+
toggleSelection(elements: E | E[], triggerCallback?: boolean, removeFromSelectables?: boolean): E[];
|
|
816
|
+
/**
|
|
817
|
+
* Sets the current selected elements and optionally run the callback
|
|
818
|
+
* By default, adds new elements also to the list of selectables
|
|
819
|
+
* @param elements dom elements
|
|
820
|
+
* @param triggerCallback if callback should be called
|
|
821
|
+
* @param dontAddToSelectables if element should not be added to the list of selectable elements
|
|
822
|
+
*/
|
|
823
|
+
setSelection(elements: E | E[], triggerCallback?: boolean, dontAddToSelectables?: boolean): E[];
|
|
824
|
+
/**
|
|
825
|
+
* Unselect / Deselect all current selected Nodes
|
|
826
|
+
* @param triggerCallback if callback should be called
|
|
827
|
+
* @return this.selected, should be empty
|
|
828
|
+
*/
|
|
829
|
+
clearSelection(triggerCallback?: boolean): E[];
|
|
830
|
+
/**
|
|
831
|
+
* Add elements that can be selected. No node is added twice
|
|
832
|
+
* @param elements dom element(s)
|
|
833
|
+
* @param addToSelection if elements should also be added to current selection
|
|
834
|
+
* @param triggerCallback if callback should be called
|
|
835
|
+
* @return the added element(s)
|
|
836
|
+
*/
|
|
837
|
+
addSelectables(elements: E | E[], addToSelection?: boolean, triggerCallback?: boolean): E[];
|
|
838
|
+
/** Gets all nodes that can potentially be selected */
|
|
839
|
+
getSelectables: () => E[];
|
|
840
|
+
/**
|
|
841
|
+
* Remove elements from the elements that can be selected.
|
|
842
|
+
* @param elements dom element(s)
|
|
843
|
+
* @param removeFromSelection if elements should also be removed from current selection
|
|
844
|
+
* @param triggerCallback if callback should be called
|
|
845
|
+
* @return the removed element(s)
|
|
846
|
+
*/
|
|
847
|
+
removeSelectables(elements: E | E[], removeFromSelection?: boolean, triggerCallback?: boolean): E[];
|
|
848
|
+
/** The starting/initial position of the cursor/selector */
|
|
849
|
+
getInitialCursorPosition: () => Vect2;
|
|
850
|
+
/** The last seen position of the cursor/selector */
|
|
851
|
+
getCurrentCursorPosition: () => Vect2;
|
|
852
|
+
/** The previous position of the cursor/selector */
|
|
853
|
+
getPreviousCursorPosition: () => Vect2;
|
|
854
|
+
/** The starting/initial position of the cursor/selector */
|
|
855
|
+
getInitialCursorPositionArea: () => Vect2;
|
|
856
|
+
/** The last seen position of the cursor/selector */
|
|
857
|
+
getCurrentCursorPositionArea: () => Vect2;
|
|
858
|
+
/** The previous position of the cursor/selector */
|
|
859
|
+
getPreviousCursorPositionArea: () => Vect2;
|
|
860
|
+
/** Whether the multi-selection key was pressed */
|
|
861
|
+
isMultiSelect: (event: MouseEvent | TouchEvent | PointerEvent | KeyboardEvent) => boolean;
|
|
862
|
+
/** Whether the user is currently drag n dropping elements (instead of selection) */
|
|
863
|
+
isDragging: () => boolean;
|
|
864
|
+
/** Returns first DropsZone under coordinates, if no coordinated provided current pointer coordinates are used */
|
|
865
|
+
getZoneByCoordinates: (coordinates?: Vect2) => DSDropZone<E> | undefined;
|
|
866
|
+
/** Returns itemsDropped into zone by zone id */
|
|
867
|
+
getItemsDroppedByZoneId: (zoneId: string) => void | E[];
|
|
868
|
+
/**
|
|
869
|
+
* Returns itemsInside by zone id
|
|
870
|
+
* @param addClasses whether or not to add/remove the "inside" classes to the items
|
|
871
|
+
*/
|
|
872
|
+
getItemsInsideByZoneId: (zoneId: string, addClasses?: boolean) => void | E[];
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
type DSPubCallback<T extends keyof DSPublicPublish<E>, E extends DSInputElement = DSInputElement> = DSCallback<DSPublishMappings<E>[T]>;
|
|
876
|
+
|
|
877
|
+
export { type DSArea, type DSBoundingRect, type DSBoundingRectBase, type DSCallbackName, type DSCallbackObject, type DSDragKeys, type DSEdges, type DSEdgesObj, type DSElementPos, type DSEvent, type DSInputDropZone, type DSInputElement, type DSInternalEventName, type DSMultiSelectKeys, type DSPubCallback, type DSSelectorArea, type Settings, type Vect2, DragSelect as default };
|