dragselect 3.0.2 → 3.0.4

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 (53) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +1 -1
  3. package/dist/{DragSelect.es6m.js → DragSelect.esm.js} +11 -4
  4. package/dist/DragSelect.js +11 -4
  5. package/dist/{ds.es6m.min.js → ds.esm.min.js} +1 -1
  6. package/dist/ds.min.js +1 -1
  7. package/package.json +3 -3
  8. package/src/DragSelect.ts +0 -425
  9. package/src/methods/addModificationObservers.ts +0 -51
  10. package/src/methods/canScroll.ts +0 -19
  11. package/src/methods/createSelectorAreaElement.ts +0 -8
  12. package/src/methods/createSelectorElement.ts +0 -13
  13. package/src/methods/debounce.ts +0 -31
  14. package/src/methods/ensureArray.ts +0 -13
  15. package/src/methods/getAllParentNodes.ts +0 -15
  16. package/src/methods/getAreaRect.ts +0 -27
  17. package/src/methods/getCurrentScroll.ts +0 -14
  18. package/src/methods/getDocumentScroll.ts +0 -5
  19. package/src/methods/getOverflowEdges.ts +0 -27
  20. package/src/methods/getPointerPos.ts +0 -9
  21. package/src/methods/getSelectionRect.ts +0 -29
  22. package/src/methods/getSelectorPosition.ts +0 -74
  23. package/src/methods/getStylePosition.spec.ts +0 -114
  24. package/src/methods/getStylePosition.ts +0 -83
  25. package/src/methods/handleElementPositionAttribute.ts +0 -15
  26. package/src/methods/handleKeyboardDragPosDifference.ts +0 -35
  27. package/src/methods/handleSelection.ts +0 -26
  28. package/src/methods/handleUnSelection.ts +0 -36
  29. package/src/methods/hydrateSettings.ts +0 -245
  30. package/src/methods/isCollision.ts +0 -66
  31. package/src/methods/limitDirection.ts +0 -36
  32. package/src/methods/moveElement.ts +0 -18
  33. package/src/methods/scrollElement.ts +0 -26
  34. package/src/methods/setStylePosition.ts +0 -16
  35. package/src/methods/subscriberAliases.ts +0 -240
  36. package/src/methods/updateElementStylePos.ts +0 -7
  37. package/src/methods/vect2.ts +0 -34
  38. package/src/modules/Area.ts +0 -169
  39. package/src/modules/Drag.ts +0 -236
  40. package/src/modules/DropZone.ts +0 -223
  41. package/src/modules/DropZones.ts +0 -151
  42. package/src/modules/Interaction.ts +0 -251
  43. package/src/modules/PubSub.ts +0 -111
  44. package/src/modules/SelectableSet.ts +0 -146
  45. package/src/modules/SelectedSet.ts +0 -92
  46. package/src/modules/Selection.ts +0 -133
  47. package/src/modules/Selector.ts +0 -81
  48. package/src/modules/SelectorArea.ts +0 -161
  49. package/src/stores/KeyStore.ts +0 -92
  50. package/src/stores/PointerStore.ts +0 -194
  51. package/src/stores/ScrollStore.ts +0 -87
  52. package/src/stores/SettingsStore.ts +0 -88
  53. package/src/types.ts +0 -158
@@ -1,87 +0,0 @@
1
- import DragSelect from '../DragSelect'
2
- import PubSub from '../modules/PubSub'
3
- import { DSInputElement, Settings, Vect2 } from '../types'
4
- import { calcVect, num2vect } from '../methods/vect2'
5
- import { canScroll } from '../methods/canScroll'
6
- import { getCurrentScroll } from '../methods/getCurrentScroll'
7
-
8
- export default class ScrollStore<E extends DSInputElement> {
9
- private _initialVal: Vect2 = { x: 0, y: 0 }
10
- private _currentVal: Vect2 = { x: 0, y: 0 }
11
- private _canScroll?: boolean
12
- private DS: DragSelect<E>
13
- private PS: PubSub<E>
14
- private Settings: Required<Settings<E>>
15
-
16
- constructor({ DS, PS }: { DS: DragSelect<E>; PS: PubSub<E> }) {
17
- this.DS = DS
18
- this.PS = PS
19
- this.Settings = this.DS.stores.SettingsStore.s
20
- this.PS.subscribe('Area:modified', () => {
21
- this.stop()
22
- this.init()
23
- })
24
- this.PS.subscribe('Interaction:init', this.init)
25
- this.PS.subscribe('Interaction:start', () => this.start())
26
- this.PS.subscribe('Interaction:end', () => this.reset())
27
- }
28
-
29
- private init = () => this.addListeners()
30
-
31
- private addListeners = () =>
32
- this.DS.Area.HTMLNode.addEventListener('scroll', this.update)
33
- private removeListeners = () =>
34
- this.DS.Area.HTMLNode.removeEventListener('scroll', this.update)
35
-
36
- private start = () => {
37
- this._currentVal = this._initialVal = getCurrentScroll(
38
- this.DS.Area.HTMLNode
39
- )
40
- }
41
-
42
- private update = () =>
43
- (this._currentVal = getCurrentScroll(this.DS.Area.HTMLNode))
44
-
45
- public stop = () => {
46
- this.reset()
47
- this.removeListeners()
48
- }
49
-
50
- private reset = () => {
51
- this._initialVal = { x: 0, y: 0 }
52
- this._canScroll = undefined
53
- }
54
-
55
- public get canScroll() {
56
- if (typeof this._canScroll === 'boolean') return this._canScroll
57
- return (this._canScroll = canScroll(this.DS.Area.HTMLNode))
58
- }
59
-
60
- public get scrollAmount() {
61
- const scrollDiff = calcVect(this.currentVal, '-', this.initialVal)
62
-
63
- // if area is zoomed, the scroll values are skewed, we need to fix that manually :(
64
- const zoom = num2vect(this.Settings.zoom)
65
- const zoomScroll = calcVect(
66
- calcVect(scrollDiff, '*', zoom),
67
- '-',
68
- scrollDiff
69
- )
70
-
71
- return {
72
- x: scrollDiff.x + zoomScroll.x,
73
- y: scrollDiff.y + zoomScroll.y,
74
- }
75
- }
76
-
77
- private get initialVal() {
78
- if (!this._initialVal) return { x: 0, y: 0 }
79
- return this._initialVal
80
- }
81
-
82
- public get currentVal() {
83
- if (!this._currentVal)
84
- this._currentVal = getCurrentScroll(this.DS.Area.HTMLNode)
85
- return this._currentVal
86
- }
87
- }
@@ -1,88 +0,0 @@
1
- import { DSInputElement, Settings } from '../types'
2
- import DragSelect from '../DragSelect'
3
-
4
- import { hydrateSettings } from '../methods/hydrateSettings'
5
- import PubSub from '../modules/PubSub'
6
-
7
- type WithPostfix<T, Postfix extends string> = {
8
- [K in keyof T as K | `${string & K}${Postfix}`]: T[K];
9
- }
10
-
11
- export type DSSettings<E extends DSInputElement> = WithPostfix<Required<Settings<E>>, ':pre'>
12
-
13
- export type DSSettingsPublishEventNames = "Settings:updated:pre"|"Settings:updated"|`Settings:updated:${string}:pre`|`Settings:updated:${string}`
14
-
15
- export type DSSettingsPublishEventData<E extends DSInputElement> = {
16
- /** whether this is the initial settings call */
17
- 'settings:init': boolean;
18
- /** the settings being updates/manipulated/passed, holds all settings including the previous value. i.e. updating selectorClass will publish { settings: { ...settings, selectorClass: 'newVal', 'selectorClass:pre': 'oldVal' } } this is a deep cloned copy so manipulating it will have no effect */
19
- settings: DSSettings<E>;
20
- /** the new settings that are passed, not available on the initial settings call */
21
- 'settings:new'?: Settings<E>;
22
- };
23
-
24
- export type DSSettingsPublish<E extends DSInputElement> = {
25
- [K in DSSettingsPublishEventNames]: DSSettingsPublishEventData<E>;
26
- }
27
-
28
- export default class SettingsStore<E extends DSInputElement> {
29
- private _settings: DSSettings<E> = {} as DSSettings<E>
30
- /**
31
- * Holds the settings and their previous value `:pre`
32
- * @example {
33
- * autoScrollSpeed: 3,
34
- * 'autoScrollSpeed:pre': 5
35
- * }
36
- **/
37
- s: DSSettings<E> = {} as DSSettings<E>
38
- private PS: PubSub<E>
39
-
40
- /**
41
- * @class ScrollStore
42
- * @constructor ScrollStore
43
- * @param {{ DS:DragSelect, settings:Settings }} p
44
- * @ignore
45
- */
46
- constructor({
47
- PS,
48
- settings
49
- }: { PS: PubSub<E>, settings: Settings<E> }) {
50
- this.PS = PS
51
- this.update({ settings, init: true })
52
- }
53
-
54
- update = ({ settings, init }: { settings: Settings<E>, init?: boolean }) => {
55
- this.PS.publish('Settings:updated:pre', {
56
- settings: this._settings,
57
- 'settings:init': Boolean(init),
58
- 'settings:new': settings
59
- })
60
- this._update({ settings, init })
61
- }
62
-
63
- private _update = ({ settings = {}, init = false }: { settings?: Settings<E>, init?: boolean }) => {
64
- const _settings = hydrateSettings(settings, init)
65
-
66
- for (const [key, value] of Object.entries(_settings) as [keyof Settings<E>, DSSettings<E>[keyof Settings<E>]][]) {
67
- (<K extends keyof Settings<E>>(key: K, value: DSSettings<E>[K]) => {
68
- if (!(key in this._settings)) {
69
- Object.defineProperty(this.s, key, {
70
- get: () => this._settings[key],
71
- set: (newValue) => this.update({ settings: { [key]: newValue } }),
72
- })
73
- }
74
-
75
- this._settings[`${key}:pre` as K] = this._settings[key] // need to cast as K, see https://stackoverflow.com/a/76070928/3712591
76
- this._settings[key] = value
77
-
78
- const update = {
79
- settings: this._settings,
80
- 'settings:init': init,
81
- 'settings:new': settings
82
- }
83
- this.PS.publish('Settings:updated', update)
84
- this.PS.publish(`Settings:updated:${key}`, update)
85
- })(key, value); // method used for typecasting, see https://stackoverflow.com/q/76036535/3712591
86
- }
87
- }
88
- }
package/src/types.ts DELETED
@@ -1,158 +0,0 @@
1
- import { DSPublicPublishAdditionalEventData, DSPublicPublishEventNames } from "./methods/subscriberAliases"
2
- import { DSAreaPublishEventData, DSAreaPublishEventNames } from "./modules/Area"
3
- import { DSInteractionPublishEventData, DSInteractionPublishEventNames } from "./modules/Interaction"
4
- import { DSSelectablePublishEventData, DSSelectablePublishEventNames } from "./modules/SelectableSet"
5
- import { DSSelectedPublishEventData, DSSelectedPublishEventNames } from "./modules/SelectedSet"
6
- import { DSKeyStorePublishEventData, DSKeyStorePublishEventNames } from "./stores/KeyStore"
7
- import { DSPointerStorePublishEventData, DSPointerStorePublishEventNames } from "./stores/PointerStore"
8
- import { DSSettingsPublishEventData, DSSettingsPublishEventNames } from "./stores/SettingsStore"
9
-
10
- export type Vect2 = {
11
- x: number,
12
- y: number
13
- }
14
-
15
- export type Settings<E extends DSInputElement> = {
16
- /** area in which you can drag. If not provided it will be the whole document. Default Document */
17
- area?: HTMLElement | SVGElement | Document
18
- /** [=[]] the elements that can be selected. */
19
- selectables?: E | E[]
20
- /** [=5] Speed in which the area scrolls while selecting (if available). Unit is pixel per movement. */
21
- autoScrollSpeed?: number
22
- /** [={x:25,y:25}] Tolerance for autoScroll (how close one has to be near an edges for autoScroll to start). */
23
- overflowTolerance?: Vect2
24
- /** [=1] Zoom scale factor (in case of using CSS style transform: scale() which messes with real positions). Unit scale zoom. */
25
- zoom?: number
26
- /** [=false] if set to true, no styles (except for position absolute) will be applied by default */
27
- customStyles?: boolean
28
- /** [=false] Add newly selected elements to the selection instead of replacing them */
29
- multiSelectMode?: boolean
30
- /** [=true] Whether or not to toggle already active elements while multi-selecting */
31
- multiSelectToggling?: boolean
32
- /** [=['Control', 'Shift', 'Meta']] Keys that allows switching to the multi-select mode (see the multiSelectMode option). Any key value is possible ([see MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)). Note that the best support is given for <kbd>Control</kbd>, <kbd>Shift</kbd> and <kbd>Meta</kbd>. Provide an empty array `[]` if you want to turn off the functionality. */
33
- multiSelectKeys?: DSMultiSelectKeys
34
- /** [=HTMLElement] the square that will draw the selection */
35
- selector?: HTMLElement
36
- /** [=0] how much % of the element has to be selected to be considered selected (0 = just touching, 1 = inside the selection) */
37
- selectionThreshold?: number
38
- /** [=true] When a user is dragging on an already selected element, the selection is dragged. */
39
- draggability?: boolean
40
- /** [=true] Whether an element is draggable from the start or needs to be selected first */
41
- immediateDrag?: boolean
42
- /** [=true] Whether or not the user can drag with the keyboard (we don't recommend disabling it) */
43
- keyboardDrag?: boolean
44
- /** [={up:['ArrowUp'],down:['ArrowDown'],left:['ArrowLeft'],righ:['ArrowRight']}] The keys available to drag element using the keyboard. */
45
- dragKeys?: DSDragKeys
46
- /** [=10] The speed at which elements are dragged using the keyboard. In pixels per keydown. */
47
- keyboardDragSpeed?: number
48
- /** [=true] Whether to use hardware accelerated css transforms when dragging or top/left instead */
49
- useTransform?: boolean
50
- /** [=80] Refresh rate on memoization, higher numbers mean better performance but more lag if elements are moving, lower numbers mean less lag but worse performance. If none of your DOMNodes are moving, you can set it to a very high number to increase performance. Value in milliseconds. */
51
- refreshMemoryRate?: number
52
- /** [=[]] one or more drop-elements: where the selectables can be dropped into */
53
- dropZones?: DSInputDropZone<E>[]
54
- /** [=1] how much % of the item has to be inside the dropzone to be considered inside (0 = barely touching, 1 = completely inside) */
55
- dropInsideThreshold?: number
56
- /** [=0] how much % of the zone does the pointer has to be in to be considered a target (0 = anywhere in the zone, max: 0.5 = has to point at the center of the zone) */
57
- dropTargetThreshold?: number
58
- /** [=false] Whether to use Pointer Events to replace traditional Mouse or Touch Events. Useful for tools like Google Blockly. */
59
- usePointerEvents?: boolean
60
- /** [=ds-hover] the class assigned to the mouse hovered items */
61
- hoverClass?: string
62
- /** [=ds-selectable] the class assigned to the elements that can be selected */
63
- selectableClass?: string
64
- /** [=ds-selected] the class assigned to the selected items */
65
- selectedClass?: string
66
- /** [=ds-selector] the class assigned to the square selector helper */
67
- selectorClass?: string
68
- /** [=ds-selector-area] the class assigned to the square in which the selector resides. By default it's invisible */
69
- selectorAreaClass?: string
70
- /** [=ds-dropped-target] on an item corresponding the target dropzone. This is also the prefix for ds-dropped-target-${zone.id} */
71
- droppedTargetClass?: string
72
- /** [=ds-dropped-inside] on an item that is within its dropzone bounds after a drop. This is also the prefix for ds-dropped-inside-${zone.id} */
73
- droppedInsideClass?: string
74
- /** [=ds-droppable] on element that can be dropped into at least one container. This is also the prefix for ds-droppable-${zone.id} */
75
- droppableClass?: string
76
- /** [=ds-dropzone] on each dropZone */
77
- dropZoneClass?: string
78
- /** [=ds-dropzone-ready] on corresponding dropZone when element is dragged */
79
- dropZoneReadyClass?: string
80
- /** [=ds-dropzone-target] on dropZone that has elements from any successful target drop */
81
- dropZoneTargetClass?: string
82
- /** [=ds-dropzone-inside] on dropZone that has elements inside after any drop */
83
- dropZoneInsideClass?: string
84
- }
85
-
86
- export type DSCallbackObject<E extends DSInputElement> =
87
- Readonly<
88
- Partial<
89
- & DSSettingsPublishEventData<E>
90
- & DSAreaPublishEventData<E>
91
- & DSKeyStorePublishEventData
92
- & DSPointerStorePublishEventData
93
- & DSInteractionPublishEventData
94
- & DSSelectablePublishEventData<E>
95
- & DSSelectedPublishEventData<E>
96
- & DSPublicPublishAdditionalEventData<E>
97
- >
98
- >
99
-
100
- export type DSInputDropZone<E extends DSInputElement> = {
101
- /** can be any unique identifier of type string */
102
- id: string
103
- /** the dropzone itself */
104
- element: E // @TODO this would not be of type InputElement!
105
- /** elements that can be dropped into that zone. This is optional, by default it will be all selectables */
106
- droppables?: E[]
107
- }
108
-
109
- export type DSElementPos = {
110
- x: number,
111
- y: number,
112
- w: number,
113
- h: number,
114
- r: number,
115
- b: number
116
- }
117
-
118
- export type DSEdges = Array<'top'|'bottom'|'left'|'right'|undefined>
119
- export type DSEdgesObj = {top:number,bottom:number,left:number,right:number}
120
-
121
- /** area within which you can drag */
122
- export type DSArea = HTMLElement|SVGElement|Document
123
-
124
- /** area in which you can drag */
125
- export type DSSelectorArea = HTMLElement
126
-
127
- /** elements that can be selected */
128
- export type DSInputElement = HTMLElement | SVGElement
129
-
130
- /** element that can be selected */
131
- // export type DSElement = HTMLElement|SVGElement
132
-
133
- /** An array of keys that allows switching to the multi-select mode */
134
- export type DSMultiSelectKeys = Array<'Shift'|'Control'|'Meta'|string>
135
-
136
- export type DSEvent = KeyboardEvent|MouseEvent|PointerEvent|TouchEvent
137
-
138
- export type DSInternalEventName = DSSettingsPublishEventNames|DSAreaPublishEventNames|DSKeyStorePublishEventNames|DSPointerStorePublishEventNames|DSInteractionPublishEventNames|DSSelectablePublishEventNames|DSSelectedPublishEventNames
139
- export type DSCallbackName<E extends DSInputElement> = DSPublicPublishEventNames<E>|DSInternalEventName
140
-
141
- export type DSBoundingRectBase = {
142
- top: number,
143
- left: number,
144
- bottom: number,
145
- right: number,
146
- }
147
-
148
- export interface DSBoundingRect extends DSBoundingRectBase {
149
- width: number,
150
- height: number
151
- }
152
-
153
- export type DSDragKeys = {
154
- up: Array<string>,
155
- down: Array<string>,
156
- left: Array<string>,
157
- right: Array<string>
158
- }