Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/pip/ruff-0.8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbgk authored Dec 23, 2024
2 parents 46ad3f9 + f840ac8 commit f97e8b7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 55 deletions.
2 changes: 1 addition & 1 deletion docs-users/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ dependencies = [

[project.optional-dependencies]
dev = [
"hatch==1.13.0",
"hatch==1.14.0",
"ruff==0.8.4",
"djlint==1.36.3",
"mkdocs==1.6.1",
"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 = [
Expand All @@ -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",
Expand Down
55 changes: 55 additions & 0 deletions umap/static/umap/js/modules/drop.js
Original file line number Diff line number Diff line change
@@ -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')
}
}
11 changes: 8 additions & 3 deletions umap/static/umap/js/modules/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 = ''
Expand Down
3 changes: 2 additions & 1 deletion umap/static/umap/js/modules/rendering/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
},

Expand Down
46 changes: 0 additions & 46 deletions umap/static/umap/js/umap.controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
for (const file of event.dataTransfer.files) {
this.map._umap.processFileToImport(file)
}
this.map._umap.onceDataLoaded(this.map._umap.fitDataBounds)
},

dragleave: function () {
this.map.scrollWheelZoom.enable()
this.dropzone.classList.remove('umap-dragover')
},
})

U.EditControl = L.Control.extend({
options: {
position: 'topright',
Expand Down

0 comments on commit f97e8b7

Please sign in to comment.