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