victory-shared-events 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.
@@ -4,363 +4,203 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VictorySharedEvents = void 0;
7
-
8
7
  var _fromPairs2 = _interopRequireDefault(require("lodash/fromPairs"));
9
-
10
8
  var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
11
-
12
9
  var _defaults2 = _interopRequireDefault(require("lodash/defaults"));
13
-
14
10
  var _react = _interopRequireDefault(require("react"));
15
-
16
11
  var _victoryCore = require("victory-core");
17
-
18
12
  var _reactFastCompare = _interopRequireDefault(require("react-fast-compare"));
19
-
20
13
  var _jsonStringifySafe = _interopRequireDefault(require("json-stringify-safe"));
21
-
22
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
25
-
26
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
27
-
28
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
29
-
30
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
-
32
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
33
-
34
- 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."); }
35
-
36
- 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); }
37
-
38
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
39
-
40
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
41
-
42
- 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; }
43
-
44
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
45
-
46
- 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); } }
47
-
48
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
49
-
50
- 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); }
51
-
52
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
53
-
54
- 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); }; }
55
-
56
- 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); }
57
-
58
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
59
-
60
- 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; } }
61
-
62
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
63
-
64
- var VictorySharedEvents = /*#__PURE__*/function (_React$Component) {
65
- _inherits(VictorySharedEvents, _React$Component);
66
-
67
- var _super = _createSuper(VictorySharedEvents);
68
-
69
- function VictorySharedEvents(props) {
70
- var _this;
71
-
72
- _classCallCheck(this, VictorySharedEvents);
73
-
74
- _this = _super.call(this, props);
75
- _this.getScopedEvents = void 0;
76
- _this.getEventState = void 0;
77
- _this.baseProps = void 0;
78
- _this.sharedEventsCache = void 0;
79
- _this.globalEvents = void 0;
80
- _this.prevGlobalEventKeys = void 0;
81
- _this.boundGlobalEvents = void 0;
82
- _this.getScopedEvents = _victoryCore.Events.getScopedEvents.bind(_assertThisInitialized(_this));
83
- _this.getEventState = _victoryCore.Events.getEventState.bind(_assertThisInitialized(_this));
84
- _this.state = _this.state || {};
85
- _this.sharedEventsCache = {};
86
- _this.globalEvents = {};
87
- _this.prevGlobalEventKeys = [];
88
- _this.boundGlobalEvents = {};
89
- _this.baseProps = _this.getBaseProps(props);
90
- return _this;
15
+ // DISCLAIMER:
16
+ // This file is not currently tested, and it is first on the list of files
17
+ // to refactor in our current refactoring effort. Please do not make changes
18
+ // to this file without manual testing and/or refactoring and adding tests.
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
21
+
22
+ class VictorySharedEvents extends _react.default.Component {
23
+ static displayName = "VictorySharedEvents";
24
+ static role = "shared-event-wrapper";
25
+ static contextType = _victoryCore.TimerContext;
26
+ static defaultProps = {
27
+ groupComponent: /*#__PURE__*/_react.default.createElement("g", null)
28
+ };
29
+ constructor(props) {
30
+ super(props);
31
+ this.getScopedEvents = _victoryCore.Events.getScopedEvents.bind(this);
32
+ this.getEventState = _victoryCore.Events.getEventState.bind(this);
33
+ this.state = this.state || {};
34
+ this.sharedEventsCache = {};
35
+ this.globalEvents = {};
36
+ this.prevGlobalEventKeys = [];
37
+ this.boundGlobalEvents = {};
38
+ this.baseProps = this.getBaseProps(props);
91
39
  }
92
-
93
- _createClass(VictorySharedEvents, [{
94
- key: "shouldComponentUpdate",
95
- value: function shouldComponentUpdate(nextProps) {
96
- if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
97
- this.baseProps = this.getBaseProps(nextProps);
98
- var externalMutations = this.getExternalMutations(nextProps, this.baseProps);
99
- this.applyExternalMutations(nextProps, externalMutations);
100
- }
101
-
102
- return true;
103
- }
104
- }, {
105
- key: "componentDidMount",
106
- value: function componentDidMount() {
107
- var _this2 = this;
108
-
109
- var globalEventKeys = Object.keys(this.globalEvents);
110
- globalEventKeys.forEach(function (key) {
111
- return _this2.addGlobalListener(key);
112
- });
113
- this.prevGlobalEventKeys = globalEventKeys;
40
+ shouldComponentUpdate(nextProps) {
41
+ if (!(0, _reactFastCompare.default)(this.props, nextProps)) {
42
+ this.baseProps = this.getBaseProps(nextProps);
43
+ const externalMutations = this.getExternalMutations(nextProps, this.baseProps);
44
+ this.applyExternalMutations(nextProps, externalMutations);
114
45
  }
115
- }, {
116
- key: "componentDidUpdate",
117
- value: function componentDidUpdate() {
118
- var _this3 = this;
119
-
120
- var globalEventKeys = Object.keys(this.globalEvents);
121
-
122
- var removedGlobalEventKeys = _victoryCore.Collection.difference(this.prevGlobalEventKeys, globalEventKeys);
123
-
124
- removedGlobalEventKeys.forEach(function (key) {
125
- return _this3.removeGlobalListener(key);
126
- });
127
-
128
- var addedGlobalEventKeys = _victoryCore.Collection.difference(globalEventKeys, this.prevGlobalEventKeys);
129
-
130
- addedGlobalEventKeys.forEach(function (key) {
131
- return _this3.addGlobalListener(key);
132
- });
133
- this.prevGlobalEventKeys = globalEventKeys;
134
- }
135
- }, {
136
- key: "componentWillUnmount",
137
- value: function componentWillUnmount() {
138
- var _this4 = this;
139
-
140
- this.prevGlobalEventKeys.forEach(function (key) {
141
- return _this4.removeGlobalListener(key);
142
- });
46
+ return true;
47
+ }
48
+ componentDidMount() {
49
+ const globalEventKeys = Object.keys(this.globalEvents);
50
+ globalEventKeys.forEach(key => this.addGlobalListener(key));
51
+ this.prevGlobalEventKeys = globalEventKeys;
52
+ }
53
+ componentDidUpdate() {
54
+ const globalEventKeys = Object.keys(this.globalEvents);
55
+ const removedGlobalEventKeys = _victoryCore.Collection.difference(this.prevGlobalEventKeys, globalEventKeys);
56
+ removedGlobalEventKeys.forEach(key => this.removeGlobalListener(key));
57
+ const addedGlobalEventKeys = _victoryCore.Collection.difference(globalEventKeys, this.prevGlobalEventKeys);
58
+ addedGlobalEventKeys.forEach(key => this.addGlobalListener(key));
59
+ this.prevGlobalEventKeys = globalEventKeys;
60
+ }
61
+ componentWillUnmount() {
62
+ this.prevGlobalEventKeys.forEach(key => this.removeGlobalListener(key));
63
+ }
64
+ addGlobalListener(key) {
65
+ const boundListener = event => {
66
+ const listener = this.globalEvents[key];
67
+ return listener && listener(_victoryCore.Events.emulateReactEvent(event));
68
+ };
69
+ this.boundGlobalEvents[key] = boundListener;
70
+ window.addEventListener(_victoryCore.Events.getGlobalEventNameFromKey(key), boundListener);
71
+ }
72
+ removeGlobalListener(key) {
73
+ window.removeEventListener(_victoryCore.Events.getGlobalEventNameFromKey(key), this.boundGlobalEvents[key]);
74
+ }
75
+ getAllEvents(props) {
76
+ const components = ["container", "groupComponent"];
77
+ const componentEvents = _victoryCore.Events.getComponentEvents(props, components);
78
+ if (Array.isArray(componentEvents)) {
79
+ return Array.isArray(props.events) ? componentEvents.concat(...props.events) : componentEvents;
143
80
  }
144
- }, {
145
- key: "addGlobalListener",
146
- value: function addGlobalListener(key) {
147
- var _this5 = this;
148
-
149
- var boundListener = function (event) {
150
- var listener = _this5.globalEvents[key];
151
- return listener && listener(_victoryCore.Events.emulateReactEvent(event));
152
- };
153
-
154
- this.boundGlobalEvents[key] = boundListener;
155
- window.addEventListener(_victoryCore.Events.getGlobalEventNameFromKey(key), boundListener);
81
+ return props.events;
82
+ }
83
+ applyExternalMutations(props, externalMutations) {
84
+ if (!(0, _isEmpty2.default)(externalMutations)) {
85
+ const callbacks = props.externalEventMutations.reduce((memo, mutation) => _victoryCore.Helpers.isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo, []);
86
+ const compiledCallbacks = callbacks.length ? () => {
87
+ callbacks.forEach(c => c());
88
+ } : undefined;
89
+ this.setState(externalMutations, compiledCallbacks);
156
90
  }
157
- }, {
158
- key: "removeGlobalListener",
159
- value: function removeGlobalListener(key) {
160
- window.removeEventListener(_victoryCore.Events.getGlobalEventNameFromKey(key), this.boundGlobalEvents[key]);
91
+ }
92
+ getExternalMutations(props, baseProps) {
93
+ return !(0, _isEmpty2.default)(props.externalEventMutations) ? _victoryCore.Events.getExternalMutationsWithChildren(props.externalEventMutations, baseProps, this.state, Object.keys(baseProps)) : undefined;
94
+ }
95
+ cacheSharedEvents(name, sharedEvents, cacheValues) {
96
+ this.sharedEventsCache[name] = [sharedEvents, cacheValues];
97
+ }
98
+ getCachedSharedEvents(name, cacheValues) {
99
+ const [sharedEvents, prevCacheValues] = this.sharedEventsCache[name] || [];
100
+ if (sharedEvents && (0, _reactFastCompare.default)(cacheValues, prevCacheValues)) {
101
+ return sharedEvents;
161
102
  }
162
- }, {
163
- key: "getAllEvents",
164
- value: function getAllEvents(props) {
165
- var components = ["container", "groupComponent"];
166
-
167
- var componentEvents = _victoryCore.Events.getComponentEvents(props, components);
168
-
169
- if (Array.isArray(componentEvents)) {
170
- return Array.isArray(props.events) ? componentEvents.concat.apply(componentEvents, _toConsumableArray(props.events)) : componentEvents;
103
+ return undefined;
104
+ }
105
+ getBaseProps(props) {
106
+ const {
107
+ container
108
+ } = props;
109
+ const children = _react.default.Children.toArray(this.props.children);
110
+ const childBaseProps = this.getBasePropsFromChildren(children);
111
+ const parentBaseProps = container ? container.props : {};
112
+ return Object.assign({}, childBaseProps, {
113
+ parent: parentBaseProps
114
+ });
115
+ }
116
+ getBasePropsFromChildren(childComponents) {
117
+ const iteratee = (child, childName) => {
118
+ if (child.type && _victoryCore.Helpers.isFunction(child.type.getBaseProps)) {
119
+ const baseProps = child.props && child.type.getBaseProps(child.props);
120
+ return baseProps ? [[childName, baseProps]] : null;
171
121
  }
172
-
173
- return props.events;
174
- }
175
- }, {
176
- key: "applyExternalMutations",
177
- value: function applyExternalMutations(props, externalMutations) {
178
- if (!(0, _isEmpty2.default)(externalMutations)) {
179
- var callbacks = props.externalEventMutations.reduce(function (memo, mutation) {
180
- return _victoryCore.Helpers.isFunction(mutation.callback) ? memo.concat(mutation.callback) : memo;
181
- }, []);
182
- var compiledCallbacks = callbacks.length ? function () {
183
- callbacks.forEach(function (c) {
184
- return c();
122
+ return null;
123
+ };
124
+ const baseProps = _victoryCore.Helpers.reduceChildren(childComponents, iteratee);
125
+ return (0, _fromPairs2.default)(baseProps);
126
+ }
127
+ getNewChildren(props, baseProps) {
128
+ const {
129
+ events,
130
+ eventKey
131
+ } = props;
132
+ const alterChildren = (children, childNames) => {
133
+ return children.reduce((memo, child, index) => {
134
+ if (child.props.children) {
135
+ const newChildren = _react.default.Children.toArray(child.props.children);
136
+ const names = childNames.slice(index, index + newChildren.length);
137
+ const results = /*#__PURE__*/_react.default.cloneElement(child, child.props, alterChildren(newChildren, names));
138
+ return memo.concat(results);
139
+ } else if (childNames[index] !== "parent" && child.type && _victoryCore.Helpers.isFunction(child.type.getBaseProps)) {
140
+ const name = child.props.name || childNames[index];
141
+ const childEvents = Array.isArray(events) && events.filter(event => {
142
+ if (event.target === "parent") {
143
+ return false;
144
+ }
145
+ return Array.isArray(event.childName) ? event.childName.indexOf(name) > -1 : event.childName === name || event.childName === "all";
185
146
  });
186
- } : undefined;
187
- this.setState(externalMutations, compiledCallbacks);
188
- }
189
- }
190
- }, {
191
- key: "getExternalMutations",
192
- value: function getExternalMutations(props, baseProps) {
193
- return !(0, _isEmpty2.default)(props.externalEventMutations) ? _victoryCore.Events.getExternalMutationsWithChildren(props.externalEventMutations, baseProps, this.state, Object.keys(baseProps)) : undefined;
194
- }
195
- }, {
196
- key: "cacheSharedEvents",
197
- value: function cacheSharedEvents(name, sharedEvents, cacheValues) {
198
- this.sharedEventsCache[name] = [sharedEvents, cacheValues];
199
- }
200
- }, {
201
- key: "getCachedSharedEvents",
202
- value: function getCachedSharedEvents(name, cacheValues) {
203
- var _ref = this.sharedEventsCache[name] || [],
204
- _ref2 = _slicedToArray(_ref, 2),
205
- sharedEvents = _ref2[0],
206
- prevCacheValues = _ref2[1];
207
-
208
- if (sharedEvents && (0, _reactFastCompare.default)(cacheValues, prevCacheValues)) {
209
- return sharedEvents;
210
- }
211
-
212
- return undefined;
213
- }
214
- }, {
215
- key: "getBaseProps",
216
- value: function getBaseProps(props) {
217
- var container = props.container;
218
-
219
- var children = _react.default.Children.toArray(this.props.children);
220
-
221
- var childBaseProps = this.getBasePropsFromChildren(children);
222
- var parentBaseProps = container ? container.props : {};
223
- return Object.assign({}, childBaseProps, {
224
- parent: parentBaseProps
225
- });
226
- }
227
- }, {
228
- key: "getBasePropsFromChildren",
229
- value: function getBasePropsFromChildren(childComponents) {
230
- var iteratee = function (child, childName) {
231
- if (child.type && _victoryCore.Helpers.isFunction(child.type.getBaseProps)) {
232
- var _baseProps = child.props && child.type.getBaseProps(child.props);
233
-
234
- return _baseProps ? [[childName, _baseProps]] : null;
147
+ const sharedEventsCacheValues = [name, baseProps, childEvents, (0, _jsonStringifySafe.default)(this.state[name])];
148
+ const sharedEvents = this.getCachedSharedEvents(name, sharedEventsCacheValues) || {
149
+ events: childEvents,
150
+ // partially apply child name and baseProps,
151
+ getEvents: (evts, target) => this.getScopedEvents(evts, target, name, baseProps),
152
+ // partially apply child name
153
+ getEventState: (key, target) => this.getEventState(key, target, name)
154
+ };
155
+ this.cacheSharedEvents(name, sharedEvents, sharedEventsCacheValues);
156
+ return memo.concat( /*#__PURE__*/_react.default.cloneElement(child, Object.assign({
157
+ key: `events-${name}`,
158
+ sharedEvents,
159
+ eventKey,
160
+ name
161
+ }, child.props)));
235
162
  }
236
-
237
- return null;
238
- };
239
-
240
- var baseProps = _victoryCore.Helpers.reduceChildren(childComponents, iteratee);
241
-
242
- return (0, _fromPairs2.default)(baseProps);
243
- }
244
- }, {
245
- key: "getNewChildren",
246
- value: function getNewChildren(props, baseProps) {
247
- var _this6 = this;
248
-
249
- var events = props.events,
250
- eventKey = props.eventKey;
251
-
252
- var alterChildren = function (children, childNames) {
253
- return children.reduce(function (memo, child, index) {
254
- if (child.props.children) {
255
- var newChildren = _react.default.Children.toArray(child.props.children);
256
-
257
- var names = childNames.slice(index, index + newChildren.length);
258
-
259
- var results = /*#__PURE__*/_react.default.cloneElement(child, child.props, alterChildren(newChildren, names));
260
-
261
- return memo.concat(results);
262
- } else if (childNames[index] !== "parent" && child.type && _victoryCore.Helpers.isFunction(child.type.getBaseProps)) {
263
- var name = child.props.name || childNames[index];
264
- var childEvents = Array.isArray(events) && events.filter(function (event) {
265
- if (event.target === "parent") {
266
- return false;
267
- }
268
-
269
- return Array.isArray(event.childName) ? event.childName.indexOf(name) > -1 : event.childName === name || event.childName === "all";
270
- });
271
- var sharedEventsCacheValues = [name, baseProps, childEvents, (0, _jsonStringifySafe.default)(_this6.state[name])];
272
- var sharedEvents = _this6.getCachedSharedEvents(name, sharedEventsCacheValues) || {
273
- events: childEvents,
274
- // partially apply child name and baseProps,
275
- getEvents: function (evts, target) {
276
- return _this6.getScopedEvents(evts, target, name, baseProps);
277
- },
278
- // partially apply child name
279
- getEventState: function (key, target) {
280
- return _this6.getEventState(key, target, name);
281
- }
282
- };
283
-
284
- _this6.cacheSharedEvents(name, sharedEvents, sharedEventsCacheValues);
285
-
286
- return memo.concat( /*#__PURE__*/_react.default.cloneElement(child, Object.assign({
287
- key: "events-".concat(name),
288
- sharedEvents: sharedEvents,
289
- eventKey: eventKey,
290
- name: name
291
- }, child.props)));
292
- }
293
-
294
- return memo.concat(child);
295
- }, []);
296
- };
297
-
298
- var childNames = Object.keys(baseProps);
299
-
300
- var childComponents = _react.default.Children.toArray(props.children);
301
-
302
- return alterChildren(childComponents, childNames);
303
- }
304
- }, {
305
- key: "getContainer",
306
- value: function getContainer(props, baseProps, events) {
307
- var _this7 = this;
308
-
309
- var children = this.getNewChildren(props, baseProps);
310
- var parents = Array.isArray(events) ? events.filter(function (event) {
311
- return event.target === "parent";
312
- }) : [];
313
- var sharedEvents = parents.length > 0 ? {
314
- events: parents,
315
- // partially apply childName (null) and baseProps,
316
- getEvents: function (evts, target) {
317
- return _this7.getScopedEvents(evts, target, null, baseProps);
318
- },
319
- getEventState: this.getEventState
320
- } : null;
321
- var container = props.container || props.groupComponent;
322
- var role = container.type && container.type.role;
323
- var containerProps = container.props || {};
324
-
325
- var boundGetEvents = _victoryCore.Events.getEvents.bind(this);
326
-
327
- var parentEvents = sharedEvents && boundGetEvents({
328
- sharedEvents: sharedEvents
329
- }, "parent");
330
- var parentProps = (0, _defaults2.default)({}, this.getEventState("parent", "parent"), containerProps, baseProps.parent, {
331
- children: children
332
- });
333
- var containerEvents = (0, _defaults2.default)({}, _victoryCore.Events.getPartialEvents(parentEvents, "parent", parentProps), containerProps.events);
334
- this.globalEvents = _victoryCore.Events.getGlobalEvents(containerEvents);
335
-
336
- var localEvents = _victoryCore.Events.omitGlobalEvents(containerEvents);
337
-
338
- return role === "container" ? /*#__PURE__*/_react.default.cloneElement(container, Object.assign({}, parentProps, {
339
- events: localEvents
340
- })) : /*#__PURE__*/_react.default.cloneElement(container, localEvents, children);
341
- }
342
- }, {
343
- key: "render",
344
- value: function render() {
345
- var events = this.getAllEvents(this.props);
346
-
347
- if (events) {
348
- return this.getContainer(this.props, this.baseProps, events);
349
- }
350
-
351
- return /*#__PURE__*/_react.default.cloneElement(this.props.container, {
352
- children: this.props.children
353
- });
354
- }
355
- }]);
356
-
357
- return VictorySharedEvents;
358
- }(_react.default.Component);
359
-
360
- exports.VictorySharedEvents = VictorySharedEvents;
361
- VictorySharedEvents.displayName = "VictorySharedEvents";
362
- VictorySharedEvents.role = "shared-event-wrapper";
363
- VictorySharedEvents.contextType = _victoryCore.TimerContext;
364
- VictorySharedEvents.defaultProps = {
365
- groupComponent: /*#__PURE__*/_react.default.createElement("g", null)
366
- };
163
+ return memo.concat(child);
164
+ }, []);
165
+ };
166
+ const childNames = Object.keys(baseProps);
167
+ const childComponents = _react.default.Children.toArray(props.children);
168
+ return alterChildren(childComponents, childNames);
169
+ }
170
+ getContainer(props, baseProps, events) {
171
+ const children = this.getNewChildren(props, baseProps);
172
+ const parents = Array.isArray(events) ? events.filter(event => event.target === "parent") : [];
173
+ const sharedEvents = parents.length > 0 ? {
174
+ events: parents,
175
+ // partially apply childName (null) and baseProps,
176
+ getEvents: (evts, target) => this.getScopedEvents(evts, target, null, baseProps),
177
+ getEventState: this.getEventState
178
+ } : null;
179
+ const container = props.container || props.groupComponent;
180
+ const role = container.type && container.type.role;
181
+ const containerProps = container.props || {};
182
+ const boundGetEvents = _victoryCore.Events.getEvents.bind(this);
183
+ const parentEvents = sharedEvents && boundGetEvents({
184
+ sharedEvents
185
+ }, "parent");
186
+ const parentProps = (0, _defaults2.default)({}, this.getEventState("parent", "parent"), containerProps, baseProps.parent, {
187
+ children
188
+ });
189
+ const containerEvents = (0, _defaults2.default)({}, _victoryCore.Events.getPartialEvents(parentEvents, "parent", parentProps), containerProps.events);
190
+ this.globalEvents = _victoryCore.Events.getGlobalEvents(containerEvents);
191
+ const localEvents = _victoryCore.Events.omitGlobalEvents(containerEvents);
192
+ return role === "container" ? /*#__PURE__*/_react.default.cloneElement(container, Object.assign({}, parentProps, {
193
+ events: localEvents
194
+ })) : /*#__PURE__*/_react.default.cloneElement(container, localEvents, children);
195
+ }
196
+ render() {
197
+ const events = this.getAllEvents(this.props);
198
+ if (events) {
199
+ return this.getContainer(this.props, this.baseProps, events);
200
+ }
201
+ return /*#__PURE__*/_react.default.cloneElement(this.props.container, {
202
+ children: this.props.children
203
+ });
204
+ }
205
+ }
206
+ exports.VictorySharedEvents = VictorySharedEvents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-shared-events",
3
- "version": "36.9.2",
3
+ "version": "37.0.0",
4
4
  "description": "Shared Event Helper for Victory",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -23,7 +23,7 @@
23
23
  "json-stringify-safe": "^5.0.1",
24
24
  "lodash": "^4.17.19",
25
25
  "react-fast-compare": "^3.2.0",
26
- "victory-core": "^36.9.2"
26
+ "victory-core": "^37.0.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "react": ">=16.6.0"