@mk-kit/ui 0.52.0 → 0.53.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.
@@ -2181,6 +2181,15 @@ class MkTableDataSource {
2181
2181
  refresh() {
2182
2182
  this.load();
2183
2183
  }
2184
+ /**
2185
+ * Back to page 1 and load — the "filters changed outside the search box"
2186
+ * case. Unlike {@link setPage}, this loads even when already on page 1, so
2187
+ * callers no longer need `page() === 1 ? refresh() : setPage(1)`.
2188
+ */
2189
+ reload() {
2190
+ this._page.set(1);
2191
+ this.load();
2192
+ }
2184
2193
  /**
2185
2194
  * Pipe an `mkSort` directive's changes into {@link setSort}. Idempotent per
2186
2195
  * directive instance; all subscriptions are released by {@link destroy}.
@@ -2300,6 +2309,45 @@ class MkTableDataSource {
2300
2309
  sub.unsubscribe();
2301
2310
  }
2302
2311
  }
2312
+ /**
2313
+ * In-memory {@link MkDataFetcher}: filter, sort and slice a full row set that
2314
+ * the app already holds (an API that returns everything). Lets a client-side
2315
+ * list use {@link MkTableDataSource} — same pager, footer and API as a
2316
+ * server-paged one — without hand-rolling `filtered/sorted/paged` computeds.
2317
+ *
2318
+ * ```ts
2319
+ * ds = new MkTableDataSource(mkClientFetcher(() => this.rows()));
2320
+ * ```
2321
+ */
2322
+ function mkClientFetcher(rows, opts = {}) {
2323
+ const match = opts.match ??
2324
+ ((row, q) => Object.values(row).some((v) => (typeof v === 'string' || typeof v === 'number') &&
2325
+ String(v).toLowerCase().includes(q)));
2326
+ const compare = opts.compare ??
2327
+ ((a, b, sort) => {
2328
+ const av = a[sort.active];
2329
+ const bv = b[sort.active];
2330
+ if (av == null && bv == null)
2331
+ return 0;
2332
+ if (av == null)
2333
+ return 1;
2334
+ if (bv == null)
2335
+ return -1;
2336
+ if (typeof av === 'number' && typeof bv === 'number')
2337
+ return av - bv;
2338
+ return String(av).localeCompare(String(bv), undefined, { numeric: true, sensitivity: 'base' });
2339
+ });
2340
+ return (req) => {
2341
+ const q = req.filter.trim().toLowerCase();
2342
+ let out = q ? rows().filter((r) => match(r, q)) : [...rows()];
2343
+ if (req.sort && req.sort.direction !== 'none') {
2344
+ const dir = req.sort.direction === 'desc' ? -1 : 1;
2345
+ out = [...out].sort((a, b) => dir * compare(a, b, req.sort));
2346
+ }
2347
+ const start = (req.page - 1) * req.pageSize;
2348
+ return Promise.resolve({ rows: out.slice(start, start + req.pageSize), total: out.length });
2349
+ };
2350
+ }
2303
2351
 
2304
2352
  /**
2305
2353
  * @mk-kit/ui/table — the data table, grid features and sort directives.
@@ -2309,5 +2357,5 @@ class MkTableDataSource {
2309
2357
  * Generated bundle index. Do not edit.
2310
2358
  */
2311
2359
 
2312
- export { MkSort, MkSortHeader, MkTable, MkTableCell, MkTableDataSource, MkTableRowDetail, mkCompactFilters, mkDownloadText, mkExportCsv, mkToCsv };
2360
+ export { MkSort, MkSortHeader, MkTable, MkTableCell, MkTableDataSource, MkTableRowDetail, mkClientFetcher, mkCompactFilters, mkDownloadText, mkExportCsv, mkToCsv };
2313
2361
  //# sourceMappingURL=mk-kit-ui-table.mjs.map