pagy 8.6.0 → 8.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 013eaae07b22187a35f7f0d3a4af1fab4116898753a980608cb92206f97ab7f1
4
- data.tar.gz: 112ecb19602649ba6f3afcdb6970033de2da04d99323862c23bd848cbde91229
3
+ metadata.gz: ecb6acd23c9fdc3becbfb216f79fd6cec4e25071963d20c53e7ad89e561af9eb
4
+ data.tar.gz: e3d4f4cb0c5b3d56730c3de331a3a7bb52161441e02c51dfaa081802d4b826a6
5
5
  SHA512:
6
- metadata.gz: a6628de44f14b335a77033c22137ff5010899a4f9582323bd10579fda3bc4a4021bdac3bb95ac5d092f988ab49219c02a7cf8f9c8e0c1adca7c34f32288503ac
7
- data.tar.gz: 9bb3d14d068e87b4863781ed0469f34702d21a71d999c9069c67eade9017ec2f33b21868b6ebe79cd2cc8ff3bf1017b2978ea0088f165fa48bb283f992d3ef93
6
+ metadata.gz: 28a45fe02d58b4364a1f349b39140339988d669395b54209a449ddfc5efca7561d46c7c74dfd616ecaa2992c4de41569552eb4445273425a0d469b878ac8fc2f
7
+ data.tar.gz: 184d3c67eca97b36c6b95643bb1bbf9981112f0c93f77ed2b412100876286431f60097d8cdfa083fc9549c5ef9af9710a66ef4ff2cfe1315d3ec9f6a1fc6dd9d
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.0'
18
+ VERSION = '8.6.2'
19
19
 
20
20
  # Gemfile
21
21
  require 'bundler/inline'
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.0'
21
+ VERSION = '8.6.2'
22
22
 
23
23
  require 'bundler/inline'
24
24
  require 'bundler'
@@ -44,7 +44,6 @@ end
44
44
  require 'pagy/extras/items'
45
45
  require 'pagy/extras/trim'
46
46
  Pagy::DEFAULT[:trim_extra] = false # opt-in trim
47
- Pagy::DEFAULT[:size] = [1, 4, 4, 1] # old size default
48
47
 
49
48
  # sinatra setup
50
49
  require 'sinatra/base'
@@ -381,18 +380,18 @@ for details</p>
381
380
  <%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'simple-nav', aria_label: 'Pages simple-nav', size: 5) %>
382
381
  <%= highlight(html) %>
383
382
 
384
- <h2>pagy<%= prefix %>_nav <span class="notes">Classic nav <code>size: [1,4,4,1]</code></span></h2>
383
+ <h2>pagy<%= prefix %>_nav <span class="notes">Fast nav <code>size: 7</code></span></h2>
385
384
  <%= html = send(:"pagy#{prefix}_nav", @pagy, id: 'nav', aria_label: 'Pages nav') %>
386
385
  <%= highlight(html) %>
387
386
 
388
- <h2>pagy<%= prefix %>_nav_js <span class="notes">Classic nav <code>size: [1,4,4,1]</code></span></h2>
387
+ <h2>pagy<%= prefix %>_nav_js <span class="notes">Fast nav <code>size: 7</code></span></h2>
389
388
  <%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js', aria_label: 'Pages nav_js') %>
390
389
  <%= highlight(html) %>
391
390
 
392
- <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>
393
392
  <%= html = send(:"pagy#{prefix}_nav_js", @pagy, id: 'nav-js-responsive',
394
393
  aria_label: 'Pages nav_js_responsive',
395
- steps: { 0 => [1,1,1,1], 500 => [1,3,3,1], 750 => [1,5,5,1], 1000 => [2,6,6,2] }) %>
394
+ steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
396
395
  <%= highlight(html) %>
397
396
 
398
397
  <h2>pagy<%= prefix %>_combo_nav_js</h2>
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.0'
18
+ VERSION = '8.6.2'
19
19
 
20
20
  # Gemfile
21
21
  require 'bundler/inline'
@@ -63,7 +63,6 @@ end
63
63
  require 'pagy/extras/pagy'
64
64
  require 'pagy/extras/items'
65
65
  require 'pagy/extras/overflow'
66
- Pagy::DEFAULT[:size] = [1, 4, 4, 1]
67
66
  Pagy::DEFAULT[:items] = 10
68
67
  Pagy::DEFAULT[:overflow] = :empty_page
69
68
  Pagy::DEFAULT.freeze
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.0'
18
+ VERSION = '8.6.2'
19
19
 
20
20
  require 'bundler/inline'
21
21
  require 'bundler'
@@ -34,7 +34,6 @@ require 'pagy/extras/pagy'
34
34
  require 'pagy/extras/items'
35
35
  require 'pagy/extras/overflow'
36
36
  Pagy::DEFAULT[:overflow] = :empty_page
37
- Pagy::DEFAULT[:size] = [1, 4, 4, 1]
38
37
  Pagy::DEFAULT.freeze
39
38
 
40
39
  require 'sinatra/base'
@@ -165,7 +164,7 @@ __END__
165
164
 
166
165
  <h4>pagy_nav_js</h4>
167
166
  <%= pagy_nav_js(@pagy, id: 'nav-js-responsive', aria_label: 'Pages nav_js_responsove',
168
- steps: { 0 => [1,1,1,1], 500 => [1,3,3,1], 750 => [1,5,5,1], 1000 => [2,6,6,2] }) %>
167
+ steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
169
168
 
170
169
  <h4>pagy_combo_nav_js</h4>
171
170
  <%= pagy_combo_nav_js(@pagy, id: 'combo-nav-js', aria_label: 'Pages combo_nav_js') %>
Binary file
Binary file
Binary file
@@ -1 +1 @@
1
- 4c768dd9af0cc4594a919e6d97ad57eae7eb49ff053ff829c361a3d8aa7364023f94aa9f9613d122a3c42803217a44c4ddf9846d6a300e7a78fcaa344decd317
1
+ 4c57eebd7544c7f0acc9943ab614ab3da71d2461f5581ed8d41e9b8aa1bf23bff831f82e934eed96c608da0feac2c3dd21383c269d896cf01fcd6fa81aca2462
data/bin/pagy CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- VERSION = '8.6.0'
4
+ VERSION = '8.6.2'
5
5
  APPS = %w[repro rails demo calendar].freeze
6
6
  LINUX = RbConfig::CONFIG['host_os'].include?('linux')
7
7
  HOST = '0.0.0.0'
data/config/pagy.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Pagy initializer file (8.6.0)
3
+ # Pagy initializer file (8.6.2)
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
 
@@ -11,7 +11,8 @@
11
11
  # Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
12
12
  # Here are the few that make more sense as DEFAULTs:
13
13
  # Pagy::DEFAULT[:items] = 20 # default
14
- # Pagy::DEFAULT[:size] = [1,4,4,1] # default in pagy < 7.0
14
+ # Pagy::DEFAULT[:size] = 7 # default
15
+ # Pagy::DEFAULT[:ends] = true # default
15
16
  # Pagy::DEFAULT[:page_param] = :page # default
16
17
  # Pagy::DEFAULT[:count_args] = [] # example for non AR ORMs
17
18
 
@@ -20,6 +21,13 @@
20
21
  # See https://ddnexus.github.io/pagy/categories/extra
21
22
 
22
23
 
24
+ # Legacy Compatibility Extras
25
+
26
+ # Size extra: Enable the Array type for the `:size` variable (e.g. `size: [1,4,4,1]`)
27
+ # See https://ddnexus.github.io/pagy/docs/extras/size
28
+ # require 'pagy/extras/size' # must be required before the other extras
29
+
30
+
23
31
  # Backend Extras
24
32
 
25
33
  # Arel extra: For better performance utilizing grouped ActiveRecord collections:
@@ -33,21 +41,12 @@
33
41
  # Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
34
42
  # See https://ddnexus.github.io/pagy/docs/extras/calendar
35
43
  # require 'pagy/extras/calendar'
36
- # Default for each unit
37
- # Pagy::Calendar::Year::DEFAULT[:order] = :asc # Time direction of pagination
38
- # Pagy::Calendar::Year::DEFAULT[:format] = '%Y' # strftime format
39
- #
40
- # Pagy::Calendar::Quarter::DEFAULT[:order] = :asc # Time direction of pagination
41
- # Pagy::Calendar::Quarter::DEFAULT[:format] = '%Y-Q%q' # strftime format
42
- #
43
- # Pagy::Calendar::Month::DEFAULT[:order] = :asc # Time direction of pagination
44
- # Pagy::Calendar::Month::DEFAULT[:format] = '%Y-%m' # strftime format
45
- #
46
- # Pagy::Calendar::Week::DEFAULT[:order] = :asc # Time direction of pagination
47
- # Pagy::Calendar::Week::DEFAULT[:format] = '%Y-%W' # strftime format
48
- #
49
- # Pagy::Calendar::Day::DEFAULT[:order] = :asc # Time direction of pagination
50
- # Pagy::Calendar::Day::DEFAULT[:format] = '%Y-%m-%d' # strftime format
44
+ # Default for each calendar unit class in IRB:
45
+ # >> Pagy::Calendar::Year::DEFAULT
46
+ # >> Pagy::Calendar::Quarter::DEFAULT
47
+ # >> Pagy::Calendar::Month::DEFAULT
48
+ # >> Pagy::Calendar::Week::DEFAULT
49
+ # >> Pagy::Calendar::Day::DEFAULT
51
50
  #
52
51
  # Uncomment the following lines, if you need calendar localization without using the I18n extra
53
52
  # module LocalizePagyCalendar
@@ -125,7 +124,7 @@
125
124
 
126
125
  # Multi size var used by the *_nav_js helpers
127
126
  # See https://ddnexus.github.io/pagy/docs/extras/pagy#steps
128
- # Pagy::DEFAULT[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example
127
+ # Pagy::DEFAULT[:steps] = { 0 => 5, 540 => 7, 720 => 9 } # example
129
128
 
130
129
 
131
130
  # Feature Extras
@@ -167,7 +166,6 @@
167
166
  # set to false only if you want to make :jsonapi an opt-in variable
168
167
  # Pagy::DEFAULT[:jsonapi] = false # default true
169
168
 
170
-
171
169
  # Rails
172
170
  # Enable the .js file required by the helpers that use javascript
173
171
  # (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
@@ -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.0",
76
+ version: "8.6.2",
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.0",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)}}}})();
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.2",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=8A823851C046F97864756e2164756e21
3
+ //# debugId=9A17C02353E06CE464756E2164756E21
4
4
  //# sourceMappingURL=pagy.min.js.map
@@ -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.0",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)}}}})();
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.2",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=8A823851C046F97864756e2164756e21
3
+ //# debugId=9A17C02353E06CE464756E2164756E21
4
4
  //# sourceMappingURL=pagy.min.js.map
@@ -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.0\",\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"
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.2\",\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,EAAQ,QAAQ,KAAK,EAAE,OAAO,iBAA6B,WAAW,EAC/C,QAAQ,KAAM,EAAG,WAAW,CAAC,CAAC,CAAC,EAE/D,EAAU,CAAC,GAAgB,EAAQ,EAAS,EAAc,KAAuB,CACrF,MAAM,EAAY,EAAG,eAAiB,EAChC,EAAY,OAAO,KAAK,CAAO,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,EAAG,IAAM,EAAI,CAAC,EACjF,IAAI,GAAc,EAClB,MAAM,EAAY,CAAC,EAAU,EAAa,IACtC,EAAE,QAAQ,iBAAkB,CAAI,EAAE,QAAQ,kBAAmB,CAAK,EAwBtE,IAvBC,EAAG,mBAAsB,EA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AG,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": "9A17C02353E06CE464756E2164756E21",
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.0",
76
+ version: "8.6.2",
77
77
  init(arg) {
78
78
  const target = arg instanceof Element ? arg : document;
79
79
  const elements = target.querySelectorAll("[data-pagy]");
@@ -34,7 +34,7 @@ class Pagy # :nodoc:
34
34
  module SeriesOverride # :nodoc:
35
35
  # Override the original series.
36
36
  # Return nil if :countless_minimal is enabled
37
- def series(*, **)
37
+ def series(**)
38
38
  super unless @vars[:countless_minimal]
39
39
  end
40
40
  end
@@ -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
@@ -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 => [1,2,2,1], 350 => [2,3,3,2], 550 => [3,4,4,3]})
16
+ # >> pagy = Pagy.new(count:1000, page: 20, steps: {0 => 5, 350 => 7, 550 => 9})
17
17
  # >> pagy.sequels
18
- # #=> { "0" => [1, :gap, 18, 19, "20", 21, 22, :gap, 50],
19
- # "350" => [1, 2, :gap, 17, 18, 19, "20", 21, 22, 23, :gap, 49, 50],
20
- # "550" => [1, 2, 3, :gap, 16, 17, 18, 19, "20", 21, 22, 23, 24, :gap, 48, 49, 50] }
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)
@@ -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] = [] # no page in the series
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])
@@ -9,7 +9,7 @@ class Pagy # :nodoc:
9
9
  def series(size: @vars[:size], **_)
10
10
  return super unless size.is_a?(Array)
11
11
  return [] if size == []
12
- raise VariableError.new(self, :size, 'to be an Array of size 4 || 0', size) \
12
+ raise VariableError.new(self, :size, 'to be an Array of 4 Integers or []', size) \
13
13
  unless size.is_a?(Array) && size.size == 4 && size.all? { |num| !num.negative? rescue false } # rubocop:disable Style/RescueModifier
14
14
 
15
15
  [].tap do |series|
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.0'
8
+ VERSION = '8.6.2'
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
@@ -40,10 +40,10 @@ class Pagy
40
40
  @next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
41
41
  end
42
42
 
43
- # Return the array of page numbers and :gap items e.g. [1, :gap, 7, 8, "9", 10, 11, :gap, 36]
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
- raise VariableError.new(self, :size, 'to be a positive Integer or 0', size) \
46
- unless size.is_a?(Integer)
45
+ raise VariableError.new(self, :size, 'to be an Integer >= 0', size) \
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 - (size - left) # end pages
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
- # Insert first and last ends plus gaps when needed
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
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.0
4
+ version: 8.6.2
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-06-27 00:00:00.000000000 Z
11
+ date: 2024-07-01 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,6 @@ 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-rails.sqlite3
31
30
  - bin/pagy
32
31
  - config/pagy.rb
33
32
  - javascripts/pagy-module.js
Binary file