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 #11

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
8 changes: 0 additions & 8 deletions .eslintrc

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ node_modules
npm-debug.log
dist
docs
/coverage
.rete-cli
.sonar
.svelte-kit
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/unbound-method': 'off'
}
}
)
4,002 changes: 2,191 additions & 1,811 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 @@ -33,9 +33,10 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@sveltejs/package": "^2.1.0",
"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",
"rollup-plugin-scss": "^4.0.0",
"rollup-plugin-svelte": "^7.1.6",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* @listens render
* @listens unmount
*/
export class SveltePlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> extends Scope<Produces<Schemes>, [Requires<Schemes> | T]> {

Check warning on line 32 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

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

Check warning on line 32 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 137. Maximum allowed is 120
renderer: Renderer<SvelteComponent>
presets: RenderPreset<Schemes, T>[] = []
owners = new WeakMap<HTMLElement, RenderPreset<Schemes, T>>()
Expand All @@ -47,8 +47,8 @@
if ('filled' in context.data && context.data.filled) {
return context
}
if (this.mount(context.data.element, context as T)) {

Check warning on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as T' has unsafe 'as' type assertion

Check warning on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as T' has unsafe 'as' type assertion
return {

Check warning on line 51 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ ...context, data: { ...context.data, filled: true } } as typeof context' has unsafe 'as' type assertion

Check warning on line 51 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ ...context, data: { ...context.data, filled: true } } as typeof context' has unsafe 'as' type assertion
...context,
data: {
...context.data,
Expand Down Expand Up @@ -78,23 +78,23 @@
apps = new Map<HTMLElement, Node>()

private mount(element: HTMLElement, context: T) {
const existing = this.renderer.get(element)

Check warning on line 81 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' contains 'any'

Check warning on line 81 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' contains 'any'
const parent = this.parentScope()

if (existing) {

Check warning on line 84 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' contains 'any'

Check warning on line 84 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' contains 'any'
this.presets.forEach(preset => {
if (this.owners.get(element) !== preset) return
const result = preset.update(context as Extract<T, { type: 'render' }>, this)

Check warning on line 87 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as Extract<T, { type: 'render' }>' has unsafe 'as' type assertion

Check warning on line 87 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as Extract<T, { type: 'render' }>' has unsafe 'as' type assertion

if (result) {
this.renderer.update(existing, result)

Check warning on line 90 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' contains 'any'

Check warning on line 90 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'existing' contains 'any'
}
})
return true
}

for (const preset of this.presets) {
const result = preset.render(context as Extract<T, { type: 'render' }>, this)

Check warning on line 97 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as Extract<T, { type: 'render' }>' has unsafe 'as' type assertion

Check warning on line 97 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as Extract<T, { type: 'render' }>' has unsafe 'as' type assertion

if (!result) continue

Expand All @@ -102,7 +102,7 @@
element,
result.component,
result.props,
() => parent?.emit({ type: 'rendered', data: (context as Requires<Schemes>).data } as T)
() => void parent.emit({ type: 'rendered', data: (context as Requires<Schemes>).data } as T)

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ type: 'rendered', data: (context as Requires<Schemes>).data } as T' has unsafe 'as' type assertion

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as Requires<Schemes>' has unsafe 'as' type assertion

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The '{ type: 'rendered', data: (context as Requires<Schemes>).data } as T' has unsafe 'as' type assertion

Check warning on line 105 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'context as Requires<Schemes>' has unsafe 'as' type assertion
)

this.owners.set(element, preset)
Expand Down
47 changes: 30 additions & 17 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-console */

import { ClassicPreset, Scope } from 'rete'
import { classicConnectionPath, getDOMSocketPosition, loopConnectionPath, SocketPositionWatcher } from 'rete-render-utils'
import type { ComponentType, SvelteComponent } from 'svelte'
Expand All @@ -24,22 +24,20 @@ type CustomizationProps<Schemes extends ClassicScheme> = {
connection?: (data: ExtractPayload<Schemes, 'connection'>) => Component<any> | null
socket?: (data: ExtractPayload<Schemes, 'socket'>) => Component<any> | null
control?: <N extends ClassicPreset.Control>(data: ExtractPayload<Schemes, 'control'>)
=> Component<{ data: N }> | null
=> Component<{ data: N }> | null
}
type ClassicProps<Schemes extends ClassicScheme, K> = {
socketPositionWatcher?: SocketPositionWatcher<Scope<never, [K]>>,
socketPositionWatcher?: SocketPositionWatcher<Scope<never, [K]>>
customize?: CustomizationProps<Schemes>
}

/**
* Classic preset for rendering nodes, connections, controls and sockets.
*/
export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Schemes>>(
props?: ClassicProps<Schemes, K>
): RenderPreset<Schemes, K> {
export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Schemes>>(props?: ClassicProps<Schemes, K>): RenderPreset<Schemes, K> {
const positionWatcher = typeof props?.socketPositionWatcher === 'undefined'
? getDOMSocketPosition<Schemes, K>()
: props?.socketPositionWatcher
: props.socketPositionWatcher
const { node, connection, socket, control } = props?.customize || {}

return {
Expand All @@ -60,8 +58,12 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche

return {
data: payload,
...(start ? { start } : {}),
...(end ? { end } : {})
...start
? { start }
: {},
...end
? { end }
: {}
}
}
return { data: payload }
Expand All @@ -72,21 +74,27 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche
const emit = parent.emit.bind(parent)

if (context.data.type === 'node') {
const component = node ? node(context.data) : Node
const component = node
? node(context.data)
: Node

return component && {
component, props: {
component,
props: {
data: context.data.payload,
emit
}
}
} else if (context.data.type === 'connection') {
const component = connection ? connection(context.data) : Connection
const component = connection
? connection(context.data)
: Connection
const { payload } = context.data
const { source, target, sourceOutput, targetInput } = payload

return component && {
component: ConnectionWrapper, props: {
component: ConnectionWrapper,
props: {
data: context.data.payload,
component,
start: context.data.start || ((change: any) => positionWatcher.listen(source, 'output', sourceOutput, change)),
Expand All @@ -110,10 +118,13 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche
}
} else if (context.data.type === 'socket') {
const { payload } = context.data
const component = socket ? socket(context.data) : Socket
const component = socket
? socket(context.data)
: Socket

return component && {
component, props: {
component,
props: {
data: payload
}
}
Expand All @@ -124,15 +135,17 @@ export function setup<Schemes extends ClassicScheme, K extends SvelteArea2D<Sche
const component = control(context.data)

return component && {
component, props: {
component,
props: {
data: payload
}
}
}

return context.data.payload instanceof ClassicPreset.InputControl
? {
component: Control, props: {
component: Control,
props: {
data: payload
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/presets/context-menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import type { ContextMenuRender } from './types'
* Preset for rendering context menu.
*/
export function setup<Schemes extends BaseSchemes, K extends ContextMenuRender>(props?: { delay?: number }): RenderPreset<Schemes, K> {
const delay = typeof props?.delay === 'undefined' ? 1000 : props.delay
const delay = typeof props?.delay === 'undefined'
? 1000
: props.delay

return {
update(context) {
Expand Down
2 changes: 1 addition & 1 deletion src/presets/minimap/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RenderSignal } from '../../types'
export type Rect = {
width: number
height: number
left: number,
left: number
top: number
}
export type Transform = {
Expand Down
6 changes: 3 additions & 3 deletions src/presets/reroute/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type Props = {
*/
export function setup<Schemes extends BaseSchemes, K extends PinsRender>(props?: Props): RenderPreset<Schemes, K> {
const getProps = () => ({
menu: props?.contextMenu || (() => null),
translate: props?.translate || (() => null),
down: props?.pointerdown || (() => null)
menu: props?.contextMenu ?? (() => null),
translate: props?.translate ?? (() => null),
down: props?.pointerdown ?? (() => null)
})

return {
Expand Down
1 change: 1 addition & 0 deletions src/presets/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-invalid-void-type */
import type { BaseSchemes } from 'rete'
import type { ComponentType } from 'svelte'

Expand Down
1 change: 1 addition & 0 deletions src/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-invalid-void-type */
import type { ComponentType, SvelteComponent } from 'svelte'

import Root from './Root.svelte'
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
Loading