From c8ae209254effb443e560fcc8a560202b1ba4d9e Mon Sep 17 00:00:00 2001 From: callumalpass Date: Sat, 28 Nov 2026 18:59:03 +1100 Subject: [PATCH] Bound Journal entry history rendering and date lookups --- benchmarks/journal-history.bench.mjs | 61 ++ package-lock.json | 1141 +++++++++++++++++++++++++- package.json | 4 +- public/index.html | 5 + public/journal.css | 2 + src/journal-data.ts | 6 +- src/view.ts | 113 ++- tests/navigation.test.ts | 75 ++ 8 files changed, 1372 insertions(+), 35 deletions(-) create mode 100644 benchmarks/journal-history.bench.mjs diff --git a/benchmarks/journal-history.bench.mjs b/benchmarks/journal-history.bench.mjs new file mode 100644 index 0000000..cbf846e --- /dev/null +++ b/benchmarks/journal-history.bench.mjs @@ -0,0 +1,61 @@ +import assert from "node:assert/strict"; +import {readFileSync} from "node:fs"; +import {setTimeout} from "node:timers/promises"; +import {afterAll, bench, describe, vi} from "vitest"; +import {JSDOM} from "jsdom"; +import {JournalDrafts} from "../src/drafts.ts"; +import {JournalData} from "../src/journal-data.ts"; +import {mountJournal} from "../src/view.ts"; + +// The shared DOM test adapter installs browser globals. Tinybench's Node +// EventTarget requires Node's own Event even while React renders into JSDOM. +const nativeEvent = globalThis.Event; +const {applicationFixture, memoryStorage} = await import("../tests/support.ts"); +globalThis.Event = nativeEvent; + +const html = readFileSync(new URL("../public/index.html", import.meta.url), "utf8"); +const entryType = {name: "collection-owned-entry", createdField: "created"}; +const dateKey = new Intl.DateTimeFormat("sv-SE", {year: "numeric", month: "2-digit", day: "2-digit"}); + +async function history(size) { + const fixture = await applicationFixture(); + const {window} = new JSDOM(html); + const {document} = window; + const drafts = new JournalDrafts(memoryStorage()); + const records = Array.from({length: size}, (_, index) => { + const date = new Date(2010, 0, index + 1, 12); + return {id: String(index), path: `journal/${dateKey.format(date)}.md`, + types: [entryType.name], frontmatter: {created: date.toISOString()}}; + }); + // The SDK boundary delivers 500-record pages without network/replica latency. + const pages = vi.spyOn(fixture.records, "pages").mockImplementation(async function* () { + for (let start = 0; start < size; start += 500) yield {complete: true, records: records.slice(start, start + 500)}; + }); + const data = new JournalData(fixture.connection, drafts); + const view = mountJournal(document, drafts, fixture.mdbase); + const dialog = document.getElementById("entries"); + const date = document.getElementById("entry-date"); + const status = document.getElementById("entries-status"); + const list = document.getElementById("entry-list"); + dialog.showModal = () => dialog.setAttribute("open", ""); + document.getElementById("browse-button").click(); + for (let i = 0; i < 100 && (status.textContent || !list.children.length); i++) await setTimeout(5); + assert.equal(status.textContent, ""); + assert.equal((await data.entries([entryType])).length, size); + assert(list.children.length > 0); + const dates = records.slice(0, 2).map(record => record.path.slice("journal/".length, -".md".length)); + console.log(`${size} saved entries: ${list.querySelectorAll("button").length} mounted entry buttons`); + return {data, dates, filter(value) {date.value = value; date.dispatchEvent(new window.Event("input"));}, + async close() {view.dispose(); data.release(); pages.mockRestore(); window.close(); await fixture.fixture.close();}}; +} + +for (const size of [1_000, 5_000]) { + const fixture = await history(size); + afterAll(() => fixture.close()); + describe(`${size} daily entries`, () => { + let day = 0; + bench("parse, collect and sort SDK pages", async () => {await fixture.data.entries([entryType]);}); + bench("render the unfiltered entry picker", () => {fixture.filter("");}, {time: 300, iterations: 5, warmupTime: 200, warmupIterations: 2}); + bench("change the date filter", () => {fixture.filter(fixture.dates[day++ % fixture.dates.length]);}); + }); +} diff --git a/package-lock.json b/package-lock.json index b72a8c7..3c0414c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,8 @@ "esbuild": "0.28.1", "jsdom": "26.1.0", "sigstore": "4.1.1", - "typescript": "5.9.3" + "typescript": "5.9.3", + "vitest": "3.2.6" } }, "node_modules/@asamuzakjp/css-color": { @@ -978,8 +979,7 @@ "version": "1.6.0", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.6.0.tgz", "integrity": "sha512-T7jf+5zgsZHwNJ4lvQ7/aezbyk0nNX+zJVWpmHA7VYsEx7a7qr5Rg5IbtJFqkgze5Y2sruq1RUY8Q837Od7iFw==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.31", @@ -1653,6 +1653,370 @@ "node": "^20.17.0 || >=22.9.0" } }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.68.9.tgz", + "integrity": "sha512-Z1hkXtnYKf3sHDD8F2Ll7g9ZGwgAdVNThyz3KiTGSWkjKgYPz/a3TEPoR7ZXE9YlLvbpaO8g+3zisGbU40WQsg==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.68.9.tgz", + "integrity": "sha512-9FG3WZfMVLlbYB8Vyy2w2t50IMbGQ1dWfiCvkacTtXAmXxkHDkxCdomxW6869YEMD1gTsgDF5i9RXASw/8iaZw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-x64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-x64/-/rollup-android-x64-4.68.9.tgz", + "integrity": "sha512-nsxur8e5bfr8YdUwupKED/XJD6X02FVIQkv2zDVJQkesfI0/Lt4vMDFjlWNqWgHbZ38nt8xhk/gbJWdzVtWCfA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.68.9.tgz", + "integrity": "sha512-tkqdvGDK6pmcd419n4zHSFkJcnEIuluYKZArnzWq+O02RYe5jymtAF/c92VP6/JR9nawrV6+LC23GhSPeNZUmA==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.68.9.tgz", + "integrity": "sha512-1vWrRYmFBNs1UKMogcvl5Vg9mdOA3yQgGQGJrQaxHgnR2Qj57L5QiAJBKk1Ednwanxa6dzxGvBaw4I+Evuxz6g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-freebsd-arm64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-arm64/-/rollup-freebsd-arm64-4.68.9.tgz", + "integrity": "sha512-4YhNOyTvFKzrL0/abahYjSG1mIEFqFR+xtVom2T8prSk96z8aNgN3f8GUGCtkkC2eYbZvN9tUAGvgMgVq5FfXg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-freebsd-x64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-freebsd-x64/-/rollup-freebsd-x64-4.68.9.tgz", + "integrity": "sha512-Ng7i+xFFd6I21dpTyA/1VKOuKVUCw5+s9kjeffTmg0OkP3Ldnf2F+XcmNfFAqIirK4Nadi505MVG6delN4XqMw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.68.9.tgz", + "integrity": "sha512-J9JGwMHb6B2Pi6ewp6kVMhzKHSblqC5QS5gV5u8NKw7semdTzETwwZeJLLUfV3YQqAAQxXNz5FGZDGukcwgO4A==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.68.9.tgz", + "integrity": "sha512-cD3CbynGfXBU0BKX6AJ2TCqyd14ChhDQsH2P6BMAKSQaDXGzY1DUPZoQWcNXeJnsTqmoEWo59VlKgnZ9iAAd1w==", + "cpu": [ + "arm" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.68.9.tgz", + "integrity": "sha512-pEMURtf2ARso1VzpDp66G7FGdvpHcOKAT1+9TEqbbkWZ2ek91/KUGSP7RUSH1io8JpZiBkvoNhwELdgHH9b38g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.68.9.tgz", + "integrity": "sha512-x3Ei7a0FYjMe2FMonmgjtRqVlCmrek2NgWC57b4mUbpwtHI9mZV58F0aEdTeA90U0liRks/NRXGQSVETsGP1kg==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-gnu/-/rollup-linux-loong64-gnu-4.68.9.tgz", + "integrity": "sha512-teiOZq8Eka0Yb3IJypBc4dq2U3u5l6P1vZ4sVjOPWJhOFBeOc3bjUnxv2RHn88jsL2qwX4tXuPc0MoqTO+8gww==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-loong64-musl": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-loong64-musl/-/rollup-linux-loong64-musl-4.68.9.tgz", + "integrity": "sha512-51rITRfuF6LN+kZgAdYwk7qkQFlO87Tm1L/nO34kWEIuu8tJmMn1EBdBNdCOM68f93dILWY64QZECKcW2j2i7Q==", + "cpu": [ + "loong64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-gnu/-/rollup-linux-ppc64-gnu-4.68.9.tgz", + "integrity": "sha512-nA1dtgROg2B4FPJbp3cpldu1dfbAs/uGFGsy+ZgZyIojvrGldgdeasnsKHNRuDI6gF47mb63rge6GKZHCiItuA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-ppc64-musl": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-ppc64-musl/-/rollup-linux-ppc64-musl-4.68.9.tgz", + "integrity": "sha512-BG9NS84ehLVomSi35jSFDeMCRL+Mkz0PsBrjuAkgGHT/k+ZZIQ6rlQBmrAa11q/voQsiH8UeaUzi4FZFQn3syw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.68.9.tgz", + "integrity": "sha512-771hNPYszO5g7FeqxR4LO8Qmi2xpjRcXjXfMYsgXLFz+5bNkCR4OPllgyz65v9wlTX4ZoVmbh8pCZhpm2LsykA==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-musl": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-musl/-/rollup-linux-riscv64-musl-4.68.9.tgz", + "integrity": "sha512-zLCA6Rw0J04hsqogzzsUxEUr5jaInUgqkKnw3WsSHuCSQPbXWexrgphDDRJZGMeSCn2GQP7gJtzq/I5NwzVc3w==", + "cpu": [ + "riscv64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.68.9.tgz", + "integrity": "sha512-TDl99JOOD8/uz6I3ECtboFOTZzodZ4VzJqfVjHqCo12fF+F/3bcf4dC5UC3lsGXQCGBMCxGZqrjj3h7fQijf1Q==", + "cpu": [ + "s390x" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.68.9.tgz", + "integrity": "sha512-oagkVYyesngXT4SmFKcGigT1rOZm/uYYowzg7JPP2k9wngF8cw8Kaunzn+HjejJl+Ec2ZD1F68hiXw2FB4cHYA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.68.9.tgz", + "integrity": "sha512-uDyXfmD1FCL+6WtyjhHDjqBKl4j0Kej11iQybR6+h72o5fFL6xyEmWsQWoMngJph9tOeiCeD45f+X0OccYyRlQ==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-openbsd-x64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openbsd-x64/-/rollup-openbsd-x64-4.68.9.tgz", + "integrity": "sha512-sHr4zSqntivPmVau57RrRBMEoTqW8V/iLLfWghbvWcLMOR9PuswVASI4cGA4rJ3PLt8rynrNGK5tVftrH2g+dw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/@rollup/rollup-openharmony-arm64": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-openharmony-arm64/-/rollup-openharmony-arm64-4.68.9.tgz", + "integrity": "sha512-WCZET31LREmsAQCWictbgAdkJLejg7Gzm7hYL51wEROMZ7gziQK38WEfLKRp1Rdm2jnwnLxoJu7ttpjHQWr9CQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openharmony" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.68.9.tgz", + "integrity": "sha512-UwlCeuUlZqWrLpw4LuMgfpp+2e0HOe7cnbkUPoICxCtAFVv3IaB1qKfGaC/iRG3T29hGuzX1Dr20/rqtuVN4bw==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.68.9.tgz", + "integrity": "sha512-NgU7PKTSftWBK2wecMH/McGvM3a4nSa/I8zoS8o22sjPSScuGGyAfr1FoDQWEs+iuvFEQ/PKuRcZ3vO5u0Xqjw==", + "cpu": [ + "ia32" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-gnu": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-gnu/-/rollup-win32-x64-gnu-4.68.9.tgz", + "integrity": "sha512-xbFrHua9IPguaCF7I2bRiebq/OGdIJbHbTUruHMrVD91CcIxhNRpkl2JAiGEPpPaqW7hJLUbroXQ07Kde/ziGg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.68.9.tgz", + "integrity": "sha512-7xXs09Zvhwb0aaVJQ+t+NZYp/G7SMKxt+0BVsoNVP1ckLsTxazNBeqL8b91STBOOPj0o/6NEGLXnFaICm9Yi5Q==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@sigstore/bundle": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@sigstore/bundle/-/bundle-4.0.0.tgz", @@ -1781,6 +2145,31 @@ "node": "^20.17.0 || >=22.9.0" } }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/estree": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.11.tgz", + "integrity": "sha512-YBdNe5JcjYR0sPhJW1QIeRCmI11YhYvaRuGCs9+WCeTTb+Yhb2BE2XMe5/wAqF10FK5g3+q1PDhQABfT7aX0gg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", @@ -1873,6 +2262,147 @@ "license": "MIT", "peer": true }, + "node_modules/@vitest/expect": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.2.6.tgz", + "integrity": "sha512-1+7q9BtaKzEmO+fmNT3kYvoNn5Y71XWAx2Q5HRim4tTVRQVRv4uJFAQ5FbK0OPUeNP/WmVCpxYxoJdvuHVjzBQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/spy": "3.2.6", + "@vitest/utils": "3.2.6", + "chai": "^5.2.0", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/mocker": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/mocker/-/mocker-3.2.6.tgz", + "integrity": "sha512-EZOrpDbkKotFAP7wPAQV1UIyoGOk4oX7ynWhBhLB7v+meMHbQhU16oPpIYGTTe4oFlhpryGpgpcZP/sin3hYuw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/spy": "3.2.6", + "estree-walker": "^3.0.3", + "magic-string": "^0.30.17" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "msw": "^2.4.9", + "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0" + }, + "peerDependenciesMeta": { + "msw": { + "optional": true + }, + "vite": { + "optional": true + } + } + }, + "node_modules/@vitest/pretty-format": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.7.tgz", + "integrity": "sha512-KUHlwqVu0sRlhCdyPdQ/wBoTfRahjUky1MubOmYw9fWfIZy1gNoHpuaaQBPAaMaVYdQYHJLurzj8ECCj5OwTqA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-3.2.6.tgz", + "integrity": "sha512-HYcoSj1w5tcgUnzoF0HcyaAQjpA1gj9ftUJ7iSJSuipc02jW9gKkigwZbjFldAfYHA1fa8UZVRftdMY5msWM9Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/utils": "3.2.6", + "pathe": "^2.0.3", + "strip-literal": "^3.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-3.2.6.tgz", + "integrity": "sha512-H+ZjNTWGpObenh0YnlBctAPnJSI20P81PL8BPzWpx54YXLLTm8hEsWawtcYLMrwvpK48hGxLLbCS+1KRXhsKhw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.2.6", + "magic-string": "^0.30.17", + "pathe": "^2.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/snapshot/node_modules/@vitest/pretty-format": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.6.tgz", + "integrity": "sha512-lb7XXXzmm2h2ASzFnRvQpDo6onT1NmMJA3tkGTWiBFtRJ9lxGY3d3mm/Apt36gej2bkkOVLL/yTOtufDaFa/jA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-3.2.6.tgz", + "integrity": "sha512-oq6BbH68WzcWmwtBrU9nqLeaXTR4XwJF7FSLkKEZo4i6eoXcrxjcwSuTvWBIRUTC6VC72nXYunzqgZA+IKdtxg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyspy": "^4.0.3" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-3.2.6.tgz", + "integrity": "sha512-lI23nIs4bnT3T8NIoh+vFaz5s2/DdP0Jgt2jxwgWljvwn82cLJtyi/If+fjFyoLMGIOz0U/fKvWE0d4jsNQEfg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@vitest/pretty-format": "3.2.6", + "loupe": "^3.1.4", + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils/node_modules/@vitest/pretty-format": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/@vitest/pretty-format/-/pretty-format-3.2.6.tgz", + "integrity": "sha512-lb7XXXzmm2h2ASzFnRvQpDo6onT1NmMJA3tkGTWiBFtRJ9lxGY3d3mm/Apt36gej2bkkOVLL/yTOtufDaFa/jA==", + "dev": true, + "license": "MIT", + "dependencies": { + "tinyrainbow": "^2.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/agent-base": { "version": "7.1.4", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.4.tgz", @@ -1944,6 +2474,16 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/balanced-match": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-4.0.4.tgz", @@ -2027,6 +2567,16 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/cac": { + "version": "6.7.14", + "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", + "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/cacache": { "version": "20.0.4", "resolved": "https://registry.npmjs.org/cacache/-/cacache-20.0.4.tgz", @@ -2093,6 +2643,23 @@ "license": "CC-BY-4.0", "peer": true }, + "node_modules/chai": { + "version": "5.3.3", + "resolved": "https://registry.npmjs.org/chai/-/chai-5.3.3.tgz", + "integrity": "sha512-4zNhdJD/iOjSH0A05ea+Ke6MU5mmpQcbQsSOkgdaUMJ9zTlDTD/GYlwohmIE2u0gaxHYiVHEn1Fw9mZ/ktJWgw==", + "dev": true, + "license": "MIT", + "dependencies": { + "assertion-error": "^2.0.1", + "check-error": "^2.1.1", + "deep-eql": "^5.0.1", + "loupe": "^3.1.0", + "pathval": "^2.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -2110,6 +2677,16 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/check-error": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-2.1.3.tgz", + "integrity": "sha512-PAJdDJusoxnwm1VwW07VWwUN1sl7smmC3OKggvndJFadxxDRyFJBX/ggnu/KE4kQAB7a3Dp8f/YXC1FlUprWmA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 16" + } + }, "node_modules/chokidar": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-5.0.0.tgz", @@ -2281,6 +2858,16 @@ "dev": true, "license": "MIT" }, + "node_modules/deep-eql": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-5.0.2.tgz", + "integrity": "sha512-h5k/5U50IJJFpzfL6nO9jaaumfjO/f2NjK/oYB2Djzm4p9L+3T9qWpZqZ2hAbLPuuYq9wrU08WQyBTL5GbPk5Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/electron-to-chromium": { "version": "1.5.487", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.487.tgz", @@ -2308,6 +2895,13 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/es-module-lexer": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.7.0.tgz", + "integrity": "sha512-jEQoCwk8hyb2AZziIOLhDqpm5+2ww5uIE6lkO/6jcOCusfk6LhMHpXXfBLXTZ7Ydyt0j4VoUQv6uGNYbdW+kBA==", + "dev": true, + "license": "MIT" + }, "node_modules/esbuild": { "version": "0.28.1", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.28.1.tgz", @@ -2360,6 +2954,26 @@ "node": ">=6" } }, + "node_modules/estree-walker": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", + "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.0" + } + }, + "node_modules/expect-type": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/expect-type/-/expect-type-1.4.0.tgz", + "integrity": "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", @@ -2410,6 +3024,21 @@ "node": "^14.17.0 || ^16.13.0 || >=18.0.0" } }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -2775,6 +3404,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/loupe": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-3.2.1.tgz", + "integrity": "sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==", + "dev": true, + "license": "MIT" + }, "node_modules/lru-cache": { "version": "10.4.3", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", @@ -2782,6 +3418,16 @@ "dev": true, "license": "ISC" }, + "node_modules/magic-string": { + "version": "0.30.21", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.21.tgz", + "integrity": "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.5.5" + } + }, "node_modules/make-fetch-happen": { "version": "15.0.6", "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-15.0.6.tgz", @@ -2999,6 +3645,25 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "license": "MIT" }, + "node_modules/nanoid": { + "version": "3.3.20", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.20.tgz", + "integrity": "sha512-uKdg2G3GNCKQn9byYOpxbGqrT2fGO5KRt5J/8b3pok8rT6qxGWF6hxMyJiEYtAf+FVyYuD9hRaDqX5uPFYJ4ZQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/negotiator": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz", @@ -3194,6 +3859,23 @@ "node": "20 || >=22" } }, + "node_modules/pathe": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz", + "integrity": "sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==", + "dev": true, + "license": "MIT" + }, + "node_modules/pathval": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-2.0.1.tgz", + "integrity": "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 14.16" + } + }, "node_modules/pele": { "version": "1.13.0", "resolved": "https://registry.npmjs.org/pele/-/pele-1.13.0.tgz", @@ -3207,8 +3889,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", - "license": "ISC", - "peer": true + "license": "ISC" }, "node_modules/picomatch": { "version": "2.3.2", @@ -3233,6 +3914,35 @@ "node": ">=20" } }, + "node_modules/postcss": { + "version": "8.5.34", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.34.tgz", + "integrity": "sha512-P1Qzj0XXZjMda74C7qiVnBG90UKNbyNUAOeQRBW8X63RsIMV57gevRqjnkELdwtZ/S2/uQFksJhmwuN8xShLPw==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "license": "MIT", + "dependencies": { + "nanoid": "^3.3.20", + "picocolors": "^1.1.1", + "source-map-js": "^1.2.4" + }, + "engines": { + "node": "^10 || ^12 || >=14" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", @@ -3376,6 +4086,52 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/rollup": { + "version": "4.68.9", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.68.9.tgz", + "integrity": "sha512-cv6sHP984hH1Wo4m1yBwyYOTtOVczamnB4KapDqQHCJZLVsMNDsEEP3/+6mHkt7NIAeVGPoE+fFKXRBL5dIjHg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/estree": "^1.0.10" + }, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=18.0.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.68.9", + "@rollup/rollup-android-arm64": "4.68.9", + "@rollup/rollup-android-x64": "4.68.9", + "@rollup/rollup-darwin-arm64": "4.68.9", + "@rollup/rollup-darwin-x64": "4.68.9", + "@rollup/rollup-freebsd-arm64": "4.68.9", + "@rollup/rollup-freebsd-x64": "4.68.9", + "@rollup/rollup-linux-arm-gnueabihf": "4.68.9", + "@rollup/rollup-linux-arm-musleabihf": "4.68.9", + "@rollup/rollup-linux-arm64-gnu": "4.68.9", + "@rollup/rollup-linux-arm64-musl": "4.68.9", + "@rollup/rollup-linux-loong64-gnu": "4.68.9", + "@rollup/rollup-linux-loong64-musl": "4.68.9", + "@rollup/rollup-linux-ppc64-gnu": "4.68.9", + "@rollup/rollup-linux-ppc64-musl": "4.68.9", + "@rollup/rollup-linux-riscv64-gnu": "4.68.9", + "@rollup/rollup-linux-riscv64-musl": "4.68.9", + "@rollup/rollup-linux-s390x-gnu": "4.68.9", + "@rollup/rollup-linux-x64-gnu": "4.68.9", + "@rollup/rollup-linux-x64-musl": "4.68.9", + "@rollup/rollup-openbsd-x64": "4.68.9", + "@rollup/rollup-openharmony-arm64": "4.68.9", + "@rollup/rollup-win32-arm64-msvc": "4.68.9", + "@rollup/rollup-win32-ia32-msvc": "4.68.9", + "@rollup/rollup-win32-x64-gnu": "4.68.9", + "@rollup/rollup-win32-x64-msvc": "4.68.9", + "fsevents": "~2.3.2" + } + }, "node_modules/rrweb-cssom": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz", @@ -3422,6 +4178,13 @@ "node": ">=10" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true, + "license": "ISC" + }, "node_modules/signal-exit": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", @@ -3504,6 +4267,16 @@ "node": ">= 12" } }, + "node_modules/source-map-js": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.4.tgz", + "integrity": "sha512-J7ZjMvHd9O1fcT/5V09QWaaSl2BbWx3F6O08spde82Namf9UB0GxRVIPiNbVsdKkoizHiSpTodo3vp2bAy91MA==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/ssri": { "version": "13.0.1", "resolved": "https://registry.npmjs.org/ssri/-/ssri-13.0.1.tgz", @@ -3517,6 +4290,20 @@ "node": "^20.17.0 || >=22.9.0" } }, + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true, + "license": "MIT" + }, + "node_modules/std-env": { + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.10.0.tgz", + "integrity": "sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==", + "dev": true, + "license": "MIT" + }, "node_modules/stdin-discarder": { "version": "0.3.2", "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.3.2.tgz", @@ -3558,6 +4345,26 @@ "node": ">=8" } }, + "node_modules/strip-literal": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-3.1.0.tgz", + "integrity": "sha512-8r3mkIM/2+PpjHoOtiAW8Rg3jJLHaV7xPwG+YRGrv6FP0wwk/toTpATxWYOW0BKdWwl82VT2tFYi5DlROa0Mxg==", + "dev": true, + "license": "MIT", + "dependencies": { + "js-tokens": "^9.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, + "node_modules/strip-literal/node_modules/js-tokens": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-9.0.1.tgz", + "integrity": "sha512-mxa9E9ITFOt0ban3j6L5MpjwegGz6lBQmM1IJkWeBZGcMxto50+eWdjC/52xDbS2vy0k7vIMK0Fe2wfL9OQSpQ==", + "dev": true, + "license": "MIT" + }, "node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -3578,6 +4385,68 @@ "dev": true, "license": "MIT" }, + "node_modules/tinybench": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz", + "integrity": "sha512-0+DUvqWMValLmha6lr4kD8iAMK1HzV0/aKnCtWb9v9641TnP/MFb7Pc2bxoxQjTXAErryXVgUOfv2YqNllqGeg==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyexec": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-0.3.2.tgz", + "integrity": "sha512-KQQR9yN7R5+OSwaK0XQoj22pwHoTlgYqmUscPYoknOoWCWfj/5/ABTMRi69FrKU5ffPVh5QcFikpWJI/P1ocHA==", + "dev": true, + "license": "MIT" + }, + "node_modules/tinyglobby": { + "version": "0.2.17", + "resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.17.tgz", + "integrity": "sha512-wXR/dYpcqKmfWpEdZjiKJOwCNFndD0DMnrW/cYjVGttEkBfVgcLFHoNrlj47mjOVic9yyNu65alsgF4NQyTa2g==", + "dev": true, + "license": "MIT", + "dependencies": { + "fdir": "^6.5.0", + "picomatch": "^4.0.4" + }, + "engines": { + "node": ">=12.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/SuperchupuDev" + } + }, + "node_modules/tinyglobby/node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/tinyglobby/node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/tinypool": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-2.2.0.tgz", @@ -3588,6 +4457,26 @@ "node": "^20.0.0 || >=22.0.0" } }, + "node_modules/tinyrainbow": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tinyrainbow/-/tinyrainbow-2.0.0.tgz", + "integrity": "sha512-op4nsTR47R6p0vMUUoYl/a+ljLFVtlfaXkLQmqfLR1qHma1h/ysYk4hEXZ880bf2CYgTskvTa/e196Vd5dDQXw==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tinyspy": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-4.0.6.tgz", + "integrity": "sha512-u8KszXvGfU68hVcZpRHKG28T0krMuv2G5nDhiHaMLen/gIuFEgIJhaJuO69qjnXg5paSrbPMFfx3brNuN8eVSg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/tldts": { "version": "6.1.86", "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz", @@ -3723,6 +4612,231 @@ "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, + "node_modules/vite": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/vite/-/vite-7.3.8.tgz", + "integrity": "sha512-3tTi78MAKhVk9h+YZVXMQ8POmneJuE97QUPAWtJghHzhH7BAyiqQOC2KZh1DWOsu/USB2cRXhznPByaabvYXfw==", + "dev": true, + "license": "MIT", + "dependencies": { + "esbuild": "^0.27.0 || ^0.28.0", + "fdir": "^6.5.0", + "picomatch": "^4.0.3", + "postcss": "^8.5.6", + "rollup": "^4.43.0", + "tinyglobby": "^0.2.15" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^20.19.0 || >=22.12.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.3" + }, + "peerDependencies": { + "@types/node": "^20.19.0 || >=22.12.0", + "jiti": ">=1.21.0", + "less": "^4.0.0", + "lightningcss": "^1.21.0", + "sass": "^1.70.0", + "sass-embedded": "^1.70.0", + "stylus": ">=0.54.8", + "sugarss": "^5.0.0", + "terser": "^5.16.0", + "tsx": "^4.8.1", + "yaml": "^2.4.2" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "jiti": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "sass-embedded": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + }, + "tsx": { + "optional": true + }, + "yaml": { + "optional": true + } + } + }, + "node_modules/vite-node": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-3.2.4.tgz", + "integrity": "sha512-EbKSKh+bh1E1IFxeO0pg1n4dvoOTt0UDiXMd/qn++r98+jPO1xtJilvXldeuQ8giIB5IkpjCgMleHMNEsGH6pg==", + "dev": true, + "license": "MIT", + "dependencies": { + "cac": "^6.7.14", + "debug": "^4.4.1", + "es-module-lexer": "^1.7.0", + "pathe": "^2.0.3", + "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0" + }, + "bin": { + "vite-node": "vite-node.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vite/node_modules/fdir": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz", + "integrity": "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12.0.0" + }, + "peerDependencies": { + "picomatch": "^3 || ^4" + }, + "peerDependenciesMeta": { + "picomatch": { + "optional": true + } + } + }, + "node_modules/vite/node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/vitest": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-3.2.6.tgz", + "integrity": "sha512-xejya+bT/j/+R/AGa1XOfRxLmNUlLtlwjRsFUILF+xHfzElmGcmFydy2gqqIrd62ptIEfwVMofd19uNWD9L7Nw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/chai": "^5.2.2", + "@vitest/expect": "3.2.6", + "@vitest/mocker": "3.2.6", + "@vitest/pretty-format": "^3.2.6", + "@vitest/runner": "3.2.6", + "@vitest/snapshot": "3.2.6", + "@vitest/spy": "3.2.6", + "@vitest/utils": "3.2.6", + "chai": "^5.2.0", + "debug": "^4.4.1", + "expect-type": "^1.2.1", + "magic-string": "^0.30.17", + "pathe": "^2.0.3", + "picomatch": "^4.0.2", + "std-env": "^3.9.0", + "tinybench": "^2.9.0", + "tinyexec": "^0.3.2", + "tinyglobby": "^0.2.14", + "tinypool": "^1.1.1", + "tinyrainbow": "^2.0.0", + "vite": "^5.0.0 || ^6.0.0 || ^7.0.0-0", + "vite-node": "3.2.4", + "why-is-node-running": "^2.3.0" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": "^18.0.0 || ^20.0.0 || >=22.0.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@types/debug": "^4.1.12", + "@types/node": "^18.0.0 || ^20.0.0 || >=22.0.0", + "@vitest/browser": "3.2.6", + "@vitest/ui": "3.2.6", + "happy-dom": "*", + "jsdom": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@types/debug": { + "optional": true + }, + "@types/node": { + "optional": true + }, + "@vitest/browser": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + } + } + }, + "node_modules/vitest/node_modules/picomatch": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.7.tgz", + "integrity": "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/vitest/node_modules/tinypool": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-1.1.1.tgz", + "integrity": "sha512-Zba82s87IFq9A9XmjiX5uZA/ARWDrB03OHlq+Vw1fSdt0I+4/Kutwy8BP4Y/y/aORMo61FQ0vIb5j44vSo5Pkg==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^18.0.0 || >=20.0.0" + } + }, "node_modules/w3c-xmlserializer": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", @@ -3784,6 +4898,23 @@ "node": ">=18" } }, + "node_modules/why-is-node-running": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.3.0.tgz", + "integrity": "sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==", + "dev": true, + "license": "MIT", + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/ws": { "version": "8.22.0", "resolved": "https://registry.npmjs.org/ws/-/ws-8.22.0.tgz", diff --git a/package.json b/package.json index 3c6336e..6a8239c 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "private": true, "type": "module", "scripts": { + "bench:history": "node node_modules/vitest/vitest.mjs bench --run benchmarks/journal-history.bench.mjs", "check:release-downloads": "node scripts/check-release-downloads.mjs", "test:release-downloads": "node --test scripts/check-release-downloads.test.mjs", "build": "node scripts/build-application.mjs", @@ -35,6 +36,7 @@ "esbuild": "0.28.1", "jsdom": "26.1.0", "sigstore": "4.1.1", - "typescript": "5.9.3" + "typescript": "5.9.3", + "vitest": "3.2.6" } } diff --git a/public/index.html b/public/index.html index 2b6fd01..7cf9140 100644 --- a/public/index.html +++ b/public/index.html @@ -100,6 +100,11 @@

Journal entries

+
diff --git a/public/journal.css b/public/journal.css index fa1ac17..e0798dd 100644 --- a/public/journal.css +++ b/public/journal.css @@ -45,6 +45,8 @@ body.typing:not(.quiet) .hint,body.undo .hint,body.retry .hint,.hint:focus-withi #entry-list { display:grid; gap:0; max-height:45vh; overflow:auto; } #entry-list button { display:grid; gap:4px; text-align:left; min-height:44px; margin:0; padding:12px 0; border-bottom:1px solid var(--faint); } #entry-list small { color:var(--muted); overflow-wrap:anywhere; } +#entry-pagination { align-items:center; justify-content:space-between; } +#entry-range { color:var(--muted); font-variant-numeric:tabular-nums; } .sheet { padding:20px; display:grid; grid-template-columns:minmax(0,1fr); min-width:0; gap:16px; } .sheet > h2 { margin:0; font:500 .9375rem/1.3 Inter,sans-serif; } .sheet p:not(.mdbase-collections *) { margin:0; color:var(--muted); } .sheet a:not(.mdbase-collections *) { display:inline-flex; align-items:center; min-height:44px; min-width:0; overflow-wrap:anywhere; color:var(--accent); } .row { display:grid; grid-template-columns:minmax(0,1fr); min-width:0; gap:6px; } .row label,.label { font-size:.75rem; color:var(--muted); } diff --git a/src/journal-data.ts b/src/journal-data.ts index d760a07..5bec8cd 100644 --- a/src/journal-data.ts +++ b/src/journal-data.ts @@ -81,8 +81,10 @@ export class JournalData { for (const record of page.records) { const type = types.find(type => record.types.includes(type.name)); const created = type ? record.frontmatter[type.createdField] : null; - if (typeof created !== "string" || !Number.isFinite(Date.parse(created))) continue; - entries.push({id: record.id, created, createdMs: Date.parse(created), path: record.path}); + if (typeof created !== "string") continue; + const createdMs = Date.parse(created); + if (!Number.isFinite(createdMs)) continue; + entries.push({id: record.id, created, createdMs, path: record.path}); } } // A query can omit a record because its type/date changed. Only an ordinary diff --git a/src/view.ts b/src/view.ts index d3de434..62fb584 100644 --- a/src/view.ts +++ b/src/view.ts @@ -14,6 +14,28 @@ import { } from "./setup-conflicts.js"; export interface JournalView {dispose(): void; currentDraft(): JournalDraft; newPage(): void; undoNewPage(): void} const app = {name: "Journal"}; +const entriesPerPage = 50; + +function dayBounds(year: number, month: number, day: number): [start: number, end: number] { + const midnight = (day: number) => { + const local = new Date(0); + local.setFullYear(year, month, day); + return local.setHours(0, 0, 0, 0); + }; + return [midnight(day), midnight(day + 1)]; +} + +/** JournalData returns newest first, so a date filter can skip unrelated entries. */ +function firstOlderThan(entries: readonly JournalEntry[], time: number): number { + let start = 0, end = entries.length; + while (start < end) { + const middle = Math.floor((start + end) / 2); + if (entries[middle]!.createdMs >= time) start = middle + 1; + else end = middle; + } + return start; +} + interface TypesProblem {readonly title: string; readonly detail: string} /** Why the open collection gives Journal no entry type. Journal's own catalog * checks explain themselves; SDK errors use SDK copy; anything else is named @@ -86,10 +108,14 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: unpersistedDraft = !earlier; } catch {problem = "Earlier notes could not be read on this device. Their text is still preserved.";} const entriesDialog = element("entries"), entryDate = element("entry-date"); + const entryList = element("entry-list"), entryStatus = element("entries-status"); + const entryPagination = element("entry-pagination"), entryRange = element("entry-range"); + const newerEntries = element("newer-entries"), olderEntries = element("older-entries"); + const entryLabel = new Intl.DateTimeFormat(undefined, {weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"}); let entries: JournalEntry[] = []; + let entryPage = 0; let entriesProblem: string | null = null; let entriesLoading = false; - const dateKey = (ms: number): string => {const date = new Date(ms); return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;}; try {drafts.pruneConfirmed();} catch {/* Best-effort cleanup never interrupts local writing. */} try {drafts.importLegacy();} catch {problem = "Earlier notes could not be copied on this device. Their original text is still preserved.";} const listen = (target: EventTarget, name: string, handler: EventListener) => target.addEventListener(name, handler, {signal: caller.signal}); @@ -197,7 +223,6 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: element("start-new-after-deletion").hidden = !current.deletedElsewhere; element("use-saved-version").hidden = !!current.deletedElsewhere; element("use-saved-version").disabled = !!current.deletedElsewhere || current.reviewRequired === true && !data; - if (entriesDialog.open) renderEntries(); document.body.classList.toggle("typing", !!current.body.trim()); const state = snapshot(); const phase = state?.phase ?? null; @@ -205,7 +230,14 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: phase && "displayName" in phase && phase.displayName ? phase.displayName : "your collection"; const record = data?.snapshot(current.id); let unresolved: JournalDraft[] = []; - try {unresolved = drafts.list().filter(draft => !!draft.body.trim() && draft.body !== draft.savedBody);} catch {problem = "Keep this page open: Journal cannot read its drafts on this device.";} + try { + const localDrafts = drafts.list(); + if (entriesDialog.open) renderEntries(localDrafts); + unresolved = localDrafts.filter(draft => !!draft.body.trim() && draft.body !== draft.savedBody); + } catch { + if (entriesDialog.open) {entriesProblem = "Earlier notes could not be read on this device."; renderEntries([]);} + problem = "Keep this page open: Journal cannot read its drafts on this device."; + } let message = problem ?? data?.problem(current.id); const opening = opens?.state(current.id); if (!message && current.deletedElsewhere) message = DELETED_ENTRY_NOTICE; @@ -348,24 +380,46 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: page.focus(); } catch {problem = "Keep this page open: Journal cannot restore the earlier text safely."; render();} });} - function visibleEntries(): {entry: JournalEntry; draft: JournalDraft | null}[] { + function visibleEntries(bounds: [number, number] | null, localDrafts: readonly JournalDraft[]): {entry: JournalEntry; draft: JournalDraft | null}[] { const collection = snapshot()?.selectedCollectionId ?? current.targetCollectionId; - const local = drafts.list().filter(draft => draft.targetCollectionId === collection && + const local = localDrafts.filter(draft => draft.targetCollectionId === collection && (draft.deletedElsewhere ? draft.body !== draft.savedBody : draft.body.trim())); - const rows = entries.filter(entry => !local.some(draft => draft.recordId === entry.id)) + const [start, end] = bounds ?? [-Infinity, Infinity]; + const saved = bounds ? entries.slice(firstOlderThan(entries, end), firstOlderThan(entries, start)) : entries; + const localRecordIds = new Set(local.map(draft => draft.recordId)); + const rows = saved.filter(entry => !localRecordIds.has(entry.id)) .map(entry => ({entry, draft: null as JournalDraft | null})); - rows.push(...local.map(draft => ({entry: {id: draft.id, created: draft.created, createdMs: draft.createdMs, path: draft.path ?? ""}, draft}))); + for (const draft of local) { + if (draft.createdMs < start || draft.createdMs >= end) continue; + rows.push({entry: {id: draft.id, created: draft.created, createdMs: draft.createdMs, path: draft.path ?? ""}, draft}); + } return rows.sort((a, b) => b.entry.createdMs - a.entry.createdMs); } - function renderEntries(): void { + function renderEntries(localDrafts?: readonly JournalDraft[]): void { let rows: ReturnType = []; - try {rows = visibleEntries().filter(row => !entryDate.value || dateKey(row.entry.createdMs) === entryDate.value);} + try { + const [year, month, day] = entryDate.value.split("-").map(Number); + const bounds = year && month && day ? dayBounds(year, month - 1, day) : null; + rows = visibleEntries(bounds, localDrafts ?? drafts.list()); + } catch {entriesProblem = "Earlier notes could not be read on this device.";} - element("entries-status").textContent = entriesProblem ?? (entriesLoading ? "Loading entries…" : rows.length ? "" : "No entries on this date. Start a page below."); - element("entry-list").replaceChildren(...rows.map(({entry, draft}) => { + const message = entriesProblem ?? (entriesLoading ? "Loading entries…" : rows.length ? "" : "No entries on this date. Start a page below."); + if (entryStatus.textContent !== message) entryStatus.textContent = message; + entryPage = Math.min(entryPage, Math.max(0, Math.ceil(rows.length / entriesPerPage) - 1)); + const first = entryPage * entriesPerPage, last = Math.min(first + entriesPerPage, rows.length); + entryPagination.hidden = rows.length <= entriesPerPage; + newerEntries.disabled = first === 0; + olderEntries.disabled = last === rows.length; + const range = rows.length > entriesPerPage ? `${first + 1}–${last} of ${rows.length}` : ""; + if (entryRange.textContent !== range) entryRange.textContent = range; + const focusedId = entryList.contains(document.activeElement) ? (document.activeElement as HTMLElement).dataset.entryId : null; + let refocus: HTMLButtonElement | undefined; + entryList.replaceChildren(...rows.slice(first, last).map(({entry, draft}) => { const button = document.createElement("button"); button.type = "button"; + button.dataset.entryId = entry.id; + if (entry.id === focusedId) refocus = button; const date = document.createElement("span"), summary = document.createElement("small"); - date.textContent = new Date(entry.createdMs).toLocaleString(undefined, {weekday: "short", month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit"}); + date.textContent = entryLabel.format(entry.createdMs); summary.textContent = draft?.body.trim().split("\n")[0]?.slice(0, 100) ?? entry.path.split("/").pop() ?? "Journal entry"; if (draft?.deletedElsewhere) summary.textContent = `Deleted elsewhere · ${summary.textContent || "Your text stays on this device"}`; button.append(date, summary); button.disabled = memoryOnly; @@ -381,17 +435,15 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: }; return button; })); + refocus?.focus({preventScroll: true}); } - function browse(date = ""): void { - entryDate.value = date; entriesProblem = null; renderEntries(); + function browse(): void { + entryDate.value = ""; entryPage = 0; entriesProblem = null; entriesLoading = !!data; + renderEntries(); entryList.scrollTop = 0; if (!entriesDialog.open) entriesDialog.showModal(); - const owned = data; - if (!owned) return; - entriesLoading = true; renderEntries(); // The ready connection can arrive before its catalog. Its completion below // refreshes this sheet; never mistake that interval for an empty journal. - if (!types.length) return; - void refreshEntries?.(); + if (types.length) void refreshEntries?.(); } function closeEntries(): void {entriesDialog.close();} function startOnDate(date: Date, onSelected?: () => void): void {transaction(() => { @@ -409,7 +461,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: const originalId = current.id, owned = data; const date = new Date(current.createdMs); date.setDate(date.getDate() + offset); date.setHours(12, 0, 0, 0); - const destination = dateKey(date.getTime()); + const destination = dayBounds(date.getFullYear(), date.getMonth(), date.getDate()); const stillCurrent = (): boolean => !disposed && !memoryOnly && data === owned && current.id === originalId && !entriesDialog.open; navigatingDay = true; element("previous-day").disabled = true; @@ -421,7 +473,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: if (!stillCurrent()) return; entries = loaded; } - const row = visibleEntries().find(row => dateKey(row.entry.createdMs) === destination); + const row = visibleEntries(destination, drafts.list())[0]; if (row) { const earlier = row.draft ?? await owned?.resume(row.entry); if (!stillCurrent() || !earlier) return; @@ -438,7 +490,15 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: listen(element("browse-button"), "click", () => browse()); listen(element("previous-day"), "click", () => {void adjacentDay(-1);}); listen(element("next-day"), "click", () => {void adjacentDay(1);}); - listen(entryDate, "input", renderEntries); + listen(entryDate, "input", () => {entryPage = 0; renderEntries(); entryList.scrollTop = 0;}); + function moveEntryPage(offset: number): void { + entryPage += offset; + renderEntries(); + entryList.scrollTop = 0; + entryList.querySelector("button")?.focus(); + } + listen(newerEntries, "click", () => moveEntryPage(-1)); + listen(olderEntries, "click", () => moveEntryPage(1)); listen(element("close-entries"), "click", closeEntries); listen(entriesDialog, "close", () => page.focus()); listen(element("write-date"), "click", () => { @@ -497,13 +557,13 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: if (next !== data?.connection) { unlistenData?.(); unlistenData = null; unlistenStatus?.(); unlistenStatus = null; unlistenEntries?.(); unlistenEntries = null; refreshEntries = null; opens?.dispose(); opens = null; data?.release(); data = null; types = []; type = null; catalogProblem = null; - entries = []; entriesLoading = false; + entries = []; entryPage = 0; entriesLoading = !!next && entriesDialog.open; if (next) { const owned = new JournalData(next, drafts); data = owned; let refreshing: Promise | null = null, refreshAgain = false; - const refresh = (): Promise => { + const refresh = (again = true): Promise => { if (disposed || data !== owned || !types.length) return Promise.resolve(); - if (refreshing) {refreshAgain = true; return refreshing;} + if (refreshing) {refreshAgain ||= again; return refreshing;} refreshing = (async () => { do { refreshAgain = false; @@ -520,7 +580,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: })().finally(() => {refreshing = null; if (refreshAgain) void refresh();}); return refreshing; }; - refreshEntries = refresh; + refreshEntries = () => refresh(false); opens = new DraftOpens(owned, drafts, () => !disposed && data === owned && owned.connection.isCurrent(), render, document.defaultView?.navigator.locks); unlistenData = owned.subscribe(render); // Entry types come from the collection's catalog. Until they load, notes @@ -537,7 +597,6 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase: types = value; type = value.find(item => item.name === preferences.entryTypes?.[owned.connection.id]) ?? (value.length === 1 ? value[0]! : null); render(); void save(); void refresh(); - if (entriesDialog.open) browse(entryDate.value); }, error => { loadingTypes = false; if (disposed || data !== owned) return; diff --git a/tests/navigation.test.ts b/tests/navigation.test.ts index 56a9112..35cbd85 100644 --- a/tests/navigation.test.ts +++ b/tests/navigation.test.ts @@ -62,6 +62,81 @@ test("date navigation lists every local page, resumes its identity and survives assert.equal(drafts.get(first.id)?.body, "First January page"); reloaded.dispose(); window.close(); }); + +test("large entry history keeps pagination bounded and date filtering can reach the oldest page", () => { + const {window} = new JSDOM(html, {url: "https://journal.fixture/"}); + const {document} = window; + const drafts = new JournalDrafts(memoryStorage()); + for (let day = 1; day <= 120; day++) { + const entry = drafts.create(null, new Date(2025, 0, day, 12)); + drafts.patch(entry.id, {body: `Page ${day}`, finished: true}); + } + const view = mountJournal(document, drafts, null); + const dialog = document.querySelector("#entries")!; + dialog.showModal = () => dialog.setAttribute("open", ""); + dialog.close = () => dialog.removeAttribute("open"); + const list = document.getElementById("entry-list")!; + const range = document.getElementById("entry-range")!; + const newer = document.querySelector("#newer-entries")!; + const older = document.querySelector("#older-entries")!; + const date = document.querySelector("#entry-date")!; + try { + document.getElementById("browse-button")!.click(); + assert.equal(list.childElementCount, 50); + assert.equal(range.textContent, "1–50 of 120"); + assert.equal(newer.disabled, true); + older.click(); + assert.equal(range.textContent, "51–100 of 120"); + assert.equal(document.activeElement, list.firstElementChild); + older.click(); + assert.equal(list.childElementCount, 20); + assert.equal(range.textContent, "101–120 of 120"); + assert.equal(older.disabled, true); + newer.click(); + assert.equal(range.textContent, "51–100 of 120"); + + date.value = "2025-01-01"; + date.dispatchEvent(new window.Event("input")); + assert.equal(list.childElementCount, 1); + assert.equal(document.getElementById("entry-pagination")!.hidden, true); + assert.equal(list.querySelector("small")!.textContent, "Page 1"); + list.querySelector("button")!.click(); + assert.equal(dialog.open, false); + assert.equal(view.currentDraft().body, "Page 1"); + } finally {view.dispose(); window.close();} +}); +test("date filtering uses local midnight and hides saved rows shadowed by a local draft", async () => { + const f = await applicationFixture(); + const {window} = new JSDOM(html, {url: "https://journal.fixture/"}); + const {document} = window; + const drafts = new JournalDrafts(memoryStorage()); + const start = new Date(2025, 3, 6), end = new Date(2025, 3, 7); + const recordId = "018e0000-0000-7000-8000-000000000050"; + const saved = (name: string, time: number, id = name) => ({id, created: new Date(time).toISOString(), createdMs: time, path: `journal/${name}.md`}); + const shadowed = saved("shadowed", end.getTime() - 1, recordId); + await f.records.settle(f.records.create({id: recordId, type: "collection-owned-entry", path: shadowed.path, + frontmatter: {created: shadowed.created}, body: "Local copy"})); + const rows = [ + saved("next-day", end.getTime()), shadowed, + saved("midnight", start.getTime()), saved("previous-day", start.getTime() - 1), + ]; + const lookup = mock.method(JournalData.prototype, "entries", async () => rows); + const local = drafts.create(f.connection.id, new Date(end.getTime() - 1)); + drafts.patch(local.id, {recordId, body: "Local copy", savedBody: "Local copy"}); + const view = mountJournal(document, drafts, f.mdbase); + const dialog = document.querySelector("#entries")!; + dialog.showModal = () => dialog.setAttribute("open", ""); + const date = document.querySelector("#entry-date")!; + const summaries = () => [...document.querySelectorAll("#entry-list small")].map(item => item.textContent); + try { + document.getElementById("browse-button")!.click(); + date.value = "2025-04-06"; + date.dispatchEvent(new window.Event("input")); + for (let i = 0; i < 100 && summaries().length !== 2; i++) await new Promise(resolve => setTimeout(resolve, 5)); + assert.deepEqual(summaries(), ["Local copy", "midnight.md"]); + } finally {view.dispose(); lookup.mock.restore(); window.close(); await f.fixture.close();} +}); + test("day arrows resume the latest same-collection page and step empty dates without creating records", () => { const window = new JSDOM(html, {url: "https://journal.fixture/"}).window, document = window.document; const drafts = new JournalDrafts(memoryStorage());