react-contributors
Version:
A lightweight React component for displaying GitHub repository contributors
557 lines (554 loc) • 20.3 kB
JavaScript
(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)}})();
import G from "react";
import { Octokit as we } from "@octokit/rest";
var k = { 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 de;
function Re() {
if (de) return w;
de = 1;
var u = Symbol.for("react.transitional.element"), s = Symbol.for("react.fragment");
function i(l, c, v) {
var b = null;
if (v !== void 0 && (b = "" + v), c.key !== void 0 && (b = "" + c.key), "key" in c) {
v = {};
for (var g in c)
g !== "key" && (v[g] = c[g]);
} else v = c;
return c = v.ref, {
$$typeof: u,
type: l,
key: b,
ref: c !== void 0 ? c : null,
props: v
};
}
return w.Fragment = s, 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 ve;
function Ne() {
return ve || (ve = 1, process.env.NODE_ENV !== "production" && function() {
function u(e) {
if (e == null) return null;
if (typeof e == "function")
return e.$$typeof === ye ? null : e.displayName || e.name || null;
if (typeof e == "string") return e;
switch (e) {
case Y:
return "Fragment";
case _e:
return "Portal";
case Z:
return "Profiler";
case L:
return "StrictMode";
case $:
return "Suspense";
case W:
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 Q:
return (e.displayName || "Context") + ".Provider";
case I:
return (e._context.displayName || "Context") + ".Consumer";
case M:
var r = e.render;
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
case U:
return r = e.displayName || null, r !== null ? r : u(e.type) || "Memo";
case J:
r = e._payload, e = e._init;
try {
return u(e(r));
} catch {
}
}
return null;
}
function s(e) {
return "" + e;
}
function i(e) {
try {
s(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
), s(e);
}
}
function l() {
}
function c() {
if (j === 0) {
ee = console.log, re = console.info, te = console.warn, oe = console.error, ne = console.group, ae = console.groupCollapsed, se = 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
});
}
j++;
}
function v() {
if (j--, j === 0) {
var e = { configurable: !0, enumerable: !0, writable: !0 };
Object.defineProperties(console, {
log: _({}, e, { value: ee }),
info: _({}, e, { value: re }),
warn: _({}, e, { value: te }),
error: _({}, e, { value: oe }),
group: _({}, e, { value: ne }),
groupCollapsed: _({}, e, { value: ae }),
groupEnd: _({}, e, { value: se })
});
}
0 > j && console.error(
"disabledDepth fell below zero. This is a bug in React. Please file an issue."
);
}
function b(e) {
if (z === void 0)
try {
throw Error();
} catch (t) {
var r = t.stack.trim().match(/\n( *(at )?)/);
z = r && r[1] || "", ie = -1 < t.stack.indexOf(`
at`) ? " (<anonymous>)" : -1 < t.stack.indexOf("@") ? "@unknown:0:0" : "";
}
return `
` + z + e + ie;
}
function g(e, r) {
if (!e || V) return "";
var t = B.get(e);
if (t !== void 0) return t;
V = !0, t = Error.prepareStackTrace, Error.prepareStackTrace = void 0;
var n = null;
n = x.H, x.H = null, c();
try {
var f = {
DetermineComponentFrameRoot: function() {
try {
if (r) {
var h = function() {
throw Error();
};
if (Object.defineProperty(h.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(h, []);
} catch (p) {
var N = p;
}
Reflect.construct(e, [], h);
} else {
try {
h.call();
} catch (p) {
N = p;
}
e.call(h.prototype);
}
} else {
try {
throw Error();
} catch (p) {
N = p;
}
(h = e()) && typeof h.catch == "function" && h.catch(function() {
});
}
} catch (p) {
if (p && N && typeof p.stack == "string")
return [p.stack, N.stack];
}
return [null, null];
}
};
f.DetermineComponentFrameRoot.displayName = "DetermineComponentFrameRoot";
var a = Object.getOwnPropertyDescriptor(
f.DetermineComponentFrameRoot,
"name"
);
a && a.configurable && Object.defineProperty(
f.DetermineComponentFrameRoot,
"name",
{ value: "DetermineComponentFrameRoot" }
);
var o = f.DetermineComponentFrameRoot(), m = o[0], y = o[1];
if (m && y) {
var d = m.split(`
`), C = y.split(`
`);
for (o = a = 0; a < d.length && !d[a].includes(
"DetermineComponentFrameRoot"
); )
a++;
for (; o < C.length && !C[o].includes(
"DetermineComponentFrameRoot"
); )
o++;
if (a === d.length || o === C.length)
for (a = d.length - 1, o = C.length - 1; 1 <= a && 0 <= o && d[a] !== C[o]; )
o--;
for (; 1 <= a && 0 <= o; a--, o--)
if (d[a] !== C[o]) {
if (a !== 1 || o !== 1)
do
if (a--, o--, 0 > o || d[a] !== C[o]) {
var T = `
` + d[a].replace(
" at new ",
" at "
);
return e.displayName && T.includes("<anonymous>") && (T = T.replace("<anonymous>", e.displayName)), typeof e == "function" && B.set(e, T), T;
}
while (1 <= a && 0 <= o);
break;
}
}
} finally {
V = !1, x.H = n, v(), Error.prepareStackTrace = t;
}
return d = (d = e ? e.displayName || e.name : "") ? b(d) : "", typeof e == "function" && B.set(e, d), d;
}
function A(e) {
if (e == null) return "";
if (typeof e == "function") {
var r = e.prototype;
return g(
e,
!(!r || !r.isReactComponent)
);
}
if (typeof e == "string") return b(e);
switch (e) {
case $:
return b("Suspense");
case W:
return b("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case M:
return e = g(e.render, !1), e;
case U:
return A(e.type);
case J:
r = e._payload, e = e._init;
try {
return A(e(r));
} catch {
}
}
return "";
}
function S() {
var e = x.A;
return e === null ? null : e.getOwner();
}
function Ee(e) {
if (D.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning) return !1;
}
return e.key !== void 0;
}
function me(e, r) {
function t() {
ue || (ue = !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 pe() {
var e = u(this.type);
return le[e] || (le[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 ge(e, r, t, n, f, a) {
return t = a.ref, e = {
$$typeof: P,
type: e,
key: r,
props: a,
_owner: f
}, (t !== void 0 ? t : null) !== null ? Object.defineProperty(e, "ref", {
enumerable: !1,
get: pe
}) : 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 H(e, r, t, n, f, a) {
if (typeof e == "string" || typeof e == "function" || e === Y || e === Z || e === L || e === $ || e === W || e === Ce || typeof e == "object" && e !== null && (e.$$typeof === J || e.$$typeof === U || e.$$typeof === Q || e.$$typeof === I || e.$$typeof === M || e.$$typeof === je || e.getModuleId !== void 0)) {
var o = r.children;
if (o !== void 0)
if (n)
if (q(o)) {
for (n = 0; n < o.length; n++)
X(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 X(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" : q(e) ? n = "array" : e !== void 0 && e.$$typeof === P ? (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 (D.call(r, "key")) {
o = u(e);
var m = Object.keys(r).filter(function(d) {
return d !== "key";
});
n = 0 < m.length ? "{key: someKey, " + m.join(": ..., ") + ": ...}" : "{key: someKey}", ce[o + n] || (m = 0 < m.length ? "{" + m.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,
m,
o
), ce[o + n] = !0);
}
if (o = null, t !== void 0 && (i(t), o = "" + t), Ee(r) && (i(r.key), o = "" + r.key), "key" in r) {
t = {};
for (var y in r)
y !== "key" && (t[y] = r[y]);
} else t = r;
return o && me(
t,
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
), ge(e, o, a, f, S(), t);
}
function X(e, r) {
if (typeof e == "object" && e && e.$$typeof !== Te) {
if (q(e))
for (var t = 0; t < e.length; t++) {
var n = e[t];
O(n) && F(n, r);
}
else if (O(e))
e._store && (e._store.validated = 1);
else if (e === null || typeof e != "object" ? t = null : (t = K && e[K] || 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; )
O(e.value) && F(e.value, r);
}
}
function O(e) {
return typeof e == "object" && e !== null && e.$$typeof === P;
}
function F(e, r) {
if (e._store && !e._store.validated && e.key == null && (e._store.validated = 1, r = he(r), !fe[r])) {
fe[r] = !0;
var t = "";
e && e._owner != null && e._owner !== S() && (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 = x.getCurrentStack;
x.getCurrentStack = function() {
var f = A(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
), x.getCurrentStack = n;
}
}
function he(e) {
var r = "", t = S();
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 xe = G, P = Symbol.for("react.transitional.element"), _e = Symbol.for("react.portal"), Y = Symbol.for("react.fragment"), L = Symbol.for("react.strict_mode"), Z = Symbol.for("react.profiler"), I = Symbol.for("react.consumer"), Q = Symbol.for("react.context"), M = Symbol.for("react.forward_ref"), $ = Symbol.for("react.suspense"), W = Symbol.for("react.suspense_list"), U = Symbol.for("react.memo"), J = Symbol.for("react.lazy"), Ce = Symbol.for("react.offscreen"), K = Symbol.iterator, ye = Symbol.for("react.client.reference"), x = xe.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, D = Object.prototype.hasOwnProperty, _ = Object.assign, je = Symbol.for("react.client.reference"), q = Array.isArray, j = 0, ee, re, te, oe, ne, ae, se;
l.__reactDisabledLog = !0;
var z, ie, V = !1, B = new (typeof WeakMap == "function" ? WeakMap : Map)(), Te = Symbol.for("react.client.reference"), ue, le = {}, ce = {}, fe = {};
R.Fragment = Y, R.jsx = function(e, r, t, n, f) {
return H(e, r, t, !1, n, f);
}, R.jsxs = function(e, r, t, n, f) {
return H(e, r, t, !0, n, f);
};
}()), R;
}
var be;
function ke() {
return be || (be = 1, process.env.NODE_ENV === "production" ? k.exports = Re() : k.exports = Ne()), k.exports;
}
var E = ke();
function Ae(u, s) {
const i = /* @__PURE__ */ new Map();
return u.forEach((l) => {
i.set(l.login, l);
}), s.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 Se(u) {
return [...u].sort((s, i) => i.contributions - s.contributions);
}
class Oe extends G.Component {
render() {
return /* @__PURE__ */ E.jsx(
"a",
{
className: "react-contributors-profile",
href: this.props.url,
target: "_blank",
rel: "noopener noreferrer",
children: /* @__PURE__ */ E.jsxs("div", { className: "react-contributors-profile-inner", children: [
/* @__PURE__ */ E.jsx(
"img",
{
className: "react-contributors-avatar",
src: this.props.avatar_url || "/placeholder.svg",
alt: `${this.props.name}'s avatar`
}
),
/* @__PURE__ */ E.jsxs("div", { className: "react-contributors-info", children: [
/* @__PURE__ */ E.jsx("h4", { className: "react-contributors-name", children: this.props.name }),
/* @__PURE__ */ E.jsxs("small", { className: "react-contributors-contributions", children: [
"Contributions: ",
this.props.contributions
] })
] })
] })
}
);
}
}
const Pe = new we();
class $e extends G.Component {
constructor(s) {
super(s), this.state = {
contributors: []
};
}
loadContributors(s, i) {
return new Promise((l, c) => {
Pe.repos.listContributors({
owner: s,
repo: i
}).then(
(v) => {
const b = Ae(
this.state.contributors,
v.data
), g = Se(b);
this.setState({
contributors: g
}), 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(
(s) => this.loadContributors(this.props.owner, s)
)
).then(() => {
});
}
render() {
return /* @__PURE__ */ E.jsx("div", { className: "react-contributors-container", children: /* @__PURE__ */ E.jsx("div", { className: "react-contributors-list", children: this.state.contributors && this.state.contributors.length ? this.state.contributors.map((s, i) => /* @__PURE__ */ E.jsx(
Oe,
{
avatar_url: s.avatar_url,
name: s.login,
url: s.html_url,
contributions: s.contributions
},
i
)) : /* @__PURE__ */ E.jsx("p", { className: "react-contributors-message", children: "No contributors found." }) }) });
}
}
export {
$e as Contributors,
$e as default
};