Skip to content

Commit

Permalink
fix: update cli and fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ni55aN committed Aug 30, 2024
1 parent b5ee3a0 commit 7ff45bc
Show file tree
Hide file tree
Showing 14 changed files with 2,130 additions and 1,653 deletions.
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
@@ -1,3 +1,6 @@
node_modules
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,678 changes: 2,067 additions & 1,611 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"rete-area-plugin": "^2.0.0"
},
"devDependencies": {
"globals": "^15.9.0",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"typescript": "4.8.4"
"rete-cli": "~2.0.0"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
Expand Down
30 changes: 17 additions & 13 deletions src/agents/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export const useScopeAgent: ScopeAgent = (params: DefaultScopesAgentParams, { ar
function pick(id: NodeId) {
const timeoutId = window.setTimeout(() => {
const selected = editor.getNodes().filter(n => n.selected)
const targets = selected.length ? selected.map(n => n.id) : [id]
const targets = selected.length
? selected.map(n => n.id)
: [id]

candidates.push(...targets)
scopes.emit({ type: 'scopepicked', data: { ids: targets } })
void scopes.emit({ type: 'scopepicked', data: { ids: targets } })
}, timeout)

picked = { timeout: timeoutId }
Expand All @@ -39,13 +41,13 @@ export const useScopeAgent: ScopeAgent = (params: DefaultScopesAgentParams, { ar
cancel()
candidates = []

scopes.emit({ type: 'scopereleased', data: { ids: list } })
void scopes.emit({ type: 'scopereleased', data: { ids: list } })

return list
}

area.addPipe(async context => {
if (!('type' in context)) return context
if (!context || typeof context !== 'object' || !('type' in context)) return context
if (context.type === 'nodepicked') {
pick(context.data.id)
}
Expand Down Expand Up @@ -103,26 +105,28 @@ export function useVisualEffects<T>({ area, editor, scopes }: AgentContext<T>):
}
}
}
// eslint-disable-next-line max-statements

scopes.addPipe(context => {
if (context.type === 'scopepicked') {
const { ids } = context.data

editor.getNodes().filter(n => !ids.includes(n.id)).forEach(node => {
const view = area.nodeViews.get(node.id)
editor.getNodes().filter(n => !ids.includes(n.id))
.forEach(node => {
const view = area.nodeViews.get(node.id)

if (view) view.element.style.opacity = '0.4'
})
if (view) view.element.style.opacity = '0.4'
})
if (clientPointerPostion) updateHighlightedScopes(clientPointerPostion, pickedNodes)
}
if (context.type === 'scopereleased') {
const { ids } = context.data

editor.getNodes().filter(n => !ids.includes(n.id)).forEach(node => {
const view = area.nodeViews.get(node.id)
editor.getNodes().filter(n => !ids.includes(n.id))
.forEach(node => {
const view = area.nodeViews.get(node.id)

if (view) view.element.style.opacity = ''
})
if (view) view.element.style.opacity = ''
})
if (clientPointerPostion) updateHighlightedScopes(clientPointerPostion, pickedNodes)
}
if (context.type === 'pointermove') {
Expand Down
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export class ScopesPlugin<Schemes extends ExpectedScheme, T = never> extends Sco
this.size = props?.size || ((id, size) => size)

Check warning on line 63 in src/index.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 63 in src/index.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 63 in src/index.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 63 in src/index.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 max-statements
setParent(scope: Scope<BaseArea<Schemes>, [Root<Schemes>]>): void {
super.setParent(scope)

Expand All @@ -90,13 +89,17 @@ export class ScopesPlugin<Schemes extends ExpectedScheme, T = never> extends Sco
const current = props.editor.getNode(id)

if (!current) throw new Error('cannot find node')

Check warning on line 91 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

Check warning on line 91 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

Check warning on line 91 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

Check warning on line 91 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy
// prevent translating children if the node translation
// is triggered by its resizing (when its children moved)
/*
* prevent translating children if the node translation
* is triggered by its resizing (when its children moved)
*/
if (!isTranslating(id)) {
await translateChildren(id, context.data, props)
}

const parent = current.parent ? props.editor.getNode(current.parent) : null
const parent = current.parent
? props.editor.getNode(current.parent)
: null

if (parent && !agentParams.exclude(id)) {
const hasAnySelectedParent = hasSelectedParent(id, props)
Expand Down Expand Up @@ -149,7 +152,7 @@ export class ScopesPlugin<Schemes extends ExpectedScheme, T = never> extends Sco
export function getPickedNodes<S extends ExpectedScheme>(scopes: Scope<Scopes, [Requires<S>, Root<S>]>) {
const nodes: NodeId[] = []

scopes.addPipe(async context => {
scopes.addPipe(context => {
if (!('type' in context)) return context
if (context.type === 'scopepicked') {
nodes.push(...context.data.ids)
Expand Down
13 changes: 8 additions & 5 deletions src/ordering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ function bringForward<T>(nodeId: NodeId, props: Props<T>) {
return n.parent === nodeId
})

connections.forEach(connection => bringConnectionForward(connection.id, props))
connections.forEach(connection => {
bringConnectionForward(connection.id, props)
})

if (view) {
props.area.area.content.reorder(view.element, null)
}

children.forEach(child => bringForward(child.id, props))
children.forEach(child => {
bringForward(child.id, props)
})
}

export function useOrdering<T>(props: Props<T>) {
// eslint-disable-next-line max-statements
props.area.addPipe(async context => {
if (!('type' in context)) return context
props.area.addPipe(context => {
if (!context || typeof context !== 'object' || !('type' in context)) return context
if (context.type === 'nodepicked') {
bringForward(context.data.id, props)
}
Expand Down
3 changes: 2 additions & 1 deletion src/scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export async function reassignParent<T>(ids: NodeId[], pointer: { x: number, y:
if (!view) throw new Error('node view')

return { node, view }
}).filter(({ node, view }) => {
})
.filter(({ node, view }) => {
return !ids.includes(node.id)
&& pointer.x > view.position.x
&& pointer.y > view.position.y
Expand Down
2 changes: 1 addition & 1 deletion src/sizing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function updateNodeSizes<T>(node: ExpectedScheme['Node'], size: Size, { a
node.width = width
node.height = height

area.resize(node.id, width, height)
void area.resize(node.id, width, height)
}

// eslint-disable-next-line max-statements
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ConnectionBase, GetSchemes, NodeBase, NodeId } from 'rete'

export type Padding = {
top: number,
left: number,
right: number,
top: number
left: number
right: number
bottom: number
}

Expand Down
8 changes: 4 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export type Translate = (nodeId: string, x: number, y: number) => Promise<void>
* keep track of currently moving nodes (to prevent infinite loop)
*/
export function trackedTranslate<T>(props: Props<T>): {
translate: Translate,
translate: Translate
isTranslating: (id: NodeId) => boolean
} {
const active = new Map<NodeId, number>()
const increment = (id: NodeId) => active.set(id, (active.get(id) || 0) + 1)
const decrement = (id: NodeId) => active.set(id, (active.get(id) || 0) - 1)
const increment = (id: NodeId) => active.set(id, (active.get(id) ?? 0) + 1)
const decrement = (id: NodeId) => active.set(id, (active.get(id) ?? 0) - 1)

return {
async translate(id, x, y) {
Expand All @@ -59,7 +59,7 @@ export function trackedTranslate<T>(props: Props<T>): {
}
},
isTranslating(id) {
return (active.get(id) || 0) > 0
return (active.get(id) ?? 0) > 0
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ type Props<T> = { editor: NodeEditor<ExpectedScheme>, area: BaseAreaPlugin<Expec
export function useValidator<T>(props: Props<T>) {
const isClearing = watchClearing(props.editor)

// eslint-disable-next-line max-statements
props.area.addPipe(context => {
if (!context || !(typeof context === 'object' && 'type' in context)) return context
if (context.type === 'nodecreate') {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "rete-cli/configs/tsconfig.json",
"compilerOptions": {
"strict": true,
"lib": [
"DOM"
]
Expand Down

0 comments on commit 7ff45bc

Please sign in to comment.