UNPKG

organization-chart-react

Version:
28 lines (24 loc) 15.3 kB
(function(y,O){typeof exports=="object"&&typeof module<"u"?module.exports=O(require("react")):typeof define=="function"&&define.amd?define(["react"],O):(y=typeof globalThis<"u"?globalThis:y||self,y.OrganizationChart=O(y.React))})(this,function(y){"use strict";var O={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 Q;function Oe(){if(Q)return N;Q=1;var P=y,j=Symbol.for("react.element"),l=Symbol.for("react.fragment"),E=Object.prototype.hasOwnProperty,C=P.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,k={key:!0,ref:!0,__self:!0,__source:!0};function b(_,o,h){var g,R={},S=null,$=null;h!==void 0&&(S=""+h),o.key!==void 0&&(S=""+o.key),o.ref!==void 0&&($=o.ref);for(g in o)E.call(o,g)&&!k.hasOwnProperty(g)&&(R[g]=o[g]);if(_&&_.defaultProps)for(g in o=_.defaultProps,o)R[g]===void 0&&(R[g]=o[g]);return{$$typeof:j,type:_,key:S,ref:$,props:R,_owner:C.current}}return N.Fragment=l,N.jsx=b,N.jsxs=b,N}var I={};/** * @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 ee;function Se(){return ee||(ee=1,process.env.NODE_ENV!=="production"&&function(){var P=y,j=Symbol.for("react.element"),l=Symbol.for("react.portal"),E=Symbol.for("react.fragment"),C=Symbol.for("react.strict_mode"),k=Symbol.for("react.profiler"),b=Symbol.for("react.provider"),_=Symbol.for("react.context"),o=Symbol.for("react.forward_ref"),h=Symbol.for("react.suspense"),g=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),S=Symbol.for("react.lazy"),$=Symbol.for("react.offscreen"),te=Symbol.iterator,we="@@iterator";function Pe(e){if(e===null||typeof e!="object")return null;var r=te&&e[te]||e[we];return typeof r=="function"?r:null}var A=P.__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];ke("error",e,t)}}function ke(e,r,t){{var n=A.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 Ae=!1,Fe=!1,De=!1,Ne=!1,Ie=!1,ne;ne=Symbol.for("react.module.reference");function We(e){return!!(typeof e=="string"||typeof e=="function"||e===E||e===k||Ie||e===C||e===h||e===g||Ne||e===$||Ae||Fe||De||typeof e=="object"&&e!==null&&(e.$$typeof===S||e.$$typeof===R||e.$$typeof===b||e.$$typeof===_||e.$$typeof===o||e.$$typeof===ne||e.getModuleId!==void 0))}function Ye(e,r,t){var n=e.displayName;if(n)return n;var s=r.displayName||r.name||"";return s!==""?t+"("+s+")":t}function ae(e){return e.displayName||"Context"}function x(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 E:return"Fragment";case l:return"Portal";case k:return"Profiler";case C:return"StrictMode";case h:return"Suspense";case g:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case _:var r=e;return ae(r)+".Consumer";case b:var t=e;return ae(t._context)+".Provider";case o:return Ye(e,e.render,"ForwardRef");case R:var n=e.displayName||null;return n!==null?n:x(e.type)||"Memo";case S:{var s=e,u=s._payload,i=s._init;try{return x(i(u))}catch{return null}}}return null}var w=Object.assign,W=0,ie,oe,se,ue,le,ce,fe;function de(){}de.__reactDisabledLog=!0;function $e(){{if(W===0){ie=console.log,oe=console.info,se=console.warn,ue=console.error,le=console.group,ce=console.groupCollapsed,fe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:de,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}W++}}function Le(){{if(W--,W===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:w({},e,{value:ie}),info:w({},e,{value:oe}),warn:w({},e,{value:se}),error:w({},e,{value:ue}),group:w({},e,{value:le}),groupCollapsed:w({},e,{value:ce}),groupEnd:w({},e,{value:fe})})}W<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var z=A.ReactCurrentDispatcher,J;function L(e,r,t){{if(J===void 0)try{throw Error()}catch(s){var n=s.stack.trim().match(/\n( *(at )?)/);J=n&&n[1]||""}return` `+J+e}}var G=!1,M;{var Me=typeof WeakMap=="function"?WeakMap:Map;M=new Me}function ve(e,r){if(!e||G)return"";{var t=M.get(e);if(t!==void 0)return t}var n;G=!0;var s=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var u;u=z.current,z.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(T){n=T}Reflect.construct(e,[],i)}else{try{i.call()}catch(T){n=T}e.call(i.prototype)}}else{try{throw Error()}catch(T){n=T}e()}}catch(T){if(T&&n&&typeof T.stack=="string"){for(var a=T.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"&&M.set(e,m),m}while(c>=1&&f>=0);break}}}finally{G=!1,z.current=u,Le(),Error.prepareStackTrace=s}var D=e?e.displayName||e.name:"",Ce=D?L(D):"";return typeof e=="function"&&M.set(e,Ce),Ce}function Ve(e,r,t){return ve(e,!1)}function Ue(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function V(e,r,t){if(e==null)return"";if(typeof e=="function")return ve(e,Ue(e));if(typeof e=="string")return L(e);switch(e){case h:return L("Suspense");case g:return L("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case o:return Ve(e.render);case R:return V(e.type,r,t);case S:{var n=e,s=n._payload,u=n._init;try{return V(u(s),r,t)}catch{}}}return""}var U=Object.prototype.hasOwnProperty,pe={},he=A.ReactDebugCurrentFrame;function B(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);he.setExtraStackFrame(t)}else he.setExtraStackFrame(null)}function Be(e,r,t,n,s){{var u=Function.call.bind(U);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)&&(B(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),B(null)),a instanceof Error&&!(a.message in pe)&&(pe[a.message]=!0,B(s),v("Failed %s type: %s",t,a.message),B(null))}}}var ze=Array.isArray;function q(e){return ze(e)}function Je(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function Ge(e){try{return ge(e),!1}catch{return!0}}function ge(e){return""+e}function me(e){if(Ge(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Je(e)),ge(e)}var Y=A.ReactCurrentOwner,qe={key:!0,ref:!0,__self:!0,__source:!0},ye,be,K;K={};function Ke(e){if(U.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function He(e){if(U.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function Xe(e,r){if(typeof e.ref=="string"&&Y.current&&r&&Y.current.stateNode!==r){var t=x(Y.current.type);K[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',x(Y.current.type),e.ref),K[t]=!0)}}function Ze(e,r){{var t=function(){ye||(ye=!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 Qe(e,r){{var t=function(){be||(be=!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 er=function(e,r,t,n,s,u,i){var a={$$typeof:j,type:e,key:r,ref:t,props:i,_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 rr(e,r,t,n,s){{var u,i={},a=null,p=null;t!==void 0&&(me(t),a=""+t),He(r)&&(me(r.key),a=""+r.key),Ke(r)&&(p=r.ref,Xe(r,s));for(u in r)U.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&&Ze(i,f),p&&Qe(i,f)}return er(e,a,p,s,n,Y.current,i)}}var H=A.ReactCurrentOwner,Ee=A.ReactDebugCurrentFrame;function F(e){if(e){var r=e._owner,t=V(e.type,e._source,r?r.type:null);Ee.setExtraStackFrame(t)}else Ee.setExtraStackFrame(null)}var X;X=!1;function Z(e){return typeof e=="object"&&e!==null&&e.$$typeof===j}function _e(){{if(H.current){var e=x(H.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function tr(e){{if(e!==void 0){var r=e.fileName.replace(/^.*[\\\/]/,""),t=e.lineNumber;return` Check your code at `+r+":"+t+"."}return""}}var Re={};function nr(e){{var r=_e();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 xe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=nr(r);if(Re[t])return;Re[t]=!0;var n="";e&&e._owner&&e._owner!==H.current&&(n=" It was passed a child from "+x(e._owner.type)+"."),F(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),F(null)}}function Te(e,r){{if(typeof e!="object")return;if(q(e))for(var t=0;t<e.length;t++){var n=e[t];Z(n)&&xe(n,r)}else if(Z(e))e._store&&(e._store.validated=!0);else if(e){var s=Pe(e);if(typeof s=="function"&&s!==e.entries)for(var u=s.call(e),i;!(i=u.next()).done;)Z(i.value)&&xe(i.value,r)}}}function ar(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||r.$$typeof===R))t=r.propTypes;else return;if(t){var n=x(r);Be(t,e.props,"prop",n,e)}else if(r.PropTypes!==void 0&&!X){X=!0;var s=x(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 ir(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var n=r[t];if(n!=="children"&&n!=="key"){F(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",n),F(null);break}}e.ref!==null&&(F(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),F(null))}}function je(e,r,t,n,s,u){{var i=We(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=tr(s);p?a+=p:a+=_e();var c;e===null?c="null":q(e)?c="array":e!==void 0&&e.$$typeof===j?(c="<"+(x(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=rr(e,r,t,s,u);if(f==null)return f;if(i){var m=r.children;if(m!==void 0)if(n)if(q(m)){for(var D=0;D<m.length;D++)Te(m[D],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 Te(m,e)}return e===E?ir(f):ar(f),f}}function or(e,r,t){return je(e,r,t,!0)}function sr(e,r,t){return je(e,r,t,!1)}var ur=sr,lr=or;I.Fragment=E,I.jsx=ur,I.jsxs=lr}()),I}process.env.NODE_ENV==="production"?O.exports=Oe():O.exports=Se();var d=O.exports;const cr="";function re({data:P,onClickNode:j}){const[l,E]=y.useState({}),C=y.useCallback(o=>{o.extend=!0,Array.isArray(o.children)&&o.children.forEach(h=>{C(h)}),E(o)},[]),k=(o,h)=>{o.extend=h,E({...o})},b=()=>Array.isArray(l.children)&&l.children.length,_=()=>Array.isArray(l.member)&&l.member.length;return y.useEffect(()=>{C(P)},[P,C]),d.jsx("table",{className:"org-table",style:{display:l.title?"block":"none"},children:d.jsxs("tbody",{children:[d.jsx("tr",{children:d.jsxs("td",{colSpan:Array.isArray(l.children)?l.children.length*2:1,className:`${b()||"org-parent-level"} ${b()&&l.extend?"org-extend":""}`,children:[d.jsx("div",{className:"org-node",children:d.jsxs("div",{className:"org-container",onClick:()=>j(l),children:[d.jsx("div",{className:`org-title ${l.titleClass||""}`,children:l.title}),_()&&d.jsx("div",{className:`org-content ${l.contentClass||""}`,children:l.member.map((o,h)=>d.jsxs("div",{className:"org-content-item",children:[d.jsxs("div",{className:"item-box",children:[d.jsx("p",{className:"item-title",children:o.name}),d.jsx("p",{className:"item-add",children:o.add})]}),o.image_url&&d.jsx("div",{className:"avat",children:o.image_url&&d.jsx("img",{src:o.image_url})})]},h))})]})}),d.jsx("div",{className:"org-extend-arrow",style:{display:b()?"block":"none"},onClick:()=>k(l,!l.extend)})]})}),d.jsx("tr",{children:b()&&l.extend&&l.children.map((o,h)=>d.jsx("td",{colSpan:2,className:"org-child-level",children:d.jsx(re,{data:o,onClickNode:j})},h))})]})})}return re});