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 f9f752e commit 185477b
Show file tree
Hide file tree
Showing 12 changed files with 2,146 additions and 1,654 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
Expand Up @@ -4,3 +4,6 @@ node_modules
npm-debug.log
dist
docs
/coverage
.rete-cli
.sonar
17 changes: 17 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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
}
},
rules: {
'@typescript-eslint/no-invalid-void-type': 'off',
}
}
)
3,683 changes: 2,070 additions & 1,613 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 @@ -24,9 +24,10 @@
},
"devDependencies": {
"elkjs": "^0.8.2",
"globals": "^15.9.0",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2"
"rete-cli": "~2.0.0"
},
"peerDependencies": {
"elkjs": "^0.8.2",
Expand Down
14 changes: 8 additions & 6 deletions src/appliers/list/transition/animation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

type AnimationRecord = {
startTime: number
duration: number
cb: (t: number) => void
done: (success: boolean) => void
startTime: number
duration: number
cb: (t: number) => void
done: (success: boolean) => void
}

export class AnimationSystem {
Expand All @@ -28,14 +28,16 @@ export class AnimationSystem {
}
cb(t)
})
this.frameId = requestAnimationFrame(() => this.start())
this.frameId = requestAnimationFrame(() => {
this.start()
})
}

async add<R>(duration: number, id: string, tick: (t: number) => Promise<R>) {
const startTime = Date.now()

return new Promise<boolean>(done => {
this.activeAnimations.set(id, { startTime, duration, cb: tick, done })
this.activeAnimations.set(id, { startTime, duration, cb: t => void tick(t), done })
})
}

Expand Down
22 changes: 16 additions & 6 deletions src/appliers/list/transition/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ export class TransitionApplier<S extends ExpectedSchemes, K> extends StandardApp
*/
constructor(private props?: Props) {
super()
this.duration = typeof props?.duration !== 'undefined' ? props.duration : 2000
this.timingFunction = typeof props?.timingFunction !== 'undefined' ? props.timingFunction : t => t
this.duration = typeof props?.duration !== 'undefined'
? props.duration
: 2000
this.timingFunction = typeof props?.timingFunction !== 'undefined'
? props.timingFunction
: t => t

this.animation.start()
}
Expand All @@ -54,7 +58,9 @@ export class TransitionApplier<S extends ExpectedSchemes, K> extends StandardApp
const currentWidth = this.applyTiming(previous.width, width, t)
const currentHeight = this.applyTiming(previous.height, height, t)

this.props?.onTick && this.props.onTick(t)
if (this.props?.onTick) {
this.props.onTick(t)
}
return super.resizeNode(id, currentWidth, currentHeight)
})
}
Expand All @@ -69,7 +75,9 @@ export class TransitionApplier<S extends ExpectedSchemes, K> extends StandardApp
const currentX = this.applyTiming(previous.x, x, t)
const currentY = this.applyTiming(previous.y, y, t)

this.props?.onTick && this.props.onTick(t)
if (this.props?.onTick) {
this.props.onTick(t)
}
return super.translateNode(id, currentX, currentY)
})
}
Expand All @@ -83,8 +91,10 @@ export class TransitionApplier<S extends ExpectedSchemes, K> extends StandardApp
const correctNodes = this.getValidShapes(nodes)

await Promise.all(correctNodes.map(({ id, x, y, width, height, children }) => {
const hasChilden = children && children.length
const needsLayout = this.props?.needsLayout ? this.props.needsLayout(id) : true
const hasChilden = children?.length
const needsLayout = this.props?.needsLayout
? this.props.needsLayout(id)
: true
const forceSelf = !hasChilden || needsLayout

return Promise.all([
Expand Down
32 changes: 17 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ export class AutoArrangePlugin<Schemes extends ExpectedSchemes, T = never> exten
: []
const preset = this.findPreset(id)

return <ElkNode>{
return {
id,
width,
height,
labels: [
{
text: 'label' in node ? node.label : ''
text: 'label' in node
? node.label
: ''
}
],
...this.graphToElk(context, id),
ports: [
...inputs
.sort((a, b) => (a.input?.index || 0) - (b.input?.index || 0))
.sort((a, b) => (a.input?.index ?? 0) - (b.input?.index ?? 0))
.map(({ key }, index) => {
const { side, width: portWidth, height: portHeight, x, y } = preset.port({
nodeId: id,
Expand All @@ -94,7 +96,7 @@ export class AutoArrangePlugin<Schemes extends ExpectedSchemes, T = never> exten
ports: inputs.length
})

return <ElkPort>{
return {

Check warning on line 99 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'input'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion

Check warning on line 99 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'input'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion

Check warning on line 99 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'input'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion

Check warning on line 99 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'input'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion
id: this.getPortId(id, key, 'input'),
width: portWidth,
height: portHeight,
Expand All @@ -103,10 +105,10 @@ export class AutoArrangePlugin<Schemes extends ExpectedSchemes, T = never> exten
properties: {
side
}
}
} as ElkPort
}),
...outputs
.sort((a, b) => (a.output?.index || 0) - (b.output?.index || 0))
.sort((a, b) => (a.output?.index ?? 0) - (b.output?.index ?? 0))
.map(({ key }, index) => {
const { side, width: portWidth, height: portHeight, x, y } = preset.port({
nodeId: id,
Expand All @@ -118,7 +120,7 @@ export class AutoArrangePlugin<Schemes extends ExpectedSchemes, T = never> exten
ports: outputs.length
})

return <ElkPort>{
return {

Check warning on line 123 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'output'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion

Check warning on line 123 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'output'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion

Check warning on line 123 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'output'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion

Check warning on line 123 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ id: this.getPortId(id, key, 'output'), width: portWidth, height: portHeight, x, y, properties: { side } } as ElkPort' has unsafe 'as' type assertion
id: this.getPortId(id, key, 'output'),
width: portWidth,
height: portHeight,
Expand All @@ -127,15 +129,15 @@ export class AutoArrangePlugin<Schemes extends ExpectedSchemes, T = never> exten
properties: {
side
}
}
} as ElkPort
})
],
layoutOptions: {
...preset.options?.(id) || {},

Check warning on line 136 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 136 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 136 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 136 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 @typescript-eslint/naming-convention

portConstraints: 'FIXED_POS'
}
}
} as ElkNode
}

private connectionToLayoutEdge(connection: Schemes['Connection']) {
Expand Down Expand Up @@ -176,23 +178,23 @@ export class AutoArrangePlugin<Schemes extends ExpectedSchemes, T = never> exten
* @param props.applier Layout applier. Responsible for applying node positions to the graph
* @returns Debug information about the layout
*/
// eslint-disable-next-line max-statements, max-len
// eslint-disable-next-line max-statements, complexity
async layout(props?: { options?: LayoutOptions, applier?: Applier<Schemes, T> } & Partial<Context<Schemes>>) {
const nodes = props?.nodes || this.getEditor().getNodes()
const connections = props?.connections || this.getEditor().getConnections()
const nodes = props?.nodes ?? this.getEditor().getNodes()
const connections = props?.connections ?? this.getEditor().getConnections()
const graph: ElkNode = {
id: 'root',
layoutOptions: {
/* eslint-disable @typescript-eslint/naming-convention */
'elk.algorithm': 'layered',
'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
'elk.edgeRouting': 'POLYLINE',
...(props?.options || {} as LayoutOptions)
...props?.options ?? {} as LayoutOptions
/* eslint-enable @typescript-eslint/naming-convention */
},
...this.graphToElk({ nodes, connections })
}
const applier = props?.applier || new StandardApplier()
const applier = props?.applier ?? new StandardApplier()
const source = JSON.stringify(graph, null, '\t')

applier.setEditor(this.getEditor())
Expand Down
12 changes: 9 additions & 3 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ export const setup = (props?: { spacing?: number, top?: number, bottom?: number
return () => ({
port(data): PortData {
const { spacing, top, bottom } = {
spacing: props && typeof props.spacing !== 'undefined' ? props.spacing : 35,
top: props && typeof props.top !== 'undefined' ? props.top : 35,
bottom: props && typeof props.bottom !== 'undefined' ? props.bottom : 15
spacing: typeof props?.spacing !== 'undefined'
? props.spacing
: 35,
top: typeof props?.top !== 'undefined'
? props.top
: 35,
bottom: typeof props?.bottom !== 'undefined'
? props.bottom
: 15
}

if (data.side === 'output') {
Expand Down
4 changes: 2 additions & 2 deletions src/presets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Size } from '../types'
type NodeSide = 'NORTH' | 'SOUTH' | 'EAST' | 'WEST'

export type PortData = {
y: number,
x: number,
y: number
x: number
side: NodeSide
} & Size
export type Preset = (nodeId: string) => (null | {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ type ConnectionScheme = ConnectionBase & {
export type ExpectedSchemes = GetSchemes<NodeScheme, ConnectionScheme>

export type Size = {
width: number,
width: number
height: number
}
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"]
},
"include": ["src"]
Expand Down

0 comments on commit 185477b

Please sign in to comment.