@ea-lab/reactive-json
Version:
A REACT-based lib that transforms JSON (or YAML) into interactive HTML markup.
354 lines (353 loc) • 8.07 kB
JavaScript
import { jsx as c, jsxs as B } from "react/jsx-runtime";
import * as p from "react";
import { useContext as y, useRef as I, useEffect as K, useCallback as M, useState as F } from "react";
import { g as L } from "./_commonjsHelpers-DaMA6jEr.js";
var C = { exports: {} };
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/
var g;
function S() {
return g || (g = 1, function(n) {
(function() {
var r = {}.hasOwnProperty;
function t() {
for (var e = "", i = 0; i < arguments.length; i++) {
var u = arguments[i];
u && (e = o(e, s(u)));
}
return e;
}
function s(e) {
if (typeof e == "string" || typeof e == "number")
return e;
if (typeof e != "object")
return "";
if (Array.isArray(e))
return t.apply(null, e);
if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]"))
return e.toString();
var i = "";
for (var u in e)
r.call(e, u) && e[u] && (i = o(i, u));
return i;
}
function o(e, i) {
return i ? e ? e + " " + i : e + i : e;
}
n.exports ? (t.default = t, n.exports = t) : window.classNames = t;
})();
}(C)), C.exports;
}
var T = S();
const k = /* @__PURE__ */ L(T), $ = ["xxl", "xl", "lg", "md", "sm", "xs"], _ = "xs", h = /* @__PURE__ */ p.createContext({
prefixes: {},
breakpoints: $,
minBreakpoint: _
}), {
Consumer: an,
Provider: cn
} = h;
function V(n, r) {
const {
prefixes: t
} = y(h);
return n || t[r] || r;
}
function un() {
const {
breakpoints: n
} = y(h);
return n;
}
function ln() {
const {
minBreakpoint: n
} = y(h);
return n;
}
function fn() {
const {
dir: n
} = y(h);
return n === "rtl";
}
function q(n) {
const r = I(n);
return K(() => {
r.current = n;
}, [n]), r;
}
function H(n) {
const r = q(n);
return M(function(...t) {
return r.current && r.current(...t);
}, [r]);
}
const U = ["as", "disabled"];
function W(n, r) {
if (n == null) return {};
var t = {};
for (var s in n) if ({}.hasOwnProperty.call(n, s)) {
if (r.indexOf(s) >= 0) continue;
t[s] = n[s];
}
return t;
}
function G(n) {
return !n || n.trim() === "#";
}
function j({
tagName: n,
disabled: r,
href: t,
target: s,
rel: o,
role: e,
onClick: i,
tabIndex: u = 0,
type: d
}) {
n || (t != null || s != null || o != null ? n = "a" : n = "button");
const f = {
tagName: n
};
if (n === "button")
return [{
type: d || "button",
disabled: r
}, f];
const m = (a) => {
if ((r || n === "a" && G(t)) && a.preventDefault(), r) {
a.stopPropagation();
return;
}
i == null || i(a);
}, x = (a) => {
a.key === " " && (a.preventDefault(), m(a));
};
return n === "a" && (t || (t = "#"), r && (t = void 0)), [{
role: e ?? "button",
// explicitly undefined so that it overrides the props disabled in a spread
// e.g. <Tag {...props} {...hookProps} />
disabled: void 0,
tabIndex: r ? void 0 : u,
href: t,
target: n === "a" ? s : void 0,
"aria-disabled": r || void 0,
rel: n === "a" ? o : void 0,
onClick: m,
onKeyDown: x
}, f];
}
const J = /* @__PURE__ */ p.forwardRef((n, r) => {
let {
as: t,
disabled: s
} = n, o = W(n, U);
const [e, {
tagName: i
}] = j(Object.assign({
tagName: t,
disabled: s
}, o));
return /* @__PURE__ */ c(i, Object.assign({}, o, e, {
ref: r
}));
});
J.displayName = "Button";
const Q = ["onKeyDown"];
function X(n, r) {
if (n == null) return {};
var t = {};
for (var s in n) if ({}.hasOwnProperty.call(n, s)) {
if (r.indexOf(s) >= 0) continue;
t[s] = n[s];
}
return t;
}
function Y(n) {
return !n || n.trim() === "#";
}
const A = /* @__PURE__ */ p.forwardRef((n, r) => {
let {
onKeyDown: t
} = n, s = X(n, Q);
const [o] = j(Object.assign({
tagName: "a"
}, s)), e = H((i) => {
o.onKeyDown(i), t == null || t(i);
});
return Y(s.href) || s.role === "button" ? /* @__PURE__ */ c("a", Object.assign({
ref: r
}, s, o, {
onKeyDown: e
})) : /* @__PURE__ */ c("a", Object.assign({
ref: r
}, s, {
onKeyDown: t
}));
});
A.displayName = "Anchor";
const N = /* @__PURE__ */ p.forwardRef(({
active: n = !1,
disabled: r = !1,
className: t,
style: s,
activeLabel: o = "(current)",
children: e,
linkStyle: i,
linkClassName: u,
as: d = A,
...f
}, m) => {
const x = n || r ? "span" : d;
return /* @__PURE__ */ c("li", {
ref: m,
style: s,
className: k(t, "page-item", {
active: n,
disabled: r
}),
children: /* @__PURE__ */ B(x, {
className: k("page-link", u),
style: i,
...f,
children: [e, n && o && /* @__PURE__ */ c("span", {
className: "visually-hidden",
children: o
})]
})
});
});
N.displayName = "PageItem";
function b(n, r, t = n) {
const s = /* @__PURE__ */ p.forwardRef(({
children: o,
...e
}, i) => /* @__PURE__ */ B(N, {
...e,
ref: i,
children: [/* @__PURE__ */ c("span", {
"aria-hidden": "true",
children: o || r
}), /* @__PURE__ */ c("span", {
className: "visually-hidden",
children: t
})]
}));
return s.displayName = n, s;
}
const Z = b("First", "«"), z = b("Prev", "‹", "Previous"), nn = b("Ellipsis", "…", "More"), tn = b("Next", "›"), en = b("Last", "»"), D = /* @__PURE__ */ p.forwardRef(({
bsPrefix: n,
className: r,
size: t,
...s
}, o) => {
const e = V(n, "pagination");
return /* @__PURE__ */ c("ul", {
ref: o,
...s,
className: k(r, e, t && `${e}-${t}`)
});
});
D.displayName = "Pagination";
const l = Object.assign(D, {
First: Z,
Prev: z,
Ellipsis: nn,
Item: N,
Next: tn,
Last: en
}), dn = ({
dataToPaginate: n = [],
forcePaginationDisplay: r = !1,
maxPageButtonsCount: t = 5,
pageMaxItemCount: s = 10
}) => {
const [o, e] = F(0), i = Math.floor(t / 2), u = o * s, d = u + s, f = (a) => Math.ceil(a.length / s);
return {
firstShownItemIndex: u,
getPageCountForContent: f,
maxShownItemIndexExcluded: d,
PageControls: () => {
const a = f(n);
return !r && a <= 1 ? null : /* @__PURE__ */ B(l, { children: [
/* @__PURE__ */ c(
l.First,
{
disabled: o <= 0,
onClick: () => {
e(0);
}
}
),
/* @__PURE__ */ c(
l.Prev,
{
disabled: o <= 0,
onClick: () => {
e(o - 1);
}
}
),
Math.min(o - i, a - t) > 0 ? /* @__PURE__ */ c(l.Ellipsis, { disabled: !0 }) : null,
(() => {
const O = [];
let P = Math.min(Math.max(0, a - t), Math.max(0, o - i)), w = t;
const E = (v, R) => {
O.push(/* @__PURE__ */ c(
l.Item,
{
active: o === v,
onClick: () => {
e(v);
},
children: v + 1
},
t - R
));
};
for (; w && (E(P, w), ++P, --w, !(P >= a)); )
;
return O;
})(),
a > Math.max(i, o) + Math.ceil(t / 2) ? /* @__PURE__ */ c(l.Ellipsis, { disabled: !0 }) : null,
/* @__PURE__ */ c(
l.Next,
{
disabled: o + 1 >= a,
onClick: () => {
e(o + 1);
}
}
),
/* @__PURE__ */ c(
l.Last,
{
disabled: o + 1 >= a,
onClick: () => {
e(a - 1);
}
}
)
] });
},
pageMaxItemCount: s,
sliceVisibleContent: (a) => Array.isArray(a) ? a.slice(u, d) : a
};
};
export {
A,
J as B,
V as a,
un as b,
k as c,
ln as d,
j as e,
H as f,
fn as g,
dn as u
};