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