Skip to content

Commit

Permalink
Adding options to allow/disallow resizing the start or end of a region
Browse files Browse the repository at this point in the history
  • Loading branch information
ibash committed Dec 20, 2024
1 parent 8368928 commit 36e5097
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/plugins/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ export type RegionParams = {
drag?: boolean
/** Allow/dissallow resizing the region */
resize?: boolean
/** Allow/dissallow resizing the start of the region */
resizeStart?: boolean
/** Allow/dissallow resizing the end of the region */
resizeEnd?: boolean
/** The color of the region (CSS color) */
color?: string
/** Content string or HTML element */
Expand All @@ -81,6 +85,8 @@ class SingleRegion extends EventEmitter<RegionEvents> implements Region {
public end: number
public drag: boolean
public resize: boolean
public resizeStart: boolean
public resizeEnd: boolean
public color: string
public content?: HTMLElement
public minLength = 0
Expand All @@ -98,6 +104,8 @@ class SingleRegion extends EventEmitter<RegionEvents> implements Region {
this.end = this.clampPosition(params.end ?? params.start)
this.drag = params.drag ?? true
this.resize = params.resize ?? true
this.resizeStart = params.resizeStart ?? true
this.resizeEnd = params.resizeEnd ?? true
this.color = params.color ?? 'rgba(0, 0, 0, 0.1)'
this.minLength = params.minLength ?? this.minLength
this.maxLength = params.maxLength ?? this.maxLength
Expand Down Expand Up @@ -296,6 +304,8 @@ class SingleRegion extends EventEmitter<RegionEvents> implements Region {

private onResize(dx: number, side: 'start' | 'end') {
if (!this.resize) return
if (!this.resizeStart && side === 'start') return
if (!this.resizeEnd && side === 'end') return
this._onUpdate(dx, side)
}

Expand Down Expand Up @@ -389,6 +399,14 @@ class SingleRegion extends EventEmitter<RegionEvents> implements Region {
this.removeResizeHandles(this.element)
}
}

if (options.resizeStart !== undefined) {
this.resizeStart = options.resizeStart
}

if (options.resizeEnd !== undefined) {
this.resizeEnd = options.resizeEnd
}
}

/** Remove the region */
Expand Down

0 comments on commit 36e5097

Please sign in to comment.