pagy 8.4.5 → 8.6.1
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 +4 -4
- data/apps/calendar.ru +681 -2136
- data/apps/demo.ru +4 -5
- data/apps/rails.ru +3 -2
- data/apps/repro.ru +1 -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 -0
- data/apps/tmp/pagy-rails.sqlite3 +0 -0
- data/bin/pagy +12 -13
- data/config/pagy.rb +17 -19
- 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 +2 -2
- data/javascripts/pagy.mjs +1 -1
- data/lib/pagy/calendar/day.rb +3 -2
- data/lib/pagy/calendar/month.rb +3 -2
- data/lib/pagy/calendar/quarter.rb +3 -2
- data/lib/pagy/calendar/unit.rb +106 -0
- data/lib/pagy/calendar/week.rb +2 -2
- data/lib/pagy/calendar/year.rb +3 -2
- data/lib/pagy/calendar.rb +54 -97
- data/lib/pagy/countless.rb +4 -1
- data/lib/pagy/extras/calendar.rb +34 -4
- data/lib/pagy/extras/i18n.rb +1 -1
- data/lib/pagy/extras/js_tools.rb +1 -1
- data/lib/pagy/extras/metadata.rb +5 -1
- data/lib/pagy/extras/overflow.rb +3 -2
- data/lib/pagy/extras/size.rb +40 -0
- data/lib/pagy/frontend.rb +1 -1
- data/lib/pagy.rb +29 -38
- data/locales/ar.yml +6 -8
- metadata +9 -3
- data/lib/pagy/calendar/helper.rb +0 -65
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.
|
21
|
+
VERSION = '8.6.1'
|
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:
|
383
|
+
<h2>pagy<%= prefix %>_nav <span class="notes">Classic 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:
|
387
|
+
<h2>pagy<%= prefix %>_nav_js <span class="notes">Classic 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
391
|
<h2>pagy<%= prefix %>_nav_js <span class="notes">Responsive <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 =>
|
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.
|
18
|
+
VERSION = '8.6.1'
|
19
19
|
|
20
20
|
# Gemfile
|
21
21
|
require 'bundler/inline'
|
@@ -26,6 +26,8 @@ gemfile(ENV['PAGY_INSTALL_BUNDLE'] == 'true') do
|
|
26
26
|
gem 'oj'
|
27
27
|
gem 'puma'
|
28
28
|
gem 'rails'
|
29
|
+
# activerecord/sqlite3_adapter.rb probably useless) constraint !!!
|
30
|
+
# https://github.com/rails/rails/blame/v7.1.3.4/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb#L14
|
29
31
|
gem 'sqlite3', '~> 1.4.0'
|
30
32
|
end
|
31
33
|
|
@@ -61,7 +63,6 @@ end
|
|
61
63
|
require 'pagy/extras/pagy'
|
62
64
|
require 'pagy/extras/items'
|
63
65
|
require 'pagy/extras/overflow'
|
64
|
-
Pagy::DEFAULT[:size] = [1, 4, 4, 1]
|
65
66
|
Pagy::DEFAULT[:items] = 10
|
66
67
|
Pagy::DEFAULT[:overflow] = :empty_page
|
67
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.
|
18
|
+
VERSION = '8.6.1'
|
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'
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
4c768dd9af0cc4594a919e6d97ad57eae7eb49ff053ff829c361a3d8aa7364023f94aa9f9613d122a3c42803217a44c4ddf9846d6a300e7a78fcaa344decd317
|
Binary file
|
data/bin/pagy
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
VERSION = '8.
|
4
|
+
VERSION = '8.6.1'
|
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'
|
8
|
+
PORT = '8000'
|
8
9
|
|
9
10
|
require_relative '../lib/optimist'
|
10
11
|
opts = Optimist.options do
|
@@ -21,19 +22,19 @@ opts = Optimist.options do
|
|
21
22
|
pagy clone APP Clone APP to the current dir
|
22
23
|
pagy APPFILE [options] Develop APPFILE from local path
|
23
24
|
EXAMPLES
|
24
|
-
pagy demo Showcase demo at http
|
25
|
+
pagy demo Showcase demo at http://#{HOST}:#{PORT}
|
25
26
|
pagy clone repro Clone repro to ./repro.ru
|
26
|
-
pagy ~/my-repro.ru Develop ~/my-repro.ru at
|
27
|
+
pagy ~/my-repro.ru Develop ~/my-repro.ru at#{HOST}:#{PORT}
|
27
28
|
HEAD
|
28
29
|
text 'Rackup options'
|
29
30
|
opt :env, 'Environment', default: 'development'
|
30
|
-
opt :host, 'Host', default:
|
31
|
-
opt :port, 'Port', default:
|
31
|
+
opt :host, 'Host', default: HOST, short: :o
|
32
|
+
opt :port, 'Port', default: PORT
|
32
33
|
opt :install, 'Install bundle for users', default: true
|
33
34
|
if LINUX
|
34
35
|
text 'Rerun options'
|
35
|
-
opt :rerun,
|
36
|
-
opt :clear,
|
36
|
+
opt :rerun, 'Enable rerun for development', default: true
|
37
|
+
opt :clear, 'Clear screen before each rerun'
|
37
38
|
end
|
38
39
|
text 'Other options'
|
39
40
|
opt :quiet, 'Quiet mode for development'
|
@@ -41,9 +42,7 @@ opts = Optimist.options do
|
|
41
42
|
end
|
42
43
|
Optimist.educate if ARGV.empty?
|
43
44
|
|
44
|
-
run_from_repo = File.exist?(File.expand_path('../pagy.gemspec',
|
45
|
-
# Never install if run from pagy repo (for pagy devs)
|
46
|
-
opts[:install] = false if run_from_repo && !ENV['CI']
|
45
|
+
run_from_repo = File.exist?(File.expand_path('../pagy.gemspec', __dir__))
|
47
46
|
|
48
47
|
# Handles gems
|
49
48
|
require 'bundler/inline'
|
@@ -55,7 +54,7 @@ gemfile(opts[:install]) do
|
|
55
54
|
gem 'rerun' if LINUX
|
56
55
|
end
|
57
56
|
|
58
|
-
path = ->(app) { File.expand_path("../apps/#{app}.ru",
|
57
|
+
path = ->(app) { File.expand_path("../apps/#{app}.ru", __dir__) }
|
59
58
|
arg = ARGV.shift
|
60
59
|
if arg.eql?('clone')
|
61
60
|
arg = ARGV.shift
|
@@ -82,7 +81,7 @@ else
|
|
82
81
|
end
|
83
82
|
Optimist.die("#{file.inspect} app not found") unless File.exist?(file)
|
84
83
|
# Run command
|
85
|
-
gem_dir = File.expand_path('..',
|
84
|
+
gem_dir = File.expand_path('..', __dir__)
|
86
85
|
rackup = "rackup -I #{gem_dir}/lib -r pagy -o #{opts[:host]} -p #{opts[:port]} -E #{opts[:env]} #{file}"
|
87
86
|
rackup << ' -q' if opts[:quiet]
|
88
87
|
if opts[:rerun]
|
data/config/pagy.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# Pagy initializer file (8.
|
3
|
+
# Pagy initializer file (8.6.1)
|
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] =
|
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
|
38
|
-
# Pagy::Calendar::
|
39
|
-
#
|
40
|
-
# Pagy::Calendar::
|
41
|
-
# Pagy::Calendar::
|
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 =>
|
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)
|
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.
|
76
|
+
version: "8.6.1",
|
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.
|
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",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=EB723B90BB158B5C64756e2164756e21
|
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.
|
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",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=EB723B90BB158B5C64756e2164756e21
|
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.
|
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.1\",\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
7
|
"mappings": "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",
|
8
|
-
"debugId": "
|
8
|
+
"debugId": "EB723B90BB158B5C64756e2164756e21",
|
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.
|
76
|
+
version: "8.6.1",
|
77
77
|
init(arg) {
|
78
78
|
const target = arg instanceof Element ? arg : document;
|
79
79
|
const elements = target.querySelectorAll("[data-pagy]");
|
data/lib/pagy/calendar/day.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
class Calendar # :nodoc:
|
6
|
-
#
|
7
|
-
class Day <
|
6
|
+
# Day unit subclass
|
7
|
+
class Day < Unit
|
8
8
|
DEFAULT = { size: 31, # rubocop:disable Style/MutableConstant
|
9
|
+
ends: false,
|
9
10
|
order: :asc,
|
10
11
|
format: '%d' }
|
11
12
|
|
data/lib/pagy/calendar/month.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
class Calendar # :nodoc:
|
6
|
-
#
|
7
|
-
class Month <
|
6
|
+
# Month unit subclass
|
7
|
+
class Month < Unit
|
8
8
|
DEFAULT = { size: 12, # rubocop:disable Style/MutableConstant
|
9
|
+
ends: false,
|
9
10
|
order: :asc,
|
10
11
|
format: '%b' }
|
11
12
|
|
@@ -3,9 +3,10 @@
|
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
class Calendar # :nodoc:
|
6
|
-
#
|
7
|
-
class Quarter <
|
6
|
+
# Quarter unit subclass
|
7
|
+
class Quarter < Unit
|
8
8
|
DEFAULT = { size: 4, # rubocop:disable Style/MutableConstant
|
9
|
+
ends: false,
|
9
10
|
order: :asc,
|
10
11
|
format: 'Q%q' } # '%q' token
|
11
12
|
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support'
|
4
|
+
require 'active_support/core_ext/time'
|
5
|
+
require 'active_support/core_ext/date_and_time/calculations'
|
6
|
+
require 'active_support/core_ext/numeric/time'
|
7
|
+
require 'active_support/core_ext/integer/time'
|
8
|
+
|
9
|
+
class Pagy # :nodoc:
|
10
|
+
class Calendar < Hash # :nodoc:
|
11
|
+
# Base class for time units subclasses (Year, Quarter, Month, Week, Day)
|
12
|
+
class Unit < Pagy
|
13
|
+
attr_reader :order, :from, :to
|
14
|
+
|
15
|
+
# Merge and validate the options, do some simple arithmetic and set a few instance variables
|
16
|
+
def initialize(vars) # rubocop:disable Lint/MissingSuper
|
17
|
+
raise InternalError, 'Pagy::Calendar::Unit is a base class; use one of its subclasses' \
|
18
|
+
if instance_of?(Pagy::Calendar::Unit)
|
19
|
+
|
20
|
+
vars = self.class::DEFAULT.merge(vars) # subclass specific default
|
21
|
+
normalize_vars(vars) # general default
|
22
|
+
setup_vars(page: 1)
|
23
|
+
setup_unit_vars
|
24
|
+
raise OverflowError.new(self, :page, "in 1..#{@last}", @page) if @page > @last
|
25
|
+
|
26
|
+
@prev = (@page - 1 unless @page == 1)
|
27
|
+
@next = @page == @last ? (1 if @vars[:cycle]) : @page + 1
|
28
|
+
end
|
29
|
+
|
30
|
+
# The label for the current page (it can pass along the I18n gem opts when it's used with the i18n extra)
|
31
|
+
def label(opts = {})
|
32
|
+
label_for(@page, opts)
|
33
|
+
end
|
34
|
+
|
35
|
+
# The label for any page (it can pass along the I18n gem opts when it's used with the i18n extra)
|
36
|
+
def label_for(page, opts = {})
|
37
|
+
opts[:format] ||= @vars[:format]
|
38
|
+
localize(starting_time_for(page.to_i), opts) # page could be a string
|
39
|
+
end
|
40
|
+
|
41
|
+
protected
|
42
|
+
|
43
|
+
# The page that includes time
|
44
|
+
# In case of out of range time, the :fit_time option avoids the outOfRangeError
|
45
|
+
# and returns the closest page to the passed time argument (first or last page)
|
46
|
+
def page_at(time, **opts)
|
47
|
+
fit_time = time
|
48
|
+
fit_final = @final - 1
|
49
|
+
unless time.between?(@initial, fit_final)
|
50
|
+
raise OutOfRangeError.new(self, :time, "between #{@initial} and #{fit_final}", time) unless opts[:fit_time]
|
51
|
+
|
52
|
+
if time < @final
|
53
|
+
fit_time = @initial
|
54
|
+
ordinal = 'first'
|
55
|
+
else
|
56
|
+
fit_time = fit_final
|
57
|
+
ordinal = 'last'
|
58
|
+
end
|
59
|
+
warn "Pagy::Calendar#page_at: Rescued #{time} out of range by returning the #{ordinal} page."
|
60
|
+
end
|
61
|
+
offset = page_offset_at(fit_time) # offset starts from 0
|
62
|
+
@order == :asc ? offset + 1 : @last - offset
|
63
|
+
end
|
64
|
+
|
65
|
+
# Base class method for the setup of the unit variables (subclasses must implement it and call super)
|
66
|
+
def setup_unit_vars
|
67
|
+
raise VariableError.new(self, :format, 'to be a strftime format', @vars[:format]) unless @vars[:format].is_a?(String)
|
68
|
+
raise VariableError.new(self, :order, 'to be in [:asc, :desc]', @order) \
|
69
|
+
unless %i[asc desc].include?(@order = @vars[:order])
|
70
|
+
|
71
|
+
@starting, @ending = @vars[:period]
|
72
|
+
raise VariableError.new(self, :period, 'to be a an Array of min and max TimeWithZone instances', @vars[:period]) \
|
73
|
+
unless @starting.is_a?(ActiveSupport::TimeWithZone) \
|
74
|
+
&& @ending.is_a?(ActiveSupport::TimeWithZone) && @starting <= @ending
|
75
|
+
end
|
76
|
+
|
77
|
+
# Apply the strftime format to the time (overridden by the i18n extra when localization is required)
|
78
|
+
def localize(time, opts)
|
79
|
+
time.strftime(opts[:format])
|
80
|
+
end
|
81
|
+
|
82
|
+
# Number of time units to offset from the @initial time, in order to get the ordered starting time for the page.
|
83
|
+
# Used in starting_time_for(page) where page starts from 1 (e.g. page to starting_time means subtracting 1)
|
84
|
+
def time_offset_for(page)
|
85
|
+
@order == :asc ? page - 1 : @last - page
|
86
|
+
end
|
87
|
+
|
88
|
+
# Period of the active page (used internally for nested units)
|
89
|
+
def active_period
|
90
|
+
[[@starting, @from].max, [@to - 1, @ending].min] # -1 sec: include only last unit day
|
91
|
+
end
|
92
|
+
|
93
|
+
# :nocov:
|
94
|
+
# This method must be implemented by the unit subclass
|
95
|
+
def starting_time_for(*)
|
96
|
+
raise NoMethodError, 'the starting_time_for method must be implemented by the unit subclass'
|
97
|
+
end
|
98
|
+
|
99
|
+
# This method must be implemented by the unit subclass
|
100
|
+
def page_offset_at(*)
|
101
|
+
raise NoMethodError, 'the page_offset_at method must be implemented by the unit subclass'
|
102
|
+
end
|
103
|
+
# :nocov:
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/pagy/calendar/week.rb
CHANGED
data/lib/pagy/calendar/year.rb
CHANGED
@@ -3,9 +3,10 @@
|
|
3
3
|
|
4
4
|
class Pagy # :nodoc:
|
5
5
|
class Calendar # :nodoc:
|
6
|
-
#
|
7
|
-
class Year <
|
6
|
+
# Year unit subclass
|
7
|
+
class Year < Unit
|
8
8
|
DEFAULT = { size: 10, # rubocop:disable Style/MutableConstant
|
9
|
+
ends: false,
|
9
10
|
order: :asc,
|
10
11
|
format: '%Y' }
|
11
12
|
|