organization-chart-react
Version:
A react component to display organization chart
687 lines (683 loc) • 23.7 kB
JavaScript
import je, { useState as sr, useCallback as ur, useEffect as lr } from "react";
var X = { exports: {} }, N = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var xe;
function cr() {
if (xe)
return N;
xe = 1;
var S = je, T = Symbol.for("react.element"), l = Symbol.for("react.fragment"), b = Object.prototype.hasOwnProperty, j = S.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, w = { key: !0, ref: !0, __self: !0, __source: !0 };
function y(E, o, h) {
var g, _ = {}, C = null, I = null;
h !== void 0 && (C = "" + h), o.key !== void 0 && (C = "" + o.key), o.ref !== void 0 && (I = o.ref);
for (g in o)
b.call(o, g) && !w.hasOwnProperty(g) && (_[g] = o[g]);
if (E && E.defaultProps)
for (g in o = E.defaultProps, o)
_[g] === void 0 && (_[g] = o[g]);
return { $$typeof: T, type: E, key: C, ref: I, props: _, _owner: j.current };
}
return N.Fragment = l, N.jsx = y, N.jsxs = y, N;
}
var $ = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Te;
function fr() {
return Te || (Te = 1, process.env.NODE_ENV !== "production" && function() {
var S = je, T = Symbol.for("react.element"), l = Symbol.for("react.portal"), b = Symbol.for("react.fragment"), j = Symbol.for("react.strict_mode"), w = Symbol.for("react.profiler"), y = Symbol.for("react.provider"), E = Symbol.for("react.context"), o = Symbol.for("react.forward_ref"), h = Symbol.for("react.suspense"), g = Symbol.for("react.suspense_list"), _ = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), I = Symbol.for("react.offscreen"), Z = Symbol.iterator, Ce = "@@iterator";
function Oe(e) {
if (e === null || typeof e != "object")
return null;
var r = Z && e[Z] || e[Ce];
return typeof r == "function" ? r : null;
}
var P = S.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function v(e) {
{
for (var r = arguments.length, t = new Array(r > 1 ? r - 1 : 0), n = 1; n < r; n++)
t[n - 1] = arguments[n];
Se("error", e, t);
}
}
function Se(e, r, t) {
{
var n = P.ReactDebugCurrentFrame, s = n.getStackAddendum();
s !== "" && (r += "%s", t = t.concat([s]));
var u = t.map(function(i) {
return String(i);
});
u.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, u);
}
}
var we = !1, Pe = !1, ke = !1, Ae = !1, Fe = !1, Q;
Q = Symbol.for("react.module.reference");
function De(e) {
return !!(typeof e == "string" || typeof e == "function" || e === b || e === w || Fe || e === j || e === h || e === g || Ae || e === I || we || Pe || ke || typeof e == "object" && e !== null && (e.$$typeof === C || e.$$typeof === _ || e.$$typeof === y || e.$$typeof === E || e.$$typeof === o || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === Q || e.getModuleId !== void 0));
}
function Ne(e, r, t) {
var n = e.displayName;
if (n)
return n;
var s = r.displayName || r.name || "";
return s !== "" ? t + "(" + s + ")" : t;
}
function ee(e) {
return e.displayName || "Context";
}
function R(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case b:
return "Fragment";
case l:
return "Portal";
case w:
return "Profiler";
case j:
return "StrictMode";
case h:
return "Suspense";
case g:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case E:
var r = e;
return ee(r) + ".Consumer";
case y:
var t = e;
return ee(t._context) + ".Provider";
case o:
return Ne(e, e.render, "ForwardRef");
case _:
var n = e.displayName || null;
return n !== null ? n : R(e.type) || "Memo";
case C: {
var s = e, u = s._payload, i = s._init;
try {
return R(i(u));
} catch {
return null;
}
}
}
return null;
}
var O = Object.assign, F = 0, re, te, ne, ae, ie, oe, se;
function ue() {
}
ue.__reactDisabledLog = !0;
function $e() {
{
if (F === 0) {
re = console.log, te = console.info, ne = console.warn, ae = console.error, ie = console.group, oe = console.groupCollapsed, se = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: ue,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
F++;
}
}
function Ie() {
{
if (F--, F === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: O({}, e, {
value: re
}),
info: O({}, e, {
value: te
}),
warn: O({}, e, {
value: ne
}),
error: O({}, e, {
value: ae
}),
group: O({}, e, {
value: ie
}),
groupCollapsed: O({}, e, {
value: oe
}),
groupEnd: O({}, e, {
value: se
})
});
}
F < 0 && v("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var U = P.ReactCurrentDispatcher, B;
function W(e, r, t) {
{
if (B === void 0)
try {
throw Error();
} catch (s) {
var n = s.stack.trim().match(/\n( *(at )?)/);
B = n && n[1] || "";
}
return `
` + B + e;
}
}
var q = !1, Y;
{
var We = typeof WeakMap == "function" ? WeakMap : Map;
Y = new We();
}
function le(e, r) {
if (!e || q)
return "";
{
var t = Y.get(e);
if (t !== void 0)
return t;
}
var n;
q = !0;
var s = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var u;
u = U.current, U.current = null, $e();
try {
if (r) {
var i = function() {
throw Error();
};
if (Object.defineProperty(i.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(i, []);
} catch (x) {
n = x;
}
Reflect.construct(e, [], i);
} else {
try {
i.call();
} catch (x) {
n = x;
}
e.call(i.prototype);
}
} else {
try {
throw Error();
} catch (x) {
n = x;
}
e();
}
} catch (x) {
if (x && n && typeof x.stack == "string") {
for (var a = x.stack.split(`
`), p = n.stack.split(`
`), c = a.length - 1, f = p.length - 1; c >= 1 && f >= 0 && a[c] !== p[f]; )
f--;
for (; c >= 1 && f >= 0; c--, f--)
if (a[c] !== p[f]) {
if (c !== 1 || f !== 1)
do
if (c--, f--, f < 0 || a[c] !== p[f]) {
var m = `
` + a[c].replace(" at new ", " at ");
return e.displayName && m.includes("<anonymous>") && (m = m.replace("<anonymous>", e.displayName)), typeof e == "function" && Y.set(e, m), m;
}
while (c >= 1 && f >= 0);
break;
}
}
} finally {
q = !1, U.current = u, Ie(), Error.prepareStackTrace = s;
}
var A = e ? e.displayName || e.name : "", Re = A ? W(A) : "";
return typeof e == "function" && Y.set(e, Re), Re;
}
function Ye(e, r, t) {
return le(e, !1);
}
function Le(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function L(e, r, t) {
if (e == null)
return "";
if (typeof e == "function")
return le(e, Le(e));
if (typeof e == "string")
return W(e);
switch (e) {
case h:
return W("Suspense");
case g:
return W("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case o:
return Ye(e.render);
case _:
return L(e.type, r, t);
case C: {
var n = e, s = n._payload, u = n._init;
try {
return L(u(s), r, t);
} catch {
}
}
}
return "";
}
var M = Object.prototype.hasOwnProperty, ce = {}, fe = P.ReactDebugCurrentFrame;
function V(e) {
if (e) {
var r = e._owner, t = L(e.type, e._source, r ? r.type : null);
fe.setExtraStackFrame(t);
} else
fe.setExtraStackFrame(null);
}
function Me(e, r, t, n, s) {
{
var u = Function.call.bind(M);
for (var i in e)
if (u(e, i)) {
var a = void 0;
try {
if (typeof e[i] != "function") {
var p = Error((n || "React class") + ": " + t + " type `" + i + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[i] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw p.name = "Invariant Violation", p;
}
a = e[i](r, i, n, t, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (c) {
a = c;
}
a && !(a instanceof Error) && (V(s), v("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", n || "React class", t, i, typeof a), V(null)), a instanceof Error && !(a.message in ce) && (ce[a.message] = !0, V(s), v("Failed %s type: %s", t, a.message), V(null));
}
}
}
var Ve = Array.isArray;
function z(e) {
return Ve(e);
}
function Ue(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, t = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return t;
}
}
function Be(e) {
try {
return de(e), !1;
} catch {
return !0;
}
}
function de(e) {
return "" + e;
}
function ve(e) {
if (Be(e))
return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Ue(e)), de(e);
}
var D = P.ReactCurrentOwner, qe = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, pe, he, J;
J = {};
function ze(e) {
if (M.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function Je(e) {
if (M.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function Ge(e, r) {
if (typeof e.ref == "string" && D.current && r && D.current.stateNode !== r) {
var t = R(D.current.type);
J[t] || (v('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', R(D.current.type), e.ref), J[t] = !0);
}
}
function Ke(e, r) {
{
var t = function() {
pe || (pe = !0, v("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "key", {
get: t,
configurable: !0
});
}
}
function He(e, r) {
{
var t = function() {
he || (he = !0, v("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
t.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: t,
configurable: !0
});
}
}
var Xe = function(e, r, t, n, s, u, i) {
var a = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: T,
// Built-in properties that belong on the element
type: e,
key: r,
ref: t,
props: i,
// Record the component responsible for creating this element.
_owner: u
};
return a._store = {}, Object.defineProperty(a._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(a, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: n
}), Object.defineProperty(a, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: s
}), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
};
function Ze(e, r, t, n, s) {
{
var u, i = {}, a = null, p = null;
t !== void 0 && (ve(t), a = "" + t), Je(r) && (ve(r.key), a = "" + r.key), ze(r) && (p = r.ref, Ge(r, s));
for (u in r)
M.call(r, u) && !qe.hasOwnProperty(u) && (i[u] = r[u]);
if (e && e.defaultProps) {
var c = e.defaultProps;
for (u in c)
i[u] === void 0 && (i[u] = c[u]);
}
if (a || p) {
var f = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
a && Ke(i, f), p && He(i, f);
}
return Xe(e, a, p, s, n, D.current, i);
}
}
var G = P.ReactCurrentOwner, ge = P.ReactDebugCurrentFrame;
function k(e) {
if (e) {
var r = e._owner, t = L(e.type, e._source, r ? r.type : null);
ge.setExtraStackFrame(t);
} else
ge.setExtraStackFrame(null);
}
var K;
K = !1;
function H(e) {
return typeof e == "object" && e !== null && e.$$typeof === T;
}
function me() {
{
if (G.current) {
var e = R(G.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function Qe(e) {
{
if (e !== void 0) {
var r = e.fileName.replace(/^.*[\\\/]/, ""), t = e.lineNumber;
return `
Check your code at ` + r + ":" + t + ".";
}
return "";
}
}
var ye = {};
function er(e) {
{
var r = me();
if (!r) {
var t = typeof e == "string" ? e : e.displayName || e.name;
t && (r = `
Check the top-level render call using <` + t + ">.");
}
return r;
}
}
function be(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var t = er(r);
if (ye[t])
return;
ye[t] = !0;
var n = "";
e && e._owner && e._owner !== G.current && (n = " It was passed a child from " + R(e._owner.type) + "."), k(e), v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', t, n), k(null);
}
}
function Ee(e, r) {
{
if (typeof e != "object")
return;
if (z(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
H(n) && be(n, r);
}
else if (H(e))
e._store && (e._store.validated = !0);
else if (e) {
var s = Oe(e);
if (typeof s == "function" && s !== e.entries)
for (var u = s.call(e), i; !(i = u.next()).done; )
H(i.value) && be(i.value, r);
}
}
}
function rr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var t;
if (typeof r == "function")
t = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === o || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === _))
t = r.propTypes;
else
return;
if (t) {
var n = R(r);
Me(t, e.props, "prop", n, e);
} else if (r.PropTypes !== void 0 && !K) {
K = !0;
var s = R(r);
v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", s || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function tr(e) {
{
for (var r = Object.keys(e.props), t = 0; t < r.length; t++) {
var n = r[t];
if (n !== "children" && n !== "key") {
k(e), v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", n), k(null);
break;
}
}
e.ref !== null && (k(e), v("Invalid attribute `ref` supplied to `React.Fragment`."), k(null));
}
}
function _e(e, r, t, n, s, u) {
{
var i = De(e);
if (!i) {
var a = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var p = Qe(s);
p ? a += p : a += me();
var c;
e === null ? c = "null" : z(e) ? c = "array" : e !== void 0 && e.$$typeof === T ? (c = "<" + (R(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : c = typeof e, v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", c, a);
}
var f = Ze(e, r, t, s, u);
if (f == null)
return f;
if (i) {
var m = r.children;
if (m !== void 0)
if (n)
if (z(m)) {
for (var A = 0; A < m.length; A++)
Ee(m[A], e);
Object.freeze && Object.freeze(m);
} else
v("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
Ee(m, e);
}
return e === b ? tr(f) : rr(f), f;
}
}
function nr(e, r, t) {
return _e(e, r, t, !0);
}
function ar(e, r, t) {
return _e(e, r, t, !1);
}
var ir = ar, or = nr;
$.Fragment = b, $.jsx = ir, $.jsxs = or;
}()), $;
}
process.env.NODE_ENV === "production" ? X.exports = cr() : X.exports = fr();
var d = X.exports;
function dr({ data: S, onClickNode: T }) {
const [l, b] = sr({}), j = ur((o) => {
o.extend = !0, Array.isArray(o.children) && o.children.forEach((h) => {
j(h);
}), b(o);
}, []), w = (o, h) => {
o.extend = h, b({ ...o });
}, y = () => Array.isArray(l.children) && l.children.length, E = () => Array.isArray(l.member) && l.member.length;
return lr(() => {
j(S);
}, [S, j]), /* @__PURE__ */ d.jsx(
"table",
{
className: "org-table",
style: { display: l.title ? "block" : "none" },
children: /* @__PURE__ */ d.jsxs("tbody", { children: [
/* @__PURE__ */ d.jsx("tr", { children: /* @__PURE__ */ d.jsxs(
"td",
{
colSpan: Array.isArray(l.children) ? l.children.length * 2 : 1,
className: `${y() || "org-parent-level"} ${y() && l.extend ? "org-extend" : ""}`,
children: [
/* @__PURE__ */ d.jsx("div", { className: "org-node", children: /* @__PURE__ */ d.jsxs(
"div",
{
className: "org-container",
onClick: () => T(l),
children: [
/* @__PURE__ */ d.jsx("div", { className: `org-title ${l.titleClass || ""}`, children: l.title }),
E() && /* @__PURE__ */ d.jsx("div", { className: `org-content ${l.contentClass || ""}`, children: l.member.map((o, h) => /* @__PURE__ */ d.jsxs("div", { className: "org-content-item", children: [
/* @__PURE__ */ d.jsxs("div", { className: "item-box", children: [
/* @__PURE__ */ d.jsx("p", { className: "item-title", children: o.name }),
/* @__PURE__ */ d.jsx("p", { className: "item-add", children: o.add })
] }),
o.image_url && /* @__PURE__ */ d.jsx("div", { className: "avat", children: o.image_url && /* @__PURE__ */ d.jsx("img", { src: o.image_url }) })
] }, h)) })
]
}
) }),
/* @__PURE__ */ d.jsx(
"div",
{
className: "org-extend-arrow",
style: { display: y() ? "block" : "none" },
onClick: () => w(l, !l.extend)
}
)
]
}
) }),
/* @__PURE__ */ d.jsx("tr", { children: y() && l.extend && l.children.map((o, h) => /* @__PURE__ */ d.jsx("td", { colSpan: 2, className: "org-child-level", children: /* @__PURE__ */ d.jsx(dr, { data: o, onClickNode: T }) }, h)) })
] })
}
);
}
export {
dr as default
};