meraproject/lib/js/bws/react/ui/pagination.js
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

120 lines
2.7 KiB
JavaScript

var Pagination;
export default window.Pagination = Pagination = class Pagination extends React.Component {
constructor(props) {
var ref, ref1;
super(props);
this.state = {
pages: (ref = props.pages) != null ? ref : 0,
now: (ref1 = props.now) != null ? ref1 : 0,
wing: 3
};
}
aSetPage() {
var base;
return typeof (base = this.props).onChange === "function" ? base.onChange(this.state.now) : void 0;
}
setPage(x) {
return this.setState({
now: x
}, this.aSetPage.bind(this));
}
setNow(now) {
return this.setState({
now
});
}
prev() {
if (this.state.now > 1) {
return this.setPage(this.state.now - 1);
}
}
next() {
if (this.state.now < this.state.pages) {
return this.setPage(this.state.now + 1);
}
}
componentWillReceiveProps(props) {
return this.setState({
pages: props.pages
});
}
render() {
var a, b, count, i, j, k, l, len, m, m1, m2, now, pages, prev, ref, ref1, ref2, ref3, ref4, style;
b = this.state.wing;
count = this.state.pages;
now = this.state.now;
a = [];
if (count > 1) {
a.push(1);
m1 = Math.min(count, b);
for (i = j = 2, ref = m1; 2 <= ref ? j <= ref : j >= ref; i = 2 <= ref ? ++j : --j) {
a.push(i);
}
m1 = Math.max(m1 + 1, now - b);
m2 = Math.min(count, now + b);
if (m1 <= m2) {
for (i = k = ref1 = m1, ref2 = m2; ref1 <= ref2 ? k <= ref2 : k >= ref2; i = ref1 <= ref2 ? ++k : --k) {
a.push(i);
}
}
m1 = Math.max(m2 + 1, count - b);
if (m1 <= count) {
for (i = l = ref3 = m1, ref4 = count; ref3 <= ref4 ? l <= ref4 : l >= ref4; i = ref3 <= ref4 ? ++l : --l) {
a.push(i);
}
}
}
pages = [];
prev = 0;
for (m = 0, len = a.length; m < len; m++) {
i = a[m];
if (i - prev > 1) {
pages.push( /*#__PURE__*/React.createElement("span", null, "..."));
}
pages.push( /*#__PURE__*/React.createElement("a", {
onClick: this.setPage.bind(this, i),
className: i === now ? 'selected' : ''
}, i));
prev = i;
}
style = {};
if (pages.length === 0) {
style = {
display: 'none'
};
}
return /*#__PURE__*/React.createElement("div", {
className: "pagination",
style: style
}, /*#__PURE__*/React.createElement("a", {
className: now < 2 ? 'disable' : '',
onClick: this.prev.bind(this)
}, "<"), pages, /*#__PURE__*/React.createElement("a", {
className: this.state.now === this.state.pages ? 'disable' : '',
onClick: this.next.bind(this)
}, ">"));
}
};
//# sourceMappingURL=pagination.js.map