dragselect 3.0.2 → 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.
Files changed (51) hide show
  1. package/CHANGELOG.md +5 -1
  2. package/dist/{DragSelect.es6m.js → DragSelect.esm.js} +1 -1
  3. package/dist/DragSelect.js +1 -1
  4. package/package.json +2 -2
  5. package/src/DragSelect.ts +0 -425
  6. package/src/methods/addModificationObservers.ts +0 -51
  7. package/src/methods/canScroll.ts +0 -19
  8. package/src/methods/createSelectorAreaElement.ts +0 -8
  9. package/src/methods/createSelectorElement.ts +0 -13
  10. package/src/methods/debounce.ts +0 -31
  11. package/src/methods/ensureArray.ts +0 -13
  12. package/src/methods/getAllParentNodes.ts +0 -15
  13. package/src/methods/getAreaRect.ts +0 -27
  14. package/src/methods/getCurrentScroll.ts +0 -14
  15. package/src/methods/getDocumentScroll.ts +0 -5
  16. package/src/methods/getOverflowEdges.ts +0 -27
  17. package/src/methods/getPointerPos.ts +0 -9
  18. package/src/methods/getSelectionRect.ts +0 -29
  19. package/src/methods/getSelectorPosition.ts +0 -74
  20. package/src/methods/getStylePosition.spec.ts +0 -114
  21. package/src/methods/getStylePosition.ts +0 -83
  22. package/src/methods/handleElementPositionAttribute.ts +0 -15
  23. package/src/methods/handleKeyboardDragPosDifference.ts +0 -35
  24. package/src/methods/handleSelection.ts +0 -26
  25. package/src/methods/handleUnSelection.ts +0 -36
  26. package/src/methods/hydrateSettings.ts +0 -245
  27. package/src/methods/isCollision.ts +0 -66
  28. package/src/methods/limitDirection.ts +0 -36
  29. package/src/methods/moveElement.ts +0 -18
  30. package/src/methods/scrollElement.ts +0 -26
  31. package/src/methods/setStylePosition.ts +0 -16
  32. package/src/methods/subscriberAliases.ts +0 -240
  33. package/src/methods/updateElementStylePos.ts +0 -7
  34. package/src/methods/vect2.ts +0 -34
  35. package/src/modules/Area.ts +0 -169
  36. package/src/modules/Drag.ts +0 -236
  37. package/src/modules/DropZone.ts +0 -223
  38. package/src/modules/DropZones.ts +0 -151
  39. package/src/modules/Interaction.ts +0 -251
  40. package/src/modules/PubSub.ts +0 -111
  41. package/src/modules/SelectableSet.ts +0 -146
  42. package/src/modules/SelectedSet.ts +0 -92
  43. package/src/modules/Selection.ts +0 -133
  44. package/src/modules/Selector.ts +0 -81
  45. package/src/modules/SelectorArea.ts +0 -161
  46. package/src/stores/KeyStore.ts +0 -92
  47. package/src/stores/PointerStore.ts +0 -194
  48. package/src/stores/ScrollStore.ts +0 -87
  49. package/src/stores/SettingsStore.ts +0 -88
  50. package/src/types.ts +0 -158
  51. /package/dist/{ds.es6m.min.js → ds.esm.min.js} +0 -0
@@ -1,245 +0,0 @@
1
- import { DSInputElement, Settings } from "../types"
2
-
3
- const wrongTypeWarn = (key: string, type: string) =>
4
- console.warn(
5
- `[DragSelect] TypeIssue: setting "${key}" is not of type "${type}".`
6
- )
7
-
8
- const hydrateHelper = <K extends string, V>(key: K, value: V, withFallback?: boolean, fallback?: V): {
9
- [key in K]: V;
10
- } | {} => {
11
- // no value available
12
- if (value === undefined) return withFallback ? { [key]: fallback } : {}
13
- // force unsetting of a value
14
- if (value === null) return { [key]: null }
15
-
16
- // TypeCheck [GENERIC]
17
- let isAvailable = true // if it’s not undefined, it was set voluntarily
18
- let forceFallback = false
19
-
20
- // TypeCheck [String]
21
- const expectedString = typeof fallback === 'string'
22
- if (expectedString)
23
- isAvailable = typeof value === 'string' || value instanceof String
24
- if (expectedString && !isAvailable) {
25
- forceFallback = true
26
- wrongTypeWarn(key, 'string')
27
- }
28
-
29
- // TypeCheck [Number]
30
- const expectedNumber = !Number.isNaN(fallback) && typeof fallback === 'number'
31
- if (expectedNumber)
32
- isAvailable = !Number.isNaN(value) && typeof value === 'number'
33
- if (expectedNumber && !isAvailable) {
34
- forceFallback = true
35
- wrongTypeWarn(key, 'number')
36
- }
37
-
38
- // TypeCheck [Object]
39
- const expectedObject =
40
- Object.prototype.toString.call(fallback) === '[object Object]'
41
- if (expectedObject)
42
- isAvailable = Object.prototype.toString.call(value) === '[object Object]'
43
- if (expectedObject && !isAvailable) {
44
- forceFallback = true
45
- wrongTypeWarn(key, 'object')
46
- }
47
-
48
- // TypeCheck [Boolean]
49
- const expectedBoolean = typeof fallback === 'boolean'
50
- if (expectedBoolean) isAvailable = typeof value === 'boolean'
51
- if (expectedBoolean && !isAvailable) {
52
- forceFallback = true
53
- wrongTypeWarn(key, 'boolean')
54
- }
55
-
56
- // TypeCheck [Array]
57
- const expectedArray = Array.isArray(fallback)
58
- if (expectedArray) isAvailable = Array.isArray(value)
59
- if (expectedArray && !isAvailable) {
60
- forceFallback = true
61
- wrongTypeWarn(key, 'array')
62
- }
63
-
64
- const isFallback = forceFallback || withFallback
65
-
66
- // Special rule for [dragKeys]
67
- if (key === 'dragKeys' && isAvailable)
68
- return { [key]: Object.assign(fallback as {}, value) }
69
- if (key === 'dragKeys' && !isAvailable)
70
- return isFallback ? { [key]: fallback } : {}
71
-
72
- // Special rule for [dropZones]
73
- if (
74
- key === 'dropZones' &&
75
- isAvailable &&
76
- Array.isArray(value) &&
77
- new Set(value.map((v) => v.id)).size !== value.length
78
- )
79
- console.warn(
80
- `[DragSelect] UniqueConstraintsIssue: setting "dropZones" contains duplicate ids.`
81
- )
82
-
83
- if (isAvailable) return { [key]: value }
84
- if (isFallback) return { [key]: fallback }
85
- return {}
86
- }
87
-
88
- /**
89
- * This helper method creates the setting object,
90
- * - if the settings provided are of wrong type, the fallback value will be used
91
- * - - except for if settings are undefined or explicitly marked as "null"
92
- * - if "withfallback" is true, it will return the object with all settings:
93
- * - - if not provided from the settings object (or wrong type), the fallback will be used
94
- * (the fallback value for each setting is the last prop of the hydrateHelper)
95
- */
96
- export const hydrateSettings = <E extends DSInputElement>(settings: Settings<E>, withFallback: boolean): Required<Settings<E>> => ({
97
- ...hydrateHelper('area', settings.area, withFallback, document),
98
- ...hydrateHelper('selectables', settings.selectables, withFallback, null),
99
- ...hydrateHelper(
100
- 'autoScrollSpeed',
101
- settings.autoScrollSpeed,
102
- withFallback,
103
- 5
104
- ),
105
- ...hydrateHelper(
106
- 'overflowTolerance',
107
- settings.overflowTolerance,
108
- withFallback,
109
- { x: 25, y: 25 }
110
- ),
111
- ...hydrateHelper('zoom', settings.zoom, withFallback, 1),
112
- ...hydrateHelper('customStyles', settings.customStyles, withFallback, false),
113
- ...hydrateHelper(
114
- 'multiSelectMode',
115
- settings.multiSelectMode,
116
- withFallback,
117
- false
118
- ),
119
- ...hydrateHelper(
120
- 'multiSelectToggling',
121
- settings.multiSelectToggling,
122
- withFallback,
123
- true
124
- ),
125
- ...hydrateHelper('multiSelectKeys', settings.multiSelectKeys, withFallback, [
126
- 'Control',
127
- 'Shift',
128
- 'Meta',
129
- ]),
130
- ...hydrateHelper('selector', settings.selector, withFallback, null),
131
- ...hydrateHelper(
132
- 'selectionThreshold',
133
- settings.selectionThreshold,
134
- withFallback,
135
- 0
136
- ),
137
- ...hydrateHelper('draggability', settings.draggability, withFallback, true),
138
- ...hydrateHelper('immediateDrag', settings.immediateDrag, withFallback, true),
139
- ...hydrateHelper('keyboardDrag', settings.keyboardDrag, withFallback, true),
140
- ...hydrateHelper('dragKeys', settings.dragKeys, withFallback, {
141
- up: ['ArrowUp'],
142
- down: ['ArrowDown'],
143
- left: ['ArrowLeft'],
144
- right: ['ArrowRight'],
145
- }),
146
- ...hydrateHelper(
147
- 'keyboardDragSpeed',
148
- settings.keyboardDragSpeed,
149
- withFallback,
150
- 10
151
- ),
152
- ...hydrateHelper('useTransform', settings.useTransform, withFallback, true),
153
- ...hydrateHelper(
154
- 'refreshMemoryRate',
155
- settings.refreshMemoryRate,
156
- withFallback,
157
- 80
158
- ),
159
- ...hydrateHelper('dropZones', settings.dropZones, withFallback, []),
160
- ...hydrateHelper(
161
- 'dropInsideThreshold',
162
- settings.dropInsideThreshold,
163
- withFallback,
164
- 1
165
- ),
166
- ...hydrateHelper(
167
- 'dropTargetThreshold',
168
- settings.dropTargetThreshold,
169
- withFallback,
170
- 0
171
- ),
172
- ...hydrateHelper(
173
- 'usePointerEvents',
174
- settings.usePointerEvents,
175
- withFallback,
176
- false
177
- ),
178
- ...hydrateHelper('hoverClass', settings.hoverClass, withFallback, 'ds-hover'),
179
- ...hydrateHelper(
180
- 'selectableClass',
181
- settings.selectableClass,
182
- withFallback,
183
- 'ds-selectable'
184
- ),
185
- ...hydrateHelper(
186
- 'selectedClass',
187
- settings.selectedClass,
188
- withFallback,
189
- 'ds-selected'
190
- ),
191
- ...hydrateHelper(
192
- 'selectorClass',
193
- settings.selectorClass,
194
- withFallback,
195
- 'ds-selector'
196
- ),
197
- ...hydrateHelper(
198
- 'selectorAreaClass',
199
- settings.selectorAreaClass,
200
- withFallback,
201
- 'ds-selector-area'
202
- ),
203
- ...hydrateHelper(
204
- 'droppedTargetClass',
205
- settings.droppedTargetClass,
206
- withFallback,
207
- 'ds-dropped-target'
208
- ),
209
- ...hydrateHelper(
210
- 'droppedInsideClass',
211
- settings.droppedInsideClass,
212
- withFallback,
213
- 'ds-dropped-inside'
214
- ),
215
- ...hydrateHelper(
216
- 'droppableClass',
217
- settings.droppableClass,
218
- withFallback,
219
- 'ds-droppable'
220
- ),
221
- ...hydrateHelper(
222
- 'dropZoneClass',
223
- settings.dropZoneClass,
224
- withFallback,
225
- 'ds-dropzone'
226
- ),
227
- ...hydrateHelper(
228
- 'dropZoneReadyClass',
229
- settings.dropZoneReadyClass,
230
- withFallback,
231
- 'ds-dropzone-ready'
232
- ),
233
- ...hydrateHelper(
234
- 'dropZoneTargetClass',
235
- settings.dropZoneTargetClass,
236
- withFallback,
237
- 'ds-dropzone-target'
238
- ),
239
- ...hydrateHelper(
240
- 'dropZoneInsideClass',
241
- settings.dropZoneInsideClass,
242
- withFallback,
243
- 'ds-dropzone-inside'
244
- ),
245
- } as Required<Settings<E>>)
@@ -1,66 +0,0 @@
1
- // @ts-check
2
- import { type DSBoundingRectBase } from '../types'
3
-
4
- // [PUBLICLY EXPOSED METHOD]
5
-
6
- export type IsCollision = {
7
- /**
8
- * Axis-Aligned Bounding Box Collision Detection.
9
- * Imagine following Example:
10
- *
11
- *
12
- * b01
13
- * a01[1]a02
14
- * b02 b11
15
- * a11[2]a12
16
- * b12
17
- *
18
- *
19
- * to check if those two boxes collide we do this AABB calculation:
20
- * 1. a01 < a12 (left border pos box1 smaller than right border pos box2)
21
- * 2. a02 > a11 (right border pos box1 larger than left border pos box2)
22
- * 3. b01 < b12 (top border pos box1 smaller than bottom border pos box2)
23
- * 4. b02 > b11 (bottom border pos box1 larger than top border pos box2)
24
- * {@link https://en.wikipedia.org/wiki/Minimum_bounding_box#Axis-aligned_minimum_bounding_box Wikipedia}
25
- * {@link https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection MDN}
26
-
27
- * @param percent
28
- * 1 = the element has to be completely inside the other element
29
- * 0.8 = the element has to be 80% inside the other element
30
- * 0.5 = the element has to be 50% inside the other element
31
- * 0.2 = the element has to be 20% inside the other element
32
- * 0 = the element only has to touch the other element
33
- */
34
- (
35
- el1?: DSBoundingRectBase,
36
- el2?: DSBoundingRectBase,
37
- percent?: number
38
- ): boolean
39
- }
40
-
41
- export const isCollision: IsCollision = (el1, el2, percent = 0) => {
42
- if (!el1 || !el2) return false
43
-
44
- let element1 = el1
45
-
46
- if (percent > 0) {
47
- const widthPoint = (el1.right - el1.left) * percent
48
- const heightPoint = (el1.bottom - el1.top) * percent
49
- element1 = {
50
- left: el1.left + widthPoint,
51
- right: el1.right - widthPoint,
52
- top: el1.top + heightPoint,
53
- bottom: el1.bottom - heightPoint,
54
- }
55
- }
56
-
57
- if (
58
- element1.left < el2.right && // 1.
59
- element1.right > el2.left && // 2.
60
- element1.top < el2.bottom && // 3.
61
- element1.bottom > el2.top // 4.
62
- )
63
- return true
64
- // collision detected!
65
- return false
66
- }
@@ -1,36 +0,0 @@
1
- import SelectableSet from '../modules/SelectableSet'
2
- import SelectedSet from '../modules/SelectedSet'
3
- import { DSBoundingRect, DSInputElement, Vect2 } from '../types'
4
-
5
- type Props = {
6
- direction: Vect2
7
- containerRect: DSBoundingRect
8
- selectionRect: DSBoundingRect
9
- scrollAmount: Vect2
10
- }
11
-
12
- /**
13
- * Modify direction value so that the rect of draggable elements
14
- * does not exceed the boundaries of container rect
15
- */
16
- export const limitDirection = ({ containerRect, selectionRect, direction, scrollAmount }: Props) => {
17
- const delta = {
18
- top: containerRect.top - selectionRect.top + scrollAmount.y,
19
- left: containerRect.left - selectionRect.left + scrollAmount.x,
20
- bottom: containerRect.bottom - selectionRect.bottom + scrollAmount.y,
21
- right: containerRect.right - selectionRect.right + scrollAmount.x,
22
- }
23
-
24
- if(direction.x === 0 && direction.y === 0) return direction
25
- if (direction.y < 0) direction.y = Math.max(direction.y, delta.top)
26
- if (direction.x < 0) direction.x = Math.max(direction.x, delta.left)
27
- if (direction.y > 0) direction.y = Math.min(direction.y, delta.bottom)
28
- if (direction.x > 0) direction.x = Math.min(direction.x, delta.right)
29
-
30
- selectionRect.top += direction.y;
31
- selectionRect.bottom += direction.y;
32
- selectionRect.left += direction.x;
33
- selectionRect.right += direction.x;
34
-
35
- return direction
36
- }
@@ -1,18 +0,0 @@
1
- import { DSBoundingRect, DSInputElement, Vect2 } from "../types"
2
- import { getStylePosition } from "./getStylePosition"
3
- import { setStylePosition } from "./setStylePosition"
4
- import { calcVect } from "./vect2"
5
-
6
- type Props<E extends DSInputElement> = {
7
- element: E
8
- posDirection: Vect2
9
- containerRect: DSBoundingRect
10
- useTransform: boolean
11
- }
12
-
13
- /** Moves the element in a posDirection */
14
- export const moveElement = <E extends DSInputElement>({ element, posDirection, useTransform }: Props<E>) => {
15
- const elementPos = getStylePosition(element, useTransform)
16
- const newPos = calcVect(elementPos, '+', posDirection)
17
- setStylePosition(element, newPos, useTransform)
18
- }
@@ -1,26 +0,0 @@
1
- import { DSArea, DSEdges } from "../types"
2
-
3
- /** Scroll the element in the specified direction */
4
- export const scrollElement = (element?: DSArea, directions?: DSEdges, multiplier: number = 1) => {
5
- if (!directions?.length || !element) return
6
-
7
- const docEl =
8
- document &&
9
- document.documentElement &&
10
- document.documentElement.scrollTop &&
11
- document.documentElement
12
- const _element =
13
- element instanceof Document ? docEl || document.body : element
14
-
15
- const scrollTop = directions.includes('top') && _element.scrollTop > 0
16
- const scrollBot =
17
- directions.includes('bottom') && _element.scrollTop < _element.scrollHeight
18
- const scrollLeft = directions.includes('left') && _element.scrollLeft > 0
19
- const scrollRight =
20
- directions.includes('right') && _element.scrollLeft < _element.scrollWidth
21
-
22
- if (scrollTop) _element.scrollTop -= 1 * multiplier
23
- if (scrollBot) _element.scrollTop += 1 * multiplier
24
- if (scrollLeft) _element.scrollLeft -= 1 * multiplier
25
- if (scrollRight) _element.scrollLeft += 1 * multiplier
26
- }
@@ -1,16 +0,0 @@
1
- import { DSInputElement, Vect2 } from '../types'
2
-
3
- /** Sets the style position to the X and Y coordinates. Can handle translate and top/left */
4
- export const setStylePosition = <E extends DSInputElement>(element: E, values: Vect2, useTranslate: boolean) => {
5
- if (useTranslate) {
6
- const prevTransform = element.style.transform
7
- element.style.transform = `translate3d(${values.x}px,${
8
- values.y
9
- }px,1px) ${prevTransform.replace(/translate.*?\)/g, '')}`
10
- } else {
11
- element.style.left = `${values.x}px`
12
- element.style.top = `${values.y}px`
13
- }
14
-
15
- return element
16
- }
@@ -1,240 +0,0 @@
1
- import DragSelect from '../DragSelect'
2
- import PubSub, { DSPublishMappings } from '../modules/PubSub'
3
- import { DSAreaPublishEventData } from '../modules/Area'
4
- import { DSDropZone } from '../modules/DropZone'
5
- import { DSInteractionPublishEventData } from '../modules/Interaction'
6
- import { DSSelectedPublishEventData } from '../modules/SelectedSet'
7
- import { DSInputElement } from '../types'
8
-
9
- export type DSPublicPublishEventNames<E extends DSInputElement> =
10
- keyof DSPublicPublish<E>
11
-
12
- export type DSPublicPublishAdditionalEventData<E extends DSInputElement> = {
13
- /** The dropZone element that the element was dropped into (or the mouse is currently hovering over) */
14
- dropTarget?: DSDropZone<E>
15
- /** Selected Elements */
16
- items: E[]
17
- /** Whether the user is dragging or selecting */
18
- isDragging: boolean
19
- }
20
-
21
- type SelectionCB<E extends DSInputElement> = DSSelectedPublishEventData<E> & {
22
- /** Whether the user is dragging or selecting */
23
- isDragging: boolean
24
- }
25
-
26
- type ScrollCB<E extends DSInputElement> = Pick<
27
- DSAreaPublishEventData<E>,
28
- 'scroll_directions' | 'scroll_multiplier'
29
- > & {
30
- /** Selected Elements */
31
- items: E[]
32
- /** Whether the user is dragging or selecting */
33
- isDragging: boolean
34
- }
35
-
36
- type InteractionCB = DSInteractionPublishEventData
37
- type InteractionEndCB<E extends DSInputElement> =
38
- Partial<DSInteractionPublishEventData> & DSPublicPublishAdditionalEventData<E>
39
-
40
- export const deprecatedNamesMap = {
41
- elementselect: 'DS:select',
42
- elementunselect: 'DS:unselect',
43
- autoscroll: 'DS:scroll',
44
- dragstart: 'DS:start',
45
- dragmove: 'DS:update',
46
- callback: 'DS:end',
47
- preelementselect: 'DS:select:pre',
48
- preelementunselect: 'DS:unselect:pre',
49
- preautoscroll: 'DS:scroll:pre',
50
- predragstart: 'DS:start:pre',
51
- predragmove: 'DS:update:pre',
52
- precallback: 'DS:end:pre',
53
- }
54
-
55
- export type DSPublicPublish<E extends DSInputElement> = {
56
- // Selection Events
57
- preelementselect: SelectionCB<E>
58
- elementselect: SelectionCB<E>
59
- 'DS:select:pre': SelectionCB<E>
60
- 'DS:select': SelectionCB<E>
61
- preelementunselect: SelectionCB<E>
62
- elementunselect: SelectionCB<E>
63
- 'DS:unselect:pre': SelectionCB<E>
64
- 'DS:unselect': SelectionCB<E>
65
- // Selectables Events
66
- 'DS:added:pre': SelectionCB<E>
67
- 'DS:added': SelectionCB<E>
68
- 'DS:removed:pre': SelectionCB<E>
69
- 'DS:removed': SelectionCB<E>
70
- // Scroll Events
71
- preautoscroll: ScrollCB<E>
72
- autoscroll: ScrollCB<E>
73
- 'DS:scroll': ScrollCB<E>
74
- 'DS:scroll:pre': ScrollCB<E>
75
- // Interaction Start Events
76
- predragstart: InteractionCB
77
- dragstart: InteractionCB
78
- 'DS:start': InteractionCB
79
- 'DS:start:pre': InteractionCB
80
- // Interaction Update Events
81
- predragmove: InteractionCB
82
- dragmove: InteractionCB
83
- 'DS:update': InteractionCB
84
- 'DS:update:pre': InteractionCB
85
- // Interaction End Events
86
- precallback: InteractionEndCB<E>
87
- callback: InteractionEndCB<E>
88
- 'DS:end': InteractionEndCB<E>
89
- 'DS:end:pre': InteractionEndCB<E>
90
- }
91
-
92
- type UsedPublishNames =
93
- | 'Selected:added'
94
- | 'Selected:removed'
95
- | 'Selectable:added'
96
- | 'Selectable:removed'
97
- | 'Area:scroll'
98
- | 'Interaction:start'
99
- | 'Interaction:update'
100
- | 'Interaction:end'
101
-
102
- type UsedPublishMappings<E extends DSInputElement> = Pick<
103
- DSPublishMappings<E>,
104
- UsedPublishNames
105
- >
106
-
107
- type Condition<T, E extends DSInputElement> = (
108
- data: T,
109
- DS: DragSelect<E>
110
- ) => T | null
111
-
112
- type MappingObj<
113
- E extends DSInputElement,
114
- K extends keyof UsedPublishMappings<E>,
115
- > = {
116
- name: DSPublicPublishEventNames<E>
117
- condition?: Condition<UsedPublishMappings<E>[K], E>
118
- extraData?: Condition<UsedPublishMappings<E>[K], E>
119
- }
120
-
121
- type DSMappings<E extends DSInputElement> = {
122
- [K in keyof UsedPublishMappings<E>]: MappingObj<E, K>[]
123
- }
124
-
125
- const endExtraData = <E extends DSInputElement>(
126
- data: UsedPublishMappings<E>['Interaction:end'],
127
- DS: DragSelect<E>
128
- ) => {
129
- const target = DS.DropZones.getTarget(data)
130
- return {
131
- ...data,
132
- ...(target ? { dropTarget: target.toObject() } : {}),
133
- }
134
- }
135
-
136
- /** Maps internal events to external ones */
137
- export const subscriberAliases = <E extends DSInputElement>({
138
- PS,
139
- DS,
140
- }: {
141
- PS: PubSub<E>
142
- DS: DragSelect<E>
143
- }) => {
144
- const mapping: DSMappings<E> = {
145
- 'Selected:added': [
146
- { name: 'preelementselect' },
147
- { name: 'elementselect' },
148
- { name: 'DS:select:pre' },
149
- { name: 'DS:select' },
150
- ],
151
- 'Selected:removed': [
152
- { name: 'preelementunselect' },
153
- { name: 'elementunselect' },
154
- { name: 'DS:unselect:pre' },
155
- { name: 'DS:unselect' },
156
- ],
157
- 'Selectable:added': [{ name: 'DS:added:pre' }, { name: 'DS:added' }],
158
- 'Selectable:removed': [{ name: 'DS:removed:pre' }, { name: 'DS:removed' }],
159
- 'Area:scroll': [
160
- { name: 'preautoscroll' },
161
- { name: 'autoscroll' },
162
- { name: 'DS:scroll:pre' },
163
- { name: 'DS:scroll' },
164
- ],
165
- 'Interaction:start': [
166
- { name: 'predragstart' },
167
- { name: 'dragstart' },
168
- { name: 'DS:start:pre' },
169
- { name: 'DS:start' },
170
- ],
171
- 'Interaction:update': [
172
- { name: 'predragmove', condition: (data) => (data.event ? data : null) },
173
- { name: 'dragmove', condition: (data) => (data.event ? data : null) },
174
- {
175
- name: 'DS:update:pre',
176
- condition: (data) => (data.event ? data : null),
177
- },
178
- { name: 'DS:update', condition: (data) => (data.event ? data : null) },
179
- ],
180
- 'Interaction:end': [
181
- { name: 'precallback', extraData: (data, DS) => endExtraData(data, DS) },
182
- { name: 'callback', extraData: (data, DS) => endExtraData(data, DS) },
183
- { name: 'DS:end:pre', extraData: (data, DS) => endExtraData(data, DS) },
184
- { name: 'DS:end', extraData: (data, DS) => endExtraData(data, DS) },
185
- ],
186
- }
187
-
188
- for (const [sub_name, sub_pubs] of Object.entries(mapping) as [
189
- keyof UsedPublishMappings<E>,
190
- DSMappings<E>[keyof UsedPublishMappings<E>],
191
- ][])
192
- addSubscribers({ sub_name, sub_pubs, DS, PS })
193
- }
194
-
195
- const addSubscribers = <
196
- E extends DSInputElement,
197
- K extends keyof UsedPublishMappings<E>,
198
- >({
199
- sub_name,
200
- DS,
201
- PS,
202
- sub_pubs,
203
- }: {
204
- sub_name: K
205
- sub_pubs: DSMappings<E>[K]
206
- DS: DragSelect<E>
207
- PS: PubSub<E>
208
- }) => {
209
- // Subscribe to the internal event
210
- PS.subscribe(sub_name, (data) =>
211
- // publish to each of the mapped ones
212
- sub_pubs.forEach((sub_pub) => publish({ sub_pub, data, DS }))
213
- )
214
- }
215
-
216
- const publish = <
217
- E extends DSInputElement,
218
- K extends keyof UsedPublishMappings<E>,
219
- >({
220
- sub_pub,
221
- data,
222
- DS,
223
- }: {
224
- sub_pub: MappingObj<E, K>
225
- data: DSPublishMappings<E>[K]
226
- DS: DragSelect<E>
227
- }) => {
228
- // If the events condition is met, publish the external event
229
- const cleanedData = !sub_pub.condition ? data : sub_pub.condition(data, DS)
230
- if (cleanedData) {
231
- const extra = (sub_pub.extraData && sub_pub.extraData(data, DS)) || {}
232
- DS.publish(sub_pub.name, {
233
- // add extra data as needed
234
- items: DS.SelectedSet.elements,
235
- isDragging: DS.Interaction.isDragging,
236
- ...cleanedData,
237
- ...extra,
238
- })
239
- }
240
- }
@@ -1,7 +0,0 @@
1
- /** Updates element style left, top, width, height values according to pos input object */
2
- export default (element: HTMLElement, pos: { left?: number; top?:number; width?:number; height?:number }) => {
3
- if(pos.left) element.style.left = `${pos.left}px`
4
- if(pos.top) element.style.top = `${pos.top}px`
5
- if(pos.width) element.style.width = `${pos.width}px`
6
- if(pos.height) element.style.height = `${pos.height}px`
7
- }
@@ -1,34 +0,0 @@
1
- import { DSBoundingRect, DSBoundingRectBase, Vect2 } from "../types"
2
-
3
- type Operator = '+'|'-'|'*'|'/'
4
- export const calcVect = ({ x: x1, y: y1 }: Vect2, operator: Operator, { x: x2, y: y2 }: Vect2): Vect2 => {
5
- const calculations = {
6
- '+': {
7
- x: x1 + x2,
8
- y: y1 + y2,
9
- },
10
- '-': {
11
- x: x1 - x2,
12
- y: y1 - y2,
13
- },
14
- '*': {
15
- x: x1 * x2,
16
- y: y1 * y2,
17
- },
18
- '/': {
19
- x: x1 / x2,
20
- y: y1 / y2,
21
- },
22
- }
23
- return calculations[operator]
24
- }
25
- export const rect2vect = (rect: DSBoundingRectBase|DSBoundingRect): Vect2 => ({ x: rect.left, y: rect.top })
26
- export const vect2rect = (vect: Vect2, dimension: number = 0): DSBoundingRect => ({
27
- left: vect.x,
28
- top: vect.y,
29
- right: vect.x,
30
- bottom: vect.y,
31
- width: dimension,
32
- height: dimension,
33
- })
34
- export const num2vect = (n: number): Vect2 => ({ x: n, y: n })