@directus/composables 10.1.14 → 10.1.15

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.
Files changed (2) hide show
  1. package/dist/index.js +42 -84
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -6,26 +6,22 @@ import { API_INJECT, EXTENSIONS_INJECT, SDK_INJECT, STORES_INJECT } from "@direc
6
6
  import { inject } from "vue";
7
7
  function useStores() {
8
8
  const stores = inject(STORES_INJECT);
9
- if (!stores)
10
- throw new Error("[useStores]: The stores could not be found.");
9
+ if (!stores) throw new Error("[useStores]: The stores could not be found.");
11
10
  return stores;
12
11
  }
13
12
  function useApi() {
14
13
  const api = inject(API_INJECT);
15
- if (!api)
16
- throw new Error("[useApi]: The api could not be found.");
14
+ if (!api) throw new Error("[useApi]: The api could not be found.");
17
15
  return api;
18
16
  }
19
17
  function useSdk() {
20
18
  const sdk = inject(SDK_INJECT);
21
- if (!sdk)
22
- throw new Error("[useSdk]: The sdk could not be found.");
19
+ if (!sdk) throw new Error("[useSdk]: The sdk could not be found.");
23
20
  return sdk;
24
21
  }
25
22
  function useExtensions() {
26
23
  const extensions = inject(EXTENSIONS_INJECT);
27
- if (!extensions)
28
- throw new Error("[useExtensions]: The extensions could not be found.");
24
+ if (!extensions) throw new Error("[useExtensions]: The extensions could not be found.");
29
25
  return extensions;
30
26
  }
31
27
 
@@ -39,13 +35,11 @@ function useCollection(collectionKey) {
39
35
  return collectionsStore.collections.find(({ collection: key }) => key === collection.value) || null;
40
36
  });
41
37
  const fields = computed(() => {
42
- if (!collection.value)
43
- return [];
38
+ if (!collection.value) return [];
44
39
  return fieldsStore.getFieldsForCollectionSorted(collection.value);
45
40
  });
46
41
  const defaults = computed(() => {
47
- if (!fields.value)
48
- return {};
42
+ if (!fields.value) return {};
49
43
  const defaults2 = {};
50
44
  for (const field of fields.value) {
51
45
  if (field.schema !== null && "default_value" in field.schema) {
@@ -67,10 +61,8 @@ function useCollection(collectionKey) {
67
61
  return info.value?.meta?.singleton === true;
68
62
  });
69
63
  const accountabilityScope = computed(() => {
70
- if (!info.value)
71
- return null;
72
- if (!info.value.meta)
73
- return null;
64
+ if (!info.value) return null;
65
+ if (!info.value.meta) return null;
74
66
  return info.value.meta.accountability;
75
67
  });
76
68
  return { info, fields, defaults, primaryKeyField, userCreatedField, sortField, isSingleton, accountabilityScope };
@@ -96,8 +88,7 @@ function useCustomSelection(currentValue, items, emit) {
96
88
  }
97
89
  });
98
90
  const usesOtherValue = computed2(() => {
99
- if (items.value === null)
100
- return false;
91
+ if (items.value === null) return false;
101
92
  const values = items.value.map((item) => item.value);
102
93
  return currentValue.value !== null && currentValue.value.length > 0 && values.includes(currentValue.value) === false;
103
94
  });
@@ -108,15 +99,11 @@ function useCustomSelectionMultiple(currentValues, items, emit) {
108
99
  watch(
109
100
  currentValues,
110
101
  (newValue) => {
111
- if (newValue === null)
112
- return;
113
- if (!Array.isArray(newValue))
114
- return;
115
- if (items.value === null)
116
- return;
102
+ if (newValue === null) return;
103
+ if (!Array.isArray(newValue)) return;
104
+ if (items.value === null) return;
117
105
  newValue.forEach((value) => {
118
- if (items.value === null)
119
- return;
106
+ if (items.value === null) return;
120
107
  const values = items.value.map((item) => item.value);
121
108
  const existsInValues = values.includes(value);
122
109
  if (!existsInValues) {
@@ -154,8 +141,7 @@ function useCustomSelectionMultiple(currentValues, items, emit) {
154
141
  }
155
142
  } else {
156
143
  otherValues.value = otherValues.value.map((otherValue) => {
157
- if (otherValue.key === key)
158
- otherValue.value = newValue;
144
+ if (otherValue.key === key) otherValue.value = newValue;
159
145
  return otherValue;
160
146
  });
161
147
  if (valueWithoutPrevious.length === currentValues.value?.length) {
@@ -174,8 +160,7 @@ function useElementSize(target) {
174
160
  const width = ref3(0);
175
161
  const height = ref3(0);
176
162
  const resizeObserver = new ResizeObserver(([entry]) => {
177
- if (entry === void 0)
178
- return;
163
+ if (entry === void 0) return;
179
164
  width.value = entry.contentRect.width;
180
165
  height.value = entry.contentRect.height;
181
166
  });
@@ -201,8 +186,7 @@ function useFilterFields(fields, filters) {
201
186
  }
202
187
  return fields.value.reduce((acc2, field) => {
203
188
  for (const name in filters) {
204
- if (filters[name](field) === false)
205
- continue;
189
+ if (filters[name](field) === false) continue;
206
190
  acc2[name].push(field);
207
191
  }
208
192
  return acc2;
@@ -234,25 +218,20 @@ function useGroupable(options) {
234
218
  selection
235
219
  } = parentFunctions;
236
220
  let startActive = false;
237
- if (options?.active?.value === true)
238
- startActive = true;
239
- if (options?.value && selection.value.includes(options.value))
240
- startActive = true;
221
+ if (options?.active?.value === true) startActive = true;
222
+ if (options?.value && selection.value.includes(options.value)) startActive = true;
241
223
  const active = ref4(startActive);
242
224
  const item = { active, value: options?.value };
243
225
  register(item);
244
226
  if (options?.active !== void 0 && options.watch === true) {
245
227
  watch2(options.active, () => {
246
- if (options.active === void 0)
247
- return;
228
+ if (options.active === void 0) return;
248
229
  if (options.active.value === true) {
249
- if (active.value === false)
250
- toggle(item);
230
+ if (active.value === false) toggle(item);
251
231
  active.value = true;
252
232
  }
253
233
  if (options.active.value === false) {
254
- if (active.value === true)
255
- toggle(item);
234
+ if (active.value === true) toggle(item);
256
235
  active.value = false;
257
236
  }
258
237
  });
@@ -264,12 +243,10 @@ function useGroupable(options) {
264
243
  toggle(item);
265
244
  },
266
245
  activate: () => {
267
- if (active.value === false)
268
- toggle(item);
246
+ if (active.value === false) toggle(item);
269
247
  },
270
248
  deactivate: () => {
271
- if (active.value === true)
272
- toggle(item);
249
+ if (active.value === true) toggle(item);
273
250
  }
274
251
  };
275
252
  }
@@ -296,11 +273,9 @@ function useGroupableParent(state = {}, options = {}, group = "item-group") {
296
273
  watch2(
297
274
  () => options?.mandatory?.value,
298
275
  (newValue, oldValue) => {
299
- if (isEqual(newValue, oldValue))
300
- return;
276
+ if (isEqual(newValue, oldValue)) return;
301
277
  if (!selection.value || selection.value.length === 0 && options?.mandatory?.value === true) {
302
- if (items.value[0])
303
- selection.value = [getValueForItem(items.value[0])];
278
+ if (items.value[0]) selection.value = [getValueForItem(items.value[0])];
304
279
  }
305
280
  }
306
281
  );
@@ -378,8 +353,7 @@ function useItems(collection, query) {
378
353
  const alias = queryAlias ?? ref5();
379
354
  const deep = queryDeep ?? ref5();
380
355
  const endpoint = computed5(() => {
381
- if (!collection.value)
382
- return null;
356
+ if (!collection.value) return null;
383
357
  return getEndpoint(collection.value);
384
358
  });
385
359
  const items = ref5([]);
@@ -388,10 +362,8 @@ function useItems(collection, query) {
388
362
  const itemCount = ref5(null);
389
363
  const totalCount = ref5(null);
390
364
  const totalPages = computed5(() => {
391
- if (itemCount.value === null)
392
- return 1;
393
- if (itemCount.value < (unref(limit) ?? 100))
394
- return 1;
365
+ if (itemCount.value === null) return 1;
366
+ if (itemCount.value < (unref(limit) ?? 100)) return 1;
395
367
  return Math.ceil(itemCount.value / (unref(limit) ?? 100));
396
368
  });
397
369
  const existingRequests = {
@@ -404,12 +376,10 @@ function useItems(collection, query) {
404
376
  watch3(
405
377
  [collection, limit, sort, search, filter, fields, page, alias, deep],
406
378
  async (after, before) => {
407
- if (isEqual2(after, before))
408
- return;
379
+ if (isEqual2(after, before)) return;
409
380
  const [newCollection, newLimit, newSort, newSearch, newFilter] = after;
410
381
  const [oldCollection, oldLimit, oldSort, oldSearch, oldFilter] = before;
411
- if (!newCollection || !query)
412
- return;
382
+ if (!newCollection || !query) return;
413
383
  if (newCollection !== oldCollection) {
414
384
  reset();
415
385
  }
@@ -438,11 +408,9 @@ function useItems(collection, query) {
438
408
  getTotalCount
439
409
  };
440
410
  async function getItems() {
441
- if (!endpoint.value)
442
- return;
411
+ if (!endpoint.value) return;
443
412
  let isCurrentRequestCanceled = false;
444
- if (existingRequests.items)
445
- existingRequests.items.abort();
413
+ if (existingRequests.items) existingRequests.items.abort();
446
414
  existingRequests.items = new AbortController();
447
415
  error.value = null;
448
416
  if (loadingTimeout) {
@@ -496,8 +464,7 @@ function useItems(collection, query) {
496
464
  clearTimeout(loadingTimeout);
497
465
  loadingTimeout = null;
498
466
  }
499
- if (!loadingTimeout)
500
- loading.value = false;
467
+ if (!loadingTimeout) loading.value = false;
501
468
  }
502
469
  }
503
470
  function reset() {
@@ -507,8 +474,7 @@ function useItems(collection, query) {
507
474
  }
508
475
  async function changeManualSort({ item, to }) {
509
476
  const pk = primaryKeyField.value?.field;
510
- if (!pk)
511
- return;
477
+ if (!pk) return;
512
478
  const fromIndex = items.value.findIndex((existing) => existing[pk] === item);
513
479
  const toIndex = items.value.findIndex((existing) => existing[pk] === to);
514
480
  items.value = moveInArray(items.value, fromIndex, toIndex);
@@ -516,11 +482,9 @@ function useItems(collection, query) {
516
482
  await api.post(endpoint2.value, { item, to });
517
483
  }
518
484
  async function getTotalCount() {
519
- if (!endpoint.value)
520
- return;
485
+ if (!endpoint.value) return;
521
486
  try {
522
- if (existingRequests.total)
523
- existingRequests.total.abort();
487
+ if (existingRequests.total) existingRequests.total.abort();
524
488
  existingRequests.total = new AbortController();
525
489
  const aggregate = primaryKeyField.value ? {
526
490
  countDistinct: primaryKeyField.value.field
@@ -543,11 +507,9 @@ function useItems(collection, query) {
543
507
  }
544
508
  }
545
509
  async function getItemCount() {
546
- if (!endpoint.value)
547
- return;
510
+ if (!endpoint.value) return;
548
511
  try {
549
- if (existingRequests.filter)
550
- existingRequests.filter.abort();
512
+ if (existingRequests.filter) existingRequests.filter.abort();
551
513
  existingRequests.filter = new AbortController();
552
514
  const aggregate = primaryKeyField.value ? {
553
515
  countDistinct: primaryKeyField.value.field
@@ -695,14 +657,10 @@ var sizeProps = {
695
657
  };
696
658
  function useSizeClass(props) {
697
659
  const sizeClass = computed7(() => {
698
- if (props.xSmall)
699
- return "x-small";
700
- if (props.small)
701
- return "small";
702
- if (props.large)
703
- return "large";
704
- if (props.xLarge)
705
- return "x-large";
660
+ if (props.xSmall) return "x-small";
661
+ if (props.small) return "small";
662
+ if (props.large) return "large";
663
+ if (props.xLarge) return "x-large";
706
664
  return null;
707
665
  });
708
666
  return sizeClass;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/composables",
3
- "version": "10.1.14",
3
+ "version": "10.1.15",
4
4
  "description": "Shared Vue composables for Directus use",
5
5
  "homepage": "https://directus.io",
6
6
  "repository": {
@@ -25,20 +25,20 @@
25
25
  "axios": "1.7.2",
26
26
  "lodash-es": "4.17.21",
27
27
  "nanoid": "5.0.7",
28
- "@directus/utils": "11.0.9",
29
- "@directus/constants": "11.0.4"
28
+ "@directus/constants": "11.0.4",
29
+ "@directus/utils": "11.0.10"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/lodash-es": "4.17.12",
33
33
  "@vitest/coverage-v8": "1.5.3",
34
34
  "@vue/test-utils": "2.4.6",
35
- "tsup": "8.0.2",
35
+ "tsup": "8.1.0",
36
36
  "typescript": "5.4.5",
37
37
  "vitest": "1.5.3",
38
38
  "vue": "3.4.27",
39
- "@directus/extensions": "1.0.7",
40
- "@directus/types": "11.1.2",
41
- "@directus/sdk": "16.1.0",
39
+ "@directus/extensions": "1.0.9",
40
+ "@directus/sdk": "16.1.1",
41
+ "@directus/types": "11.2.0",
42
42
  "@directus/tsconfig": "1.0.1"
43
43
  },
44
44
  "peerDependencies": {