mirror of
https://github.com/notion-enhancer/notion-enhancer.git
synced 2025-04-05 21:29:01 +00:00
cross-window draggable tabs
This commit is contained in:
parent
cf4d8e63ee
commit
1d1503c826
@ -87,11 +87,22 @@ module.exports = (store, __exports) => {
|
|||||||
document.addEventListener('dragstart', (event) => {
|
document.addEventListener('dragstart', (event) => {
|
||||||
if (!this.$titlebar) return;
|
if (!this.$titlebar) return;
|
||||||
this.$dragging = getTab(event.target)[0];
|
this.$dragging = getTab(event.target)[0];
|
||||||
|
event.dataTransfer.setData(
|
||||||
|
'text',
|
||||||
|
document.getElementById(getTab(event.target)[0]).src
|
||||||
|
);
|
||||||
event.target.style.opacity = 0.5;
|
event.target.style.opacity = 0.5;
|
||||||
});
|
});
|
||||||
document.addEventListener('dragend', (event) => {
|
document.addEventListener('dragend', (event) => {
|
||||||
if (!this.$titlebar) return;
|
if (!this.$titlebar) return;
|
||||||
event.target.style.opacity = '';
|
event.target.style.opacity = '';
|
||||||
|
document
|
||||||
|
.querySelectorAll('.dragged-over')
|
||||||
|
.forEach((el) => el.classList.remove('dragged-over'));
|
||||||
|
if (this.$dragging !== null) {
|
||||||
|
this.closeTab(this.$dragging);
|
||||||
|
this.$dragging = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener('dragover', (event) => {
|
document.addEventListener('dragover', (event) => {
|
||||||
if (!this.$titlebar) return;
|
if (!this.$titlebar) return;
|
||||||
@ -103,11 +114,13 @@ module.exports = (store, __exports) => {
|
|||||||
if (tab[1]) tab[1].classList.add('dragged-over');
|
if (tab[1]) tab[1].classList.add('dragged-over');
|
||||||
});
|
});
|
||||||
document.addEventListener('drop', (event) => {
|
document.addEventListener('drop', (event) => {
|
||||||
if (!this.$titlebar || this.$dragging === null) return;
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
document
|
if (this.$dragging === null) {
|
||||||
.querySelectorAll('.dragged-over')
|
console.log(event.dataTransfer.getData('text'));
|
||||||
.forEach((el) => el.classList.remove('dragged-over'));
|
if (event.dataTransfer.getData('text').startsWith('notion://'))
|
||||||
|
this.newTab(event.dataTransfer.getData('text'));
|
||||||
|
} else {
|
||||||
|
if (this.$titlebar) {
|
||||||
const from = getTab(this.views.tabs[+this.$dragging]),
|
const from = getTab(this.views.tabs[+this.$dragging]),
|
||||||
to = getTab(event.target);
|
to = getTab(event.target);
|
||||||
if (from[0] !== to[0]) {
|
if (from[0] !== to[0]) {
|
||||||
@ -132,7 +145,9 @@ module.exports = (store, __exports) => {
|
|||||||
this.setState({ tabs: new Map(list) });
|
this.setState({ tabs: new Map(list) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
this.$dragging = null;
|
this.$dragging = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
document.addEventListener('keyup', (event) => {
|
document.addEventListener('keyup', (event) => {
|
||||||
if (!electron.remote.getCurrentWindow().isFocused()) return;
|
if (!electron.remote.getCurrentWindow().isFocused()) return;
|
||||||
|
Loading…
Reference in New Issue
Block a user