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