@directus/composables 11.2.17 → 11.3.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/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Component, ComputedRef, Ref, WritableComputedRef } from "vue";
1
+ import { Component, ComponentPublicInstance, ComputedRef, Ref, WritableComputedRef } from "vue";
2
2
  import { AxiosInstance } from "axios";
3
3
  import { AppCollection, AppExtensionConfigs, Field, Item, LayoutConfig, Query, RefRecord } from "@directus/types";
4
4
  import { DirectusClient, RestClient } from "@directus/sdk";
@@ -763,6 +763,15 @@ declare function useSizeClass<T>(props: T & SizeProps): ComputedRef<string | nul
763
763
  */
764
764
  declare function useSync<T, K extends keyof T & string, E extends (event: `update:${K}`, ...args: any[]) => void>(props: T, key: K, emit: E): Ref<T[K]>;
765
765
  //#endregion
766
+ //#region src/translate-shortcut.d.ts
767
+ declare function translateShortcut(keys: string[]): string;
768
+ //#endregion
769
+ //#region src/use-shortcut.d.ts
770
+ type ShortcutHandler = (event: KeyboardEvent, cancelNext: () => void) => void | any | boolean;
771
+ declare const keyMap: Record<string, string>;
772
+ declare const systemKeys: string[];
773
+ declare function useShortcut(shortcuts: string | string[], handler: ShortcutHandler, reference?: Ref<HTMLElement | undefined> | Ref<ComponentPublicInstance | undefined>): void;
774
+ //#endregion
766
775
  //#region src/use-system.d.ts
767
776
  /**
768
777
  * Vue composable that provides access to the global Directus stores through dependency injection.
@@ -1065,4 +1074,4 @@ declare function useSdk<Schema extends object = any>(): DirectusClient<Schema> &
1065
1074
  */
1066
1075
  declare function useExtensions(): RefRecord<AppExtensionConfigs>;
1067
1076
  //#endregion
1068
- export { ComputedQuery, GroupableInstance, GroupableOptions, ManualSortData, OtherValue, UsableCollection, UsableCustomSelection, UsableGroupable, UsableItems, createLayoutWrapper, isWritableProp, sizeProps, useApi, useCollection, useCustomSelection, useCustomSelectionMultiple, useElementSize, useExtensions, useFilterFields, useGroupable, useGroupableParent, useItems, useLayout, useSdk, useSizeClass, useStores, useSync };
1077
+ export { ComputedQuery, GroupableInstance, GroupableOptions, ManualSortData, OtherValue, UsableCollection, UsableCustomSelection, UsableGroupable, UsableItems, createLayoutWrapper, isWritableProp, keyMap, sizeProps, systemKeys, translateShortcut, useApi, useCollection, useCustomSelection, useCustomSelectionMultiple, useElementSize, useExtensions, useFilterFields, useGroupable, useGroupableParent, useItems, useLayout, useSdk, useShortcut, useSizeClass, useStores, useSync };
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 { capitalize, isEqual, isNil, throttle } from "lodash-es";
5
5
  import { getEndpoint, moveInArray } from "@directus/utils";
6
6
  import axios from "axios";
7
7
 
@@ -1503,4 +1503,99 @@ function useSync(props, key, emit) {
1503
1503
  }
1504
1504
 
1505
1505
  //#endregion
1506
- export { createLayoutWrapper, isWritableProp, sizeProps, useApi, useCollection, useCustomSelection, useCustomSelectionMultiple, useElementSize, useExtensions, useFilterFields, useGroupable, useGroupableParent, useItems, useLayout, useSdk, useSizeClass, useStores, useSync };
1506
+ //#region src/translate-shortcut.ts
1507
+ function translateShortcut(keys) {
1508
+ if (navigator.platform.toLowerCase().startsWith("mac") || navigator.platform.startsWith("iP")) return keys.map((key) => {
1509
+ if (key === "meta") return "⌘";
1510
+ if (key === "option") return "⌥";
1511
+ if (key === "shift") return "⇧";
1512
+ if (key === "alt") return "⌥";
1513
+ if (key === "enter") return "⏎";
1514
+ return capitalize(key);
1515
+ }).join("");
1516
+ else return keys.map((key) => {
1517
+ if (key === "meta") return "Ctrl";
1518
+ if (key === "enter") return "↵";
1519
+ return capitalize(key);
1520
+ }).join("+");
1521
+ }
1522
+
1523
+ //#endregion
1524
+ //#region src/use-shortcut.ts
1525
+ const keyMap = {
1526
+ Control: "meta",
1527
+ Command: "meta"
1528
+ };
1529
+ const systemKeys = [
1530
+ "meta",
1531
+ "shift",
1532
+ "alt",
1533
+ "backspace",
1534
+ "delete",
1535
+ "tab",
1536
+ "capslock",
1537
+ "enter",
1538
+ "home",
1539
+ "end"
1540
+ ];
1541
+ const keysDown = /* @__PURE__ */ new Set([]);
1542
+ const handlers = {};
1543
+ document.body.addEventListener("keydown", (event) => {
1544
+ if (event.repeat || !event.key) return;
1545
+ keysDown.add(mapKeys(event));
1546
+ callHandlers(event);
1547
+ });
1548
+ document.body.addEventListener("keyup", (event) => {
1549
+ if (event.repeat || !event.key) return;
1550
+ keysDown.clear();
1551
+ });
1552
+ function useShortcut(shortcuts, handler, reference = ref(document.body)) {
1553
+ const callback = (event, cancelNext) => {
1554
+ if (!reference.value) return;
1555
+ const ref$1 = reference.value instanceof HTMLElement ? reference.value : reference.value.$el;
1556
+ if (document.activeElement === ref$1 || ref$1.contains(document.activeElement) || document.activeElement === document.body) {
1557
+ event.preventDefault();
1558
+ return handler(event, cancelNext);
1559
+ }
1560
+ return false;
1561
+ };
1562
+ onMounted(() => {
1563
+ [shortcuts].flat().forEach((shortcut) => {
1564
+ if (shortcut in handlers) handlers[shortcut]?.unshift(callback);
1565
+ else handlers[shortcut] = [callback];
1566
+ });
1567
+ });
1568
+ onUnmounted(() => {
1569
+ [shortcuts].flat().forEach((shortcut) => {
1570
+ const shortcutHandler = handlers[shortcut];
1571
+ if (shortcutHandler) {
1572
+ const filteredHandlers = shortcutHandler.filter((f) => f !== callback);
1573
+ handlers[shortcut] = filteredHandlers;
1574
+ if (filteredHandlers.length === 0) delete handlers[shortcut];
1575
+ }
1576
+ });
1577
+ });
1578
+ }
1579
+ function mapKeys(key) {
1580
+ let keyString = key.key.match(/^[a-zA-Z0-9]*?$/g) === null ? key.code.replace(/(Key|Digit)/g, "") : key.key;
1581
+ keyString = keyMap[keyString] ?? keyString;
1582
+ keyString = keyString.toLowerCase();
1583
+ return keyString;
1584
+ }
1585
+ function callHandlers(event) {
1586
+ Object.entries(handlers).forEach(([key, value]) => {
1587
+ const keys = key.split("+");
1588
+ for (key of keysDown) if (keys.includes(key) === false) return;
1589
+ for (key of keys) if (keysDown.has(key) === false) return;
1590
+ for (let i = 0; i < value.length; i++) {
1591
+ let cancel = false;
1592
+ value[i]?.(event, () => {
1593
+ cancel = true;
1594
+ });
1595
+ if (typeof cancel === "boolean" && cancel) break;
1596
+ }
1597
+ });
1598
+ }
1599
+
1600
+ //#endregion
1601
+ export { createLayoutWrapper, isWritableProp, keyMap, sizeProps, systemKeys, translateShortcut, useApi, useCollection, useCustomSelection, useCustomSelectionMultiple, useElementSize, useExtensions, useFilterFields, useGroupable, useGroupableParent, useItems, useLayout, useSdk, useShortcut, useSizeClass, useStores, useSync };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@directus/composables",
3
- "version": "11.2.17",
3
+ "version": "11.3.0",
4
4
  "description": "Shared Vue composables for Directus use",
5
5
  "homepage": "https://directus.io",
6
6
  "repository": {
@@ -23,10 +23,10 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "axios": "1.13.5",
26
- "lodash-es": "4.17.23",
26
+ "lodash-es": "4.18.1",
27
27
  "nanoid": "5.1.6",
28
- "@directus/constants": "14.3.0",
29
- "@directus/utils": "13.4.0"
28
+ "@directus/utils": "13.4.0",
29
+ "@directus/constants": "14.3.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@directus/tsconfig": "4.0.0",
@@ -37,9 +37,9 @@
37
37
  "typescript": "5.9.3",
38
38
  "vitest": "3.2.4",
39
39
  "vue": "3.5.24",
40
- "@directus/sdk": "21.2.2",
41
40
  "@directus/extensions": "3.0.23",
42
- "@directus/types": "15.0.1"
41
+ "@directus/types": "15.0.1",
42
+ "@directus/sdk": "21.2.2"
43
43
  },
44
44
  "peerDependencies": {
45
45
  "vue": "3.5.24"