Skip to content

Commit 473fe0d

Browse files
committedNov 30, 2020
1.0.1 - First draft angular context menu for VisualNE
1 parent 6bf4371 commit 473fe0d

26 files changed

+13131
-0
lines changed
 

‎.babelrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
3+
"plugins": ["@babel/plugin-proposal-class-properties"]
4+
}

‎.eslintignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dist
2+
3+
node_modules
4+
5+
rollup.config.js

‎.eslintrc

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
"extends": ["plugin:@typescript-eslint/recommended"],
3+
"parser": "@typescript-eslint/parser",
4+
"globals": {
5+
"document": true,
6+
"alight": true,
7+
"window": true,
8+
"d3": true,
9+
"console": true,
10+
"uint8": true,
11+
"Promise": true,
12+
"HTMLElement": true,
13+
"alert": true,
14+
"prompt": true,
15+
"WindowEventMap": true
16+
},
17+
"rules": {
18+
"@typescript-eslint/ban-types": ["error",
19+
{
20+
"types": {
21+
"String": false,
22+
"Boolean": false,
23+
"Number": false,
24+
"Symbol": false,
25+
"{}": false,
26+
"Object": false,
27+
"object": false,
28+
"Function": false
29+
},
30+
"extendDefaults": true
31+
}
32+
],
33+
"@typescript-eslint/explicit-member-accessibility": "off",
34+
"@typescript-eslint/explicit-function-return-type": "off",
35+
"@typescript-eslint/interface-name-prefix": "off",
36+
"@typescript-eslint/no-empty-interface": "off",
37+
"@typescript-eslint/no-empty-function": "off",
38+
"@typescript-eslint/no-parameter-properties": "off",
39+
"@typescript-eslint/no-inferrable-types": "off",
40+
"@typescript-eslint/no-shadow": ["error"],
41+
"comma-dangle": [1, "never"],
42+
"no-cond-assign": 1,
43+
"no-console": 0,
44+
"no-constant-condition": 1,
45+
"sort-imports": ["warn", {
46+
"memberSyntaxSortOrder": ["single", "all", "multiple", "none"]
47+
}],
48+
"no-duplicate-imports": "warn",
49+
"no-control-regex": 1,
50+
"no-dupe-args": 2,
51+
"no-dupe-keys": 2,
52+
"no-duplicate-case": 2,
53+
"no-empty-character-class": 1,
54+
"no-empty": 1,
55+
"no-extra-boolean-cast": 2,
56+
"no-extra-semi": 1,
57+
"no-empty-function": ["error", { "allow": [
58+
"arrowFunctions", "methods", "constructors"
59+
]
60+
}],
61+
"no-func-assign": 2,
62+
"no-inner-declarations": 1,
63+
"no-negated-in-lhs": 1,
64+
"no-sparse-arrays": 2,
65+
"no-unreachable": 2,
66+
"default-case": 1,
67+
"eqeqeq": 1,
68+
"no-caller": 2,
69+
"no-else-return": 1,
70+
"no-eq-null": 2,
71+
"no-eval": 2,
72+
"no-fallthrough": 1,
73+
"no-implied-eval": 1,
74+
"no-labels": 1,
75+
"no-loop-func": 2,
76+
"no-multi-spaces": 1,
77+
"no-new": "off",
78+
"no-proto": 1,
79+
"no-redeclare": 1,
80+
"no-self-compare": 1,
81+
"init-declarations": 1,
82+
// note you must disable the base rule as it can report incorrect errors
83+
"no-shadow": "off",
84+
"no-undef": "error",
85+
"no-undefined": 2,
86+
"no-unused-vars": "off",
87+
"no-use-before-define": 1,
88+
"object-curly-spacing": [2, "always"],
89+
"camelcase": [1, {
90+
"properties": "always"
91+
}],
92+
"comma-spacing": [1, {
93+
"before": false,
94+
"after": true
95+
}],
96+
"indent": ["warn", 4],
97+
"new-cap": [1, {
98+
"newIsCap": true
99+
}],
100+
"newline-after-var": [1, "always"],
101+
"no-mixed-spaces-and-tabs": [1, "smart-tabs"],
102+
"no-multiple-empty-lines": [1, {
103+
"max": 1
104+
}],
105+
"quotes": [1, "double", "avoid-escape"],
106+
"space-before-blocks": [1, "always"],
107+
"space-in-parens": [1, "never"],
108+
"keyword-spacing": 1,
109+
"max-depth": [1, 4],
110+
"max-len": ["warn", 120],
111+
"max-params": [1, 6],
112+
"max-statements": [1, 10]
113+
},
114+
"plugins": ["@typescript-eslint"],
115+
"parserOptions": {
116+
"sourceType": "module"
117+
},
118+
"env": {
119+
"es6": true,
120+
"browser": true
121+
}
122+
}

‎.gitignore

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
# Only exists if Bazel was run
8+
/bazel-out
9+
10+
# dependencies
11+
/node_modules
12+
13+
#lock files
14+
package-lock.json
15+
yarn-lock.json
16+
17+
# profiling files
18+
chrome-profiler-events.json
19+
speed-measure-plugin.json
20+
21+
# IDEs and editors
22+
/.idea
23+
.project
24+
.classpath
25+
.c9/
26+
*.launch
27+
.settings/
28+
*.sublime-workspace
29+
30+
# IDE - VSCode
31+
.vscode/*
32+
!.vscode/settings.json
33+
!.vscode/tasks.json
34+
!.vscode/launch.json
35+
!.vscode/extensions.json
36+
.history/*
37+
38+
# misc
39+
/.sass-cache
40+
/connect.lock
41+
/coverage
42+
/libpeerconnection.log
43+
npm-debug.log
44+
yarn-error.log
45+
testem.log
46+
/typings
47+
48+
# System Files
49+
.DS_Store
50+
Thumbs.db

‎.npmignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.idea/
3+
.vscode/

‎README.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
Rete context menu plugin
2+
====
3+
#### Rete.js plugin
4+
5+
```js
6+
import ContextMenuPlugin, { Menu, Item, Search } from 'rete-context-menu-plugin';
7+
8+
editor.use(ContextMenuPlugin, {
9+
searchBar: false, // true by default
10+
searchKeep: title => true, // leave item when searching, optional. For example, title => ['Refresh'].includes(title)
11+
delay: 100,
12+
allocate(component) {
13+
return ['Submenu'];
14+
},
15+
rename(component) {
16+
return component.name;
17+
},
18+
items: {
19+
'Click me'(){ console.log('Works!') }
20+
},
21+
nodeItems: {
22+
'Click me'(){ console.log('Works for node!') },
23+
'Delete': false, // don't show Delete item
24+
'Clone': false // or Clone item
25+
},
26+
// OR
27+
nodeItems: node => {
28+
if (node.name === 'Add') {
29+
return {
30+
'Only for Add nodes'() => { console.log('Works for add node!') },
31+
};
32+
}
33+
return {
34+
'Click me'(){ console.log('Works for node!') }
35+
}
36+
},
37+
vueComponent: CustomVueComponent // extends Menu
38+
});
39+
```
40+
| Options | Description | Default |
41+
|-|-|-|
42+
| `searchBar` | Showing search bar | `true`
43+
| `delay` | Delay hide, ms | `1000`
44+
| `allocate` | function for placing of components into submenu | `() => []`
45+
| `rename` | function for renaming of items| `component => component.name`
46+
| `items` | custom items (`Object` with nested objects and functions) | `{}`
47+
| `nodeItems` | custom items for Node menu or a function that returns node items | `{}`
48+
49+
50+
You can arbitrarily put a component in a submenu. Examples:
51+
52+
```js
53+
allocate() { return ["Single submenu"] }
54+
```
55+
56+
```js
57+
allocate(component) { return component.path } // where path is a stack of menu for every component
58+
```
59+
60+
61+
```js
62+
allocate(component) { return null } // exclude component from menu items
63+
```
64+
65+
To change the items that create nodes, you may need to change the name.
66+
67+
```js
68+
class MyComponent {
69+
constructor() {
70+
super("My comp");
71+
this.contextMenuName = "Add My comp";
72+
}
73+
}
74+
///
75+
rename(component) { return component.contextMenuName || component.name }
76+
```
77+
78+
Prevent showing context menu
79+
80+
```js
81+
editor.on('showcontextmenu', ({ e, node }) => { // e - MouseEvent, node - Node instance or null
82+
return Boolean(node); // show context menu for nodes only
83+
});
84+
```
85+
Prevent context menu for particular Node
86+
87+
```js
88+
class AddComponent extends Rete.Component {
89+
constructor(){
90+
// ...
91+
this.data.noContextMenu = true;
92+
}
93+
// ...
94+
95+
editor.on('showcontextmenu', ({ node }) => {
96+
return !node || !editor.components.get(node.name).data.noContextMenu;
97+
});
98+
```

‎ng-package.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "./dist",
4+
"lib": {
5+
"entryFile": "src/index.ts",
6+
"umdModuleIds": {
7+
"visualne": "visualne"
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)