@sit-onyx/nuxt 1.0.0-alpha.8 → 1.0.0-beta.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/README.md CHANGED
@@ -1,7 +1,7 @@
1
- <div align="center">
1
+ <div align="center" style="text-align: center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-light.svg">
4
- <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg">
3
+ <source media="(prefers-color-scheme: dark)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-light.svg">
4
+ <source media="(prefers-color-scheme: light)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg">
5
5
  <img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg" width="160px">
6
6
  </picture>
7
7
  </div>
@@ -10,10 +10,10 @@
10
10
 
11
11
  # @sit-onyx/nuxt
12
12
 
13
- A Nuxt module to easily integrate onyx into [Nuxt Js](https://nuxt.com/) projects.
13
+ A Nuxt module to easily integrate onyx into [Nuxt](https://nuxt.com/) projects.
14
14
  Created by [Schwarz IT](https://it.schwarz).
15
15
 
16
- ## Adding it to a nuxt project
16
+ ## Adding it to a Nuxt project
17
17
 
18
18
  Install the module in your Nuxt application with one command:
19
19
 
package/dist/module.d.mts CHANGED
@@ -11,6 +11,20 @@ interface ModuleOptions {
11
11
  * @see https://onyx.schwarz/development/#installation
12
12
  */
13
13
  disableGlobalStyles?: boolean;
14
+ /**
15
+ * Settings related to the integration with @nuxtjs/i18n
16
+ */
17
+ i18n?: {
18
+ /**
19
+ * Mapping for registering the translations from onyx with @nuxtjs/i18n.
20
+ * @example
21
+ * ```ts
22
+ * registerLocales: { "en_US": "en-US" }
23
+ * ```
24
+ * This would register the onyx translations for the language "en-US" to the code "en_US" of your projects locales.
25
+ */
26
+ registerLocales?: Record<string, "en-US" | "de-DE" | "ko-KR">;
27
+ };
14
28
  }
15
29
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
16
30
 
package/dist/module.d.ts CHANGED
@@ -11,6 +11,20 @@ interface ModuleOptions {
11
11
  * @see https://onyx.schwarz/development/#installation
12
12
  */
13
13
  disableGlobalStyles?: boolean;
14
+ /**
15
+ * Settings related to the integration with @nuxtjs/i18n
16
+ */
17
+ i18n?: {
18
+ /**
19
+ * Mapping for registering the translations from onyx with @nuxtjs/i18n.
20
+ * @example
21
+ * ```ts
22
+ * registerLocales: { "en_US": "en-US" }
23
+ * ```
24
+ * This would register the onyx translations for the language "en-US" to the code "en_US" of your projects locales.
25
+ */
26
+ registerLocales?: Record<string, "en-US" | "de-DE" | "ko-KR">;
27
+ };
14
28
  }
15
29
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions>;
16
30
 
package/dist/module.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
- "name": "onyx-nuxt",
2
+ "name": "@sit-onyx/nuxt",
3
3
  "configKey": "onyx",
4
- "version": "1.0.0-alpha.7",
4
+ "version": "0.0.0",
5
5
  "builder": {
6
- "@nuxt/module-builder": "0.7.1",
6
+ "@nuxt/module-builder": "0.8.1",
7
7
  "unbuild": "unknown"
8
8
  }
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,13 +1,15 @@
1
- import { defineNuxtModule, addComponent } from '@nuxt/kit';
1
+ import { defineNuxtModule, useLogger, createResolver, addComponent, addPlugin } from '@nuxt/kit';
2
2
  import * as onyx from 'sit-onyx';
3
3
 
4
4
  const module = defineNuxtModule({
5
5
  meta: {
6
- name: "onyx-nuxt",
6
+ name: "@sit-onyx/nuxt",
7
7
  configKey: "onyx"
8
8
  },
9
9
  defaults: {},
10
10
  setup(options, nuxt) {
11
+ const logger = useLogger("@sit-onyx/nuxt");
12
+ const { resolve } = createResolver(import.meta.url);
11
13
  nuxt.options.postcss.plugins.cssnano = { preset: ["default", { calc: false }] };
12
14
  nuxt.options.css.push("sit-onyx/style.css");
13
15
  if (!options.disableGlobalStyles) {
@@ -20,7 +22,43 @@ const module = defineNuxtModule({
20
22
  export: component
21
23
  });
22
24
  });
25
+ const i18nModuleIndex = getModuleIndex(
26
+ nuxt.options.modules,
27
+ "@nuxtjs/i18n",
28
+ "@nuxtjs/i18n-edge"
29
+ );
30
+ const onyxModuleIndex = getModuleIndex(nuxt.options.modules, "@sit-onyx/nuxt");
31
+ if (i18nModuleIndex >= 0 && onyxModuleIndex > i18nModuleIndex) {
32
+ logger.warn(
33
+ "The @nuxtjs/i18n module was registered before the @sit-onyx/nuxt module. The default translations of onyx won't be loaded, please register the @sit-onyx/nuxt module before @nuxtjs/i18n"
34
+ );
35
+ }
36
+ if (i18nModuleIndex >= 0) {
37
+ const registerOnyxLocales = (register) => {
38
+ register({
39
+ langDir: resolve("./runtime/locales"),
40
+ // we need to use .js files instead of .ts because the .ts files would be compiled to .js in the build step, so
41
+ // when projects use this nuxt module, .ts files will throw a "can not find file" error
42
+ locales: Object.entries(options.i18n?.registerLocales ?? {}).map(([code, language]) => ({
43
+ code,
44
+ file: `${language}.js`
45
+ }))
46
+ });
47
+ };
48
+ nuxt.hook("i18n:registerModule", registerOnyxLocales);
49
+ addPlugin({ src: resolve("./runtime/plugins/onyx") });
50
+ }
23
51
  }
24
52
  });
53
+ function getModuleIndex(modules, ...moduleNames) {
54
+ for (let i = 0; i < modules.length; i++) {
55
+ const module = modules[i];
56
+ if (typeof module === "string" && moduleNames.includes(module))
57
+ return i;
58
+ if (Array.isArray(module) && moduleNames.includes(module[0]))
59
+ return i;
60
+ }
61
+ return -1;
62
+ }
25
63
 
26
64
  export { module as default };
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+ import { defineI18nLocale } from "#i18n";
3
+ import deDE from "sit-onyx/locales/de-DE.json";
4
+
5
+ export default defineI18nLocale(() => {
6
+ return { onyx: deDE };
7
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+ import { defineI18nLocale } from "#i18n";
3
+ import enUS from "sit-onyx/locales/en-US.json";
4
+
5
+ export default defineI18nLocale(() => {
6
+ return { onyx: enUS };
7
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,7 @@
1
+ // @ts-check
2
+ import { defineI18nLocale } from "#i18n";
3
+ import koKR from "sit-onyx/locales/ko-KR.json";
4
+
5
+ export default defineI18nLocale(() => {
6
+ return { onyx: koKR };
7
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,25 @@
1
+ import { computed, watchEffect } from "#imports";
2
+ import { defineNuxtPlugin, useNuxtApp } from "nuxt/app";
3
+ import { provideI18n, syncGlobalOptionalText } from "sit-onyx";
4
+ export default defineNuxtPlugin({
5
+ name: "onyx:plugin",
6
+ // @ts-ignore: dependency comes from @nuxtjs/i18n
7
+ dependsOn: ["i18n:plugin"],
8
+ setup: (app) => {
9
+ const { t: translate, localeProperties } = useNuxtApp().$i18n;
10
+ const t = computed(() => {
11
+ return (key, placeholders) => {
12
+ return translate(`onyx.${key}`, placeholders?.n ?? 1, { named: placeholders });
13
+ };
14
+ });
15
+ provideI18n(app.vueApp, {
16
+ locale: computed(() => localeProperties.value.iso ?? "en-US"),
17
+ t
18
+ });
19
+ app.hook("app:beforeMount", () => {
20
+ watchEffect(() => {
21
+ syncGlobalOptionalText(translate(`onyx.optional`));
22
+ });
23
+ });
24
+ }
25
+ });
package/dist/types.d.mts CHANGED
@@ -1,17 +1 @@
1
-
2
- import type { ModuleOptions } from './module.js'
3
-
4
-
5
-
6
- declare module '@nuxt/schema' {
7
- interface NuxtConfig { ['onyx']?: Partial<ModuleOptions> }
8
- interface NuxtOptions { ['onyx']?: ModuleOptions }
9
- }
10
-
11
- declare module 'nuxt/schema' {
12
- interface NuxtConfig { ['onyx']?: Partial<ModuleOptions> }
13
- interface NuxtOptions { ['onyx']?: ModuleOptions }
14
- }
15
-
16
-
17
- export type { ModuleOptions, default } from './module.js'
1
+ export { type ModuleOptions, default } from './module.js'
package/dist/types.d.ts CHANGED
@@ -1,17 +1 @@
1
-
2
- import type { ModuleOptions } from './module'
3
-
4
-
5
-
6
- declare module '@nuxt/schema' {
7
- interface NuxtConfig { ['onyx']?: Partial<ModuleOptions> }
8
- interface NuxtOptions { ['onyx']?: ModuleOptions }
9
- }
10
-
11
- declare module 'nuxt/schema' {
12
- interface NuxtConfig { ['onyx']?: Partial<ModuleOptions> }
13
- interface NuxtOptions { ['onyx']?: ModuleOptions }
14
- }
15
-
16
-
17
- export type { ModuleOptions, default } from './module'
1
+ export { type ModuleOptions, default } from './module'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sit-onyx/nuxt",
3
- "version": "1.0.0-alpha.8",
3
+ "version": "1.0.0-beta.0",
4
4
  "description": "A Nuxt module to easily integrate onyx into Nuxt projects",
5
5
  "author": "Schwarz IT KG",
6
6
  "license": "Apache-2.0",
@@ -26,17 +26,19 @@
26
26
  "dist"
27
27
  ],
28
28
  "dependencies": {
29
- "@nuxt/kit": "^3.12.1"
29
+ "@nuxt/kit": "^3.12.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@nuxt/devtools": "^1.3.3",
33
- "@nuxt/module-builder": "~0.7.1",
34
- "@nuxt/schema": "^3.12.1",
32
+ "@nuxt/devtools": "^1.3.9",
33
+ "@nuxt/module-builder": "~0.8.1",
34
+ "@nuxt/schema": "^3.12.3",
35
35
  "@nuxt/test-utils": "^3.13.1",
36
- "nuxt": "^3.12.1"
36
+ "@nuxtjs/i18n": "^8.3.1",
37
+ "nuxt": "^3.12.3",
38
+ "vue-i18n": "^9.13.1"
37
39
  },
38
40
  "peerDependencies": {
39
- "sit-onyx": "^1.0.0-alpha.128"
41
+ "sit-onyx": "^1.0.0-beta.0"
40
42
  },
41
43
  "scripts": {
42
44
  "dev": "nuxi dev playground",