pagy 8.6.1 → 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 +5 -5
- data/apps/demo.ru +4 -4
- data/apps/rails.ru +3 -4
- data/apps/repro.ru +2 -2
- 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 -1
- data/apps/tmp/pagy-keyset.sqlite3 +0 -0
- data/apps/tmp/{pagy-rails.sqlite3 → pagy-keyset.sqlite3-shm} +0 -0
- data/apps/tmp/pagy-keyset.sqlite3-wal +0 -0
- data/bin/pagy +1 -1
- data/config/pagy.rb +2 -1
- data/javascripts/pagy-module.js +1 -1
- data/javascripts/pagy.js +2 -2
- data/javascripts/pagy.min.js +2 -2
- data/javascripts/pagy.min.js.map +3 -3
- data/javascripts/pagy.mjs +1 -1
- data/lib/pagy/countless.rb +1 -1
- data/lib/pagy/extras/gearbox.rb +12 -12
- data/lib/pagy/extras/js_tools.rb +4 -4
- data/lib/pagy/extras/overflow.rb +1 -1
- data/lib/pagy.rb +10 -10
- data/locales/ar.yml +1 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2504119986405246907631188b14c4e366eb2247f7fdecdd6a14f187dbe56674
|
4
|
+
data.tar.gz: 9a355076182f3446c64279c7e158f9d826963c472e2e9b17e497cb863bdcadcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30b2e50c83d38b52d186c8f53615b6fe8491fd22ace660f351cca2993ed98c25ab3a8b61117e57c5f3b465f28daba3ef2efe0cf0332c0e2cc4a09d8986cfc217
|
7
|
+
data.tar.gz: 01cf06ebc92ce69ccc50252d259057d14b56b0149e9e982dbd52e8e1bd1fb889a7319dcf497df5c3c2d3b388372e5444520054eda76cbefbe908d7debb20f73e
|
data/apps/calendar.ru
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# DOC
|
16
16
|
# https://ddnexus.github.io/pagy/playground/#5-calendar-app
|
17
17
|
|
18
|
-
VERSION = '8.6.
|
18
|
+
VERSION = '8.6.3'
|
19
19
|
|
20
20
|
# Gemfile
|
21
21
|
require 'bundler/inline'
|
@@ -70,6 +70,7 @@ Groupdate.time_zone = false
|
|
70
70
|
Groupdate.week_start = :monday
|
71
71
|
|
72
72
|
# Activerecord initializer
|
73
|
+
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
73
74
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/calendar.sqlite3")
|
74
75
|
ActiveRecord::Schema.define do
|
75
76
|
create_table :events, force: true do |t|
|
@@ -735,11 +736,10 @@ TIMES = <<~TIMES
|
|
735
736
|
TIMES
|
736
737
|
|
737
738
|
# DB seed
|
739
|
+
events = []
|
738
740
|
TIMES.each_line(chomp: true).with_index do |time, i|
|
739
|
-
|
741
|
+
events << { title: "Event ##{i + 1}", time: }
|
740
742
|
end
|
741
|
-
|
742
|
-
# Down here to avoid logging the DB seed above at each restart
|
743
|
-
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
743
|
+
Event.insert_all(events)
|
744
744
|
|
745
745
|
run Calendar
|
data/apps/demo.ru
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
# DOC
|
19
19
|
# https://ddnexus.github.io/pagy/playground/#3-demo-app
|
20
20
|
|
21
|
-
VERSION = '8.6.
|
21
|
+
VERSION = '8.6.3'
|
22
22
|
|
23
23
|
require 'bundler/inline'
|
24
24
|
require 'bundler'
|
@@ -380,15 +380,15 @@ for details</p>
|
|
380
380
|
<%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'simple-nav', aria_label: 'Pages simple-nav', size: 5) %>
|
381
381
|
<%= highlight(html) %>
|
382
382
|
|
383
|
-
<h2>pagy<%= prefix %>_nav <span class="notes">
|
383
|
+
<h2>pagy<%= prefix %>_nav <span class="notes">Fast nav <code>size: 7</code></span></h2>
|
384
384
|
<%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'nav', aria_label: 'Pages nav') %>
|
385
385
|
<%= highlight(html) %>
|
386
386
|
|
387
|
-
<h2>pagy<%= prefix %>_nav_js <span class="notes">
|
387
|
+
<h2>pagy<%= prefix %>_nav_js <span class="notes">Fast nav <code>size: 7</code></span></h2>
|
388
388
|
<%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
|
389
389
|
<%= highlight(html) %>
|
390
390
|
|
391
|
-
<h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive <code>steps: {...}</code> (Resize the window to see)</span></h2>
|
391
|
+
<h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive nav <code>steps: {...}</code> (Resize the window to see)</span></h2>
|
392
392
|
<%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js-responsive',
|
393
393
|
aria_label: 'Pages nav_js_responsive',
|
394
394
|
steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
|
data/apps/rails.ru
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# DOC
|
16
16
|
# https://ddnexus.github.io/pagy/playground/#2-rails-app
|
17
17
|
|
18
|
-
VERSION = '8.6.
|
18
|
+
VERSION = '8.6.3'
|
19
19
|
|
20
20
|
# Gemfile
|
21
21
|
require 'bundler/inline'
|
@@ -67,6 +67,8 @@ Pagy::DEFAULT[:items] = 10
|
|
67
67
|
Pagy::DEFAULT[:overflow] = :empty_page
|
68
68
|
Pagy::DEFAULT.freeze
|
69
69
|
|
70
|
+
# Activerecord initializer
|
71
|
+
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
70
72
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-rails.sqlite3")
|
71
73
|
ActiveRecord::Schema.define do
|
72
74
|
create_table :posts, force: true do |t|
|
@@ -96,9 +98,6 @@ Post.all.each_with_index do |post, pi|
|
|
96
98
|
2.times { |ci| Comment.create(post:, body: "Comment #{ci + 1} to Post #{pi + 1}") }
|
97
99
|
end
|
98
100
|
|
99
|
-
# Down here to avoid logging the DB seed above at each restart
|
100
|
-
ActiveRecord::Base.logger = Logger.new(OUTPUT)
|
101
|
-
|
102
101
|
# Helpers
|
103
102
|
module CommentsHelper
|
104
103
|
include Pagy::Frontend
|
data/apps/repro.ru
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
# DOC
|
16
16
|
# https://ddnexus.github.io/pagy/playground/#1-repro-app
|
17
17
|
|
18
|
-
VERSION = '8.6.
|
18
|
+
VERSION = '8.6.3'
|
19
19
|
|
20
20
|
require 'bundler/inline'
|
21
21
|
require 'bundler'
|
@@ -164,7 +164,7 @@ __END__
|
|
164
164
|
|
165
165
|
<h4>pagy_nav_js</h4>
|
166
166
|
<%= pagy_nav_js(@pagy, id: 'nav-js-responsive', aria_label: 'Pages nav_js_responsove',
|
167
|
-
steps: { 0 =>
|
167
|
+
steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
|
168
168
|
|
169
169
|
<h4>pagy_combo_nav_js</h4>
|
170
170
|
<%= pagy_combo_nav_js(@pagy, id: 'combo-nav-js', aria_label: 'Pages combo_nav_js') %>
|
data/apps/tmp/calendar.sqlite3
CHANGED
Binary file
|
Binary file
|
Binary file
|
data/apps/tmp/local_secret.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
4c57eebd7544c7f0acc9943ab614ab3da71d2461f5581ed8d41e9b8aa1bf23bff831f82e934eed96c608da0feac2c3dd21383c269d896cf01fcd6fa81aca2462
|
Binary file
|
Binary file
|
Binary file
|
data/bin/pagy
CHANGED
data/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (8.6.
|
3
|
+
# Pagy initializer file (8.6.3)
|
4
4
|
# Customize only what you really need and notice that the core Pagy works also without any of the following lines.
|
5
5
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
6
6
|
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# Pagy::DEFAULT[:ends] = true # default
|
16
16
|
# Pagy::DEFAULT[:page_param] = :page # default
|
17
17
|
# Pagy::DEFAULT[:count_args] = [] # example for non AR ORMs
|
18
|
+
# Pagy::DEFAULT[:max_pages] = 3000 # example
|
18
19
|
|
19
20
|
|
20
21
|
# Extras
|
data/javascripts/pagy-module.js
CHANGED
@@ -73,7 +73,7 @@ const Pagy = (() => {
|
|
73
73
|
};
|
74
74
|
const trim = (a, param) => a.replace(new RegExp(`[?&]${param}=1\\b(?!&)|\\b${param}=1&`), "");
|
75
75
|
return {
|
76
|
-
version: "8.6.
|
76
|
+
version: "8.6.3",
|
77
77
|
init(arg) {
|
78
78
|
const target = arg instanceof Element ? arg : document;
|
79
79
|
const elements = target.querySelectorAll("[data-pagy]");
|
data/javascripts/pagy.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>Q<F.clientWidth)||0;if(H===L)return;let M=D.before;const R=E[H.toString()],X=z?.[H.toString()]??R.map((Q)=>Q.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_items__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(T<L||T>H){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"8.6.
|
1
|
+
window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>Q<F.clientWidth)||0;if(H===L)return;let M=D.before;const R=E[H.toString()],X=z?.[H.toString()]??R.map((Q)=>Q.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_items__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(T<L||T>H){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"8.6.3",init(B){const E=(B instanceof Element?B:document).querySelectorAll("[data-pagy]");for(let z of E)try{const G=Uint8Array.from(atob(z.getAttribute("data-pagy")),(L)=>L.charCodeAt(0)),[F,...K]=JSON.parse((new TextDecoder()).decode(G));if(F==="nav")x(z,K);else if(F==="combo")A(z,K);else if(F==="selector")C(z,K);else console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'",z,F)}catch(G){console.warn("Skipped Pagy.init() for: %o\n%s",z,G)}}}})();
|
2
2
|
|
3
|
-
//# debugId=
|
3
|
+
//# debugId=B9DC02765C7A5B6764756E2164756E21
|
4
4
|
//# sourceMappingURL=pagy.min.js.map
|
data/javascripts/pagy.min.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>Q<F.clientWidth)||0;if(H===L)return;let M=D.before;const R=E[H.toString()],X=z?.[H.toString()]??R.map((Q)=>Q.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_items__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(T<L||T>H){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"8.6.
|
1
|
+
window.Pagy=(()=>{const j=new ResizeObserver((B)=>B.forEach((D)=>D.target.querySelectorAll(".pagy-rjs").forEach((E)=>E.pagyRender()))),x=(B,[D,E,z,G])=>{const F=B.parentElement??B,K=Object.keys(E).map((H)=>parseInt(H)).sort((H,M)=>M-H);let L=-1;const T=(H,M,R)=>H.replace(/__pagy_page__/g,M).replace(/__pagy_label__/g,R);if((B.pagyRender=function(){const H=K.find((Q)=>Q<F.clientWidth)||0;if(H===L)return;let M=D.before;const R=E[H.toString()],X=z?.[H.toString()]??R.map((Q)=>Q.toString());R.forEach((Q,J)=>{const $=X[J];let U;if(typeof Q==="number")U=T(D.a,Q.toString(),$);else if(Q==="gap")U=D.gap;else U=T(D.current,Q,$);M+=typeof G==="string"&&Q==1?Z(U,G):U}),M+=D.after,B.innerHTML="",B.insertAdjacentHTML("afterbegin",M),L=H})(),B.classList.contains("pagy-rjs"))j.observe(F)},A=(B,[D,E])=>Y(B,(z)=>[z,D.replace(/__pagy_page__/,z)],E),C=(B,[D,E,z])=>{Y(B,(G)=>{const F=Math.max(Math.ceil(D/parseInt(G)),1).toString(),K=E.replace(/__pagy_page__/,F).replace(/__pagy_items__/,G);return[F,K]},z)},Y=(B,D,E)=>{const z=B.querySelector("input"),G=B.querySelector("a"),F=z.value,K=function(){if(z.value===F)return;const[L,T,H]=[z.min,z.value,z.max].map((X)=>parseInt(X)||0);if(T<L||T>H){z.value=F,z.select();return}let[M,R]=D(z.value);if(typeof E==="string"&&M==="1")R=Z(R,E);G.href=R,G.click()};["change","focus"].forEach((L)=>z.addEventListener(L,()=>z.select())),z.addEventListener("focusout",K),z.addEventListener("keypress",(L)=>{if(L.key==="Enter")K()})},Z=(B,D)=>B.replace(new RegExp(`[?&]${D}=1\\b(?!&)|\\b${D}=1&`),"");return{version:"8.6.3",init(B){const E=(B instanceof Element?B:document).querySelectorAll("[data-pagy]");for(let z of E)try{const G=Uint8Array.from(atob(z.getAttribute("data-pagy")),(L)=>L.charCodeAt(0)),[F,...K]=JSON.parse((new TextDecoder()).decode(G));if(F==="nav")x(z,K);else if(F==="combo")A(z,K);else if(F==="selector")C(z,K);else console.warn("Skipped Pagy.init() for: %o\nUnknown keyword '%s'",z,F)}catch(G){console.warn("Skipped Pagy.init() for: %o\n%s",z,G)}}}})();
|
2
2
|
|
3
|
-
//# debugId=
|
3
|
+
//# debugId=B9DC02765C7A5B6764756E2164756E21
|
4
4
|
//# sourceMappingURL=pagy.min.js.map
|
data/javascripts/pagy.min.js.map
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
"version": 3,
|
3
3
|
"sources": ["../../src/pagy.ts"],
|
4
4
|
"sourcesContent": [
|
5
|
-
"type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll<NavElement>(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the items_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_items__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"8.6.
|
5
|
+
"type NavArgs = readonly [Tokens, Sequels, null | LabelSequels, string?]\ntype ComboArgs = readonly [string, string?]\ntype SelectorArgs = readonly [number, string, string?]\ntype JsonArgs = ['nav', NavArgs] | ['combo', ComboArgs] | ['selector', SelectorArgs]\n\ninterface Tokens {\n readonly before:string\n readonly a:string\n readonly current:string\n readonly gap:string\n readonly after:string\n}\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => e.target.querySelectorAll<NavElement>(\".pagy-rjs\")\n .forEach(el => el.pagyRender())));\n // Init the *_nav_js helpers\n const initNav = (el:NavElement, [tokens, sequels, labelSequels, trimParam]:NavArgs) => {\n const container = el.parentElement ?? el;\n const widths = Object.keys(sequels).map(w => parseInt(w)).sort((a, b) => b - a);\n let lastWidth = -1;\n const fillIn = (a:string, page:string, label:string):string =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = function () {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n let html = tokens.before; // already trimmed in html\n const series = sequels[width.toString()];\n const labels = labelSequels?.[width.toString()] ?? series.map(l => l.toString());\n series.forEach((item, i) => {\n const label = labels[i];\n let filled;\n if (typeof item === \"number\") {\n filled = fillIn(tokens.a, item.toString(), label);\n } else if (item === \"gap\") {\n filled = tokens.gap;\n } else { // active page\n filled = fillIn(tokens.current, item, label);\n }\n html += (typeof trimParam === \"string\" && item == 1) ? trim(filled, trimParam) : filled;\n });\n html += tokens.after;\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initCombo = (el:Element, [url_token, trimParam]:ComboArgs) =>\n initInput(el, inputValue => [inputValue, url_token.replace(/__pagy_page__/, inputValue)], trimParam);\n\n // Init the items_selector_js helper\n const initSelector = (el:Element, [from, url_token, trimParam]:SelectorArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n const url = url_token.replace(/__pagy_page__/, page).replace(/__pagy_items__/, inputValue);\n return [page, url];\n }, trimParam);\n };\n\n // Init the input element\n const initInput = (el:Element, getVars:(v:string) => [string, string], trimParam?:string) => {\n const input = el.querySelector(\"input\") as HTMLInputElement;\n const link = el.querySelector(\"a\") as HTMLAnchorElement;\n const initial = input.value;\n const action = function () {\n if (input.value === initial) { return } // not changed\n const [min, val, max] = [input.min, input.value, input.max].map(n => parseInt(n) || 0);\n if (val < min || val > max) { // reset invalid/out-of-range\n input.value = initial;\n input.select();\n return;\n }\n let [page, url] = getVars(input.value); // eslint-disable-line prefer-const\n if (typeof trimParam === \"string\" && page === \"1\") { url = trim(url, trimParam) }\n link.href = url;\n link.click();\n };\n [\"change\", \"focus\"].forEach(e => input.addEventListener(e, () => input.select())); // auto-select\n input.addEventListener(\"focusout\", action); // trigger action\n input.addEventListener(\"keypress\", e => { if (e.key === \"Enter\") { action() } }); // trigger action\n };\n\n // Trim the ${page-param}=1 params in links\n const trim = (a:string, param:string) =>\n a.replace(new RegExp(`[?&]${param}=1\\\\b(?!&)|\\\\b${param}=1&`), \"\");\n\n // Public interface\n return {\n version: \"8.6.3\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document;\n const elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const uint8array = Uint8Array.from(atob(el.getAttribute(\"data-pagy\") as string), c => c.charCodeAt(0));\n const [keyword, ...args] = JSON.parse((new TextDecoder()).decode(uint8array)) as JsonArgs; // base64-utf8 -> JSON -> Array\n if (keyword === \"nav\") {\n initNav(el as NavElement, args as unknown as NavArgs);\n } else if (keyword === \"combo\") {\n initCombo(el, args as unknown as ComboArgs);\n } else if (keyword === \"selector\") {\n initSelector(el, args as unknown as SelectorArgs);\n } else {\n console.warn(\"Skipped Pagy.init() for: %o\\nUnknown keyword '%s'\", el, keyword);\n }\n } catch (err) { console.warn(\"Skipped Pagy.init() for: %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n"
|
6
6
|
],
|
7
|
-
"mappings": "AAgBA,IAAM,GAAQ,IAAM,CAElB,MAAM,EAAc,IAAI,eACpB,KAAW,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M,OAAO,CAAC,CAAC,EAChF,EAAM,iBAAiB,WAAY,CAAM,EACzC,EAAM,iBAAiB,WAAY,KAAK,CAAE,GAAI,EAAE,MAAQ,QAAW,EAAO,EAAK,GAI3E,EAAO,CAAC,EAAU,IACpB,EAAE,QAAQ,IAAI,OAAO,OAAO,kBAAsB,MAAU,EAAG,EAAE,EAGrE,MAAO,CACL,QAAS,QAGT,IAAI,CAAC,EAAc,CAEjB,MAAM,GADW,aAAe,QAAU,EAAM,UACxB,iBAAiB,aAAa,EACtD,QAAW,KAAM,EACf,GAAI,CACF,MAAM,EAAqB,WAAW,KAAK,KAAK,EAAG,aAAa,WAAW,CAAW,EAAG,KAAK,EAAE,WAAW,CAAC,CAAC,GACtG,KAAY,GAAQ,KAAK,OAAO,IAAI,YAAY,GAAG,OAAO,CAAU,CAAC,EAC5E,GAAI,IAAY,MACd,EAAQ,EAAkB,CAA0B,UAC3C,IAAY,QACrB,EAAU,EAAI,CAA4B,UACjC,IAAY,WACrB,EAAa,EAAI,CAA+B,MAEhD,SAAQ,KAAK,oDAAqD,EAAI,CAAO,QAExE,EAAP,CAAc,QAAQ,KAAK,kCAAmC,EAAI,CAAG,GAG7E,IACC",
|
8
|
+
"debugId": "B9DC02765C7A5B6764756E2164756E21",
|
9
9
|
"names": []
|
10
10
|
}
|
data/javascripts/pagy.mjs
CHANGED
@@ -73,7 +73,7 @@ const Pagy = (() => {
|
|
73
73
|
};
|
74
74
|
const trim = (a, param) => a.replace(new RegExp(`[?&]${param}=1\\b(?!&)|\\b${param}=1&`), "");
|
75
75
|
return {
|
76
|
-
version: "8.6.
|
76
|
+
version: "8.6.3",
|
77
77
|
init(arg) {
|
78
78
|
const target = arg instanceof Element ? arg : document;
|
79
79
|
const elements = target.querySelectorAll("[data-pagy]");
|
data/lib/pagy/countless.rb
CHANGED
data/lib/pagy/extras/gearbox.rb
CHANGED
@@ -19,6 +19,18 @@ class Pagy # :nodoc:
|
|
19
19
|
@items = gears[@page - 1] || gears.last
|
20
20
|
end
|
21
21
|
|
22
|
+
# Setup @offset based on the :gearbox_items variable
|
23
|
+
def setup_offset_var
|
24
|
+
return super if !@vars[:gearbox_extra] || @vars[:items_extra]
|
25
|
+
|
26
|
+
gears = @vars[:gearbox_items]
|
27
|
+
@offset = if @page <= gears.count
|
28
|
+
gears[0, @page - 1].sum
|
29
|
+
else
|
30
|
+
gears.sum + (gears.last * (@page - gears.count - 1))
|
31
|
+
end + @outset
|
32
|
+
end
|
33
|
+
|
22
34
|
# Setup Pagy @last based on the :gearbox_items variable and @count
|
23
35
|
def setup_last_var
|
24
36
|
return super if !@vars[:gearbox_extra] || @vars[:items_extra]
|
@@ -38,18 +50,6 @@ class Pagy # :nodoc:
|
|
38
50
|
end)
|
39
51
|
@last = vars[:max_pages] if vars[:max_pages] && @last > vars[:max_pages]
|
40
52
|
end
|
41
|
-
|
42
|
-
# Setup @offset based on the :gearbox_items variable
|
43
|
-
def setup_offset_var
|
44
|
-
return super if !@vars[:gearbox_extra] || @vars[:items_extra]
|
45
|
-
|
46
|
-
gears = @vars[:gearbox_items]
|
47
|
-
@offset = if @page <= gears.count
|
48
|
-
gears[0, @page - 1].sum
|
49
|
-
else
|
50
|
-
gears.sum + (gears.last * (@page - gears.count - 1))
|
51
|
-
end + @outset
|
52
|
-
end
|
53
53
|
end
|
54
54
|
prepend GearboxExtra
|
55
55
|
end
|
data/lib/pagy/extras/js_tools.rb
CHANGED
@@ -13,11 +13,11 @@ class Pagy # :nodoc:
|
|
13
13
|
# `Pagy` instance method used by the `pagy*_nav_js` helpers.
|
14
14
|
# It returns the sequels of width/series generated from the :steps hash
|
15
15
|
# Example:
|
16
|
-
# >> pagy = Pagy.new(count:1000, page: 20, steps: {0 =>
|
16
|
+
# >> pagy = Pagy.new(count:1000, page: 20, steps: {0 => 5, 350 => 7, 550 => 9})
|
17
17
|
# >> pagy.sequels
|
18
|
-
# #=> { "0" => [
|
19
|
-
# "350" => [1,
|
20
|
-
# "550" => [1
|
18
|
+
# #=> { "0" => [18, 19, "20", 21, 22],
|
19
|
+
# "350" => [1, :gap, 19, "20", 21, :gap, 50],
|
20
|
+
# "550" => [1 :gap, 18, 19, "20", 21, 22, :gap, 50] }
|
21
21
|
# Notice: if :steps is false it will use the single {0 => @vars[:size]} size
|
22
22
|
def sequels(steps: @vars[:steps] || { 0 => @vars[:size] }, **_)
|
23
23
|
raise VariableError.new(self, :steps, 'to define the 0 width', steps) unless steps.key?(0)
|
data/lib/pagy/extras/overflow.rb
CHANGED
@@ -67,7 +67,7 @@ class Pagy # :nodoc:
|
|
67
67
|
raise # same as without the extra
|
68
68
|
when :empty_page
|
69
69
|
@offset = @items = @from = @to = 0 # vars relative to the actual page
|
70
|
-
@vars[:size] =
|
70
|
+
@vars[:size] = 0 # no page in the series
|
71
71
|
self
|
72
72
|
else
|
73
73
|
raise VariableError.new(self, :overflow, 'to be in [:empty_page, :exception]', @vars[:overflow])
|
data/lib/pagy.rb
CHANGED
@@ -5,7 +5,7 @@ require 'pathname'
|
|
5
5
|
|
6
6
|
# Core class
|
7
7
|
class Pagy
|
8
|
-
VERSION = '8.6.
|
8
|
+
VERSION = '8.6.3'
|
9
9
|
|
10
10
|
# Gem root pathname to get the path of Pagy files stylesheets, javascripts, apps, locales, etc.
|
11
11
|
def self.root
|
@@ -29,10 +29,10 @@ class Pagy
|
|
29
29
|
normalize_vars(vars)
|
30
30
|
setup_vars(count: 0, page: 1, outset: 0)
|
31
31
|
setup_items_var
|
32
|
+
setup_offset_var
|
32
33
|
setup_last_var
|
33
34
|
raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
|
34
35
|
|
35
|
-
setup_offset_var
|
36
36
|
@from = [@offset - @outset + 1, @count].min
|
37
37
|
@to = [@offset - @outset + @items, @count].min
|
38
38
|
@in = [@to - @from + 1, @count].min
|
@@ -43,7 +43,7 @@ class Pagy
|
|
43
43
|
# Return the array of page numbers and :gap items e.g. [1, :gap, 8, "9", 10, :gap, 36]
|
44
44
|
def series(size: @vars[:size], **_)
|
45
45
|
raise VariableError.new(self, :size, 'to be an Integer >= 0', size) \
|
46
|
-
unless size.is_a?(Integer)
|
46
|
+
unless size.is_a?(Integer) && size >= 0
|
47
47
|
return [] if size.zero?
|
48
48
|
|
49
49
|
[].tap do |series|
|
@@ -53,13 +53,13 @@ class Pagy
|
|
53
53
|
left = ((size - 1) / 2.0).floor # left half might be 1 page shorter for even size
|
54
54
|
start = if @page <= left # beginning pages
|
55
55
|
1
|
56
|
-
elsif @page > @last -
|
56
|
+
elsif @page > (@last - size + left) # end pages
|
57
57
|
@last - size + 1
|
58
58
|
else # intermediate pages
|
59
59
|
@page - left
|
60
60
|
end
|
61
61
|
series.push(*start...start + size)
|
62
|
-
#
|
62
|
+
# Set first and last pages plus gaps when needed, respecting the size
|
63
63
|
if vars[:ends] && size >= 7
|
64
64
|
series[0] = 1 unless series[0] == 1
|
65
65
|
series[1] = :gap unless series[1] == 2
|
@@ -101,17 +101,17 @@ class Pagy
|
|
101
101
|
setup_vars(items: 1)
|
102
102
|
end
|
103
103
|
|
104
|
+
# Setup @offset (overridden by the gearbox extra)
|
105
|
+
def setup_offset_var
|
106
|
+
@offset = (@items * (@page - 1)) + @outset # may be already set from gear_box
|
107
|
+
end
|
108
|
+
|
104
109
|
# Setup @last (overridden by the gearbox extra)
|
105
110
|
def setup_last_var
|
106
111
|
@last = [(@count.to_f / @items).ceil, 1].max
|
107
112
|
@last = vars[:max_pages] if vars[:max_pages] && @last > vars[:max_pages]
|
108
113
|
end
|
109
114
|
alias setup_pages_var setup_last_var
|
110
|
-
|
111
|
-
# Setup @offset based on the :gearbox_items variable
|
112
|
-
def setup_offset_var
|
113
|
-
@offset = (@items * (@page - 1)) + @outset # may be already set from gear_box
|
114
|
-
end
|
115
115
|
end
|
116
116
|
|
117
117
|
require_relative 'pagy/extras/size' # will be opt in in v9.0
|
data/locales/ar.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.6.
|
4
|
+
version: 8.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Domizio Demichelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Agnostic pagination in plain ruby. It does it all. Better.
|
14
14
|
email:
|
@@ -27,7 +27,9 @@ files:
|
|
27
27
|
- apps/tmp/calendar.sqlite3-shm
|
28
28
|
- apps/tmp/calendar.sqlite3-wal
|
29
29
|
- apps/tmp/local_secret.txt
|
30
|
-
- apps/tmp/pagy-
|
30
|
+
- apps/tmp/pagy-keyset.sqlite3
|
31
|
+
- apps/tmp/pagy-keyset.sqlite3-shm
|
32
|
+
- apps/tmp/pagy-keyset.sqlite3-wal
|
31
33
|
- bin/pagy
|
32
34
|
- config/pagy.rb
|
33
35
|
- javascripts/pagy-module.js
|