@takazudo/zfb 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/paginate.js +6 -4
- package/dist/paginate.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -79,7 +79,10 @@ surface. Today it covers:
|
|
|
79
79
|
|
|
80
80
|
The package is JSX-runtime-agnostic: the `Island` component does not
|
|
81
81
|
import preact or react, so it works under either framework adapter
|
|
82
|
-
without bundling the wrong runtime.
|
|
82
|
+
without bundling the wrong runtime. `react` is listed as a peer
|
|
83
|
+
dependency but is **optional** (`peerDependenciesMeta.react.optional`)
|
|
84
|
+
— a preact/compat-only consumer does not need `react` installed and
|
|
85
|
+
does not need `auto-install-peers=true`.
|
|
83
86
|
|
|
84
87
|
## Usage
|
|
85
88
|
|
package/dist/paginate.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
// `zfb/paginate` — paginate an array of items into per-page route entries.
|
|
2
2
|
//
|
|
3
|
-
// Mirrors the shape of Astro's `paginate()` so
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
3
|
+
// Mirrors the shape of Astro's `paginate()` so a `paths()` export can emit
|
|
4
|
+
// one route per page. The renderer treats each returned object as
|
|
5
|
+
// `{ params, props }`, the same convention used elsewhere by the routing
|
|
6
|
+
// engine. The bundled basic-blog template ships no paginated route — it
|
|
7
|
+
// links this API as a next step instead — so the docs page is the worked
|
|
8
|
+
// example.
|
|
7
9
|
/**
|
|
8
10
|
* Slice `items` into pages of `opts.pageSize` and produce one route entry
|
|
9
11
|
* per page. The `param` option names the dynamic segment to fill — for
|
package/dist/paginate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paginate.js","sourceRoot":"","sources":["../src/paginate.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,
|
|
1
|
+
{"version":3,"file":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;YACV,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,IAAI,CAAC,EAAuB;YAC3D,KAAK,EAAE;gBACL,IAAI,EAAE;oBACJ,IAAI,EAAE,KAAK;oBACX,IAAI;oBACJ,QAAQ;oBACR,QAAQ;oBACR,KAAK;iBACN;aACF;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["// `zfb/paginate` — paginate an array of items into per-page route entries.\n//\n// Mirrors the shape of Astro's `paginate()` so a `paths()` export can emit\n// one route per page. The renderer treats each returned object as\n// `{ params, props }`, the same convention used elsewhere by the routing\n// engine. The bundled basic-blog template ships no paginated route — it\n// links this API as a next step instead — so the docs page is the worked\n// example.\n\n/** Options accepted by [`paginate`]. */\nexport type PaginateOptions<K extends string = string> = {\n /** Items per page. Must be a positive integer (>= 1). */\n pageSize: number;\n /** Name of the dynamic param to fill (e.g. `\"page\"` for `[page].tsx`). */\n param: K;\n};\n\n/** One page of paginated results. The shape consumed by the page component. */\nexport type PaginatedPage<T> = {\n /** Items belonging to this page. */\n data: T[];\n /** 1-based page number. */\n page: number;\n /** Total number of pages (>= 1). */\n lastPage: number;\n /** Items per page (echoed for convenience). */\n pageSize: number;\n /** Total item count across all pages. */\n total: number;\n};\n\n/**\n * Route entry returned by [`paginate`], one per page.\n *\n * The `K` generic carries the literal param name through, so consumers\n * accessing e.g. `route.params.page` get `string` rather than\n * `string | undefined` under `noUncheckedIndexedAccess`.\n */\nexport type PaginateRoute<T, K extends string = string> = {\n params: Record<K, string>;\n props: { page: PaginatedPage<T> };\n};\n\n/**\n * Slice `items` into pages of `opts.pageSize` and produce one route entry\n * per page. The `param` option names the dynamic segment to fill — for\n * `pages/blog/page/[page].tsx` pass `param: \"page\"`.\n *\n * Always emits at least one route. An empty input list yields a single\n * empty page so the index route still renders rather than 404ing.\n */\nexport function paginate<T, K extends string = string>(\n items: readonly T[],\n opts: PaginateOptions<K>,\n): PaginateRoute<T, K>[] {\n if (!Number.isInteger(opts.pageSize) || opts.pageSize < 1) {\n throw new RangeError(\n `paginate: pageSize must be an integer >= 1, got ${String(opts.pageSize)}`,\n );\n }\n if (typeof opts.param !== \"string\" || opts.param.length === 0) {\n throw new TypeError(\n `paginate: param must be a non-empty string, got ${JSON.stringify(opts.param)}`,\n );\n }\n const pageSize = opts.pageSize;\n const total = items.length;\n const lastPage = Math.max(1, Math.ceil(total / pageSize));\n const routes: PaginateRoute<T, K>[] = [];\n for (let page = 1; page <= lastPage; page++) {\n const start = (page - 1) * pageSize;\n const slice = items.slice(start, start + pageSize);\n routes.push({\n params: { [opts.param]: String(page) } as Record<K, string>,\n props: {\n page: {\n data: slice,\n page,\n lastPage,\n pageSize,\n total,\n },\n },\n });\n }\n return routes;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takazudo/zfb",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Rust-built static-site engine for Astro and Next.js users — millisecond rebuilds, single binary. SDK with islands, content collections, pagination, and config helpers.",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
"LICENSE"
|
|
75
75
|
],
|
|
76
76
|
"optionalDependencies": {
|
|
77
|
-
"@takazudo/zfb-darwin-arm64": "2.
|
|
78
|
-
"@takazudo/zfb-darwin-x64": "2.
|
|
79
|
-
"@takazudo/zfb-linux-arm64-gnu": "2.
|
|
80
|
-
"@takazudo/zfb-linux-x64-gnu": "2.
|
|
81
|
-
"@takazudo/zfb-win32-x64-msvc": "2.
|
|
77
|
+
"@takazudo/zfb-darwin-arm64": "2.2.0",
|
|
78
|
+
"@takazudo/zfb-darwin-x64": "2.2.0",
|
|
79
|
+
"@takazudo/zfb-linux-arm64-gnu": "2.2.0",
|
|
80
|
+
"@takazudo/zfb-linux-x64-gnu": "2.2.0",
|
|
81
|
+
"@takazudo/zfb-win32-x64-msvc": "2.2.0"
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"access": "public"
|