dragselect 3.1.0 → 3.1.2

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/DragSelect.d.ts +2 -1
  3. package/dist/DragSelect.es6m.js +3886 -0
  4. package/dist/DragSelect.esm.js +34 -5
  5. package/dist/DragSelect.js +34 -5
  6. package/dist/ds.es6m.min.js +1 -0
  7. package/dist/ds.esm.min.js +1 -1
  8. package/dist/ds.min.js +1 -1
  9. package/dist/methods/addModificationObservers.d.ts +11 -0
  10. package/dist/methods/canScroll.d.ts +3 -0
  11. package/dist/methods/createSelectorAreaElement.d.ts +3 -0
  12. package/dist/methods/createSelectorElement.d.ts +3 -0
  13. package/dist/methods/debounce.d.ts +3 -0
  14. package/dist/methods/documentScroll.d.ts +6 -0
  15. package/dist/methods/getAllParentNodes.d.ts +3 -0
  16. package/dist/methods/getAreaRect.d.ts +3 -0
  17. package/dist/methods/getBoundingClientRect.d.ts +4 -0
  18. package/dist/methods/getCurrentScroll.d.ts +3 -0
  19. package/dist/methods/getOverflowEdges.d.ts +7 -0
  20. package/dist/methods/getPointerPos.d.ts +5 -0
  21. package/dist/methods/getSelectorPosition.d.ts +12 -0
  22. package/dist/methods/getStylePosition.d.ts +3 -0
  23. package/dist/methods/handleElementOverflow.d.ts +10 -0
  24. package/dist/methods/handleElementPositionAttribute.d.ts +6 -0
  25. package/dist/methods/handleKeyboardDragPosDifference.d.ts +13 -0
  26. package/dist/methods/handleSelection.d.ts +9 -0
  27. package/dist/methods/handleUnSelection.d.ts +9 -0
  28. package/dist/methods/hydrateSettings.d.ts +3 -0
  29. package/dist/methods/index.d.ts +30 -0
  30. package/dist/methods/isCollision.d.ts +13 -0
  31. package/dist/methods/moveElement.d.ts +8 -0
  32. package/dist/methods/removeModificationObservers.d.ts +3 -0
  33. package/dist/methods/scrollElement.d.ts +3 -0
  34. package/dist/methods/setStylePosition.d.ts +3 -0
  35. package/dist/methods/subscriberAliases.d.ts +14 -0
  36. package/dist/methods/toArray.d.ts +3 -0
  37. package/dist/methods/updateElementStylePos.d.ts +8 -0
  38. package/dist/methods/vect2.d.ts +8 -0
  39. package/dist/modules/Area.d.ts +80 -0
  40. package/dist/modules/Drag.d.ts +71 -0
  41. package/dist/modules/DropZone.d.ts +90 -0
  42. package/dist/modules/DropZones.d.ts +73 -0
  43. package/dist/modules/Interaction.d.ts +51 -0
  44. package/dist/modules/PubSub.d.ts +37 -0
  45. package/dist/modules/SelectableSet.d.ts +43 -0
  46. package/dist/modules/SelectedSet.d.ts +32 -0
  47. package/dist/modules/Selection.d.ts +54 -0
  48. package/dist/modules/Selector.d.ts +29 -0
  49. package/dist/modules/SelectorArea.d.ts +58 -0
  50. package/dist/modules/index.d.ts +11 -0
  51. package/dist/stores/KeyStore.d.ts +34 -0
  52. package/dist/stores/PointerStore.d.ts +83 -0
  53. package/dist/stores/ScrollStore.d.ts +38 -0
  54. package/dist/stores/SettingsStore.d.ts +39 -0
  55. package/dist/stores/index.d.ts +5 -0
  56. package/dist/types.d.ts +276 -0
  57. package/package.json +2 -2
@@ -0,0 +1,38 @@
1
+ export default class ScrollStore {
2
+ /**
3
+ * @class ScrollStore
4
+ * @constructor ScrollStore
5
+ * @param {{ DS:DragSelect }} p
6
+ * @ignore
7
+ */
8
+ constructor({ DS }: {
9
+ DS: DragSelect;
10
+ });
11
+ /**
12
+ * @type {Vect2}
13
+ * @private */
14
+ private _initialVal;
15
+ /**
16
+ * @type {Vect2}
17
+ * @private */
18
+ private _currentVal;
19
+ /**
20
+ * @type {boolean}
21
+ * @private */
22
+ private _canScroll;
23
+ DS: DragSelect;
24
+ init: () => void;
25
+ start: () => void;
26
+ update: () => Vect2;
27
+ stop: () => void;
28
+ reset: () => void;
29
+ get canScroll(): boolean;
30
+ get scrollAmount(): {
31
+ x: number;
32
+ y: number;
33
+ };
34
+ get initialVal(): Vect2;
35
+ get currentVal(): Vect2;
36
+ }
37
+ import DragSelect from "../DragSelect";
38
+ import "../types"
@@ -0,0 +1,39 @@
1
+ export default class SettingsStore {
2
+ /**
3
+ * @class ScrollStore
4
+ * @constructor ScrollStore
5
+ * @param {{ DS:DragSelect, settings:Settings }} p
6
+ * @ignore
7
+ */
8
+ constructor({ DS, settings }: {
9
+ DS: DragSelect;
10
+ settings: Settings;
11
+ });
12
+ /**
13
+ * @type {Settings}
14
+ * @private
15
+ * */
16
+ private _settings;
17
+ /**
18
+ * Holds the settings and their previous value `:pre`
19
+ * @example {
20
+ * autoScrollSpeed: 3,
21
+ * 'autoScrollSpeed:pre': 5
22
+ * }
23
+ * @type {Settings}
24
+ * */
25
+ s: Settings;
26
+ DS: DragSelect;
27
+ /** @param {{settings: Settings, init?: boolean}} props */
28
+ update: ({ settings, init }: {
29
+ settings: Settings;
30
+ init?: boolean;
31
+ }) => void;
32
+ /** @param {{settings: Settings, init: boolean}} props */
33
+ _update: ({ settings, init }: {
34
+ settings: Settings;
35
+ init: boolean;
36
+ }) => void;
37
+ }
38
+ import DragSelect from "../DragSelect";
39
+ import "../types"
@@ -0,0 +1,5 @@
1
+ export { default as KeyStore } from "./KeyStore";
2
+ export { default as PointerStore } from "./PointerStore";
3
+ export { default as ScrollStore } from "./ScrollStore";
4
+ export { default as SettingsStore } from "./SettingsStore";
5
+ import "../types"
@@ -0,0 +1,276 @@
1
+ /**
2
+ * The Settings to be passed to the Class
3
+ */
4
+ type Settings = {
5
+ /**
6
+ * area in which you can drag. If not provided it will be the whole document
7
+ */
8
+ area?: HTMLElement | SVGElement | Document;
9
+ /**
10
+ * the elements that can be selected
11
+ */
12
+ selectables?: DSInputElements;
13
+ /**
14
+ * Speed in which the area scrolls while selecting (if available). Unit is pixel per movement.
15
+ */
16
+ autoScrollSpeed?: number;
17
+ /**
18
+ * Tolerance for autoScroll (how close one has to be near an edges for autoScroll to start)
19
+ */
20
+ overflowTolerance?: Vect2;
21
+ /**
22
+ * Zoom scale factor (in case of using CSS style transform: scale() which messes with real positions). Unit scale zoom.
23
+ */
24
+ zoom?: number;
25
+ /**
26
+ * if set to true, no styles (except for position absolute) will be applied by default
27
+ */
28
+ customStyles?: boolean;
29
+ /**
30
+ * Add newly selected elements to the selection instead of replacing them
31
+ */
32
+ multiSelectMode?: boolean;
33
+ /**
34
+ * Whether or not to toggle already active elements while multi-selecting
35
+ */
36
+ multiSelectToggling?: boolean;
37
+ /**
38
+ * 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.
39
+ */
40
+ multiSelectKeys?: DSMultiSelectKeys;
41
+ /**
42
+ * the square that will draw the selection
43
+ */
44
+ selector?: HTMLElement;
45
+ /**
46
+ * how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection)
47
+ */
48
+ selectionThreshold?: number;
49
+ /**
50
+ * When a user is dragging on an already selected element, the selection is dragged.
51
+ */
52
+ draggability?: boolean;
53
+ /**
54
+ * Whether an element is draggable from the start or needs to be selected first
55
+ */
56
+ immediateDrag?: boolean;
57
+ /**
58
+ * Whether or not the user can drag with the keyboard (we don't recommend disabling it)
59
+ */
60
+ keyboardDrag?: boolean;
61
+ /**
62
+ * The keys available to drag element using the keyboard.
63
+ */
64
+ dragKeys?: DSDragKeys;
65
+ /**
66
+ * The speed at which elements are dragged using the keyboard. In pixels per keydown.
67
+ */
68
+ keyboardDragSpeed?: number;
69
+ /**
70
+ * Whether to use hardware accelerated css transforms when dragging or top/left instead
71
+ */
72
+ useTransform?: boolean;
73
+ /**
74
+ * 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.
75
+ */
76
+ refreshMemoryRate?: number;
77
+ /**
78
+ * one or more drop-elements: where the selectables can be dropped into
79
+ */
80
+ dropZones?: DSInputDropZone[];
81
+ /**
82
+ * how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside)
83
+ */
84
+ dropInsideThreshold?: number;
85
+ /**
86
+ * 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)
87
+ */
88
+ dropTargetThreshold?: number;
89
+ /**
90
+ * Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly.
91
+ */
92
+ usePointerEvents?: boolean;
93
+ /**
94
+ * the class assigned to the mouse hovered items
95
+ */
96
+ hoverClass?: string;
97
+ /**
98
+ * the class assigned to the elements that can be selected
99
+ */
100
+ selectableClass?: string;
101
+ /**
102
+ * the class assigned to the selected items
103
+ */
104
+ selectedClass?: string;
105
+ /**
106
+ * the class assigned to the square selector helper
107
+ */
108
+ selectorClass?: string;
109
+ /**
110
+ * the class assigned to the square in which the selector resides. By default it's invisible
111
+ */
112
+ selectorAreaClass?: string;
113
+ /**
114
+ * on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id}
115
+ */
116
+ droppedTargetClass?: string;
117
+ /**
118
+ * on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id}
119
+ */
120
+ droppedInsideClass?: string;
121
+ /**
122
+ * on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id}
123
+ */
124
+ droppableClass?: string;
125
+ /**
126
+ * on each dropZone
127
+ */
128
+ dropZoneClass?: string;
129
+ /**
130
+ * on corresponding dropZone when element is dragged
131
+ */
132
+ dropZoneReadyClass?: string;
133
+ /**
134
+ * on dropZone that has elements from any successful target drop
135
+ */
136
+ dropZoneTargetClass?: string;
137
+ /**
138
+ * on dropZone that has elements inside after any drop
139
+ */
140
+ dropZoneInsideClass?: string;
141
+ /**
142
+ * whether to drag multiple elements as a single block or as individual items
143
+ */
144
+ dragAsBlock?: boolean;
145
+ };
146
+ /**
147
+ * The Object that is passed back to any callback method
148
+ */
149
+ type CallbackObject = {
150
+ /**
151
+ * The items currently selected
152
+ */
153
+ items?: Array<HTMLElement | SVGElement | any>;
154
+ /**
155
+ * The respective event object
156
+ */
157
+ event?: MouseEvent | TouchEvent | PointerEvent | KeyboardEvent | Event;
158
+ /**
159
+ * The single item currently interacted with
160
+ */
161
+ item?: HTMLElement | SVGElement | any;
162
+ /**
163
+ * Whether the interaction is a drag or a select
164
+ */
165
+ isDragging?: boolean;
166
+ /**
167
+ * Whether or not the drag interaction is via keyboard
168
+ */
169
+ isDraggingKeyboard?: boolean;
170
+ /**
171
+ * Pressed key (lowercase)
172
+ */
173
+ key?: string;
174
+ /**
175
+ * the settings being updates/manipulated/passed, also holds the previous value. i.e. updating selectorClass will publish { settings: { selectorClass: 'newVal', 'selectorClass:pre': 'oldVal' } }
176
+ */
177
+ settings?: Settings;
178
+ scroll_directions?: Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
179
+ scroll_multiplier?: number;
180
+ /**
181
+ * The dropZone element that the element was dropped into (or the mouse is currently hovering over)
182
+ */
183
+ dropTarget?: DSDropZone;
184
+ };
185
+ type DSCallback = Function;
186
+ type DSInputDropZone = {
187
+ /**
188
+ * can be any unique identifier of type string
189
+ */
190
+ id: string;
191
+ /**
192
+ * is the dropzone itself
193
+ */
194
+ element: DSElement;
195
+ /**
196
+ * the elements that can be dropped into that zone. This is optional, by default it will be all selectables
197
+ */
198
+ droppables?: DSInputElements;
199
+ };
200
+ type DSDropZone = {
201
+ id: string;
202
+ element: DSElement;
203
+ droppables: DSElements;
204
+ /**
205
+ * the items related to the target zone
206
+ */
207
+ itemsDropped?: DSElements;
208
+ /**
209
+ * the items that are within the targets bounds
210
+ */
211
+ itemsInside?: DSElements;
212
+ };
213
+ type Vect2 = {
214
+ x: number;
215
+ y: number;
216
+ };
217
+ type DSElementPos = {
218
+ x: number;
219
+ y: number;
220
+ w: number;
221
+ h: number;
222
+ r: number;
223
+ b: number;
224
+ };
225
+ type DSEdges = Array<'top' | 'bottom' | 'left' | 'right' | undefined>;
226
+ /**
227
+ * area within which you can drag
228
+ */
229
+ type DSArea = HTMLElement | SVGElement | Document;
230
+ /**
231
+ * area in which you can drag
232
+ */
233
+ type DSSelectorArea = HTMLElement;
234
+ /**
235
+ * the elements that can be selected
236
+ */
237
+ type DSInputElements = Array<HTMLElement | SVGElement> | HTMLElement | SVGElement;
238
+ /**
239
+ * the elements that can be selected
240
+ */
241
+ type DSElements = Array<HTMLElement | SVGElement>;
242
+ /**
243
+ * a single element that can be selected
244
+ */
245
+ type DSElement = HTMLElement | SVGElement;
246
+ /**
247
+ * en event from a touch or mouse interaction
248
+ */
249
+ type DSEvent = MouseEvent | TouchEvent | PointerEvent;
250
+ /**
251
+ * An array of keys that allows switching to the multi-select mode
252
+ */
253
+ type DSMultiSelectKeys = Array<'Shift' | 'Control' | 'Meta' | string>;
254
+ type DSEventNames = 'dragmove' | 'autoscroll' | 'dragstart' | 'elementselect' | 'elementunselect' | 'callback';
255
+ type DSInternalEventNames = 'Interaction:init' | 'Interaction:start' | 'Interaction:end' | 'Interaction:update' | 'Area:modified' | 'Area:scroll' | 'PointerStore:updated' | 'Selected:added' | 'Selected:removed' | 'Selectable:click' | 'Selectable:added' | 'Selectable:removed' | 'Selectable:pointer' | 'KeyStore:down' | 'KeyStore:up';
256
+ type DSInternalEventNamesPre = 'Interaction:init:pre' | 'Interaction:start:pre' | 'Interaction:end:pre' | 'Interaction:update:pre' | 'Area:modified:pre' | 'Area:scroll:pre' | 'PointerStore:updated:pre' | 'Selected:added:pre' | 'Selected:removed:pre' | 'Selectable:click:pre' | 'Selectable:added:pre' | 'Selectable:removed:pre' | 'Selectable:pointer:pre' | 'KeyStore:down:pre' | 'KeyStore:up:pre';
257
+ type DSInternalSettingEvents = 'Settings:updated' | 'Settings:updated:pre' | 'Settings:updated:*' | 'Settings:updated:*:pre';
258
+ /**
259
+ * the name of the callback
260
+ */
261
+ type DSCallbackNames = DSEventNames | DSInternalEventNames | DSInternalEventNamesPre | DSInternalSettingEvents;
262
+ type DSBoundingRect = {
263
+ top: number;
264
+ left: number;
265
+ bottom: number;
266
+ right: number;
267
+ width: number;
268
+ height: number;
269
+ };
270
+ type DSDragKeys = {
271
+ up: string[];
272
+ down: string[];
273
+ left: string[];
274
+ right: string[];
275
+ };
276
+ type DSModificationCallback = (event: any) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dragselect",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "Easy JavaScript library for selecting and moving elements. With no dependencies. Drag-Select & Drag-And-Drop.",
5
5
  "main": "./dist/DragSelect.js",
6
6
  "module": "./dist/DragSelect.esm.js",
@@ -52,7 +52,7 @@
52
52
  "minami": "^1.2.3",
53
53
  "prettier": "^3.0.3",
54
54
  "puppeteer": "21.3.1",
55
- "rollup": "^3.29.2",
55
+ "rollup": "^3.29.5",
56
56
  "rollup-plugin-dts": "^6.0.2",
57
57
  "rollup-plugin-terser": "^7.0.2",
58
58
  "ts-jest": "^29.1.1",