pagy 7.0.11 → 8.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/apps/calendar.ru +745 -0
- data/apps/demo.ru +435 -0
- data/apps/rails.ru +212 -0
- data/apps/repro.ru +177 -0
- data/apps/tmp/calendar.sqlite3 +0 -0
- data/apps/tmp/calendar.sqlite3-shm +0 -0
- data/apps/tmp/calendar.sqlite3-wal +0 -0
- data/apps/tmp/local_secret.txt +1 -0
- data/apps/tmp/pagy-keyset.sqlite3 +0 -0
- data/apps/tmp/pagy-keyset.sqlite3-shm +0 -0
- data/apps/tmp/pagy-keyset.sqlite3-wal +0 -0
- data/bin/pagy +100 -0
- data/{lib/config → config}/pagy.rb +31 -73
- data/javascripts/pagy-module.js +100 -0
- data/javascripts/pagy.js +4 -0
- data/javascripts/pagy.min.js +4 -0
- data/javascripts/pagy.min.js.map +10 -0
- data/javascripts/pagy.mjs +100 -0
- data/lib/optimist.rb +1022 -0
- data/lib/pagy/backend.rb +8 -3
- data/lib/pagy/calendar/day.rb +4 -3
- data/lib/pagy/calendar/month.rb +4 -3
- data/lib/pagy/calendar/quarter.rb +4 -3
- data/lib/pagy/calendar/unit.rb +106 -0
- data/lib/pagy/calendar/week.rb +3 -3
- data/lib/pagy/calendar/year.rb +4 -3
- data/lib/pagy/calendar.rb +55 -99
- data/lib/pagy/console.rb +2 -2
- data/lib/pagy/countless.rb +15 -10
- data/lib/pagy/extras/arel.rb +1 -1
- data/lib/pagy/extras/array.rb +1 -1
- data/lib/pagy/extras/bootstrap.rb +52 -63
- data/lib/pagy/extras/bulma.rb +49 -64
- data/lib/pagy/extras/calendar.rb +35 -5
- data/lib/pagy/extras/countless.rb +2 -2
- data/lib/pagy/extras/foundation.rb +52 -62
- data/lib/pagy/extras/gearbox.rb +28 -27
- data/lib/pagy/extras/headers.rb +1 -1
- data/lib/pagy/extras/i18n.rb +1 -1
- data/lib/pagy/extras/items.rb +21 -18
- data/lib/pagy/extras/{frontend_helpers.rb → js_tools.rb} +9 -6
- data/lib/pagy/extras/jsonapi.rb +2 -2
- data/lib/pagy/extras/materialize.rb +56 -52
- data/lib/pagy/extras/metadata.rb +6 -2
- data/lib/pagy/extras/overflow.rb +5 -4
- data/lib/pagy/extras/pagy.rb +82 -0
- data/lib/pagy/extras/semantic.rb +50 -51
- data/lib/pagy/extras/size.rb +40 -0
- data/lib/pagy/extras/standalone.rb +2 -2
- data/lib/pagy/extras/trim.rb +12 -12
- data/lib/pagy/extras/uikit.rb +51 -50
- data/lib/pagy/frontend.rb +39 -53
- data/lib/pagy/url_helpers.rb +9 -10
- data/lib/pagy.rb +51 -82
- data/{lib/locales → locales}/ar.yml +10 -11
- data/{lib/locales → locales}/be.yml +5 -5
- data/{lib/locales → locales}/bg.yml +5 -5
- data/{lib/locales → locales}/bs.yml +5 -5
- data/locales/ca.yml +21 -0
- data/locales/ckb.yml +18 -0
- data/{lib/locales → locales}/cs.yml +5 -5
- data/locales/da.yml +21 -0
- data/{lib/locales → locales}/de.yml +5 -5
- data/{lib/locales → locales}/en.yml +5 -5
- data/{lib/locales → locales}/es.yml +3 -3
- data/{lib/locales → locales}/fr.yml +5 -5
- data/{lib/locales → locales}/hr.yml +5 -5
- data/{lib/locales → locales}/id.yml +5 -5
- data/{lib/locales → locales}/it.yml +5 -5
- data/{lib/locales → locales}/ja.yml +5 -5
- data/{lib/locales → locales}/km.yml +5 -5
- data/locales/ko.yml +17 -0
- data/{lib/locales → locales}/nb.yml +5 -5
- data/{lib/locales → locales}/nl.yml +5 -5
- data/{lib/locales → locales}/nn.yml +5 -5
- data/{lib/locales → locales}/pl.yml +5 -5
- data/{lib/locales → locales}/pt-BR.yml +3 -3
- data/{lib/locales → locales}/pt.yml +3 -3
- data/locales/ru.yml +25 -0
- data/{lib/locales → locales}/sr.yml +5 -5
- data/{lib/locales → locales}/sv-SE.yml +5 -5
- data/{lib/locales → locales}/sv.yml +5 -5
- data/{lib/locales → locales}/sw.yml +5 -5
- data/{lib/locales → locales}/ta.yml +5 -5
- data/{lib/locales → locales}/tr.yml +5 -5
- data/{lib/locales → locales}/uk.yml +5 -5
- data/locales/vi.yml +17 -0
- data/{lib/locales → locales}/zh-CN.yml +5 -5
- data/{lib/locales → locales}/zh-HK.yml +5 -5
- data/{lib/locales → locales}/zh-TW.yml +5 -5
- data/{lib/stylesheets → stylesheets}/pagy.css +19 -34
- data/{lib/stylesheets → stylesheets}/pagy.scss +17 -19
- data/stylesheets/pagy.tailwind.css +21 -0
- metadata +76 -53
- data/lib/javascripts/pagy-dev.js +0 -112
- data/lib/javascripts/pagy-module.js +0 -111
- data/lib/javascripts/pagy.js +0 -1
- data/lib/locales/ca.yml +0 -23
- data/lib/locales/ckb.yml +0 -18
- data/lib/locales/da.yml +0 -23
- data/lib/locales/ko.yml +0 -19
- data/lib/locales/ru.yml +0 -27
- data/lib/locales/vi.yml +0 -17
- data/lib/pagy/calendar/helper.rb +0 -65
- data/lib/pagy/extras/navs.rb +0 -51
- data/lib/pagy/extras/support.rb +0 -40
- data/lib/stylesheets/pagy.tailwind.scss +0 -24
- /data/{lib/javascripts/pagy-module.d.ts → javascripts/pagy.d.ts} +0 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
const Pagy = (() => {
|
2
|
+
const rjsObserver = new ResizeObserver((entries) => entries.forEach((e) => e.target.querySelectorAll(".pagy-rjs").forEach((el) => el.pagyRender())));
|
3
|
+
const initNav = (el, [tokens, sequels, labelSequels, trimParam]) => {
|
4
|
+
const container = el.parentElement ?? el;
|
5
|
+
const widths = Object.keys(sequels).map((w) => parseInt(w)).sort((a, b) => b - a);
|
6
|
+
let lastWidth = -1;
|
7
|
+
const fillIn = (a, page, label) => a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);
|
8
|
+
(el.pagyRender = function() {
|
9
|
+
const width = widths.find((w) => w < container.clientWidth) || 0;
|
10
|
+
if (width === lastWidth) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
let html = tokens.before;
|
14
|
+
const series = sequels[width.toString()];
|
15
|
+
const labels = labelSequels?.[width.toString()] ?? series.map((l) => l.toString());
|
16
|
+
series.forEach((item, i) => {
|
17
|
+
const label = labels[i];
|
18
|
+
let filled;
|
19
|
+
if (typeof item === "number") {
|
20
|
+
filled = fillIn(tokens.a, item.toString(), label);
|
21
|
+
} else if (item === "gap") {
|
22
|
+
filled = tokens.gap;
|
23
|
+
} else {
|
24
|
+
filled = fillIn(tokens.current, item, label);
|
25
|
+
}
|
26
|
+
html += typeof trimParam === "string" && item == 1 ? trim(filled, trimParam) : filled;
|
27
|
+
});
|
28
|
+
html += tokens.after;
|
29
|
+
el.innerHTML = "";
|
30
|
+
el.insertAdjacentHTML("afterbegin", html);
|
31
|
+
lastWidth = width;
|
32
|
+
})();
|
33
|
+
if (el.classList.contains("pagy-rjs")) {
|
34
|
+
rjsObserver.observe(container);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
const initCombo = (el, [url_token, trimParam]) => initInput(el, (inputValue) => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);
|
38
|
+
const initSelector = (el, [from, url_token, trimParam]) => {
|
39
|
+
initInput(el, (inputValue) => {
|
40
|
+
const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();
|
41
|
+
const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_items__/, inputValue);
|
42
|
+
return [page, url];
|
43
|
+
}, trimParam);
|
44
|
+
};
|
45
|
+
const initInput = (el, getVars, trimParam) => {
|
46
|
+
const input = el.querySelector("input");
|
47
|
+
const link = el.querySelector("a");
|
48
|
+
const initial = input.value;
|
49
|
+
const action = function() {
|
50
|
+
if (input.value === initial) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
const [min, val, max] = [input.min, input.value, input.max].map((n) => parseInt(n) || 0);
|
54
|
+
if (val < min || val > max) {
|
55
|
+
input.value = initial;
|
56
|
+
input.select();
|
57
|
+
return;
|
58
|
+
}
|
59
|
+
let [page, url] = getVars(input.value);
|
60
|
+
if (typeof trimParam === "string" && page === "1") {
|
61
|
+
url = trim(url, trimParam);
|
62
|
+
}
|
63
|
+
link.href = url;
|
64
|
+
link.click();
|
65
|
+
};
|
66
|
+
["change", "focus"].forEach((e) => input.addEventListener(e, () => input.select()));
|
67
|
+
input.addEventListener("focusout", action);
|
68
|
+
input.addEventListener("keypress", (e) => {
|
69
|
+
if (e.key === "Enter") {
|
70
|
+
action();
|
71
|
+
}
|
72
|
+
});
|
73
|
+
};
|
74
|
+
const trim = (a, param) => a.replace(new RegExp(`[?&]${param}=1\\b(?!&)|\\b${param}=1&`), "");
|
75
|
+
return {
|
76
|
+
version: "8.6.3",
|
77
|
+
init(arg) {
|
78
|
+
const target = arg instanceof Element ? arg : document;
|
79
|
+
const elements = target.querySelectorAll("[data-pagy]");
|
80
|
+
for (const el of elements) {
|
81
|
+
try {
|
82
|
+
const uint8array = Uint8Array.from(atob(el.getAttribute("data-pagy")), (c) => c.charCodeAt(0));
|
83
|
+
const [keyword, ...args] = JSON.parse(new TextDecoder().decode(uint8array));
|
84
|
+
if (keyword === "nav") {
|
85
|
+
initNav(el, args);
|
86
|
+
} else if (keyword === "combo") {
|
87
|
+
initCombo(el, args);
|
88
|
+
} else if (keyword === "selector") {
|
89
|
+
initSelector(el, args);
|
90
|
+
} else {
|
91
|
+
console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'", el, keyword);
|
92
|
+
}
|
93
|
+
} catch (err) {
|
94
|
+
console.warn("Skipped Pagy.init() for: %o\n%s", el, err);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
};
|
99
|
+
})();
|
100
|
+
export default Pagy;
|