forked from cory/tildefriends
core: Revisit drag+drop into the editor. Works better but not as I intended. Use it just to update the screenshot in the welcome app.
This commit is contained in:
@ -411,6 +411,7 @@ class TfFilesElement extends LitElement {
|
||||
current: {type: String},
|
||||
files: {type: Object},
|
||||
dropping: {type: Number},
|
||||
drop_target: {type: String},
|
||||
};
|
||||
}
|
||||
|
||||
@ -449,6 +450,9 @@ class TfFilesElement extends LitElement {
|
||||
if (!this.files[file].clean) {
|
||||
classes.push('dirty');
|
||||
}
|
||||
if (this.drop_target == file) {
|
||||
classes.push('drop');
|
||||
}
|
||||
return html`<div
|
||||
class="${classes.join(' ')}"
|
||||
@click=${(x) => this.file_click(file)}
|
||||
@ -465,11 +469,12 @@ class TfFilesElement extends LitElement {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
this.dropping = 0;
|
||||
this.drop_target = undefined;
|
||||
for (let file of event.dataTransfer.files) {
|
||||
let buffer = await file.arrayBuffer();
|
||||
let text = new TextDecoder('latin1').decode(buffer);
|
||||
gFiles[file.name] = {
|
||||
doc: new cm6.EditorState.create({
|
||||
doc: cm6.EditorState.create({
|
||||
doc: text,
|
||||
extensions: cm6.extensions,
|
||||
}),
|
||||
@ -488,6 +493,7 @@ class TfFilesElement extends LitElement {
|
||||
*/
|
||||
drag_enter(event) {
|
||||
this.dropping++;
|
||||
this.drop_target = event.srcElement.innerText.trim();
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
@ -497,6 +503,13 @@ class TfFilesElement extends LitElement {
|
||||
*/
|
||||
drag_leave(event) {
|
||||
this.dropping--;
|
||||
if (this.dropping == 0) {
|
||||
this.drop_target = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
drag_over(event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -523,6 +536,10 @@ class TfFilesElement extends LitElement {
|
||||
background-color: #2aa198;
|
||||
}
|
||||
|
||||
div.file.drop {
|
||||
border: 4px solid red;
|
||||
}
|
||||
|
||||
div.file.dirty::after {
|
||||
content: '*';
|
||||
}
|
||||
@ -531,20 +548,12 @@ class TfFilesElement extends LitElement {
|
||||
@drop=${this.drop}
|
||||
@dragenter=${this.drag_enter}
|
||||
@dragleave=${this.drag_leave}
|
||||
@dragover=${this.drag_over}
|
||||
>
|
||||
${Object.keys(this.files)
|
||||
.sort()
|
||||
.map((x) => self.render_file(x))}
|
||||
</div>
|
||||
<div
|
||||
?hidden=${this.dropping == 0}
|
||||
@drop=${this.drop}
|
||||
@dragenter=${this.drag_enter}
|
||||
@dragleave=${this.drag_leave}
|
||||
style="text-align: center; vertical-align: middle; outline: 16px solid red; margin: -8px; background-color: rgba(255, 0, 0, 0.5); position: absolute; left: 16px; top: 16px; width: calc(100% - 16px); height: calc(100% - 16px); z-index: 1000"
|
||||
>
|
||||
Drop File(s)
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user