source: node_modules/recharts/lib/util/ReactUtils.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 3.0 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.SCALE_TYPES = void 0;
7exports.findAllByType = findAllByType;
8exports.toArray = exports.isClipDot = exports.getDisplayName = void 0;
9var _get = _interopRequireDefault(require("es-toolkit/compat/get"));
10var _react = require("react");
11var _reactIs = require("react-is");
12var _DataUtils = require("./DataUtils");
13function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14var SCALE_TYPES = exports.SCALE_TYPES = ['auto', 'linear', 'pow', 'sqrt', 'log', 'identity', 'time', 'band', 'point', 'ordinal', 'quantile', 'quantize', 'utc', 'sequential', 'threshold'];
15
16/**
17 * @deprecated instead find another approach that does not depend on displayName.
18 * Get the display name of a component
19 * @param {Object} Comp Specified Component
20 * @return {String} Display name of Component
21 */
22var getDisplayName = Comp => {
23 if (typeof Comp === 'string') {
24 return Comp;
25 }
26 if (!Comp) {
27 return '';
28 }
29 return Comp.displayName || Comp.name || 'Component';
30};
31
32// `toArray` gets called multiple times during the render
33// so we can memoize last invocation (since reference to `children` is the same)
34exports.getDisplayName = getDisplayName;
35var lastChildren = null;
36var lastResult = null;
37
38/**
39 * @deprecated instead find another approach that does not require reading React Elements from DOM.
40 *
41 * @param children do not use
42 * @return deprecated do not use
43 */
44var toArray = children => {
45 if (children === lastChildren && Array.isArray(lastResult)) {
46 return lastResult;
47 }
48 var result = [];
49 _react.Children.forEach(children, child => {
50 if ((0, _DataUtils.isNullish)(child)) return;
51 if ((0, _reactIs.isFragment)(child)) {
52 result = result.concat(toArray(child.props.children));
53 } else {
54 // @ts-expect-error this could still be Iterable<ReactNode> and TS does not like that
55 result.push(child);
56 }
57 });
58 lastResult = result;
59 lastChildren = children;
60 return result;
61};
62
63/**
64 * @deprecated instead find another approach that does not require reading React Elements from DOM.
65 *
66 * Find and return all matched children by type.
67 * `type` must be a React.ComponentType
68 *
69 * @param children do not use
70 * @param type do not use
71 * @return deprecated do not use
72 */
73exports.toArray = toArray;
74function findAllByType(children, type) {
75 var result = [];
76 var types = [];
77 if (Array.isArray(type)) {
78 types = type.map(t => getDisplayName(t));
79 } else {
80 types = [getDisplayName(type)];
81 }
82 toArray(children).forEach(child => {
83 // @ts-expect-error toArray and lodash.get are not compatible. Let's get rid of the whole findAllByType function
84 var childType = (0, _get.default)(child, 'type.displayName') || (0, _get.default)(child, 'type.name');
85 if (childType && types.indexOf(childType) !== -1) {
86 result.push(child);
87 }
88 });
89 return result;
90}
91var isClipDot = dot => {
92 if (dot && typeof dot === 'object' && 'clipDot' in dot) {
93 return Boolean(dot.clipDot);
94 }
95 return true;
96};
97exports.isClipDot = isClipDot;
Note: See TracBrowser for help on using the repository browser.