@anweb/nuxt-ancore 1.3.6 → 1.4.1

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.d.mts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { InitOptions } from 'i18next';
2
3
 
3
4
  interface ModuleOptions {
4
5
  api?: string;
6
+ i18n?: InitOptions<unknown>;
5
7
  }
6
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
7
9
 
package/dist/module.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { InitOptions } from 'i18next';
2
3
 
3
4
  interface ModuleOptions {
4
5
  api?: string;
6
+ i18n?: InitOptions<unknown>;
5
7
  }
6
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
7
9
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnCore",
3
3
  "configKey": "ancore",
4
- "version": "1.3.6",
4
+ "version": "1.4.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.1",
7
7
  "unbuild": "3.5.0"
package/dist/module.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addComponentsDir, addImportsDir, addPlugin } from '@nuxt/kit';
2
+ import { pathToFileURL } from 'node:url';
2
3
 
3
4
  const module = defineNuxtModule({
4
5
  meta: {
@@ -8,13 +9,27 @@ const module = defineNuxtModule({
8
9
  defaults: {},
9
10
  async setup(_options, _nuxt) {
10
11
  const { resolve, resolvePath } = createResolver(import.meta.url);
11
- _nuxt.options.runtimeConfig.public = {};
12
+ _nuxt.options.runtimeConfig.public = {
13
+ i18n: _options.i18n
14
+ };
12
15
  _nuxt.options.alias["#ancore/types"] = resolve("./runtime/types");
13
16
  if (_options.api) {
14
17
  _nuxt.options.alias["#ancore/customApi"] = await resolvePath(_options.api);
15
18
  }
19
+ addComponentsDir({
20
+ path: resolve("./runtime/components")
21
+ });
16
22
  addImportsDir(resolve("./runtime/composables"));
17
23
  addImportsDir(resolve("./runtime/utils"));
24
+ if (_options.i18n) {
25
+ for (const lng in _options.i18n.resources) {
26
+ if (!_options.i18n.resources[lng]) continue;
27
+ const path = await resolvePath(_options.i18n.resources[lng].translation);
28
+ const fileUrl = pathToFileURL(path).href;
29
+ _options.i18n.resources[lng].translation = structuredClone((await import(fileUrl)).default);
30
+ }
31
+ addPlugin(resolve("./runtime/plugins/i18n.ts"));
32
+ }
18
33
  }
19
34
  });
20
35
 
@@ -0,0 +1,22 @@
1
+ export type TabExposed = {
2
+ reset: () => void;
3
+ };
4
+ declare const Tab: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
5
+ show: {
6
+ type: BooleanConstructor;
7
+ required: true;
8
+ };
9
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
10
+ [key: string]: any;
11
+ }> | import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
12
+ [key: string]: any;
13
+ }>[] | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
14
+ show: {
15
+ type: BooleanConstructor;
16
+ required: true;
17
+ };
18
+ }>> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
19
+ declare const _default: typeof Tab & {
20
+ new (): TabExposed;
21
+ };
22
+ export default _default;
@@ -0,0 +1,39 @@
1
+ import { defineComponent, h, Fragment, watch, ref } from "vue";
2
+ const Tab = defineComponent({
3
+ name: "Tab",
4
+ props: {
5
+ show: {
6
+ type: Boolean,
7
+ required: true
8
+ }
9
+ },
10
+ setup(props, { slots, expose }) {
11
+ const created = ref(false);
12
+ const reset = () => {
13
+ created.value = false;
14
+ };
15
+ watch(() => props.show, () => {
16
+ if (props.show) created.value = true;
17
+ }, { immediate: true });
18
+ expose({ reset });
19
+ return () => {
20
+ if (!created.value) return null;
21
+ const content = slots.default?.() ?? [];
22
+ if (props.show) return h(Fragment, {}, content);
23
+ return content.map(
24
+ (vnode) => h(
25
+ vnode.type,
26
+ {
27
+ ...vnode.props,
28
+ style: {
29
+ ...vnode.props?.style || {},
30
+ display: "none"
31
+ }
32
+ },
33
+ vnode.children
34
+ )
35
+ );
36
+ };
37
+ }
38
+ });
39
+ export default Tab;
@@ -4,7 +4,7 @@ import { useAsyncData } from '#app';
4
4
  interface TConfig {
5
5
  request: NitroFetchRequest;
6
6
  }
7
- interface TUseData<TData, TError> {
7
+ interface TUseAnData<TData, TError> {
8
8
  init: () => Promise<void>;
9
9
  loading: ComputedRef<boolean>;
10
10
  request: Ref<NitroFetchRequest>;
@@ -12,5 +12,5 @@ interface TUseData<TData, TError> {
12
12
  error: ComputedRef<TError>;
13
13
  status: ReturnType<typeof useAsyncData>['status'];
14
14
  }
15
- export declare const useData: <TData = unknown, TError = unknown>(config: TConfig) => TUseData<TData, TError>;
15
+ export declare const useAnData: <TData = unknown, TError = unknown>(config: TConfig) => TUseAnData<TData, TError>;
16
16
  export {};
@@ -1,7 +1,7 @@
1
1
  import { computed, ref } from "vue";
2
2
  import { useAsyncData } from "#app";
3
3
  import { userApi } from "../utils/index.js";
4
- export const useData = (config) => {
4
+ export const useAnData = (config) => {
5
5
  const request = ref(config.request);
6
6
  const loading = computed(() => {
7
7
  return status.value === "pending";
@@ -0,0 +1,6 @@
1
+ declare const _default: (resources?: Record<string, any>, ns?: string) => {
2
+ t: import("i18next").TFunction<["translation", ...string[]], undefined>;
3
+ } | {
4
+ t: (key: string, options?: {}) => string;
5
+ };
6
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import i18next from "i18next";
2
+ export default (resources, ns) => {
3
+ if (!ns) return { t: i18next.t };
4
+ for (const lang in resources) {
5
+ if (!i18next.hasResourceBundle(lang, ns)) {
6
+ i18next.addResourceBundle(lang, ns, resources[lang]);
7
+ }
8
+ }
9
+ const t = (key, options = {}) => i18next.t(key, { ns: [ns, "translation"], ...options });
10
+ return { t };
11
+ };
@@ -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,7 @@
1
+ import i18next from "i18next";
2
+ import { defineNuxtPlugin, useRuntimeConfig } from "#app";
3
+ export default defineNuxtPlugin(async () => {
4
+ const config = useRuntimeConfig().public.i18n;
5
+ if (!config) return;
6
+ await i18next.init(config);
7
+ });
@@ -1,3 +1,4 @@
1
+ import type { InitOptions } from 'i18next'
1
2
  import type { ModuleOptions } from '../../module'
2
3
  import type { TApi } from '#ancore/types'
3
4
 
@@ -11,6 +12,7 @@ declare module 'nuxt/schema' {
11
12
  }
12
13
 
13
14
  interface PublicRuntimeConfig {
15
+ i18n?: InitOptions<unknown>
14
16
  }
15
17
  }
16
18
 
@@ -1,4 +1,4 @@
1
- export * from './ancore.js';
2
1
  export * from './api.js';
2
+ export * from './global.js';
3
3
  export * from './ws.js';
4
4
  export * from './responseList.js';
@@ -1,4 +1,4 @@
1
- export * from "./ancore";
2
1
  export * from "./api";
2
+ export * from "./global";
3
3
  export * from "./ws";
4
4
  export * from "./responseList";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.3.6",
3
+ "version": "1.4.1",
4
4
  "description": "AnCore Nuxt module",
5
5
  "repository": "https://github.com/ANLTD/ancore",
6
6
  "license": "MIT",
@@ -35,7 +35,8 @@
35
35
  "@nuxt/kit": "^4.0.1",
36
36
  "@vueuse/core": "^13.5.0",
37
37
  "@vueuse/integrations": "^13.5.0",
38
- "async-validator": "^4.2.5"
38
+ "async-validator": "^4.2.5",
39
+ "i18next": "^25.3.2"
39
40
  },
40
41
  "devDependencies": {
41
42
  "@nuxt/devtools": "^2.6.2",