echarts-for-react 3.0.4 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/esm/core.d.ts +9 -1
  2. package/esm/core.js +25 -20
  3. package/esm/core.js.map +1 -1
  4. package/esm/helper/pick.d.ts +1 -1
  5. package/esm/helper/pick.js.map +1 -1
  6. package/esm/types.d.ts +2 -10
  7. package/esm/types.js.map +1 -1
  8. package/lib/core.d.ts +9 -1
  9. package/lib/core.js +24 -19
  10. package/lib/core.js.map +1 -1
  11. package/lib/helper/pick.d.ts +1 -1
  12. package/lib/helper/pick.js.map +1 -1
  13. package/lib/types.d.ts +2 -10
  14. package/lib/types.js.map +1 -1
  15. package/package.json +1 -1
  16. package/src/.umi/core/devScripts.ts +53 -0
  17. package/src/.umi/core/history.ts +21 -0
  18. package/src/.umi/core/plugin.ts +8 -0
  19. package/src/.umi/core/pluginConfig.d.ts +300 -0
  20. package/src/.umi/core/pluginRegister.ts +5 -0
  21. package/src/.umi/core/polyfill.ts +4 -0
  22. package/src/.umi/core/routes.ts +389 -0
  23. package/src/.umi/core/umiExports.ts +3 -0
  24. package/src/.umi/dumi/apis.json +1 -0
  25. package/src/.umi/dumi/config.json +129 -0
  26. package/src/.umi/dumi/demos/index.ts +5469 -0
  27. package/src/.umi/dumi/layout.tsx +8 -0
  28. package/src/.umi/umi.ts +58 -0
  29. package/src/.umi-production/core/history.ts +21 -0
  30. package/src/.umi-production/core/plugin.ts +8 -0
  31. package/src/.umi-production/core/pluginConfig.d.ts +300 -0
  32. package/src/.umi-production/core/pluginRegister.ts +5 -0
  33. package/src/.umi-production/core/polyfill.ts +4 -0
  34. package/src/.umi-production/core/routes.ts +389 -0
  35. package/src/.umi-production/core/umiExports.ts +3 -0
  36. package/src/.umi-production/dumi/apis.json +1 -0
  37. package/src/.umi-production/dumi/config.json +129 -0
  38. package/src/.umi-production/dumi/demos/index.ts +5469 -0
  39. package/src/.umi-production/dumi/layout.tsx +8 -0
  40. package/src/.umi-production/umi.ts +58 -0
  41. package/src/core.tsx +48 -20
  42. package/src/helper/pick.ts +2 -2
  43. package/src/types.ts +1 -10
@@ -0,0 +1,8 @@
1
+ // @ts-nocheck
2
+ import React from 'react';
3
+ import config from '@@/dumi/config';
4
+ import demos from '@@/dumi/demos';
5
+ import apis from '@@/dumi/apis';
6
+ import Layout from '/Users/xiaowei/Documents/code/antv/echarts-for-react/node_modules/_@umijs_preset-dumi@1.1.54@@umijs/preset-dumi/lib/theme/layout';
7
+
8
+ export default (props) => <Layout {...props} config={config} demos={demos} apis={apis} />;
@@ -0,0 +1,58 @@
1
+ // @ts-nocheck
2
+ import './core/polyfill';
3
+
4
+ import { plugin } from './core/plugin';
5
+ import './core/pluginRegister';
6
+ import { createHistory } from './core/history';
7
+ import { ApplyPluginsType } from '/Users/xiaowei/Documents/code/antv/echarts-for-react/node_modules/_@umijs_runtime@3.5.43@@umijs/runtime';
8
+ import { renderClient } from '/Users/xiaowei/Documents/code/antv/echarts-for-react/node_modules/_@umijs_renderer-react@3.5.43@@umijs/renderer-react/dist/index.js';
9
+ import { getRoutes } from './core/routes';
10
+
11
+
12
+
13
+
14
+ const getClientRender = (args: { hot?: boolean; routes?: any[] } = {}) => plugin.applyPlugins({
15
+ key: 'render',
16
+ type: ApplyPluginsType.compose,
17
+ initialValue: () => {
18
+ const opts = plugin.applyPlugins({
19
+ key: 'modifyClientRenderOpts',
20
+ type: ApplyPluginsType.modify,
21
+ initialValue: {
22
+ routes: args.routes || getRoutes(),
23
+ plugin,
24
+ history: createHistory(args.hot),
25
+ isServer: process.env.__IS_SERVER,
26
+ rootElement: 'root',
27
+ defaultTitle: ``,
28
+ },
29
+ });
30
+ return renderClient(opts);
31
+ },
32
+ args,
33
+ });
34
+
35
+ const clientRender = getClientRender();
36
+ export default clientRender();
37
+
38
+
39
+ window.g_umi = {
40
+ version: '3.5.43',
41
+ };
42
+
43
+
44
+ // hot module replacement
45
+ // @ts-ignore
46
+ if (module.hot) {
47
+ // @ts-ignore
48
+ module.hot.accept('./core/routes', () => {
49
+ const ret = require('./core/routes');
50
+ if (ret.then) {
51
+ ret.then(({ getRoutes }) => {
52
+ getClientRender({ hot: true, routes: getRoutes() })();
53
+ });
54
+ } else {
55
+ getClientRender({ hot: true, routes: ret.getRoutes() })();
56
+ }
57
+ });
58
+ }
package/src/core.tsx CHANGED
@@ -26,12 +26,18 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
26
26
  */
27
27
  protected echarts: any;
28
28
 
29
+ /**
30
+ * Currently attached ECharts event listeners
31
+ */
32
+ private eventHandlerRefs: Record<string, Function>;
33
+
29
34
  constructor(props: EChartsReactProps) {
30
35
  super(props);
31
36
 
32
37
  this.echarts = props.echarts;
33
38
  this.ele = null;
34
39
  this.isInitialResize = true;
40
+ this.eventHandlerRefs = {};
35
41
  }
36
42
 
37
43
  componentDidMount() {
@@ -52,10 +58,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
52
58
  // 以下属性修改的时候,需要 dispose 之后再新建
53
59
  // 1. 切换 theme 的时候
54
60
  // 2. 修改 opts 的时候
55
- if (
56
- !isEqual(prevProps.theme, this.props.theme) ||
57
- !isEqual(prevProps.opts, this.props.opts)
58
- ) {
61
+ if (!isEqual(prevProps.theme, this.props.theme) || !isEqual(prevProps.opts, this.props.opts)) {
59
62
  this.dispose();
60
63
 
61
64
  this.renderNewEcharts(); // 重建
@@ -65,13 +68,13 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
65
68
  // 修改 onEvent 的时候先移除历史事件再添加
66
69
  const echartsInstance = this.getEchartsInstance();
67
70
  if (!isEqual(prevProps.onEvents, this.props.onEvents)) {
68
- this.offEvents(echartsInstance, prevProps.onEvents);
71
+ this.unbindEvents(echartsInstance);
69
72
  this.bindEvents(echartsInstance, this.props.onEvents);
70
73
  }
71
74
 
72
75
  // when these props are not isEqual, update echarts
73
- const pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'];
74
- if (!isEqual(pick(this.props, pickKeys), pick(prevProps, pickKeys))) {
76
+ const pickKeys = ['option', 'notMerge', 'replaceMerge', 'lazyUpdate', 'showLoading', 'loadingOption'] as const;
77
+ if (!isEqual(pick(this.props, pickKeys), pick(prevProps as any, pickKeys))) {
75
78
  this.updateEChartsOption();
76
79
  }
77
80
 
@@ -166,15 +169,21 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
166
169
 
167
170
  // bind the events
168
171
  private bindEvents(instance, events: EChartsReactProps['onEvents']) {
169
- function _bindEvent(eventName: string, func: Function) {
172
+ const _bindEvent = (eventName: string, func: Function) => {
170
173
  // ignore the event config which not satisfy
171
174
  if (isString(eventName) && isFunction(func)) {
172
175
  // binding event
173
- instance.on(eventName, (param) => {
176
+ const handler = (param) => {
174
177
  func(param, instance);
175
- });
178
+ };
179
+
180
+ instance.on(eventName, handler);
181
+
182
+ // Store currently bound event handlers. This way we can unbind them
183
+ // on next component update, before binding the new handlers.
184
+ this.eventHandlerRefs[eventName] = handler;
176
185
  }
177
- }
186
+ };
178
187
 
179
188
  // loop and bind
180
189
  for (const eventName in events) {
@@ -184,15 +193,16 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
184
193
  }
185
194
  }
186
195
 
187
- // off the events
188
- private offEvents(instance, events: EChartsReactProps['onEvents']) {
189
- if (!events) return;
190
- // loop and off
191
- for (const eventName in events) {
192
- if (isString(eventName)) {
193
- instance.off(eventName);
194
- }
196
+ /**
197
+ * Unbind all currently bound event handlers. Importantly, this does not
198
+ * unbind the `"finished"` event that is used for chart initialization.
199
+ */
200
+ private unbindEvents(instance: EChartsInstance) {
201
+ for (const [eventName, listener] of Object.entries(this.eventHandlerRefs)) {
202
+ instance.off(eventName, listener);
195
203
  }
204
+
205
+ this.eventHandlerRefs = {};
196
206
  }
197
207
 
198
208
  /**
@@ -243,7 +253,24 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
243
253
  }
244
254
 
245
255
  render(): JSX.Element {
246
- const { style, className = '' } = this.props;
256
+ const {
257
+ style,
258
+ className = '',
259
+ echarts,
260
+ option,
261
+ theme,
262
+ notMerge,
263
+ replaceMerge,
264
+ lazyUpdate,
265
+ showLoading,
266
+ loadingOption,
267
+ opts,
268
+ onChartReady,
269
+ onEvents,
270
+ shouldSetOption,
271
+ autoResize,
272
+ ...divHTMLAttributes
273
+ } = this.props;
247
274
  // default height = 300
248
275
  const newStyle = { height: 300, ...style };
249
276
 
@@ -254,6 +281,7 @@ export default class EChartsReactCore extends PureComponent<EChartsReactProps> {
254
281
  }}
255
282
  style={newStyle}
256
283
  className={`echarts-for-react ${className}`}
284
+ {...divHTMLAttributes}
257
285
  />
258
286
  );
259
287
  }
@@ -3,8 +3,8 @@
3
3
  * @param obj
4
4
  * @param keys
5
5
  */
6
- export function pick(obj: Record<string, unknown>, keys: string[]): Record<string, unknown> {
7
- const r = {};
6
+ export function pick<T extends object>(obj: T, keys: readonly (keyof T)[]): Partial<T> {
7
+ const r = {} as Partial<T>;
8
8
  keys.forEach((key) => {
9
9
  r[key] = obj[key];
10
10
  });
package/src/types.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { CSSProperties } from 'react';
2
1
  import type { EChartsType } from 'echarts';
3
2
 
4
3
  /**
@@ -16,19 +15,11 @@ export type Opts = {
16
15
  readonly locale?: string;
17
16
  };
18
17
 
19
- export type EChartsReactProps = {
18
+ export type EChartsReactProps = React.HTMLAttributes<HTMLDivElement> & {
20
19
  /**
21
20
  * echarts library entry, use it for import necessary.
22
21
  */
23
22
  readonly echarts?: any;
24
- /**
25
- * `className` for container
26
- */
27
- readonly className?: string;
28
- /**
29
- * `style` for container
30
- */
31
- readonly style?: CSSProperties;
32
23
  /**
33
24
  * echarts option
34
25
  */