UNPKG

react-contributors

Version:

A lightweight React component for displaying GitHub repository contributors

33 lines (30 loc) 14.1 kB
(function(){"use strict";try{if(typeof document<"u"){var t=document.createElement("style");t.appendChild(document.createTextNode(".react-contributors-container{width:100%;margin:0 auto;padding:2rem 1rem}.react-contributors-list{display:flex;flex-wrap:wrap}.react-contributors-profile{display:flex;width:25%;padding:1rem;text-decoration:none;color:inherit}.react-contributors-profile-inner{display:flex;flex-direction:column;align-items:center}.react-contributors-avatar{width:4rem;height:4rem;border-radius:9999px;overflow:hidden;margin-bottom:.5rem}.react-contributors-info{text-align:center}.react-contributors-name{margin:0;color:#2d767f;font-weight:500}.react-contributors-contributions{margin-top:.25rem;display:block;color:#3b9a9c;font-size:.875rem}.react-contributors-message{width:100%;text-align:center;padding:2rem 0}@media (max-width: 768px){.react-contributors-profile{width:33.333%}}@media (max-width: 640px){.react-contributors-profile{width:50%}}@media (max-width: 480px){.react-contributors-profile{width:100%}}")),document.head.appendChild(t)}}catch(e){console.error("vite-plugin-css-injected-by-js",e)}})(); (function(m,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("react"),require("@octokit/rest")):typeof define=="function"&&define.amd?define(["exports","react","@octokit/rest"],x):(m=typeof globalThis<"u"?globalThis:m||self,x(m.ReactContributors={},m.React,m.Octokit))})(this,function(m,x,pe){"use strict";var A={exports:{}},w={};/** * @license React * react-jsx-runtime.production.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var X;function ge(){if(X)return w;X=1;var u=Symbol.for("react.transitional.element"),a=Symbol.for("react.fragment");function i(l,c,v){var E=null;if(v!==void 0&&(E=""+v),c.key!==void 0&&(E=""+c.key),"key"in c){v={};for(var h in c)h!=="key"&&(v[h]=c[h])}else v=c;return c=v.ref,{$$typeof:u,type:l,key:E,ref:c!==void 0?c:null,props:v}}return w.Fragment=a,w.jsx=i,w.jsxs=i,w}var R={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var F;function he(){return F||(F=1,process.env.NODE_ENV!=="production"&&function(){function u(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===Pe?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case $:return"Fragment";case Se:return"Portal";case ee:return"Profiler";case D:return"StrictMode";case U:return"Suspense";case q:return"SuspenseList"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case te:return(e.displayName||"Context")+".Provider";case re:return(e._context.displayName||"Context")+".Consumer";case W:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case J:return r=e.displayName||null,r!==null?r:u(e.type)||"Memo";case z:r=e._payload,e=e._init;try{return u(e(r))}catch{}}return null}function a(e){return""+e}function i(e){try{a(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),a(e)}}function l(){}function c(){if(k===0){se=console.log,ae=console.info,ie=console.warn,ue=console.error,le=console.group,ce=console.groupCollapsed,fe=console.groupEnd;var e={configurable:!0,enumerable:!0,value:l,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}k++}function v(){if(k--,k===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:C({},e,{value:se}),info:C({},e,{value:ae}),warn:C({},e,{value:ie}),error:C({},e,{value:ue}),group:C({},e,{value:le}),groupCollapsed:C({},e,{value:ce}),groupEnd:C({},e,{value:fe})})}0>k&&console.error("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}function E(e){if(B===void 0)try{throw Error()}catch(t){var r=t.stack.trim().match(/\n( *(at )?)/);B=r&&r[1]||"",de=-1<t.stack.indexOf(` at`)?" (<anonymous>)":-1<t.stack.indexOf("@")?"@unknown:0:0":""}return` `+B+e+de}function h(e,r){if(!e||G)return"";var t=H.get(e);if(t!==void 0)return t;G=!0,t=Error.prepareStackTrace,Error.prepareStackTrace=void 0;var n=null;n=y.H,y.H=null,c();try{var f={DetermineComponentFrameRoot:function(){try{if(r){var _=function(){throw Error()};if(Object.defineProperty(_.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(_,[])}catch(g){var S=g}Reflect.construct(e,[],_)}else{try{_.call()}catch(g){S=g}e.call(_.prototype)}}else{try{throw Error()}catch(g){S=g}(_=e())&&typeof _.catch=="function"&&_.catch(function(){})}}catch(g){if(g&&S&&typeof g.stack=="string")return[g.stack,S.stack]}return[null,null]}};f.DetermineComponentFrameRoot.displayName="DetermineComponentFrameRoot";var s=Object.getOwnPropertyDescriptor(f.DetermineComponentFrameRoot,"name");s&&s.configurable&&Object.defineProperty(f.DetermineComponentFrameRoot,"name",{value:"DetermineComponentFrameRoot"});var o=f.DetermineComponentFrameRoot(),p=o[0],j=o[1];if(p&&j){var d=p.split(` `),T=j.split(` `);for(o=s=0;s<d.length&&!d[s].includes("DetermineComponentFrameRoot");)s++;for(;o<T.length&&!T[o].includes("DetermineComponentFrameRoot");)o++;if(s===d.length||o===T.length)for(s=d.length-1,o=T.length-1;1<=s&&0<=o&&d[s]!==T[o];)o--;for(;1<=s&&0<=o;s--,o--)if(d[s]!==T[o]){if(s!==1||o!==1)do if(s--,o--,0>o||d[s]!==T[o]){var N=` `+d[s].replace(" at new "," at ");return e.displayName&&N.includes("<anonymous>")&&(N=N.replace("<anonymous>",e.displayName)),typeof e=="function"&&H.set(e,N),N}while(1<=s&&0<=o);break}}}finally{G=!1,y.H=n,v(),Error.prepareStackTrace=t}return d=(d=e?e.displayName||e.name:"")?E(d):"",typeof e=="function"&&H.set(e,d),d}function O(e){if(e==null)return"";if(typeof e=="function"){var r=e.prototype;return h(e,!(!r||!r.isReactComponent))}if(typeof e=="string")return E(e);switch(e){case U:return E("Suspense");case q:return E("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case W:return e=h(e.render,!1),e;case J:return O(e.type);case z:r=e._payload,e=e._init;try{return O(e(r))}catch{}}return""}function P(){var e=y.A;return e===null?null:e.getOwner()}function je(e){if(ne.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function we(e,r){function t(){ve||(ve=!0,console.error("%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://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function Re(){var e=u(this.type);return be[e]||(be[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function ke(e,r,t,n,f,s){return t=s.ref,e={$$typeof:Y,type:e,key:r,props:s,_owner:f},(t!==void 0?t:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:Re}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function I(e,r,t,n,f,s){if(typeof e=="string"||typeof e=="function"||e===$||e===ee||e===D||e===U||e===q||e===Oe||typeof e=="object"&&e!==null&&(e.$$typeof===z||e.$$typeof===J||e.$$typeof===te||e.$$typeof===re||e.$$typeof===W||e.$$typeof===Me||e.getModuleId!==void 0)){var o=r.children;if(o!==void 0)if(n)if(V(o)){for(n=0;n<o.length;n++)Q(o[n],e);Object.freeze&&Object.freeze(o)}else console.error("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 Q(o,e)}else o="",(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(o+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."),e===null?n="null":V(e)?n="array":e!==void 0&&e.$$typeof===Y?(n="<"+(u(e.type)||"Unknown")+" />",o=" Did you accidentally export a JSX literal instead of a component?"):n=typeof e,console.error("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",n,o);if(ne.call(r,"key")){o=u(e);var p=Object.keys(r).filter(function(d){return d!=="key"});n=0<p.length?"{key: someKey, "+p.join(": ..., ")+": ...}":"{key: someKey}",Ee[o+n]||(p=0<p.length?"{"+p.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,n,o,p,o),Ee[o+n]=!0)}if(o=null,t!==void 0&&(i(t),o=""+t),je(r)&&(i(r.key),o=""+r.key),"key"in r){t={};for(var j in r)j!=="key"&&(t[j]=r[j])}else t=r;return o&&we(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),ke(e,o,s,f,P(),t)}function Q(e,r){if(typeof e=="object"&&e&&e.$$typeof!==Ye){if(V(e))for(var t=0;t<e.length;t++){var n=e[t];M(n)&&K(n,r)}else if(M(e))e._store&&(e._store.validated=1);else if(e===null||typeof e!="object"?t=null:(t=oe&&e[oe]||e["@@iterator"],t=typeof t=="function"?t:null),typeof t=="function"&&t!==e.entries&&(t=t.call(e),t!==e))for(;!(e=t.next()).done;)M(e.value)&&K(e.value,r)}}function M(e){return typeof e=="object"&&e!==null&&e.$$typeof===Y}function K(e,r){if(e._store&&!e._store.validated&&e.key==null&&(e._store.validated=1,r=Ne(r),!me[r])){me[r]=!0;var t="";e&&e._owner!=null&&e._owner!==P()&&(t=null,typeof e._owner.tag=="number"?t=u(e._owner.type):typeof e._owner.name=="string"&&(t=e._owner.name),t=" It was passed a child from "+t+".");var n=y.getCurrentStack;y.getCurrentStack=function(){var f=O(e.type);return n&&(f+=n()||""),f},console.error('Each child in a list should have a unique "key" prop.%s%s See https://react.dev/link/warning-keys for more information.',r,t),y.getCurrentStack=n}}function Ne(e){var r="",t=P();return t&&(t=u(t.type))&&(r=` Check the render method of \``+t+"`."),r||(e=u(e))&&(r=` Check the top-level render call using <`+e+">."),r}var Ae=x,Y=Symbol.for("react.transitional.element"),Se=Symbol.for("react.portal"),$=Symbol.for("react.fragment"),D=Symbol.for("react.strict_mode"),ee=Symbol.for("react.profiler"),re=Symbol.for("react.consumer"),te=Symbol.for("react.context"),W=Symbol.for("react.forward_ref"),U=Symbol.for("react.suspense"),q=Symbol.for("react.suspense_list"),J=Symbol.for("react.memo"),z=Symbol.for("react.lazy"),Oe=Symbol.for("react.offscreen"),oe=Symbol.iterator,Pe=Symbol.for("react.client.reference"),y=Ae.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,ne=Object.prototype.hasOwnProperty,C=Object.assign,Me=Symbol.for("react.client.reference"),V=Array.isArray,k=0,se,ae,ie,ue,le,ce,fe;l.__reactDisabledLog=!0;var B,de,G=!1,H=new(typeof WeakMap=="function"?WeakMap:Map),Ye=Symbol.for("react.client.reference"),ve,be={},Ee={},me={};R.Fragment=$,R.jsx=function(e,r,t,n,f){return I(e,r,t,!1,n,f)},R.jsxs=function(e,r,t,n,f){return I(e,r,t,!0,n,f)}}()),R}var L;function _e(){return L||(L=1,process.env.NODE_ENV==="production"?A.exports=ge():A.exports=he()),A.exports}var b=_e();function xe(u,a){const i=new Map;return u.forEach(l=>{i.set(l.login,l)}),a.forEach(l=>{if(i.has(l.login)){const c=i.get(l.login);i.set(l.login,{...c,contributions:c.contributions+l.contributions})}else i.set(l.login,l)}),Array.from(i.values())}function ye(u){return[...u].sort((a,i)=>i.contributions-a.contributions)}class Ce extends x.Component{render(){return b.jsx("a",{className:"react-contributors-profile",href:this.props.url,target:"_blank",rel:"noopener noreferrer",children:b.jsxs("div",{className:"react-contributors-profile-inner",children:[b.jsx("img",{className:"react-contributors-avatar",src:this.props.avatar_url||"/placeholder.svg",alt:`${this.props.name}'s avatar`}),b.jsxs("div",{className:"react-contributors-info",children:[b.jsx("h4",{className:"react-contributors-name",children:this.props.name}),b.jsxs("small",{className:"react-contributors-contributions",children:["Contributions: ",this.props.contributions]})]})]})})}}const Te=new pe.Octokit;class Z extends x.Component{constructor(a){super(a),this.state={contributors:[]}}loadContributors(a,i){return new Promise((l,c)=>{Te.repos.listContributors({owner:a,repo:i}).then(v=>{const E=xe(this.state.contributors,v.data),h=ye(E);this.setState({contributors:h}),l()},v=>{c(v)})})}componentDidMount(){if(!this.props.repo){this.setState({contributors:[]});return}if(this.props.repo&&!Array.isArray(this.props.repo)){this.loadContributors(this.props.owner,this.props.repo).then(()=>{});return}Array.isArray(this.props.repo)&&Promise.all(this.props.repo.map(a=>this.loadContributors(this.props.owner,a))).then(()=>{})}render(){return b.jsx("div",{className:"react-contributors-container",children:b.jsx("div",{className:"react-contributors-list",children:this.state.contributors&&this.state.contributors.length?this.state.contributors.map((a,i)=>b.jsx(Ce,{avatar_url:a.avatar_url,name:a.login,url:a.html_url,contributions:a.contributions},i)):b.jsx("p",{className:"react-contributors-message",children:"No contributors found."})})})}}m.Contributors=Z,m.default=Z,Object.defineProperties(m,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});