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
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
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": "
|
|
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": "^
|
|
26
|
+
"victory-core": "^37.0.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": ">=16.6.0"
|