From 3fff54baab34d7e592902a41bad478d70f9cbe4d Mon Sep 17 00:00:00 2001 From: David Larlet Date: Mon, 23 Dec 2024 12:09:16 -0500 Subject: [PATCH 1/5] fix: zoom to droped file once loaded --- umap/static/umap/js/modules/importer.js | 11 ++++++++--- umap/static/umap/js/umap.controls.js | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/umap/static/umap/js/modules/importer.js b/umap/static/umap/js/modules/importer.js index 9d1d6180f..268b1d15e 100644 --- a/umap/static/umap/js/modules/importer.js +++ b/umap/static/umap/js/modules/importer.js @@ -124,6 +124,11 @@ export default class Importer extends Utils.WithTemplate { return this.qs('[type=file]').files } + set files(files) { + this.qs('[type=file]').files = files + this.onFileChange() + } + get raw() { return this.qs('textarea').value } @@ -213,11 +218,11 @@ export default class Importer extends Utils.WithTemplate { this.qs('[name=submit').toggleAttribute('disabled', !this.canSubmit()) } - onFileChange(e) { + onFileChange() { let type = '' let newType - for (const file of e.target.files) { - newType = U.Utils.detectFileType(file) + for (const file of this.files) { + newType = Utils.detectFileType(file) if (!type && newType) type = newType if (type && newType !== type) { type = '' diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 4cdcc15cc..350207df2 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -371,10 +371,10 @@ U.DropControl = L.Class.extend({ this.map.scrollWheelZoom.enable() this.dropzone.classList.remove('umap-dragover') L.DomEvent.stop(event) - for (const file of event.dataTransfer.files) { - this.map._umap.processFileToImport(file) - } - this.map._umap.onceDataLoaded(this.map._umap.fitDataBounds) + const importer = this.map._umap.importer + importer.build() + importer.files = event.dataTransfer.files + importer.submit() }, dragleave: function () { From 35ef460640d192cd3524ee2698448b0aa18f0e3f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:25:11 +0000 Subject: [PATCH 2/5] chore: bump moto[s3] from 5.0.21 to 5.0.24 Bumps [moto[s3]](https://github.com/getmoto/moto) from 5.0.21 to 5.0.24. - [Release notes](https://github.com/getmoto/moto/releases) - [Changelog](https://github.com/getmoto/moto/blob/master/CHANGELOG.md) - [Commits](https://github.com/getmoto/moto/compare/5.0.21...5.0.24) --- updated-dependencies: - dependency-name: moto[s3] dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 20c0cc63e..58593cd06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ test = [ "pytest-playwright==0.6.2", "pytest-rerunfailures==15.0", "pytest-xdist>=3.5.0,<4", - "moto[s3]==5.0.21" + "moto[s3]==5.0.24" ] docker = [ "uwsgi==2.0.28", From 8e9eaa5e3eb0c0d3a5440c84647da5dd75c73a7e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:25:17 +0000 Subject: [PATCH 3/5] chore: bump hatch from 1.13.0 to 1.14.0 Bumps [hatch](https://github.com/pypa/hatch) from 1.13.0 to 1.14.0. - [Release notes](https://github.com/pypa/hatch/releases) - [Commits](https://github.com/pypa/hatch/compare/hatch-v1.13.0...hatch-v1.14.0) --- updated-dependencies: - dependency-name: hatch dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 20c0cc63e..b8cffbfd1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ dependencies = [ [project.optional-dependencies] dev = [ - "hatch==1.13.0", + "hatch==1.14.0", "ruff==0.8.2", "djlint==1.36.3", "mkdocs==1.6.1", From e7b776d44d39dad0cb6e1ad88a444861518e5493 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:25:21 +0000 Subject: [PATCH 4/5] chore: bump pymdown-extensions from 10.12 to 10.13 Bumps [pymdown-extensions](https://github.com/facelessuser/pymdown-extensions) from 10.12 to 10.13. - [Release notes](https://github.com/facelessuser/pymdown-extensions/releases) - [Commits](https://github.com/facelessuser/pymdown-extensions/compare/10.12...10.13) --- updated-dependencies: - dependency-name: pymdown-extensions dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- docs-users/requirements.txt | 2 +- docs/requirements.txt | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs-users/requirements.txt b/docs-users/requirements.txt index f1bc6509d..6052f3fd7 100644 --- a/docs-users/requirements.txt +++ b/docs-users/requirements.txt @@ -1,5 +1,5 @@ # Force rtfd to use a recent version of mkdocs mkdocs==1.6.1 -pymdown-extensions==10.12 +pymdown-extensions==10.13 mkdocs-material==9.5.48 mkdocs-static-i18n==1.2.3 diff --git a/docs/requirements.txt b/docs/requirements.txt index f1bc6509d..6052f3fd7 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ # Force rtfd to use a recent version of mkdocs mkdocs==1.6.1 -pymdown-extensions==10.12 +pymdown-extensions==10.13 mkdocs-material==9.5.48 mkdocs-static-i18n==1.2.3 diff --git a/pyproject.toml b/pyproject.toml index 20c0cc63e..b9b9172ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ dev = [ "mkdocs-material==9.5.48", "mkdocs-static-i18n==1.2.3", "vermin==1.6.0", - "pymdown-extensions==10.12", + "pymdown-extensions==10.13", "isort==5.13.2", ] test = [ From 4cc8ae3d1fe295f2424592197e7b12af68253308 Mon Sep 17 00:00:00 2001 From: David Larlet Date: Mon, 23 Dec 2024 12:26:40 -0500 Subject: [PATCH 5/5] chore: extract DropControl to a module --- umap/static/umap/js/modules/drop.js | 55 ++++++++++++++++++++ umap/static/umap/js/modules/rendering/map.js | 3 +- umap/static/umap/js/umap.controls.js | 46 ---------------- 3 files changed, 57 insertions(+), 47 deletions(-) create mode 100644 umap/static/umap/js/modules/drop.js diff --git a/umap/static/umap/js/modules/drop.js b/umap/static/umap/js/modules/drop.js new file mode 100644 index 000000000..a757a6f05 --- /dev/null +++ b/umap/static/umap/js/modules/drop.js @@ -0,0 +1,55 @@ +export default class DropControl { + constructor(umap, leafletMap, dropzone) { + this._umap = umap + this._leafletMap = leafletMap + this.dropzone = dropzone + } + + enable() { + this.controller = new AbortController() + this.dropzone.addEventListener('dragenter', (e) => this.dragenter(e), { + signal: this.controller.signal, + }) + this.dropzone.addEventListener('dragover', (e) => this.dragover(e), { + signal: this.controller.signal, + }) + this.dropzone.addEventListener('drop', (e) => this.drop(e), { + signal: this.controller.signal, + }) + this.dropzone.addEventListener('dragleave', (e) => this.dragleave(e), { + signal: this.controller.signal, + }) + } + + disable() { + this.controller.abort() + } + + dragenter(event) { + event.stopPropagation() + event.preventDefault() + this._leafletMap.scrollWheelZoom.disable() + this.dropzone.classList.add('umap-dragover') + } + + dragover(event) { + event.stopPropagation() + event.preventDefault() + } + + drop(event) { + this._leafletMap.scrollWheelZoom.enable() + this.dropzone.classList.remove('umap-dragover') + event.stopPropagation() + event.preventDefault() + const importer = this._umap.importer + importer.build() + importer.files = event.dataTransfer.files + importer.submit() + } + + dragleave() { + this._leafletMap.scrollWheelZoom.enable() + this.dropzone.classList.remove('umap-dragover') + } +} diff --git a/umap/static/umap/js/modules/rendering/map.js b/umap/static/umap/js/modules/rendering/map.js index ae92c6845..b969c5ed8 100644 --- a/umap/static/umap/js/modules/rendering/map.js +++ b/umap/static/umap/js/modules/rendering/map.js @@ -12,6 +12,7 @@ import { translate } from '../i18n.js' import { uMapAlert as Alert } from '../../components/alerts/alert.js' import * as Utils from '../utils.js' import * as Icon from './icon.js' +import DropControl from '../drop.js' // Those options are not saved on the server, so they can live here // instead of in umap.properties @@ -96,7 +97,7 @@ const ControlsMixin = { this._controls.more = new U.MoreControls() this._controls.scale = L.control.scale() this._controls.permanentCredit = new U.PermanentCreditsControl(this) - this._umap.drop = new U.DropControl(this) + this._umap.drop = new DropControl(this._umap, this, this._container) this._controls.tilelayers = new U.TileLayerControl(this) }, diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 350207df2..f402d81c4 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -337,52 +337,6 @@ U.DrawToolbar = L.Toolbar.Control.extend({ }, }) -U.DropControl = L.Class.extend({ - initialize: function (map) { - this.map = map - this.dropzone = map._container - }, - - enable: function () { - L.DomEvent.on(this.dropzone, 'dragenter', this.dragenter, this) - L.DomEvent.on(this.dropzone, 'dragover', this.dragover, this) - L.DomEvent.on(this.dropzone, 'drop', this.drop, this) - L.DomEvent.on(this.dropzone, 'dragleave', this.dragleave, this) - }, - - disable: function () { - L.DomEvent.off(this.dropzone, 'dragenter', this.dragenter, this) - L.DomEvent.off(this.dropzone, 'dragover', this.dragover, this) - L.DomEvent.off(this.dropzone, 'drop', this.drop, this) - L.DomEvent.off(this.dropzone, 'dragleave', this.dragleave, this) - }, - - dragenter: function (event) { - L.DomEvent.stop(event) - this.map.scrollWheelZoom.disable() - this.dropzone.classList.add('umap-dragover') - }, - - dragover: (event) => { - L.DomEvent.stop(event) - }, - - drop: function (event) { - this.map.scrollWheelZoom.enable() - this.dropzone.classList.remove('umap-dragover') - L.DomEvent.stop(event) - const importer = this.map._umap.importer - importer.build() - importer.files = event.dataTransfer.files - importer.submit() - }, - - dragleave: function () { - this.map.scrollWheelZoom.enable() - this.dropzone.classList.remove('umap-dragover') - }, -}) - U.EditControl = L.Control.extend({ options: { position: 'topright',