@witchcraft/ui 0.2.5 → 0.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.
Files changed (37) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +1 -1
  3. package/dist/runtime/components/LibRoot/LibRoot.d.vue.ts +1 -1
  4. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +1 -1
  5. package/dist/runtime/composables/index.d.ts +0 -1
  6. package/dist/runtime/composables/index.js +0 -1
  7. package/dist/runtime/composables/useDarkMode.d.ts +1 -5
  8. package/dist/runtime/composables/useDarkMode.js +5 -12
  9. package/dist/runtime/composables/useInjectedDarkMode.d.ts +1 -1
  10. package/dist/runtime/composables/useInjectedDarkMode.js +1 -1
  11. package/dist/runtime/composables/useInjectedI18n.js +1 -1
  12. package/dist/runtime/composables/useInjectedLocale.d.ts +1 -1
  13. package/dist/runtime/composables/useInjectedLocale.js +1 -1
  14. package/dist/runtime/composables/useSetupI18n.d.ts +1 -3
  15. package/dist/runtime/composables/useSetupI18n.js +3 -6
  16. package/dist/runtime/composables/useSetupLocale.d.ts +1 -3
  17. package/dist/runtime/composables/useSetupLocale.js +1 -2
  18. package/dist/runtime/composables/useShowDevOnlyKey.d.ts +0 -1
  19. package/dist/runtime/composables/useShowDevOnlyKey.js +2 -3
  20. package/dist/runtime/helpers/defaultTranslationFunction.js +1 -1
  21. package/dist/runtime/injectionKeys.d.ts +14 -0
  22. package/dist/runtime/injectionKeys.js +9 -0
  23. package/dist/runtime/main.lib.d.ts +1 -0
  24. package/dist/runtime/main.lib.js +1 -0
  25. package/package.json +1 -1
  26. package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -1
  27. package/src/runtime/composables/index.ts +0 -1
  28. package/src/runtime/composables/useDarkMode.ts +7 -18
  29. package/src/runtime/composables/useInjectedDarkMode.ts +3 -1
  30. package/src/runtime/composables/useInjectedI18n.ts +2 -1
  31. package/src/runtime/composables/useInjectedLocale.ts +3 -1
  32. package/src/runtime/composables/useSetupI18n.ts +3 -7
  33. package/src/runtime/composables/useSetupLocale.ts +3 -3
  34. package/src/runtime/composables/useShowDevOnlyKey.ts +3 -3
  35. package/src/runtime/helpers/defaultTranslationFunction.ts +4 -3
  36. package/src/runtime/injectionKeys.ts +28 -0
  37. package/src/runtime/main.lib.ts +1 -0
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "witchcraftUi",
3
3
  "configKey": "witchcraftUi",
4
- "version": "0.2.5",
4
+ "version": "0.3.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -24,7 +24,7 @@
24
24
 
25
25
  <script setup>
26
26
  import { computed, inject, ref, useAttrs } from "vue";
27
- import { showDevOnlyInjectionKey } from "../../composables/useShowDevOnlyKey.js";
27
+ import { showDevOnlyInjectionKey } from "../../injectionKeys.js";
28
28
  import { twMerge } from "../../utils/twMerge.js";
29
29
  const $attrs = useAttrs();
30
30
  const props = defineProps({
@@ -23,8 +23,8 @@ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {
23
23
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
24
24
  theme: Theme;
25
25
  id: string;
26
- useBuiltinTranslations: boolean;
27
26
  isClientSide: boolean;
27
+ useBuiltinTranslations: boolean;
28
28
  outline: boolean;
29
29
  forceOutline: boolean;
30
30
  testWrapperMode: boolean;
@@ -23,8 +23,8 @@ declare const __VLS_component: import("vue").DefineComponent<__VLS_Props, {
23
23
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
24
24
  theme: Theme;
25
25
  id: string;
26
- useBuiltinTranslations: boolean;
27
26
  isClientSide: boolean;
27
+ useBuiltinTranslations: boolean;
28
28
  outline: boolean;
29
29
  forceOutline: boolean;
30
30
  testWrapperMode: boolean;
@@ -1,4 +1,3 @@
1
- export { languageLocaleInjectionKey } from "./useSetupLocale.js.js";
2
1
  export { useAccesibilityOutline } from "./useAccesibilityOutline.js.js";
3
2
  export { useAriaLabel } from "./useAriaLabel.js.js";
4
3
  export { useDarkMode } from "./useDarkMode.js.js";
@@ -1,4 +1,3 @@
1
- export { languageLocaleInjectionKey } from "./useSetupLocale.js";
2
1
  export { useAccesibilityOutline } from "./useAccesibilityOutline.js";
3
2
  export { useAriaLabel } from "./useAriaLabel.js";
4
3
  export { useDarkMode } from "./useDarkMode.js";
@@ -1,4 +1,4 @@
1
- import { type InjectionKey, type Ref } from "vue";
1
+ import { type Ref } from "vue";
2
2
  /**
3
3
  * @deprecated Use `useSetupDarkMode` instead.
4
4
  *
@@ -12,10 +12,6 @@ import { type InjectionKey, type Ref } from "vue";
12
12
  */
13
13
  export declare const useDarkMode: ({ useLocalStorage, darkModeOrder, isClientSide }?: DarkModeOptions) => DarkModeState & DarkModeCommands;
14
14
  export declare const defaultDarkModeOrder: readonly ["system", "dark", "light"];
15
- export declare const isDarkModeInjectionKey: InjectionKey<Ref<boolean, boolean>>;
16
- export declare const manualDarkModeInjectionKey: InjectionKey<Ref<boolean | undefined, boolean | undefined>>;
17
- export declare const darkModeCommandsInjectionKey: InjectionKey<DarkModeCommands>;
18
- export declare const darkModeStateInjectionKey: InjectionKey<DarkModeState>;
19
15
  export type DarkModeOptions = {
20
16
  useLocalStorage?: boolean | string;
21
17
  darkModeOrder?: readonly ("system" | "dark" | "light")[];
@@ -1,10 +1,7 @@
1
1
  import { computed, onMounted, provide, ref, watch } from "vue";
2
+ import { darkModeCommandsInjectionKey, darkModeStateInjectionKey, isDarkModeInjectionKey, manualDarkModeInjectionKey } from "../injectionKeys.js";
2
3
  const defaultLocalStorageKey = "prefersColorSchemeDark";
3
4
  const defaultOrder = ["system", "dark", "light"];
4
- const injectionKey = Symbol("isDarkMode");
5
- const manualInjectionKey = Symbol("manualDarkMode");
6
- const commandsInjectionKey = Symbol("darkModeCommands");
7
- const stateInjectionKey = Symbol("darkModeState");
8
5
  export const useDarkMode = ({
9
6
  useLocalStorage = true,
10
7
  darkModeOrder = defaultOrder,
@@ -51,15 +48,15 @@ export const useDarkMode = ({
51
48
  }
52
49
  }
53
50
  });
54
- provide(injectionKey, darkMode);
55
- provide(manualInjectionKey, manualDarkMode);
56
- provide(stateInjectionKey, {
51
+ provide(isDarkModeInjectionKey, darkMode);
52
+ provide(manualDarkModeInjectionKey, manualDarkMode);
53
+ provide(darkModeStateInjectionKey, {
57
54
  darkMode,
58
55
  darkModeState,
59
56
  manualDarkMode,
60
57
  systemDarkMode
61
58
  });
62
- provide(commandsInjectionKey, {
59
+ provide(darkModeCommandsInjectionKey, {
63
60
  setDarkMode,
64
61
  cycleDarkMode
65
62
  });
@@ -73,7 +70,3 @@ export const useDarkMode = ({
73
70
  };
74
71
  };
75
72
  export const defaultDarkModeOrder = defaultOrder;
76
- export const isDarkModeInjectionKey = injectionKey;
77
- export const manualDarkModeInjectionKey = manualInjectionKey;
78
- export const darkModeCommandsInjectionKey = commandsInjectionKey;
79
- export const darkModeStateInjectionKey = stateInjectionKey;
@@ -1,2 +1,2 @@
1
- import { type DarkModeCommands, type DarkModeState } from "./useDarkMode.js.js";
1
+ import type { DarkModeCommands, DarkModeState } from "./useDarkMode.js.js";
2
2
  export declare function useInjectedDarkMode(): DarkModeState & DarkModeCommands;
@@ -1,5 +1,5 @@
1
1
  import { inject } from "vue";
2
- import { darkModeCommandsInjectionKey, darkModeStateInjectionKey } from "./useDarkMode.js";
2
+ import { darkModeCommandsInjectionKey, darkModeStateInjectionKey } from "../injectionKeys.js";
3
3
  export function useInjectedDarkMode() {
4
4
  const darkModeState = inject(darkModeStateInjectionKey);
5
5
  const darkModeCommands = inject(darkModeCommandsInjectionKey);
@@ -1,5 +1,5 @@
1
1
  import { inject } from "vue";
2
- import { i18nInjectionKey } from "./useSetupI18n.js";
2
+ import { i18nInjectionKey } from "../injectionKeys.js";
3
3
  export function useInjectedI18n() {
4
4
  const val = inject(i18nInjectionKey, void 0);
5
5
  if (val === void 0) throw new Error("witchcraft/ui: i18n is not injected. See useSetupI18n.");
@@ -1,2 +1,2 @@
1
- import { type useSetupLocale } from "./useSetupLocale.js.js";
1
+ import type { useSetupLocale } from "./useSetupLocale.js.js";
2
2
  export declare function useInjectedLocale(): ReturnType<typeof useSetupLocale>;
@@ -1,5 +1,5 @@
1
1
  import { inject } from "vue";
2
- import { languageLocaleInjectionKey, timeLocaleInjectionKey } from "./useSetupLocale.js";
2
+ import { languageLocaleInjectionKey, timeLocaleInjectionKey } from "../injectionKeys.js";
3
3
  export function useInjectedLocale() {
4
4
  const timeLocale = inject(timeLocaleInjectionKey);
5
5
  const languageLocale = inject(languageLocaleInjectionKey);
@@ -1,4 +1,4 @@
1
- import { type InjectionKey, type Ref } from "vue";
1
+ import { type Ref } from "vue";
2
2
  export type TranslationFunction = (key: string, replacements?: Record<string, any>) => string;
3
3
  /**
4
4
  * A composable for providing a translation function + messages for the library. Note the Root component already takes care of setting this up with defaults, disable it via it's `useBuiltinTranslations` option.
@@ -18,5 +18,3 @@ export declare function useSetupI18n({ locale, useBuiltinTranslations, useDummyM
18
18
  /** A custom translation function. The default requires the `useBuiltinTranslations` option to be true. */
19
19
  translationFunction?: TranslationFunction;
20
20
  }): Promise<void>;
21
- export declare const i18nInjectionKey: InjectionKey<TranslationFunction>;
22
- export declare const translationMessagesInjectionKey: InjectionKey<Ref<Record<string, any>, Record<string, any>>>;
@@ -4,8 +4,7 @@ import {
4
4
  watch
5
5
  } from "vue";
6
6
  import { defaultTranslationFunction } from "../helpers/defaultTranslationFunction.js";
7
- const _i18nInjectionKey = Symbol("witchcraftUiI18n");
8
- const _translationMessagesInjectionKey = Symbol("witchcraftUiI18nMessages");
7
+ import { i18nInjectionKey, translationMessagesInjectionKey } from "../injectionKeys.js";
9
8
  const messagesGlob = import.meta.glob("../assets/locales/*.json");
10
9
  const loaded = {};
11
10
  const dummyLibraryMessages = new Proxy({}, {
@@ -26,10 +25,10 @@ export async function useSetupI18n({
26
25
  useDummyMessageSetWhileLoading = true,
27
26
  translationFunction = defaultTranslationFunction
28
27
  }) {
29
- provide(_i18nInjectionKey, translationFunction);
28
+ provide(i18nInjectionKey, translationFunction);
30
29
  if (useBuiltinTranslations) {
31
30
  const messages = ref(useDummyMessageSetWhileLoading ? dummyMessageSet : {});
32
- provide(_translationMessagesInjectionKey, messages);
31
+ provide(translationMessagesInjectionKey, messages);
33
32
  async function loadMessageSet(l) {
34
33
  const isLoaded = loaded[l];
35
34
  if (isLoaded) {
@@ -50,5 +49,3 @@ export async function useSetupI18n({
50
49
  });
51
50
  }
52
51
  }
53
- export const i18nInjectionKey = _i18nInjectionKey;
54
- export const translationMessagesInjectionKey = _translationMessagesInjectionKey;
@@ -1,6 +1,4 @@
1
- import { type InjectionKey, type Ref } from "vue";
2
- export declare const languageLocaleInjectionKey: InjectionKey<Ref<string>>;
3
- export declare const timeLocaleInjectionKey: InjectionKey<Ref<string>>;
1
+ import { type Ref } from "vue";
4
2
  export declare function useSetupLocale(): {
5
3
  languageLocale: Ref<string>;
6
4
  timeLocale: Ref<string>;
@@ -1,6 +1,5 @@
1
1
  import { provide, ref } from "vue";
2
- export const languageLocaleInjectionKey = Symbol("witchcraftUiLanguageLocale");
3
- export const timeLocaleInjectionKey = Symbol("witchcraftUiTimeLocale");
2
+ import { languageLocaleInjectionKey, timeLocaleInjectionKey } from "../injectionKeys.js";
4
3
  export function useSetupLocale() {
5
4
  const languageLocale = ref("en");
6
5
  const timeLocale = ref("en-GB");
@@ -4,4 +4,3 @@
4
4
  * Communicates with the dev only component to show/hide it depending on a keypress (single key, no modifiers, `F1` by default). *
5
5
  */
6
6
  export declare function useShowDevOnlyKey(key?: string): void;
7
- export declare const showDevOnlyInjectionKey: symbol;
@@ -1,9 +1,9 @@
1
1
  import { onBeforeUnmount, onMounted, provide, ref } from "vue";
2
- const injectionKey = Symbol("showDevOnly");
2
+ import { showDevOnlyInjectionKey } from "../injectionKeys.js";
3
3
  export function useShowDevOnlyKey(key = "F1") {
4
4
  if (!import.meta.dev) return;
5
5
  const showDevOnly = ref(false);
6
- provide(injectionKey, showDevOnly);
6
+ provide(showDevOnlyInjectionKey, showDevOnly);
7
7
  const listener = (e) => {
8
8
  if (e.key === key && !e.ctrlKey && !e.metaKey && !e.altKey) {
9
9
  showDevOnly.value = !showDevOnly.value;
@@ -17,4 +17,3 @@ export function useShowDevOnlyKey(key = "F1") {
17
17
  document.removeEventListener("keydown", listener);
18
18
  });
19
19
  }
20
- export const showDevOnlyInjectionKey = injectionKey;
@@ -1,5 +1,5 @@
1
1
  import { inject } from "vue";
2
- import { translationMessagesInjectionKey } from "../composables/useSetupI18n.js";
2
+ import { translationMessagesInjectionKey } from "../injectionKeys.js";
3
3
  export function defaultTranslationFunction(key, replacements) {
4
4
  const messages = inject(translationMessagesInjectionKey);
5
5
  if (messages === void 0) throw new Error("witchcraft/ui: The default translation function requires the useSetupI18n `useBuiltinTranslations` options to be true. Did you set it?");
@@ -0,0 +1,14 @@
1
+ import type { InjectionKey, Ref } from "vue";
2
+ import type { DarkModeCommands, DarkModeState } from "./composables/useDarkMode.js.js";
3
+ import type { TranslationFunction } from "./composables/useSetupI18n.js.js";
4
+ /** @deprecated */
5
+ export declare const isDarkModeInjectionKey: InjectionKey<Ref<boolean>>;
6
+ /** @deprecated */
7
+ export declare const manualDarkModeInjectionKey: InjectionKey<Ref<boolean | undefined>>;
8
+ export declare const darkModeCommandsInjectionKey: InjectionKey<DarkModeCommands>;
9
+ export declare const darkModeStateInjectionKey: InjectionKey<DarkModeState>;
10
+ export declare const languageLocaleInjectionKey: InjectionKey<Ref<string>>;
11
+ export declare const timeLocaleInjectionKey: InjectionKey<Ref<string>>;
12
+ export declare const i18nInjectionKey: InjectionKey<TranslationFunction>;
13
+ export declare const translationMessagesInjectionKey: InjectionKey<Ref<Record<string, any>>>;
14
+ export declare const showDevOnlyInjectionKey: InjectionKey<Ref<boolean>>;
@@ -0,0 +1,9 @@
1
+ export const isDarkModeInjectionKey = Symbol("isDarkMode");
2
+ export const manualDarkModeInjectionKey = Symbol("manualDarkMode");
3
+ export const darkModeCommandsInjectionKey = Symbol("darkModeCommands");
4
+ export const darkModeStateInjectionKey = Symbol("darkModeState");
5
+ export const languageLocaleInjectionKey = Symbol("witchcraftUiLanguageLocale");
6
+ export const timeLocaleInjectionKey = Symbol("witchcraftUiTimeLocale");
7
+ export const i18nInjectionKey = Symbol("witchcraftUiI18n");
8
+ export const translationMessagesInjectionKey = Symbol("witchcraftUiI18nMessages");
9
+ export const showDevOnlyInjectionKey = Symbol("showDevOnly");
@@ -6,6 +6,7 @@ export * as directives from "./directives/index.js.js";
6
6
  export { registerDirectives } from "./vue/registerDirectives.js.js";
7
7
  export { registerComponents } from "./vue/registerComponents.js.js";
8
8
  export { VueComponentsPlugin } from "./vue/VueComponentsPlugin.js.js";
9
+ export * from "./injectionKeys.js.js";
9
10
  import type * as components from "./components/index.js.js";
10
11
  type Components = typeof components;
11
12
  /**
@@ -6,3 +6,4 @@ export * as directives from "./directives/index.js";
6
6
  export { registerDirectives } from "./vue/registerDirectives.js";
7
7
  export { registerComponents } from "./vue/registerComponents.js";
8
8
  export { VueComponentsPlugin } from "./vue/VueComponentsPlugin.js";
9
+ export * from "./injectionKeys.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@witchcraft/ui",
3
- "version": "0.2.5",
3
+ "version": "0.3.0",
4
4
  "description": "Vue component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/runtime/main.lib.js",
@@ -24,7 +24,7 @@
24
24
  <script lang="ts" setup>
25
25
  import { computed, inject, ref, useAttrs } from "vue"
26
26
 
27
- import { showDevOnlyInjectionKey } from "../../composables/useShowDevOnlyKey.js"
27
+ import { showDevOnlyInjectionKey } from "../../injectionKeys.js"
28
28
  import { twMerge } from "../../utils/twMerge.js"
29
29
 
30
30
  const $attrs = useAttrs()
@@ -1,6 +1,5 @@
1
1
  /* Autogenerated Index */
2
2
 
3
- export { languageLocaleInjectionKey } from "./useSetupLocale.js"
4
3
  export { useAccesibilityOutline } from "./useAccesibilityOutline.js"
5
4
  export { useAriaLabel } from "./useAriaLabel.js"
6
5
  export { useDarkMode } from "./useDarkMode.js"
@@ -1,13 +1,9 @@
1
- import { computed, type InjectionKey, onMounted, provide, type Ref, ref, watch } from "vue"
1
+ import { computed, onMounted, provide, type Ref, ref, watch } from "vue"
2
+
3
+ import { darkModeCommandsInjectionKey, darkModeStateInjectionKey, isDarkModeInjectionKey, manualDarkModeInjectionKey } from "../injectionKeys.js"
2
4
 
3
5
  const defaultLocalStorageKey = "prefersColorSchemeDark"
4
6
  const defaultOrder = ["system", "dark", "light"] as const
5
- /** @deprecated */
6
- const injectionKey = Symbol("isDarkMode") as InjectionKey<Ref<boolean>>
7
- /** @deprecated */
8
- const manualInjectionKey = Symbol("manualDarkMode") as InjectionKey<Ref<boolean | undefined>>
9
- const commandsInjectionKey = Symbol("darkModeCommands") as InjectionKey<DarkModeCommands>
10
- const stateInjectionKey = Symbol("darkModeState") as InjectionKey<DarkModeState>
11
7
 
12
8
  /**
13
9
  * @deprecated Use `useSetupDarkMode` instead.
@@ -82,16 +78,16 @@ export const useDarkMode = ({
82
78
  }
83
79
  }
84
80
  })
85
- provide(injectionKey, darkMode)
86
- provide(manualInjectionKey, manualDarkMode)
81
+ provide(isDarkModeInjectionKey, darkMode)
82
+ provide(manualDarkModeInjectionKey, manualDarkMode)
87
83
 
88
- provide(stateInjectionKey, {
84
+ provide(darkModeStateInjectionKey, {
89
85
  darkMode,
90
86
  darkModeState,
91
87
  manualDarkMode,
92
88
  systemDarkMode
93
89
  })
94
- provide(commandsInjectionKey, {
90
+ provide(darkModeCommandsInjectionKey, {
95
91
  setDarkMode,
96
92
  cycleDarkMode
97
93
  })
@@ -107,13 +103,6 @@ export const useDarkMode = ({
107
103
  }
108
104
  export const defaultDarkModeOrder = defaultOrder
109
105
 
110
- export const isDarkModeInjectionKey = injectionKey
111
-
112
- export const manualDarkModeInjectionKey = manualInjectionKey
113
-
114
- export const darkModeCommandsInjectionKey = commandsInjectionKey
115
-
116
- export const darkModeStateInjectionKey = stateInjectionKey
117
106
 
118
107
  export type DarkModeOptions = {
119
108
  /* Whether to save the manual dark mode to local storage. Uses the key "prefersColorSchemeDark" by default. You can pass a key instead of true to use that as the key instead. */
@@ -1,6 +1,8 @@
1
1
  import { inject } from "vue"
2
2
 
3
- import { type DarkModeCommands, darkModeCommandsInjectionKey, type DarkModeState, darkModeStateInjectionKey } from "./useDarkMode.js"
3
+ import type { DarkModeCommands, DarkModeState } from "./useDarkMode.js"
4
+
5
+ import { darkModeCommandsInjectionKey, darkModeStateInjectionKey } from "../injectionKeys.js"
4
6
 
5
7
  export function useInjectedDarkMode(): DarkModeState & DarkModeCommands {
6
8
  const darkModeState = inject(darkModeStateInjectionKey)
@@ -1,7 +1,8 @@
1
1
  import { inject } from "vue"
2
2
 
3
3
  import type { TranslationFunction } from "./useSetupI18n.js"
4
- import { i18nInjectionKey } from "./useSetupI18n.js"
4
+
5
+ import { i18nInjectionKey } from "../injectionKeys.js"
5
6
 
6
7
  export function useInjectedI18n(): TranslationFunction {
7
8
  const val = inject(i18nInjectionKey, undefined)
@@ -1,6 +1,8 @@
1
1
  import { inject } from "vue"
2
2
 
3
- import { languageLocaleInjectionKey, timeLocaleInjectionKey, type useSetupLocale } from "./useSetupLocale.js"
3
+ import type { useSetupLocale } from "./useSetupLocale.js"
4
+
5
+ import { languageLocaleInjectionKey, timeLocaleInjectionKey } from "../injectionKeys.js"
4
6
 
5
7
  export function useInjectedLocale(): ReturnType<typeof useSetupLocale> {
6
8
  const timeLocale = inject(timeLocaleInjectionKey)
@@ -1,5 +1,4 @@
1
1
  import {
2
- type InjectionKey,
3
2
  provide,
4
3
  type Ref,
5
4
  ref,
@@ -7,11 +6,10 @@ import {
7
6
  } from "vue"
8
7
 
9
8
  import { defaultTranslationFunction } from "../helpers/defaultTranslationFunction.js"
9
+ import { i18nInjectionKey, translationMessagesInjectionKey } from "../injectionKeys.js"
10
10
 
11
11
  export type TranslationFunction = (key: string, replacements?: Record<string, any>) => string
12
12
 
13
- const _i18nInjectionKey = Symbol("witchcraftUiI18n") as InjectionKey<TranslationFunction>
14
- const _translationMessagesInjectionKey = Symbol("witchcraftUiI18nMessages") as InjectionKey<Ref<Record<string, any>>>
15
13
 
16
14
  const messagesGlob = import.meta.glob("../assets/locales/*.json")
17
15
  const loaded: Record<string, any> = {}
@@ -51,10 +49,10 @@ export async function useSetupI18n({
51
49
  /** A custom translation function. The default requires the `useBuiltinTranslations` option to be true. */
52
50
  translationFunction?: TranslationFunction
53
51
  }): Promise<void> {
54
- provide(_i18nInjectionKey, translationFunction)
52
+ provide(i18nInjectionKey, translationFunction)
55
53
  if (useBuiltinTranslations) {
56
54
  const messages = ref(useDummyMessageSetWhileLoading ? dummyMessageSet : {})
57
- provide(_translationMessagesInjectionKey, messages)
55
+ provide(translationMessagesInjectionKey, messages)
58
56
  async function loadMessageSet(l: string): Promise<void> {
59
57
  const isLoaded = loaded[l]
60
58
  if (isLoaded) {
@@ -76,5 +74,3 @@ export async function useSetupI18n({
76
74
  }
77
75
  }
78
76
 
79
- export const i18nInjectionKey = _i18nInjectionKey
80
- export const translationMessagesInjectionKey = _translationMessagesInjectionKey
@@ -1,7 +1,7 @@
1
- import { type InjectionKey, provide, type Ref, ref } from "vue"
1
+ import { provide, type Ref, ref } from "vue"
2
+
3
+ import { languageLocaleInjectionKey, timeLocaleInjectionKey } from "../injectionKeys.js"
2
4
 
3
- export const languageLocaleInjectionKey = Symbol("witchcraftUiLanguageLocale") as InjectionKey<Ref<string>>
4
- export const timeLocaleInjectionKey = Symbol("witchcraftUiTimeLocale") as InjectionKey<Ref<string>>
5
5
 
6
6
  export function useSetupLocale(): {
7
7
  languageLocale: Ref<string>
@@ -1,6 +1,7 @@
1
1
  import { onBeforeUnmount, onMounted, provide, ref } from "vue"
2
2
 
3
- const injectionKey = Symbol("showDevOnly")
3
+ import { showDevOnlyInjectionKey } from "../injectionKeys.js"
4
+
4
5
  /**
5
6
  * For nuxt only.
6
7
  *
@@ -9,7 +10,7 @@ const injectionKey = Symbol("showDevOnly")
9
10
  export function useShowDevOnlyKey(key: string = "F1"): void {
10
11
  if (!(import.meta as any).dev) return
11
12
  const showDevOnly = ref(false)
12
- provide(injectionKey, showDevOnly)
13
+ provide(showDevOnlyInjectionKey, showDevOnly)
13
14
 
14
15
  const listener = (e: KeyboardEvent): void => {
15
16
  if (e.key === key && !e.ctrlKey && !e.metaKey && !e.altKey) {
@@ -25,4 +26,3 @@ export function useShowDevOnlyKey(key: string = "F1"): void {
25
26
  })
26
27
  }
27
28
 
28
- export const showDevOnlyInjectionKey = injectionKey
@@ -1,6 +1,7 @@
1
- import { inject, type Ref } from "vue"
1
+ import { inject } from "vue"
2
+
3
+ import { translationMessagesInjectionKey } from "../injectionKeys.js"
2
4
 
3
- import { translationMessagesInjectionKey } from "../composables/useSetupI18n.js"
4
5
 
5
6
  /**
6
7
  * A default translation function to use with `useSetupI18n`. Requires at least one set of translation message sets (or a dummy) be loaded (the useSetupI18n function takes care of setting up a temporary dummy if you set `useBuiltinTranslations: true`).
@@ -19,7 +20,7 @@ import { translationMessagesInjectionKey } from "../composables/useSetupI18n.js"
19
20
  */
20
21
 
21
22
  export function defaultTranslationFunction(key: string, replacements?: Record<string, any>): string {
22
- const messages = inject(translationMessagesInjectionKey) as Ref<Record<string, any>> | undefined
23
+ const messages = inject(translationMessagesInjectionKey)
23
24
  if (messages === undefined) throw new Error("witchcraft/ui: The default translation function requires the useSetupI18n `useBuiltinTranslations` options to be true. Did you set it?")
24
25
  let value = (messages.value)["witchcraft-ui"][key]
25
26
  if (value === undefined) throw new Error(`No translation for key ${key}.`)
@@ -0,0 +1,28 @@
1
+ import type { InjectionKey, Ref } from "vue"
2
+
3
+ import type { DarkModeCommands, DarkModeState } from "./composables/useDarkMode.js"
4
+ import type { TranslationFunction } from "./composables/useSetupI18n.js"
5
+
6
+ /** @deprecated */
7
+ export const isDarkModeInjectionKey = Symbol("isDarkMode") as InjectionKey<Ref<boolean>>
8
+
9
+ /** @deprecated */
10
+ export const manualDarkModeInjectionKey = Symbol("manualDarkMode") as InjectionKey<Ref<boolean | undefined>>
11
+
12
+ export const darkModeCommandsInjectionKey = Symbol("darkModeCommands") as InjectionKey<DarkModeCommands>
13
+
14
+ export const darkModeStateInjectionKey = Symbol("darkModeState") as InjectionKey<DarkModeState>
15
+
16
+
17
+ export const languageLocaleInjectionKey = Symbol("witchcraftUiLanguageLocale") as InjectionKey<Ref<string>>
18
+
19
+ export const timeLocaleInjectionKey = Symbol("witchcraftUiTimeLocale") as InjectionKey<Ref<string>>
20
+
21
+
22
+ export const i18nInjectionKey = Symbol("witchcraftUiI18n") as InjectionKey<TranslationFunction>
23
+
24
+ export const translationMessagesInjectionKey = Symbol("witchcraftUiI18nMessages") as InjectionKey<Ref<Record<string, any>>>
25
+
26
+
27
+ export const showDevOnlyInjectionKey = Symbol("showDevOnly") as InjectionKey<Ref<boolean>>
28
+
@@ -6,6 +6,7 @@ export * as directives from "./directives/index.js"
6
6
  export { registerDirectives } from "./vue/registerDirectives.js"
7
7
  export { registerComponents } from "./vue/registerComponents.js"
8
8
  export { VueComponentsPlugin } from "./vue/VueComponentsPlugin.js"
9
+ export * from "./injectionKeys.js"
9
10
 
10
11
  import type * as components from "./components/index.js"
11
12