Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update cli and fix linting errors #36

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .eslintrc

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ node_modules
npm-debug.log
dist
docs
/coverage
.rete-cli
.sonar
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import tseslint from 'typescript-eslint'
import configs from 'rete-cli/configs/eslint.mjs'
import gloals from 'globals'

export default tseslint.config(
...configs,
{
languageOptions: {
globals: {
...gloals.browser
}
}
}
)
3,690 changes: 2,080 additions & 1,610 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 @@ -28,9 +28,10 @@
"rete-render-utils": "^2.0.0"
},
"devDependencies": {
"globals": "^15.9.0",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"rete-cli": "~2.0.1",
"rete-render-utils": "^2.0.0",
"typescript": "4.8.4"
},
Expand Down
5 changes: 2 additions & 3 deletions src/extensions/selectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* @listens pinunselected
* @listens pintranslated
*/
export function selectablePins<S extends BaseSchemes>(reroutePlugin: ReroutePlugin<S>, selector: Selector, accumulating: { active(): boolean }) {

Check warning on line 17 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 145. Maximum allowed is 120

Check warning on line 17 in src/extensions/selectable.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 145. Maximum allowed is 120
// eslint-disable-next-line max-statements
reroutePlugin.addPipe(context => {
if (!('type' in context)) return context

Expand All @@ -26,10 +25,10 @@
id,
label: 'pin',
translate(dx, dy) {
reroutePlugin.translate(id, dx, dy)
void reroutePlugin.translate(id, dx, dy)
},
unselect() {
reroutePlugin.unselect(id)
void reroutePlugin.unselect(id)
}
}, accumulating.active())
selector.pick({ id, label: 'pin' })
Expand Down
17 changes: 10 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @emits pinunselected
* @priority 9
*/
export class ReroutePlugin<Schemes extends BaseSchemes> extends Scope<RerouteProduces, [Requires<Schemes>, BaseArea<Schemes> | RerouteExtra]> {

Check warning on line 42 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 143. Maximum allowed is 120

Check warning on line 42 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 143. Maximum allowed is 120
pinContainers = new Map<ConnectionId, { element: HTMLElement }>()
pinParents = new Map<HTMLElement, { id: ConnectionId, pinContainer: HTMLElement }>()
pins = getPinsStorage()
Expand All @@ -54,7 +54,7 @@

// eslint-disable-next-line max-statements, complexity
scope.addPipe(context => {
if (!context || typeof context !== 'object' || !('type' in context)) return context

Check warning on line 57 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

Check warning on line 57 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

if (context.type === 'rendered' && context.data.type === 'connection') {
const area = scope.parentScope<Base>(BaseAreaPlugin)
Expand All @@ -63,7 +63,7 @@
if (!this.pinParents.has(element)) {
const pinContainer = document.createElement('div')

pinContainer.dataset['type'] = 'pin-container'
pinContainer.dataset.type = 'pin-container'
this.pinContainers.set(id, { element: pinContainer })
this.pinParents.set(element, { id, pinContainer })
area.area.content.add(pinContainer)
Expand All @@ -78,7 +78,7 @@
if (record) {
this.pinParents.delete(element)
this.pinContainers.delete(record.id)
area.emit({ type: 'unmount', data: { element: record.pinContainer } })
void area.emit({ type: 'unmount', data: { element: record.pinContainer } })
area.area.content.remove(record.pinContainer)
}
}
Expand All @@ -101,8 +101,9 @@
const pins = this.pins.getPins(id)

if (container) {
area.emit({
type: 'render', data: {
void area.emit({
type: 'render',
data: {
type: 'reroute-pins',
element: container.element,
data: { id, pins }
Expand Down Expand Up @@ -140,7 +141,7 @@
const svgPath = deepQuerySelector(view.element, 'path')
const pins = this.pins.getPins(id)

if (svgPath && pins) {

Check warning on line 144 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always truthy

Check warning on line 144 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always truthy
const position = { ...area.area.pointer }
const start = svgPath.getPointAtLength(0)
const end = svgPath.getPointAtLength(1)
Expand Down Expand Up @@ -169,7 +170,7 @@
const pin = { id: getUID(), position }

this.pins.add(connectionId, pin, index)
area.update('connection', connectionId)
void area.update('connection', connectionId)
}

/**
Expand Down Expand Up @@ -235,10 +236,12 @@
public update(pin: string | PinStorageRecord) {
type Base = BaseAreaPlugin<Schemes, BaseArea<Schemes> | RerouteExtra>

const pinRecord = typeof pin === 'object' ? pin : this.pins.getPin(pin)
const pinRecord = typeof pin === 'object'
? pin
: this.pins.getPin(pin)
const area = this.parentScope().parentScope<Base>(BaseAreaPlugin)

if (!pinRecord) return
area.update('connection', pinRecord.connectionId)
void area.update('connection', pinRecord.connectionId)
}
}
6 changes: 4 additions & 2 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
add(connectionId: ConnectionId, pin: Pin, index?: number) {
if (pins.has(pin.id)) throw new Error('already exists')
const data = { ...pin, connectionId }
const list = [...connectionPins.get(connectionId) || []]

Check warning on line 15 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator

Check warning on line 15 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Prefer using nullish coalescing operator (`??`) instead of a logical or (`||`), as it is a safer operator
// eslint-disable-next-line @typescript-eslint/naming-convention
const _index = typeof index === 'number' ? index : list.length

const _index = typeof index === 'number'
? index
: list.length

list.splice(_index, 0, data)
connectionPins.set(connectionId, list)
pins.set(pin.id, data)
},
remove(id: string) {
const existing = this.getPin(id)

Check warning on line 26 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' is 'any'

Check warning on line 26 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'this' is 'any'

Check warning on line 26 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'getPin' is 'any'

Check warning on line 26 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' is 'any'

Check warning on line 26 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'this' is 'any'

Check warning on line 26 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'getPin' is 'any'

if (existing) {

Check warning on line 28 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' is 'any'

Check warning on line 28 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' is 'any'
const list = connectionPins.get(existing.connectionId) || []

Check warning on line 29 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' is 'any'

Check warning on line 29 in src/storage.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' is 'any'

connectionPins.set(existing.connectionId, list.filter(item => item.id !== existing.id))
pins.delete(existing.id)
Expand Down
19 changes: 8 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export function distance(point0: Position, point1: Position) {
return Math.sqrt(Math.pow(point1.x - point0.x, 2) + Math.pow(point1.y - point0.y, 2))
}

// eslint-disable-next-line max-statements
export function findRightIndex(point: Position, line: Position[] = []) {
let minIdx = -1
let minDist = Infinity
Expand All @@ -57,7 +56,7 @@ export function findRightIndex(point: Position, line: Position[] = []) {
return minIdx
}

// eslint-disable-next-line max-statements, complexity
// eslint-disable-next-line complexity
export function pointInBound(p0: Position, p1: Position, p2: Position) {
const { x: x1, y: y1 } = p1
const { x: x2, y: y2 } = p2
Expand All @@ -81,10 +80,10 @@ export function pointInBound(p0: Position, p1: Position, p2: Position) {

export function distanceToLine(p0: Position, p1: Position, p2: Position) {
const top = (p2.y - p1.y) * p0.x
- (p2.x - p1.x) * p0.y
+ p2.x * p1.y
- p2.y * p1.x
const bot = Math.pow((p2.y - p1.y), 2) + Math.pow((p2.x - p1.x), 2)
- (p2.x - p1.x) * p0.y
+ p2.x * p1.y
- p2.y * p1.x
const bot = Math.pow(p2.y - p1.y, 2) + Math.pow(p2.x - p1.x, 2)

return Math.abs(top) / Math.sqrt(bot)
}
Expand All @@ -106,10 +105,8 @@ export function alignEndsHorizontally(points: [number, number][], curvature: num

type Root = Element | DocumentFragment

/* eslint-disable no-undef */
type TagMap = HTMLElementTagNameMap
type SVGMap = SVGElementTagNameMap
/* eslint-enable no-undef */

export function deepQuerySelector<K extends keyof TagMap>(root: Root, selectors: K): TagMap[K] | null
export function deepQuerySelector<K extends keyof SVGMap>(root: Root, selectors: K): SVGMap[K] | null
Expand All @@ -119,10 +116,10 @@ export function deepQuerySelector(root: Root, selector: string): Element | null

if (element) return element

const childNodes = root.querySelectorAll('*')
const childNodes = Array.from(root.querySelectorAll('*'))

for (let i = 0; i < childNodes.length; i++) {
const shadowRoot = (childNodes[i] as Element).shadowRoot
for (const node of childNodes) {
const shadowRoot = node.shadowRoot

if (shadowRoot) {
const found = deepQuerySelector(shadowRoot, selector)
Expand Down
4 changes: 1 addition & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{
"compilerOptions": {
"strict": true
},
"extends": "rete-cli/configs/tsconfig.json",
"include": ["src"]
}
Loading