Skip to content

Commit

Permalink
Make keepSelection the default behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Jun 19, 2021
1 parent fe66fdf commit dd5f0f5
Show file tree
Hide file tree
Showing 6 changed files with 5,728 additions and 9,594 deletions.
15,262 changes: 5,703 additions & 9,559 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"lint": "eslint packages/**/src/**/*.ts",
"lint:fix": "eslint packages/**/src/**/*.ts --fix",
"ci:dryrun": "npm run lint:fix && npm run build",
"prepublishOnly": "npm run lint && npm run build"
"prepublishOnly": "npm run lint && npm run build",
"postinstall": "lerna bootstrap"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.26.1",
Expand Down
5 changes: 0 additions & 5 deletions packages/react/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ function SelectableArea({boxes, offset, className}: {
});
};

const onStop = ({selection}: SelectionEvent) => {
selection.keepSelection();
};

return (
<>
<SelectionArea className={`container ${className}`}
onStart={onStart}
onMove={onMove}
onStop={onStop}
selectables=".selectable">
{new Array(boxes).fill(0).map((_, index) => (
<div className={selected.has(index + offset) ? 'selected selectable' : 'selectable'}
Expand Down
5 changes: 2 additions & 3 deletions packages/vanilla/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const selection = new SelectionArea({

// Specifies what should be done if already selected elements get selected again.
// invert: Invert selection for elements which were already selected
// keep: Make stored elements (by keepSelection()) 'fix'
// keep: Keep selected elements (use clearSelection() to remove those)
// drop: Remove stored elements after they have been touched
overlap: 'invert',

Expand Down Expand Up @@ -149,8 +149,7 @@ selection.on('beforestart', evt => {
console.log('move', evt);
}).on('stop', evt => {

// The last event can be used to call functions like keepSelection() in case the user wants
// to select multiple elements.
// Do something with the selected elements.
console.log('stop', evt);
});
```
2 changes: 0 additions & 2 deletions packages/vanilla/demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,4 @@ const selection = new SelectionArea({
el.classList.remove('selected');
}

}).on('stop', () => {
selection.keepSelection();
});
45 changes: 21 additions & 24 deletions packages/vanilla/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {

// Hide selection area
css(this._area, 'display', 'none');
this._keepSelection();
}

_updateElementSelection(): void {
Expand Down Expand Up @@ -588,30 +589,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
});
}

/**
* Manually triggers the start of a selection
* @param evt A MouseEvent / TouchEvent -like object
* @param silent If beforestart should be fired,
*/
trigger(evt: MouseEvent | TouchEvent, silent = true): void {
this._onTapStart(evt, silent);
}

/**
* Can be used if during a selection elements have been added.
* Will update everything which can be selected.
*/
resolveSelectables(): void {

// Resolve selectors
this._selectables = selectAll(this._options.selectables, this._options.document);
}

/**
* Saves the current selection for the next selecion.
* Allows multiple selections.
*/
keepSelection(): void {
_keepSelection(): void {
const {_options, _selection} = this;
const {selected, changed, touched, stored} = _selection;

Expand Down Expand Up @@ -646,6 +624,25 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
}
}

/**
* Manually triggers the start of a selection
* @param evt A MouseEvent / TouchEvent -like object
* @param silent If beforestart should be fired,
*/
trigger(evt: MouseEvent | TouchEvent, silent = true): void {
this._onTapStart(evt, silent);
}

/**
* Can be used if during a selection elements have been added.
* Will update everything which can be selected.
*/
resolveSelectables(): void {

// Resolve selectors
this._selectables = selectAll(this._options.selectables, this._options.document);
}

/**
* Clear the elements which where saved by 'keepSelection()'.
* @param store If the store should also get cleared
Expand Down

0 comments on commit dd5f0f5

Please sign in to comment.