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

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
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,413 changes: 2,477 additions & 1,936 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 @@ -34,9 +34,10 @@
"@vitejs/plugin-vue": "^4.1.0",
"@vitejs/plugin-vue2": "^2.2.0",
"@vue/compiler-sfc": "^3.2.22",
"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-commonjs": "^9.2.2",
"rollup-plugin-pug": "1.1.1",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @param [context] to be used for createApp({ ...context }) or new Vue({ ...context })
* @returns app / vue instance.
*/
setup?: (context: Context) => Instance;
setup?: (context: Context) => Instance

Check warning on line 34 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'context' contains 'any'

Check warning on line 34 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'Context' contains 'any'

Check warning on line 34 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'context' contains 'any'

Check warning on line 34 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'Context' contains 'any'
}

/**
Expand All @@ -41,7 +41,7 @@
* @listens render
* @listens unmount
*/
export class VuePlugin<Schemes extends BaseSchemes, T = Requires<Schemes>> extends Scope<Produces<Schemes>, [Requires<Schemes> | T]> {

Check warning on line 44 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

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

Check warning on line 44 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

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

Check warning on line 62 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 62 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 63 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 63 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 @@ -94,7 +94,7 @@
if (existing) {
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 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) {
this.renderer.update(existing, result)
Expand All @@ -104,15 +104,15 @@
}

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

Check warning on line 107 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 107 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

this.renderer.mount(
element,
result.component,

Check warning on line 113 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'component' is 'any'

Check warning on line 113 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'component' is 'any'
result.props,
() => parent?.emit({ type: 'rendered', data: (context as Requires<Schemes>).data } as T)
() => parent.emit({ type: 'rendered', data: (context as Requires<Schemes>).data } as T)

Check warning on line 115 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 115 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 115 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 115 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
49 changes: 31 additions & 18 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,18 @@ type CustomizationProps<Schemes extends ClassicScheme> = {
control?: (data: ExtractPayload<Schemes, 'control'>) => Component<any> | 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 VueArea2D<Schemes>>(
props?: ClassicProps<Schemes, K>
): RenderPreset<Schemes, K> {
export function setup<Schemes extends ClassicScheme, K extends VueArea2D<Schemes>>(props?: ClassicProps<Schemes, K>): RenderPreset<Schemes, K> {
const positionWatcher = typeof props?.socketPositionWatcher === 'undefined'
? getDOMSocketPosition<Schemes, K>()
: props?.socketPositionWatcher
const { node, connection, socket, control } = props?.customize || {}
: props.socketPositionWatcher
const { node, connection, socket, control } = props?.customize ?? {}

return {
attach(plugin) {
Expand All @@ -60,8 +58,12 @@ export function setup<Schemes extends ClassicScheme, K extends VueArea2D<Schemes

return {
data: payload,
...(start ? { start } : {}),
...(end ? { end } : {})
...start
? { start }
: {},
...end
? { end }
: {}
}
}
return { data: payload }
Expand All @@ -72,25 +74,31 @@ export function setup<Schemes extends ClassicScheme, K extends VueArea2D<Schemes
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)),
end: context.data.end || ((change: any) => positionWatcher.listen(target, 'input', targetInput, change)),
start: context.data.start ?? ((change: any) => positionWatcher.listen(source, 'output', sourceOutput, change)),
end: context.data.end ?? ((change: any) => positionWatcher.listen(target, 'input', targetInput, change)),
path: async (start: Position, end: Position) => {
const response = await plugin.emit({ type: 'connectionpath', data: { payload, points: [start, end] } })

Expand All @@ -110,10 +118,13 @@ export function setup<Schemes extends ClassicScheme, K extends VueArea2D<Schemes
}
} 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, props: {
component,
props: {
data: payload
}
}
Expand All @@ -124,15 +135,17 @@ export function setup<Schemes extends ClassicScheme, K extends VueArea2D<Schemes
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: 2 additions & 2 deletions src/presets/classic/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ClassicPreset as Classic, GetSchemes, NodeId } from 'rete'

import { Position, RenderSignal } from '../../types'

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I)=> void)
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void)
? I
: never
type GetControls<
Expand Down Expand Up @@ -33,4 +33,4 @@ export type VueArea2D<T extends ClassicScheme> =
}>
| { type: 'unmount', data: { element: HTMLElement } }

export type ExtractPayload<T extends ClassicScheme, K extends string> = Extract<VueArea2D<T>, { type: 'render', data: { type: K }}>['data']
export type ExtractPayload<T extends ClassicScheme, K extends string> = Extract<VueArea2D<T>, { type: 'render', data: { type: K } }>['data']
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 { 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
4 changes: 2 additions & 2 deletions src/presets/minimap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function setup<Schemes extends BaseSchemes, K extends MinimapRender>(prop
if (context.data.type === 'minimap') {
return {
nodes: context.data.nodes,
size: props?.size || 200,
size: props?.size ?? 200,
ratio: context.data.ratio,
viewport: context.data.viewport,
translate: context.data.translate,
Expand All @@ -27,7 +27,7 @@ export function setup<Schemes extends BaseSchemes, K extends MinimapRender>(prop
component: Minimap,
props: {
nodes: context.data.nodes,
size: props?.size || 200,
size: props?.size ?? 200,
ratio: context.data.ratio,
viewport: context.data.viewport,
translate: context.data.translate,
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 { 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 { BaseSchemes } from 'rete'

import { VuePlugin } from '..'
Expand Down
4 changes: 2 additions & 2 deletions src/vuecompat/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ type Vue = typeof VueNamespace

export type Context = Vue extends { createApp: (arg: infer U) => any }
? U
: (Vue extends { new(options: infer U): any } ? U : any)
: (Vue extends new(options: infer U) => any ? U : any)

export type Instance = Vue extends { createApp: (arg: any) => infer U }
? U
: (Vue extends { new(options: any): infer U } ? U : any)
: (Vue extends new(options: any) => infer U ? U : any)
4 changes: 3 additions & 1 deletion src/vuecompat/vue2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export function create(element: any, component: any, payload: any, onRendered: a
}
}

const app: Vue & { payload?: Record<string, unknown> } = props?.setup ? props.setup(context) as Vue : new Vue(context)
const app: Vue & { payload?: Record<string, unknown> } = props?.setup
? props.setup(context) as Vue
: new Vue(context)

app.payload = payload

Expand Down
4 changes: 3 additions & 1 deletion src/vuecompat/vue3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export function create<P extends object>(element: HTMLElement, component: any, p
}
}

const app = props?.setup ? props.setup(context) : createApp(context)
const app = props?.setup
? props.setup(context)
: createApp(context)

app.mount(element)

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"]
},
"include": ["src"]
Expand Down
Loading