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