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
|
@@ -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
|
-
}
|
package/src/methods/vect2.ts
DELETED
|
@@ -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 })
|
package/src/modules/Area.ts
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import DragSelect from '../DragSelect'
|
|
2
|
-
import PubSub from './PubSub'
|
|
3
|
-
import {
|
|
4
|
-
DSArea,
|
|
5
|
-
DSBoundingRect,
|
|
6
|
-
DSEdges,
|
|
7
|
-
DSEdgesObj,
|
|
8
|
-
DSInputElement,
|
|
9
|
-
} from '../types'
|
|
10
|
-
import { DSSettings } from '../stores/SettingsStore'
|
|
11
|
-
import {
|
|
12
|
-
MutationCallbackEvent,
|
|
13
|
-
addModificationObservers,
|
|
14
|
-
} from '../methods/addModificationObservers'
|
|
15
|
-
import { debounce } from '../methods/debounce'
|
|
16
|
-
import { getAllParentNodes } from '../methods/getAllParentNodes'
|
|
17
|
-
import { getAreaRect } from '../methods/getAreaRect'
|
|
18
|
-
import { handleElementPositionAttribute } from '../methods/handleElementPositionAttribute'
|
|
19
|
-
import { scrollElement } from '../methods/scrollElement'
|
|
20
|
-
|
|
21
|
-
export type DSAreaPublishEventNames =
|
|
22
|
-
| 'Area:modified:pre'
|
|
23
|
-
| 'Area:modified'
|
|
24
|
-
| 'Area:scroll'
|
|
25
|
-
| 'Area:scroll:pre'
|
|
26
|
-
|
|
27
|
-
export type DSAreaPublishEventData<E extends DSInputElement> = {
|
|
28
|
-
/** The single item currently interacted with */
|
|
29
|
-
item: DSArea
|
|
30
|
-
/** The respective event object */
|
|
31
|
-
event?: MutationCallbackEvent
|
|
32
|
-
scroll_directions: DSEdges
|
|
33
|
-
scroll_multiplier: number
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export type DSAreaPublish<E extends DSInputElement> = {
|
|
37
|
-
'Area:modified:pre': Pick<DSAreaPublishEventData<E>, 'event' | 'item'>
|
|
38
|
-
'Area:modified': Pick<DSAreaPublishEventData<E>, 'event' | 'item'>
|
|
39
|
-
'Area:scroll:pre': Pick<
|
|
40
|
-
DSAreaPublishEventData<E>,
|
|
41
|
-
'scroll_directions' | 'scroll_multiplier'
|
|
42
|
-
>
|
|
43
|
-
'Area:scroll': Pick<
|
|
44
|
-
DSAreaPublishEventData<E>,
|
|
45
|
-
'scroll_directions' | 'scroll_multiplier'
|
|
46
|
-
>
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export default class Area<E extends DSInputElement> {
|
|
50
|
-
private DS: DragSelect<E>
|
|
51
|
-
private PS: PubSub<E>
|
|
52
|
-
private Settings: DSSettings<E>
|
|
53
|
-
private _observers?: { cleanup: () => void }
|
|
54
|
-
private _node: DSArea
|
|
55
|
-
private _parentNodes?: Node[]
|
|
56
|
-
private _computedStyle?: CSSStyleDeclaration
|
|
57
|
-
private _computedBorder?: DSEdgesObj
|
|
58
|
-
private _rect?: DSBoundingRect
|
|
59
|
-
|
|
60
|
-
constructor({ DS, PS }: { DS: DragSelect<E>; PS: PubSub<E> }) {
|
|
61
|
-
this.DS = DS
|
|
62
|
-
this.PS = PS
|
|
63
|
-
this.Settings = this.DS.stores.SettingsStore.s
|
|
64
|
-
|
|
65
|
-
this._node = this.Settings.area
|
|
66
|
-
this.setArea(this.Settings.area)
|
|
67
|
-
this.PS.subscribe('Settings:updated:area', ({ settings: { area } }) =>
|
|
68
|
-
this.setArea(area)
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
this.PS.subscribe('Interaction:init', this.init)
|
|
72
|
-
this.PS.subscribe('Interaction:end', this.reset)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private setArea = (area: DSArea) => {
|
|
76
|
-
this.reset()
|
|
77
|
-
this._node = area
|
|
78
|
-
handleElementPositionAttribute({
|
|
79
|
-
computedStyle: this.computedStyle,
|
|
80
|
-
node: this._node,
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
// first immediate debounce to update values after dom-update
|
|
84
|
-
setTimeout(() => {
|
|
85
|
-
this.PS.publish('Area:modified:pre', { item: this.HTMLNode })
|
|
86
|
-
this.reset()
|
|
87
|
-
this.PS.publish('Area:modified', { item: this.HTMLNode })
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private init = () => {
|
|
92
|
-
this._observers = addModificationObservers(
|
|
93
|
-
this.parentNodes,
|
|
94
|
-
debounce((event: MutationCallbackEvent) => {
|
|
95
|
-
this.PS.publish('Area:modified:pre', { event, item: this.HTMLNode })
|
|
96
|
-
this.reset()
|
|
97
|
-
this.PS.publish('Area:modified', { event, item: this.HTMLNode })
|
|
98
|
-
}, 60)
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private reset = () => {
|
|
103
|
-
this._computedStyle = undefined
|
|
104
|
-
this._rect = undefined
|
|
105
|
-
this._computedBorder = undefined
|
|
106
|
-
this._parentNodes = undefined
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
public stop = () => {
|
|
110
|
-
this._observers?.cleanup()
|
|
111
|
-
this.reset()
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
115
|
-
// Scroll
|
|
116
|
-
|
|
117
|
-
/** Scroll the area in the specified direction */
|
|
118
|
-
public scroll = (directions: DSEdges, multiplier: number) => {
|
|
119
|
-
const data = {
|
|
120
|
-
scroll_directions: directions,
|
|
121
|
-
scroll_multiplier: multiplier,
|
|
122
|
-
}
|
|
123
|
-
this.PS.publish('Area:scroll:pre', data)
|
|
124
|
-
scrollElement(this._node, directions, multiplier)
|
|
125
|
-
this.PS.publish('Area:scroll', data)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
129
|
-
// Node Getters
|
|
130
|
-
|
|
131
|
-
public get HTMLNode() {
|
|
132
|
-
return this._node
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** The computed border from the element (caches result) */
|
|
136
|
-
public get computedBorder() {
|
|
137
|
-
if (this._computedBorder) return this._computedBorder
|
|
138
|
-
return {
|
|
139
|
-
top: parseInt(this.computedStyle.borderTopWidth),
|
|
140
|
-
bottom: parseInt(this.computedStyle.borderBottomWidth),
|
|
141
|
-
left: parseInt(this.computedStyle.borderLeftWidth),
|
|
142
|
-
right: parseInt(this.computedStyle.borderRightWidth),
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/** The computed styles from the element (caches result) */
|
|
147
|
-
private get computedStyle() {
|
|
148
|
-
if (this._computedStyle) return this._computedStyle
|
|
149
|
-
if (this.HTMLNode instanceof Document)
|
|
150
|
-
return (this._computedStyle = window.getComputedStyle(
|
|
151
|
-
this.HTMLNode.body || this.HTMLNode.documentElement
|
|
152
|
-
))
|
|
153
|
-
return (this._computedStyle = window.getComputedStyle(this.HTMLNode!))
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/** The element rect (caches result) (without scrollbar or borders) */
|
|
157
|
-
public get rect() {
|
|
158
|
-
if (this._rect) return this._rect
|
|
159
|
-
return (this._rect = getAreaRect(
|
|
160
|
-
this.HTMLNode,
|
|
161
|
-
this.DS.stores.SettingsStore.s.zoom
|
|
162
|
-
))
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private get parentNodes() {
|
|
166
|
-
if (this._parentNodes) return this._parentNodes
|
|
167
|
-
return (this._parentNodes = getAllParentNodes(this.HTMLNode))
|
|
168
|
-
}
|
|
169
|
-
}
|