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 1b8e00e commit 326f630
Show file tree
Hide file tree
Showing 11 changed files with 2,122 additions and 1,674 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 @@ -3,3 +3,6 @@ node_modules
.vscode/
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/eslint.config.mjs';
import gloals from 'globals'

export default tseslint.config(
...configs,
{
languageOptions: {
globals: {
...gloals.browser
}
}
}
)
3,727 changes: 2,077 additions & 1,650 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 @@ -28,10 +28,10 @@
},
"devDependencies": {
"@types/node": "^20.4.2",
"globals": "^15.9.0",
"rete": "^2.0.1",
"rete-area-plugin": "^2.0.0",
"rete-cli": "^1.0.2",
"typescript": "^4.9.3"
"rete-cli": "~2.0.0"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
Expand Down
1 change: 1 addition & 0 deletions src/click-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class ClickStrategy<K> implements Strategy {
constructor(private editor: NodeEditor<BaseSchemes>, private area: AreaPlugin<BaseSchemes, K>) { }

add(element: HTMLElement, create: () => BaseSchemes['Node']): void {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
element.addEventListener('click', async () => {
const node = create()

Expand Down
8 changes: 5 additions & 3 deletions src/drop-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ export class DropStrategy<K> implements Strategy {
current?: () => BaseSchemes['Node']

constructor(private editor: NodeEditor<BaseSchemes>, private area: AreaPlugin<BaseSchemes, K>) {
area.container.addEventListener('dragover', e => e.preventDefault())
area.container.addEventListener('drop', async event => {
area.container.addEventListener('dragover', e => {
e.preventDefault()
})
area.container.addEventListener('drop', event => {
if (!this.current) return

try {
this.area.area.setPointerFrom(event)
this.drop(this.current(), this.area.area.pointer)
void this.drop(this.current(), this.area.area.pointer)
} finally {
delete this.current
}
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export * as DockPresets from './presets'
* @priority 10
* @emits render
*/
export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2DInherited<Schemes, never>> {
export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2DInherited<Schemes>> {
nodes = new Map<() => Schemes['Node'], { preset: Preset, element: HTMLElement }>()
clickStrategy!: Strategy
dropStrategy!: Strategy
Expand Down Expand Up @@ -46,7 +46,7 @@ export class DockPlugin<Schemes extends BaseSchemes> extends Scope<never, Area2D

if (!element) continue

this.parentScope().emit({
void this.parentScope().emit({
type: 'render',
data: {
type: 'node',
Expand Down
21 changes: 15 additions & 6 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ function getContainer(size: number) {

style.background = getGradient(size)

element.addEventListener('pointerdown', e => e.stopPropagation())
element.addEventListener('contextmenu', e => e.stopPropagation())
element.addEventListener('pointerdown', e => {
e.stopPropagation()
})
element.addEventListener('contextmenu', e => {
e.stopPropagation()
})

return element
}

// eslint-disable-next-line max-statements
function getNodeContainer(size: number, scale: number) {
const element = document.createElement('div')
const { style } = element
Expand All @@ -61,16 +64,22 @@ function getNodeContainer(size: number, scale: number) {
* @param props.area Area plugin instance
*/
export function setup<T>(props: { size?: number, scale?: number, area: AreaPlugin<BaseSchemes, T> }): Preset {
const size = typeof props.size === 'undefined' ? 100 : props.size
const scale = typeof props.scale === 'undefined' ? 0.7 : props.scale
const size = typeof props.size === 'undefined'
? 100
: props.size
const scale = typeof props.scale === 'undefined'
? 0.7
: props.scale
const container = getContainer(size)

props.area.container.appendChild(container)

return {
createItem(index) {
const element = getNodeContainer(size, scale)
const beforeChild = typeof index !== 'undefined' ? container.children[index] : null
const beforeChild = typeof index !== 'undefined'
? container.children[index]
: null

container.insertBefore(element, beforeChild)

Expand Down
4 changes: 2 additions & 2 deletions src/presets/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Preset = {
createItem(index?: number): HTMLElement | null
removeItem(element: HTMLElement): void
createItem(index?: number): HTMLElement | null
removeItem(element: HTMLElement): void
}
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"]
}

0 comments on commit 326f630

Please sign in to comment.