Skip to content

Commit

Permalink
Remove barall files and simplify ESLint config
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Nov 13, 2024
1 parent afc147b commit 16b7e93
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 39 deletions.
25 changes: 5 additions & 20 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,7 @@ export default [
...vue.configs['flat/recommended'],
react.configs.flat.recommended,
{
files: ['**/*.{js,mjs}'],
rules: {
semi: ['error', 'always'],
'no-console': 'error'
}
},
{
files: ['**/*.ts'],
languageOptions: {
parser: tsParser
},
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'no-console': 'error'
}
},
{
files: ['**/*.tsx'],
files: ['**/*.ts', '**/*.tsx', '**/*.mjs'],
languageOptions: {
parser: tsParser,
parserOptions: {
Expand All @@ -44,10 +27,12 @@ export default [
}
},
rules: {
'@typescript-eslint/no-non-null-assertion': 'off',
'react/react-in-jsx-scope': 'off',
'react/prop-types': 'off',
'no-console': 'error'
},
'no-console': 'error',
quotes: ['error', 'single']
}
},
{
files: ['**/*.vue'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"scripts": {
"dev": "pnpm run --parallel dev",
"build": "pnpm run --recursive build",
"lint": "eslint 'packages/*/{src,demo}/*.{ts,tsx,vue,js}' --cache",
"lint": "eslint 'packages/*/{src,demo}/**/*.{ts,tsx,vue,js}' --cache",
"lint:fix": "pnpm run lint --fix",
"test:ci": "pnpm run lint:fix && pnpm run build",
"release:major": "lerna version major",
Expand Down
11 changes: 9 additions & 2 deletions packages/vanilla/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import {EventTarget} from './EventEmitter';
import type {AreaLocation, Coordinates, ScrollEvent, SelectionEvents, SelectionOptions, SelectionStore} from './types';
import {PartialSelectionOptions} from './types';
import {css, domRect, frames, Frames, intersects, isSafariBrowser, isTouchDevice, off, on, selectAll, SelectAllSelectors, simplifyEvent, shouldTrigger} from './utils';
import {css} from './utils/css';
import {domRect} from './utils/domRect';
import {Frames, frames} from './utils/frames';
import {intersects} from './utils/intersects';
import {isSafariBrowser, isTouchDevice} from './utils/browser';
import {on, off, simplifyEvent} from './utils/events';
import {selectAll, SelectAllSelectors} from './utils/selectAll';
import {shouldTrigger} from './utils/shouldTrigger';

// Re-export types
export * from './types';
Expand Down Expand Up @@ -39,7 +46,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {

// Dynamically constructed area rect
private _areaLocation: AreaLocation = {y1: 0, x2: 0, y2: 0, x1: 0};
private _areaRect = domRect();
private _areaRect = domRect();

// If a single click is being performed, it's a single-click until the user dragged the mouse
private _singleClick = true;
Expand Down
2 changes: 1 addition & 1 deletion packages/vanilla/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type SelectionArea from './index';
import type {Intersection} from './utils';
import type {Intersection} from './utils/intersects';

export type DeepPartial<T> =
T extends unknown[] ? T :
Expand Down
File renamed without changes.
7 changes: 6 additions & 1 deletion packages/vanilla/src/utils/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ export function css(
if (typeof attr === 'object') {

for (const [key, value] of Object.entries(attr)) {
value !== undefined && (style[key as any] = unitify(value));
if (value !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
style[key as any] = unitify(value);
}

}

} else if (val !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
style[attr as any] = unitify(val);
}
}
Expand Down
8 changes: 0 additions & 8 deletions packages/vanilla/src/utils/index.ts

This file was deleted.

12 changes: 6 additions & 6 deletions packages/vanilla/src/utils/shouldTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Trigger} from "../types";
import {Trigger} from '../types';

/**
* Determines whether a MouseEvent should execute until completion depending on
Expand All @@ -11,21 +11,21 @@ import {Trigger} from "../types";
export function shouldTrigger(event: MouseEvent, triggers: Trigger[]): boolean {
for (const trigger of triggers) {
// The trigger requires only a specific button to be pressed
if (typeof trigger === "number") {
if (typeof trigger === 'number') {
return event.button === trigger;
}

// The trigger requires a specific button to be pressed AND some modifiers
if (typeof trigger === "object") {
if (typeof trigger === 'object') {
const reqButtonIsPressed = trigger.button === event.button;

const allReqModifiersArePressed = trigger.modifiers.every((modifier) => {
switch (modifier) {
case "alt":
case 'alt':
return event.altKey;
case "ctrl":
case 'ctrl':
return event.ctrlKey || event.metaKey;
case "shift":
case 'shift':
return event.shiftKey;
}
});
Expand Down

0 comments on commit 16b7e93

Please sign in to comment.