dragselect 2.7.4 → 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 +97 -23
- 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 -3886
- package/dist/DragSelect.js +0 -3894
- 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 -43
- package/dist/modules/SelectedSet.d.ts +0 -32
- 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 -149
- package/src/modules/SelectedSet.js +0 -72
- 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/README.md
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
</p>
|
|
16
16
|
<p align="center" style="text-align: center; margin-bottom: 50px;">
|
|
17
17
|
<a href="https://github.com/ThibaultJanBeyer/DragSelect/actions"><img alt="Build Status" src="https://github.com/ThibaultJanBeyer/DragSelect/actions/workflows/github-actions-build.yml/badge.svg"></a>
|
|
18
|
-
<a href="https://
|
|
18
|
+
<a href="https://unpkg.com/dragselect@latest/dist/ds.min.js"><img alt="gzip size" src="https://img.badgesize.io/https://unpkg.com/dragselect@latest/dist/ds.min.js?compression=gzip"></a>
|
|
19
19
|
<a href="https://www.npmjs.com/package/dragselect"><img alt="npm downloads count" src="https://img.shields.io/npm/dt/dragselect.svg"></a>
|
|
20
20
|
<a href="https://github.com/ThibaultJanBeyer/DragSelect/blob/master/DragSelect/package.json"><img alt="No Dependency" src="https://img.shields.io/badge/dependencies-none-informational"></a>
|
|
21
21
|
<a href="https://github.com/ThibaultJanBeyer/DragSelect/blob/master/CONTRIBUTING.md"><img alt="Contributors Welcome" src="https://img.shields.io/badge/contributors-welcome-blueviolet"></a>
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
</p>
|
|
24
24
|
|
|
25
25
|
# DragSelect [](https://GitHub.com/ThibaultJanBeyer/DragSelect/releases/)
|
|
26
|
+
|
|
26
27
|
easily add a selection algorithm to your application/website.
|
|
27
28
|
|
|
28
29
|
The project page is [https://dragselect.com/](https://dragselect.com/). And you find the [documentation there](http://dragselect.com/docs/intro).
|
package/jest-puppeteer.config.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
let jest_puppeteer_conf = {
|
|
2
2
|
launch: {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
4
|
+
timeout: 30000,
|
|
5
|
+
headless: 'new',
|
|
6
|
+
dumpio: true, // Whether to pipe the browser process stdout and stderr
|
|
5
7
|
},
|
|
6
8
|
}
|
|
9
|
+
|
|
10
|
+
if (process.env.DEBUG) {
|
|
11
|
+
jest_puppeteer_conf.launch.headless = false // for debug: to see what the browser is displaying
|
|
12
|
+
// jest_puppeteer_conf.launch.slowMo = 250; // slow down by 250ms for each step
|
|
13
|
+
jest_puppeteer_conf.launch.devtools = true // This lets you debug code in the application code browser
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = jest_puppeteer_conf
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dragselect",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Easy JavaScript library for selecting and moving elements. With no dependencies. Drag-Select & Drag-And-Drop.",
|
|
5
5
|
"main": "./dist/DragSelect.js",
|
|
6
6
|
"types": "./dist/DragSelect.d.ts",
|
|
@@ -8,60 +8,54 @@
|
|
|
8
8
|
"open": "open __tests__/quicktest.html -a 'Google Chrome'",
|
|
9
9
|
"prestart": "yarn",
|
|
10
10
|
"start": "yarn open & yarn watch",
|
|
11
|
-
"watch": "concurrently --kill-others \"yarn
|
|
11
|
+
"watch": "concurrently --kill-others \"yarn rollup:watch\" \"yarn test:watch\"",
|
|
12
12
|
"\n# TESTING:": "",
|
|
13
|
-
"checkjs": "tsc --lib es2019,dom -t es5 --allowJs --skipLibCheck --checkJs --noEmit src/*.js",
|
|
14
|
-
"checkjs:watch": "yarn checkjs -- -w",
|
|
15
13
|
"pretest": "yarn build",
|
|
16
|
-
"
|
|
17
|
-
"test": "
|
|
18
|
-
"test:watch": "yarn jest --
|
|
14
|
+
"test": "yarn jest",
|
|
15
|
+
"test:debug": "DEBUG=true yarn jest",
|
|
16
|
+
"test:watch": "yarn jest --watch",
|
|
19
17
|
"\n# BUILDING:": "",
|
|
20
18
|
"prebuild": "yarn install",
|
|
21
19
|
"build": "yarn rollup",
|
|
22
|
-
"prerollup": "yarn types",
|
|
23
20
|
"rollup": "rollup -c",
|
|
24
|
-
"rollup:watch": "yarn rollup
|
|
25
|
-
"types": "tsc src/DragSelect.js --lib es2019,dom -t es5 --declaration --allowJs --emitDeclarationOnly --skipLibCheck --outDir dist"
|
|
21
|
+
"rollup:watch": "yarn rollup -w"
|
|
26
22
|
},
|
|
27
23
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"eslint-
|
|
46
|
-
"eslint-
|
|
47
|
-
"eslint-
|
|
48
|
-
"eslint-plugin-
|
|
49
|
-
"eslint-plugin-
|
|
50
|
-
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
51
|
-
"eslint-plugin-prettier": "^3.3.1",
|
|
52
|
-
"eslint-plugin-react": "^7.22.0",
|
|
53
|
-
"eslint-plugin-react-hooks": "^4.2.0",
|
|
54
|
-
"eslint-plugin-security": "^1.4.0",
|
|
24
|
+
"@jest/globals": "^29.7.0",
|
|
25
|
+
"@rollup/plugin-node-resolve": "^15.2.1",
|
|
26
|
+
"@rollup/plugin-typescript": "^11.1.3",
|
|
27
|
+
"@types/expect-puppeteer": "^5.0.3",
|
|
28
|
+
"@types/jest": "^29.5.5",
|
|
29
|
+
"@types/jest-environment-puppeteer": "^5.0.4",
|
|
30
|
+
"@types/puppeteer": "^7.0.4",
|
|
31
|
+
"@typescript-eslint/eslint-plugin-tslint": "^6.7.2",
|
|
32
|
+
"@typescript-eslint/parser": "^6.7.2",
|
|
33
|
+
"better-docs": "^2.7.2",
|
|
34
|
+
"concurrently": "^8.2.1",
|
|
35
|
+
"eslint": "^8.49.0",
|
|
36
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
37
|
+
"eslint-config-prettier": "^9.0.0",
|
|
38
|
+
"eslint-config-standard": "^17.1.0",
|
|
39
|
+
"eslint-plugin-import": "^2.28.1",
|
|
40
|
+
"eslint-plugin-jest": "^27.4.0",
|
|
41
|
+
"eslint-plugin-jsx-a11y": "^6.7.1",
|
|
42
|
+
"eslint-plugin-prettier": "^5.0.0",
|
|
43
|
+
"eslint-plugin-react": "^7.33.2",
|
|
44
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
45
|
+
"eslint-plugin-security": "^1.7.1",
|
|
55
46
|
"eslint-plugin-standard": "^5.0.0",
|
|
56
|
-
"glob": "^
|
|
57
|
-
"jest": "^
|
|
58
|
-
"jest-
|
|
47
|
+
"glob": "^10.3.5",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
50
|
+
"jest-puppeteer": "^9.0.0",
|
|
59
51
|
"minami": "^1.2.3",
|
|
60
|
-
"prettier": "^
|
|
61
|
-
"puppeteer": "
|
|
62
|
-
"rollup": "^
|
|
52
|
+
"prettier": "^3.0.3",
|
|
53
|
+
"puppeteer": "21.3.1",
|
|
54
|
+
"rollup": "^3.29.2",
|
|
55
|
+
"rollup-plugin-dts": "^6.0.2",
|
|
63
56
|
"rollup-plugin-terser": "^7.0.2",
|
|
64
|
-
"
|
|
57
|
+
"ts-jest": "^29.1.1",
|
|
58
|
+
"typescript": "^5.2.2"
|
|
65
59
|
},
|
|
66
60
|
"repository": {
|
|
67
61
|
"type": "git",
|
|
@@ -76,9 +70,9 @@
|
|
|
76
70
|
"vanillajs"
|
|
77
71
|
],
|
|
78
72
|
"author": "Thibault Jan Beyer",
|
|
79
|
-
"license": "
|
|
73
|
+
"license": "GPLv3",
|
|
80
74
|
"bugs": {
|
|
81
75
|
"url": "https://github.com/ThibaultJanBeyer/DragSelect/issues"
|
|
82
76
|
},
|
|
83
|
-
"homepage": "https://
|
|
77
|
+
"homepage": "https://DragSelect.com/"
|
|
84
78
|
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import resolve from '@rollup/plugin-node-resolve'
|
|
2
|
+
import { terser } from 'rollup-plugin-terser'
|
|
3
|
+
import typescript from '@rollup/plugin-typescript'
|
|
4
|
+
import dts from 'rollup-plugin-dts'
|
|
5
|
+
|
|
6
|
+
const banner = `/***
|
|
7
|
+
|
|
8
|
+
~~~ Version ${process.env.npm_package_version} ~~~
|
|
9
|
+
|
|
10
|
+
******************************************
|
|
11
|
+
|
|
12
|
+
____ _____ __ __
|
|
13
|
+
/ __ \\_________ _____ _/ ___/___ / /__ _____/ /_
|
|
14
|
+
/ / / / ___/ __ \`/ __ \`/\\__ \\/ _ \\/ / _ \\/ ___/ __/
|
|
15
|
+
/ /_/ / / / /_/ / /_/ /___/ / __/ / __/ /__/ /_
|
|
16
|
+
/_____/_/ \\__,_/\\__, //____/\\___/_/\\___/\\___/\\__/
|
|
17
|
+
/____/
|
|
18
|
+
|
|
19
|
+
******************************************
|
|
20
|
+
|
|
21
|
+
{*} {*} STAR THIS PROJECT ON GITHUB {*} {*}
|
|
22
|
+
|
|
23
|
+
https://github.com/ThibaultJanBeyer/DragSelect
|
|
24
|
+
Please give it a like, this is what makes me happy :-)
|
|
25
|
+
Thank You
|
|
26
|
+
|
|
27
|
+
{*} {*} STAR THIS PROJECT ON GITHUB {*} {*}
|
|
28
|
+
|
|
29
|
+
***************************************
|
|
30
|
+
********* GPLv3 / Commercial **********
|
|
31
|
+
***************************************
|
|
32
|
+
Created 2017 by ThibaultJanBeyer
|
|
33
|
+
Web: http://www.DragSelect.com/
|
|
34
|
+
GitHub: https://github.com/ThibaultJanBeyer/DragSelect
|
|
35
|
+
***************************************
|
|
36
|
+
*/`
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @type {import('rollup').RollupOptions}
|
|
40
|
+
*/
|
|
41
|
+
export default [
|
|
42
|
+
{
|
|
43
|
+
input: 'src/DragSelect.ts',
|
|
44
|
+
output: [
|
|
45
|
+
{
|
|
46
|
+
file: 'dist/DragSelect.es6m.js',
|
|
47
|
+
format: 'es',
|
|
48
|
+
name: 'DragSelect',
|
|
49
|
+
banner,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
file: 'dist/DragSelect.js',
|
|
53
|
+
format: 'umd',
|
|
54
|
+
name: 'DragSelect',
|
|
55
|
+
banner,
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
file: 'dist/ds.es6m.min.js',
|
|
59
|
+
format: 'es',
|
|
60
|
+
name: 'DragSelect',
|
|
61
|
+
compact: true,
|
|
62
|
+
plugins: [terser()],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
file: 'dist/ds.min.js',
|
|
66
|
+
format: 'umd',
|
|
67
|
+
name: 'DragSelect',
|
|
68
|
+
compact: true,
|
|
69
|
+
plugins: [terser()],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
plugins: [typescript(), resolve()],
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
input: `src/DragSelect.ts`,
|
|
76
|
+
plugins: [dts()],
|
|
77
|
+
output: {
|
|
78
|
+
file: `dist/DragSelect.d.ts`,
|
|
79
|
+
format: 'es',
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
]
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/*
|
|
2
|
+
____ _____ __ __
|
|
3
|
+
/ __ \_________ _____ _/ ___/___ / /__ _____/ /_
|
|
4
|
+
/ / / / ___/ __ `/ __ `/\__ \/ _ \/ / _ \/ ___/ __/
|
|
5
|
+
/ /_/ / / / /_/ / /_/ /___/ / __/ / __/ /__/ /_
|
|
6
|
+
/_____/_/ \__,_/\__, //____/\___/_/\___/\___/\__/
|
|
7
|
+
/____/
|
|
8
|
+
|
|
9
|
+
{*} {*} STAR THIS PROJECT ON GITHUB {*} {*}
|
|
10
|
+
|
|
11
|
+
https://github.com/ThibaultJanBeyer/DragSelect
|
|
12
|
+
Please give it a like, this is what makes me happy :-)
|
|
13
|
+
Thank You
|
|
14
|
+
|
|
15
|
+
{*} {*} STAR THIS PROJECT ON GITHUB {*} {*}
|
|
16
|
+
|
|
17
|
+
***************************************
|
|
18
|
+
********* GPLv3 / Commercial **********
|
|
19
|
+
***************************************
|
|
20
|
+
Created 2017 by ThibaultJanBeyer
|
|
21
|
+
Web: http://www.DragSelect.com/
|
|
22
|
+
GitHub: https://github.com/ThibaultJanBeyer/DragSelect
|
|
23
|
+
***************************************
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import Area from './modules/Area'
|
|
27
|
+
import Drag from './modules/Drag'
|
|
28
|
+
import DropZones from './modules/DropZones'
|
|
29
|
+
import Interaction from './modules/Interaction'
|
|
30
|
+
import KeyStore from './stores/KeyStore'
|
|
31
|
+
import PointerStore from './stores/PointerStore'
|
|
32
|
+
import PubSub, {
|
|
33
|
+
type DSCallback,
|
|
34
|
+
type DSPublishMappings,
|
|
35
|
+
} from './modules/PubSub'
|
|
36
|
+
import ScrollStore from './stores/ScrollStore'
|
|
37
|
+
import SelectableSet from './modules/SelectableSet'
|
|
38
|
+
import SelectedSet from './modules/SelectedSet'
|
|
39
|
+
import Selector from './modules/Selector'
|
|
40
|
+
import Selection from './modules/Selection'
|
|
41
|
+
import SelectorArea from './modules/SelectorArea'
|
|
42
|
+
import SettingsStore from './stores/SettingsStore'
|
|
43
|
+
import {
|
|
44
|
+
type DSCallbackName,
|
|
45
|
+
type DSInputElement,
|
|
46
|
+
type Settings,
|
|
47
|
+
type Vect2,
|
|
48
|
+
} from './types'
|
|
49
|
+
import { IsCollision, isCollision } from './methods/isCollision'
|
|
50
|
+
import {
|
|
51
|
+
type DSPublicPublish,
|
|
52
|
+
deprecatedNamesMap,
|
|
53
|
+
subscriberAliases,
|
|
54
|
+
} from './methods/subscriberAliases'
|
|
55
|
+
import { ensureArray } from './methods/ensureArray'
|
|
56
|
+
import { DSDropZone } from './modules/DropZone'
|
|
57
|
+
|
|
58
|
+
// Setup
|
|
59
|
+
/// ///////////////////////////////////////////////////////////////////////////////////
|
|
60
|
+
|
|
61
|
+
class DragSelect<E extends DSInputElement> {
|
|
62
|
+
/** used to skip all current Selection and dragNdrop functionality */
|
|
63
|
+
public continue: boolean = false
|
|
64
|
+
private PubSub: PubSub<E>
|
|
65
|
+
public stores: {
|
|
66
|
+
SettingsStore: SettingsStore<E>
|
|
67
|
+
PointerStore: PointerStore<E>
|
|
68
|
+
ScrollStore: ScrollStore<E>
|
|
69
|
+
KeyStore: KeyStore<E>
|
|
70
|
+
}
|
|
71
|
+
public Area: Area<E>
|
|
72
|
+
public Selector: Selector<E>
|
|
73
|
+
public SelectorArea: SelectorArea<E>
|
|
74
|
+
public SelectableSet: SelectableSet<E>
|
|
75
|
+
public SelectedSet: SelectedSet<E>
|
|
76
|
+
public Selection: Selection<E>
|
|
77
|
+
private Drag: Drag<E>
|
|
78
|
+
public DropZones: DropZones<E>
|
|
79
|
+
public Interaction: Interaction<E>
|
|
80
|
+
public stopped: boolean
|
|
81
|
+
|
|
82
|
+
constructor(settings: Settings<E>) {
|
|
83
|
+
this.stopped = false
|
|
84
|
+
|
|
85
|
+
this.PubSub = new PubSub({ DS: this })
|
|
86
|
+
|
|
87
|
+
this.stores = {} as {
|
|
88
|
+
SettingsStore: SettingsStore<E>
|
|
89
|
+
PointerStore: PointerStore<E>
|
|
90
|
+
ScrollStore: ScrollStore<E>
|
|
91
|
+
KeyStore: KeyStore<E>
|
|
92
|
+
}
|
|
93
|
+
;(this.stores.SettingsStore = new SettingsStore({
|
|
94
|
+
settings,
|
|
95
|
+
PS: this.PubSub,
|
|
96
|
+
})),
|
|
97
|
+
(this.stores.PointerStore = new PointerStore({
|
|
98
|
+
DS: this,
|
|
99
|
+
PS: this.PubSub,
|
|
100
|
+
})),
|
|
101
|
+
(this.stores.ScrollStore = new ScrollStore({
|
|
102
|
+
DS: this,
|
|
103
|
+
PS: this.PubSub,
|
|
104
|
+
})),
|
|
105
|
+
(this.stores.KeyStore = new KeyStore({ DS: this, PS: this.PubSub })),
|
|
106
|
+
(this.Area = new Area({ DS: this, PS: this.PubSub }))
|
|
107
|
+
this.Selector = new Selector({ DS: this, PS: this.PubSub })
|
|
108
|
+
this.SelectorArea = new SelectorArea({ DS: this, PS: this.PubSub })
|
|
109
|
+
|
|
110
|
+
this.SelectableSet = new SelectableSet({ DS: this, PS: this.PubSub })
|
|
111
|
+
this.SelectedSet = new SelectedSet({ DS: this, PS: this.PubSub })
|
|
112
|
+
this.Selection = new Selection({ DS: this, PS: this.PubSub })
|
|
113
|
+
|
|
114
|
+
this.Drag = new Drag({ DS: this, PS: this.PubSub })
|
|
115
|
+
this.DropZones = new DropZones({ DS: this, PS: this.PubSub })
|
|
116
|
+
this.Interaction = new Interaction({ DS: this, PS: this.PubSub })
|
|
117
|
+
|
|
118
|
+
subscriberAliases({ DS: this, PS: this.PubSub })
|
|
119
|
+
|
|
120
|
+
this.PubSub.subscribe('Interaction:end', () => (this.continue = false))
|
|
121
|
+
this.PubSub.subscribe('DS:end', ({ items }) => (this.continue = false))
|
|
122
|
+
|
|
123
|
+
this.start()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Useful methods for the user
|
|
127
|
+
//////////////////////////////////////////////////////////////////////////////////////
|
|
128
|
+
|
|
129
|
+
public static isCollision: IsCollision
|
|
130
|
+
|
|
131
|
+
// any input data from the user is valid in this public PubSub but the exposed values are recommended
|
|
132
|
+
/** Subscribe to events */
|
|
133
|
+
public subscribe = <T extends keyof DSPublicPublish<E>>(
|
|
134
|
+
eventName: T,
|
|
135
|
+
callback: DSCallback<DSPublishMappings<E>[T]>
|
|
136
|
+
) => {
|
|
137
|
+
// Deprecation warnings
|
|
138
|
+
if (deprecatedNamesMap[eventName as keyof typeof deprecatedNamesMap])
|
|
139
|
+
console.warn(
|
|
140
|
+
`[DragSelect]: The event name "${eventName}" is deprecated and was/will be removed in a future version. Please use the new event name "${
|
|
141
|
+
deprecatedNamesMap[eventName as keyof typeof deprecatedNamesMap]
|
|
142
|
+
}" instead.`
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
this.PubSub.subscribe(eventName, callback)
|
|
146
|
+
}
|
|
147
|
+
/** Un-Subscribe from events */
|
|
148
|
+
public unsubscribe = <T extends keyof DSPublicPublish<E>>(
|
|
149
|
+
eventName: T,
|
|
150
|
+
callback?: DSCallback<DSPublishMappings<E>[T]>,
|
|
151
|
+
id?: number
|
|
152
|
+
) => this.PubSub.unsubscribe(eventName, callback, id)
|
|
153
|
+
/** Publish events */
|
|
154
|
+
public publish = <T extends DSCallbackName<E>>(
|
|
155
|
+
eventName: T | T[],
|
|
156
|
+
data: DSPublishMappings<E>[T]
|
|
157
|
+
) => this.PubSub.publish(eventName, data)
|
|
158
|
+
|
|
159
|
+
/** Initializes the functionality. Automatically triggered when created. Also, reset the functionality after a teardown */
|
|
160
|
+
public start = () => {
|
|
161
|
+
this.stopped = false
|
|
162
|
+
this.Interaction.init()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Complete function teardown
|
|
167
|
+
* Will teardown/stop the whole functionality
|
|
168
|
+
* @param remove if elements should be removed.
|
|
169
|
+
* @param fromSelection if elements should also be added/removed to the selection.
|
|
170
|
+
* @param withCallback if elements should also be added/removed to the selection.
|
|
171
|
+
*/
|
|
172
|
+
public stop(
|
|
173
|
+
remove: boolean = true,
|
|
174
|
+
fromSelection: boolean = true,
|
|
175
|
+
withCallback: boolean = false
|
|
176
|
+
) {
|
|
177
|
+
if (withCallback)
|
|
178
|
+
this.publish('DS:end', {
|
|
179
|
+
items: this.SelectedSet.elements,
|
|
180
|
+
isDragging: this.Interaction.isDragging,
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
this.Interaction.stop()
|
|
184
|
+
this.Area.stop()
|
|
185
|
+
this.Drag.stop()
|
|
186
|
+
this.Selector.stop()
|
|
187
|
+
this.SelectorArea.stop(remove)
|
|
188
|
+
this.stores.KeyStore.stop()
|
|
189
|
+
this.stores.PointerStore.stop()
|
|
190
|
+
this.stores.ScrollStore.stop()
|
|
191
|
+
|
|
192
|
+
if (remove) this.SelectableSet.clear()
|
|
193
|
+
if (fromSelection) this.SelectedSet.clear()
|
|
194
|
+
|
|
195
|
+
this.stopped = true
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Utility to override DragSelect internal functionality:
|
|
200
|
+
* Break will skip the selection or dragging functionality (until after the callback) but let everything continue to run.
|
|
201
|
+
* Useful utility to write your own functionality/move/dragNdrop based on DragSelect pointer positions.
|
|
202
|
+
*/
|
|
203
|
+
public break = () => (this.continue = true)
|
|
204
|
+
|
|
205
|
+
/** Update any setting dynamically */
|
|
206
|
+
public setSettings = (settings: Settings<E>) =>
|
|
207
|
+
this.stores.SettingsStore.update({ settings })
|
|
208
|
+
|
|
209
|
+
/** Returns the current selected nodes */
|
|
210
|
+
public getSelection = () => this.SelectedSet.elements
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Adds several elements to the selection list also adds the specific classes and take into account all calculations.
|
|
214
|
+
* Does not clear the selection, in contrary to .setSelection. Can add multiple elements at once
|
|
215
|
+
* @param elements one or multiple elements
|
|
216
|
+
* @param triggerCallback if callback should be called
|
|
217
|
+
* @param dontAddToSelectables if element should not be added to the list of selectable elements
|
|
218
|
+
* @return all selected elements
|
|
219
|
+
*/
|
|
220
|
+
public addSelection(
|
|
221
|
+
elements: E | E[],
|
|
222
|
+
triggerCallback: boolean = false,
|
|
223
|
+
dontAddToSelectables: boolean = false
|
|
224
|
+
) {
|
|
225
|
+
const els = ensureArray(elements)
|
|
226
|
+
this.SelectedSet.addAll(els)
|
|
227
|
+
if (!dontAddToSelectables) this.addSelectables(elements, false, false)
|
|
228
|
+
if (triggerCallback)
|
|
229
|
+
this.PubSub.publish('DS:end', {
|
|
230
|
+
items: this.SelectedSet.elements,
|
|
231
|
+
isDragging: this.Interaction.isDragging,
|
|
232
|
+
})
|
|
233
|
+
return this.getSelection()
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Removes specific elements from the selection
|
|
238
|
+
* Multiple elements can be given at once, in contrary to unselect
|
|
239
|
+
* @param elements one or multiple elements
|
|
240
|
+
* @param triggerCallback if callback should be called
|
|
241
|
+
* @param removeFromSelectables if element should be removed from the list of selectable elements
|
|
242
|
+
* @return all selected elements
|
|
243
|
+
*/
|
|
244
|
+
public removeSelection(
|
|
245
|
+
elements: E | E[],
|
|
246
|
+
triggerCallback: boolean = false,
|
|
247
|
+
removeFromSelectables: boolean = false
|
|
248
|
+
) {
|
|
249
|
+
const els = ensureArray(elements)
|
|
250
|
+
this.SelectedSet.deleteAll(els)
|
|
251
|
+
if (removeFromSelectables) this.removeSelectables(elements, false, false)
|
|
252
|
+
if (triggerCallback)
|
|
253
|
+
this.PubSub.publish('DS:end', {
|
|
254
|
+
items: this.SelectedSet.elements,
|
|
255
|
+
isDragging: this.Interaction.isDragging,
|
|
256
|
+
})
|
|
257
|
+
return this.getSelection()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Toggles specific elements from the selection:
|
|
262
|
+
* If element is not in selection it will be added, if it is already selected, it will be removed.
|
|
263
|
+
* Multiple elements can be given at once.
|
|
264
|
+
* @param elements one or multiple elements
|
|
265
|
+
* @param triggerCallback if callback should be called
|
|
266
|
+
* @param removeFromSelectables if element should not be added/removed to the list of selectable elements accordingly
|
|
267
|
+
* @return all selected elements
|
|
268
|
+
*/
|
|
269
|
+
public toggleSelection(
|
|
270
|
+
elements: E | E[],
|
|
271
|
+
triggerCallback: boolean = false,
|
|
272
|
+
removeFromSelectables: boolean = false
|
|
273
|
+
) {
|
|
274
|
+
const els = ensureArray(elements)
|
|
275
|
+
els.forEach((el: E) =>
|
|
276
|
+
this.SelectedSet.has(el)
|
|
277
|
+
? this.removeSelection(elements, triggerCallback, removeFromSelectables)
|
|
278
|
+
: this.addSelection(elements, triggerCallback, removeFromSelectables)
|
|
279
|
+
)
|
|
280
|
+
if (triggerCallback)
|
|
281
|
+
this.PubSub.publish('DS:end', {
|
|
282
|
+
items: this.SelectedSet.elements,
|
|
283
|
+
isDragging: this.Interaction.isDragging,
|
|
284
|
+
})
|
|
285
|
+
return this.getSelection()
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Sets the current selected elements and optionally run the callback
|
|
290
|
+
* By default, adds new elements also to the list of selectables
|
|
291
|
+
* @param elements dom elements
|
|
292
|
+
* @param triggerCallback if callback should be called
|
|
293
|
+
* @param dontAddToSelectables if element should not be added to the list of selectable elements
|
|
294
|
+
*/
|
|
295
|
+
public setSelection(
|
|
296
|
+
elements: E | E[],
|
|
297
|
+
triggerCallback: boolean = false,
|
|
298
|
+
dontAddToSelectables: boolean = false
|
|
299
|
+
) {
|
|
300
|
+
this.clearSelection()
|
|
301
|
+
this.addSelection(elements, triggerCallback, dontAddToSelectables)
|
|
302
|
+
return this.getSelection()
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Unselect / Deselect all current selected Nodes
|
|
307
|
+
* @param triggerCallback if callback should be called
|
|
308
|
+
* @return this.selected, should be empty
|
|
309
|
+
*/
|
|
310
|
+
public clearSelection(triggerCallback: boolean = false) {
|
|
311
|
+
this.SelectedSet.clear()
|
|
312
|
+
if (triggerCallback)
|
|
313
|
+
this.PubSub.publish('DS:end', {
|
|
314
|
+
items: this.SelectedSet.elements,
|
|
315
|
+
isDragging: this.Interaction.isDragging,
|
|
316
|
+
})
|
|
317
|
+
return this.getSelection()
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Add elements that can be selected. No node is added twice
|
|
322
|
+
* @param elements dom element(s)
|
|
323
|
+
* @param addToSelection if elements should also be added to current selection
|
|
324
|
+
* @param triggerCallback if callback should be called
|
|
325
|
+
* @return the added element(s)
|
|
326
|
+
*/
|
|
327
|
+
public addSelectables(
|
|
328
|
+
elements: E | E[],
|
|
329
|
+
addToSelection?: boolean,
|
|
330
|
+
triggerCallback?: boolean
|
|
331
|
+
) {
|
|
332
|
+
const els = ensureArray(elements)
|
|
333
|
+
this.SelectableSet.addAll(els)
|
|
334
|
+
if (addToSelection) this.SelectedSet.addAll(els)
|
|
335
|
+
if (triggerCallback)
|
|
336
|
+
this.PubSub.publish('DS:end', {
|
|
337
|
+
items: this.SelectedSet.elements,
|
|
338
|
+
isDragging: this.Interaction.isDragging,
|
|
339
|
+
})
|
|
340
|
+
return els
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** Gets all nodes that can potentially be selected */
|
|
344
|
+
public getSelectables = () => this.SelectableSet.elements
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Remove elements from the elements that can be selected.
|
|
348
|
+
* @param elements dom element(s)
|
|
349
|
+
* @param removeFromSelection if elements should also be removed from current selection
|
|
350
|
+
* @param triggerCallback if callback should be called
|
|
351
|
+
* @return the removed element(s)
|
|
352
|
+
*/
|
|
353
|
+
public removeSelectables(
|
|
354
|
+
elements: E | E[],
|
|
355
|
+
removeFromSelection?: boolean,
|
|
356
|
+
triggerCallback?: boolean
|
|
357
|
+
) {
|
|
358
|
+
const els = ensureArray(elements)
|
|
359
|
+
this.SelectableSet.deleteAll(els)
|
|
360
|
+
if (removeFromSelection) this.removeSelection(elements)
|
|
361
|
+
if (triggerCallback)
|
|
362
|
+
this.PubSub.publish('DS:end', {
|
|
363
|
+
items: this.SelectedSet.elements,
|
|
364
|
+
isDragging: this.Interaction.isDragging,
|
|
365
|
+
})
|
|
366
|
+
return els
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** The starting/initial position of the cursor/selector */
|
|
370
|
+
public getInitialCursorPosition = (): Vect2 =>
|
|
371
|
+
this.stores.PointerStore.initialVal
|
|
372
|
+
|
|
373
|
+
/** The last seen position of the cursor/selector */
|
|
374
|
+
public getCurrentCursorPosition = (): Vect2 =>
|
|
375
|
+
this.stores.PointerStore.currentVal
|
|
376
|
+
|
|
377
|
+
/** The previous position of the cursor/selector */
|
|
378
|
+
public getPreviousCursorPosition = (): Vect2 =>
|
|
379
|
+
this.stores.PointerStore.lastVal
|
|
380
|
+
|
|
381
|
+
/** The starting/initial position of the cursor/selector */
|
|
382
|
+
public getInitialCursorPositionArea = (): Vect2 =>
|
|
383
|
+
this.stores.PointerStore.initialValArea
|
|
384
|
+
|
|
385
|
+
/** The last seen position of the cursor/selector */
|
|
386
|
+
public getCurrentCursorPositionArea = (): Vect2 =>
|
|
387
|
+
this.stores.PointerStore.currentValArea
|
|
388
|
+
|
|
389
|
+
/** The previous position of the cursor/selector */
|
|
390
|
+
public getPreviousCursorPositionArea = (): Vect2 =>
|
|
391
|
+
this.stores.PointerStore.lastValArea
|
|
392
|
+
|
|
393
|
+
/** Whether the multi-selection key was pressed */
|
|
394
|
+
public isMultiSelect = (
|
|
395
|
+
event: MouseEvent | TouchEvent | PointerEvent | KeyboardEvent
|
|
396
|
+
): boolean => this.stores.KeyStore.isMultiSelectKeyPressed(event)
|
|
397
|
+
|
|
398
|
+
/** Whether the user is currently drag n dropping elements (instead of selection) */
|
|
399
|
+
public isDragging = (): boolean => this.Interaction.isDragging
|
|
400
|
+
|
|
401
|
+
/** Returns first DropsZone under coordinates, if no coordinated provided current pointer coordinates are used */
|
|
402
|
+
public getZoneByCoordinates = (
|
|
403
|
+
coordinates?: Vect2
|
|
404
|
+
): DSDropZone<E> | undefined =>
|
|
405
|
+
this.DropZones.getTarget({ coordinates })?.toObject()
|
|
406
|
+
|
|
407
|
+
/** Returns itemsDropped into zone by zone id */
|
|
408
|
+
public getItemsDroppedByZoneId = (zoneId: string) =>
|
|
409
|
+
this.DropZones.getItemsDroppedById(zoneId)
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Returns itemsInside by zone id
|
|
413
|
+
* @param addClasses whether or not to add/remove the "inside" classes to the items
|
|
414
|
+
*/
|
|
415
|
+
public getItemsInsideByZoneId = (zoneId: string, addClasses?: boolean) =>
|
|
416
|
+
this.DropZones.getItemsInsideById(zoneId, addClasses)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
DragSelect.isCollision = isCollision
|
|
420
|
+
export default DragSelect
|
|
421
|
+
export * from './types'
|
|
422
|
+
export type DSPubCallback<
|
|
423
|
+
T extends keyof DSPublicPublish<E>,
|
|
424
|
+
E extends DSInputElement = DSInputElement,
|
|
425
|
+
> = DSCallback<DSPublishMappings<E>[T]>
|