diff --git a/packages/selecto/src/SelectoManager.tsx b/packages/selecto/src/SelectoManager.tsx index e1b7dd4..a0c93a0 100644 --- a/packages/selecto/src/SelectoManager.tsx +++ b/packages/selecto/src/SelectoManager.tsx @@ -149,7 +149,7 @@ class Selecto extends EventEmitter { * selectByClick, continueSelect, and continueSelectWithoutDeselect are not applied. */ public setSelectedTargets( - selectedTargets: Array + selectedTargets: Array, ): SelectedTargets { const beforeSelected = this.selectedTargets; const { added, removed, prevList, list } = diff( @@ -762,6 +762,17 @@ class Selecto extends EventEmitter { 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) { /** @@ -796,6 +807,7 @@ class Selecto extends EventEmitter { */ this.emit("selectStart", { ...result, + ...startResult, rect, inputEvent, data: data.data, @@ -829,6 +841,7 @@ class Selecto extends EventEmitter { */ this.emit("select", { ...result, + ...startResult, rect, inputEvent, data: data.data, diff --git a/packages/selecto/src/types.ts b/packages/selecto/src/types.ts index d6f5dff..71b8165 100644 --- a/packages/selecto/src/types.ts +++ b/packages/selecto/src/types.ts @@ -255,7 +255,7 @@ export interface SelectedTargetsWithRect extends SelectedTargets { * @extends Selecto.SelectedTargetsWithRect * @typedef */ -export interface OnSelect extends CurrentTarget, SelectedTargetsWithRect { +export interface OnSelectEvent extends CurrentTarget, SelectedTargetsWithRect { /** * inputEvent */ @@ -275,11 +275,29 @@ export interface OnSelect extends CurrentTarget, SelectedTargets } /** * @memberof Selecto - * @extends Selecto.OnSelect - * @extends Selecto.CurrentTarget + * @extends Selecto.OnSelectEvent + * @typedef + */ +export interface OnSelect extends OnSelectEvent { + /** + * start selected elements + */ + startSelected: Array; + /** + * added from start selected + */ + startAdded: Array; + /** + * removed from start selected + */ + startRemoved: Array; +} +/** + * @memberof Selecto + * @extends Selecto.OnSelectEvent * @typedef */ -export interface OnSelectEnd extends OnSelect, CurrentTarget { +export interface OnSelectEnd extends OnSelectEvent { /** * start selected elements */