@sit-onyx/nuxt 1.0.0-alpha.33 → 1.0.0-alpha.34
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 +2 -2
- package/dist/module.mjs +39 -2
- package/dist/runtime/locales/de-DE.d.ts +2 -0
- package/dist/runtime/locales/de-DE.js +5 -0
- package/dist/runtime/locales/en-US.d.ts +2 -0
- package/dist/runtime/locales/en-US.js +5 -0
- package/dist/runtime/locales/ko-KR.d.ts +2 -0
- package/dist/runtime/locales/ko-KR.js +5 -0
- package/dist/runtime/plugins/onyx.d.ts +2 -0
- package/dist/runtime/plugins/onyx.js +25 -0
- package/package.json +5 -3
package/dist/module.json
CHANGED
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
|
|
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,42 @@ 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 (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
|
+
locales: [
|
|
41
|
+
{ code: "de-DE", file: "de-DE.ts" },
|
|
42
|
+
{ code: "en-US", file: "en-US.ts" },
|
|
43
|
+
{ code: "ko-KR", file: "ko-KR.ts" }
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
nuxt.hook("i18n:registerModule", registerOnyxLocales);
|
|
48
|
+
addPlugin({ src: resolve("./runtime/plugins/onyx") });
|
|
49
|
+
}
|
|
23
50
|
}
|
|
24
51
|
});
|
|
52
|
+
function getModuleIndex(modules, ...moduleNames) {
|
|
53
|
+
for (let i = 0; i < modules.length; i++) {
|
|
54
|
+
const module = modules[i];
|
|
55
|
+
if (typeof module === "string" && moduleNames.includes(module))
|
|
56
|
+
return i;
|
|
57
|
+
if (Array.isArray(module) && moduleNames.includes(module[0]))
|
|
58
|
+
return i;
|
|
59
|
+
}
|
|
60
|
+
return -1;
|
|
61
|
+
}
|
|
25
62
|
|
|
26
63
|
export { module as 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sit-onyx/nuxt",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.34",
|
|
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",
|
|
@@ -33,10 +33,12 @@
|
|
|
33
33
|
"@nuxt/module-builder": "~0.8.0",
|
|
34
34
|
"@nuxt/schema": "^3.12.2",
|
|
35
35
|
"@nuxt/test-utils": "^3.13.1",
|
|
36
|
-
"
|
|
36
|
+
"@nuxtjs/i18n": "^8.3.1",
|
|
37
|
+
"nuxt": "^3.12.2",
|
|
38
|
+
"vue-i18n": "^9.13.1"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
|
-
"sit-onyx": "^1.0.0-alpha.
|
|
41
|
+
"sit-onyx": "^1.0.0-alpha.154"
|
|
40
42
|
},
|
|
41
43
|
"scripts": {
|
|
42
44
|
"dev": "nuxi dev playground",
|