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.
Files changed (102) hide show
  1. package/dist/victory-core.js +14792 -14613
  2. package/dist/victory-core.min.js +1 -1
  3. package/es/index.js +2 -0
  4. package/es/victory-accessible-group/victory-accessible-group.js +38 -40
  5. package/es/victory-animation/util.js +1 -1
  6. package/es/victory-animation/victory-animation.js +46 -48
  7. package/es/victory-clip-container/victory-clip-container.js +74 -75
  8. package/es/victory-container/victory-container.js +86 -94
  9. package/es/victory-label/victory-label.js +32 -25
  10. package/es/victory-portal/portal-context.js +1 -1
  11. package/es/victory-portal/portal.js +28 -26
  12. package/es/victory-portal/victory-portal.js +31 -41
  13. package/es/victory-primitives/arc.js +6 -4
  14. package/es/victory-primitives/background.js +8 -6
  15. package/es/victory-primitives/border.js +6 -4
  16. package/es/victory-primitives/circle.js +8 -4
  17. package/es/victory-primitives/clip-path.js +1 -1
  18. package/es/victory-primitives/line-segment.js +6 -4
  19. package/es/victory-primitives/line.js +8 -4
  20. package/es/victory-primitives/path.js +7 -3
  21. package/es/victory-primitives/point.js +6 -4
  22. package/es/victory-primitives/rect.js +8 -4
  23. package/es/victory-primitives/text.js +7 -3
  24. package/es/victory-primitives/tspan.js +1 -1
  25. package/es/victory-primitives/whisker.js +9 -7
  26. package/es/victory-transition/victory-transition.js +30 -32
  27. package/es/victory-util/add-events.js +324 -315
  28. package/es/victory-util/axis.js +12 -5
  29. package/es/victory-util/collection.js +8 -4
  30. package/es/victory-util/common-props.js +2 -2
  31. package/es/victory-util/data.js +9 -5
  32. package/es/victory-util/domain.js +8 -4
  33. package/es/victory-util/events.js +8 -4
  34. package/es/victory-util/helpers.js +1 -1
  35. package/es/victory-util/hooks/use-animation-state.js +11 -5
  36. package/es/victory-util/line-helpers.js +1 -1
  37. package/es/victory-util/scale.js +19 -19
  38. package/es/victory-util/textsize.js +11 -7
  39. package/es/victory-util/timer-context.js +1 -1
  40. package/es/victory-util/timer.js +3 -5
  41. package/es/victory-util/user-props.js +123 -0
  42. package/es/victory-util/wrapper.js +18 -12
  43. package/lib/index.js +72 -58
  44. package/lib/victory-accessible-group/victory-accessible-group.js +38 -40
  45. package/lib/victory-animation/util.js +2 -2
  46. package/lib/victory-animation/victory-animation.js +49 -49
  47. package/lib/victory-clip-container/victory-clip-container.js +78 -76
  48. package/lib/victory-container/victory-container.js +90 -95
  49. package/lib/victory-label/victory-label.js +38 -27
  50. package/lib/victory-portal/portal-context.js +1 -1
  51. package/lib/victory-portal/portal.js +31 -27
  52. package/lib/victory-portal/victory-portal.js +34 -42
  53. package/lib/victory-primitives/arc.js +9 -5
  54. package/lib/victory-primitives/background.js +11 -7
  55. package/lib/victory-primitives/border.js +9 -5
  56. package/lib/victory-primitives/circle.js +8 -4
  57. package/lib/victory-primitives/clip-path.js +1 -1
  58. package/lib/victory-primitives/line-segment.js +9 -5
  59. package/lib/victory-primitives/line.js +8 -4
  60. package/lib/victory-primitives/path.js +7 -3
  61. package/lib/victory-primitives/point.js +9 -5
  62. package/lib/victory-primitives/rect.js +8 -4
  63. package/lib/victory-primitives/text.js +7 -3
  64. package/lib/victory-primitives/tspan.js +1 -1
  65. package/lib/victory-primitives/whisker.js +12 -8
  66. package/lib/victory-transition/victory-transition.js +33 -33
  67. package/lib/victory-util/add-events.js +322 -311
  68. package/lib/victory-util/axis.js +20 -11
  69. package/lib/victory-util/collection.js +11 -7
  70. package/lib/victory-util/common-props.js +6 -4
  71. package/lib/victory-util/data.js +13 -7
  72. package/lib/victory-util/default-transitions.js +1 -1
  73. package/lib/victory-util/domain.js +11 -5
  74. package/lib/victory-util/events.js +17 -11
  75. package/lib/victory-util/helpers.js +14 -14
  76. package/lib/victory-util/hooks/index.js +4 -4
  77. package/lib/victory-util/hooks/use-animation-state.js +14 -6
  78. package/lib/victory-util/immutable.js +3 -3
  79. package/lib/victory-util/label-helpers.js +6 -4
  80. package/lib/victory-util/line-helpers.js +4 -2
  81. package/lib/victory-util/prop-types.js +5 -3
  82. package/lib/victory-util/scale.js +24 -21
  83. package/lib/victory-util/selection.js +6 -4
  84. package/lib/victory-util/textsize.js +12 -8
  85. package/lib/victory-util/timer-context.js +1 -1
  86. package/lib/victory-util/timer.js +3 -5
  87. package/lib/victory-util/user-props.js +139 -0
  88. package/lib/victory-util/wrapper.js +31 -23
  89. package/package.json +5 -12
  90. package/src/index.js +1 -0
  91. package/src/victory-animation/util.js +1 -1
  92. package/src/victory-animation/victory-animation.js +1 -1
  93. package/src/victory-clip-container/victory-clip-container.js +3 -1
  94. package/src/victory-container/victory-container.js +7 -1
  95. package/src/victory-label/victory-label.js +11 -7
  96. package/src/victory-util/add-events.js +2 -1
  97. package/src/victory-util/axis.js +3 -0
  98. package/src/victory-util/common-props.js +2 -2
  99. package/src/victory-util/line-helpers.js +1 -1
  100. package/src/victory-util/scale.js +18 -9
  101. package/src/victory-util/timer.js +1 -1
  102. 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
+ };