victory-core 37.0.2 → 37.1.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/victory-core.js +395 -358
  3. package/dist/victory-core.min.js +1 -1
  4. package/es/index.d.ts +2 -1
  5. package/es/index.js +2 -1
  6. package/es/types/prop-types.d.ts +1 -0
  7. package/es/victory-container/victory-container.d.ts +29 -35
  8. package/es/victory-container/victory-container.js +134 -162
  9. package/es/victory-portal/portal-context.d.ts +9 -8
  10. package/es/victory-portal/portal-context.js +34 -6
  11. package/es/victory-portal/portal-outlet.d.ts +12 -0
  12. package/es/victory-portal/portal-outlet.js +14 -0
  13. package/es/victory-portal/portal.d.ts +1 -12
  14. package/es/victory-portal/portal.js +6 -32
  15. package/es/victory-portal/victory-portal.d.ts +5 -22
  16. package/es/victory-portal/victory-portal.js +37 -52
  17. package/es/victory-util/index.d.ts +1 -0
  18. package/es/victory-util/index.js +1 -0
  19. package/es/victory-util/merge-refs.d.ts +13 -0
  20. package/es/victory-util/merge-refs.js +23 -0
  21. package/lib/index.d.ts +2 -1
  22. package/lib/index.js +16 -4
  23. package/lib/types/prop-types.d.ts +1 -0
  24. package/lib/victory-container/victory-container.d.ts +29 -35
  25. package/lib/victory-container/victory-container.js +136 -163
  26. package/lib/victory-portal/portal-context.d.ts +9 -8
  27. package/lib/victory-portal/portal-context.js +37 -7
  28. package/lib/victory-portal/portal-outlet.d.ts +12 -0
  29. package/lib/victory-portal/portal-outlet.js +22 -0
  30. package/lib/victory-portal/portal.d.ts +1 -12
  31. package/lib/victory-portal/portal.js +6 -33
  32. package/lib/victory-portal/victory-portal.d.ts +5 -22
  33. package/lib/victory-portal/victory-portal.js +37 -52
  34. package/lib/victory-util/index.d.ts +1 -0
  35. package/lib/victory-util/index.js +12 -0
  36. package/lib/victory-util/merge-refs.d.ts +13 -0
  37. package/lib/victory-util/merge-refs.js +31 -0
  38. package/package.json +2 -2
  39. package/src/index.ts +2 -1
  40. package/src/types/prop-types.ts +7 -0
  41. package/src/victory-container/victory-container.tsx +167 -195
  42. package/src/victory-portal/portal-context.tsx +63 -0
  43. package/src/victory-portal/portal-outlet.tsx +26 -0
  44. package/src/victory-portal/portal.tsx +5 -42
  45. package/src/victory-portal/victory-portal.tsx +44 -73
  46. package/src/victory-util/index.ts +1 -0
  47. package/src/victory-util/merge-refs.ts +26 -0
  48. package/src/victory-portal/portal-context.ts +0 -14
@@ -3,12 +3,42 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.PortalContext = void 0;
6
+ exports.usePortalContext = exports.PortalProvider = exports.PortalContext = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * The React context object consumers may use to access the context of the
11
- * portal.
12
- */
13
- const PortalContext = exports.PortalContext = /*#__PURE__*/_react.default.createContext({});
14
- PortalContext.displayName = "PortalContext";
9
+ const PortalContext = exports.PortalContext = /*#__PURE__*/_react.default.createContext(undefined);
10
+ PortalContext.displayName = "PortalContext";
11
+ const usePortalContext = () => {
12
+ const context = _react.default.useContext(PortalContext);
13
+ return context;
14
+ };
15
+ exports.usePortalContext = usePortalContext;
16
+ const PortalProvider = _ref => {
17
+ let {
18
+ children
19
+ } = _ref;
20
+ const [portalChildren, setPortalChildren] = _react.default.useState(new Map());
21
+ const addChild = _react.default.useCallback((id, element) => {
22
+ setPortalChildren(prevChildren => {
23
+ const nextChildren = new Map(prevChildren);
24
+ nextChildren.set(id, element);
25
+ return nextChildren;
26
+ });
27
+ }, [setPortalChildren]);
28
+ const removeChild = _react.default.useCallback(id => {
29
+ setPortalChildren(prevChildren => {
30
+ const nextChildren = new Map(prevChildren);
31
+ nextChildren.delete(id);
32
+ return nextChildren;
33
+ });
34
+ }, [setPortalChildren]);
35
+ const contextValue = _react.default.useMemo(() => ({
36
+ addChild,
37
+ removeChild,
38
+ children: portalChildren
39
+ }), [addChild, removeChild, portalChildren]);
40
+ return /*#__PURE__*/_react.default.createElement(PortalContext.Provider, {
41
+ value: contextValue
42
+ }, children);
43
+ };
44
+ exports.PortalProvider = PortalProvider;
@@ -0,0 +1,12 @@
1
+ import React from "react";
2
+ export interface PortalOutletProps {
3
+ as: React.ReactElement;
4
+ width?: number;
5
+ height?: number;
6
+ viewBox?: string;
7
+ preserveAspectRatio?: string;
8
+ style?: React.CSSProperties;
9
+ children?: (children: React.ReactElement[]) => React.ReactNode | undefined;
10
+ }
11
+ export declare const PortalOutlet: ({ as: portalComponent, ...props }: PortalOutletProps) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
12
+ //# sourceMappingURL=portal-outlet.d.ts.map
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PortalOutlet = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _portalContext = require("./portal-context");
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const PortalOutlet = _ref => {
11
+ let {
12
+ as: portalComponent,
13
+ ...props
14
+ } = _ref;
15
+ const portalContext = (0, _portalContext.usePortalContext)();
16
+ if (!portalContext) {
17
+ return null;
18
+ }
19
+ const children = Array.from(portalContext.children.values());
20
+ return /*#__PURE__*/_react.default.cloneElement(portalComponent, props, children);
21
+ };
22
+ exports.PortalOutlet = PortalOutlet;
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import { PortalContextValue } from "./portal-context";
3
2
  export interface PortalProps {
4
3
  className?: string;
5
4
  height?: number;
@@ -7,15 +6,5 @@ export interface PortalProps {
7
6
  viewBox?: string;
8
7
  width?: number;
9
8
  }
10
- export declare class Portal extends React.Component<PortalProps> implements PortalContextValue {
11
- static displayName: string;
12
- private readonly map;
13
- private index;
14
- constructor(props: PortalProps);
15
- portalRegister: () => number;
16
- portalUpdate: (key: number, element: React.ReactElement) => void;
17
- portalDeregister: (key: number) => void;
18
- getChildren(): React.ReactElement<any, string | React.JSXElementConstructor<any>>[];
19
- render(): JSX.Element;
20
- }
9
+ export declare const Portal: React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<SVGSVGElement>>;
21
10
  //# sourceMappingURL=portal.d.ts.map
@@ -6,36 +6,9 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.Portal = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- class Portal extends _react.default.Component {
10
- static displayName = "Portal";
11
- constructor(props) {
12
- super(props);
13
- this.map = {};
14
- this.index = 1;
15
- }
16
- portalRegister = () => {
17
- return ++this.index;
18
- };
19
- portalUpdate = (key, element) => {
20
- this.map[key] = element;
21
- this.forceUpdate();
22
- };
23
- portalDeregister = key => {
24
- delete this.map[key];
25
- this.forceUpdate();
26
- };
27
- getChildren() {
28
- return Object.keys(this.map).map(key => {
29
- const el = this.map[key];
30
- return el ? /*#__PURE__*/_react.default.cloneElement(el, {
31
- key
32
- }) : el;
33
- });
34
- }
35
-
36
- // Overridden in victory-core-native
37
- render() {
38
- return /*#__PURE__*/_react.default.createElement("svg", this.props, this.getChildren());
39
- }
40
- }
41
- exports.Portal = Portal;
9
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
10
+ const Portal = exports.Portal = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
11
+ return /*#__PURE__*/_react.default.createElement("svg", _extends({
12
+ ref: ref
13
+ }, props));
14
+ });
@@ -1,27 +1,10 @@
1
1
  import React from "react";
2
- import { PortalContext } from "./portal-context";
3
2
  export interface VictoryPortalProps {
4
- children?: React.ReactElement;
3
+ children: React.ReactElement;
5
4
  groupComponent?: React.ReactElement;
6
5
  }
7
- export interface VictoryPortal {
8
- context: React.ContextType<typeof PortalContext>;
9
- }
10
- export declare class VictoryPortal extends React.Component<VictoryPortalProps> {
11
- static displayName: string;
12
- static role: string;
13
- static defaultProps: {
14
- groupComponent: JSX.Element;
15
- };
16
- static contextType: React.Context<import("./portal-context").PortalContextValue>;
17
- private checkedContext;
18
- private portalKey;
19
- renderInPlace: boolean;
20
- element: React.ReactElement;
21
- componentDidMount(): void;
22
- componentDidUpdate(): void;
23
- componentWillUnmount(): void;
24
- renderPortal(child: React.ReactElement): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
25
- render(): React.ReactElement<any, string | React.JSXElementConstructor<any>> | null;
26
- }
6
+ export declare const VictoryPortal: {
7
+ (initialProps: VictoryPortalProps): any;
8
+ role: string;
9
+ };
27
10
  //# sourceMappingURL=victory-portal.d.ts.map
@@ -12,57 +12,42 @@ var _portalContext = require("./portal-context");
12
12
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
13
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- class VictoryPortal extends _react.default.Component {
16
- static displayName = "VictoryPortal";
17
- static role = "portal";
18
- static defaultProps = {
19
- groupComponent: /*#__PURE__*/_react.default.createElement("g", null)
15
+ const defaultProps = {
16
+ groupComponent: /*#__PURE__*/_react.default.createElement("g", null)
17
+ };
18
+ const VictoryPortal = initialProps => {
19
+ const props = {
20
+ ...defaultProps,
21
+ ...initialProps
20
22
  };
21
- static contextType = _portalContext.PortalContext;
22
- componentDidMount() {
23
- if (!this.checkedContext) {
24
- if (typeof this.context.portalUpdate !== "function") {
25
- const msg = "`renderInPortal` is not supported outside of `VictoryContainer`. " + "Component will be rendered in place";
26
- Log.warn(msg);
27
- this.renderInPlace = true;
28
- }
29
- this.checkedContext = true;
30
- }
31
- this.forceUpdate();
23
+ const id = _react.default.useId();
24
+ const portalContext = (0, _portalContext.usePortalContext)();
25
+ if (!portalContext) {
26
+ const msg = "`renderInPortal` is not supported outside of `VictoryContainer`. " + "Component will be rendered in place";
27
+ Log.warn(msg);
32
28
  }
33
- componentDidUpdate() {
34
- if (!this.renderInPlace) {
35
- this.portalKey = this.portalKey || this.context.portalRegister();
36
- this.context.portalUpdate(this.portalKey, this.element);
37
- }
38
- }
39
- componentWillUnmount() {
40
- if (this.context && this.context.portalDeregister) {
41
- this.context.portalDeregister(this.portalKey);
42
- }
43
- }
44
-
45
- // Overridden in victory-core-native
46
- renderPortal(child) {
47
- if (this.renderInPlace) {
48
- return child;
49
- }
50
- this.element = child;
51
- return null;
52
- }
53
- render() {
54
- const children = Array.isArray(this.props.children) ? this.props.children[0] : this.props.children;
55
- const {
56
- groupComponent
57
- } = this.props;
58
- const childProps = children && children.props || {};
59
- const standardProps = childProps.groupComponent ? {
60
- groupComponent,
61
- standalone: false
62
- } : {};
63
- const newProps = (0, _defaults2.default)(standardProps, childProps, Helpers.omit(this.props, ["children", "groupComponent"]));
64
- const child = children && /*#__PURE__*/_react.default.cloneElement(children, newProps);
65
- return this.renderPortal(child);
66
- }
67
- }
68
- exports.VictoryPortal = VictoryPortal;
29
+ const children = Array.isArray(props.children) ? props.children[0] : props.children;
30
+ const {
31
+ groupComponent
32
+ } = props;
33
+ const childProps = children && children.props || {};
34
+ const standardProps = childProps.groupComponent ? {
35
+ groupComponent,
36
+ standalone: false
37
+ } : {};
38
+ const newProps = (0, _defaults2.default)(standardProps, childProps, Helpers.omit(props, ["children", "groupComponent"]), {
39
+ key: childProps.key ?? id
40
+ });
41
+ const child = children && /*#__PURE__*/_react.default.cloneElement(children, newProps);
42
+ _react.default.useEffect(() => {
43
+ portalContext?.addChild(id, child);
44
+ // eslint-disable-next-line react-hooks/exhaustive-deps
45
+ }, [props.children]);
46
+ _react.default.useEffect(() => {
47
+ return () => portalContext?.removeChild(id);
48
+ // eslint-disable-next-line react-hooks/exhaustive-deps
49
+ }, []);
50
+ return portalContext ? null : child;
51
+ };
52
+ exports.VictoryPortal = VictoryPortal;
53
+ VictoryPortal.role = "portal";
@@ -1,4 +1,5 @@
1
1
  export * from "./add-events";
2
+ export * from "./merge-refs";
2
3
  export * as Axis from "./axis";
3
4
  export * as Collection from "./collection";
4
5
  export * from "./common-props";
@@ -53,6 +53,18 @@ Object.keys(_addEvents).forEach(function (key) {
53
53
  }
54
54
  });
55
55
  });
56
+ var _mergeRefs = require("./merge-refs");
57
+ Object.keys(_mergeRefs).forEach(function (key) {
58
+ if (key === "default" || key === "__esModule") return;
59
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
60
+ if (key in exports && exports[key] === _mergeRefs[key]) return;
61
+ Object.defineProperty(exports, key, {
62
+ enumerable: true,
63
+ get: function () {
64
+ return _mergeRefs[key];
65
+ }
66
+ });
67
+ });
56
68
  var _Axis = _interopRequireWildcard(require("./axis"));
57
69
  exports.Axis = _Axis;
58
70
  var _Collection = _interopRequireWildcard(require("./collection"));
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ declare type Ref<T> = React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null;
3
+ /**
4
+ * Used to merge multiple React refs into a single callback ref.
5
+ *
6
+ * @example
7
+ * ```tsx
8
+ * <div ref={mergeRefs([ref, forwardedRef])} />
9
+ * ```
10
+ */
11
+ export declare function mergeRefs<T>(refs: Ref<T>[]): React.RefCallback<T>;
12
+ export {};
13
+ //# sourceMappingURL=merge-refs.d.ts.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.mergeRefs = mergeRefs;
7
+ var Helpers = _interopRequireWildcard(require("./helpers"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ /**
11
+ * Used to merge multiple React refs into a single callback ref.
12
+ *
13
+ * @example
14
+ * ```tsx
15
+ * <div ref={mergeRefs([ref, forwardedRef])} />
16
+ * ```
17
+ */
18
+ function mergeRefs(refs) {
19
+ return value => {
20
+ refs.forEach(ref => {
21
+ // If the ref is a function, it's a callback ref and we call it with the value.
22
+ if (Helpers.isFunction(ref)) {
23
+ ref(value);
24
+ } else if (ref !== null && ref !== undefined) {
25
+ // If the ref is an object (not null and not undefined), it's an object ref.
26
+ // We assign the value to its 'current' property.
27
+ ref.current = value;
28
+ }
29
+ });
30
+ };
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "victory-core",
3
- "version": "37.0.2",
3
+ "version": "37.1.0",
4
4
  "description": "Victory Core",
5
5
  "keywords": [
6
6
  "data visualization",
@@ -22,7 +22,7 @@
22
22
  "dependencies": {
23
23
  "lodash": "^4.17.21",
24
24
  "react-fast-compare": "^3.2.0",
25
- "victory-vendor": "^37.0.2"
25
+ "victory-vendor": "37.1.0"
26
26
  },
27
27
  "peerDependencies": {
28
28
  "react": ">=16.6.0"
package/src/index.ts CHANGED
@@ -9,8 +9,9 @@ export * from "./victory-clip-container/victory-clip-container";
9
9
  export * from "./victory-theme/types";
10
10
  export * from "./victory-theme/victory-theme";
11
11
  export * from "./victory-portal/portal";
12
- export * from "./victory-portal/portal-context";
13
12
  export * from "./victory-portal/victory-portal";
13
+ export * from "./victory-portal/portal-context";
14
+ export * from "./victory-portal/portal-outlet";
14
15
  export * from "./victory-primitives";
15
16
  export { Border as Box } from "./victory-primitives";
16
17
  export type { BorderProps as BoxProps } from "./victory-primitives";
@@ -194,3 +194,10 @@ export type CoordinatesPropType = {
194
194
  x: number;
195
195
  y: number;
196
196
  };
197
+
198
+ export type VictoryEventHandler = (
199
+ event?: any,
200
+ targetProps?: any,
201
+ eventKey?: any,
202
+ context?: any,
203
+ ) => void;