@witchcraft/ui 0.2.4 → 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 (42) hide show
  1. package/dist/module.d.mts +10 -3
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +12 -7
  4. package/dist/runtime/components/LibButton/LibButton.vue +4 -4
  5. package/dist/runtime/components/LibDevOnly/LibDevOnly.vue +1 -1
  6. package/dist/runtime/components/LibRoot/LibRoot.d.vue.ts +1 -1
  7. package/dist/runtime/components/LibRoot/LibRoot.vue.d.ts +1 -1
  8. package/dist/runtime/composables/index.d.ts +0 -1
  9. package/dist/runtime/composables/index.js +0 -1
  10. package/dist/runtime/composables/useDarkMode.d.ts +1 -5
  11. package/dist/runtime/composables/useDarkMode.js +5 -12
  12. package/dist/runtime/composables/useInjectedDarkMode.d.ts +1 -1
  13. package/dist/runtime/composables/useInjectedDarkMode.js +1 -1
  14. package/dist/runtime/composables/useInjectedI18n.js +1 -1
  15. package/dist/runtime/composables/useInjectedLocale.d.ts +1 -1
  16. package/dist/runtime/composables/useInjectedLocale.js +1 -1
  17. package/dist/runtime/composables/useSetupI18n.d.ts +1 -3
  18. package/dist/runtime/composables/useSetupI18n.js +3 -6
  19. package/dist/runtime/composables/useSetupLocale.d.ts +1 -3
  20. package/dist/runtime/composables/useSetupLocale.js +1 -2
  21. package/dist/runtime/composables/useShowDevOnlyKey.d.ts +0 -1
  22. package/dist/runtime/composables/useShowDevOnlyKey.js +2 -3
  23. package/dist/runtime/helpers/defaultTranslationFunction.js +1 -1
  24. package/dist/runtime/injectionKeys.d.ts +14 -0
  25. package/dist/runtime/injectionKeys.js +9 -0
  26. package/dist/runtime/main.lib.d.ts +1 -0
  27. package/dist/runtime/main.lib.js +1 -0
  28. package/package.json +1 -1
  29. package/src/module.ts +28 -11
  30. package/src/runtime/components/LibButton/LibButton.vue +4 -4
  31. package/src/runtime/components/LibDevOnly/LibDevOnly.vue +1 -1
  32. package/src/runtime/composables/index.ts +0 -1
  33. package/src/runtime/composables/useDarkMode.ts +7 -18
  34. package/src/runtime/composables/useInjectedDarkMode.ts +3 -1
  35. package/src/runtime/composables/useInjectedI18n.ts +2 -1
  36. package/src/runtime/composables/useInjectedLocale.ts +3 -1
  37. package/src/runtime/composables/useSetupI18n.ts +3 -7
  38. package/src/runtime/composables/useSetupLocale.ts +3 -3
  39. package/src/runtime/composables/useShowDevOnlyKey.ts +3 -3
  40. package/src/runtime/helpers/defaultTranslationFunction.ts +4 -3
  41. package/src/runtime/injectionKeys.ts +28 -0
  42. package/src/runtime/main.lib.ts +1 -0
package/dist/module.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import Icons from 'unplugin-icons/vite';
2
3
 
3
4
  declare const knownDirectives: readonly ["vExtractRootEl", "vResizableCols", "vResizeObserver", "vResizableCols"];
4
5
  declare module "@nuxt/schema" {
@@ -8,15 +9,21 @@ declare module "@nuxt/schema" {
8
9
  }
9
10
  interface ModuleOptions {
10
11
  /**
11
- * Whether to include the vite unplugin-icons plugins (pre-configured with the ui module's defaults.
12
+ * Whether to include the vite unplugin-icons plugins (pre-configured with the ui module's defaults, i.e. prefix "i").
12
13
  *
13
14
  * @default true
14
15
  */
15
16
  includeUnpluginIconsPlugins?: boolean;
17
+ /**
18
+ * Pass options to unplugin-icons/nuxt
19
+ *
20
+ * The module doesn't define a key for it's options so this is the only way to allow proper merging.
21
+ */
22
+ unpluginOptions?: Parameters<typeof Icons>[0];
16
23
  directives: (typeof knownDirectives[number])[];
17
24
  /**
18
- * Which components (without a prefix) to register for auto-importing globally.
19
- */
25
+ * Which components (without a prefix) to register for auto-importing globally.
26
+ */
20
27
  globalComponents: string[];
21
28
  /**
22
29
  * @default "W"
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "witchcraftUi",
3
3
  "configKey": "witchcraftUi",
4
- "version": "0.2.4",
4
+ "version": "0.3.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { indent, crop } from '@alanscodelog/utils';
2
- import { createResolver, defineNuxtModule, useLogger, addTemplate, addComponent, addImports, addTypeTemplate } from '@nuxt/kit';
2
+ import { createResolver, defineNuxtModule, installModule, useLogger, addTemplate, addComponent, addImports, addTypeTemplate } from '@nuxt/kit';
3
3
  import tailwindcss from '@tailwindcss/vite';
4
4
  import { addImportsCustom } from '@witchcraft/nuxt-utils/utils/addImportsCustom';
5
5
  import { globFiles } from '@witchcraft/nuxt-utils/utils/globFiles';
@@ -13,8 +13,7 @@ import { themeConvertionOpts } from '../dist/runtime/tailwind/themeConvertionOpt
13
13
  import { theme } from '../dist/runtime/theme.js';
14
14
 
15
15
  const dependencies = {
16
- "reka-ui": "^2.5.0",
17
- "unplugin-icons": "^22.2.0"};
16
+ "reka-ui": "^2.5.0"};
18
17
  const pkg = {
19
18
  dependencies: dependencies};
20
19
 
@@ -35,6 +34,7 @@ const module = defineNuxtModule({
35
34
  },
36
35
  defaults: {
37
36
  includeUnpluginIconsPlugins: true,
37
+ unpluginOptions: unpluginIconViteOptions,
38
38
  directives: [...knownDirectives],
39
39
  globalComponents: [
40
40
  ...componentsInfo.map((_) => _.name.slice("PREFIX".length))
@@ -45,16 +45,20 @@ const module = defineNuxtModule({
45
45
  _playgroundWorkaround: false
46
46
  },
47
47
  moduleDependencies: {
48
- "unplugin-icons/nuxt": {
49
- version: pkg.dependencies["unplugin-icons"],
50
- defaults: unpluginIconViteOptions
51
- },
48
+ // not working, see note for unpluginOptions
49
+ // "unplugin-icons/nuxt": {
50
+ // version: pkg.dependencies["unplugin-icons"],
51
+ // defaults: unpluginIconViteOptions as any
52
+ // },
52
53
  "reka-ui/nuxt": {
53
54
  version: pkg.dependencies["reka-ui"]
54
55
  }
55
56
  },
56
57
  async setup(options, nuxt) {
57
58
  const moduleName = "@witchcraft/ui";
59
+ installModule("unplugin-icons/nuxt", defu(
60
+ options.unpluginOptions
61
+ ));
58
62
  const logger = useLogger(moduleName, { level: options.debug ? 10 : 0 });
59
63
  const filteredComponentsInfo = [];
60
64
  for (const component of componentsInfo) {
@@ -121,6 +125,7 @@ const module = defineNuxtModule({
121
125
  IconsResolver({ prefix: "i" })
122
126
  ]
123
127
  })
128
+ // this is taken care of by unplugin-icons
124
129
  // Icons({
125
130
  // compiler: "vue3",
126
131
  // ...unpluginIconViteOptions,
@@ -19,7 +19,7 @@
19
19
  text-fg
20
20
  hover:text-accent-700
21
21
  dark:text-bg
22
- dark:hover:text-accent-500
22
+ dark:hover:text-accent-400
23
23
  dark:disabled:text-neutral-500
24
24
  dark:disabled:hover:text-neutral-500
25
25
  `,
@@ -27,7 +27,7 @@
27
27
  border && `
28
28
  transition-all
29
29
  bg-neutral-100
30
- dark:bg-neutral-900
30
+ dark:bg-neutral-800
31
31
  shadow-[0_1px_1px_0]
32
32
  shadow-neutral-950/20
33
33
  hover:shadow-[0_1px_3px_0]
@@ -36,7 +36,7 @@
36
36
  dark:hover:border-neutral-800
37
37
  relative
38
38
  after:absolute
39
- after:rounded-xs
39
+ after:rounded-sm
40
40
  after:inset-0
41
41
  after:content
42
42
  after:shadow-[0_1px_0_0_inset]
@@ -53,7 +53,7 @@
53
53
  border-neutral-300
54
54
  disabled:border-neutral-200
55
55
  disabled:bg-neutral-50
56
- dark:hover:shadow-accent-950/30
56
+ dark:hover:shadow-neutral-950/70
57
57
  dark:active:shadow-fg/40
58
58
  dark:active:border-neutral-900
59
59
  dark:border-neutral-900
@@ -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.4",
3
+ "version": "0.3.0",
4
4
  "description": "Vue component library.",
5
5
  "type": "module",
6
6
  "main": "./dist/runtime/main.lib.js",
package/src/module.ts CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  addImports, addTemplate, addTypeTemplate,
5
5
  createResolver,
6
6
  defineNuxtModule,
7
+ installModule,
7
8
  useLogger
8
9
  } from "@nuxt/kit"
9
10
  import tailwindcss from "@tailwindcss/vite"
@@ -13,6 +14,7 @@ import { defu } from "defu"
13
14
  import { themeAsTailwindCss } from "metamorphosis/tailwind"
14
15
  import fs from "node:fs"
15
16
  import IconsResolver from "unplugin-icons/resolver"
17
+ import type Icons from "unplugin-icons/vite"
16
18
  import ViteComponents from "unplugin-vue-components/vite"
17
19
 
18
20
  import { unpluginIconViteOptions } from "./runtime/build/unpluginIconViteOptions.js"
@@ -45,16 +47,24 @@ declare module "@nuxt/schema" {
45
47
  }
46
48
 
47
49
  export interface ModuleOptions {
48
- /**
49
- * Whether to include the vite unplugin-icons plugins (pre-configured with the ui module's defaults.
50
- *
51
- * @default true
52
- */
50
+ /**
51
+ * Whether to include the vite unplugin-icons plugins (pre-configured with the ui module's defaults, i.e. prefix "i").
52
+ *
53
+ * @default true
54
+ */
53
55
  includeUnpluginIconsPlugins?: boolean
56
+ /**
57
+ * Pass options to unplugin-icons/nuxt
58
+ *
59
+ * The module doesn't define a key for it's options so this is the only way to allow proper merging.
60
+ */
61
+ // also moduleDependencies + defaults (or even overrides) isn't working, hence the use of the deprecated installModule
62
+ // I think this is due to how the module is defined (without a key)
63
+ unpluginOptions?: Parameters<typeof Icons>[0]
54
64
  directives: (typeof knownDirectives[number])[]
55
65
  /**
56
- * Which components (without a prefix) to register for auto-importing globally.
57
- */
66
+ * Which components (without a prefix) to register for auto-importing globally.
67
+ */
58
68
  globalComponents: string[]
59
69
  /**
60
70
  * @default "W"
@@ -76,6 +86,7 @@ export default defineNuxtModule<ModuleOptions>({
76
86
  },
77
87
  defaults: {
78
88
  includeUnpluginIconsPlugins: true,
89
+ unpluginOptions: unpluginIconViteOptions,
79
90
  directives: [...knownDirectives],
80
91
  globalComponents: [
81
92
  ...componentsInfo.map(_ => _.name.slice("PREFIX".length))
@@ -86,16 +97,21 @@ export default defineNuxtModule<ModuleOptions>({
86
97
  _playgroundWorkaround: false
87
98
  },
88
99
  moduleDependencies: {
89
- "unplugin-icons/nuxt": {
90
- version: pkg.dependencies["unplugin-icons"],
91
- defaults: unpluginIconViteOptions as any
92
- },
100
+ // not working, see note for unpluginOptions
101
+ // "unplugin-icons/nuxt": {
102
+ // version: pkg.dependencies["unplugin-icons"],
103
+ // defaults: unpluginIconViteOptions as any
104
+ // },
93
105
  "reka-ui/nuxt": {
94
106
  version: pkg.dependencies["reka-ui"]
95
107
  }
96
108
  },
97
109
  async setup(options, nuxt) {
98
110
  const moduleName = "@witchcraft/ui"
111
+ // see note for unpluginOptions
112
+ installModule("unplugin-icons/nuxt", defu(
113
+ options.unpluginOptions
114
+ ))
99
115
  const logger = useLogger(moduleName, { level: options.debug ? 10 : 0 })
100
116
 
101
117
  const filteredComponentsInfo: typeof componentsInfo = []
@@ -173,6 +189,7 @@ export default defineNuxtModule<ModuleOptions>({
173
189
  IconsResolver({ prefix: "i" })
174
190
  ]
175
191
  })
192
+ // this is taken care of by unplugin-icons
176
193
  // Icons({
177
194
  // compiler: "vue3",
178
195
  // ...unpluginIconViteOptions,
@@ -18,7 +18,7 @@
18
18
  text-fg
19
19
  hover:text-accent-700
20
20
  dark:text-bg
21
- dark:hover:text-accent-500
21
+ dark:hover:text-accent-400
22
22
  dark:disabled:text-neutral-500
23
23
  dark:disabled:hover:text-neutral-500
24
24
  `,
@@ -26,7 +26,7 @@
26
26
  border && `
27
27
  transition-all
28
28
  bg-neutral-100
29
- dark:bg-neutral-900
29
+ dark:bg-neutral-800
30
30
  shadow-[0_1px_1px_0]
31
31
  shadow-neutral-950/20
32
32
  hover:shadow-[0_1px_3px_0]
@@ -35,7 +35,7 @@
35
35
  dark:hover:border-neutral-800
36
36
  relative
37
37
  after:absolute
38
- after:rounded-xs
38
+ after:rounded-sm
39
39
  after:inset-0
40
40
  after:content
41
41
  after:shadow-[0_1px_0_0_inset]
@@ -52,7 +52,7 @@
52
52
  border-neutral-300
53
53
  disabled:border-neutral-200
54
54
  disabled:bg-neutral-50
55
- dark:hover:shadow-accent-950/30
55
+ dark:hover:shadow-neutral-950/70
56
56
  dark:active:shadow-fg/40
57
57
  dark:active:border-neutral-900
58
58
  dark:border-neutral-900
@@ -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