@katlux/preset-modern 0.1.1-alpha.110 → 0.1.1-alpha.112

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@katlux/preset-modern",
3
3
  "configKey": "katluxTemplateModern",
4
- "version": "0.1.1-alpha.110",
4
+ "version": "0.1.1-alpha.112",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -82,7 +82,7 @@
82
82
  </template>
83
83
 
84
84
  <script setup>
85
- import { ref, computed, isRef } from "vue";
85
+ import { ref, computed, isRef, watch, shallowRef } from "vue";
86
86
  import { ADataProvider } from "@katlux/providers";
87
87
  import { useKatluxI18n } from "#toolkit/composables/useKatluxI18n";
88
88
  import { useDataProvider } from "#toolkit/composables/useDataProvider";
@@ -330,9 +330,86 @@ const {
330
330
  }
331
331
  }
332
332
  });
333
+ const deliveredRowsCache = shallowRef(/* @__PURE__ */ new Map());
334
+ const requestedPages = /* @__PURE__ */ new Set();
335
+ watch(pageRows, (rows) => {
336
+ if (Array.isArray(rows) && rows.length > 0) {
337
+ const idKey = rowIdKey.value;
338
+ const nextCache = new Map(deliveredRowsCache.value);
339
+ for (const r of rows) {
340
+ const id = r?.[idKey] ?? r?.id;
341
+ if (id !== void 0 && id !== null) {
342
+ nextCache.set(id, r);
343
+ }
344
+ }
345
+ deliveredRowsCache.value = nextCache;
346
+ }
347
+ }, { immediate: true, deep: true });
348
+ watch([dpFilter, () => props.dataProvider?.sortList], () => {
349
+ deliveredRowsCache.value = /* @__PURE__ */ new Map();
350
+ requestedPages.clear();
351
+ const curPage = props.dataProvider?.currentPage || 1;
352
+ requestedPages.add(curPage);
353
+ }, { deep: true });
354
+ let isFetchingPage = false;
355
+ const pageQueue = [];
356
+ const processPageQueue = async () => {
357
+ if (isFetchingPage || pageQueue.length === 0) return;
358
+ const nextPage = pageQueue.shift();
359
+ const dp = props.dataProvider;
360
+ if (dp && typeof dp.setCurrentPage === "function") {
361
+ isFetchingPage = true;
362
+ try {
363
+ dp.setCurrentPage(nextPage);
364
+ if (typeof dp.loadPageData === "function") {
365
+ const res = dp.loadPageData();
366
+ if (res instanceof Promise) await res;
367
+ }
368
+ } finally {
369
+ isFetchingPage = false;
370
+ if (pageQueue.length > 0) {
371
+ processPageQueue();
372
+ }
373
+ }
374
+ }
375
+ };
376
+ const queuePage = (page) => {
377
+ if (!requestedPages.has(page)) {
378
+ requestedPages.add(page);
379
+ pageQueue.push(page);
380
+ processPageQueue();
381
+ }
382
+ };
383
+ const ensureVisiblePagesLoaded = () => {
384
+ if (!props.virtualScroll) return;
385
+ const ps = dpPageSize?.value ?? props.pageSize ?? props.dataProvider?.pageSize ?? 10;
386
+ if (!ps || ps <= 0) return;
387
+ const start = startIndex.value;
388
+ const end = endIndex.value;
389
+ const startPage = Math.floor(start / ps) + 1;
390
+ const endPage = Math.floor(Math.max(0, end - 1) / ps) + 1;
391
+ for (let p = startPage; p <= endPage; p++) {
392
+ queuePage(p);
393
+ }
394
+ };
395
+ watch([startIndex, endIndex], () => {
396
+ ensureVisiblePagesLoaded();
397
+ }, { immediate: true });
333
398
  const displayRows = computed(() => {
334
399
  if (props.virtualScroll) {
335
- return visibleItems.value;
400
+ const items = visibleItems.value;
401
+ const cache = deliveredRowsCache.value;
402
+ if (cache.size > 0) {
403
+ const idKey = rowIdKey.value;
404
+ return items.map((item) => {
405
+ const id = item?.[idKey] ?? item?.id;
406
+ if (id !== void 0 && id !== null && cache.has(id)) {
407
+ return cache.get(id);
408
+ }
409
+ return item;
410
+ });
411
+ }
412
+ return items;
336
413
  }
337
414
  return pageRows.value;
338
415
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@katlux/preset-modern",
3
- "version": "0.1.1-alpha.110",
3
+ "version": "0.1.1-alpha.112",
4
4
  "description": "Modern default design preset and styling variables for Katlux components",
5
5
  "author": "Katlux",
6
6
  "license": "Apache-2.0",
@@ -25,7 +25,7 @@
25
25
  "**/*.sass"
26
26
  ],
27
27
  "dependencies": {
28
- "@katlux/toolkit": "^0.1.1-alpha.135",
28
+ "@katlux/toolkit": "^0.1.1-alpha.137",
29
29
  "@nuxt/kit": "^3.12.0"
30
30
  },
31
31
  "files": [