Skip to content

Commit 104c6c1

Browse files
committed
feat: upgrade to G6 3.3.x
1 parent e05421a commit 104c6c1

File tree

40 files changed

+250
-397
lines changed

40 files changed

+250
-397
lines changed

babel.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ module.exports = function(api) {
1212
'@babel/preset-react',
1313
];
1414

15+
const plugins = ['lodash'];
16+
1517
return {
1618
presets,
19+
plugins,
1720
};
1821
};

examples/component-command/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import upperFirst from 'lodash/upperFirst';
44
import { Divider, Tooltip } from 'antd';
55
import { EditorCommand } from '@/common/constants/index.js';
66
import GGEditor, { Flow, Mind, Command, ContextMenu, EditableLabel } from '@/index';
7+
import { Item } from '@/common/interfaces';
78
import flowData from '../mock/flow.json';
89
import mindData from '../mock/mind.json';
910
import IconFont from './IconFont';
@@ -40,7 +41,7 @@ const MIND_COMMAND_LIST = [
4041
];
4142

4243
class Index extends React.Component {
43-
renderContent = (item: G6.Item, position: { x: number; y: number }, hide: () => void) => {
44+
renderContent = (item: Item, position: { x: number; y: number }, hide: () => void) => {
4445
const { x: left, y: top } = position;
4546

4647
return (

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@
6060
"@babel/plugin-transform-runtime": "^7.7.6",
6161
"@babel/preset-env": "^7.7.6",
6262
"@babel/preset-react": "^7.7.4",
63-
"@types/lodash": "^4.14.144",
63+
"@rollup/plugin-commonjs": "^11.0.2",
64+
"@rollup/plugin-json": "^4.0.2",
65+
"@rollup/plugin-node-resolve": "^7.1.1",
66+
"@rollup/plugin-replace": "^2.3.1",
67+
"@types/lodash": "^4.14.149",
6468
"@types/react": "^16.9.9",
6569
"@types/react-dom": "^16.9.2",
6670
"@typescript-eslint/eslint-plugin": "^2.4.0",
6771
"@typescript-eslint/parser": "^2.4.0",
6872
"antd": "^3.24.2",
73+
"babel-plugin-lodash": "^3.3.4",
6974
"conventional-changelog-cli": "^2.0.31",
7075
"cz-conventional-changelog": "^3.0.2",
7176
"eslint": "^6.5.1",
@@ -75,20 +80,15 @@
7580
"husky": "^3.0.9",
7681
"inquirer": "^7.0.0",
7782
"less": "^3.10.3",
78-
"lodash": "^4.17.15",
7983
"prettier": "^1.18.2",
8084
"pretty-quick": "^2.0.0",
8185
"react": "^16.11.0",
8286
"react-dom": "^16.11.0",
8387
"rimraf": "^3.0.0",
8488
"rollup": "^1.24.0",
8589
"rollup-plugin-babel": "^4.3.3",
86-
"rollup-plugin-commonjs": "^10.1.0",
87-
"rollup-plugin-json": "^4.0.0",
8890
"rollup-plugin-livereload": "^1.0.4",
89-
"rollup-plugin-node-resolve": "^5.2.0",
9091
"rollup-plugin-postcss": "^2.0.3",
91-
"rollup-plugin-replace": "^2.2.0",
9292
"rollup-plugin-serve": "^1.0.1",
9393
"rollup-plugin-terser": "^5.1.2",
9494
"rollup-plugin-typescript2": "^0.24.3",

scripts/build.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
const signale = require('signale');
55
const rimraf = require('rimraf');
66
const rollup = require('rollup');
7-
const resolve = require('rollup-plugin-node-resolve');
8-
const replace = require('rollup-plugin-replace');
9-
const commonjs = require('rollup-plugin-commonjs');
7+
const resolve = require('@rollup/plugin-node-resolve');
8+
const replace = require('@rollup/plugin-replace');
9+
const commonjs = require('@rollup/plugin-commonjs');
1010
const typescript = require('rollup-plugin-typescript2');
1111
const babel = require('rollup-plugin-babel');
1212
const { terser } = require('rollup-plugin-terser');
@@ -37,7 +37,9 @@ async function build() {
3737
const umdBundle = await rollup.rollup({
3838
input: 'src/index.tsx',
3939
plugins: [
40-
resolve(),
40+
resolve({
41+
browser: true,
42+
}),
4143
replace({
4244
'process.env.GG_EDITOR_VERSION': JSON.stringify(version),
4345
}),
@@ -50,8 +52,7 @@ async function build() {
5052
},
5153
}),
5254
babel({
53-
exclude: 'node_modules/**',
54-
extensions: ['.ts', '.tsx'],
55+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
5556
}),
5657
terser(),
5758
],

scripts/start.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const signale = require('signale');
77
const rimraf = require('rimraf');
88
const rollup = require('rollup');
99
const postcss = require('rollup-plugin-postcss');
10-
const resolve = require('rollup-plugin-node-resolve');
11-
const replace = require('rollup-plugin-replace');
12-
const commonjs = require('rollup-plugin-commonjs');
10+
const resolve = require('@rollup/plugin-node-resolve');
11+
const replace = require('@rollup/plugin-replace');
12+
const commonjs = require('@rollup/plugin-commonjs');
1313
const typescript = require('rollup-plugin-typescript2');
1414
const babel = require('rollup-plugin-babel');
15-
const json = require('rollup-plugin-json');
15+
const json = require('@rollup/plugin-json');
1616
const serve = require('rollup-plugin-serve');
1717
const livereload = require('rollup-plugin-livereload');
1818
const { version } = require('../package.json');
@@ -46,7 +46,9 @@ function start(name) {
4646
generateScopedName: '[local]--[hash:base64:5]',
4747
},
4848
}),
49-
resolve(),
49+
resolve({
50+
browser: true,
51+
}),
5052
replace({
5153
'process.env.GG_EDITOR_VERSION': JSON.stringify(version),
5254
}),
@@ -55,8 +57,7 @@ function start(name) {
5557
tsconfig: 'examples/tsconfig.json',
5658
}),
5759
babel({
58-
exclude: 'node_modules/**',
59-
extensions: ['.ts', '.tsx'],
60+
extensions: ['.js', '.jsx', '.ts', '.tsx'],
6061
}),
6162
json(),
6263
serve({

src/common/behaviorManager/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import G6 from '@antv/g6';
22
import { isMind } from '@/utils';
33
import { GraphType } from '@/common/constants';
4-
import { Behavior } from '@/common/interfaces';
4+
import { Graph, Behavior } from '@/common/interfaces';
55

66
class BehaviorManager {
77
behaviors: {
@@ -47,8 +47,8 @@ class BehaviorManager {
4747
const { graph } = this;
4848

4949
if (
50-
(type === GraphType.Flow && isMind(graph as G6.Graph) === false) ||
51-
(type === GraphType.Mind && isMind(graph as G6.Graph))
50+
(type === GraphType.Flow && isMind(graph as Graph) === false) ||
51+
(type === GraphType.Mind && isMind(graph as Graph))
5252
) {
5353
handler.apply(this, params);
5454
}
@@ -65,15 +65,15 @@ class BehaviorManager {
6565

6666
switch (graphType) {
6767
case GraphType.Flow:
68-
G6.registerBehavior(name, this.wrapEventHandler(GraphType.Flow, behavior));
68+
G6.registerBehavior(name, this.wrapEventHandler(GraphType.Flow, behavior) as any);
6969
break;
7070

7171
case GraphType.Mind:
72-
G6.registerBehavior(name, this.wrapEventHandler(GraphType.Mind, behavior));
72+
G6.registerBehavior(name, this.wrapEventHandler(GraphType.Mind, behavior) as any);
7373
break;
7474

7575
default:
76-
G6.registerBehavior(name, behavior);
76+
G6.registerBehavior(name, behavior as any);
7777
break;
7878
}
7979
}

src/common/commandManager/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import cloneDeep from 'lodash/cloneDeep';
22
import { getGraphState } from '@/utils';
33
import { EditorEvent } from '@/common/constants';
4-
import { Command } from '@/common/interfaces';
4+
import { Graph, Command } from '@/common/interfaces';
55

66
class CommandManager {
77
command: {
@@ -25,7 +25,7 @@ class CommandManager {
2525
}
2626

2727
/** 执行命令 */
28-
execute(graph: G6.Graph, name: string, params?: object) {
28+
execute(graph: Graph, name: string, params?: object) {
2929
const Command = this.command[name];
3030

3131
if (!Command) {
@@ -79,12 +79,12 @@ class CommandManager {
7979
}
8080

8181
/** 判断是否可以执行 */
82-
canExecute(graph: G6.Graph, name: string) {
82+
canExecute(graph: Graph, name: string) {
8383
return this.command[name].canExecute(graph);
8484
}
8585

8686
/** 注入是否应该执行 */
87-
injectShouldExecute(name: string, shouldExecute: (graph: G6.Graph) => boolean) {
87+
injectShouldExecute(name: string, shouldExecute: (graph: Graph) => boolean) {
8888
this.command[name].shouldExecute = shouldExecute;
8989
}
9090
}

0 commit comments

Comments
 (0)