victory-shared-events 36.8.2 → 36.8.4
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.
- package/CHANGELOG.md +14 -0
- package/dist/victory-shared-events.js +1007 -8791
- package/dist/victory-shared-events.min.js +1 -1
- package/es/index.d.ts +2 -23
- package/es/index.js +1 -1
- package/es/victory-shared-events.d.ts +51 -0
- package/es/victory-shared-events.js +17 -37
- package/lib/index.d.ts +2 -23
- package/lib/index.js +11 -8
- package/lib/victory-shared-events.d.ts +51 -0
- package/lib/victory-shared-events.js +16 -35
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/{victory-shared-events.js → victory-shared-events.tsx} +39 -70
- package/src/index.d.ts +0 -23
- package/src/index.js +0 -1
|
@@ -8,92 +8,65 @@ import {
|
|
|
8
8
|
difference,
|
|
9
9
|
} from "lodash";
|
|
10
10
|
import React from "react";
|
|
11
|
-
import PropTypes from "prop-types";
|
|
12
11
|
import {
|
|
13
|
-
|
|
12
|
+
EventCallbackInterface,
|
|
13
|
+
EventMixinCalculatedValues,
|
|
14
|
+
EventPropTypeInterface,
|
|
14
15
|
Events,
|
|
15
16
|
Helpers,
|
|
17
|
+
StringOrNumberOrCallback,
|
|
16
18
|
TimerContext,
|
|
17
19
|
} from "victory-core";
|
|
18
20
|
import isEqual from "react-fast-compare";
|
|
19
21
|
import stringify from "json-stringify-safe";
|
|
20
22
|
|
|
23
|
+
export type VictorySharedEventsProps = {
|
|
24
|
+
children?: React.ReactElement | React.ReactElement[];
|
|
25
|
+
container?: React.ReactElement;
|
|
26
|
+
groupComponent?: React.ReactElement;
|
|
27
|
+
events?: EventPropTypeInterface<string, StringOrNumberOrCallback>[];
|
|
28
|
+
eventKey?: StringOrNumberOrCallback;
|
|
29
|
+
externalEventMutations?: EventCallbackInterface<
|
|
30
|
+
string | string[],
|
|
31
|
+
string | number | (string | number)[]
|
|
32
|
+
>[];
|
|
33
|
+
};
|
|
34
|
+
|
|
21
35
|
// DISCLAIMER:
|
|
22
36
|
// This file is not currently tested, and it is first on the list of files
|
|
23
37
|
// to refactor in our current refactoring effort. Please do not make changes
|
|
24
38
|
// to this file without manual testing and/or refactoring and adding tests.
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
|
|
40
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
41
|
+
export interface VictorySharedEvents extends EventMixinCalculatedValues {}
|
|
28
42
|
|
|
43
|
+
export class VictorySharedEvents extends React.Component<VictorySharedEventsProps> {
|
|
44
|
+
static displayName = "VictorySharedEvents";
|
|
29
45
|
static role = "shared-event-wrapper";
|
|
30
|
-
|
|
31
|
-
static propTypes = {
|
|
32
|
-
children: PropTypes.oneOfType([
|
|
33
|
-
PropTypes.arrayOf(PropTypes.node),
|
|
34
|
-
PropTypes.node,
|
|
35
|
-
]),
|
|
36
|
-
container: PropTypes.node,
|
|
37
|
-
eventKey: PropTypes.oneOfType([
|
|
38
|
-
PropTypes.array,
|
|
39
|
-
PropTypes.func,
|
|
40
|
-
CustomPropTypes.allOfType([
|
|
41
|
-
CustomPropTypes.integer,
|
|
42
|
-
CustomPropTypes.nonNegative,
|
|
43
|
-
]),
|
|
44
|
-
PropTypes.string,
|
|
45
|
-
]),
|
|
46
|
-
events: PropTypes.arrayOf(
|
|
47
|
-
PropTypes.shape({
|
|
48
|
-
childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
|
49
|
-
eventHandlers: PropTypes.object,
|
|
50
|
-
eventKey: PropTypes.oneOfType([
|
|
51
|
-
PropTypes.array,
|
|
52
|
-
PropTypes.func,
|
|
53
|
-
CustomPropTypes.allOfType([
|
|
54
|
-
CustomPropTypes.integer,
|
|
55
|
-
CustomPropTypes.nonNegative,
|
|
56
|
-
]),
|
|
57
|
-
PropTypes.string,
|
|
58
|
-
]),
|
|
59
|
-
target: PropTypes.string,
|
|
60
|
-
}),
|
|
61
|
-
),
|
|
62
|
-
externalEventMutations: PropTypes.arrayOf(
|
|
63
|
-
PropTypes.shape({
|
|
64
|
-
callback: PropTypes.func,
|
|
65
|
-
childName: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
|
66
|
-
eventKey: PropTypes.oneOfType([
|
|
67
|
-
PropTypes.array,
|
|
68
|
-
CustomPropTypes.allOfType([
|
|
69
|
-
CustomPropTypes.integer,
|
|
70
|
-
CustomPropTypes.nonNegative,
|
|
71
|
-
]),
|
|
72
|
-
PropTypes.string,
|
|
73
|
-
]),
|
|
74
|
-
mutation: PropTypes.func,
|
|
75
|
-
target: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
|
|
76
|
-
}),
|
|
77
|
-
),
|
|
78
|
-
groupComponent: PropTypes.node,
|
|
79
|
-
};
|
|
80
|
-
|
|
46
|
+
static contextType = TimerContext;
|
|
81
47
|
static defaultProps = {
|
|
82
48
|
groupComponent: <g />,
|
|
83
49
|
};
|
|
84
50
|
|
|
85
|
-
|
|
51
|
+
getScopedEvents;
|
|
52
|
+
getEventState;
|
|
53
|
+
baseProps;
|
|
54
|
+
sharedEventsCache;
|
|
55
|
+
globalEvents;
|
|
56
|
+
prevGlobalEventKeys;
|
|
57
|
+
boundGlobalEvents;
|
|
86
58
|
|
|
87
|
-
constructor(props) {
|
|
59
|
+
constructor(props: VictorySharedEventsProps) {
|
|
88
60
|
super(props);
|
|
89
|
-
|
|
61
|
+
|
|
90
62
|
this.getScopedEvents = Events.getScopedEvents.bind(this);
|
|
91
63
|
this.getEventState = Events.getEventState.bind(this);
|
|
92
|
-
this.
|
|
64
|
+
this.state = this.state || {};
|
|
93
65
|
this.sharedEventsCache = {};
|
|
94
66
|
this.globalEvents = {};
|
|
95
67
|
this.prevGlobalEventKeys = [];
|
|
96
68
|
this.boundGlobalEvents = {};
|
|
69
|
+
this.baseProps = this.getBaseProps(props);
|
|
97
70
|
}
|
|
98
71
|
|
|
99
72
|
shouldComponentUpdate(nextProps) {
|
|
@@ -166,12 +139,8 @@ export default class VictorySharedEvents extends React.Component {
|
|
|
166
139
|
applyExternalMutations(props, externalMutations) {
|
|
167
140
|
if (!isEmpty(externalMutations)) {
|
|
168
141
|
const callbacks = props.externalEventMutations.reduce(
|
|
169
|
-
(memo, mutation) =>
|
|
170
|
-
|
|
171
|
-
? memo.concat(mutation.callback)
|
|
172
|
-
: memo;
|
|
173
|
-
return memo;
|
|
174
|
-
},
|
|
142
|
+
(memo, mutation) =>
|
|
143
|
+
isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo,
|
|
175
144
|
[],
|
|
176
145
|
);
|
|
177
146
|
const compiledCallbacks = callbacks.length
|
|
@@ -302,9 +271,9 @@ export default class VictorySharedEvents extends React.Component {
|
|
|
302
271
|
|
|
303
272
|
getContainer(props, baseProps, events) {
|
|
304
273
|
const children = this.getNewChildren(props, baseProps);
|
|
305
|
-
const parents =
|
|
306
|
-
|
|
307
|
-
|
|
274
|
+
const parents = Array.isArray(events)
|
|
275
|
+
? events.filter((event) => event.target === "parent")
|
|
276
|
+
: [];
|
|
308
277
|
|
|
309
278
|
const sharedEvents =
|
|
310
279
|
parents.length > 0
|
|
@@ -344,12 +313,12 @@ export default class VictorySharedEvents extends React.Component {
|
|
|
344
313
|
: React.cloneElement(container, localEvents, children);
|
|
345
314
|
}
|
|
346
315
|
|
|
347
|
-
render() {
|
|
316
|
+
render(): React.ReactElement {
|
|
348
317
|
const events = this.getAllEvents(this.props);
|
|
349
318
|
if (events) {
|
|
350
319
|
return this.getContainer(this.props, this.baseProps, events);
|
|
351
320
|
}
|
|
352
|
-
return React.cloneElement(this.props.container, {
|
|
321
|
+
return React.cloneElement(this.props.container as React.ReactElement, {
|
|
353
322
|
children: this.props.children,
|
|
354
323
|
});
|
|
355
324
|
}
|
package/src/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
EventCallbackInterface,
|
|
4
|
-
EventPropTypeInterface,
|
|
5
|
-
StringOrNumberOrCallback,
|
|
6
|
-
} from "victory-core";
|
|
7
|
-
|
|
8
|
-
export type VictorySharedEventsProps = {
|
|
9
|
-
children?: React.ReactElement | React.ReactElement[];
|
|
10
|
-
container?: React.ReactElement;
|
|
11
|
-
groupComponent?: React.ReactElement;
|
|
12
|
-
events?: EventPropTypeInterface<string, StringOrNumberOrCallback>[];
|
|
13
|
-
eventKey?: StringOrNumberOrCallback;
|
|
14
|
-
externalEventMutations?: EventCallbackInterface<
|
|
15
|
-
string | string[],
|
|
16
|
-
string | number | (string | number)[]
|
|
17
|
-
>[];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export class VictorySharedEvents extends React.Component<
|
|
21
|
-
VictorySharedEventsProps,
|
|
22
|
-
any
|
|
23
|
-
> {}
|
package/src/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as VictorySharedEvents } from "./victory-shared-events";
|