victory-core 36.9.2 → 37.0.0

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 (110) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/victory-core.js +4371 -5749
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/victory-accessible-group/victory-accessible-group.js +9 -15
  5. package/es/victory-animation/util.js +28 -47
  6. package/es/victory-animation/victory-animation.js +51 -67
  7. package/es/victory-clip-container/victory-clip-container.js +153 -229
  8. package/es/victory-container/victory-container.js +157 -216
  9. package/es/victory-label/victory-label.js +246 -323
  10. package/es/victory-portal/portal-context.js +1 -2
  11. package/es/victory-portal/portal.js +30 -76
  12. package/es/victory-portal/victory-portal.js +47 -104
  13. package/es/victory-primitives/arc.js +44 -47
  14. package/es/victory-primitives/background.js +14 -17
  15. package/es/victory-primitives/border.js +20 -24
  16. package/es/victory-primitives/circle.js +13 -27
  17. package/es/victory-primitives/clip-path.js +3 -7
  18. package/es/victory-primitives/line-segment.js +20 -24
  19. package/es/victory-primitives/line.js +13 -27
  20. package/es/victory-primitives/path.js +13 -27
  21. package/es/victory-primitives/point.js +36 -40
  22. package/es/victory-primitives/rect.js +13 -27
  23. package/es/victory-primitives/text.js +15 -28
  24. package/es/victory-primitives/tspan.js +13 -26
  25. package/es/victory-primitives/whisker.js +43 -47
  26. package/es/victory-theme/grayscale.js +22 -22
  27. package/es/victory-theme/material.js +46 -46
  28. package/es/victory-theme/victory-theme.js +3 -3
  29. package/es/victory-transition/victory-transition.js +126 -206
  30. package/es/victory-util/add-events.js +263 -374
  31. package/es/victory-util/axis.js +126 -222
  32. package/es/victory-util/collection.js +13 -41
  33. package/es/victory-util/data.js +159 -214
  34. package/es/victory-util/default-transitions.js +33 -51
  35. package/es/victory-util/domain.js +122 -171
  36. package/es/victory-util/events.js +168 -258
  37. package/es/victory-util/helpers.js +153 -178
  38. package/es/victory-util/hooks/use-animation-state.js +61 -99
  39. package/es/victory-util/hooks/use-previous-props.js +2 -2
  40. package/es/victory-util/immutable.js +6 -8
  41. package/es/victory-util/label-helpers.js +128 -130
  42. package/es/victory-util/line-helpers.js +29 -41
  43. package/es/victory-util/log.js +1 -1
  44. package/es/victory-util/point-path-helpers.js +89 -49
  45. package/es/victory-util/scale.js +24 -42
  46. package/es/victory-util/selection.js +39 -40
  47. package/es/victory-util/style.js +8 -13
  48. package/es/victory-util/textsize.js +80 -154
  49. package/es/victory-util/timer-context.js +2 -2
  50. package/es/victory-util/timer.js +40 -76
  51. package/es/victory-util/transitions.js +110 -150
  52. package/es/victory-util/type-helpers.js +2 -3
  53. package/es/victory-util/user-props.js +24 -49
  54. package/es/victory-util/wrapper.js +184 -247
  55. package/lib/index.js +0 -30
  56. package/lib/victory-accessible-group/victory-accessible-group.js +9 -19
  57. package/lib/victory-animation/util.js +28 -63
  58. package/lib/victory-animation/victory-animation.js +54 -83
  59. package/lib/victory-clip-container/victory-clip-container.js +156 -243
  60. package/lib/victory-container/victory-container.js +160 -232
  61. package/lib/victory-label/victory-label.js +248 -344
  62. package/lib/victory-portal/portal-context.js +1 -6
  63. package/lib/victory-portal/portal.js +31 -81
  64. package/lib/victory-portal/victory-portal.js +50 -116
  65. package/lib/victory-primitives/arc.js +48 -57
  66. package/lib/victory-primitives/background.js +16 -28
  67. package/lib/victory-primitives/border.js +22 -34
  68. package/lib/victory-primitives/circle.js +16 -36
  69. package/lib/victory-primitives/clip-path.js +3 -11
  70. package/lib/victory-primitives/index.js +0 -28
  71. package/lib/victory-primitives/line-segment.js +22 -34
  72. package/lib/victory-primitives/line.js +16 -36
  73. package/lib/victory-primitives/path.js +16 -36
  74. package/lib/victory-primitives/point.js +38 -52
  75. package/lib/victory-primitives/rect.js +16 -36
  76. package/lib/victory-primitives/text.js +15 -33
  77. package/lib/victory-primitives/tspan.js +13 -31
  78. package/lib/victory-primitives/whisker.js +45 -57
  79. package/lib/victory-theme/grayscale.js +23 -24
  80. package/lib/victory-theme/material.js +47 -48
  81. package/lib/victory-theme/victory-theme.js +2 -7
  82. package/lib/victory-transition/victory-transition.js +129 -224
  83. package/lib/victory-util/add-events.js +263 -380
  84. package/lib/victory-util/axis.js +128 -241
  85. package/lib/victory-util/collection.js +13 -50
  86. package/lib/victory-util/data.js +160 -239
  87. package/lib/victory-util/default-transitions.js +33 -54
  88. package/lib/victory-util/domain.js +123 -193
  89. package/lib/victory-util/events.js +167 -274
  90. package/lib/victory-util/helpers.js +156 -207
  91. package/lib/victory-util/hooks/index.js +0 -2
  92. package/lib/victory-util/hooks/use-animation-state.js +63 -113
  93. package/lib/victory-util/hooks/use-previous-props.js +2 -7
  94. package/lib/victory-util/immutable.js +6 -18
  95. package/lib/victory-util/index.js +2 -51
  96. package/lib/victory-util/label-helpers.js +130 -141
  97. package/lib/victory-util/line-helpers.js +31 -49
  98. package/lib/victory-util/log.js +1 -2
  99. package/lib/victory-util/point-path-helpers.js +91 -63
  100. package/lib/victory-util/scale.js +26 -57
  101. package/lib/victory-util/selection.js +41 -49
  102. package/lib/victory-util/style.js +8 -16
  103. package/lib/victory-util/textsize.js +80 -157
  104. package/lib/victory-util/timer-context.js +2 -8
  105. package/lib/victory-util/timer.js +40 -76
  106. package/lib/victory-util/transitions.js +110 -152
  107. package/lib/victory-util/type-helpers.js +2 -9
  108. package/lib/victory-util/user-props.js +25 -59
  109. package/lib/victory-util/wrapper.js +186 -281
  110. package/package.json +2 -2
@@ -15,34 +15,18 @@ exports.getGlobalEvents = void 0;
15
15
  exports.getPartialEvents = getPartialEvents;
16
16
  exports.getScopedEvents = getScopedEvents;
17
17
  exports.omitGlobalEvents = void 0;
18
-
19
18
  var _uniq2 = _interopRequireDefault(require("lodash/uniq"));
20
-
21
19
  var _omitBy2 = _interopRequireDefault(require("lodash/omitBy"));
22
-
23
20
  var _pickBy2 = _interopRequireDefault(require("lodash/pickBy"));
24
-
25
21
  var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
26
-
27
22
  var _helpers = require("./helpers");
28
-
29
23
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+ /* eslint-disable no-use-before-define */
30
25
 
31
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
32
-
33
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
34
-
35
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
26
+ const GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
36
27
 
37
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
38
-
39
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
40
-
41
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
42
-
43
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
44
-
45
- var GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
28
+ // Normally we'd use Template Literal Types, but we're avoiding it to maximize TS compatibility with TS < 4.1
29
+ // `on${Capitalize<string>}`;
46
30
 
47
31
  /* Returns all own and shared events that should be attached to a single target element,
48
32
  * i.e. an individual bar specified by target: "data", eventKey: [index].
@@ -51,254 +35,206 @@ var GLOBAL_EVENT_REGEX = /^onGlobal(.*)$/;
51
35
  * (i.e. VictoryChart) in the case of shared events
52
36
  */
53
37
  // eslint-disable-next-line max-params
54
- function getEvents(props, target, eventKey, // eslint-disable-next-line no-shadow
38
+ function getEvents(props, target, eventKey,
39
+ // eslint-disable-next-line no-shadow
55
40
  getScopedEvents) {
56
- var _this = this;
57
-
58
41
  // Returns all events that apply to a particular target element
59
- var getEventsByTarget = function (events) {
60
- var getSelectedEvents = function () {
61
- var targetEvents = events.reduce(function (memo, event) {
42
+ const getEventsByTarget = events => {
43
+ const getSelectedEvents = () => {
44
+ const targetEvents = events.reduce((memo, event) => {
62
45
  if (event.target !== undefined) {
63
- var matchesTarget = Array.isArray(event.target) ? event.target.includes(target) : "".concat(event.target) === "".concat(target);
46
+ const matchesTarget = Array.isArray(event.target) ? event.target.includes(target) : `${event.target}` === `${target}`;
64
47
  return matchesTarget ? memo.concat(event) : memo;
65
48
  }
66
-
67
49
  return memo.concat(event);
68
50
  }, []);
69
-
70
51
  if (eventKey !== undefined && target !== "parent") {
71
- return targetEvents.filter(function (obj) {
72
- var targetKeys = obj.eventKey;
73
-
74
- var useKey = function (key) {
75
- return key ? "".concat(key) === "".concat(eventKey) : true;
76
- };
77
-
78
- return Array.isArray(targetKeys) ? targetKeys.some(function (k) {
79
- return useKey(k);
80
- }) : useKey(targetKeys);
52
+ return targetEvents.filter(obj => {
53
+ const targetKeys = obj.eventKey;
54
+ const useKey = key => key ? `${key}` === `${eventKey}` : true;
55
+ return Array.isArray(targetKeys) ? targetKeys.some(k => useKey(k)) : useKey(targetKeys);
81
56
  });
82
57
  }
83
-
84
58
  return targetEvents;
85
59
  };
86
-
87
- var selectedEvents = getSelectedEvents();
88
- return Array.isArray(selectedEvents) && selectedEvents.reduce(function (memo, event) {
60
+ const selectedEvents = getSelectedEvents();
61
+ return Array.isArray(selectedEvents) && selectedEvents.reduce((memo, event) => {
89
62
  return event ? Object.assign(memo, event.eventHandlers) : memo;
90
63
  }, {});
91
64
  };
65
+
92
66
  /* Returns all events from props and defaultEvents from components. Events handlers
93
67
  * specified in props will override handlers for the same event if they are also
94
68
  * specified in defaultEvents of a sub-component
95
69
  */
96
-
97
-
98
- var getAllEvents = function () {
70
+ const getAllEvents = () => {
99
71
  // Mandatory usage: `getEvents.bind(this)`
100
-
101
72
  /* eslint-disable no-invalid-this */
102
- if (Array.isArray(_this.componentEvents)) {
103
- var _this$componentEvents;
104
-
105
- return Array.isArray(props.events) ? (_this$componentEvents = _this.componentEvents).concat.apply(_this$componentEvents, _toConsumableArray(props.events)) : _this.componentEvents;
73
+ if (Array.isArray(this.componentEvents)) {
74
+ return Array.isArray(props.events) ? this.componentEvents.concat(...props.events) : this.componentEvents;
106
75
  }
107
76
  /* eslint-enable no-invalid-this */
108
-
109
-
110
77
  return props.events;
111
78
  };
112
-
113
- var allEvents = getAllEvents();
114
- var ownEvents = allEvents && (0, _helpers.isFunction)(getScopedEvents) ? getScopedEvents(getEventsByTarget(allEvents), target) : undefined;
115
-
79
+ const allEvents = getAllEvents();
80
+ const ownEvents = allEvents && (0, _helpers.isFunction)(getScopedEvents) ? getScopedEvents(getEventsByTarget(allEvents), target) : undefined;
116
81
  if (!props.sharedEvents) {
117
82
  return ownEvents;
118
83
  }
119
-
120
- var getSharedEvents = props.sharedEvents.getEvents;
121
- var sharedEvents = props.sharedEvents.events && getSharedEvents(getEventsByTarget(props.sharedEvents.events), target);
84
+ const getSharedEvents = props.sharedEvents.getEvents;
85
+ const sharedEvents = props.sharedEvents.events && getSharedEvents(getEventsByTarget(props.sharedEvents.events), target);
122
86
  return Object.assign({}, sharedEvents, ownEvents);
123
87
  }
88
+
124
89
  /* Returns a modified events object where each event handler is replaced by a new
125
90
  * function that calls the original handler and then calls setState with the return
126
91
  * of the original event handler assigned to state property that maps to the target
127
92
  * element.
128
93
  */
129
94
  // eslint-disable-next-line max-params
130
-
131
-
132
95
  function getScopedEvents(events, namespace, childType, baseProps) {
133
- var _this2 = this;
134
-
135
96
  if ((0, _isEmpty2.default)(events)) {
136
97
  return {};
137
- } // Mandatory usage: `getScopedEvents.bind(this)`
138
- // eslint-disable-next-line no-invalid-this
139
-
140
-
141
- var newBaseProps = baseProps || this.baseProps; // returns the original base props or base state of a given target element
142
-
143
- var getTargetProps = function (identifier, type) {
144
- var childName = identifier.childName,
145
- target = identifier.target,
146
- key = identifier.key; // eslint-disable-next-line no-invalid-this
98
+ }
147
99
 
148
- var baseType = type === "props" ? newBaseProps : _this2.state || {};
149
- var base = childName === undefined || childName === null || !baseType[childName] ? baseType : baseType[childName];
100
+ // Mandatory usage: `getScopedEvents.bind(this)`
101
+ // eslint-disable-next-line no-invalid-this
102
+ const newBaseProps = baseProps || this.baseProps;
103
+ // returns the original base props or base state of a given target element
104
+ const getTargetProps = (identifier, type) => {
105
+ const {
106
+ childName,
107
+ target,
108
+ key
109
+ } = identifier;
110
+ // eslint-disable-next-line no-invalid-this
111
+ const baseType = type === "props" ? newBaseProps : this.state || {};
112
+ const base = childName === undefined || childName === null || !baseType[childName] ? baseType : baseType[childName];
150
113
  return key === "parent" ? base.parent : base[key] && base[key][target];
151
- }; // Returns the state object with the mutation caused by a given eventReturn
152
- // applied to the appropriate property on the state object
153
-
114
+ };
154
115
 
155
- var parseEvent = function (eventReturn, eventKey) {
156
- var childNames = namespace === "parent" ? eventReturn.childName : eventReturn.childName || childType;
157
- var target = eventReturn.target || namespace; // returns all eventKeys to modify for a targeted childName
116
+ // Returns the state object with the mutation caused by a given eventReturn
117
+ // applied to the appropriate property on the state object
118
+ const parseEvent = (eventReturn, eventKey) => {
119
+ const childNames = namespace === "parent" ? eventReturn.childName : eventReturn.childName || childType;
120
+ const target = eventReturn.target || namespace;
158
121
 
159
- var getKeys = function (childName) {
122
+ // returns all eventKeys to modify for a targeted childName
123
+ const getKeys = childName => {
160
124
  if (target === "parent") {
161
125
  return "parent";
162
126
  }
163
-
164
127
  if (eventReturn.eventKey === "all") {
165
- return newBaseProps[childName] ? Object.keys(newBaseProps[childName]).filter(function (value) {
166
- return value !== "parent";
167
- }) : Object.keys(newBaseProps).filter(function (value) {
168
- return value !== "parent";
169
- });
128
+ return newBaseProps[childName] ? Object.keys(newBaseProps[childName]).filter(value => value !== "parent") : Object.keys(newBaseProps).filter(value => value !== "parent");
170
129
  } else if (eventReturn.eventKey === undefined && eventKey === "parent") {
171
130
  return newBaseProps[childName] ? Object.keys(newBaseProps[childName]) : Object.keys(newBaseProps);
172
131
  }
173
-
174
132
  return eventReturn.eventKey !== undefined ? eventReturn.eventKey : eventKey;
175
- }; // returns the state object with mutated props applied for a single key
176
-
133
+ };
177
134
 
178
- var getMutationObject = function (key, childName) {
135
+ // returns the state object with mutated props applied for a single key
136
+ const getMutationObject = (key, childName) => {
179
137
  // eslint-disable-next-line no-invalid-this
180
- var baseState = _this2.state || {};
181
-
138
+ const baseState = this.state || {};
182
139
  if (!(0, _helpers.isFunction)(eventReturn.mutation)) {
183
140
  return baseState;
184
141
  }
185
-
186
- var mutationTargetProps = getTargetProps({
187
- childName: childName,
188
- key: key,
189
- target: target
142
+ const mutationTargetProps = getTargetProps({
143
+ childName,
144
+ key,
145
+ target
190
146
  }, "props");
191
- var mutationTargetState = getTargetProps({
192
- childName: childName,
193
- key: key,
194
- target: target
147
+ const mutationTargetState = getTargetProps({
148
+ childName,
149
+ key,
150
+ target
195
151
  }, "state");
196
- var mutatedProps = eventReturn.mutation(Object.assign({}, mutationTargetProps, mutationTargetState), newBaseProps);
197
- var childState = baseState[childName] || {};
198
-
199
- var filterState = function (state) {
152
+ const mutatedProps = eventReturn.mutation(Object.assign({}, mutationTargetProps, mutationTargetState), newBaseProps);
153
+ const childState = baseState[childName] || {};
154
+ const filterState = state => {
200
155
  if (state[key] && state[key][target]) {
201
156
  delete state[key][target];
202
157
  }
203
-
204
158
  if (state[key] && !Object.keys(state[key]).length) {
205
159
  delete state[key];
206
160
  }
207
-
208
161
  return state;
209
162
  };
210
-
211
- var extendState = function (state) {
212
- return target === "parent" ? Object.assign(state, _defineProperty({}, key, Object.assign(state[key] || {}, mutatedProps))) : Object.assign(state, _defineProperty({}, key, Object.assign(state[key] || {}, _defineProperty({}, target, mutatedProps))));
163
+ const extendState = state => {
164
+ return target === "parent" ? Object.assign(state, {
165
+ [key]: Object.assign(state[key] || {}, mutatedProps)
166
+ }) : Object.assign(state, {
167
+ [key]: Object.assign(state[key] || {}, {
168
+ [target]: mutatedProps
169
+ })
170
+ });
213
171
  };
214
-
215
- var updateState = function (state) {
172
+ const updateState = state => {
216
173
  return mutatedProps ? extendState(state) : filterState(state);
217
174
  };
175
+ return childName !== undefined && childName !== null ? Object.assign(baseState, {
176
+ [childName]: updateState(childState)
177
+ }) : updateState(baseState);
178
+ };
218
179
 
219
- return childName !== undefined && childName !== null ? Object.assign(baseState, _defineProperty({}, childName, updateState(childState))) : updateState(baseState);
220
- }; // returns entire mutated state for a given childName
221
-
222
-
223
- var getReturnByChild = function (childName) {
224
- var mutationKeys = getKeys(childName);
225
- return Array.isArray(mutationKeys) ? mutationKeys.reduce(function (memo, key) {
180
+ // returns entire mutated state for a given childName
181
+ const getReturnByChild = childName => {
182
+ const mutationKeys = getKeys(childName);
183
+ return Array.isArray(mutationKeys) ? mutationKeys.reduce((memo, key) => {
226
184
  return Object.assign(memo, getMutationObject(key, childName));
227
185
  }, {}) : getMutationObject(mutationKeys, childName);
228
- }; // returns an entire mutated state for all children
229
-
186
+ };
230
187
 
231
- var allChildNames = childNames === "all" ? Object.keys(newBaseProps).filter(function (value) {
232
- return value !== "parent";
233
- }) : childNames;
234
- return Array.isArray(allChildNames) ? allChildNames.reduce(function (memo, childName) {
188
+ // returns an entire mutated state for all children
189
+ const allChildNames = childNames === "all" ? Object.keys(newBaseProps).filter(value => value !== "parent") : childNames;
190
+ return Array.isArray(allChildNames) ? allChildNames.reduce((memo, childName) => {
235
191
  return Object.assign(memo, getReturnByChild(childName));
236
192
  }, {}) : getReturnByChild(allChildNames);
237
- }; // Parses an array of event returns into a single state mutation
238
-
239
-
240
- var parseEventReturn = function (eventReturn, eventKey) {
241
- return Array.isArray(eventReturn) ? eventReturn.reduce(function (memo, props) {
242
- return Object.assign({}, memo, parseEvent(props, eventKey));
243
- }, {}) : parseEvent(eventReturn, eventKey);
244
193
  };
245
194
 
246
- var compileCallbacks = function (eventReturn) {
247
- var getCallback = function (obj) {
248
- return (0, _helpers.isFunction)(obj.callback) && obj.callback;
249
- };
195
+ // Parses an array of event returns into a single state mutation
196
+ const parseEventReturn = (eventReturn, eventKey) => {
197
+ return Array.isArray(eventReturn) ? eventReturn.reduce((memo, props) => Object.assign({}, memo, parseEvent(props, eventKey)), {}) : parseEvent(eventReturn, eventKey);
198
+ };
199
+ const compileCallbacks = eventReturn => {
200
+ const getCallback = obj => (0, _helpers.isFunction)(obj.callback) && obj.callback;
201
+ const callbacks = Array.isArray(eventReturn) ? eventReturn.map(evtObj => getCallback(evtObj)) : [getCallback(eventReturn)];
202
+ const callbackArray = callbacks.filter(callback => callback !== false);
203
+ return callbackArray.length ? () => callbackArray.forEach(callback => callback()) : undefined;
204
+ };
250
205
 
251
- var callbacks = Array.isArray(eventReturn) ? eventReturn.map(function (evtObj) {
252
- return getCallback(evtObj);
253
- }) : [getCallback(eventReturn)];
254
- var callbackArray = callbacks.filter(function (callback) {
255
- return callback !== false;
256
- });
257
- return callbackArray.length ? function () {
258
- return callbackArray.forEach(function (callback) {
259
- return callback();
260
- });
261
- } : undefined;
262
- }; // A function that calls a particular event handler, parses its return
206
+ // A function that calls a particular event handler, parses its return
263
207
  // into a state mutation, and calls setState
264
208
  // eslint-disable-next-line max-params
265
-
266
-
267
- var onEvent = function (evt, childProps, eventKey, eventName) {
209
+ const onEvent = (evt, childProps, eventKey, eventName) => {
268
210
  // eslint-disable-next-line no-invalid-this
269
- var eventReturn = events[eventName](evt, childProps, eventKey, _this2);
270
-
211
+ const eventReturn = events[eventName](evt, childProps, eventKey, this);
271
212
  if (!(0, _isEmpty2.default)(eventReturn)) {
272
- var callbacks = compileCallbacks(eventReturn); // eslint-disable-next-line no-invalid-this
273
-
274
- _this2.setState(parseEventReturn(eventReturn, eventKey), callbacks);
213
+ const callbacks = compileCallbacks(eventReturn);
214
+ // eslint-disable-next-line no-invalid-this
215
+ this.setState(parseEventReturn(eventReturn, eventKey), callbacks);
275
216
  }
276
- }; // returns a new events object with enhanced event handlers
277
-
217
+ };
278
218
 
279
- return Object.keys(events).reduce(function (memo, event) {
219
+ // returns a new events object with enhanced event handlers
220
+ return Object.keys(events).reduce((memo, event) => {
280
221
  memo[event] = onEvent;
281
222
  return memo;
282
223
  }, {});
283
224
  }
225
+
284
226
  /*
285
227
  * Returns a partially applied event handler for a specific target element
286
228
  * This allows event handlers to have access to props controlling each element
287
229
  */
288
-
289
-
290
230
  function getPartialEvents(events, eventKey, childProps) {
291
231
  if (!events) return {};
292
- return Object.keys(events).reduce(function (memo, eventName) {
293
- var appliedEvent = function (evt) {
294
- return events[eventName](evt, childProps, eventKey, eventName);
295
- };
296
-
232
+ return Object.keys(events).reduce((memo, eventName) => {
233
+ const appliedEvent = evt => events[eventName](evt, childProps, eventKey, eventName);
297
234
  memo[eventName] = appliedEvent;
298
235
  return memo;
299
236
  }, {});
300
237
  }
301
-
302
238
  /* Returns the property of the state object corresponding to event changes for
303
239
  * a particular element
304
240
  */
@@ -306,14 +242,13 @@ function getPartialEvents(events, eventKey, childProps) {
306
242
  function getEventState(eventKey, namespace, childType) {
307
243
  // Mandatory usage: `getEventState.bind(this)`
308
244
  // eslint-disable-next-line no-invalid-this
309
- var state = this.state || {};
310
-
245
+ const state = this.state || {};
311
246
  if (!childType) {
312
247
  return eventKey === "parent" ? state[eventKey] && state[eventKey][namespace] || state[eventKey] : state[eventKey] && state[eventKey][namespace];
313
248
  }
314
-
315
249
  return state[childType] && state[childType][eventKey] && state[childType][eventKey][namespace];
316
250
  }
251
+
317
252
  /**
318
253
  * Returns a set of all mutations for shared events
319
254
  *
@@ -325,21 +260,21 @@ function getEventState(eventKey, namespace, childType) {
325
260
  * @return {Object} a object describing all mutations for VictorySharedEvents
326
261
  */
327
262
  // eslint-disable-next-line max-params
328
-
329
-
330
- function getExternalMutationsWithChildren(mutations) {
331
- var baseProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
332
- var baseState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
333
- var childNames = arguments.length > 3 ? arguments[3] : undefined;
334
- return childNames.reduce(function (memo, childName) {
335
- var childState = baseState[childName];
336
- var mutation = getExternalMutations(mutations, baseProps[childName], baseState[childName], childName);
263
+ function getExternalMutationsWithChildren(mutations, baseProps, baseState, childNames) {
264
+ if (baseProps === void 0) {
265
+ baseProps = {};
266
+ }
267
+ if (baseState === void 0) {
268
+ baseState = {};
269
+ }
270
+ return childNames.reduce((memo, childName) => {
271
+ const childState = baseState[childName];
272
+ const mutation = getExternalMutations(mutations, baseProps[childName], baseState[childName], childName);
337
273
  memo[childName] = mutation ? mutation : childState;
338
- return (0, _pickBy2.default)(memo, function (v) {
339
- return !(0, _isEmpty2.default)(v);
340
- });
274
+ return (0, _pickBy2.default)(memo, v => !(0, _isEmpty2.default)(v));
341
275
  }, {});
342
276
  }
277
+
343
278
  /**
344
279
  * Returns a set of all mutations for a component
345
280
  *
@@ -351,47 +286,43 @@ function getExternalMutationsWithChildren(mutations) {
351
286
  * @return {Object} a object describing mutations for a given component
352
287
  */
353
288
  // eslint-disable-next-line max-params
354
-
355
-
356
- function getExternalMutations(mutations) {
357
- var baseProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
358
- var baseState = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
359
- var childName = arguments.length > 3 ? arguments[3] : undefined;
360
- var eventKeys = Object.keys(baseProps);
361
- return eventKeys.reduce(function (memo, eventKey) {
362
- var keyState = baseState[eventKey] || {};
363
- var keyProps = baseProps[eventKey] || {};
364
-
289
+ function getExternalMutations(mutations, baseProps, baseState, childName) {
290
+ if (baseProps === void 0) {
291
+ baseProps = {};
292
+ }
293
+ if (baseState === void 0) {
294
+ baseState = {};
295
+ }
296
+ const eventKeys = Object.keys(baseProps);
297
+ return eventKeys.reduce((memo, eventKey) => {
298
+ const keyState = baseState[eventKey] || {};
299
+ const keyProps = baseProps[eventKey] || {};
365
300
  if (eventKey === "parent") {
366
- var identifier = {
367
- eventKey: eventKey,
301
+ const identifier = {
302
+ eventKey,
368
303
  target: "parent"
369
304
  };
370
- var mutation = getExternalMutation(mutations, keyProps, keyState, identifier);
305
+ const mutation = getExternalMutation(mutations, keyProps, keyState, identifier);
371
306
  memo[eventKey] = mutation !== undefined ? Object.assign({}, keyState, mutation) : keyState;
372
307
  } else {
373
308
  // use keys from both state and props so that elements not intially included in baseProps
374
309
  // will be used. (i.e. labels)
375
- var targets = (0, _uniq2.default)(Object.keys(keyProps).concat(Object.keys(keyState)));
376
- memo[eventKey] = targets.reduce(function (m, target) {
377
- var identifier = {
378
- eventKey: eventKey,
379
- target: target,
380
- childName: childName
310
+ const targets = (0, _uniq2.default)(Object.keys(keyProps).concat(Object.keys(keyState)));
311
+ memo[eventKey] = targets.reduce((m, target) => {
312
+ const identifier = {
313
+ eventKey,
314
+ target,
315
+ childName
381
316
  };
382
- var mutation = getExternalMutation(mutations, keyProps[target], keyState[target], identifier);
317
+ const mutation = getExternalMutation(mutations, keyProps[target], keyState[target], identifier);
383
318
  m[target] = mutation !== undefined ? Object.assign({}, keyState[target], mutation) : keyState[target];
384
- return (0, _pickBy2.default)(m, function (v) {
385
- return !(0, _isEmpty2.default)(v);
386
- });
319
+ return (0, _pickBy2.default)(m, v => !(0, _isEmpty2.default)(v));
387
320
  }, {});
388
321
  }
389
-
390
- return (0, _pickBy2.default)(memo, function (v) {
391
- return !(0, _isEmpty2.default)(v);
392
- });
322
+ return (0, _pickBy2.default)(memo, v => !(0, _isEmpty2.default)(v));
393
323
  }, {});
394
324
  }
325
+
395
326
  /**
396
327
  * Returns a set of mutations for a particular element given scoped baseProps and baseState
397
328
  *
@@ -403,96 +334,58 @@ function getExternalMutations(mutations) {
403
334
  * @return {Object | undefined} a object describing mutations for a given element, or undefined
404
335
  */
405
336
  // eslint-disable-next-line max-params
406
-
407
-
408
337
  function getExternalMutation(mutations, baseProps, baseState, identifier) {
409
- var filterMutations = function (mutation, type) {
338
+ const filterMutations = (mutation, type) => {
410
339
  if (typeof mutation[type] === "string") {
411
340
  return mutation[type] === "all" || mutation[type] === identifier[type];
412
341
  } else if (Array.isArray(mutation[type])) {
413
342
  // coerce arrays to strings before matching
414
- var stringArray = mutation[type].map(function (m) {
415
- return "".concat(m);
416
- });
343
+ const stringArray = mutation[type].map(m => `${m}`);
417
344
  return stringArray.includes(identifier[type]);
418
345
  }
419
-
420
346
  return false;
421
347
  };
422
-
423
- var scopedMutations = Array.isArray(mutations) ? mutations : [mutations];
424
-
348
+ let scopedMutations = Array.isArray(mutations) ? mutations : [mutations];
425
349
  if (identifier.childName) {
426
- scopedMutations = mutations.filter(function (m) {
427
- return filterMutations(m, "childName");
428
- });
429
- } // find any mutation objects that match the target
430
-
431
-
432
- var targetMutations = scopedMutations.filter(function (m) {
433
- return filterMutations(m, "target");
434
- });
435
-
350
+ scopedMutations = mutations.filter(m => filterMutations(m, "childName"));
351
+ }
352
+ // find any mutation objects that match the target
353
+ const targetMutations = scopedMutations.filter(m => filterMutations(m, "target"));
436
354
  if ((0, _isEmpty2.default)(targetMutations)) {
437
355
  return undefined;
438
356
  }
439
-
440
- var keyMutations = targetMutations.filter(function (m) {
441
- return filterMutations(m, "eventKey");
442
- });
443
-
357
+ const keyMutations = targetMutations.filter(m => filterMutations(m, "eventKey"));
444
358
  if ((0, _isEmpty2.default)(keyMutations)) {
445
359
  return undefined;
446
360
  }
447
-
448
- return keyMutations.reduce(function (memo, curr) {
449
- var mutationFunction = curr && (0, _helpers.isFunction)(curr.mutation) ? curr.mutation : function () {
450
- return undefined;
451
- };
452
- var currentMutation = mutationFunction(Object.assign({}, baseProps, baseState));
361
+ return keyMutations.reduce((memo, curr) => {
362
+ const mutationFunction = curr && (0, _helpers.isFunction)(curr.mutation) ? curr.mutation : () => undefined;
363
+ const currentMutation = mutationFunction(Object.assign({}, baseProps, baseState));
453
364
  return Object.assign({}, memo, currentMutation);
454
365
  }, {});
455
366
  }
367
+
456
368
  /* Returns an array of defaultEvents from sub-components of a given component.
457
369
  * i.e. any static `defaultEvents` on `labelComponent` will be returned
458
370
  */
459
-
460
-
461
371
  function getComponentEvents(props, components) {
462
- var events = Array.isArray(components) && components.reduce(function (memo, componentName) {
463
- var component = props[componentName];
464
- var defaultEvents = component && component.type && component.type.defaultEvents;
465
- var componentEvents = (0, _helpers.isFunction)(defaultEvents) ? defaultEvents(component.props) : defaultEvents;
466
- return Array.isArray(componentEvents) ? memo.concat.apply(memo, _toConsumableArray(componentEvents)) : memo;
372
+ const events = Array.isArray(components) && components.reduce((memo, componentName) => {
373
+ const component = props[componentName];
374
+ const defaultEvents = component && component.type && component.type.defaultEvents;
375
+ const componentEvents = (0, _helpers.isFunction)(defaultEvents) ? defaultEvents(component.props) : defaultEvents;
376
+ return Array.isArray(componentEvents) ? memo.concat(...componentEvents) : memo;
467
377
  }, []);
468
378
  return events && events.length ? events : undefined;
469
379
  }
470
-
471
380
  function getGlobalEventNameFromKey(key) {
472
- var match = key.match(GLOBAL_EVENT_REGEX);
381
+ const match = key.match(GLOBAL_EVENT_REGEX);
473
382
  return match && match[1] && match[1].toLowerCase();
474
383
  }
475
-
476
- var getGlobalEvents = function (events) {
477
- return (0, _pickBy2.default)(events, function (_, key) {
478
- return GLOBAL_EVENT_REGEX.test(key);
479
- });
480
- };
481
-
384
+ const getGlobalEvents = events => (0, _pickBy2.default)(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
482
385
  exports.getGlobalEvents = getGlobalEvents;
483
-
484
- var omitGlobalEvents = function (events) {
485
- return (0, _omitBy2.default)(events, function (_, key) {
486
- return GLOBAL_EVENT_REGEX.test(key);
487
- });
488
- };
489
-
386
+ const omitGlobalEvents = events => (0, _omitBy2.default)(events, (_, key) => GLOBAL_EVENT_REGEX.test(key));
490
387
  exports.omitGlobalEvents = omitGlobalEvents;
491
-
492
- var emulateReactEvent = function (event) {
493
- return Object.assign(event, {
494
- nativeEvent: event
495
- });
496
- };
497
-
388
+ const emulateReactEvent = event => Object.assign(event, {
389
+ nativeEvent: event
390
+ });
498
391
  exports.emulateReactEvent = emulateReactEvent;