@directus/composables 11.2.3 → 11.2.5

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/index.d.ts CHANGED
@@ -399,6 +399,7 @@ type UsableItems = {
399
399
  items: Ref<Item[]>;
400
400
  totalPages: ComputedRef<number>;
401
401
  loading: Ref<boolean>;
402
+ loadingItemCount: Ref<boolean>;
402
403
  error: Ref<any>;
403
404
  changeManualSort: (data: ManualSortData) => Promise<void>;
404
405
  getItems: () => Promise<void>;
@@ -474,7 +475,7 @@ declare function isWritableProp(prop: string): prop is WritableProp;
474
475
  * const LayoutWrapper = createLayoutWrapper<MyLayoutOptions, MyLayoutQuery>(layoutConfig);
475
476
  * ```
476
477
  */
477
- declare function createLayoutWrapper<Options, Query>(layout: LayoutConfig): Component;
478
+ declare function createLayoutWrapper<Options, Query$1>(layout: LayoutConfig): Component;
478
479
  /**
479
480
  * Composable for managing layout components in Directus.
480
481
  *
@@ -516,7 +517,7 @@ declare function createLayoutWrapper<Options, Query>(layout: LayoutConfig): Comp
516
517
  * const { layoutWrapper } = useLayout<TableOptions, TableQuery>(layoutId);
517
518
  * ```
518
519
  */
519
- declare function useLayout<Options = any, Query = any>(layoutId: Ref<string | null>): {
520
+ declare function useLayout<Options = any, Query$1 = any>(layoutId: Ref<string | null>): {
520
521
  layoutWrapper: ComputedRef<Component>;
521
522
  };
522
523
  //#endregion
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { computed, defineComponent, inject, isRef, nextTick, onBeforeUnmount, onMounted, onUnmounted, provide, reactive, ref, shallowRef, toRef, toRefs, unref, watch } from "vue";
2
2
  import { API_INJECT, EXTENSIONS_INJECT, SDK_INJECT, STORES_INJECT } from "@directus/constants";
3
3
  import { nanoid } from "nanoid";
4
- import { isEqual, isNil, throttle } from "lodash-es";
4
+ import { debounce, isEqual, isNil } from "lodash-es";
5
5
  import { getEndpoint, moveInArray } from "@directus/utils";
6
6
  import axios from "axios";
7
7
 
@@ -372,36 +372,30 @@ function useCollection(collectionKey) {
372
372
  if (!collection.value) return [];
373
373
  return fieldsStore.getFieldsForCollectionSorted(collection.value);
374
374
  });
375
- const defaults = computed(() => {
376
- if (!fields.value) return {};
377
- const defaults$1 = {};
378
- for (const field of fields.value) if (field.schema !== null && "default_value" in field.schema) defaults$1[field.field] = field.schema.default_value;
379
- return defaults$1;
380
- });
381
- const primaryKeyField = computed(() => {
382
- return fields.value.find((field) => field.collection === collection.value && field.schema?.is_primary_key === true) || null;
383
- });
384
- const userCreatedField = computed(() => {
385
- return fields.value?.find((field) => (field.meta?.special || []).includes("user_created")) || null;
386
- });
387
- const sortField = computed(() => {
388
- return info.value?.meta?.sort_field || null;
389
- });
390
- const isSingleton = computed(() => {
391
- return info.value?.meta?.singleton === true;
392
- });
393
- const accountabilityScope = computed(() => {
394
- return info.value?.meta?.accountability || null;
395
- });
396
375
  return {
397
376
  info,
398
377
  fields,
399
- defaults,
400
- primaryKeyField,
401
- userCreatedField,
402
- sortField,
403
- isSingleton,
404
- accountabilityScope
378
+ defaults: computed(() => {
379
+ if (!fields.value) return {};
380
+ const defaults = {};
381
+ for (const field of fields.value) if (field.schema !== null && "default_value" in field.schema) defaults[field.field] = field.schema.default_value;
382
+ return defaults;
383
+ }),
384
+ primaryKeyField: computed(() => {
385
+ return fields.value.find((field) => field.collection === collection.value && field.schema?.is_primary_key === true) || null;
386
+ }),
387
+ userCreatedField: computed(() => {
388
+ return fields.value?.find((field) => (field.meta?.special || []).includes("user_created")) || null;
389
+ }),
390
+ sortField: computed(() => {
391
+ return info.value?.meta?.sort_field || null;
392
+ }),
393
+ isSingleton: computed(() => {
394
+ return info.value?.meta?.singleton === true;
395
+ }),
396
+ accountabilityScope: computed(() => {
397
+ return info.value?.meta?.accountability || null;
398
+ })
405
399
  };
406
400
  }
407
401
 
@@ -881,6 +875,7 @@ function useItems(collection, query) {
881
875
  });
882
876
  const items = ref([]);
883
877
  const loading = ref(false);
878
+ const loadingItemCount = ref(false);
884
879
  const error = ref(null);
885
880
  const itemCount = ref(null);
886
881
  const totalCount = ref(null);
@@ -895,7 +890,9 @@ function useItems(collection, query) {
895
890
  filter: null
896
891
  };
897
892
  let loadingTimeout = null;
898
- const fetchItems = throttle(getItems, 500);
893
+ const fetchItems = debounce((shouldUpdateCount) => {
894
+ Promise.all([getItems(), shouldUpdateCount ? getItemCount() : Promise.resolve()]);
895
+ }, 350);
899
896
  watch([
900
897
  collection,
901
898
  limit,
@@ -915,8 +912,7 @@ function useItems(collection, query) {
915
912
  if (!isEqual(newFilter, oldFilter) || !isEqual(newSort, oldSort) || newLimit !== oldLimit || newSearch !== oldSearch) {
916
913
  if (oldCollection) page.value = 1;
917
914
  }
918
- if (newCollection !== oldCollection || !isEqual(newFilter, oldFilter) || newSearch !== oldSearch) getItemCount();
919
- fetchItems();
915
+ fetchItems(newCollection !== oldCollection || !isEqual(newFilter, oldFilter) || newSearch !== oldSearch);
920
916
  }, {
921
917
  deep: true,
922
918
  immediate: true
@@ -934,6 +930,7 @@ function useItems(collection, query) {
934
930
  items,
935
931
  totalPages,
936
932
  loading,
933
+ loadingItemCount,
937
934
  error,
938
935
  changeManualSort,
939
936
  getItems,
@@ -1034,6 +1031,7 @@ function useItems(collection, query) {
1034
1031
  }
1035
1032
  async function getItemCount() {
1036
1033
  if (!endpoint.value) return;
1034
+ loadingItemCount.value = true;
1037
1035
  try {
1038
1036
  if (existingRequests.filter) existingRequests.filter.abort();
1039
1037
  existingRequests.filter = new AbortController();
@@ -1051,6 +1049,8 @@ function useItems(collection, query) {
1051
1049
  itemCount.value = count;
1052
1050
  } catch (err) {
1053
1051
  if (!axios.isCancel(err)) throw err;
1052
+ } finally {
1053
+ loadingItemCount.value = false;
1054
1054
  }
1055
1055
  }
1056
1056
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/composables",
3
- "version": "11.2.3",
3
+ "version": "11.2.5",
4
4
  "description": "Shared Vue composables for Directus use",
5
5
  "homepage": "https://directus.io",
6
6
  "repository": {
@@ -22,27 +22,27 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "axios": "1.11.0",
25
+ "axios": "1.12.2",
26
26
  "lodash-es": "4.17.21",
27
- "nanoid": "5.1.5",
28
- "@directus/utils": "13.0.10",
29
- "@directus/constants": "13.0.3"
27
+ "nanoid": "5.1.6",
28
+ "@directus/utils": "13.0.12",
29
+ "@directus/constants": "14.0.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@directus/tsconfig": "3.0.0",
33
33
  "@types/lodash-es": "4.17.12",
34
34
  "@vitest/coverage-v8": "3.2.4",
35
35
  "@vue/test-utils": "2.4.6",
36
- "tsdown": "0.14.2",
37
- "typescript": "5.8.3",
36
+ "tsdown": "0.15.11",
37
+ "typescript": "5.9.3",
38
38
  "vitest": "3.2.4",
39
- "vue": "3.5.18",
40
- "@directus/extensions": "3.0.11",
41
- "@directus/sdk": "20.1.0",
42
- "@directus/types": "13.2.3"
39
+ "vue": "3.5.22",
40
+ "@directus/extensions": "3.0.13",
41
+ "@directus/sdk": "20.1.1",
42
+ "@directus/types": "13.3.1"
43
43
  },
44
44
  "peerDependencies": {
45
- "vue": "3.5.18"
45
+ "vue": "3.5.22"
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsdown src/index.ts --dts",