Selecto

Selecto

Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.

Constructor

new Selecto(optionsopt)

Source:
Name Type Default Description
options? Partial<SelectoOptions> {}

Extends

Members

(static, constant) OPTIONS

Source:

(static, constant) METHODS

Source:

(static, constant) EVENTS

Source:

(static, constant) CLASS_NAME

Source:

Methods

triggerDragStart(e)

Source:
`OnDragStart` is triggered by an external event.
Name Type Description
e MouseEvent | TouchEvent external event
Example
import Selecto from "selecto";

const selecto = new Selecto();

window.addEventListener("mousedown", e => {
  selecto.triggerDragStart(e);
});

trigger<Name extends keyof Events>(eventName, paramopt) → {boolean}

Source:
Overrides:
Fires an event to call listeners.
Name Type Default Description
eventName Name | ... Event name
param? TargetParam<any> | ... {} Event parameter

trigger<Name extends keyof Events, Param = Events[Name]>(eventName) → {boolean}

Name Type Description
eventName extends TargetParam<Param> ? Name : never

trigger<Name extends keyof Events, Param = Events[Name]>(eventName, param) → {boolean}

Name Type Description
eventName Name
param TargetParam<Param>
Example
import EventEmitter from "@scena/event-emitter";


const emitter = new EventEmitter();

emitter.on("a", e => {
});


emitter.emit("a", {
  a: 1,
});
     
Returns:
If false, stop the event.
Type
boolean

setSelectedTargetsByPoints(point1, point2) → {SelectedTargetsWithRect}

Source:
You can set the currently selected targets by points selectByClick, continueSelect, and continueSelectWithoutDeselect are not applied.
Name Type Description
point1 number[]
point2 number[]
Returns:
Type
SelectedTargetsWithRect

setSelectedTargets(selectedTargets) → {SelectedTargets}

Source:
You can set the currently selected targets. selectByClick, continueSelect, and continueSelectWithoutDeselect are not applied.
Name Type Description
selectedTargets ElementType[]
Returns:
Type
SelectedTargets

selectTargetsByPoints(startPoint, endPoint)

Source:
Select target by virtual drag from startPoint to endPoint. The target of inputEvent is null.
Name Type Description
startPoint number[]
endPoint number[]

once<Name extends keyof Events & string, Param = Events[Name]>(eventName, listeneropt) → {Promise<OnEvent<Param, this>>}

Source:
Overrides:
Add a disposable listener and Use promise to the registered event.
Name Type Description
eventName Name Name of the event to be added
listener? EventListener<Param, this> disposable listener function of the event to be added
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();

// Add a disposable listener in "a" event
emitter.once("a", () => {
});

// Use Promise
emitter.once("a").then(e => {
});
Returns:
Type
Promise<OnEvent<Param, this>>

on(eventName, listeneropt) → {this}

Source:
Overrides:
Add a listener to the registered event.
Name Type Description
eventName string | object | ... Name of the event to be added
listener? EventListener<Events[any], this> | ... listener function of the event to be added

on<Name extends keyof Events, Param = Events[Name]>(eventName, listener) → {this}

Name Type Description
eventName Name
listener EventListener<Param, this>

on(events) → {this}

Name Type Description
events EventHash<Events, this>
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();

// Add listener in "a" event
emitter.on("a", () => {
});
// Add listeners
emitter.on({
 a: () => {},
 b: () => {},
});
Returns:
Type
this

off(eventNameopt, listeneropt) → {this}

Source:
Overrides:
Remove listeners registered in the event target.
Name Type Description
eventName? string | object | ... Name of the event to be removed
listener? EventListener<Events[any], this> | ... listener function of the event to be removed

off<Name extends keyof Events, Param = Events[Name]>(eventName, listener) → {this}

Name Type Description
eventName? Name
listener? EventListener<Param, this>

off(events) → {this}

Name Type Description
events EventHash<Events, this>
Example
import EventEmitter from "@scena/event-emitter";
cosnt emitter = new EventEmitter();

// Remove all listeners.
emitter.off();

// Remove all listeners in "A" event.
emitter.off("a");


// Remove "listener" listener in "a" event.
emitter.off("a", listener);
Returns:
Type
this

getSelectedTargets() → {ElementType[]}

Source:
You can get the currently selected targets.
Returns:
Type
ElementType[]

getSelectableElements()

Source:
Get all elements set in `selectableTargets`.

findSelectableTargets(dataopt)

Source:
Find for selectableTargets again during drag event You can update selectable targets during an event.
Name Type Default Description
data? IObject<any> this.gesto.getEventData()

emit(eventName, paramopt) → {boolean}

Source:
Overrides:
Fires an event to call listeners.
Name Type Default Description
eventName string | ... Event name
param? TargetParam<any> | ... {} Event parameter

emit<Name extends keyof Events, Param = Events[Name]>(eventName) → {boolean}

Name Type Description
eventName extends Param ? Name : never

emit<Name extends keyof Events, Param = Events[Name]>(eventName, param) → {boolean}

Name Type Description
eventName Name
param TargetParam<Param>
Example
import EventEmitter from "@scena/event-emitter";


const emitter = new EventEmitter();

emitter.on("a", e => {
});


emitter.emit("a", {
  a: 1,
});
Returns:
If false, stop the event.
Type
boolean

destroy()

Source:
Destroy elements, properties, and events.

clickTarget(e, clickedTargetopt) → {this}

Source:
External click or mouse events can be applied to the selecto.
Name Type Description
e MouseEvent | TouchEvent
clickedTarget? Element
Returns:
Type
this

checkScroll()

Source:
If scroll occurs during dragging, you can manually call this method to check the position again.

Type Definitions

BoundContainer

Source:
Properties:
element: HTMLElement | string | boolean
left optional
left?: boolean
top optional
top?: boolean
right optional
right?: boolean
bottom optional
bottom?: boolean
Type:
  • TSInterface

CurrentTarget<T = Selecto>

Source:
Properties:
currentTarget: T
An Selecto instance itself
Type:
  • TSInterface

OnDrag<T = Selecto>

Source:
Properties:
rect: Rect
Rect of Selection Element
isSelect: boolean
Whether it is in select
Type:
  • TSInterface

OnDragEnd<T = Selecto>

Source:
Properties:
rect: Rect
Rect of Selection Element
isSelect: boolean
Whether it is in select
Type:
  • TSInterface

OnDragStart<T = Selecto>

Source:
Properties:
stop: () => void
Stop all events
isClick: boolean
Type:
  • TSInterface

OnSelect<T = Selecto>

Source:
Properties:
beforeSelected: Array<HTMLElement | SVGElement>
before selecting elements
selected: Array<HTMLElement | SVGElement>
selected elements
added: Array<HTMLElement | SVGElement>
added elements
removed: Array<HTMLElement | SVGElement>
removed elements
rect: Rect
Rect of Selection Element
currentTarget: T
An Selecto instance itself
inputEvent: any
inputEvent
data: Record<string, any>
Data shared from dragStart, selectStart to dragEnd, selectEnd
isDragStartEnd: boolean
Whether it ends as soon as dragStart(mousedown, touchstart)
isTrusted: boolean
Whether or not you directly dragged
startSelected: Array<HTMLElement | SVGElement>
start selected elements
startAdded: Array<HTMLElement | SVGElement>
added from start selected
startRemoved: Array<HTMLElement | SVGElement>
removed from start selected
Type:
  • TSInterface

OnSelectEnd<T = Selecto>

Source:
Properties:
beforeSelected: Array<HTMLElement | SVGElement>
before selecting elements
selected: Array<HTMLElement | SVGElement>
selected elements
added: Array<HTMLElement | SVGElement>
added elements
removed: Array<HTMLElement | SVGElement>
removed elements
rect: Rect
Rect of Selection Element
currentTarget: T
An Selecto instance itself
inputEvent: any
inputEvent
data: Record<string, any>
Data shared from dragStart, selectStart to dragEnd, selectEnd
isDragStartEnd: boolean
Whether it ends as soon as dragStart(mousedown, touchstart)
isTrusted: boolean
Whether or not you directly dragged
startSelected: Array<HTMLElement | SVGElement>
start selected elements
afterAdded: Array<HTMLElement | SVGElement>
after added elements
afterRemoved: Array<HTMLElement | SVGElement>
after removed elements
isDragStart: boolean
Whether it is a mousedown or touchstart event
isDragStartEnd: boolean
Whether it ends as soon as dragStart(mousedown, touchstart)
isClick: boolean
Whether it is click
isDouble: boolean
Wheter it is double click or double start
Type:
  • TSInterface

OnSelectEvent<T = Selecto>

Source:
Properties:
beforeSelected: Array<HTMLElement | SVGElement>
before selecting elements
selected: Array<HTMLElement | SVGElement>
selected elements
added: Array<HTMLElement | SVGElement>
added elements
removed: Array<HTMLElement | SVGElement>
removed elements
rect: Rect
Rect of Selection Element
currentTarget: T
An Selecto instance itself
inputEvent: any
inputEvent
data: Record<string, any>
Data shared from dragStart, selectStart to dragEnd, selectEnd
isDragStartEnd: boolean
Whether it ends as soon as dragStart(mousedown, touchstart)
isTrusted: boolean
Whether or not you directly dragged
Type:
  • TSInterface

SelectedTargets

Source:
Properties:
beforeSelected: Array<HTMLElement | SVGElement>
before selecting elements
selected: Array<HTMLElement | SVGElement>
selected elements
added: Array<HTMLElement | SVGElement>
added elements
removed: Array<HTMLElement | SVGElement>
removed elements
Type:
  • TSInterface

SelectedTargetsWithRect

Source:
Properties:
beforeSelected: Array<HTMLElement | SVGElement>
before selecting elements
selected: Array<HTMLElement | SVGElement>
selected elements
added: Array<HTMLElement | SVGElement>
added elements
removed: Array<HTMLElement | SVGElement>
removed elements
rect: Rect
Rect of Selection Element
Type:
  • TSInterface

SelectoOptions

Source:
Properties:
container: HTMLElement | null
The container to add a selection element for vanilla
rootContainer: HTMLElement | null
Selecto's root container (No transformed container.)
Default Value: container
dragContainer: Element | Window | Element[] | string | null | undefined
The area to drag selection element.
Default Value: ""
className: string
custom class name of selecto element
Default Value: []
selectableTargets: Array<ElementType | string | (() => ElementType | ElementType[]) | ElementRef<ElementType>>
Targets to select. You can register a queryselector or an Element.
Default Value: true
selectFromInside: boolean
Whether to select from the target inside (If hitTest is 0, it becomes inside select as well)
Default Value: false
selectByClick: boolean
Whether to force drag end when selectFromInside, selectByClick is true.
Default Value: true
preventDragFromInside: boolean
When the target is clicked, the event is stopped and selected. (If hitTest is 0, it becomes click as well.)
Default Value: false
clickBySelectEnd: boolean
Whether to click when mouse(touch) ends while using selectByClick(true)
Default Value: false
continueSelect: boolean
After the select, whether to select the next target with the selected target (deselected if the target is selected again)
Default Value: false
continueSelectWithoutDeselect: boolean
Whether to continue the previously selected items without deselect when using `continueSelect` or `toggleContinueSelect`.
toggleContinueSelect: string[][] | string[] | string | null
Determines which key to continue selecting the next target via keydown and keyup. The initially set `continueSelect` value is the inactive(keyup) value.
toggleContinueSelectWithoutDeselect: string[][] | string[] | string | null
Determines which key to continue selecting the next target without deselect via keydown and keyup. The initially set `continueSelectWithoutDeselect` value is the inactive(keyup) value.
keyContainer: Document | HTMLElement | Window | null
The container for keydown and keyup events.
Default Value: 100
hitRate: number | string | ((element: Element) => number | string)
The rate at which the target overlaps the drag area to be selected. If you want an absolute number, set it to a px value. (ex: 10px)
Default Value: false
boundContainer: BoundContainer | boolean | HTMLElement | string | null
Container to bound the selection area. If false, do not bound. If true, it is the container of selecto.
Default Value: null
scrollOptions: DragScrollOptions
Set the scroll options, time, etc. to automatically scroll by dragging.
Default Value: null
innerScrollOptions: boolean | Partial<DragScrollOptions>
Set the inner scroll options, time, etc. to automatically scroll by dragging.
Default Value: false
checkInput: boolean
hecks whether this is an element to input text or contentEditable, and prevents dragging.
Default Value: false
preventDefault: boolean
When dragging, preventDefault is called. (Touch occurs unconditionally)
Default Value: ""
cspNonce: string
add nonce property to style for CSP
Default Value: 0
ratio: number
Adjust the ratio of the selection.
Default Value: null
getElementRect: getElementRectFunction
A function to get the exact position of an element's rect
Default Value: null
dragCondition: ((e: OnParentDragStart) => boolean) | null
Conditional function to start dragging
Default Value: false
preventClickEventOnDrag?: boolean
Prevent click event on drag. (mousemove, touchmove)
Default Value: false
preventClickEventOnDragStart?: boolean
Prevent click event on dragStart. (mousedown, touchstart)
Default Value: null
preventClickEventByCondition?: ((e: MouseEvent) => boolean) | null
Prevent click event according to specific conditions. Returning true allows the click event, returning false prevents it.
Default Value: true
preventRightClick?: boolean
Whether to prevent dragging of the right mouse button
Default Value: false
checkOverflow: boolean
Inspect the overflow area and exclude the outside target from the select.
Type:
  • TSInterface

Events

drag

Source:
When the drag, the drag event is called. Call the stop () function if you have a specific element or don't want to raise a select
Type Description
OnDrag Parameters for the drag event
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  selectByClick: true,
  selectFromInside: false,
});

selecto.on("drag", e => {
  e.stop();
}).on("select", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
});

dragEnd

Source:
When the drag ends (triggers on mouseup or touchend after drag), the dragEnd event is called.
Type Description
OnDragEnd Parameters for the dragEnd event

dragStart

Source:
When the drag starts (triggers on mousedown or touchstart), the dragStart event is called. Call the stop () function if you have a specific element or don't want to raise a select
Type Description
OnDragStart Parameters for the dragStart event
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  selectByClick: true,
  selectFromInside: false,
});

selecto.on("dragStart", e => {
  if (e.inputEvent.target.tagName === "SPAN") {
    e.stop();
  }
}).on("select", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
});

keydown

Source:
When you keydown the key you specified in toggleContinueSelect, the keydown event is called.
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  toggleContinueSelect: "shift";
  keyContainer: window,
});

selecto.on("keydown", () => {
  document.querySelector(".button").classList.add("selected");
}).on("keyup", () => {
  document.querySelector(".button").classList.remove("selected");
}).on("select", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
});

keyup

Source:
When you keyup the key you specified in toggleContinueSelect, the keyup event is called.
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  toggleContinueSelect: "shift";
  keyContainer: window,
});

selecto.on("keydown", () => {
  document.querySelector(".button").classList.add("selected");
}).on("keyup", () => {
  document.querySelector(".button").classList.remove("selected");
}).on("select", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
});

select

Source:
When the select in real time, the select event is called.
Type Description
Selecto.OnSelect Parameters for the select event
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  selectByClick: true,
  selectFromInside: false,
});

selecto.on("select", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
});

selectEnd

Source:
When the select(dragEnd or click) ends, the selectEnd event is called.
Type Description
Selecto.OnSelectEnd Parameters for the selectEnd event
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  selectByClick: true,
  selectFromInside: false,
});

selecto.on("selectStart", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
}).on("selectEnd", e => {
  e.afterAdded.forEach(el => {
    el.classList.add("selected");
  });
  e.afterRemoved.forEach(el => {
    el.classList.remove("selected");
  });
});

selectStart

Source:
When the select(drag) starts, the selectStart event is called.
Type Description
Selecto.OnSelect Parameters for the selectStart event
Example
import Selecto from "selecto";

const selecto = new Selecto({
  container: document.body,
  selectByClick: true,
  selectFromInside: false,
});

selecto.on("selectStart", e => {
  e.added.forEach(el => {
    el.classList.add("selected");
  });
  e.removed.forEach(el => {
    el.classList.remove("selected");
  });
}).on("selectEnd", e => {
  e.afterAdded.forEach(el => {
    el.classList.add("selected");
  });
  e.afterRemoved.forEach(el => {
    el.classList.remove("selected");
  });
});