Constructor
new Selecto(optionsopt)
| 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)
    `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}
    You can set the currently selected targets by points
selectByClick, continueSelect, and continueSelectWithoutDeselect are not applied.
    
| Name | Type | Description | 
|---|---|---|
point1 | 
            
            number[] | |
point2 | 
            
            number[] | 
Returns:
setSelectedTargets(selectedTargets) → {SelectedTargets}
    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)
    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[]}
    You can get the currently selected targets.
Returns:
- Type
 - ElementType[]
 
getSelectableElements()
    Get all elements set in `selectableTargets`.
        
            
    
    findSelectableTargets(dataopt)
    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()
    Destroy elements, properties, and events.
        
            
    
    clickTarget(e, clickedTargetopt) → {this}
    External click or mouse events can be applied to the selecto.
    
| Name | Type | Description | 
|---|---|---|
e | 
            
            MouseEvent | TouchEvent | |
clickedTarget? | 
            
            Element | 
Returns:
- Type
 - this
 
checkScroll()
    If scroll occurs during dragging, you can manually call this method to check the position again.
        
    
    
        Type Definitions
BoundContainer
- Source:
 
Properties:
Type:
- TSInterface
 
CurrentTarget<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
OnDrag<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
OnDragEnd<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
OnDragStart<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
OnSelect<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
OnSelectEnd<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
OnSelectEvent<T = Selecto>
- Source:
 
Properties:
Type:
- TSInterface
 
SelectedTargets
- Source:
 
Properties:
Type:
- TSInterface
 
SelectedTargetsWithRect
- Source:
 
Properties:
Type:
- TSInterface
 
SelectoOptions
- Source:
 
Properties:
            
                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: []
     
            
        
        
            
                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: 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
        
        
        
    
                preventClickEventOnDrag
                optional
                
            
        
        
        
        
            
                Default Value: false
     
            
        
        
            
                preventClickEventOnDrag?: 
boolean
            
        
        
            Prevent click event on drag. (mousemove, touchmove)
        
        
        
    
                preventClickEventOnDragStart
                optional
                
            
        
        
        
        
            
                Default Value: false
     
            
        
        
            
                preventClickEventOnDragStart?: 
boolean
            
        
        
            Prevent click event on dragStart. (mousedown, touchstart)
        
        
        
    
                preventClickEventByCondition
                optional
                
            
        
        
        
        
            
                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.
        
        
        
    
                preventRightClick
                optional
                
            
        
        
        
        
            
                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
    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
    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
    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
    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
    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
    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
    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
    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");
  });
});