victory-shared-events 36.8.2 → 36.8.3
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 +8 -0
- package/dist/victory-shared-events.js +1008 -8795
- 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 +48 -0
- package/es/victory-shared-events.js +16 -39
- package/lib/index.d.ts +2 -23
- package/lib/index.js +11 -8
- package/lib/victory-shared-events.d.ts +48 -0
- package/lib/victory-shared-events.js +14 -36
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/{victory-shared-events.js → victory-shared-events.tsx} +39 -73
- package/src/index.d.ts +0 -23
- package/src/index.js +0 -1
|
@@ -8,92 +8,62 @@ 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
|
-
|
|
81
|
-
static defaultProps = {
|
|
82
|
-
groupComponent: <g />,
|
|
83
|
-
};
|
|
84
|
-
|
|
85
46
|
static contextType = TimerContext;
|
|
86
47
|
|
|
87
|
-
|
|
48
|
+
getScopedEvents;
|
|
49
|
+
getEventState;
|
|
50
|
+
baseProps;
|
|
51
|
+
sharedEventsCache;
|
|
52
|
+
globalEvents;
|
|
53
|
+
prevGlobalEventKeys;
|
|
54
|
+
boundGlobalEvents;
|
|
55
|
+
|
|
56
|
+
constructor(props: VictorySharedEventsProps) {
|
|
88
57
|
super(props);
|
|
89
|
-
|
|
58
|
+
|
|
90
59
|
this.getScopedEvents = Events.getScopedEvents.bind(this);
|
|
91
60
|
this.getEventState = Events.getEventState.bind(this);
|
|
92
|
-
this.
|
|
61
|
+
this.state = this.state || {};
|
|
93
62
|
this.sharedEventsCache = {};
|
|
94
63
|
this.globalEvents = {};
|
|
95
64
|
this.prevGlobalEventKeys = [];
|
|
96
65
|
this.boundGlobalEvents = {};
|
|
66
|
+
this.baseProps = this.getBaseProps(props);
|
|
97
67
|
}
|
|
98
68
|
|
|
99
69
|
shouldComponentUpdate(nextProps) {
|
|
@@ -166,12 +136,8 @@ export default class VictorySharedEvents extends React.Component {
|
|
|
166
136
|
applyExternalMutations(props, externalMutations) {
|
|
167
137
|
if (!isEmpty(externalMutations)) {
|
|
168
138
|
const callbacks = props.externalEventMutations.reduce(
|
|
169
|
-
(memo, mutation) =>
|
|
170
|
-
|
|
171
|
-
? memo.concat(mutation.callback)
|
|
172
|
-
: memo;
|
|
173
|
-
return memo;
|
|
174
|
-
},
|
|
139
|
+
(memo, mutation) =>
|
|
140
|
+
isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo,
|
|
175
141
|
[],
|
|
176
142
|
);
|
|
177
143
|
const compiledCallbacks = callbacks.length
|
|
@@ -302,9 +268,9 @@ export default class VictorySharedEvents extends React.Component {
|
|
|
302
268
|
|
|
303
269
|
getContainer(props, baseProps, events) {
|
|
304
270
|
const children = this.getNewChildren(props, baseProps);
|
|
305
|
-
const parents =
|
|
306
|
-
|
|
307
|
-
|
|
271
|
+
const parents = Array.isArray(events)
|
|
272
|
+
? events.filter((event) => event.target === "parent")
|
|
273
|
+
: [];
|
|
308
274
|
|
|
309
275
|
const sharedEvents =
|
|
310
276
|
parents.length > 0
|
|
@@ -344,12 +310,12 @@ export default class VictorySharedEvents extends React.Component {
|
|
|
344
310
|
: React.cloneElement(container, localEvents, children);
|
|
345
311
|
}
|
|
346
312
|
|
|
347
|
-
render() {
|
|
313
|
+
render(): React.ReactElement {
|
|
348
314
|
const events = this.getAllEvents(this.props);
|
|
349
315
|
if (events) {
|
|
350
316
|
return this.getContainer(this.props, this.baseProps, events);
|
|
351
317
|
}
|
|
352
|
-
return React.cloneElement(this.props.container, {
|
|
318
|
+
return React.cloneElement(this.props.container as React.ReactElement, {
|
|
353
319
|
children: this.props.children,
|
|
354
320
|
});
|
|
355
321
|
}
|
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";
|