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

Merged
merged 3 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
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 globals from 'globals'

export default tseslint.config(
...configs,
{
languageOptions: {
globals: {
...globals.browser
}
}
}
)
3,729 changes: 2,083 additions & 1,646 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 @@ -27,10 +27,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": "5.0"
"rete-cli": "~2.0.1"
},
"dependencies": {
"@babel/runtime": "^7.21.0"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* @listens contextmenu
* @listens pointerdown
*/
export class ContextMenuPlugin<Schemes extends BaseSchemes> extends Scope<never, [Requires<Schemes> | ContextMenuExtra]> {

Check warning on line 46 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

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

Check warning on line 46 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

This line has a length of 122. Maximum allowed is 120
/**
* @param props Properties
*/
Expand All @@ -55,9 +55,9 @@
super.setParent(scope)

const area = this.parentScope<BaseAreaPlugin<Schemes, BaseArea<Schemes>>>(BaseAreaPlugin)
const container: HTMLElement = (area as any).container

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unsafe assignment of an `any` value

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'area as any' has unsafe 'as' type assertion

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unsafe member access .container on an `any` value

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'container' is 'any'

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unsafe assignment of an `any` value

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The 'area as any' has unsafe 'as' type assertion

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unsafe member access .container on an `any` value

Check warning on line 58 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'container' is 'any'

if (!container || !(container instanceof HTMLElement)) throw new Error('container expected')

Check warning on line 60 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

Check warning on line 60 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

const element = document.createElement('div')

Expand All @@ -68,7 +68,7 @@
this.addPipe(context => {
const parent = this.parentScope()

if (!context || typeof context !== 'object' || !('type' in context)) return context

Check warning on line 71 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy

Check warning on line 71 in src/index.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unnecessary conditional, value is always falsy
if (context.type === 'unmount') {
if (context.data.element === element) {
element.style.display = 'none'
Expand All @@ -84,21 +84,21 @@
element.style.top = `${context.data.event.clientY}px`
element.style.display = ''

parent.emit({
void parent.emit({
type: 'render',
data: {
type: 'contextmenu',
element,
searchBar,
onHide() {
parent.emit({ type: 'unmount', data: { element } })
void parent.emit({ type: 'unmount', data: { element } })
},
items: list
}
})
} else if (context.type === 'pointerdown') {
if (!context.data.event.composedPath().includes(element)) {
parent.emit({ type: 'unmount', data: { element } })
void parent.emit({ type: 'unmount', data: { element } })
}
}
return context
Expand Down
19 changes: 11 additions & 8 deletions src/presets/classic/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@
export function createItem<S extends BSchemes>(
[label, factory]: ItemDefinition<S>,
key: string | number,
context: { editor: NodeEditor<S>, area: BaseAreaPlugin<S, any> }

Check warning on line 10 in src/presets/classic/factory.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'area' contains 'any'

Check warning on line 10 in src/presets/classic/factory.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type

Check warning on line 10 in src/presets/classic/factory.ts

View workflow job for this annotation

GitHub Actions / ci / ci

The type of 'area' contains 'any'

Check warning on line 10 in src/presets/classic/factory.ts

View workflow job for this annotation

GitHub Actions / ci / ci

Unexpected any. Specify a different type
): Item {
const item = {
const item: Item = {
label,
key: String(key)
key: String(key),
handler() {
/* noop */
}
}

if (typeof factory === 'function') {
return <Item>{
return {
...item,
async handler() {
const node = await factory()

await context.editor.addNode(node)

context.area.translate(node.id, context.area.area.pointer)
void context.area.translate(node.id, context.area.area.pointer)
}
}
} satisfies Item
}
return <Item>{
return {
...item,
handler() {/* do nothing */},
handler() { /* do nothing */ },
subitems: factory.map((data, i) => createItem(data, i, context))
}
} satisfies Item
}
18 changes: 10 additions & 8 deletions src/presets/classic/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { BSchemes, ItemDefinition } from './types'
* Configures nodes/actions items for root and Delete/Clone items for nodes
* @param nodes List of items
* @example Presets.classic.setup([
["Math", [
["Number", () => new NumberNode()],
]]
])
* ["Math", [
* ["Number", () => new NumberNode()],
* ]]
*])
*/
export function setup<Schemes extends BSchemes>(nodes: ItemDefinition<Schemes>[]) {
return <Items<Schemes>>(function (context, plugin) {
return function (context, plugin) {
const area = plugin.parentScope<BaseAreaPlugin<Schemes, any>>(BaseAreaPlugin)
const editor = area.parentScope<NodeEditor<Schemes>>(NodeEditor)

Expand Down Expand Up @@ -60,16 +60,18 @@ export function setup<Schemes extends BSchemes>(nodes: ItemDefinition<Schemes>[]

await editor.addNode(node)

area.translate(node.id, area.area.pointer)
void area.translate(node.id, area.area.pointer)
}
}

return {
searchBar: false,
list: [
deleteItem,
...(cloneItem ? [cloneItem] : [])
...cloneItem
? [cloneItem]
: []
]
}
})
} satisfies Items<Schemes>
}
2 changes: 1 addition & 1 deletion src/presets/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Presets that create items for root and node specific context menu.
* @module
*/
*/

export * as classic from './classic'
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export type Position = { x: number, y: number }
export type Item = {
label: string
key: string
handler(): void
handler(): void | Promise<void>
subitems?: Item[]
}

export type ItemsCollection = {
searchBar?: boolean,
searchBar?: boolean
list: Item[]
}

Expand Down
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"]
}
Loading