@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.
- package/dist/module.json +1 -1
- package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +1 -1
- package/dist/runtime/components/LibRoot/LibRoot.d.vue.ts +1 -1
- package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +1 -1
- package/dist/runtime/composables/index.d.ts +0 -1
- package/dist/runtime/composables/index.js +0 -1
- package/dist/runtime/composables/useDarkMode.d.ts +1 -5
- package/dist/runtime/composables/useDarkMode.js +5 -12
- package/dist/runtime/composables/useInjectedDarkMode.d.ts +1 -1
- package/dist/runtime/composables/useInjectedDarkMode.js +1 -1
- package/dist/runtime/composables/useInjectedI18n.js +1 -1
- package/dist/runtime/composables/useInjectedLocale.d.ts +1 -1
- package/dist/runtime/composables/useInjectedLocale.js +1 -1
- package/dist/runtime/composables/useSetupI18n.d.ts +1 -3
- package/dist/runtime/composables/useSetupI18n.js +3 -6
- package/dist/runtime/composables/useSetupLocale.d.ts +1 -3
- package/dist/runtime/composables/useSetupLocale.js +1 -2
- package/dist/runtime/composables/useShowDevOnlyKey.d.ts +0 -1
- package/dist/runtime/composables/useShowDevOnlyKey.js +2 -3
- package/dist/runtime/helpers/defaultTranslationFunction.js +1 -1
- package/dist/runtime/injectionKeys.d.ts +14 -0
- package/dist/runtime/injectionKeys.js +9 -0
- package/dist/runtime/main.lib.d.ts +1 -0
- package/dist/runtime/main.lib.js +1 -0
- package/package.json +1 -1
- package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -1
- package/src/runtime/composables/index.ts +0 -1
- package/src/runtime/composables/useDarkMode.ts +7 -18
- package/src/runtime/composables/useInjectedDarkMode.ts +3 -1
- package/src/runtime/composables/useInjectedI18n.ts +2 -1
- package/src/runtime/composables/useInjectedLocale.ts +3 -1
- package/src/runtime/composables/useSetupI18n.ts +3 -7
- package/src/runtime/composables/useSetupLocale.ts +3 -3
- package/src/runtime/composables/useShowDevOnlyKey.ts +3 -3
- package/src/runtime/helpers/defaultTranslationFunction.ts +4 -3
- package/src/runtime/injectionKeys.ts +28 -0
- package/src/runtime/main.lib.ts +1 -0
package/dist/module.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
<script setup>
|
|
26
26
|
import { computed, inject, ref, useAttrs } from "vue";
|
|
27
|
-
import { showDevOnlyInjectionKey } from "../../
|
|
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,4 @@
|
|
|
1
|
-
import { type
|
|
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(
|
|
55
|
-
provide(
|
|
56
|
-
provide(
|
|
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(
|
|
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 {
|
|
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 "
|
|
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 "
|
|
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 {
|
|
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 "
|
|
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
|
|
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
|
-
|
|
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(
|
|
28
|
+
provide(i18nInjectionKey, translationFunction);
|
|
30
29
|
if (useBuiltinTranslations) {
|
|
31
30
|
const messages = ref(useDummyMessageSetWhileLoading ? dummyMessageSet : {});
|
|
32
|
-
provide(
|
|
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
|
|
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
|
-
|
|
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");
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { onBeforeUnmount, onMounted, provide, ref } from "vue";
|
|
2
|
-
|
|
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(
|
|
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 "../
|
|
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
|
/**
|
package/dist/runtime/main.lib.js
CHANGED
|
@@ -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
|
@@ -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 "../../
|
|
27
|
+
import { showDevOnlyInjectionKey } from "../../injectionKeys.js"
|
|
28
28
|
import { twMerge } from "../../utils/twMerge.js"
|
|
29
29
|
|
|
30
30
|
const $attrs = useAttrs()
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { computed,
|
|
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(
|
|
86
|
-
provide(
|
|
81
|
+
provide(isDarkModeInjectionKey, darkMode)
|
|
82
|
+
provide(manualDarkModeInjectionKey, manualDarkMode)
|
|
87
83
|
|
|
88
|
-
provide(
|
|
84
|
+
provide(darkModeStateInjectionKey, {
|
|
89
85
|
darkMode,
|
|
90
86
|
darkModeState,
|
|
91
87
|
manualDarkMode,
|
|
92
88
|
systemDarkMode
|
|
93
89
|
})
|
|
94
|
-
provide(
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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(
|
|
52
|
+
provide(i18nInjectionKey, translationFunction)
|
|
55
53
|
if (useBuiltinTranslations) {
|
|
56
54
|
const messages = ref(useDummyMessageSetWhileLoading ? dummyMessageSet : {})
|
|
57
|
-
provide(
|
|
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 {
|
|
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
|
-
|
|
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(
|
|
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
|
|
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)
|
|
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
|
+
|
package/src/runtime/main.lib.ts
CHANGED
|
@@ -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
|
|