victory-core 36.3.0 → 36.4.1
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/dist/victory-core.js +14792 -14613
- package/dist/victory-core.min.js +1 -1
- package/es/index.js +2 -0
- package/es/victory-accessible-group/victory-accessible-group.js +38 -40
- package/es/victory-animation/util.js +1 -1
- package/es/victory-animation/victory-animation.js +46 -48
- package/es/victory-clip-container/victory-clip-container.js +74 -75
- package/es/victory-container/victory-container.js +86 -94
- package/es/victory-label/victory-label.js +32 -25
- package/es/victory-portal/portal-context.js +1 -1
- package/es/victory-portal/portal.js +28 -26
- package/es/victory-portal/victory-portal.js +31 -41
- package/es/victory-primitives/arc.js +6 -4
- package/es/victory-primitives/background.js +8 -6
- package/es/victory-primitives/border.js +6 -4
- package/es/victory-primitives/circle.js +8 -4
- package/es/victory-primitives/clip-path.js +1 -1
- package/es/victory-primitives/line-segment.js +6 -4
- package/es/victory-primitives/line.js +8 -4
- package/es/victory-primitives/path.js +7 -3
- package/es/victory-primitives/point.js +6 -4
- package/es/victory-primitives/rect.js +8 -4
- package/es/victory-primitives/text.js +7 -3
- package/es/victory-primitives/tspan.js +1 -1
- package/es/victory-primitives/whisker.js +9 -7
- package/es/victory-transition/victory-transition.js +30 -32
- package/es/victory-util/add-events.js +324 -315
- package/es/victory-util/axis.js +12 -5
- package/es/victory-util/collection.js +8 -4
- package/es/victory-util/common-props.js +2 -2
- package/es/victory-util/data.js +9 -5
- package/es/victory-util/domain.js +8 -4
- package/es/victory-util/events.js +8 -4
- package/es/victory-util/helpers.js +1 -1
- package/es/victory-util/hooks/use-animation-state.js +11 -5
- package/es/victory-util/line-helpers.js +1 -1
- package/es/victory-util/scale.js +19 -19
- package/es/victory-util/textsize.js +11 -7
- package/es/victory-util/timer-context.js +1 -1
- package/es/victory-util/timer.js +3 -5
- package/es/victory-util/user-props.js +123 -0
- package/es/victory-util/wrapper.js +18 -12
- package/lib/index.js +72 -58
- package/lib/victory-accessible-group/victory-accessible-group.js +38 -40
- package/lib/victory-animation/util.js +2 -2
- package/lib/victory-animation/victory-animation.js +49 -49
- package/lib/victory-clip-container/victory-clip-container.js +78 -76
- package/lib/victory-container/victory-container.js +90 -95
- package/lib/victory-label/victory-label.js +38 -27
- package/lib/victory-portal/portal-context.js +1 -1
- package/lib/victory-portal/portal.js +31 -27
- package/lib/victory-portal/victory-portal.js +34 -42
- package/lib/victory-primitives/arc.js +9 -5
- package/lib/victory-primitives/background.js +11 -7
- package/lib/victory-primitives/border.js +9 -5
- package/lib/victory-primitives/circle.js +8 -4
- package/lib/victory-primitives/clip-path.js +1 -1
- package/lib/victory-primitives/line-segment.js +9 -5
- package/lib/victory-primitives/line.js +8 -4
- package/lib/victory-primitives/path.js +7 -3
- package/lib/victory-primitives/point.js +9 -5
- package/lib/victory-primitives/rect.js +8 -4
- package/lib/victory-primitives/text.js +7 -3
- package/lib/victory-primitives/tspan.js +1 -1
- package/lib/victory-primitives/whisker.js +12 -8
- package/lib/victory-transition/victory-transition.js +33 -33
- package/lib/victory-util/add-events.js +322 -311
- package/lib/victory-util/axis.js +20 -11
- package/lib/victory-util/collection.js +11 -7
- package/lib/victory-util/common-props.js +6 -4
- package/lib/victory-util/data.js +13 -7
- package/lib/victory-util/default-transitions.js +1 -1
- package/lib/victory-util/domain.js +11 -5
- package/lib/victory-util/events.js +17 -11
- package/lib/victory-util/helpers.js +14 -14
- package/lib/victory-util/hooks/index.js +4 -4
- package/lib/victory-util/hooks/use-animation-state.js +14 -6
- package/lib/victory-util/immutable.js +3 -3
- package/lib/victory-util/label-helpers.js +6 -4
- package/lib/victory-util/line-helpers.js +4 -2
- package/lib/victory-util/prop-types.js +5 -3
- package/lib/victory-util/scale.js +24 -21
- package/lib/victory-util/selection.js +6 -4
- package/lib/victory-util/textsize.js +12 -8
- package/lib/victory-util/timer-context.js +1 -1
- package/lib/victory-util/timer.js +3 -5
- package/lib/victory-util/user-props.js +139 -0
- package/lib/victory-util/wrapper.js +31 -23
- package/package.json +5 -12
- package/src/index.js +1 -0
- package/src/victory-animation/util.js +1 -1
- package/src/victory-animation/victory-animation.js +1 -1
- package/src/victory-clip-container/victory-clip-container.js +3 -1
- package/src/victory-container/victory-container.js +7 -1
- package/src/victory-label/victory-label.js +11 -7
- package/src/victory-util/add-events.js +2 -1
- package/src/victory-util/axis.js +3 -0
- package/src/victory-util/common-props.js +2 -2
- package/src/victory-util/line-helpers.js +1 -1
- package/src/victory-util/scale.js +18 -9
- package/src/victory-util/timer.js +1 -1
- package/src/victory-util/user-props.js +94 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
USER_PROPS_SAFELIST is to contain any string deemed safe for user props.
|
|
5
|
+
The startsWidth array will contain the start of any accepted user-prop that
|
|
6
|
+
starts with these characters.
|
|
7
|
+
The exactMatch will contain a list of exact prop names that are accepted.
|
|
8
|
+
*/
|
|
9
|
+
const USER_PROPS_SAFELIST = {
|
|
10
|
+
startsWith: ["data-", "aria-"],
|
|
11
|
+
exactMatch: []
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* doesPropStartWith: Function that takes a prop's key and runs it against all
|
|
16
|
+
* options in the USER_PROPS_SAFELIST and checks to see if it starts with any
|
|
17
|
+
* of those options.
|
|
18
|
+
* @param {string} key: prop key to be tested against whitelist
|
|
19
|
+
* @returns {Boolean}: returns true if the key starts with an option or false if
|
|
20
|
+
* otherwise
|
|
21
|
+
*/
|
|
22
|
+
const doesPropStartWith = (key) => {
|
|
23
|
+
let startsWith = false;
|
|
24
|
+
|
|
25
|
+
USER_PROPS_SAFELIST.startsWith.forEach((starterString) => {
|
|
26
|
+
const regex = new RegExp(`\\b(${starterString})(\\w|-)+`, "g");
|
|
27
|
+
if (regex.test(key)) startsWith = true;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return startsWith;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* isExactMatch: checks to see if the given key matches any of the 'exactMatch'
|
|
35
|
+
* items in the whitelist
|
|
36
|
+
* @param {String} key: prop key to be tested against the whitelist-exact match
|
|
37
|
+
* array.
|
|
38
|
+
* @returns {Boolean}: return true if whitelist contains that key, otherwise
|
|
39
|
+
* returns false.
|
|
40
|
+
*/
|
|
41
|
+
const isExactMatch = (key) => USER_PROPS_SAFELIST.exactMatch.includes(key);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* testIfSafeProp: tests prop's key against both startsWith and exactMatch values
|
|
45
|
+
* @param {String} key: prop key to be tested against the whitelist
|
|
46
|
+
* @returns {Boolean}: returns true if found in whitelist, otherwise returns false
|
|
47
|
+
*/
|
|
48
|
+
const testIfSafeProp = (key) => {
|
|
49
|
+
if (doesPropStartWith(key) || isExactMatch(key)) return true;
|
|
50
|
+
return false;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Gets the value from props if a function value is provided
|
|
55
|
+
* @param {any} value: maybe function value
|
|
56
|
+
* @param {Object} props: props object
|
|
57
|
+
* @returns {any} newValue
|
|
58
|
+
*/
|
|
59
|
+
const getValue = (value, props) => {
|
|
60
|
+
if (typeof value === "function") {
|
|
61
|
+
return value(props);
|
|
62
|
+
}
|
|
63
|
+
return value;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* getSafeUserProps - function that takes in a props object and removes any
|
|
68
|
+
* key-value entries that do not match filter strings in the USER_PROPS_SAFELIST
|
|
69
|
+
* object.
|
|
70
|
+
*
|
|
71
|
+
* @param {Object} props: props to be filtered against USER_PROPS_SAFELIST
|
|
72
|
+
* @returns {Object}: object containing remaining acceptable props
|
|
73
|
+
*/
|
|
74
|
+
export const getSafeUserProps = (props) => {
|
|
75
|
+
const propsToFilter = { ...props };
|
|
76
|
+
return Object.fromEntries(
|
|
77
|
+
Object.entries(propsToFilter)
|
|
78
|
+
.filter(([key]) => testIfSafeProp(key))
|
|
79
|
+
.map(([key, value]) => {
|
|
80
|
+
return [key, getValue(value, props)];
|
|
81
|
+
})
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Wraps a component and adds safe user props
|
|
87
|
+
*
|
|
88
|
+
* @param {ReactNode} component: parent component
|
|
89
|
+
* @param {Object} props: props to be filtered
|
|
90
|
+
* @returns {ReactNode} modified component
|
|
91
|
+
*/
|
|
92
|
+
export const withSafeUserProps = (component, props) => {
|
|
93
|
+
return React.cloneElement(component, getSafeUserProps(props));
|
|
94
|
+
};
|