@anweb/nuxt-ancore 1.3.5 → 1.4.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.d.mts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { TApi } from '../dist/runtime/types/index.js';
2
+ import { InitOptions } from 'i18next';
3
3
 
4
4
  interface ModuleOptions {
5
- api?: TApi;
5
+ api?: string;
6
+ i18n?: InitOptions<unknown>;
6
7
  }
7
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
8
9
 
package/dist/module.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import { TApi } from '../dist/runtime/types/index.js';
2
+ import { InitOptions } from 'i18next';
3
3
 
4
4
  interface ModuleOptions {
5
- api?: TApi;
5
+ api?: string;
6
+ i18n?: InitOptions<unknown>;
6
7
  }
7
8
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
8
9
 
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "AnCore",
3
3
  "configKey": "ancore",
4
- "version": "1.3.5",
4
+ "version": "1.4.0",
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,4 @@
1
- import { defineNuxtModule, createResolver, addImportsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addComponentsDir, addImportsDir, addPlugin } from '@nuxt/kit';
2
2
 
3
3
  const module = defineNuxtModule({
4
4
  meta: {
@@ -7,13 +7,27 @@ const module = defineNuxtModule({
7
7
  },
8
8
  defaults: {},
9
9
  async setup(_options, _nuxt) {
10
- const { resolve } = createResolver(import.meta.url);
11
- _nuxt.options.runtimeConfig.public.ancore = {
12
- api: _options.api
10
+ const { resolve, resolvePath } = createResolver(import.meta.url);
11
+ _nuxt.options.runtimeConfig.public = {
12
+ i18n: _options.i18n
13
13
  };
14
14
  _nuxt.options.alias["#ancore/types"] = resolve("./runtime/types");
15
+ if (_options.api) {
16
+ _nuxt.options.alias["#ancore/customApi"] = await resolvePath(_options.api);
17
+ }
18
+ addComponentsDir({
19
+ path: resolve("./runtime/components")
20
+ });
15
21
  addImportsDir(resolve("./runtime/composables"));
16
22
  addImportsDir(resolve("./runtime/utils"));
23
+ if (_options.i18n) {
24
+ for (const lng in _options.i18n.resources) {
25
+ if (!_options.i18n.resources[lng]) continue;
26
+ const path = await resolvePath(_options.i18n.resources[lng].translation);
27
+ _options.i18n.resources[lng].translation = structuredClone((await import(path)).default);
28
+ }
29
+ addPlugin(resolve("./runtime/plugins/i18n.ts"));
30
+ }
17
31
  }
18
32
  });
19
33
 
@@ -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,4 +1,6 @@
1
+ import type { InitOptions } from 'i18next'
1
2
  import type { ModuleOptions } from '../../module'
3
+ import type { TApi } from '#ancore/types'
2
4
 
3
5
 
4
6
  declare module 'nuxt/schema' {
@@ -10,8 +12,10 @@ declare module 'nuxt/schema' {
10
12
  }
11
13
 
12
14
  interface PublicRuntimeConfig {
13
- ancore?: Partial<ModuleOptions>
15
+ i18n?: InitOptions<unknown>
14
16
  }
15
17
  }
16
18
 
17
- export {}
19
+ declare module '#ancore/customApi' {
20
+ export const api: TApi
21
+ }
@@ -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";
@@ -1,2 +1,2 @@
1
1
  import type { NitroFetchOptions, NitroFetchRequest } from 'nitropack';
2
- export declare const userApi: <TData = unknown, TError = unknown>(request: NitroFetchRequest, opts: NitroFetchOptions<string>) => Promise<TData>;
2
+ export declare const userApi: <TData = unknown, TError = unknown>(request: NitroFetchRequest, opts: NitroFetchOptions<string>) => any;
@@ -1,9 +1,8 @@
1
- import { useRuntimeConfig } from "#app";
2
1
  import { coreApi } from "./index.js";
2
+ import { api as customApi } from "#ancore/customApi";
3
3
  export const userApi = (request, opts) => {
4
- const runtimeConfig = useRuntimeConfig().public.ancore;
5
- if (runtimeConfig.api) {
6
- return runtimeConfig.api(request, opts);
4
+ if (customApi) {
5
+ return customApi(request, opts);
7
6
  } else {
8
7
  return coreApi(request, opts);
9
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anweb/nuxt-ancore",
3
- "version": "1.3.5",
3
+ "version": "1.4.0",
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",