diff --git a/docs/api/javascript/setup.md b/docs/api/javascript/setup.md index 710a0b837..ec6c91258 100644 --- a/docs/api/javascript/setup.md +++ b/docs/api/javascript/setup.md @@ -56,7 +56,7 @@ Your app needs standard script or old browser compatibility * It's an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) file meant to be loaded as is, directly in your production pages and without any further processing -* Minified (~2k) and polyfilled to work also with quite old browsers +* Minified (~3k) [!file](/gem/javascripts/pagy.min.js) @@ -64,16 +64,31 @@ Your app needs standard script or old browser compatibility script_path = Pagy.root.join('javascripts', 'pagy.min.js') ``` -+++ `pagy.min.js.map` ++++ `pagy.js` +!!! success +Developer version: plain Javascript to use for debugging with its `pagy.js.map` +!!! + +* It's an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) file meant to be loaded as is, directly in your + production pages and without any further processing +* Minified (~2k) and polyfilled to work also with quite old browsers + +[!file](/gem/javascripts/pagy.js) + +```ruby +script_path = Pagy.root.join('javascripts', 'pagy.js') +``` + ++++ `pagy.js.map` !!! success -You need to debug the javascript helpers while using the `pagy.min.js` file +You need to debug the javascript helpers while using the `pagy.js` file !!! -[!file](/gem/javascripts/pagy.min.js.map) +[!file](/gem/javascripts/pagy.js.map) ```ruby -script_path = Pagy.root.join('javascripts', 'pagy.min.js.map') +script_path = Pagy.root.join('javascripts', 'pagy.js.map') ``` +++ diff --git a/gem/apps/keyset_for_ui.ru b/gem/apps/keyset_for_ui.ru index beb89029b..16e6c7753 100644 --- a/gem/apps/keyset_for_ui.ru +++ b/gem/apps/keyset_for_ui.ru @@ -78,7 +78,7 @@ class PagyKeyset < Sinatra::Base Pagy Keyset For UI App - + diff --git a/gem/javascripts/pagy.js b/gem/javascripts/pagy.js new file mode 100644 index 000000000..32b5417a1 --- /dev/null +++ b/gem/javascripts/pagy.js @@ -0,0 +1,144 @@ +// pagy.ts +window.Pagy = (() => { + const keysetSupport = "sessionStorage" in window && "BroadcastChannel" in window; + let sS, sync, tabId; + if (keysetSupport) { + sS = sessionStorage, sync = new BroadcastChannel("pagy"), tabId = Date.now(); + sync.addEventListener("message", (e) => { + if (e.data.from) { + const cutoffs = sS.getItem(e.data.key); + if (cutoffs) { + sync.postMessage({ to: e.data.from, key: e.data.key, cutoffs }); + } + } else if (e.data.to) { + if (e.data.to == tabId) { + sS.setItem(e.data.key, e.data.cutoffs); + } + } + }); + } + const rjsObserver = new ResizeObserver((entries) => entries.forEach((e) => { + e.target.querySelectorAll(".pagy-rjs").forEach((el) => el.pagyRender()); + })); + const B64Encode = (unicode) => btoa(String.fromCharCode(...new TextEncoder().encode(unicode))), B64Safe = (unsafe) => unsafe.replace(/=/g, "").replace(/[+/]/g, (match) => match == "+" ? "-" : "_"), B64SafeEncode = (unicode) => B64Safe(B64Encode(unicode)), B64Decode = (base64) => new TextDecoder().decode(Uint8Array.from(atob(base64), (c) => c.charCodeAt(0))); + const initNav = (el, keysetArgs) => { + initCutoff(el, keysetArgs); + }; + const initCutoff = async (el, [cutoffsName, pageName, [key, ...spliceArgs]]) => { + if (!keysetSupport) { + return; + } + const pagyId = document.cookie.split(/;\s+/).find((row) => row.startsWith("pagy="))?.split("=")[1] || Math.floor(Math.random() * 36 ** 3).toString(36); + document.cookie = "pagy=" + pagyId; + if (key && !(key in sS)) { + sync.postMessage({ from: tabId, key }); + await new Promise((resolve) => setTimeout(() => resolve(""), 10)); + } + key ||= "pagy-" + Date.now().toString(36); + const cs = sS.getItem(key), cutoffs = cs ? JSON.parse(cs) : [null]; + if (spliceArgs) { + cutoffs.splice(...spliceArgs); + sS.setItem(key, JSON.stringify(cutoffs)); + } + for (const a of el.querySelectorAll("a[href]")) { + const url = a.href, re = new RegExp(`(?<=\\?.*)\\b${pageName}=([\\d]+)`), page = parseInt(url.match(re)?.[1]), value = B64SafeEncode(JSON.stringify([ + pagyId, + key, + cutoffs.length, + cutoffs[page - 1], + cutoffs[page] + ])); + a.href = url + `&${cutoffsName}=${value}`; + } + }; + const initNavJs = (el, [tokens, sequels, labelSequels, keysetArgs]) => { + const container = el.parentElement ?? el, widths = Object.keys(sequels).map((w) => parseInt(w)).sort((a, b) => b - a); + let lastWidth = -1; + const fillIn = (a, page, label) => a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label); + (el.pagyRender = () => { + const width = widths.find((w) => w < container.clientWidth) || 0; + if (width === lastWidth) { + return; + } + let html = tokens.before; + const series = sequels[width.toString()], labels = labelSequels?.[width.toString()] ?? series.map((l) => l.toString()); + series.forEach((item, i) => { + const label = labels[i]; + let filled; + if (typeof item == "number") { + filled = fillIn(tokens.a, item.toString(), label); + } else if (item == "gap") { + filled = tokens.gap; + } else { + filled = fillIn(tokens.current, item, label); + } + html += filled; + }); + html += tokens.after; + el.innerHTML = ""; + el.insertAdjacentHTML("afterbegin", html); + lastWidth = width; + if (keysetArgs) { + initCutoff(el, keysetArgs); + } + })(); + if (el.classList.contains("pagy-rjs")) { + rjsObserver.observe(container); + } + }; + const initComboJs = (el, [url_token]) => initInput(el, (inputValue) => url_token.replace(/__pagy_page__/, inputValue)); + const initSelectorJs = (el, [from, url_token]) => { + initInput(el, (inputValue) => { + const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString(); + return url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue); + }); + }; + const initInput = (el, getUrl) => { + const input = el.querySelector("input"), link = el.querySelector("a"), initial = input.value; + const action = () => { + if (input.value === initial) { + return; + } + const [min, val, max] = [input.min, input.value, input.max].map((n) => parseInt(n) || 0); + if (val < min || val > max) { + input.value = initial; + input.select(); + return; + } + link.href = getUrl(input.value); + link.click(); + }; + ["change", "focus"].forEach((e) => input.addEventListener(e, () => input.select())); + input.addEventListener("focusout", action); + input.addEventListener("keypress", (e) => { + if (e.key == "Enter") { + action(); + } + }); + }; + return { + version: "9.3.3", + init(arg) { + const target = arg instanceof Element ? arg : document, elements = target.querySelectorAll("[data-pagy]"); + for (const el of elements) { + try { + const [keyword, ...args] = JSON.parse(B64Decode(el.getAttribute("data-pagy"))); + if (keyword == "nav") { + initNav(el, args); + } else if (keyword == "nav_js") { + initNavJs(el, args); + } else if (keyword == "combo_js") { + initComboJs(el, args); + } else if (keyword == "selector_js") { + initSelectorJs(el, args); + } + } catch (err) { + console.warn("Failed Pagy.init(): %o\n%s", el, err); + } + } + } + }; +})(); + +//# debugId=B1D0372CA2211BB464756E2164756E21 +//# sourceMappingURL=pagy.js.map diff --git a/gem/javascripts/pagy.min.js.map b/gem/javascripts/pagy.js.map similarity index 68% rename from gem/javascripts/pagy.min.js.map rename to gem/javascripts/pagy.js.map index 0cb2dc0f1..9e0087540 100644 --- a/gem/javascripts/pagy.min.js.map +++ b/gem/javascripts/pagy.js.map @@ -2,9 +2,9 @@ "version": 3, "sources": ["../../src/pagy.ts"], "sourcesContent": [ - "type InitArgs = [\"nav\", NavArgs] | [\"nav_js\", NavJsArgs] | [\"combo_js\", ComboJsArgs] | [\"selector_js\", SelectorJsArgs]\ntype NavArgs = KeysetArgs\ntype NavJsArgs = readonly [Tokens, Sequels, null | LabelSequels, KeysetArgs?]\ntype KeysetArgs = [string, string, Update]\ntype SpliceArgs = readonly [number, number, ...Cutoff[]] | [number, number]\ntype Update = [string, SpliceArgs] | [string]\ntype Cutoff = readonly (string | number | boolean)[]\ntype Cutoffs = [null, ...Cutoff[]]\ntype CutoffsParam = [string, string, number, null | Cutoff, Cutoff | undefined]\ntype ComboJsArgs = readonly [string]\ntype SelectorJsArgs = readonly [number, string]\n\ninterface SyncData {\n from?: number\n to?: number\n key: string\n cutoffs?: string\n}\n\ninterface Tokens {\n readonly before: string\n readonly a: string\n readonly current: string\n readonly gap: string\n readonly after: string\n}\n\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavJsElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n const keysetSupport = 'sessionStorage' in window && 'BroadcastChannel' in window;\n let sS: Storage, sync: BroadcastChannel, tabId: number;\n if (keysetSupport) {\n sS = sessionStorage, // shorten the .min.js\n sync = new BroadcastChannel(\"pagy\"),\n tabId = Date.now();\n\n // Sync the sessionStorage keys for the cutoffs used in the new tab/window\n // e.g. The user copies the page number link and pastes it in a new window\n // or the user right-clicks on a page link and choses \"Open in a new tab/window\"\n sync.addEventListener(\"message\", (e:MessageEvent) => {\n if (e.data.from) { // request cutoffs\n const cutoffs = sS.getItem(e.data.key);\n if (cutoffs) {\n sync.postMessage({to: e.data.from, key: e.data.key, cutoffs: cutoffs});\n } // send response\n } else if (e.data.to) { // receive cutoffs\n if (e.data.to == tabId) {\n sS.setItem(e.data.key, e.data.cutoffs);\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(\".pagy-rjs\").forEach(el => el.pagyRender());\n }));\n\n const B64Encode = (unicode:string) => btoa(String.fromCharCode(...(new TextEncoder).encode(unicode))),\n B64Safe = (unsafe:string) => unsafe.replace(/=/g, \"\").replace(/[+/]/g, (match) => match == \"+\" ? \"-\" : \"_\"),\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 // Init the *_nav helpers\n const initNav = (el:Element, keysetArgs:NavArgs) => {\n void initCutoff(el, keysetArgs);\n };\n\n// Init the Cutoff features\n const initCutoff = async (el:Element, [cutoffsName, pageName, [key, ...spliceArgs]]:KeysetArgs) => {\n if (!keysetSupport) { return }\n\n const pagyId = document.cookie.split(/;\\s+/) // it works even if malformed\n .find((row) => row.startsWith(\"pagy=\"))\n ?.split(\"=\")[1] || Math.floor(Math.random() * 36 ** 3).toString(36);\n document.cookie = \"pagy=\" + pagyId;\n\n if (key && !(key in sS)) {\n // Sync the sessiongStorage from other tabs/windows (e.g. open page in new tab/window)_\n sync.postMessage({ from: tabId, key: key });\n // Wait for the listener to copy the cutoffs in the current sessionStorage\n await new Promise((resolve) => setTimeout(() => resolve(\"\"), 10) );\n }\n key ||= \"pagy-\" + Date.now().toString(36);\n const cs = sS.getItem(key),\n cutoffs = (cs ? JSON.parse(cs) : [null]);\n if (spliceArgs) {\n // @ts-expect-error: spliceArgs should be a tuple type or passed to a rest param, but it contains all the args\n cutoffs.splice(...spliceArgs);\n sS.setItem(key, JSON.stringify(cutoffs));\n }\n for (const a of el.querySelectorAll('a[href]')) {\n const url = a.href,\n re = new RegExp(`(?<=\\\\?.*)\\\\b${pageName}=([\\\\d]+)`), // find the numeric page\n page = parseInt(url.match(re)?.[1]), // sure that page=\\d+ is in href\n value = B64SafeEncode(JSON.stringify([pagyId,\n key,\n cutoffs.length, // actual cutoffs + 1 (first null)\n cutoffs[page - 1],\n cutoffs[page]]));\n a.href = url + `&${cutoffsName}=${value}`; // \"&\" because the query_string is always present\n };\n };\n\n // Init the *_nav_js helpers\n const initNavJs = (el:NavJsElement, [tokens, sequels, labelSequels, keysetArgs]:NavJsArgs) => {\n const container = el.parentElement ?? el,\n 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) =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = () => {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n\n let html = tokens.before;\n const series = sequels[width.toString()],\n 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 += filled;\n });\n html += tokens.after;\n\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n if (keysetArgs) { void initCutoff(el, keysetArgs) }\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initComboJs = (el:Element, [url_token]:ComboJsArgs) =>\n initInput(el, inputValue => url_token.replace(/__pagy_page__/, inputValue));\n\n // Init the limit_selector_js helper\n const initSelectorJs = (el:Element, [from, url_token]:SelectorJsArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n return url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);\n });\n };\n\n // Init the input element\n const initInput = (el:Element, getUrl:(v:string) => string) => {\n const input = el.querySelector(\"input\"),\n link = el.querySelector(\"a\"),\n initial = input.value;\n const 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 [\"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 // Public interface\n return {\n version: \"9.3.3\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document,\n elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const [keyword, ...args] = JSON.parse(B64Decode(el.getAttribute(\"data-pagy\")));\n if (keyword == \"nav\") {\n initNav(el, args);\n } else if (keyword == \"nav_js\") {\n initNavJs(el, args);\n } else if (keyword == \"combo_js\") {\n initComboJs(el, args);\n } else if (keyword == \"selector_js\") {\n initSelectorJs(el, args);\n }\n //else { console.warn(\"Failed Pagy.init(): %o\\nUnknown keyword '%s'\", el, keyword) }\n } catch (err) { console.warn(\"Failed Pagy.init(): %o\\n%s\", el, err) }\n }\n }\n };\n})();\n\nexport default Pagy;\n" + "type InitArgs = [\"nav\", NavArgs] | [\"nav_js\", NavJsArgs] | [\"combo_js\", ComboJsArgs] | [\"selector_js\", SelectorJsArgs]\ntype NavArgs = KeysetArgs\ntype NavJsArgs = readonly [Tokens, Sequels, null | LabelSequels, KeysetArgs?]\ntype KeysetArgs = [string, string, Update]\ntype SpliceArgs = readonly [number, number, ...Cutoff[]] | [number, number]\ntype Update = [string, SpliceArgs] | [string]\ntype Cutoff = readonly (string | number | boolean)[]\ntype Cutoffs = [null, ...Cutoff[]]\ntype CutoffsParam = [string, string, number, null | Cutoff, Cutoff | undefined]\ntype ComboJsArgs = readonly [string]\ntype SelectorJsArgs = readonly [number, string]\n\ninterface SyncData {\n from?: number\n to?: number\n key: string\n cutoffs?: string\n}\n\ninterface Tokens {\n readonly before: string\n readonly a: string\n readonly current: string\n readonly gap: string\n readonly after: string\n}\n\ninterface Sequels {readonly [width:string]:(string | number)[]}\ninterface LabelSequels {readonly [width:string]:string[]}\ninterface NavJsElement extends Element {pagyRender():void}\n\nconst Pagy = (() => {\n const keysetSupport = 'sessionStorage' in window && 'BroadcastChannel' in window;\n let sS: Storage, sync: BroadcastChannel, tabId: number;\n if (keysetSupport) {\n sS = sessionStorage, // shorten the .min.js\n sync = new BroadcastChannel(\"pagy\"),\n tabId = Date.now();\n\n // Sync the sessionStorage keys for the cutoffs used in the new tab/window\n // e.g. The user copies the page number link and pastes it in a new window\n // or the user right-clicks on a page link and choses \"Open in a new tab/window\"\n sync.addEventListener(\"message\", (e:MessageEvent) => {\n if (e.data.from) { // request cutoffs\n const cutoffs = sS.getItem(e.data.key);\n if (cutoffs) {\n sync.postMessage({to: e.data.from, key: e.data.key, cutoffs: cutoffs});\n } // send response\n } else if (e.data.to) { // receive cutoffs\n if (e.data.to == tabId) {\n sS.setItem(e.data.key, e.data.cutoffs);\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(\".pagy-rjs\").forEach(el => el.pagyRender());\n }));\n\n const B64Encode = (unicode:string) => btoa(String.fromCharCode(...(new TextEncoder).encode(unicode))),\n B64Safe = (unsafe:string) => unsafe.replace(/=/g, \"\").replace(/[+/]/g, (match) => match == \"+\" ? \"-\" : \"_\"),\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 // Init the *_nav helpers\n const initNav = (el:Element, keysetArgs:NavArgs) => {\n void initCutoff(el, keysetArgs);\n };\n\n// Init the Cutoff features\n const initCutoff = async (el:Element, [cutoffsName, pageName, [key, ...spliceArgs]]:KeysetArgs) => {\n if (!keysetSupport) { return }\n\n const pagyId = document.cookie.split(/;\\s+/) // it works even if malformed\n .find((row) => row.startsWith(\"pagy=\"))\n ?.split(\"=\")[1] || Math.floor(Math.random() * 36 ** 3).toString(36);\n document.cookie = \"pagy=\" + pagyId;\n\n if (key && !(key in sS)) {\n // Sync the sessiongStorage from other tabs/windows (e.g. open page in new tab/window)_\n sync.postMessage({ from: tabId, key: key });\n // Wait for the listener to copy the cutoffs in the current sessionStorage\n await new Promise((resolve) => setTimeout(() => resolve(\"\"), 10) );\n }\n key ||= \"pagy-\" + Date.now().toString(36);\n const cs = sS.getItem(key),\n cutoffs = (cs ? JSON.parse(cs) : [null]);\n if (spliceArgs) {\n // @ts-expect-error: spliceArgs should be a tuple type or passed to a rest param, but it contains all the args\n cutoffs.splice(...spliceArgs);\n sS.setItem(key, JSON.stringify(cutoffs));\n }\n for (const a of el.querySelectorAll('a[href]')) {\n const url = a.href,\n re = new RegExp(`(?<=\\\\?.*)\\\\b${pageName}=([\\\\d]+)`), // find the numeric page\n page = parseInt(url.match(re)?.[1]), // sure that page=\\d+ is in href\n value = B64SafeEncode(JSON.stringify([pagyId,\n key,\n cutoffs.length, // actual cutoffs + 1 (first null)\n cutoffs[page - 1],\n cutoffs[page]]));\n a.href = url + `&${cutoffsName}=${value}`; // \"&\" because the query_string is always present\n };\n };\n\n // Init the *_nav_js helpers\n const initNavJs = (el:NavJsElement, [tokens, sequels, labelSequels, keysetArgs]:NavJsArgs) => {\n const container = el.parentElement ?? el,\n 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) =>\n a.replace(/__pagy_page__/g, page).replace(/__pagy_label__/g, label);\n (el.pagyRender = () => {\n const width = widths.find(w => w < container.clientWidth) || 0;\n if (width === lastWidth) { return } // no change: abort\n\n let html = tokens.before;\n const series = sequels[width.toString()],\n 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 += filled;\n });\n html += tokens.after;\n\n el.innerHTML = \"\";\n el.insertAdjacentHTML(\"afterbegin\", html);\n lastWidth = width;\n if (keysetArgs) { void initCutoff(el, keysetArgs) }\n })();\n if (el.classList.contains(\"pagy-rjs\")) { rjsObserver.observe(container) }\n };\n\n // Init the *_combo_nav_js helpers\n const initComboJs = (el:Element, [url_token]:ComboJsArgs) =>\n initInput(el, inputValue => url_token.replace(/__pagy_page__/, inputValue));\n\n // Init the limit_selector_js helper\n const initSelectorJs = (el:Element, [from, url_token]:SelectorJsArgs) => {\n initInput(el, inputValue => {\n const page = Math.max(Math.ceil(from / parseInt(inputValue)), 1).toString();\n return url_token.replace(/__pagy_page__/, page).replace(/__pagy_limit__/, inputValue);\n });\n };\n\n // Init the input element\n const initInput = (el:Element, getUrl:(v:string) => string) => {\n const input = el.querySelector(\"input\"),\n link = el.querySelector(\"a\"),\n initial = input.value;\n const 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 [\"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 // Public interface\n return {\n version: \"9.3.3\",\n\n // Scan for elements with a \"data-pagy\" attribute and call their init functions with the decoded args\n init(arg?:Element) {\n const target = arg instanceof Element ? arg : document,\n elements = target.querySelectorAll(\"[data-pagy]\");\n for (const el of elements) {\n try {\n const [keyword, ...args] = JSON.parse(B64Decode(el.getAttribute(\"data-pagy\")));\n if (keyword == \"nav\") {\n initNav(el, args);\n } else if (keyword == \"nav_js\") {\n initNavJs(el, args);\n } else if (keyword == \"combo_js\") {\n initComboJs(el, args);\n } else if (keyword == \"selector_js\") {\n initSelectorJs(el, args);\n }\n //else { console.warn(\"Failed Pagy.init(): %o\\nUnknown keyword '%s'\", el, keyword) }\n } catch (err) { console.warn(\"Failed Pagy.init(): %o\\n%s\", el, err) }\n }\n }\n };\n})();\n" ], - "mappings": "AA+BA,IAAM,GAAQ,IAAM,CAClB,MAAM,EAAgB,mBAAoB,QAAU,qBAAsB,OAC1E,IAAI,EAAa,EAAwB,EACzC,GAAI,EACF,EAAQ,eACR,EAAQ,IAAI,iBAAiB,MAAM,EACnC,EAAQ,KAAK,IAAI,EAKjB,EAAK,iBAAiB,UAAW,CAAC,IAA6B,CAC7D,GAAI,EAAE,KAAK,KAAM,CACf,MAAM,EAAU,EAAG,QAAQ,EAAE,KAAK,GAAG,EACrC,GAAI,EACF,EAAK,YAAsB,CAAC,GAAI,EAAE,KAAK,KAAM,IAAK,E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,UAC1C,WAAW,OAAO,iBAAiB,aAAa;AACtD,iBAAW,MAAM,UAAU;AACzB,YAAI;AACF,iBAAO,YAAY,QAAkB,KAAK,MAAM,UAAkB,GAAG,aAAa,WAAW,CAAC,CAAC;AAC/F,cAAI,WAAW,OAAO;AACpB,oBAAQ,IAAsB,IAAI;AAAA,UACpC,WAAW,WAAW,UAAU;AAC9B,sBAAwB,IAAwB,IAAI;AAAA,UACtD,WAAW,WAAW,YAAY;AAChC,wBAAY,IAA0B,IAAI;AAAA,UAC5C,WAAW,WAAW,eAAe;AACnC,2BAAe,IAA6B,IAAI;AAAA,UAClD;AAAA,iBAEO,KAAP;AAAc,kBAAQ,KAAK,8BAA8B,IAAI,GAAG;AAAA;AAAA,MACpE;AAAA;AAAA,EAEJ;AAAA,GACC;", + "debugId": "B1D0372CA2211BB464756E2164756E21", "names": [] } \ No newline at end of file diff --git a/gem/javascripts/pagy.min.js b/gem/javascripts/pagy.min.js index 967983cfa..c1f5df4f6 100644 --- a/gem/javascripts/pagy.min.js +++ b/gem/javascripts/pagy.min.js @@ -1,4 +1 @@ window.Pagy=(()=>{const P="sessionStorage"in window&&"BroadcastChannel"in window;let j,x,F;if(P)j=sessionStorage,x=new BroadcastChannel("pagy"),F=Date.now(),x.addEventListener("message",(z)=>{if(z.data.from){const G=j.getItem(z.data.key);if(G)x.postMessage({to:z.data.from,key:z.data.key,cutoffs:G})}else if(z.data.to){if(z.data.to==F)j.setItem(z.data.key,z.data.cutoffs)}});const J=new ResizeObserver((z)=>z.forEach((G)=>{G.target.querySelectorAll(".pagy-rjs").forEach((H)=>H.pagyRender())})),U=(z)=>btoa(String.fromCharCode(...new TextEncoder().encode(z))),B=(z)=>z.replace(/=/g,"").replace(/[+/]/g,(G)=>G=="+"?"-":"_"),_=(z)=>B(U(z)),q=(z)=>new TextDecoder().decode(Uint8Array.from(atob(z),(G)=>G.charCodeAt(0))),N=(z,G)=>{E(z,G)},E=async(z,[G,H,[K,...L]])=>{if(!P)return;const Q=document.cookie.split(/;\s+/).find((T)=>T.startsWith("pagy="))?.split("=")[1]||Math.floor(Math.random()*46656).toString(36);if(document.cookie="pagy="+Q,K&&!(K in j))x.postMessage({from:F,key:K}),await new Promise((T)=>setTimeout(()=>T(""),10));K||="pagy-"+Date.now().toString(36);const X=j.getItem(K),R=X?JSON.parse(X):[null];if(L)R.splice(...L),j.setItem(K,JSON.stringify(R));for(let T of z.querySelectorAll("a[href]")){const M=T.href,Y=new RegExp(`(?<=\\?.*)\\b${H}=([\\d]+)`),$=parseInt(M.match(Y)?.[1]),O=_(JSON.stringify([Q,K,R.length,R[$-1],R[$]]));T.href=M+`&${G}=${O}`}},V=(z,[G,H,K,L])=>{const Q=z.parentElement??z,X=Object.keys(H).map((M)=>parseInt(M)).sort((M,Y)=>Y-M);let R=-1;const T=(M,Y,$)=>M.replace(/__pagy_page__/g,Y).replace(/__pagy_label__/g,$);if((z.pagyRender=()=>{const M=X.find((Z)=>ZZ.toString());if($.forEach((Z,A)=>{const C=O[A];let D;if(typeof Z=="number")D=T(G.a,Z.toString(),C);else if(Z=="gap")D=G.gap;else D=T(G.current,Z,C);Y+=D}),Y+=G.after,z.innerHTML="",z.insertAdjacentHTML("afterbegin",Y),R=M,L)E(z,L)})(),z.classList.contains("pagy-rjs"))J.observe(Q)},v=(z,[G])=>W(z,(H)=>G.replace(/__pagy_page__/,H)),I=(z,[G,H])=>{W(z,(K)=>{const L=Math.max(Math.ceil(G/parseInt(K)),1).toString();return H.replace(/__pagy_page__/,L).replace(/__pagy_limit__/,K)})},W=(z,G)=>{const H=z.querySelector("input"),K=z.querySelector("a"),L=H.value,Q=()=>{if(H.value===L)return;const[X,R,T]=[H.min,H.value,H.max].map((M)=>parseInt(M)||0);if(RT){H.value=L,H.select();return}K.href=G(H.value),K.click()};["change","focus"].forEach((X)=>H.addEventListener(X,()=>H.select())),H.addEventListener("focusout",Q),H.addEventListener("keypress",(X)=>{if(X.key=="Enter")Q()})};return{version:"9.3.3",init(z){const G=z instanceof Element?z:document,H=G.querySelectorAll("[data-pagy]");for(let K of H)try{const[L,...Q]=JSON.parse(q(K.getAttribute("data-pagy")));if(L=="nav")N(K,Q);else if(L=="nav_js")V(K,Q);else if(L=="combo_js")v(K,Q);else if(L=="selector_js")I(K,Q)}catch(L){console.warn("Failed Pagy.init(): %o\n%s",K,L)}}}})(); - -//# debugId=A6278D22A2624D2A64756E2164756E21 -//# sourceMappingURL=pagy.min.js.map diff --git a/src/build b/src/build index bb33cadfa..d9450940e 100755 --- a/src/build +++ b/src/build @@ -9,6 +9,10 @@ jdir="$root/gem/javascripts" echo 'Generating javascript files' bun build ./pagy.ts --target=node --no-bundle --outfile=$jdir/pagy.mjs +echo 'export default Pagy;' >> $jdir/pagy.mjs -bun build ./pagy.min.js --target=browser --minify --sourcemap=linked --outdir=$jdir +bun build ./pagy.js --target=browser --minify --outfile=$jdir/pagy.min.js sed -i "0,/var ./{s/var ./window.Pagy/}" $jdir/pagy.min.js + +bun build ./pagy.js --target=browser --sourcemap=linked --outdir=$jdir +sed -i "0,/var Pagy/{s/var Pagy/window.Pagy/}" $jdir/pagy.js diff --git a/src/pagy.ts b/src/pagy.ts index 7fff2a7c0..3c93c73ee 100644 --- a/src/pagy.ts +++ b/src/pagy.ts @@ -29,6 +29,7 @@ interface Sequels {readonly [width:string]:(string | number)[]} interface LabelSequels {readonly [width:string]:string[]} interface NavJsElement extends Element {pagyRender():void} +// eslint-disable-next-line @typescript-eslint/no-unused-vars const Pagy = (() => { const keysetSupport = 'sessionStorage' in window && 'BroadcastChannel' in window; let sS: Storage, sync: BroadcastChannel, tabId: number; @@ -202,5 +203,3 @@ const Pagy = (() => { } }; })(); - -export default Pagy;