pagy 43.0.7 → 43.1.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 +1 -1
- data/apps/demo.ru +1 -1
- data/apps/keynav+root_key.ru +321 -0
- data/apps/keynav.ru +3 -1
- data/apps/keyset.ru +1 -1
- data/apps/keyset_sequel.ru +1 -1
- data/apps/rails.ru +1 -1
- data/apps/repro.ru +1 -1
- data/bin/pagy +1 -1
- data/config/pagy.rb +1 -1
- data/javascripts/ai_widget.js +1 -1
- data/javascripts/pagy.js +11 -10
- data/javascripts/pagy.js.map +3 -3
- data/javascripts/pagy.min.js +1 -1
- data/javascripts/pagy.mjs +10 -9
- data/lib/pagy/classes/exceptions.rb +0 -8
- data/lib/pagy/classes/keyset/keynav.rb +1 -1
- data/lib/pagy/classes/request.rb +14 -15
- data/lib/pagy/modules/abilities/linkable.rb +12 -15
- data/lib/pagy/modules/console.rb +2 -16
- data/lib/pagy/modules/searcher.rb +5 -7
- data/lib/pagy/toolbox/helpers/support/a_lambda.rb +1 -1
- data/lib/pagy/toolbox/paginators/calendar.rb +0 -1
- data/lib/pagy/toolbox/paginators/countless.rb +11 -14
- data/lib/pagy/toolbox/paginators/elasticsearch_rails.rb +16 -19
- data/lib/pagy/toolbox/paginators/keynav_js.rb +13 -16
- data/lib/pagy/toolbox/paginators/keyset.rb +6 -9
- data/lib/pagy/toolbox/paginators/meilisearch.rb +16 -19
- data/lib/pagy/toolbox/paginators/method.rb +10 -3
- data/lib/pagy/toolbox/paginators/offset.rb +7 -10
- data/lib/pagy/toolbox/paginators/searchkick.rb +16 -19
- data/lib/pagy.rb +5 -3
- data/locales/id.yml +1 -3
- data/locales/ja.yml +1 -3
- data/locales/km.yml +1 -3
- data/locales/sw.yml +2 -2
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c2d26c7bd62793daa6d3e9244fa9e01e21e13f9f2ae301b0e1a7611549f8fd69
|
|
4
|
+
data.tar.gz: 13d1f5785fc1eb8fdf771545c2b3f83778e8ce61fa942bff1ba9140a815052f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b465de78aeb499d2b7949d2ba1213fc77df827b3a48e7fb55e0b019c96b143ce20d5bb013e52555f7747911bd1ee314812a4b9f57ca1ab95e42b1f9bfa298caf
|
|
7
|
+
data.tar.gz: 689d5d5581ba78d43067f592888a19fc06d22df945158b124cea5b9eafd1a391a29969c28a798535f5f81059e92829d9a88cf52ba00f458f076e292545841370
|
data/apps/calendar.ru
CHANGED
data/apps/demo.ru
CHANGED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# DESCRIPTION
|
|
4
|
+
# Showcase the Keynav pagination with independent instances
|
|
5
|
+
#
|
|
6
|
+
# DOC
|
|
7
|
+
# https://ddnexus.github.io/pagy/playground/#keyset-apps
|
|
8
|
+
#
|
|
9
|
+
# BIN HELP
|
|
10
|
+
# pagy -h
|
|
11
|
+
#
|
|
12
|
+
# DEV USAGE
|
|
13
|
+
# pagy clone keynav
|
|
14
|
+
# pagy ./keynav.ru
|
|
15
|
+
#
|
|
16
|
+
# URL
|
|
17
|
+
# http://127.0.0.1:8000
|
|
18
|
+
|
|
19
|
+
VERSION = '43.1.1'
|
|
20
|
+
|
|
21
|
+
if VERSION != Pagy::VERSION
|
|
22
|
+
Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Bundle
|
|
26
|
+
require 'bundler/inline'
|
|
27
|
+
gemfile(!Pagy::ROOT.join('pagy.gemspec').exist?) do
|
|
28
|
+
source 'https://rubygems.org'
|
|
29
|
+
gem 'activerecord'
|
|
30
|
+
gem 'puma'
|
|
31
|
+
gem 'sinatra'
|
|
32
|
+
gem 'sqlite3'
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Sinatra setup
|
|
36
|
+
require 'sinatra/base'
|
|
37
|
+
# Sinatra application
|
|
38
|
+
class PagyKeynav < Sinatra::Base
|
|
39
|
+
include Pagy::Method
|
|
40
|
+
|
|
41
|
+
get('/javascripts/:file') do
|
|
42
|
+
format = params[:file].split('.').last
|
|
43
|
+
if format == 'js'
|
|
44
|
+
content_type 'application/javascript'
|
|
45
|
+
elsif format == 'map'
|
|
46
|
+
content_type 'application/json'
|
|
47
|
+
end
|
|
48
|
+
send_file Pagy::ROOT.join('javascripts', params[:file])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Root route/action
|
|
52
|
+
get '/' do
|
|
53
|
+
Time.zone = 'UTC'
|
|
54
|
+
|
|
55
|
+
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
|
56
|
+
@pagy1, @pets1 = pagy(:keynav_js, Pet.order(@order), limit: 4, root_key: 'animal1')
|
|
57
|
+
@ids1 = @pets1.pluck(:id)
|
|
58
|
+
@pagy2, @pets2 = pagy(:keynav_js, Pet.order(@order), limit: 4, root_key: 'animal2')
|
|
59
|
+
@ids2 = @pets2.pluck(:id)
|
|
60
|
+
erb :main
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
helpers do
|
|
64
|
+
def order_symbol(dir)
|
|
65
|
+
{ asc: '↗', desc: '↘' }[dir]
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Views
|
|
70
|
+
template :layout do
|
|
71
|
+
<<~ERB
|
|
72
|
+
<!DOCTYPE html>
|
|
73
|
+
<html lang="en">
|
|
74
|
+
<html>
|
|
75
|
+
<head>
|
|
76
|
+
<title>Pagy Keynav (root_key) App</title>
|
|
77
|
+
<script src="javascripts/pagy.js"></script>
|
|
78
|
+
<script>
|
|
79
|
+
window.addEventListener("load", Pagy.init);
|
|
80
|
+
</script>
|
|
81
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
82
|
+
<style type="text/css">
|
|
83
|
+
@media screen { html, body {
|
|
84
|
+
font-size: 1rem;
|
|
85
|
+
line-height: 1.2s;
|
|
86
|
+
padding: 0;
|
|
87
|
+
margin: 0;
|
|
88
|
+
} }
|
|
89
|
+
body {
|
|
90
|
+
background: white !important;
|
|
91
|
+
margin: 0 !important;
|
|
92
|
+
font-family: sans-serif !important;
|
|
93
|
+
}
|
|
94
|
+
.main-content {
|
|
95
|
+
padding: 1rem 1.5rem 2rem !important;
|
|
96
|
+
}
|
|
97
|
+
#content {
|
|
98
|
+
display: flex; /* Enables Flexbox */
|
|
99
|
+
flex-wrap: wrap; /* Allows stacking */
|
|
100
|
+
gap: 20px; /* Gap between items */
|
|
101
|
+
/* Just for visual clarity of the container boundaries */
|
|
102
|
+
/*padding: 10px;
|
|
103
|
+
background-color: #e0e7ff;
|
|
104
|
+
border-radius: 8px;
|
|
105
|
+
border: 2px dashed #6366f1; */
|
|
106
|
+
}
|
|
107
|
+
.box {
|
|
108
|
+
flex: 1; /* Grow to fill space */
|
|
109
|
+
min-width: 300px; /* Stack if space < 300px */
|
|
110
|
+
/* Visual Styling */
|
|
111
|
+
background-color: white;
|
|
112
|
+
padding: 25px;
|
|
113
|
+
border-radius: 6px;
|
|
114
|
+
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
|
115
|
+
border: 1px solid #ddd;
|
|
116
|
+
}
|
|
117
|
+
.pagy {
|
|
118
|
+
padding: .5em;
|
|
119
|
+
margin: .3em 0;
|
|
120
|
+
width: fit-content;
|
|
121
|
+
box-shadow: 5px 5px 10px 0px rgba(0,0,0,0.2);
|
|
122
|
+
}
|
|
123
|
+
<%= Pagy::ROOT.join('stylesheets/pagy.css').read %>
|
|
124
|
+
</style>
|
|
125
|
+
</head>
|
|
126
|
+
<body>
|
|
127
|
+
<%= yield %>
|
|
128
|
+
</body>
|
|
129
|
+
</html>
|
|
130
|
+
ERB
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
template :main do
|
|
134
|
+
<<~ERB
|
|
135
|
+
<div class="main-content">
|
|
136
|
+
<h1>Pagy Keynav App</h1>
|
|
137
|
+
<p>Self-contained, standalone app usable to easily reproduce any Keynav related pagy issue
|
|
138
|
+
with ActiveRecord sets.</p>
|
|
139
|
+
<p>The panels below show how to use the <code>:root_key</code> option for independent instances in the same request.</p>
|
|
140
|
+
|
|
141
|
+
<p>Notice that Keynav works also with Sequel sets.</p>
|
|
142
|
+
|
|
143
|
+
<h2>Versions</h2>
|
|
144
|
+
<ul>
|
|
145
|
+
<li>Ruby: <%= RUBY_VERSION %></li>
|
|
146
|
+
<li>Rack: <%= Rack::RELEASE %></li>
|
|
147
|
+
<li>Sinatra: <%= Sinatra::VERSION %></li>
|
|
148
|
+
<li>Pagy: <%= Pagy::VERSION %></li>
|
|
149
|
+
</ul>
|
|
150
|
+
|
|
151
|
+
<div id="content">
|
|
152
|
+
<div class="box">
|
|
153
|
+
<h3>Collection 1</h3>
|
|
154
|
+
<p id="records">@ids: <%= @ids1.join(',') %></p>
|
|
155
|
+
<div class="collection">
|
|
156
|
+
<table border="1" style="border-collapse: collapse; border-spacing: 0; padding: 0.2rem;">
|
|
157
|
+
<tr>
|
|
158
|
+
<th scope="col">animal <%= order_symbol(@order[:animal]) %></th>
|
|
159
|
+
<th scope="col">name <%= order_symbol(@order[:name]) %></th>
|
|
160
|
+
<th scope="col">birthdate <%= order_symbol(@order[:birthdate]) %></th>
|
|
161
|
+
<th scope="col">id <%= order_symbol(@order[:id]) %></th>
|
|
162
|
+
</tr>
|
|
163
|
+
<% @pets1.each do |pet| %>
|
|
164
|
+
<tr>
|
|
165
|
+
<td><%= pet.animal %></td>
|
|
166
|
+
<td><%= pet.name %></td>
|
|
167
|
+
<td><%= pet.birthdate %></td>
|
|
168
|
+
<td><%= pet.id %></td>
|
|
169
|
+
</tr>
|
|
170
|
+
<% end %>
|
|
171
|
+
</table>
|
|
172
|
+
</div>
|
|
173
|
+
|
|
174
|
+
<h4>@pagy.series_nav</h4>
|
|
175
|
+
<%= @pagy1.series_nav(id: 'series-nav',
|
|
176
|
+
aria_label: 'Pages (nav)') %>
|
|
177
|
+
|
|
178
|
+
<h4>@pagy.series_nav_js (responsive)</h4>
|
|
179
|
+
<%= @pagy1.series_nav_js(id: 'series-nav-js-responsive',
|
|
180
|
+
aria_label: 'Pages (nav_js_responsive)',
|
|
181
|
+
steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
|
|
182
|
+
<h4>@pagy.input_nav_js</h4>
|
|
183
|
+
<%= @pagy1.input_nav_js(id: 'input-nav-js',
|
|
184
|
+
aria_label: 'Pages (input_nav_js)') %>
|
|
185
|
+
|
|
186
|
+
<h4>@pagy.info_tag</h4>
|
|
187
|
+
<%= @pagy1.info_tag(id: 'pagy-info') %>
|
|
188
|
+
</div>
|
|
189
|
+
|
|
190
|
+
<div class="box">
|
|
191
|
+
<h3>Collection 2</h3>
|
|
192
|
+
<p id="records">@ids: <%= @ids2.join(',') %></p>
|
|
193
|
+
<div class="collection">
|
|
194
|
+
<table border="1" style="border-collapse: collapse; border-spacing: 0; padding: 0.2rem;">
|
|
195
|
+
<tr>
|
|
196
|
+
<th scope="col">animal <%= order_symbol(@order[:animal]) %></th>
|
|
197
|
+
<th scope="col">name <%= order_symbol(@order[:name]) %></th>
|
|
198
|
+
<th scope="col">birthdate <%= order_symbol(@order[:birthdate]) %></th>
|
|
199
|
+
<th scope="col">id <%= order_symbol(@order[:id]) %></th>
|
|
200
|
+
</tr>
|
|
201
|
+
<% @pets2.each do |pet| %>
|
|
202
|
+
<tr>
|
|
203
|
+
<td><%= pet.animal %></td>
|
|
204
|
+
<td><%= pet.name %></td>
|
|
205
|
+
<td><%= pet.birthdate %></td>
|
|
206
|
+
<td><%= pet.id %></td>
|
|
207
|
+
</tr>
|
|
208
|
+
<% end %>
|
|
209
|
+
</table>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<h4>@pagy.series_nav</h4>
|
|
213
|
+
<%= @pagy2.series_nav(id: 'series-nav',
|
|
214
|
+
aria_label: 'Pages (nav)') %>
|
|
215
|
+
|
|
216
|
+
<h4>@pagy.series_nav_js (responsive)</h4>
|
|
217
|
+
<%= @pagy2.series_nav_js(id: 'series-nav-js-responsive',
|
|
218
|
+
aria_label: 'Pages (nav_js_responsive)',
|
|
219
|
+
steps: { 0 => 5, 500 => 7, 750 => 9, 1000 => 11 }) %>
|
|
220
|
+
<h4>@pagy.input_nav_js</h4>
|
|
221
|
+
<%= @pagy2.input_nav_js(id: 'input-nav-js',
|
|
222
|
+
aria_label: 'Pages (input_nav_js)') %>
|
|
223
|
+
|
|
224
|
+
<h4>@pagy.info_tag</h4>
|
|
225
|
+
<%= @pagy2.info_tag(id: 'pagy-info') %>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
</div>
|
|
229
|
+
ERB
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# ActiveRecord setup
|
|
234
|
+
require 'active_record'
|
|
235
|
+
|
|
236
|
+
# Match the microsecods with the strings stored into the time columns of SQLite
|
|
237
|
+
# ActiveSupport::JSON::Encoding.time_precision = 6
|
|
238
|
+
|
|
239
|
+
# Log
|
|
240
|
+
output = ENV['APP_ENV'].equal?('showcase') ? IO::NULL : $stdout
|
|
241
|
+
ActiveRecord::Base.logger = Logger.new(output)
|
|
242
|
+
# SQLite DB files
|
|
243
|
+
dir = ENV['APP_ENV'].equal?('development') ? '.' : Dir.pwd # app dir in dev or pwd otherwise
|
|
244
|
+
abort "ERROR: Cannot create DB files: the directory #{dir.inspect} is not writable." \
|
|
245
|
+
unless File.writable?(dir)
|
|
246
|
+
# Connection
|
|
247
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: "#{dir}/tmp/pagy-keyset-ar.sqlite3")
|
|
248
|
+
# Schema
|
|
249
|
+
ActiveRecord::Schema.define do
|
|
250
|
+
create_table :pets, force: true do |t|
|
|
251
|
+
t.string :animal
|
|
252
|
+
t.string :name
|
|
253
|
+
t.date :birthdate
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
# Models
|
|
258
|
+
class Pet < ActiveRecord::Base; end
|
|
259
|
+
|
|
260
|
+
data = <<~DATA
|
|
261
|
+
Luna | dog | 2018-03-10
|
|
262
|
+
Coco | cat | 2019-05-15
|
|
263
|
+
Dodo | dog | 2020-06-25
|
|
264
|
+
Wiki | bird | 2018-03-12
|
|
265
|
+
Baby | rabbit | 2020-01-13
|
|
266
|
+
Neki | horse | 2021-07-20
|
|
267
|
+
Tino | donkey | 2019-06-18
|
|
268
|
+
Plot | cat | 2022-09-21
|
|
269
|
+
Riki | cat | 2018-09-14
|
|
270
|
+
Susi | horse | 2018-10-26
|
|
271
|
+
Coco | pig | 2020-08-29
|
|
272
|
+
Momo | bird | 2023-08-25
|
|
273
|
+
Lili | cat | 2021-07-22
|
|
274
|
+
Beli | pig | 2020-07-26
|
|
275
|
+
Rocky | bird | 2022-08-19
|
|
276
|
+
Vyvy | dog | 2018-05-16
|
|
277
|
+
Susi | horse | 2024-01-25
|
|
278
|
+
Ella | cat | 2020-02-20
|
|
279
|
+
Rocky | dog | 2019-09-19
|
|
280
|
+
Juni | rabbit | 2020-08-24
|
|
281
|
+
Coco | bird | 2021-03-17
|
|
282
|
+
Susi | dog | 2021-07-28
|
|
283
|
+
Luna | horse | 2023-05-14
|
|
284
|
+
Gigi | pig | 2022-05-19
|
|
285
|
+
Coco | cat | 2020-02-20
|
|
286
|
+
Nino | donkey | 2019-06-17
|
|
287
|
+
Luna | cat | 2022-02-09
|
|
288
|
+
Popi | dog | 2020-09-26
|
|
289
|
+
Lili | pig | 2022-06-18
|
|
290
|
+
Mina | horse | 2021-04-21
|
|
291
|
+
Susi | rabbit | 2023-05-18
|
|
292
|
+
Toni | donkey | 2018-06-22
|
|
293
|
+
Rocky | horse | 2019-09-28
|
|
294
|
+
Lili | cat | 2019-03-18
|
|
295
|
+
Roby | cat | 2022-06-19
|
|
296
|
+
Anto | horse | 2022-08-18
|
|
297
|
+
Susi | pig | 2021-04-21
|
|
298
|
+
Boly | bird | 2020-03-29
|
|
299
|
+
Sky | cat | 2023-07-19
|
|
300
|
+
Lili | dog | 2020-01-28
|
|
301
|
+
Fami | snake | 2023-04-27
|
|
302
|
+
Lopi | pig | 2019-06-19
|
|
303
|
+
Rocky | snake | 2022-03-13
|
|
304
|
+
Denis | dog | 2022-06-19
|
|
305
|
+
Maca | cat | 2022-06-19
|
|
306
|
+
Luna | dog | 2022-08-15
|
|
307
|
+
Jeme | horse | 2019-08-08
|
|
308
|
+
Sary | bird | 2023-04-29
|
|
309
|
+
Rocky | bird | 2023-05-14
|
|
310
|
+
Coco | dog | 2023-05-27
|
|
311
|
+
DATA
|
|
312
|
+
|
|
313
|
+
# DB seed
|
|
314
|
+
pets = []
|
|
315
|
+
data.each_line(chomp: true) do |pet|
|
|
316
|
+
name, animal, birthdate = pet.split('|').map(&:strip)
|
|
317
|
+
pets << { name:, animal:, birthdate: }
|
|
318
|
+
end
|
|
319
|
+
Pet.insert_all(pets)
|
|
320
|
+
|
|
321
|
+
run PagyKeynav
|
data/apps/keynav.ru
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
# URL
|
|
17
17
|
# http://127.0.0.1:8000
|
|
18
18
|
|
|
19
|
-
VERSION = '43.
|
|
19
|
+
VERSION = '43.1.1'
|
|
20
20
|
|
|
21
21
|
if VERSION != Pagy::VERSION
|
|
22
22
|
Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n")
|
|
@@ -54,6 +54,8 @@ class PagyKeynav < Sinatra::Base
|
|
|
54
54
|
|
|
55
55
|
@order = { animal: :asc, name: :asc, birthdate: :desc, id: :asc }
|
|
56
56
|
@pagy, @pets = pagy(:keynav_js, Pet.order(@order), limit: 4, client_max_limit: 100)
|
|
57
|
+
# Support also root_key for replacing url in javascript
|
|
58
|
+
# @pagy, @pets = pagy(:keynav_js, Pet.order(@order), limit: 4, client_max_limit: 100, root_key: 'animal')
|
|
57
59
|
@ids = @pets.pluck(:id)
|
|
58
60
|
erb :main
|
|
59
61
|
end
|
data/apps/keyset.ru
CHANGED
data/apps/keyset_sequel.ru
CHANGED
data/apps/rails.ru
CHANGED
data/apps/repro.ru
CHANGED
data/bin/pagy
CHANGED
data/config/pagy.rb
CHANGED
data/javascripts/ai_widget.js
CHANGED
|
@@ -68,7 +68,7 @@ const PagyAIWidget = {
|
|
|
68
68
|
script.dataset.iconUrl = this.ICON_URL;
|
|
69
69
|
script.dataset.text = 'Pagy AI';
|
|
70
70
|
script.dataset.bgColor = '#1f7a1f';
|
|
71
|
-
script.dataset.lightMode = '
|
|
71
|
+
script.dataset.lightMode = 'auto';
|
|
72
72
|
script.dataset.tooltipSide = 'bottom';
|
|
73
73
|
document.head.appendChild(script);
|
|
74
74
|
}
|
data/javascripts/pagy.js
CHANGED
|
@@ -24,18 +24,18 @@ window.Pagy = (() => {
|
|
|
24
24
|
}));
|
|
25
25
|
const B64SafeEncode = (unicode) => btoa(String.fromCharCode(...new TextEncoder().encode(unicode))).replace(/[+/=]/g, (m) => m == "+" ? "-" : m == "/" ? "_" : ""), B64Decode = (base64) => new TextDecoder().decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0)));
|
|
26
26
|
const randKey = () => Math.floor(Math.random() * 36 ** 3).toString(36);
|
|
27
|
-
const augmentKeynav = async (nav, [storageKey, pageKey, last, spliceArgs]) => {
|
|
28
|
-
let
|
|
27
|
+
const augmentKeynav = async (nav, [storageKey, rootKey, pageKey, last, spliceArgs]) => {
|
|
28
|
+
let augmentPage;
|
|
29
29
|
const browserKey = document.cookie.split(/;\s+/).find((row) => row.startsWith(pagy + "="))?.split("=")[1] ?? randKey();
|
|
30
30
|
document.cookie = pagy + "=" + browserKey;
|
|
31
31
|
if (storageKey && !(storageKey in storage)) {
|
|
32
32
|
sync.postMessage({ from: tabId, key: storageKey });
|
|
33
33
|
await new Promise((resolve) => setTimeout(() => resolve(""), 100));
|
|
34
34
|
if (!(storageKey in storage)) {
|
|
35
|
-
|
|
35
|
+
augmentPage = (page) => page + "+" + last;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
if (!
|
|
38
|
+
if (!augmentPage) {
|
|
39
39
|
if (!storageKey) {
|
|
40
40
|
do {
|
|
41
41
|
storageKey = randKey();
|
|
@@ -46,7 +46,7 @@ window.Pagy = (() => {
|
|
|
46
46
|
cutoffs.splice(...spliceArgs);
|
|
47
47
|
storage.setItem(storageKey, JSON.stringify(cutoffs));
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
augmentPage = (page) => {
|
|
50
50
|
const pageNum = parseInt(page);
|
|
51
51
|
return B64SafeEncode(JSON.stringify([
|
|
52
52
|
browserKey,
|
|
@@ -58,11 +58,12 @@ window.Pagy = (() => {
|
|
|
58
58
|
]));
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
|
+
const search = rootKey ? `${rootKey}%5B${pageKey}%5D` : pageKey;
|
|
62
|
+
const re = new RegExp(`(?<=\\?.*)(\\b${search}=)(\\d+)`);
|
|
61
63
|
for (const a of nav.querySelectorAll("a[href]")) {
|
|
62
|
-
|
|
63
|
-
a.href = url.replace(re, pageKey + "=" + augment(url.match(re)[1]));
|
|
64
|
+
a.href = a.href.replace(re, (_match, prefix, digit) => `${prefix}${augmentPage(digit)}`);
|
|
64
65
|
}
|
|
65
|
-
return
|
|
66
|
+
return augmentPage;
|
|
66
67
|
};
|
|
67
68
|
const buildNavJs = (nav, [
|
|
68
69
|
[before, anchor, current, gap, after],
|
|
@@ -124,7 +125,7 @@ window.Pagy = (() => {
|
|
|
124
125
|
});
|
|
125
126
|
};
|
|
126
127
|
return {
|
|
127
|
-
version: "43.
|
|
128
|
+
version: "43.1.1",
|
|
128
129
|
init(arg) {
|
|
129
130
|
const target = arg instanceof HTMLElement ? arg : document, elements = target.querySelectorAll("[data-pagy]");
|
|
130
131
|
for (const element of elements) {
|
|
@@ -147,5 +148,5 @@ window.Pagy = (() => {
|
|
|
147
148
|
};
|
|
148
149
|
})();
|
|
149
150
|
|
|
150
|
-
//# debugId=
|
|
151
|
+
//# debugId=7800AFC87F2D38E864756E2164756E21
|
|
151
152
|
//# sourceMappingURL=pagy.js.map
|
data/javascripts/pagy.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/pagy.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"interface SyncData {\n from?: number\n to?: number\n key: string\n str?: string\n}\ntype InitArgs = [\"k\", KeynavArgs] | // series_nav[_js] with keynav instance\n [\"snj\", SeriesNavJsArgs] | // series_nav_js\n [\"inj\", InputNavJsArgs] | // input_nav_js\n [\"ltj\", LimitTagJsArgs] // limit_tag_js\ntype AugmentKeynav = (nav:HTMLElement, keynavArgs:KeynavArgs) => Promise<((page: string) => string)>\ntype KeynavArgs = readonly [storageKey: string | null,\n pageKey: string,\n last: number,\n spliceArgs?: SpliceArgs]\ntype SpliceArgs = readonly [start: number,\n deleteCount: number, // it would be optional, but ts complains\n ...items: Cutoff[]]\ntype Cutoff = readonly (string | number | boolean)[]\ntype AugmentedPage = [browserId: string,\n storageKey: string,\n pageNumber: number,\n pages: number,\n priorCutoff: Cutoff | null,\n pageCutoff: Cutoff | null]\ntype SeriesNavJsArgs = readonly [NavJsTokens, NavJsSeries, KeynavArgs?]\ntype NavJsSeries = readonly [widths: number[],\n series: (string | number)[][],\n labels: string[][] | null]\ntype InputNavJsArgs = readonly [urlToken: string, KeynavArgs?]\ntype LimitTagJsArgs = readonly [from: number,\n urlToken: string]\ntype NavJsTokens = readonly [before: string,\n anchor: string,\n current: string,\n gap: string,\n after: string]\ninterface NavJsElement extends HTMLElement {\n render(): void\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst Pagy = (() => {\n const storageSupport = 'sessionStorage' in window && 'BroadcastChannel' in window,\n pageRe = \"P \"; // shorten the compiled size\n // eslint-disable-next-line prefer-const\n let pagy = \"pagy\", storage: Storage, sync: BroadcastChannel, tabId: number;\n if (storageSupport) {\n storage = sessionStorage; // shorten the compiled size\n sync = new BroadcastChannel(pagy);\n tabId = Date.now();\n // Sync the sessionStorage keys for the cutoffs opened in a new tab/window\n sync.addEventListener(\"message\", (e:MessageEvent<SyncData>) => {\n if (e.data.from) { // request cutoffs\n const cutoffs = storage.getItem(e.data.key);\n if (cutoffs) {\n sync.postMessage(<SyncData>{to: e.data.from, key: e.data.key, str: cutoffs});\n } // send response\n } else if (e.data.to) { // receive cutoffs\n if (e.data.to == tabId) {\n storage.setItem(e.data.key, <string>e.data.str);\n }\n }\n });\n }\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => {\n e.target.querySelectorAll<NavJsElement>(\".pagy-rjs\").forEach(el => el.render());\n }));\n\n /* Full set of B64 functions\n const B64Encode = (unicode:string) => btoa(String.fromCharCode(...(new TextEncoder).encode(unicode))),\n B64Safe = (unsafe:string) => unsafe.replace(/[+/=]/g, (m) => m == \"+\" ? \"-\" : m == \"/\" ? \"_\" : \"\"),\n B64SafeEncode = (unicode:string) => B64Safe(B64Encode(unicode)),\n B64Decode = (base64:string) => (new TextDecoder()).decode(Uint8Array.from(atob(base64), c => c.charCodeAt(0))),\n B64Unsafe = (safe:string) => safe.replace(/[-_]/g, (match) => match == \"-\" ? \"+\" : \"/\"),\n B64SafeDecode = (base64:string) => B64Decode(B64Unsafe(base64))\n */\n const B64SafeEncode = (unicode:string) => btoa(String.fromCharCode(...(new TextEncoder).encode(unicode)))\n .replace(/[+/=]/g, (m) => m == \"+\" ? \"-\" : m == \"/\" ? \"_\" : \"\"),\n B64Decode = (base64:string) => (new TextDecoder()).decode(Uint8Array.from(atob(base64), c => c.charCodeAt(0)));\n\n // Return a random key: 3 chars max, base-36 number < 36**3\n const randKey = () => Math.floor(Math.random() * 36 ** 3).toString(36);\n\n // Manage the page augmentation for Keynav, called only if storageSupport\n const augmentKeynav: AugmentKeynav = async (nav, [storageKey, pageKey, last, spliceArgs]) => {\n let augment;\n const browserKey = document.cookie.split(/;\\s+/) // it works even if malformed\n .find((row) => row.startsWith(pagy + \"=\"))\n ?.split(\"=\")[1] ?? randKey();\n document.cookie = pagy + \"=\" + browserKey; // Smaller .min size: set the cookie without checking\n if (storageKey && !(storageKey in storage)) {\n // Sync the sessiongStorage from other tabs/windows (e.g., open page in the new tab/window)\n sync.postMessage(<SyncData>{ from: tabId, key: storageKey });\n // Wait for the listener to copy the cutoffs in the current sessionStorage\n await new Promise<string|null>((resolve) => setTimeout(() => resolve(\"\"), 100));\n if (!(storageKey in storage)) { // the storageKey didn't get copied: fallback to countless pagination\n augment = (page: string) => page + '+' + last;\n }\n }\n if (!augment) { // regular keynav pagination\n if (!storageKey) { do { storageKey = randKey() } while (storageKey in storage) } // no dup keys\n const data = storage.getItem(storageKey),\n cutoffs = <Cutoff[]>(data ? JSON.parse(data) : [undefined]);\n if (spliceArgs) {\n cutoffs.splice(...spliceArgs);\n storage.setItem(storageKey, JSON.stringify(cutoffs));\n }\n // Augment function\n augment = (page:string) => {\n const pageNum = parseInt(page);\n return B64SafeEncode(JSON.stringify(\n <AugmentedPage>[browserKey,\n storageKey,\n pageNum,\n cutoffs.length, // pages/last\n cutoffs[pageNum - 1], // priorCutoff\n cutoffs[pageNum]])); // pageCutoff\n };\n }\n // Augment the page param of each href\n for (const a of <NodeListOf<HTMLAnchorElement>><unknown>nav.querySelectorAll('a[href]')) {\n const url = a.href,\n re = new RegExp(`(?<=\\\\?.*)\\\\b${pageKey}=(\\\\d+)`); // find the numeric page from pageKey\n a.href = url.replace(re, pageKey + \"=\" + augment(url.match(re)![1])); // eslint-disable-line @typescript-eslint/no-non-null-assertion\n }\n // Return the augment function for further augmentation (i.e., url token in input_nav_js)\n return augment;\n };\n\n // Build the series_nav_js helper\n const buildNavJs = (nav:NavJsElement, [[before, anchor, current, gap, after],\n [widths, series, labels], keynavArgs]:SeriesNavJsArgs) => {\n const parent = <HTMLElement>nav.parentElement;\n let lastWidth = -1;\n (nav.render = () => {\n const index = widths.findIndex(w => w < parent.clientWidth);\n if (widths[index] === lastWidth) { return } // no change: abort\n\n let html = before;\n series[index].forEach((item, i) => {\n // Avoid the if blocks and chain the results (shorter pagy.min.js and easier reading)\n html += item == \"gap\" ? gap :\n // @ts-expect-error the item may be a number, but the 'replace' converts it to string (shorter pagy.min.js)\n (typeof item == \"number\" ? anchor.replace(pageRe, item) : current)\n .replace(\"L<\", labels?.[index][i] ?? item + \"<\");\n });\n html += after;\n nav.innerHTML = \"\";\n nav.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = widths[index];\n if (keynavArgs && storageSupport) { void augmentKeynav(nav, keynavArgs) }\n })();\n if (nav.classList.contains(pagy + \"-rjs\")) { rjsObserver.observe(parent) }\n };\n\n // Init the input_nav_js helpers\n const initInputNavJs = async (nav:HTMLElement, [url_token, keynavArgs]:InputNavJsArgs) => {\n const augment = keynavArgs && storageSupport\n ? await augmentKeynav(nav, keynavArgs)\n : (page: string) => page;\n initInput(nav, inputValue => url_token.replace(pageRe, augment(inputValue)));\n };\n\n // Init the limit_tag_js helper\n const initLimitTagJs = (span:HTMLSpanElement, [from, url_token]:LimitTagJsArgs) => {\n initInput(span, inputValue => {\n // @ts-expect-error the page is a number, but the 'replace' converts it to string (shorter pagy.min.js)\n return url_token.replace(pageRe, Math.max(Math.ceil(from / parseInt(inputValue)), 1))\n .replace('L ', inputValue);\n });\n };\n\n // Init the input element\n const initInput = (element:HTMLElement, getUrl:(v:string) => string) => {\n const input = <HTMLInputElement>element.querySelector(\"input\"),\n link = <HTMLAnchorElement>element.querySelector(\"a\"),\n initial = input.value,\n action = () => {\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 link.href = getUrl(input.value);\n link.click();\n };\n input.addEventListener(\"focus\", () => input.select());\n input.addEventListener(\"focusout\", action);\n input.addEventListener(\"keypress\", e => { if (e.key == \"Enter\") { action() } });\n };\n\n // Public interface\n return {\n version: \"43.0.7\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:HTMLElement) {\n const target = arg instanceof HTMLElement ? arg : document,\n elements = target.querySelectorAll(\"[data-pagy]\");\n for (const element of <NodeListOf<HTMLElement>>elements) {\n try {\n const [helperId, ...args] = <InitArgs>JSON.parse(B64Decode(<string>element.getAttribute(\"data-pagy\")));\n if (helperId == \"k\") {\n // @ts-expect-error spread 2 arguments, not 3 as it complains about\n void augmentKeynav(element, ...<KeynavArgs><unknown>args);\n } else if (helperId == \"snj\") {\n buildNavJs(<NavJsElement>element, <SeriesNavJsArgs><unknown>args);\n } else if (helperId == \"inj\") {\n void initInputNavJs(element, <InputNavJsArgs><unknown>args);\n } else if (helperId == \"ltj\") {\n initLimitTagJs(element, <LimitTagJsArgs><unknown>args);\n }\n // else { console.warn(\"Pagy.init: %o\\nUnknown helperId '%s'\", element, helperId) }\n } catch (err) { console.warn(\"Pagy.init: %o\\n%s\", element, err) }\n }\n }\n };\n})();\n"
|
|
5
|
+
"interface SyncData {\n from?: number\n to?: number\n key: string\n str?: string\n}\ntype InitArgs = [\"k\", KeynavArgs] | // series_nav[_js] with keynav instance\n [\"snj\", SeriesNavJsArgs] | // series_nav_js\n [\"inj\", InputNavJsArgs] | // input_nav_js\n [\"ltj\", LimitTagJsArgs] // limit_tag_js\ntype AugmentKeynav = (nav:HTMLElement, keynavArgs:KeynavArgs) => Promise<((page: string) => string)>\ntype KeynavArgs = readonly [storageKey: string | null,\n rootKey: string | null,\n pageKey: string,\n last: number,\n spliceArgs?: SpliceArgs]\ntype SpliceArgs = readonly [start: number,\n deleteCount: number, // it would be optional, but ts complains\n ...items: Cutoff[]]\ntype Cutoff = readonly (string | number | boolean)[]\ntype AugmentedPage = [browserId: string,\n storageKey: string,\n pageNumber: number,\n pages: number,\n priorCutoff: Cutoff | null,\n pageCutoff: Cutoff | null]\ntype SeriesNavJsArgs = readonly [NavJsTokens, NavJsSeries, KeynavArgs?]\ntype NavJsSeries = readonly [widths: number[],\n series: (string | number)[][],\n labels: string[][] | null]\ntype InputNavJsArgs = readonly [urlToken: string, KeynavArgs?]\ntype LimitTagJsArgs = readonly [from: number,\n urlToken: string]\ntype NavJsTokens = readonly [before: string,\n anchor: string,\n current: string,\n gap: string,\n after: string]\ninterface NavJsElement extends HTMLElement {\n render(): void\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst Pagy = (() => {\n const storageSupport = 'sessionStorage' in window && 'BroadcastChannel' in window,\n pageRe = \"P \"; // shorten the compiled size\n // eslint-disable-next-line prefer-const\n let pagy = \"pagy\", storage: Storage, sync: BroadcastChannel, tabId: number;\n if (storageSupport) {\n storage = sessionStorage; // shorten the compiled size\n sync = new BroadcastChannel(pagy);\n tabId = Date.now();\n // Sync the sessionStorage keys for the cutoffs opened in a new tab/window\n sync.addEventListener(\"message\", (e:MessageEvent<SyncData>) => {\n if (e.data.from) { // request cutoffs\n const cutoffs = storage.getItem(e.data.key);\n if (cutoffs) {\n sync.postMessage(<SyncData>{to: e.data.from, key: e.data.key, str: cutoffs});\n } // send response\n } else if (e.data.to) { // receive cutoffs\n if (e.data.to == tabId) {\n storage.setItem(e.data.key, <string>e.data.str);\n }\n }\n });\n }\n // The observer instance for responsive navs\n const rjsObserver = new ResizeObserver(\n entries => entries.forEach(e => {\n e.target.querySelectorAll<NavJsElement>(\".pagy-rjs\").forEach(el => el.render());\n }));\n\n /* Full set of B64 functions\n const B64Encode = (unicode:string) => btoa(String.fromCharCode(...(new TextEncoder).encode(unicode))),\n B64Safe = (unsafe:string) => unsafe.replace(/[+/=]/g, (m) => m == \"+\" ? \"-\" : m == \"/\" ? \"_\" : \"\"),\n B64SafeEncode = (unicode:string) => B64Safe(B64Encode(unicode)),\n B64Decode = (base64:string) => (new TextDecoder()).decode(Uint8Array.from(atob(base64), c => c.charCodeAt(0))),\n B64Unsafe = (safe:string) => safe.replace(/[-_]/g, (match) => match == \"-\" ? \"+\" : \"/\"),\n B64SafeDecode = (base64:string) => B64Decode(B64Unsafe(base64))\n */\n const B64SafeEncode = (unicode:string) => btoa(String.fromCharCode(...(new TextEncoder).encode(unicode)))\n .replace(/[+/=]/g, (m) => m == \"+\" ? \"-\" : m == \"/\" ? \"_\" : \"\"),\n B64Decode = (base64:string) => (new TextDecoder()).decode(Uint8Array.from(atob(base64), c => c.charCodeAt(0)));\n\n // Return a random key: 3 chars max, base-36 number < 36**3\n const randKey = () => Math.floor(Math.random() * 36 ** 3).toString(36);\n\n // Manage the page augmentation for Keynav, called only if storageSupport\n const augmentKeynav: AugmentKeynav = async (nav, [storageKey, rootKey, pageKey, last, spliceArgs]) => {\n let augmentPage:(page: string) => string;\n const browserKey = document.cookie.split(/;\\s+/) // it works even if malformed\n .find((row) => row.startsWith(pagy + \"=\"))\n ?.split(\"=\")[1] ?? randKey();\n document.cookie = pagy + \"=\" + browserKey; // Smaller .min size: set the cookie without checking\n if (storageKey && !(storageKey in storage)) {\n // Sync the sessiongStorage from other tabs/windows (e.g., open page in the new tab/window)\n sync.postMessage(<SyncData>{ from: tabId, key: storageKey });\n // Wait for the listener to copy the cutoffs in the current sessionStorage\n await new Promise<string|null>((resolve) => setTimeout(() => resolve(\"\"), 100));\n if (!(storageKey in storage)) { // the storageKey didn't get copied: fallback to countless pagination\n augmentPage = (page: string) => page + '+' + last;\n }\n }\n // @ts-expect-error If it is not assigned it means it supports keynav\n if (!augmentPage) { // regular keynav pagination\n if (!storageKey) { do { storageKey = randKey() } while (storageKey in storage) } // no dup keys\n const data = storage.getItem(storageKey),\n cutoffs = <Cutoff[]>(data ? JSON.parse(data) : [undefined]);\n if (spliceArgs) {\n cutoffs.splice(...spliceArgs);\n storage.setItem(storageKey, JSON.stringify(cutoffs));\n }\n // Augment function\n augmentPage = (page:string) => {\n const pageNum = parseInt(page);\n return B64SafeEncode(JSON.stringify(\n <AugmentedPage>[browserKey,\n storageKey,\n pageNum,\n cutoffs.length, // pages/last\n cutoffs[pageNum - 1], // priorCutoff\n cutoffs[pageNum]])); // pageCutoff\n };\n }\n const search = (rootKey) ? `${rootKey}%5B${pageKey}%5D` : pageKey;\n const re = new RegExp(`(?<=\\\\?.*)(\\\\b${search}=)(\\\\d+)`);\n // Augment the page param of each href\n for (const a of <NodeListOf<HTMLAnchorElement>><unknown>nav.querySelectorAll('a[href]')) {\n a.href = a.href.replace(re, (_match, prefix, digit): string => `${prefix}${augmentPage(<string>digit)}`);\n }\n // Return the augment function for further augmentation (i.e., url token in input_nav_js)\n return augmentPage;\n };\n\n // Build the series_nav_js helper\n const buildNavJs = (nav:NavJsElement, [[before, anchor, current, gap, after],\n [widths, series, labels], keynavArgs]:SeriesNavJsArgs) => {\n const parent = <HTMLElement>nav.parentElement;\n let lastWidth = -1;\n (nav.render = () => {\n const index = widths.findIndex(w => w < parent.clientWidth);\n if (widths[index] === lastWidth) { return } // no change: abort\n\n let html = before;\n series[index].forEach((item, i) => {\n // Avoid the if blocks and chain the results (shorter pagy.min.js and easier reading)\n html += item == \"gap\" ? gap :\n // @ts-expect-error the item may be a number, but the 'replace' converts it to string (shorter pagy.min.js)\n (typeof item == \"number\" ? anchor.replace(pageRe, item) : current)\n .replace(\"L<\", labels?.[index][i] ?? item + \"<\");\n });\n html += after;\n nav.innerHTML = \"\";\n nav.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = widths[index];\n if (keynavArgs && storageSupport) { void augmentKeynav(nav, keynavArgs) }\n })();\n if (nav.classList.contains(pagy + \"-rjs\")) { rjsObserver.observe(parent) }\n };\n\n // Init the input_nav_js helpers\n const initInputNavJs = async (nav:HTMLElement, [url_token, keynavArgs]:InputNavJsArgs) => {\n const augment = keynavArgs && storageSupport\n ? await augmentKeynav(nav, keynavArgs)\n : (page: string) => page;\n initInput(nav, inputValue => url_token.replace(pageRe, augment(inputValue)));\n };\n\n // Init the limit_tag_js helper\n const initLimitTagJs = (span:HTMLSpanElement, [from, url_token]:LimitTagJsArgs) => {\n initInput(span, inputValue => {\n // @ts-expect-error the page is a number, but the 'replace' converts it to string (shorter pagy.min.js)\n return url_token.replace(pageRe, Math.max(Math.ceil(from / parseInt(inputValue)), 1))\n .replace('L ', inputValue);\n });\n };\n\n // Init the input element\n const initInput = (element:HTMLElement, getUrl:(v:string) => string) => {\n const input = <HTMLInputElement>element.querySelector(\"input\"),\n link = <HTMLAnchorElement>element.querySelector(\"a\"),\n initial = input.value,\n action = () => {\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 link.href = getUrl(input.value);\n link.click();\n };\n input.addEventListener(\"focus\", () => input.select());\n input.addEventListener(\"focusout\", action);\n input.addEventListener(\"keypress\", e => { if (e.key == \"Enter\") { action() } });\n };\n\n // Public interface\n return {\n version: \"43.1.1\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:HTMLElement) {\n const target = arg instanceof HTMLElement ? arg : document,\n elements = target.querySelectorAll(\"[data-pagy]\");\n for (const element of <NodeListOf<HTMLElement>>elements) {\n try {\n const [helperId, ...args] = <InitArgs>JSON.parse(B64Decode(<string>element.getAttribute(\"data-pagy\")));\n if (helperId == \"k\") {\n // @ts-expect-error spread 2 arguments, not 3 as it complains about\n void augmentKeynav(element, ...<KeynavArgs><unknown>args);\n } else if (helperId == \"snj\") {\n buildNavJs(<NavJsElement>element, <SeriesNavJsArgs><unknown>args);\n } else if (helperId == \"inj\") {\n void initInputNavJs(element, <InputNavJsArgs><unknown>args);\n } else if (helperId == \"ltj\") {\n initLimitTagJs(element, <LimitTagJsArgs><unknown>args);\n }\n // else { console.warn(\"Pagy.init: %o\\nUnknown helperId '%s'\", element, helperId) }\n } catch (err) { console.warn(\"Pagy.init: %o\\n%s\", element, err) }\n }\n }\n };\n})();\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";AA2CA,IAAM,QAAQ,MAAM;AAClB,QAAM,iBAAiB,oBAAoB,UAAU,sBAAsB,QACrE,SAAiB;AAEvB,MAAI,OAAO,QAAQ,SAAkB,MAAwB;AAC7D,MAAI,gBAAgB;AAClB,cAAU;AACV,WAAU,IAAI,iBAAiB,IAAI;AACnC,YAAU,KAAK,IAAI;AAEnB,SAAK,iBAAiB,WAAW,CAAC,MAA6B;AAC7D,UAAI,EAAE,KAAK,MAAM;AACf,cAAM,UAAU,QAAQ,QAAQ,EAAE,KAAK,GAAG;AAC1C,YAAI,SAAS;AACX,eAAK,YAAsB,EAAC,IAAI,EAAE,KAAK,MAAM,KAAK,EAAE,KAAK,KAAK,KAAK,QAAO,CAAC;AAAA,QAC7E;AAAA,MACF,WAAW,EAAE,KAAK,IAAI;AACpB,YAAI,EAAE,KAAK,MAAM,OAAO;AACtB,kBAAQ,QAAQ,EAAE,KAAK,KAAa,EAAE,KAAK,GAAG;AAAA,QAChD;AAAA,MACF;AAAA,KACD;AAAA,EACH;AAEA,QAAM,cAAc,IAAI,eACpB,aAAW,QAAQ,QAAQ,OAAK;AAC9B,MAAE,OAAO,iBAA+B,WAAW,EAAE,QAAQ,QAAM,GAAG,OAAO,CAAC;AAAA,GAC/E,CAAC;AAUN,QAAM,gBAAgB,CAAC,YAAmB,KAAK,OAAO,aAAa,GAAI,IAAI,cAAa,OAAO,OAAO,CAAC,CAAC,EAC7D,QAAQ,UAAU,CAAC,MAAM,KAAK,MAAM,MAAM,KAAK,MAAM,MAAM,EAAE,GAClG,YAA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AAA,UAClE,WAAW,YAAY,OAAO;AAC5B,YAAK,eAAe,SAAkC,IAAI;AAAA,UAC5D,WAAW,YAAY,OAAO;AAC5B,2BAAe,SAAkC,IAAI;AAAA,UACvD;AAAA,iBAEO,KAAP;AAAc,kBAAQ,KAAK,qBAAqB,SAAS,GAAG;AAAA;AAAA,MAChE;AAAA;AAAA,EAEJ;AAAA,GACC;",
|
|
8
|
+
"debugId": "7800AFC87F2D38E864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
data/javascripts/pagy.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
window.Pagy=(()=>{const
|
|
1
|
+
window.Pagy=(()=>{const T="sessionStorage"in window&&"BroadcastChannel"in window;let L="pagy",Y,O,B;if(T)Y=sessionStorage,O=new BroadcastChannel(L),B=Date.now(),O.addEventListener("message",(q)=>{if(q.data.from){const z=Y.getItem(q.data.key);if(z)O.postMessage({to:q.data.from,key:q.data.key,str:z})}else if(q.data.to){if(q.data.to==B)Y.setItem(q.data.key,q.data.str)}});const S=new ResizeObserver((q)=>q.forEach((z)=>{z.target.querySelectorAll(".pagy-rjs").forEach((C)=>C.render())})),_=(q)=>btoa(String.fromCharCode(...new TextEncoder().encode(q))).replace(/[+/=]/g,(z)=>z=="+"?"-":z=="/"?"_":""),N=(q)=>new TextDecoder().decode(Uint8Array.from(atob(q),(z)=>z.charCodeAt(0))),J=()=>Math.floor(Math.random()*46656).toString(36),W=async(q,[z,C,F,G,Q])=>{let M;const $=document.cookie.split(/;\s+/).find((H)=>H.startsWith(L+"="))?.split("=")[1]??J();if(document.cookie=L+"="+$,z&&!(z in Y)){if(O.postMessage({from:B,key:z}),await new Promise((H)=>setTimeout(()=>H(""),100)),!(z in Y))M=(H)=>H+"+"+G}if(!M){if(!z)do z=J();while(z in Y);const H=Y.getItem(z),R=H?JSON.parse(H):[void 0];if(Q)R.splice(...Q),Y.setItem(z,JSON.stringify(R));M=(Z)=>{const X=parseInt(Z);return _(JSON.stringify([$,z,X,R.length,R[X-1],R[X]]))}}const E=C?`${C}%5B${F}%5D`:F,j=new RegExp(`(?<=\\?.*)(\\b${E}=)(\\d+)`);for(let H of q.querySelectorAll("a[href]"))H.href=H.href.replace(j,(R,Z,X)=>`${Z}${M(X)}`);return M},P=(q,[[z,C,F,G,Q],[M,$,E],j])=>{const H=q.parentElement;let R=-1;if((q.render=()=>{const Z=M.findIndex((D)=>D<H.clientWidth);if(M[Z]===R)return;let X=z;if($[Z].forEach((D,A)=>{X+=D=="gap"?G:(typeof D=="number"?C.replace("P ",D):F).replace("L<",E?.[Z][A]??D+"<")}),X+=Q,q.innerHTML="",q.insertAdjacentHTML("afterbegin",X),R=M[Z],j&&T)W(q,j)})(),q.classList.contains(L+"-rjs"))S.observe(H)},V=async(q,[z,C])=>{const F=C&&T?await W(q,C):(G)=>G;U(q,(G)=>z.replace("P ",F(G)))},x=(q,[z,C])=>{U(q,(F)=>{return C.replace("P ",Math.max(Math.ceil(z/parseInt(F)),1)).replace("L ",F)})},U=(q,z)=>{const C=q.querySelector("input"),F=q.querySelector("a"),G=C.value,Q=()=>{if(C.value===G)return;const[M,$,E]=[C.min,C.value,C.max].map((j)=>parseInt(j)||0);if($<M||$>E){C.value=G,C.select();return}F.href=z(C.value),F.click()};C.addEventListener("focus",()=>C.select()),C.addEventListener("focusout",Q),C.addEventListener("keypress",(M)=>{if(M.key=="Enter")Q()})};return{version:"43.1.1",init(q){const z=q instanceof HTMLElement?q:document,C=z.querySelectorAll("[data-pagy]");for(let F of C)try{const[G,...Q]=JSON.parse(N(F.getAttribute("data-pagy")));if(G=="k")W(F,...Q);else if(G=="snj")P(F,Q);else if(G=="inj")V(F,Q);else if(G=="ltj")x(F,Q)}catch(G){console.warn("Pagy.init: %o\n%s",F,G)}}}})();
|