Skip to content

Commit

Permalink
feat: add startSelected on select event
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jun 21, 2023
1 parent 9bc7e54 commit e615626
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
15 changes: 14 additions & 1 deletion packages/selecto/src/SelectoManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
* selectByClick, continueSelect, and continueSelectWithoutDeselect are not applied.
*/
public setSelectedTargets(
selectedTargets: Array<HTMLElement | SVGElement>
selectedTargets: Array<HTMLElement | SVGElement>,
): SelectedTargets {
const beforeSelected = this.selectedTargets;
const { added, removed, prevList, list } = diff(
Expand Down Expand Up @@ -762,6 +762,17 @@ class Selecto extends EventEmitter<SelectoEvents> {
const inputEvent = e.inputEvent;
const data = e.data;
const result = this.setSelectedTargets(selectedTargets);
const { added, removed, prevList, list } = diff(
data.startSelectedTargets,
selectedTargets,
);

const startResult = {
startSelected: prevList,
startAdded: added.map(i => list[i]),
startRemoved: removed.map(i => prevList[i]),
};


if (isStart) {
/**
Expand Down Expand Up @@ -796,6 +807,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
*/
this.emit("selectStart", {
...result,
...startResult,
rect,
inputEvent,
data: data.data,
Expand Down Expand Up @@ -829,6 +841,7 @@ class Selecto extends EventEmitter<SelectoEvents> {
*/
this.emit("select", {
...result,
...startResult,
rect,
inputEvent,
data: data.data,
Expand Down
26 changes: 22 additions & 4 deletions packages/selecto/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export interface SelectedTargetsWithRect extends SelectedTargets {
* @extends Selecto.SelectedTargetsWithRect
* @typedef
*/
export interface OnSelect<T = Selecto> extends CurrentTarget<T>, SelectedTargetsWithRect {
export interface OnSelectEvent<T = Selecto> extends CurrentTarget<T>, SelectedTargetsWithRect {
/**
* inputEvent
*/
Expand All @@ -275,11 +275,29 @@ export interface OnSelect<T = Selecto> extends CurrentTarget<T>, SelectedTargets
}
/**
* @memberof Selecto
* @extends Selecto.OnSelect
* @extends Selecto.CurrentTarget
* @extends Selecto.OnSelectEvent
* @typedef
*/
export interface OnSelect<T = Selecto> extends OnSelectEvent<T> {
/**
* start selected elements
*/
startSelected: Array<HTMLElement | SVGElement>;
/**
* added from start selected
*/
startAdded: Array<HTMLElement | SVGElement>;
/**
* removed from start selected
*/
startRemoved: Array<HTMLElement | SVGElement>;
}
/**
* @memberof Selecto
* @extends Selecto.OnSelectEvent
* @typedef
*/
export interface OnSelectEnd<T = Selecto> extends OnSelect<T>, CurrentTarget<T> {
export interface OnSelectEnd<T = Selecto> extends OnSelectEvent<T> {
/**
* start selected elements
*/
Expand Down

0 comments on commit e615626

Please sign in to comment.