-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
839 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/dockview-core/src/dnd/dropTragetAnchorContainer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { CompositeDisposable, Disposable } from '../lifecycle'; | ||
import { DropTargetTargetModel } from './droptarget'; | ||
|
||
export class DropTargetAnchorContainer extends CompositeDisposable { | ||
private _model: | ||
| { root: HTMLElement; overlay: HTMLElement; changed: boolean } | ||
| undefined; | ||
|
||
private _outline: HTMLElement | undefined; | ||
|
||
get model(): DropTargetTargetModel { | ||
return { | ||
clear: () => { | ||
if (this._model) { | ||
this._model.root.parentElement?.removeChild( | ||
this._model.root | ||
); | ||
} | ||
this._model = undefined; | ||
}, | ||
exists: () => { | ||
return !!this._model; | ||
}, | ||
getElements: (event?: DragEvent, outline?: HTMLElement) => { | ||
const changed = this._outline !== outline; | ||
this._outline = outline; | ||
|
||
if (this._model) { | ||
this._model.changed = changed; | ||
return this._model; | ||
} | ||
|
||
const container = this.createContainer(); | ||
const anchor = this.createAnchor(); | ||
|
||
this._model = { root: container, overlay: anchor, changed }; | ||
|
||
container.appendChild(anchor); | ||
this.element.appendChild(container); | ||
|
||
if (event?.target instanceof HTMLElement) { | ||
const targetBox = event.target.getBoundingClientRect(); | ||
const box = this.element.getBoundingClientRect(); | ||
|
||
anchor.style.left = `${targetBox.left - box.left}px`; | ||
anchor.style.top = `${targetBox.top - box.top}px`; | ||
} | ||
|
||
return this._model; | ||
}, | ||
}; | ||
} | ||
|
||
constructor(readonly element: HTMLElement) { | ||
super(); | ||
|
||
this.addDisposables( | ||
Disposable.from(() => { | ||
this.model.clear(); | ||
}) | ||
); | ||
} | ||
|
||
private createContainer(): HTMLElement { | ||
const el = document.createElement('div'); | ||
el.className = 'dv-drop-target-container'; | ||
|
||
return el; | ||
} | ||
|
||
private createAnchor(): HTMLElement { | ||
const el = document.createElement('div'); | ||
el.className = 'dv-drop-target-anchor'; | ||
el.style.visibility = 'hidden'; | ||
|
||
return el; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.