mirror of
https://github.com/mathuo/dockview
synced 2025-01-22 17:35:57 +00:00
experiments
This commit is contained in:
parent
7adabec088
commit
b7ceaf5133
@ -931,4 +931,8 @@ export class DockviewApi implements CommonApi<SerializedDockview> {
|
|||||||
dispose(): void {
|
dispose(): void {
|
||||||
this.component.dispose();
|
this.component.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
anchor(): HTMLElement {
|
||||||
|
return this.component.anchor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,6 +168,7 @@ export interface IDockviewComponent extends IBaseGrid<DockviewGroupPanel> {
|
|||||||
readonly panels: IDockviewPanel[];
|
readonly panels: IDockviewPanel[];
|
||||||
readonly orientation: Orientation;
|
readonly orientation: Orientation;
|
||||||
readonly gap: number;
|
readonly gap: number;
|
||||||
|
readonly anchor: HTMLElement;
|
||||||
readonly onDidDrop: Event<DockviewDidDropEvent>;
|
readonly onDidDrop: Event<DockviewDidDropEvent>;
|
||||||
readonly onWillDrop: Event<DockviewWillDropEvent>;
|
readonly onWillDrop: Event<DockviewWillDropEvent>;
|
||||||
readonly onWillShowOverlay: Event<WillShowOverlayLocationEvent>;
|
readonly onWillShowOverlay: Event<WillShowOverlayLocationEvent>;
|
||||||
@ -339,6 +340,10 @@ export class DockviewComponent
|
|||||||
return this._floatingGroups;
|
return this._floatingGroups;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get anchor(): HTMLElement {
|
||||||
|
return this.options.anchor ?? this.gridview.element;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(parentElement: HTMLElement, options: DockviewComponentOptions) {
|
constructor(parentElement: HTMLElement, options: DockviewComponentOptions) {
|
||||||
super(parentElement, {
|
super(parentElement, {
|
||||||
proportionalLayout: true,
|
proportionalLayout: true,
|
||||||
@ -352,8 +357,10 @@ export class DockviewComponent
|
|||||||
className: options.className,
|
className: options.className,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._options = options;
|
||||||
|
|
||||||
this.overlayRenderContainer = new OverlayRenderContainer(
|
this.overlayRenderContainer = new OverlayRenderContainer(
|
||||||
this.gridview.element,
|
this.anchor,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -423,8 +430,6 @@ export class DockviewComponent
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._options = options;
|
|
||||||
|
|
||||||
this._rootDropTarget = new Droptarget(this.element, {
|
this._rootDropTarget = new Droptarget(this.element, {
|
||||||
canDisplayOverlay: (event, position) => {
|
canDisplayOverlay: (event, position) => {
|
||||||
const data = getPanelData();
|
const data = getPanelData();
|
||||||
@ -873,6 +878,7 @@ export class DockviewComponent
|
|||||||
|
|
||||||
const overlay = new Overlay({
|
const overlay = new Overlay({
|
||||||
container: this.gridview.element,
|
container: this.gridview.element,
|
||||||
|
anchor: this.anchor,
|
||||||
content: group.element,
|
content: group.element,
|
||||||
...anchoredBox,
|
...anchoredBox,
|
||||||
minimumInViewportWidth:
|
minimumInViewportWidth:
|
||||||
|
@ -39,6 +39,7 @@ export interface DockviewOptions {
|
|||||||
* Call `.layout(width, height)` to manually resize the container.
|
* Call `.layout(width, height)` to manually resize the container.
|
||||||
*/
|
*/
|
||||||
disableAutoResizing?: boolean;
|
disableAutoResizing?: boolean;
|
||||||
|
anchor?: HTMLElement;
|
||||||
hideBorders?: boolean;
|
hideBorders?: boolean;
|
||||||
singleTabMode?: 'fullwidth' | 'default';
|
singleTabMode?: 'fullwidth' | 'default';
|
||||||
disableFloatingGroups?: boolean;
|
disableFloatingGroups?: boolean;
|
||||||
@ -94,11 +95,12 @@ export class DockviewUnhandledDragOverEvent implements DockviewDndOverlayEvent {
|
|||||||
|
|
||||||
export const PROPERTY_KEYS: (keyof DockviewOptions)[] = (() => {
|
export const PROPERTY_KEYS: (keyof DockviewOptions)[] = (() => {
|
||||||
/**
|
/**
|
||||||
* by readong the keys from an empty value object TypeScript will error
|
* by reading the keys from an empty value object TypeScript will error
|
||||||
* when we add or remove new properties to `DockviewOptions`
|
* when we add or remove new properties to `DockviewOptions`
|
||||||
*/
|
*/
|
||||||
const properties: Record<keyof DockviewOptions, undefined> = {
|
const properties: Record<keyof DockviewOptions, undefined> = {
|
||||||
disableAutoResizing: undefined,
|
disableAutoResizing: undefined,
|
||||||
|
anchor: undefined,
|
||||||
hideBorders: undefined,
|
hideBorders: undefined,
|
||||||
singleTabMode: undefined,
|
singleTabMode: undefined,
|
||||||
disableFloatingGroups: undefined,
|
disableFloatingGroups: undefined,
|
||||||
|
@ -74,6 +74,7 @@ export class Overlay extends CompositeDisposable {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly options: AnchoredBox & {
|
private readonly options: AnchoredBox & {
|
||||||
container: HTMLElement;
|
container: HTMLElement;
|
||||||
|
anchor: HTMLElement;
|
||||||
content: HTMLElement;
|
content: HTMLElement;
|
||||||
minimumInViewportWidth?: number;
|
minimumInViewportWidth?: number;
|
||||||
minimumInViewportHeight?: number;
|
minimumInViewportHeight?: number;
|
||||||
@ -95,7 +96,7 @@ export class Overlay extends CompositeDisposable {
|
|||||||
this.setupResize('bottomright');
|
this.setupResize('bottomright');
|
||||||
|
|
||||||
this._element.appendChild(this.options.content);
|
this._element.appendChild(this.options.content);
|
||||||
this.options.container.appendChild(this._element);
|
this.options.anchor.appendChild(this._element);
|
||||||
|
|
||||||
// if input bad resize within acceptable boundaries
|
// if input bad resize within acceptable boundaries
|
||||||
this.setBounds({
|
this.setBounds({
|
||||||
@ -115,6 +116,12 @@ export class Overlay extends CompositeDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setBounds(bounds: Partial<AnchoredBox> = {}): void {
|
setBounds(bounds: Partial<AnchoredBox> = {}): void {
|
||||||
|
const containerRect = this.options.anchor.getBoundingClientRect();
|
||||||
|
const anchorRect = this.options.anchor.getBoundingClientRect();
|
||||||
|
|
||||||
|
const dy = 0; //containerRect.top - anchorRect.top;
|
||||||
|
const dx = 0; // containerRect.left - anchorRect.left;
|
||||||
|
|
||||||
if (typeof bounds.height === 'number') {
|
if (typeof bounds.height === 'number') {
|
||||||
this._element.style.height = `${bounds.height}px`;
|
this._element.style.height = `${bounds.height}px`;
|
||||||
}
|
}
|
||||||
@ -122,27 +129,26 @@ export class Overlay extends CompositeDisposable {
|
|||||||
this._element.style.width = `${bounds.width}px`;
|
this._element.style.width = `${bounds.width}px`;
|
||||||
}
|
}
|
||||||
if ('top' in bounds && typeof bounds.top === 'number') {
|
if ('top' in bounds && typeof bounds.top === 'number') {
|
||||||
this._element.style.top = `${bounds.top}px`;
|
this._element.style.top = `${bounds.top + dy}px`;
|
||||||
this._element.style.bottom = 'auto';
|
this._element.style.bottom = 'auto';
|
||||||
this.verticalAlignment = 'top';
|
this.verticalAlignment = 'top';
|
||||||
}
|
}
|
||||||
if ('bottom' in bounds && typeof bounds.bottom === 'number') {
|
if ('bottom' in bounds && typeof bounds.bottom === 'number') {
|
||||||
this._element.style.bottom = `${bounds.bottom}px`;
|
this._element.style.bottom = `${bounds.bottom + dy}px`;
|
||||||
this._element.style.top = 'auto';
|
this._element.style.top = 'auto';
|
||||||
this.verticalAlignment = 'bottom';
|
this.verticalAlignment = 'bottom';
|
||||||
}
|
}
|
||||||
if ('left' in bounds && typeof bounds.left === 'number') {
|
if ('left' in bounds && typeof bounds.left === 'number') {
|
||||||
this._element.style.left = `${bounds.left}px`;
|
this._element.style.left = `${bounds.left + dx}px`;
|
||||||
this._element.style.right = 'auto';
|
this._element.style.right = 'auto';
|
||||||
this.horiziontalAlignment = 'left';
|
this.horiziontalAlignment = 'left';
|
||||||
}
|
}
|
||||||
if ('right' in bounds && typeof bounds.right === 'number') {
|
if ('right' in bounds && typeof bounds.right === 'number') {
|
||||||
this._element.style.right = `${bounds.right}px`;
|
this._element.style.right = `${bounds.right + dx}px`;
|
||||||
this._element.style.left = 'auto';
|
this._element.style.left = 'auto';
|
||||||
this.horiziontalAlignment = 'right';
|
this.horiziontalAlignment = 'right';
|
||||||
}
|
}
|
||||||
|
|
||||||
const containerRect = this.options.container.getBoundingClientRect();
|
|
||||||
const overlayRect = this._element.getBoundingClientRect();
|
const overlayRect = this._element.getBoundingClientRect();
|
||||||
|
|
||||||
// region: ensure bounds within allowable limits
|
// region: ensure bounds within allowable limits
|
||||||
@ -156,10 +162,14 @@ export class Overlay extends CompositeDisposable {
|
|||||||
if (this.verticalAlignment === 'top') {
|
if (this.verticalAlignment === 'top') {
|
||||||
const top = clamp(
|
const top = clamp(
|
||||||
overlayRect.top - containerRect.top,
|
overlayRect.top - containerRect.top,
|
||||||
-yOffset,
|
dy + -yOffset,
|
||||||
Math.max(0, containerRect.height - overlayRect.height + yOffset)
|
dy +
|
||||||
|
Math.max(
|
||||||
|
0,
|
||||||
|
anchorRect.height - overlayRect.height + yOffset
|
||||||
|
)
|
||||||
);
|
);
|
||||||
this._element.style.top = `${top}px`;
|
this._element.style.top = `${top + dy}px`;
|
||||||
this._element.style.bottom = 'auto';
|
this._element.style.bottom = 'auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,9 +177,9 @@ export class Overlay extends CompositeDisposable {
|
|||||||
const bottom = clamp(
|
const bottom = clamp(
|
||||||
containerRect.bottom - overlayRect.bottom,
|
containerRect.bottom - overlayRect.bottom,
|
||||||
-yOffset,
|
-yOffset,
|
||||||
Math.max(0, containerRect.height - overlayRect.height + yOffset)
|
Math.max(0, anchorRect.height - overlayRect.height + yOffset)
|
||||||
);
|
);
|
||||||
this._element.style.bottom = `${bottom}px`;
|
this._element.style.bottom = `${bottom + dy}px`;
|
||||||
this._element.style.top = 'auto';
|
this._element.style.top = 'auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,9 +187,9 @@ export class Overlay extends CompositeDisposable {
|
|||||||
const left = clamp(
|
const left = clamp(
|
||||||
overlayRect.left - containerRect.left,
|
overlayRect.left - containerRect.left,
|
||||||
-xOffset,
|
-xOffset,
|
||||||
Math.max(0, containerRect.width - overlayRect.width + xOffset)
|
Math.max(0, anchorRect.width - overlayRect.width + xOffset)
|
||||||
);
|
);
|
||||||
this._element.style.left = `${left}px`;
|
this._element.style.left = `${left + dx}px`;
|
||||||
this._element.style.right = 'auto';
|
this._element.style.right = 'auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,9 +197,9 @@ export class Overlay extends CompositeDisposable {
|
|||||||
const right = clamp(
|
const right = clamp(
|
||||||
containerRect.right - overlayRect.right,
|
containerRect.right - overlayRect.right,
|
||||||
-xOffset,
|
-xOffset,
|
||||||
Math.max(0, containerRect.width - overlayRect.width + xOffset)
|
Math.max(0, anchorRect.width - overlayRect.width + xOffset)
|
||||||
);
|
);
|
||||||
this._element.style.right = `${right}px`;
|
this._element.style.right = `${right + dx}px`;
|
||||||
this._element.style.left = 'auto';
|
this._element.style.left = 'auto';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +253,13 @@ export class Overlay extends CompositeDisposable {
|
|||||||
},
|
},
|
||||||
addDisposableWindowListener(window, 'mousemove', (e) => {
|
addDisposableWindowListener(window, 'mousemove', (e) => {
|
||||||
const containerRect =
|
const containerRect =
|
||||||
this.options.container.getBoundingClientRect();
|
this.options.anchor.getBoundingClientRect();
|
||||||
|
const anchorRect =
|
||||||
|
this.options.anchor.getBoundingClientRect();
|
||||||
|
|
||||||
|
const dy = containerRect.top - anchorRect.top;
|
||||||
|
const dx = containerRect.left - anchorRect.left;
|
||||||
|
|
||||||
const x = e.clientX - containerRect.left;
|
const x = e.clientX - containerRect.left;
|
||||||
const y = e.clientY - containerRect.top;
|
const y = e.clientY - containerRect.top;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user