dragselect 2.7.3 → 3.0.0
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 +100 -22
- package/LICENSE +690 -0
- package/README.md +2 -1
- package/jest-puppeteer.config.js +13 -3
- package/jest.config.js +5 -0
- package/package.json +40 -46
- package/rollup.config.mjs +82 -0
- package/src/DragSelect.ts +425 -0
- package/src/methods/addModificationObservers.ts +51 -0
- package/src/methods/canScroll.ts +19 -0
- package/src/methods/{createSelectorAreaElement.js → createSelectorAreaElement.ts} +1 -8
- package/src/methods/{createSelectorElement.js → createSelectorElement.ts} +1 -9
- package/src/methods/{debounce.js → debounce.ts} +5 -11
- package/src/methods/ensureArray.ts +13 -0
- package/src/methods/getAllParentNodes.ts +15 -0
- package/src/methods/{getAreaRect.js → getAreaRect.ts} +2 -6
- package/src/methods/getCurrentScroll.ts +14 -0
- package/src/methods/{documentScroll.js → getDocumentScroll.ts} +2 -2
- package/src/methods/{getOverflowEdges.js → getOverflowEdges.ts} +11 -11
- package/src/methods/getPointerPos.ts +9 -0
- package/src/methods/getSelectionRect.ts +29 -0
- package/src/methods/{getSelectorPosition.js → getSelectorPosition.ts} +11 -9
- package/src/methods/{getStylePosition.spec.js → getStylePosition.spec.ts} +9 -9
- package/src/methods/{getStylePosition.js → getStylePosition.ts} +5 -21
- package/src/methods/handleElementPositionAttribute.ts +15 -0
- package/src/methods/handleKeyboardDragPosDifference.ts +35 -0
- package/src/methods/handleSelection.ts +26 -0
- package/src/methods/{handleUnSelection.js → handleUnSelection.ts} +14 -14
- package/src/methods/{hydrateSettings.js → hydrateSettings.ts} +15 -26
- package/src/methods/isCollision.ts +66 -0
- package/src/methods/limitDirection.ts +36 -0
- package/src/methods/moveElement.ts +18 -0
- package/src/methods/{scrollElement.js → scrollElement.ts} +4 -10
- package/src/methods/{setStylePosition.js → setStylePosition.ts} +3 -11
- package/src/methods/subscriberAliases.ts +240 -0
- package/src/methods/updateElementStylePos.ts +7 -0
- package/src/methods/vect2.ts +34 -0
- package/src/modules/Area.ts +169 -0
- package/src/modules/Drag.ts +236 -0
- package/src/modules/{DropZone.js → DropZone.ts} +80 -119
- package/src/modules/DropZones.ts +151 -0
- package/src/modules/Interaction.ts +251 -0
- package/src/modules/PubSub.ts +111 -0
- package/src/modules/SelectableSet.ts +146 -0
- package/src/modules/SelectedSet.ts +92 -0
- package/src/modules/{Selection.js → Selection.ts} +59 -44
- package/src/modules/Selector.ts +81 -0
- package/src/modules/{SelectorArea.js → SelectorArea.ts} +58 -71
- package/src/stores/KeyStore.ts +92 -0
- package/src/stores/PointerStore.ts +194 -0
- package/src/stores/ScrollStore.ts +87 -0
- package/src/stores/SettingsStore.ts +88 -0
- package/src/types.ts +158 -0
- package/tsconfig.json +105 -0
- package/bower.json +0 -24
- package/dist/DragSelect.d.ts +0 -200
- package/dist/DragSelect.es6m.js +0 -3877
- package/dist/DragSelect.js +0 -3885
- package/dist/ds.es6m.min.js +0 -1
- package/dist/ds.min.js +0 -1
- package/dist/methods/addModificationObservers.d.ts +0 -11
- package/dist/methods/canScroll.d.ts +0 -3
- package/dist/methods/createSelectorAreaElement.d.ts +0 -3
- package/dist/methods/createSelectorElement.d.ts +0 -3
- package/dist/methods/debounce.d.ts +0 -3
- package/dist/methods/documentScroll.d.ts +0 -6
- package/dist/methods/getAllParentNodes.d.ts +0 -3
- package/dist/methods/getAreaRect.d.ts +0 -3
- package/dist/methods/getBoundingClientRect.d.ts +0 -4
- package/dist/methods/getCurrentScroll.d.ts +0 -3
- package/dist/methods/getOverflowEdges.d.ts +0 -7
- package/dist/methods/getPointerPos.d.ts +0 -5
- package/dist/methods/getSelectorPosition.d.ts +0 -12
- package/dist/methods/getStylePosition.d.ts +0 -3
- package/dist/methods/handleElementOverflow.d.ts +0 -10
- package/dist/methods/handleElementPositionAttribute.d.ts +0 -6
- package/dist/methods/handleKeyboardDragPosDifference.d.ts +0 -13
- package/dist/methods/handleSelection.d.ts +0 -9
- package/dist/methods/handleUnSelection.d.ts +0 -9
- package/dist/methods/hydrateSettings.d.ts +0 -3
- package/dist/methods/index.d.ts +0 -30
- package/dist/methods/isCollision.d.ts +0 -13
- package/dist/methods/moveElement.d.ts +0 -8
- package/dist/methods/removeModificationObservers.d.ts +0 -3
- package/dist/methods/scrollElement.d.ts +0 -3
- package/dist/methods/setStylePosition.d.ts +0 -3
- package/dist/methods/subscriberAliases.d.ts +0 -14
- package/dist/methods/toArray.d.ts +0 -3
- package/dist/methods/updateElementStylePos.d.ts +0 -8
- package/dist/methods/vect2.d.ts +0 -8
- package/dist/modules/Area.d.ts +0 -80
- package/dist/modules/Drag.d.ts +0 -71
- package/dist/modules/DropZone.d.ts +0 -90
- package/dist/modules/DropZones.d.ts +0 -73
- package/dist/modules/Interaction.d.ts +0 -51
- package/dist/modules/PubSub.d.ts +0 -37
- package/dist/modules/SelectableSet.d.ts +0 -40
- package/dist/modules/SelectedSet.d.ts +0 -29
- package/dist/modules/Selection.d.ts +0 -54
- package/dist/modules/Selector.d.ts +0 -29
- package/dist/modules/SelectorArea.d.ts +0 -58
- package/dist/modules/index.d.ts +0 -11
- package/dist/stores/KeyStore.d.ts +0 -34
- package/dist/stores/PointerStore.d.ts +0 -83
- package/dist/stores/ScrollStore.d.ts +0 -38
- package/dist/stores/SettingsStore.d.ts +0 -39
- package/dist/stores/index.d.ts +0 -5
- package/dist/types.d.ts +0 -276
- package/jsconfig.json +0 -13
- package/rollup.config.js +0 -101
- package/src/DragSelect.js +0 -384
- package/src/methods/addModificationObservers.js +0 -38
- package/src/methods/canScroll.js +0 -20
- package/src/methods/getAllParentNodes.js +0 -17
- package/src/methods/getBoundingClientRect.js +0 -33
- package/src/methods/getCurrentScroll.js +0 -15
- package/src/methods/getPointerPos.js +0 -13
- package/src/methods/handleElementOverflow.js +0 -65
- package/src/methods/handleElementPositionAttribute.js +0 -16
- package/src/methods/handleKeyboardDragPosDifference.js +0 -57
- package/src/methods/handleSelection.js +0 -26
- package/src/methods/index.js +0 -29
- package/src/methods/isCollision.js +0 -58
- package/src/methods/moveElement.js +0 -39
- package/src/methods/removeModificationObservers.js +0 -13
- package/src/methods/subscriberAliases.js +0 -72
- package/src/methods/toArray.js +0 -18
- package/src/methods/updateElementStylePos.js +0 -15
- package/src/methods/vect2.js +0 -54
- package/src/modules/Area.js +0 -183
- package/src/modules/Drag.js +0 -257
- package/src/modules/DropZones.js +0 -161
- package/src/modules/Interaction.js +0 -208
- package/src/modules/PubSub.js +0 -78
- package/src/modules/SelectableSet.js +0 -144
- package/src/modules/SelectedSet.js +0 -69
- package/src/modules/Selector.js +0 -90
- package/src/modules/index.js +0 -10
- package/src/stores/KeyStore.js +0 -83
- package/src/stores/PointerStore.js +0 -218
- package/src/stores/ScrollStore.js +0 -92
- package/src/stores/SettingsStore.js +0 -66
- package/src/stores/index.js +0 -4
- package/src/types.js +0 -100
package/src/methods/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export * as vect2 from './vect2'
|
|
2
|
-
export { default as addModificationObservers } from './addModificationObservers'
|
|
3
|
-
export { default as canScroll } from './canScroll'
|
|
4
|
-
export { default as createSelectorAreaElement } from './createSelectorAreaElement'
|
|
5
|
-
export { default as createSelectorElement } from './createSelectorElement'
|
|
6
|
-
export { default as debounce } from './debounce'
|
|
7
|
-
export { default as documentScroll } from './documentScroll'
|
|
8
|
-
export { default as getAllParentNodes } from './getAllParentNodes'
|
|
9
|
-
export { default as getAreaRect } from './getAreaRect'
|
|
10
|
-
export { default as getBoundingClientRect } from './getBoundingClientRect'
|
|
11
|
-
export { default as getCurrentScroll } from './getCurrentScroll'
|
|
12
|
-
export { default as getOverflowEdges } from './getOverflowEdges'
|
|
13
|
-
export { default as getPointerPos } from './getPointerPos'
|
|
14
|
-
export { default as getSelectorPosition } from './getSelectorPosition'
|
|
15
|
-
export { default as getStylePosition } from './getStylePosition'
|
|
16
|
-
export { default as handleElementOverflow } from './handleElementOverflow'
|
|
17
|
-
export { default as handleElementPositionAttribute } from './handleElementPositionAttribute'
|
|
18
|
-
export { default as handleKeyboardDragPosDifference } from './handleKeyboardDragPosDifference'
|
|
19
|
-
export { default as handleSelection } from './handleSelection'
|
|
20
|
-
export { default as handleUnSelection } from './handleUnSelection'
|
|
21
|
-
export { default as hydrateSettings } from './hydrateSettings'
|
|
22
|
-
export { default as isCollision } from './isCollision'
|
|
23
|
-
export { default as moveElement } from './moveElement'
|
|
24
|
-
export { default as removeModificationObservers } from './removeModificationObservers'
|
|
25
|
-
export { default as scrollElement } from './scrollElement'
|
|
26
|
-
export { default as setStylePosition } from './setStylePosition'
|
|
27
|
-
export { default as subscriberAliases } from './subscriberAliases'
|
|
28
|
-
export { default as toArray } from './toArray'
|
|
29
|
-
export { default as updateElementStylePos } from './updateElementStylePos'
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
// [PUBLICLY EXPOSED METHOD]
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Axis-Aligned Bounding Box Collision Detection.
|
|
8
|
-
* Imagine following Example:
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* b01
|
|
12
|
-
* a01[1]a02
|
|
13
|
-
* b02 b11
|
|
14
|
-
* a11[2]a12
|
|
15
|
-
* b12
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* to check if those two boxes collide we do this AABB calculation:
|
|
19
|
-
* 1. a01 < a12 (left border pos box1 smaller than right border pos box2)
|
|
20
|
-
* 2. a02 > a11 (right border pos box1 larger than left border pos box2)
|
|
21
|
-
* 3. b01 < b12 (top border pos box1 smaller than bottom border pos box2)
|
|
22
|
-
* 4. b02 > b11 (bottom border pos box1 larger than top border pos box2)
|
|
23
|
-
* {@link https://en.wikipedia.org/wiki/Minimum_bounding_box#Axis-aligned_minimum_bounding_box Wikipedia}
|
|
24
|
-
* {@link https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection MDN}
|
|
25
|
-
* @param {{left:number,right:number,top:number,bottom:number}} el1
|
|
26
|
-
* @param {{left:number,right:number,top:number,bottom:number}} el2
|
|
27
|
-
* @param {number} [percent=0]
|
|
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
|
-
* @returns {boolean}
|
|
34
|
-
*/
|
|
35
|
-
export default (el1, el2, percent = 0) => {
|
|
36
|
-
let element1 = el1
|
|
37
|
-
|
|
38
|
-
if (percent > 0) {
|
|
39
|
-
const widthPoint = (el1.right - el1.left) * percent
|
|
40
|
-
const heightPoint = (el1.bottom - el1.top) * percent
|
|
41
|
-
element1 = {
|
|
42
|
-
left: el1.left + widthPoint,
|
|
43
|
-
right: el1.right - widthPoint,
|
|
44
|
-
top: el1.top + heightPoint,
|
|
45
|
-
bottom: el1.bottom - heightPoint,
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
element1.left < el2.right && // 1.
|
|
51
|
-
element1.right > el2.left && // 2.
|
|
52
|
-
element1.top < el2.bottom && // 3.
|
|
53
|
-
element1.bottom > el2.top // 4.
|
|
54
|
-
)
|
|
55
|
-
return true
|
|
56
|
-
// collision detected!
|
|
57
|
-
return false
|
|
58
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
getStylePosition,
|
|
6
|
-
setStylePosition,
|
|
7
|
-
handleElementOverflow,
|
|
8
|
-
getOverflowEdges,
|
|
9
|
-
vect2,
|
|
10
|
-
} from './'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Moves the element in a posDirection
|
|
14
|
-
* @param {Object} p
|
|
15
|
-
* @param {DSElement} p.element
|
|
16
|
-
* @param {Vect2} p.posDirection
|
|
17
|
-
* @param {DSBoundingRect} p.containerRect
|
|
18
|
-
* @param {boolean} p.useTransform
|
|
19
|
-
*/
|
|
20
|
-
export default ({ element, posDirection, containerRect, useTransform }) => {
|
|
21
|
-
const elementPos = getStylePosition(element, useTransform)
|
|
22
|
-
const newPos = vect2.calc(elementPos, '+', posDirection)
|
|
23
|
-
setStylePosition(element, newPos, useTransform)
|
|
24
|
-
|
|
25
|
-
const elementRect = element.getBoundingClientRect()
|
|
26
|
-
const edges = getOverflowEdges({
|
|
27
|
-
elementRect,
|
|
28
|
-
containerRect,
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
handleElementOverflow({
|
|
32
|
-
element,
|
|
33
|
-
edges,
|
|
34
|
-
elementRect,
|
|
35
|
-
containerRect,
|
|
36
|
-
elementPos: newPos,
|
|
37
|
-
useTransform,
|
|
38
|
-
})
|
|
39
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Removes event-listeners to the selectorArea
|
|
6
|
-
* @param {MutationObserver} modificationObserver
|
|
7
|
-
* @param {DSModificationCallback} callback
|
|
8
|
-
*/
|
|
9
|
-
export default (modificationObserver, callback) => {
|
|
10
|
-
window.removeEventListener('resize', callback)
|
|
11
|
-
window.removeEventListener('scroll', callback)
|
|
12
|
-
modificationObserver.disconnect()
|
|
13
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import { DropZones, Interaction, SelectedSet } from '../modules'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {function} DSSubscribe
|
|
7
|
-
* @param {DSCallbackNames} eventName
|
|
8
|
-
* @param {DSCallback} callback
|
|
9
|
-
* @returns {number} event id, can be used to unsubscribe more efficiently
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {function} DSPublish
|
|
13
|
-
* @param {DSCallbackNames} eventName
|
|
14
|
-
* @param {CallbackObject} data passed to the subscription method
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Maps internal events to external ones
|
|
19
|
-
*
|
|
20
|
-
* @param {Object} p
|
|
21
|
-
* @param {DSSubscribe} p.subscribe
|
|
22
|
-
* @param {DSPublish} p.publish
|
|
23
|
-
* @param {Interaction} p.Interaction
|
|
24
|
-
* @param {SelectedSet} p.SelectedSet
|
|
25
|
-
* @param {DropZones} p.DropZones
|
|
26
|
-
*/
|
|
27
|
-
export default ({
|
|
28
|
-
subscribe,
|
|
29
|
-
publish,
|
|
30
|
-
Interaction,
|
|
31
|
-
SelectedSet,
|
|
32
|
-
DropZones,
|
|
33
|
-
}) => {
|
|
34
|
-
const mapping = {
|
|
35
|
-
'Selected:added': [{ name: 'elementselect' }],
|
|
36
|
-
'Selected:removed': [{ name: 'elementunselect' }],
|
|
37
|
-
'Area:scroll': [{ name: 'autoscroll' }], // scroll_directions, scroll_multiplier
|
|
38
|
-
'Interaction:start': [{ name: 'dragstart' }], // event, isDraggingKeyboard
|
|
39
|
-
'Interaction:update': [
|
|
40
|
-
// event, isDraggingKeyboard
|
|
41
|
-
{ name: 'dragmove', condition: (data) => data.event },
|
|
42
|
-
],
|
|
43
|
-
'Interaction:end': [
|
|
44
|
-
// event, isDraggingKeyboard
|
|
45
|
-
{
|
|
46
|
-
name: 'callback',
|
|
47
|
-
extraData: () => {
|
|
48
|
-
const target = DropZones.getTarget()
|
|
49
|
-
return {
|
|
50
|
-
...(target ? { dropTarget: target.toObject() } : {}),
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
for (const [sub_name, pubs] of Object.entries(mapping))
|
|
58
|
-
['pre', false].forEach((filler) =>
|
|
59
|
-
subscribe(filler ? `${sub_name}:${filler}` : sub_name, (data) =>
|
|
60
|
-
pubs.forEach(
|
|
61
|
-
(pub) =>
|
|
62
|
-
(!pub.condition || pub.condition(data)) &&
|
|
63
|
-
publish(filler ? `${filler}${pub.name}` : pub.name, {
|
|
64
|
-
items: SelectedSet.elements,
|
|
65
|
-
isDragging: Interaction.isDragging,
|
|
66
|
-
...data,
|
|
67
|
-
...(pub.extraData ? pub.extraData(data) : {}),
|
|
68
|
-
})
|
|
69
|
-
)
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
}
|
package/src/methods/toArray.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Transforms any list or single dom node to an array so user doesn’t have to care. Also removes duplicates.
|
|
6
|
-
* @param {DSInputElements} items a single item, a Node-list or any element group
|
|
7
|
-
* @return {DSElements}
|
|
8
|
-
*/
|
|
9
|
-
export default (items) => {
|
|
10
|
-
if (!items) return []
|
|
11
|
-
if (
|
|
12
|
-
!Array.isArray(items) &&
|
|
13
|
-
(items instanceof HTMLElement || items instanceof SVGElement)
|
|
14
|
-
)
|
|
15
|
-
return [items]
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return [...new Set([...items])]
|
|
18
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Updates element style left, top, width, height values
|
|
6
|
-
* according to pos input object.
|
|
7
|
-
* @param {HTMLElement} element
|
|
8
|
-
* @param {{left:number,top:number,width:number,height:number}} pos
|
|
9
|
-
*/
|
|
10
|
-
export default (element, pos) => {
|
|
11
|
-
element.style.left = `${pos.left}px`
|
|
12
|
-
element.style.top = `${pos.top}px`
|
|
13
|
-
element.style.width = `${pos.width}px`
|
|
14
|
-
element.style.height = `${pos.height}px`
|
|
15
|
-
}
|
package/src/methods/vect2.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Vect2} v1
|
|
6
|
-
* @param {'+'|'-'|'*'|'/'} operator
|
|
7
|
-
* @param {Vect2} v2
|
|
8
|
-
* @return {Vect2}
|
|
9
|
-
*/
|
|
10
|
-
export const calc = ({ x: x1, y: y1 }, operator, { x: x2, y: y2 }) => {
|
|
11
|
-
const calculations = {
|
|
12
|
-
'+': {
|
|
13
|
-
x: x1 + x2,
|
|
14
|
-
y: y1 + y2,
|
|
15
|
-
},
|
|
16
|
-
'-': {
|
|
17
|
-
x: x1 - x2,
|
|
18
|
-
y: y1 - y2,
|
|
19
|
-
},
|
|
20
|
-
'*': {
|
|
21
|
-
x: x1 * x2,
|
|
22
|
-
y: y1 * y2,
|
|
23
|
-
},
|
|
24
|
-
'/': {
|
|
25
|
-
x: x1 / x2,
|
|
26
|
-
y: y1 / y2,
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
return calculations[operator]
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @param {{left:number,top:number}} rect
|
|
34
|
-
* @returns {Vect2}
|
|
35
|
-
*/
|
|
36
|
-
export const rect2vect = (rect) => ({ x: rect.left, y: rect.top })
|
|
37
|
-
/**
|
|
38
|
-
* @param {Vect2} vect
|
|
39
|
-
* @param {number} dimension
|
|
40
|
-
* @returns {DSBoundingRect}
|
|
41
|
-
*/
|
|
42
|
-
export const vect2rect = (vect, dimension = 0) => ({
|
|
43
|
-
left: vect.x,
|
|
44
|
-
top: vect.y,
|
|
45
|
-
right: vect.x,
|
|
46
|
-
bottom: vect.y,
|
|
47
|
-
width: dimension,
|
|
48
|
-
height: dimension,
|
|
49
|
-
})
|
|
50
|
-
/**
|
|
51
|
-
* @param {number} n
|
|
52
|
-
* @returns {Vect2}
|
|
53
|
-
*/
|
|
54
|
-
export const num2vect = (n) => ({ x: n, y: n })
|
package/src/modules/Area.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import '../types'
|
|
3
|
-
import DragSelect from '../DragSelect'
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
addModificationObservers,
|
|
7
|
-
debounce,
|
|
8
|
-
getAreaRect,
|
|
9
|
-
scrollElement,
|
|
10
|
-
handleElementPositionAttribute,
|
|
11
|
-
getAllParentNodes,
|
|
12
|
-
} from '../methods'
|
|
13
|
-
|
|
14
|
-
export default class Area {
|
|
15
|
-
/**
|
|
16
|
-
* @type {DragSelect}
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
DS
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @type {{cleanup:() => void}}
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
_observers
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @type {DSArea}
|
|
29
|
-
* @private
|
|
30
|
-
*/
|
|
31
|
-
_node
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @type {DSArea[]}
|
|
35
|
-
* @private
|
|
36
|
-
*/
|
|
37
|
-
_parentNodes
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @type {CSSStyleDeclaration}
|
|
41
|
-
* @private
|
|
42
|
-
* */
|
|
43
|
-
_computedStyle
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @type {{top:number,bottom:number,left:number,right:number}}
|
|
47
|
-
* @private
|
|
48
|
-
* */
|
|
49
|
-
_computedBorder
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @type {DSBoundingRect}
|
|
53
|
-
* @private
|
|
54
|
-
* */
|
|
55
|
-
_rect
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @constructor Area
|
|
59
|
-
* @param {{DS:DragSelect}} p
|
|
60
|
-
* @ignore
|
|
61
|
-
*/
|
|
62
|
-
constructor({ DS }) {
|
|
63
|
-
this.DS = DS
|
|
64
|
-
|
|
65
|
-
this.setArea(this.DS.stores.SettingsStore.s.area)
|
|
66
|
-
// @ts-ignore: @todo: update to typescript
|
|
67
|
-
this.DS.PubSub.subscribe('Settings:updated:area', ({ settings }) => {
|
|
68
|
-
this.setArea(settings.area)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
this.DS.PubSub.subscribe('Interaction:init', this.start)
|
|
72
|
-
this.DS.PubSub.subscribe('Interaction:end', this.reset)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/** @param {DSArea} area */
|
|
76
|
-
setArea = (area) => {
|
|
77
|
-
this.reset()
|
|
78
|
-
this._node = area
|
|
79
|
-
handleElementPositionAttribute({
|
|
80
|
-
computedStyle: this.computedStyle,
|
|
81
|
-
node: this._node,
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
// first immediate debounce to update values after dom-update
|
|
85
|
-
setTimeout(() => {
|
|
86
|
-
this.DS.PubSub.publish('Area:modified:pre', { item: this })
|
|
87
|
-
this.reset()
|
|
88
|
-
this.DS.PubSub.publish('Area:modified', { item: this })
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
start = () => {
|
|
93
|
-
this._observers = addModificationObservers(
|
|
94
|
-
this.parentNodes,
|
|
95
|
-
debounce((event) => {
|
|
96
|
-
this.DS.PubSub.publish('Area:modified:pre', { event, item: this })
|
|
97
|
-
this.reset()
|
|
98
|
-
this.DS.PubSub.publish('Area:modified', { event, item: this })
|
|
99
|
-
}, 60)
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
reset = () => {
|
|
104
|
-
this._computedStyle = undefined
|
|
105
|
-
this._rect = undefined
|
|
106
|
-
this._computedBorder = undefined
|
|
107
|
-
this._parentNodes = undefined
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
stop = () => {
|
|
111
|
-
this._observers.cleanup()
|
|
112
|
-
this.reset()
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
116
|
-
// Scroll
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Scroll the area in the specified direction
|
|
120
|
-
* @param {Array.<'top'|'bottom'|'left'|'right'|undefined>} directions
|
|
121
|
-
* @param {number} multiplier
|
|
122
|
-
*/
|
|
123
|
-
scroll = (directions, multiplier) => {
|
|
124
|
-
const data = {
|
|
125
|
-
scroll_directions: directions,
|
|
126
|
-
scroll_multiplier: multiplier,
|
|
127
|
-
}
|
|
128
|
-
this.DS.PubSub.publish('Area:scroll:pre', data)
|
|
129
|
-
scrollElement(this._node, directions, multiplier)
|
|
130
|
-
this.DS.PubSub.publish('Area:scroll', data)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
134
|
-
// Node Getters
|
|
135
|
-
|
|
136
|
-
get HTMLNode() {
|
|
137
|
-
return /** @type {DSArea} */ (this._node)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* The computed border from the element (caches result)
|
|
142
|
-
* @type {{top:number,bottom:number,left:number,right:number}}
|
|
143
|
-
*/
|
|
144
|
-
get computedBorder() {
|
|
145
|
-
if (this._computedBorder) return this._computedBorder
|
|
146
|
-
return {
|
|
147
|
-
top: parseInt(this.computedStyle.borderTopWidth),
|
|
148
|
-
bottom: parseInt(this.computedStyle.borderBottomWidth),
|
|
149
|
-
left: parseInt(this.computedStyle.borderLeftWidth),
|
|
150
|
-
right: parseInt(this.computedStyle.borderRightWidth),
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* The computed styles from the element (caches result)
|
|
156
|
-
* @type {CSSStyleDeclaration}
|
|
157
|
-
*/
|
|
158
|
-
get computedStyle() {
|
|
159
|
-
if (this._computedStyle) return this._computedStyle
|
|
160
|
-
if (this.HTMLNode instanceof Document)
|
|
161
|
-
return (this._computedStyle = window.getComputedStyle(
|
|
162
|
-
this.HTMLNode.body || this.HTMLNode.documentElement
|
|
163
|
-
))
|
|
164
|
-
return (this._computedStyle = window.getComputedStyle(this.HTMLNode))
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* The element rect (caches result) (without scrollbar or borders)
|
|
169
|
-
* @type {DSBoundingRect}
|
|
170
|
-
*/
|
|
171
|
-
get rect() {
|
|
172
|
-
if (this._rect) return this._rect
|
|
173
|
-
return (this._rect = getAreaRect(
|
|
174
|
-
this.HTMLNode,
|
|
175
|
-
this.DS.stores.SettingsStore.s.zoom
|
|
176
|
-
))
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
get parentNodes() {
|
|
180
|
-
if (this._parentNodes) return this._parentNodes
|
|
181
|
-
return (this._parentNodes = getAllParentNodes(this.HTMLNode))
|
|
182
|
-
}
|
|
183
|
-
}
|