victory-core 36.3.0 → 36.4.1

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 (102) hide show
  1. package/dist/victory-core.js +14792 -14613
  2. package/dist/victory-core.min.js +1 -1
  3. package/es/index.js +2 -0
  4. package/es/victory-accessible-group/victory-accessible-group.js +38 -40
  5. package/es/victory-animation/util.js +1 -1
  6. package/es/victory-animation/victory-animation.js +46 -48
  7. package/es/victory-clip-container/victory-clip-container.js +74 -75
  8. package/es/victory-container/victory-container.js +86 -94
  9. package/es/victory-label/victory-label.js +32 -25
  10. package/es/victory-portal/portal-context.js +1 -1
  11. package/es/victory-portal/portal.js +28 -26
  12. package/es/victory-portal/victory-portal.js +31 -41
  13. package/es/victory-primitives/arc.js +6 -4
  14. package/es/victory-primitives/background.js +8 -6
  15. package/es/victory-primitives/border.js +6 -4
  16. package/es/victory-primitives/circle.js +8 -4
  17. package/es/victory-primitives/clip-path.js +1 -1
  18. package/es/victory-primitives/line-segment.js +6 -4
  19. package/es/victory-primitives/line.js +8 -4
  20. package/es/victory-primitives/path.js +7 -3
  21. package/es/victory-primitives/point.js +6 -4
  22. package/es/victory-primitives/rect.js +8 -4
  23. package/es/victory-primitives/text.js +7 -3
  24. package/es/victory-primitives/tspan.js +1 -1
  25. package/es/victory-primitives/whisker.js +9 -7
  26. package/es/victory-transition/victory-transition.js +30 -32
  27. package/es/victory-util/add-events.js +324 -315
  28. package/es/victory-util/axis.js +12 -5
  29. package/es/victory-util/collection.js +8 -4
  30. package/es/victory-util/common-props.js +2 -2
  31. package/es/victory-util/data.js +9 -5
  32. package/es/victory-util/domain.js +8 -4
  33. package/es/victory-util/events.js +8 -4
  34. package/es/victory-util/helpers.js +1 -1
  35. package/es/victory-util/hooks/use-animation-state.js +11 -5
  36. package/es/victory-util/line-helpers.js +1 -1
  37. package/es/victory-util/scale.js +19 -19
  38. package/es/victory-util/textsize.js +11 -7
  39. package/es/victory-util/timer-context.js +1 -1
  40. package/es/victory-util/timer.js +3 -5
  41. package/es/victory-util/user-props.js +123 -0
  42. package/es/victory-util/wrapper.js +18 -12
  43. package/lib/index.js +72 -58
  44. package/lib/victory-accessible-group/victory-accessible-group.js +38 -40
  45. package/lib/victory-animation/util.js +2 -2
  46. package/lib/victory-animation/victory-animation.js +49 -49
  47. package/lib/victory-clip-container/victory-clip-container.js +78 -76
  48. package/lib/victory-container/victory-container.js +90 -95
  49. package/lib/victory-label/victory-label.js +38 -27
  50. package/lib/victory-portal/portal-context.js +1 -1
  51. package/lib/victory-portal/portal.js +31 -27
  52. package/lib/victory-portal/victory-portal.js +34 -42
  53. package/lib/victory-primitives/arc.js +9 -5
  54. package/lib/victory-primitives/background.js +11 -7
  55. package/lib/victory-primitives/border.js +9 -5
  56. package/lib/victory-primitives/circle.js +8 -4
  57. package/lib/victory-primitives/clip-path.js +1 -1
  58. package/lib/victory-primitives/line-segment.js +9 -5
  59. package/lib/victory-primitives/line.js +8 -4
  60. package/lib/victory-primitives/path.js +7 -3
  61. package/lib/victory-primitives/point.js +9 -5
  62. package/lib/victory-primitives/rect.js +8 -4
  63. package/lib/victory-primitives/text.js +7 -3
  64. package/lib/victory-primitives/tspan.js +1 -1
  65. package/lib/victory-primitives/whisker.js +12 -8
  66. package/lib/victory-transition/victory-transition.js +33 -33
  67. package/lib/victory-util/add-events.js +322 -311
  68. package/lib/victory-util/axis.js +20 -11
  69. package/lib/victory-util/collection.js +11 -7
  70. package/lib/victory-util/common-props.js +6 -4
  71. package/lib/victory-util/data.js +13 -7
  72. package/lib/victory-util/default-transitions.js +1 -1
  73. package/lib/victory-util/domain.js +11 -5
  74. package/lib/victory-util/events.js +17 -11
  75. package/lib/victory-util/helpers.js +14 -14
  76. package/lib/victory-util/hooks/index.js +4 -4
  77. package/lib/victory-util/hooks/use-animation-state.js +14 -6
  78. package/lib/victory-util/immutable.js +3 -3
  79. package/lib/victory-util/label-helpers.js +6 -4
  80. package/lib/victory-util/line-helpers.js +4 -2
  81. package/lib/victory-util/prop-types.js +5 -3
  82. package/lib/victory-util/scale.js +24 -21
  83. package/lib/victory-util/selection.js +6 -4
  84. package/lib/victory-util/textsize.js +12 -8
  85. package/lib/victory-util/timer-context.js +1 -1
  86. package/lib/victory-util/timer.js +3 -5
  87. package/lib/victory-util/user-props.js +139 -0
  88. package/lib/victory-util/wrapper.js +31 -23
  89. package/package.json +5 -12
  90. package/src/index.js +1 -0
  91. package/src/victory-animation/util.js +1 -1
  92. package/src/victory-animation/victory-animation.js +1 -1
  93. package/src/victory-clip-container/victory-clip-container.js +3 -1
  94. package/src/victory-container/victory-container.js +7 -1
  95. package/src/victory-label/victory-label.js +11 -7
  96. package/src/victory-util/add-events.js +2 -1
  97. package/src/victory-util/axis.js +3 -0
  98. package/src/victory-util/common-props.js +2 -2
  99. package/src/victory-util/line-helpers.js +1 -1
  100. package/src/victory-util/scale.js +18 -9
  101. package/src/victory-util/timer.js +1 -1
  102. package/src/victory-util/user-props.js +94 -0
@@ -31,30 +31,44 @@ var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
31
31
 
32
32
  var _victoryTransition = _interopRequireDefault(require("../victory-transition/victory-transition"));
33
33
 
34
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
34
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
+
36
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
37
 
36
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
37
39
 
38
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
40
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
41
+
42
+ 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."); }
43
+
44
+ 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); }
39
45
 
40
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
46
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
41
47
 
42
- function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
48
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
43
49
 
44
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
50
+ 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; }
45
51
 
46
52
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
47
53
 
48
54
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
49
55
 
50
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
56
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
57
+
58
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
59
+
60
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
51
61
 
52
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
62
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
53
63
 
54
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
64
+ function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
55
65
 
56
66
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
57
67
 
68
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
69
+
70
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
71
+
58
72
  var datumHasXandY = function (datum) {
59
73
  return !(0, _isNil2.default)(datum._x) && !(0, _isNil2.default)(datum._y);
60
74
  }; // used for checking state changes. Expected components can be passed in via options
@@ -70,347 +84,344 @@ var defaultComponents = [{
70
84
  }];
71
85
 
72
86
  var _default = function _default(WrappedComponent, options) {
73
- return (
74
- /*#__PURE__*/
75
- function (_WrappedComponent) {
76
- _inherits(addEvents, _WrappedComponent);
87
+ return /*#__PURE__*/function (_WrappedComponent) {
88
+ _inherits(addEvents, _WrappedComponent);
77
89
 
78
- function addEvents(props) {
79
- var _this;
90
+ var _super = _createSuper(addEvents);
80
91
 
81
- _classCallCheck(this, addEvents);
92
+ function addEvents(props) {
93
+ var _this;
82
94
 
83
- _this = _possibleConstructorReturn(this, (addEvents.__proto__ || Object.getPrototypeOf(addEvents)).call(this, props));
84
- var getScopedEvents = Events.getScopedEvents.bind(_assertThisInitialized(_this));
85
- var boundGetEvents = Events.getEvents.bind(_assertThisInitialized(_this));
86
- _this.state = {};
95
+ _classCallCheck(this, addEvents);
87
96
 
88
- _this.getEvents = function (p, target, eventKey) {
89
- return boundGetEvents(p, target, eventKey, getScopedEvents);
90
- };
97
+ _this = _super.call(this, props);
98
+ var getScopedEvents = Events.getScopedEvents.bind(_assertThisInitialized(_this));
99
+ var boundGetEvents = Events.getEvents.bind(_assertThisInitialized(_this));
100
+ _this.state = {};
91
101
 
92
- _this.getEventState = Events.getEventState.bind(_assertThisInitialized(_this));
102
+ _this.getEvents = function (p, target, eventKey) {
103
+ return boundGetEvents(p, target, eventKey, getScopedEvents);
104
+ };
93
105
 
94
- var calculatedValues = _this.getCalculatedValues(props);
106
+ _this.getEventState = Events.getEventState.bind(_assertThisInitialized(_this));
95
107
 
96
- _this.cacheValues(calculatedValues);
108
+ var calculatedValues = _this.getCalculatedValues(props);
97
109
 
98
- _this.externalMutations = _this.getExternalMutations(props);
99
- _this.calculatedState = _this.getStateChanges(props);
100
- _this.globalEvents = {};
101
- _this.prevGlobalEventKeys = [];
102
- _this.boundGlobalEvents = {};
103
- return _this;
104
- }
110
+ _this.cacheValues(calculatedValues);
105
111
 
106
- _createClass(addEvents, [{
107
- key: "shouldComponentUpdate",
108
- value: function shouldComponentUpdate(nextProps) {
109
- var externalMutations = this.getExternalMutations(nextProps);
110
- var animating = this.props.animating || this.props.animate;
111
- var newMutation = !(0, _reactFastCompare.default)(externalMutations, this.externalMutations);
112
-
113
- if (animating || newMutation) {
114
- this.cacheValues(this.getCalculatedValues(nextProps));
115
- this.externalMutations = externalMutations;
116
- this.applyExternalMutations(nextProps, externalMutations);
117
- return true;
118
- }
112
+ _this.externalMutations = _this.getExternalMutations(props);
113
+ _this.calculatedState = _this.getStateChanges(props);
114
+ _this.globalEvents = {};
115
+ _this.prevGlobalEventKeys = [];
116
+ _this.boundGlobalEvents = {};
117
+ return _this;
118
+ }
119
119
 
120
- var calculatedState = this.getStateChanges(nextProps);
120
+ _createClass(addEvents, [{
121
+ key: "shouldComponentUpdate",
122
+ value: function shouldComponentUpdate(nextProps) {
123
+ var externalMutations = this.getExternalMutations(nextProps);
124
+ var animating = this.props.animating || this.props.animate;
125
+ var newMutation = !(0, _reactFastCompare.default)(externalMutations, this.externalMutations);
121
126
 
122
- if (!(0, _reactFastCompare.default)(this.calculatedState, calculatedState)) {
123
- this.cacheValues(this.getCalculatedValues(nextProps));
124
- return true;
125
- }
127
+ if (animating || newMutation) {
128
+ this.cacheValues(this.getCalculatedValues(nextProps));
129
+ this.externalMutations = externalMutations;
130
+ this.applyExternalMutations(nextProps, externalMutations);
131
+ return true;
132
+ }
126
133
 
127
- if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
128
- this.cacheValues(this.getCalculatedValues(nextProps));
129
- return true;
130
- }
134
+ var calculatedState = this.getStateChanges(nextProps);
131
135
 
132
- return false;
133
- }
134
- }, {
135
- key: "componentDidMount",
136
- value: function componentDidMount() {
137
- var _this2 = this;
138
-
139
- var globalEventKeys = (0, _keys2.default)(this.globalEvents);
140
- globalEventKeys.forEach(function (key) {
141
- return _this2.addGlobalListener(key);
142
- });
143
- this.prevGlobalEventKeys = globalEventKeys;
136
+ if (!(0, _reactFastCompare.default)(this.calculatedState, calculatedState)) {
137
+ this.cacheValues(this.getCalculatedValues(nextProps));
138
+ return true;
144
139
  }
145
- }, {
146
- key: "componentDidUpdate",
147
- value: function componentDidUpdate(prevProps) {
148
- var _this3 = this;
149
-
150
- var calculatedState = this.getStateChanges(prevProps);
151
- this.calculatedState = calculatedState;
152
- var globalEventKeys = (0, _keys2.default)(this.globalEvents);
153
- var removedGlobalEventKeys = (0, _difference2.default)(this.prevGlobalEventKeys, globalEventKeys);
154
- removedGlobalEventKeys.forEach(function (key) {
155
- return _this3.removeGlobalListener(key);
156
- });
157
- var addedGlobalEventKeys = (0, _difference2.default)(globalEventKeys, this.prevGlobalEventKeys);
158
- addedGlobalEventKeys.forEach(function (key) {
159
- return _this3.addGlobalListener(key);
160
- });
161
- this.prevGlobalEventKeys = globalEventKeys;
162
- }
163
- }, {
164
- key: "componentWillUnmount",
165
- value: function componentWillUnmount() {
166
- var _this4 = this;
167
140
 
168
- this.prevGlobalEventKeys.forEach(function (key) {
169
- return _this4.removeGlobalListener(key);
170
- });
141
+ if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
142
+ this.cacheValues(this.getCalculatedValues(nextProps));
143
+ return true;
171
144
  }
172
- }, {
173
- key: "addGlobalListener",
174
- value: function addGlobalListener(key) {
175
- var _this5 = this;
176
-
177
- var boundListener = function (event) {
178
- var listener = _this5.globalEvents[key];
179
- return listener && listener(Events.emulateReactEvent(event));
180
- };
181
-
182
- this.boundGlobalEvents[key] = boundListener;
183
- window.addEventListener(Events.getGlobalEventNameFromKey(key), boundListener);
184
- }
185
- }, {
186
- key: "removeGlobalListener",
187
- value: function removeGlobalListener(key) {
188
- window.removeEventListener(Events.getGlobalEventNameFromKey(key), this.boundGlobalEvents[key]);
189
- } // compile all state changes from own and parent state. Order doesn't matter, as any state
190
- // state change should trigger a re-render
191
-
192
- }, {
193
- key: "getStateChanges",
194
- value: function getStateChanges(props) {
195
- var _this6 = this;
196
-
197
- if (!this.hasEvents) {
198
- return {};
199
- }
200
145
 
201
- var getState = function (key, type) {
202
- var result = (0, _defaults2.default)({}, _this6.getEventState(key, type), _this6.getSharedEventState(key, type));
203
- return (0, _isEmpty2.default)(result) ? undefined : result;
204
- };
205
-
206
- options = options || {};
207
- var components = options.components || defaultComponents;
208
- var stateChanges = components.map(function (component) {
209
- if (!props.standalone && component.name === "parent") {
210
- // don't check for changes on parent props for non-standalone components
211
- return undefined;
212
- } else {
213
- return component.index !== undefined ? getState(component.index, component.name) : _this6.dataKeys.map(function (key) {
214
- return getState(key, component.name);
215
- }).filter(Boolean);
216
- }
217
- }).filter(Boolean);
218
- return stateChanges;
219
- }
220
- }, {
221
- key: "applyExternalMutations",
222
- value: function applyExternalMutations(props, externalMutations) {
223
- if (!(0, _isEmpty2.default)(externalMutations)) {
224
- var callbacks = props.externalEventMutations.reduce(function (memo, mutation) {
225
- memo = (0, _isFunction2.default)(mutation.callback) ? memo.concat(mutation.callback) : memo;
226
- return memo;
227
- }, []);
228
- var compiledCallbacks = callbacks.length ? function () {
229
- callbacks.forEach(function (c) {
230
- return c();
231
- });
232
- } : undefined;
233
- this.setState(externalMutations, compiledCallbacks);
234
- }
235
- }
236
- }, {
237
- key: "getCalculatedValues",
238
- value: function getCalculatedValues(props) {
239
- var sharedEvents = props.sharedEvents;
240
- var components = WrappedComponent.expectedComponents;
241
- var componentEvents = Events.getComponentEvents(props, components);
242
- var getSharedEventState = sharedEvents && (0, _isFunction2.default)(sharedEvents.getEventState) ? sharedEvents.getEventState : function () {
243
- return undefined;
244
- };
245
- var baseProps = this.getBaseProps(props, getSharedEventState);
246
- var dataKeys = (0, _keys2.default)(baseProps).filter(function (key) {
247
- return key !== "parent";
248
- });
249
- var hasEvents = props.events || props.sharedEvents || componentEvents;
250
- var events = this.getAllEvents(props);
251
- return {
252
- componentEvents: componentEvents,
253
- getSharedEventState: getSharedEventState,
254
- baseProps: baseProps,
255
- dataKeys: dataKeys,
256
- hasEvents: hasEvents,
257
- events: events
258
- };
259
- }
260
- }, {
261
- key: "getExternalMutations",
262
- value: function getExternalMutations(props) {
263
- var sharedEvents = props.sharedEvents,
264
- externalEventMutations = props.externalEventMutations;
265
- return (0, _isEmpty2.default)(externalEventMutations) || sharedEvents ? undefined : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
266
- }
267
- }, {
268
- key: "cacheValues",
269
- value: function cacheValues(obj) {
270
- var _this7 = this;
146
+ return false;
147
+ }
148
+ }, {
149
+ key: "componentDidMount",
150
+ value: function componentDidMount() {
151
+ var _this2 = this;
152
+
153
+ var globalEventKeys = (0, _keys2.default)(this.globalEvents);
154
+ globalEventKeys.forEach(function (key) {
155
+ return _this2.addGlobalListener(key);
156
+ });
157
+ this.prevGlobalEventKeys = globalEventKeys;
158
+ }
159
+ }, {
160
+ key: "componentDidUpdate",
161
+ value: function componentDidUpdate(prevProps) {
162
+ var _this3 = this;
163
+
164
+ var calculatedState = this.getStateChanges(prevProps);
165
+ this.calculatedState = calculatedState;
166
+ var globalEventKeys = (0, _keys2.default)(this.globalEvents);
167
+ var removedGlobalEventKeys = (0, _difference2.default)(this.prevGlobalEventKeys, globalEventKeys);
168
+ removedGlobalEventKeys.forEach(function (key) {
169
+ return _this3.removeGlobalListener(key);
170
+ });
171
+ var addedGlobalEventKeys = (0, _difference2.default)(globalEventKeys, this.prevGlobalEventKeys);
172
+ addedGlobalEventKeys.forEach(function (key) {
173
+ return _this3.addGlobalListener(key);
174
+ });
175
+ this.prevGlobalEventKeys = globalEventKeys;
176
+ }
177
+ }, {
178
+ key: "componentWillUnmount",
179
+ value: function componentWillUnmount() {
180
+ var _this4 = this;
181
+
182
+ this.prevGlobalEventKeys.forEach(function (key) {
183
+ return _this4.removeGlobalListener(key);
184
+ });
185
+ }
186
+ }, {
187
+ key: "addGlobalListener",
188
+ value: function addGlobalListener(key) {
189
+ var _this5 = this;
190
+
191
+ var boundListener = function (event) {
192
+ var listener = _this5.globalEvents[key];
193
+ return listener && listener(Events.emulateReactEvent(event));
194
+ };
271
195
 
272
- (0, _keys2.default)(obj).forEach(function (key) {
273
- _this7[key] = obj[key];
274
- });
275
- }
276
- }, {
277
- key: "getBaseProps",
278
- value: function getBaseProps(props, getSharedEventState) {
279
- getSharedEventState = getSharedEventState || this.getSharedEventState;
280
- var sharedParentState = getSharedEventState("parent", "parent");
281
- var parentState = this.getEventState("parent", "parent");
282
- var baseParentProps = (0, _defaults2.default)({}, parentState, sharedParentState);
283
- var parentPropsList = baseParentProps.parentControlledProps;
284
- var parentProps = parentPropsList ? (0, _pick2.default)(baseParentProps, parentPropsList) : {};
285
- var modifiedProps = (0, _defaults2.default)({}, parentProps, props);
286
- return (0, _isFunction2.default)(WrappedComponent.getBaseProps) ? WrappedComponent.getBaseProps(modifiedProps) : {};
196
+ this.boundGlobalEvents[key] = boundListener;
197
+ window.addEventListener(Events.getGlobalEventNameFromKey(key), boundListener);
198
+ }
199
+ }, {
200
+ key: "removeGlobalListener",
201
+ value: function removeGlobalListener(key) {
202
+ window.removeEventListener(Events.getGlobalEventNameFromKey(key), this.boundGlobalEvents[key]);
203
+ } // compile all state changes from own and parent state. Order doesn't matter, as any state
204
+ // state change should trigger a re-render
205
+
206
+ }, {
207
+ key: "getStateChanges",
208
+ value: function getStateChanges(props) {
209
+ var _this6 = this;
210
+
211
+ if (!this.hasEvents) {
212
+ return {};
287
213
  }
288
- }, {
289
- key: "getAllEvents",
290
- value: function getAllEvents(props) {
291
- if (Array.isArray(this.componentEvents)) {
292
- var _componentEvents;
293
214
 
294
- return Array.isArray(props.events) ? (_componentEvents = this.componentEvents).concat.apply(_componentEvents, _toConsumableArray(props.events)) : this.componentEvents;
295
- }
215
+ var getState = function (key, type) {
216
+ var result = (0, _defaults2.default)({}, _this6.getEventState(key, type), _this6.getSharedEventState(key, type));
217
+ return (0, _isEmpty2.default)(result) ? undefined : result;
218
+ };
296
219
 
297
- return props.events;
298
- }
299
- }, {
300
- key: "getComponentProps",
301
- value: function getComponentProps(component, type, index) {
302
- var name = this.props.name || WrappedComponent.role;
303
- var key = this.dataKeys && this.dataKeys[index] || index;
304
- var id = "".concat(name, "-").concat(type, "-").concat(key);
305
- var baseProps = this.baseProps[key] && this.baseProps[key][type] || this.baseProps[key];
306
-
307
- if (!baseProps && !this.hasEvents) {
220
+ options = options || {};
221
+ var components = options.components || defaultComponents;
222
+ var stateChanges = components.map(function (component) {
223
+ if (!props.standalone && component.name === "parent") {
224
+ // don't check for changes on parent props for non-standalone components
308
225
  return undefined;
226
+ } else {
227
+ return component.index !== undefined ? getState(component.index, component.name) : _this6.dataKeys.map(function (key) {
228
+ return getState(key, component.name);
229
+ }).filter(Boolean);
309
230
  }
310
-
311
- if (this.hasEvents) {
312
- var baseEvents = this.getEvents(this.props, type, key);
313
- var componentProps = (0, _defaults2.default)({
314
- index: index,
315
- key: id
316
- }, this.getEventState(key, type), this.getSharedEventState(key, type), component.props, baseProps, {
317
- id: id
318
- });
319
- var events = (0, _defaults2.default)({}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events);
320
- return (0, _assign2.default)({}, componentProps, {
321
- events: events
231
+ }).filter(Boolean);
232
+ return stateChanges;
233
+ }
234
+ }, {
235
+ key: "applyExternalMutations",
236
+ value: function applyExternalMutations(props, externalMutations) {
237
+ if (!(0, _isEmpty2.default)(externalMutations)) {
238
+ var callbacks = props.externalEventMutations.reduce(function (memo, mutation) {
239
+ memo = (0, _isFunction2.default)(mutation.callback) ? memo.concat(mutation.callback) : memo;
240
+ return memo;
241
+ }, []);
242
+ var compiledCallbacks = callbacks.length ? function () {
243
+ callbacks.forEach(function (c) {
244
+ return c();
322
245
  });
323
- }
246
+ } : undefined;
247
+ this.setState(externalMutations, compiledCallbacks);
248
+ }
249
+ }
250
+ }, {
251
+ key: "getCalculatedValues",
252
+ value: function getCalculatedValues(props) {
253
+ var sharedEvents = props.sharedEvents;
254
+ var components = WrappedComponent.expectedComponents;
255
+ var componentEvents = Events.getComponentEvents(props, components);
256
+ var getSharedEventState = sharedEvents && (0, _isFunction2.default)(sharedEvents.getEventState) ? sharedEvents.getEventState : function () {
257
+ return undefined;
258
+ };
259
+ var baseProps = this.getBaseProps(props, getSharedEventState);
260
+ var dataKeys = (0, _keys2.default)(baseProps).filter(function (key) {
261
+ return key !== "parent";
262
+ });
263
+ var hasEvents = props.events || props.sharedEvents || componentEvents;
264
+ var events = this.getAllEvents(props);
265
+ return {
266
+ componentEvents: componentEvents,
267
+ getSharedEventState: getSharedEventState,
268
+ baseProps: baseProps,
269
+ dataKeys: dataKeys,
270
+ hasEvents: hasEvents,
271
+ events: events
272
+ };
273
+ }
274
+ }, {
275
+ key: "getExternalMutations",
276
+ value: function getExternalMutations(props) {
277
+ var sharedEvents = props.sharedEvents,
278
+ externalEventMutations = props.externalEventMutations;
279
+ return (0, _isEmpty2.default)(externalEventMutations) || sharedEvents ? undefined : Events.getExternalMutations(externalEventMutations, this.baseProps, this.state);
280
+ }
281
+ }, {
282
+ key: "cacheValues",
283
+ value: function cacheValues(obj) {
284
+ var _this7 = this;
285
+
286
+ (0, _keys2.default)(obj).forEach(function (key) {
287
+ _this7[key] = obj[key];
288
+ });
289
+ }
290
+ }, {
291
+ key: "getBaseProps",
292
+ value: function getBaseProps(props, getSharedEventState) {
293
+ getSharedEventState = getSharedEventState || this.getSharedEventState;
294
+ var sharedParentState = getSharedEventState("parent", "parent");
295
+ var parentState = this.getEventState("parent", "parent");
296
+ var baseParentProps = (0, _defaults2.default)({}, parentState, sharedParentState);
297
+ var parentPropsList = baseParentProps.parentControlledProps;
298
+ var parentProps = parentPropsList ? (0, _pick2.default)(baseParentProps, parentPropsList) : {};
299
+ var modifiedProps = (0, _defaults2.default)({}, parentProps, props);
300
+ return (0, _isFunction2.default)(WrappedComponent.getBaseProps) ? WrappedComponent.getBaseProps(modifiedProps) : {};
301
+ }
302
+ }, {
303
+ key: "getAllEvents",
304
+ value: function getAllEvents(props) {
305
+ if (Array.isArray(this.componentEvents)) {
306
+ var _this$componentEvents;
307
+
308
+ return Array.isArray(props.events) ? (_this$componentEvents = this.componentEvents).concat.apply(_this$componentEvents, _toConsumableArray(props.events)) : this.componentEvents;
309
+ }
324
310
 
325
- return (0, _defaults2.default)({
311
+ return props.events;
312
+ }
313
+ }, {
314
+ key: "getComponentProps",
315
+ value: function getComponentProps(component, type, index) {
316
+ var name = this.props.name || WrappedComponent.role;
317
+ var key = this.dataKeys && this.dataKeys[index] || index;
318
+ var id = "".concat(name, "-").concat(type, "-").concat(key);
319
+ var baseProps = this.baseProps[key] && this.baseProps[key][type] || this.baseProps[key];
320
+
321
+ if (!baseProps && !this.hasEvents) {
322
+ return undefined;
323
+ }
324
+
325
+ if (this.hasEvents) {
326
+ var baseEvents = this.getEvents(this.props, type, key);
327
+ var componentProps = (0, _defaults2.default)({
326
328
  index: index,
327
329
  key: id
328
- }, component.props, baseProps, {
330
+ }, this.getEventState(key, type), this.getSharedEventState(key, type), component.props, baseProps, {
329
331
  id: id
330
332
  });
333
+ var events = (0, _defaults2.default)({}, Events.getPartialEvents(baseEvents, key, componentProps), componentProps.events);
334
+ return (0, _assign2.default)({}, componentProps, {
335
+ events: events
336
+ });
331
337
  }
332
- }, {
333
- key: "renderContainer",
334
- value: function renderContainer(component, children) {
335
- var isContainer = component.type && component.type.role === "container";
336
- var parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
337
-
338
- if (parentProps.events) {
339
- this.globalEvents = Events.getGlobalEvents(parentProps.events);
340
- parentProps.events = Events.omitGlobalEvents(parentProps.events);
341
- }
342
338
 
343
- return _react.default.cloneElement(component, parentProps, children);
339
+ return (0, _defaults2.default)({
340
+ index: index,
341
+ key: id
342
+ }, component.props, baseProps, {
343
+ id: id
344
+ });
345
+ }
346
+ }, {
347
+ key: "renderContainer",
348
+ value: function renderContainer(component, children) {
349
+ var isContainer = component.type && component.type.role === "container";
350
+ var parentProps = isContainer ? this.getComponentProps(component, "parent", "parent") : {};
351
+
352
+ if (parentProps.events) {
353
+ this.globalEvents = Events.getGlobalEvents(parentProps.events);
354
+ parentProps.events = Events.omitGlobalEvents(parentProps.events);
344
355
  }
345
- }, {
346
- key: "animateComponent",
347
- value: function animateComponent(props, defaultAnimationWhitelist) {
348
- var animationWhitelist = props.animate && props.animate.animationWhitelist ? props.animate.animationWhitelist : defaultAnimationWhitelist;
349
- return _react.default.createElement(_victoryTransition.default, {
350
- animate: props.animate,
351
- animationWhitelist: animationWhitelist
352
- }, _react.default.createElement(this.constructor, props));
353
- } // Used by `VictoryLine` and `VictoryArea`
354
-
355
- }, {
356
- key: "renderContinuousData",
357
- value: function renderContinuousData(props) {
358
- var _this8 = this;
359
-
360
- var dataComponent = props.dataComponent,
361
- labelComponent = props.labelComponent,
362
- groupComponent = props.groupComponent;
363
- var dataKeys = (0, _without2.default)(this.dataKeys, "all");
364
- var labelComponents = dataKeys.reduce(function (memo, key) {
365
- var labelProps = _this8.getComponentProps(labelComponent, "labels", key);
366
-
367
- if (labelProps && labelProps.text !== undefined && labelProps.text !== null) {
368
- memo = memo.concat(_react.default.cloneElement(labelComponent, labelProps));
369
- }
370
356
 
371
- return memo;
372
- }, []);
373
- var dataProps = this.getComponentProps(dataComponent, "data", "all");
374
- var children = [_react.default.cloneElement(dataComponent, dataProps)].concat(_toConsumableArray(labelComponents));
375
- return this.renderContainer(groupComponent, children);
376
- }
377
- }, {
378
- key: "renderData",
379
- value: function renderData(props) {
380
- var _this9 = this;
381
-
382
- var shouldRenderDatum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : datumHasXandY;
383
- var dataComponent = props.dataComponent,
384
- labelComponent = props.labelComponent,
385
- groupComponent = props.groupComponent;
386
- var dataComponents = this.dataKeys.reduce(function (validDataComponents, _dataKey, index) {
387
- var dataProps = _this9.getComponentProps(dataComponent, "data", index);
388
-
389
- if (shouldRenderDatum(dataProps.datum)) {
390
- validDataComponents.push(_react.default.cloneElement(dataComponent, dataProps));
391
- }
392
-
393
- return validDataComponents;
394
- }, []);
395
- var labelComponents = this.dataKeys.map(function (_dataKey, index) {
396
- var labelProps = _this9.getComponentProps(labelComponent, "labels", index);
357
+ return /*#__PURE__*/_react.default.cloneElement(component, parentProps, children);
358
+ }
359
+ }, {
360
+ key: "animateComponent",
361
+ value: function animateComponent(props, defaultAnimationWhitelist) {
362
+ var animationWhitelist = props.animate && props.animate.animationWhitelist ? props.animate.animationWhitelist : defaultAnimationWhitelist;
363
+ return /*#__PURE__*/_react.default.createElement(_victoryTransition.default, {
364
+ animate: props.animate,
365
+ animationWhitelist: animationWhitelist
366
+ }, /*#__PURE__*/_react.default.createElement(this.constructor, props));
367
+ } // Used by `VictoryLine` and `VictoryArea`
368
+
369
+ }, {
370
+ key: "renderContinuousData",
371
+ value: function renderContinuousData(props) {
372
+ var _this8 = this;
373
+
374
+ var dataComponent = props.dataComponent,
375
+ labelComponent = props.labelComponent,
376
+ groupComponent = props.groupComponent;
377
+ var dataKeys = (0, _without2.default)(this.dataKeys, "all");
378
+ var labelComponents = dataKeys.reduce(function (memo, key) {
379
+ var labelProps = _this8.getComponentProps(labelComponent, "labels", key);
380
+
381
+ if (labelProps && labelProps.text !== undefined && labelProps.text !== null) {
382
+ memo = memo.concat( /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps));
383
+ }
397
384
 
398
- if (labelProps.text !== undefined && labelProps.text !== null) {
399
- return _react.default.cloneElement(labelComponent, labelProps);
400
- }
385
+ return memo;
386
+ }, []);
387
+ var dataProps = this.getComponentProps(dataComponent, "data", "all");
388
+ var children = [/*#__PURE__*/_react.default.cloneElement(dataComponent, dataProps)].concat(_toConsumableArray(labelComponents));
389
+ return this.renderContainer(groupComponent, children);
390
+ }
391
+ }, {
392
+ key: "renderData",
393
+ value: function renderData(props) {
394
+ var _this9 = this;
395
+
396
+ var shouldRenderDatum = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : datumHasXandY;
397
+ var dataComponent = props.dataComponent,
398
+ labelComponent = props.labelComponent,
399
+ groupComponent = props.groupComponent;
400
+ var dataComponents = this.dataKeys.reduce(function (validDataComponents, _dataKey, index) {
401
+ var dataProps = _this9.getComponentProps(dataComponent, "data", index);
402
+
403
+ if (shouldRenderDatum(dataProps.datum)) {
404
+ validDataComponents.push( /*#__PURE__*/_react.default.cloneElement(dataComponent, dataProps));
405
+ }
401
406
 
402
- return undefined;
403
- }).filter(Boolean);
407
+ return validDataComponents;
408
+ }, []);
409
+ var labelComponents = this.dataKeys.map(function (_dataKey, index) {
410
+ var labelProps = _this9.getComponentProps(labelComponent, "labels", index);
404
411
 
405
- var children = _toConsumableArray(dataComponents).concat(_toConsumableArray(labelComponents));
412
+ if (labelProps.text !== undefined && labelProps.text !== null) {
413
+ return /*#__PURE__*/_react.default.cloneElement(labelComponent, labelProps);
414
+ }
406
415
 
407
- return this.renderContainer(groupComponent, children);
408
- }
409
- }]);
416
+ return undefined;
417
+ }).filter(Boolean);
418
+ var children = [].concat(_toConsumableArray(dataComponents), _toConsumableArray(labelComponents));
419
+ return this.renderContainer(groupComponent, children);
420
+ }
421
+ }]);
410
422
 
411
- return addEvents;
412
- }(WrappedComponent)
413
- );
423
+ return addEvents;
424
+ }(WrappedComponent);
414
425
  };
415
426
 
416
427
  exports.default = _default;